d702cb91a3386c8c6a7740492cfb6caead213e7d
[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 worker_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 Worker Cores
489                  * Use 2 worker cores for the device args
490                  */
491                 RTE_LCORE_FOREACH_SLAVE(i) {
492                         if (worker_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                         worker_core_count++;
499                         socket_id = rte_lcore_to_socket_id(i);
500                 }
501                 if (worker_core_count != 2) {
502                         RTE_LOG(ERR, USER1,
503                                 "Cryptodev scheduler test require at least "
504                                 "two worker 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[0];
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         test_AES_CBC_HMAC_SHA1_encrypt_digest();
9330         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
9331                         &stats),
9332                 "rte_cryptodev_stats_get failed");
9333         TEST_ASSERT((stats.enqueued_count == 1),
9334                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9335         TEST_ASSERT((stats.dequeued_count == 1),
9336                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9337         TEST_ASSERT((stats.enqueue_err_count == 0),
9338                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9339         TEST_ASSERT((stats.dequeue_err_count == 0),
9340                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9341
9342         /* invalid device but should ignore and not reset device stats*/
9343         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
9344         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
9345                         &stats),
9346                 "rte_cryptodev_stats_get failed");
9347         TEST_ASSERT((stats.enqueued_count == 1),
9348                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9349
9350         /* check that a valid reset clears stats */
9351         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
9352         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
9353                         &stats),
9354                                           "rte_cryptodev_stats_get failed");
9355         TEST_ASSERT((stats.enqueued_count == 0),
9356                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9357         TEST_ASSERT((stats.dequeued_count == 0),
9358                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9359
9360         return TEST_SUCCESS;
9361 }
9362
9363 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
9364                                    struct crypto_unittest_params *ut_params,
9365                                    enum rte_crypto_auth_operation op,
9366                                    const struct HMAC_MD5_vector *test_case)
9367 {
9368         uint8_t key[64];
9369
9370         memcpy(key, test_case->key.data, test_case->key.len);
9371
9372         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9373         ut_params->auth_xform.next = NULL;
9374         ut_params->auth_xform.auth.op = op;
9375
9376         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
9377
9378         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
9379         ut_params->auth_xform.auth.key.length = test_case->key.len;
9380         ut_params->auth_xform.auth.key.data = key;
9381
9382         ut_params->sess = rte_cryptodev_sym_session_create(
9383                         ts_params->session_mpool);
9384
9385         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9386                         ut_params->sess, &ut_params->auth_xform,
9387                         ts_params->session_priv_mpool);
9388
9389         if (ut_params->sess == NULL)
9390                 return TEST_FAILED;
9391
9392         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9393
9394         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9395                         rte_pktmbuf_tailroom(ut_params->ibuf));
9396
9397         return 0;
9398 }
9399
9400 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
9401                               const struct HMAC_MD5_vector *test_case,
9402                               uint8_t **plaintext)
9403 {
9404         uint16_t plaintext_pad_len;
9405
9406         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9407
9408         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
9409                                 16);
9410
9411         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9412                         plaintext_pad_len);
9413         memcpy(*plaintext, test_case->plaintext.data,
9414                         test_case->plaintext.len);
9415
9416         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
9417                         ut_params->ibuf, MD5_DIGEST_LEN);
9418         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
9419                         "no room to append digest");
9420         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
9421                         ut_params->ibuf, plaintext_pad_len);
9422
9423         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
9424                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
9425                            test_case->auth_tag.len);
9426         }
9427
9428         sym_op->auth.data.offset = 0;
9429         sym_op->auth.data.length = test_case->plaintext.len;
9430
9431         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9432         ut_params->op->sym->m_src = ut_params->ibuf;
9433
9434         return 0;
9435 }
9436
9437 static int
9438 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
9439 {
9440         uint16_t plaintext_pad_len;
9441         uint8_t *plaintext, *auth_tag;
9442
9443         struct crypto_testsuite_params *ts_params = &testsuite_params;
9444         struct crypto_unittest_params *ut_params = &unittest_params;
9445
9446         /* Verify the capabilities */
9447         struct rte_cryptodev_sym_capability_idx cap_idx;
9448         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9449         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
9450         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9451                         &cap_idx) == NULL)
9452                 return -ENOTSUP;
9453
9454         if (MD5_HMAC_create_session(ts_params, ut_params,
9455                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
9456                 return TEST_FAILED;
9457
9458         /* Generate Crypto op data structure */
9459         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9460                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9461         TEST_ASSERT_NOT_NULL(ut_params->op,
9462                         "Failed to allocate symmetric crypto operation struct");
9463
9464         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
9465                                 16);
9466
9467         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
9468                 return TEST_FAILED;
9469
9470         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9471                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
9472                         ut_params->op);
9473         else
9474                 TEST_ASSERT_NOT_NULL(
9475                         process_crypto_request(ts_params->valid_devs[0],
9476                                 ut_params->op),
9477                                 "failed to process sym crypto op");
9478
9479         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9480                         "crypto op processing failed");
9481
9482         if (ut_params->op->sym->m_dst) {
9483                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
9484                                 uint8_t *, plaintext_pad_len);
9485         } else {
9486                 auth_tag = plaintext + plaintext_pad_len;
9487         }
9488
9489         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9490                         auth_tag,
9491                         test_case->auth_tag.data,
9492                         test_case->auth_tag.len,
9493                         "HMAC_MD5 generated tag not as expected");
9494
9495         return TEST_SUCCESS;
9496 }
9497
9498 static int
9499 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
9500 {
9501         uint8_t *plaintext;
9502
9503         struct crypto_testsuite_params *ts_params = &testsuite_params;
9504         struct crypto_unittest_params *ut_params = &unittest_params;
9505
9506         /* Verify the capabilities */
9507         struct rte_cryptodev_sym_capability_idx cap_idx;
9508         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9509         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
9510         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9511                         &cap_idx) == NULL)
9512                 return -ENOTSUP;
9513
9514         if (MD5_HMAC_create_session(ts_params, ut_params,
9515                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
9516                 return TEST_FAILED;
9517         }
9518
9519         /* Generate Crypto op data structure */
9520         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9521                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9522         TEST_ASSERT_NOT_NULL(ut_params->op,
9523                         "Failed to allocate symmetric crypto operation struct");
9524
9525         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
9526                 return TEST_FAILED;
9527
9528         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9529                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
9530                         ut_params->op);
9531         else
9532                 TEST_ASSERT_NOT_NULL(
9533                         process_crypto_request(ts_params->valid_devs[0],
9534                                 ut_params->op),
9535                                 "failed to process sym crypto op");
9536
9537         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9538                         "HMAC_MD5 crypto op processing failed");
9539
9540         return TEST_SUCCESS;
9541 }
9542
9543 static int
9544 test_MD5_HMAC_generate_case_1(void)
9545 {
9546         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
9547 }
9548
9549 static int
9550 test_MD5_HMAC_verify_case_1(void)
9551 {
9552         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
9553 }
9554
9555 static int
9556 test_MD5_HMAC_generate_case_2(void)
9557 {
9558         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
9559 }
9560
9561 static int
9562 test_MD5_HMAC_verify_case_2(void)
9563 {
9564         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
9565 }
9566
9567 static int
9568 test_multi_session(void)
9569 {
9570         struct crypto_testsuite_params *ts_params = &testsuite_params;
9571         struct crypto_unittest_params *ut_params = &unittest_params;
9572
9573         struct rte_cryptodev_info dev_info;
9574         struct rte_cryptodev_sym_session **sessions;
9575
9576         uint16_t i;
9577
9578         /* Verify the capabilities */
9579         struct rte_cryptodev_sym_capability_idx cap_idx;
9580         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9581         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
9582         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9583                         &cap_idx) == NULL)
9584                 return -ENOTSUP;
9585         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9586         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
9587         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9588                         &cap_idx) == NULL)
9589                 return -ENOTSUP;
9590
9591         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
9592                         aes_cbc_key, hmac_sha512_key);
9593
9594
9595         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9596
9597         sessions = rte_malloc(NULL,
9598                         (sizeof(struct rte_cryptodev_sym_session *) *
9599                         MAX_NB_SESSIONS) + 1, 0);
9600
9601         /* Create multiple crypto sessions*/
9602         for (i = 0; i < MAX_NB_SESSIONS; i++) {
9603
9604                 sessions[i] = rte_cryptodev_sym_session_create(
9605                                 ts_params->session_mpool);
9606
9607                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9608                                 sessions[i], &ut_params->auth_xform,
9609                                 ts_params->session_priv_mpool);
9610                 TEST_ASSERT_NOT_NULL(sessions[i],
9611                                 "Session creation failed at session number %u",
9612                                 i);
9613
9614                 /* Attempt to send a request on each session */
9615                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
9616                         sessions[i],
9617                         ut_params,
9618                         ts_params,
9619                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
9620                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
9621                         aes_cbc_iv),
9622                         "Failed to perform decrypt on request number %u.", i);
9623                 /* free crypto operation structure */
9624                 if (ut_params->op)
9625                         rte_crypto_op_free(ut_params->op);
9626
9627                 /*
9628                  * free mbuf - both obuf and ibuf are usually the same,
9629                  * so check if they point at the same address is necessary,
9630                  * to avoid freeing the mbuf twice.
9631                  */
9632                 if (ut_params->obuf) {
9633                         rte_pktmbuf_free(ut_params->obuf);
9634                         if (ut_params->ibuf == ut_params->obuf)
9635                                 ut_params->ibuf = 0;
9636                         ut_params->obuf = 0;
9637                 }
9638                 if (ut_params->ibuf) {
9639                         rte_pktmbuf_free(ut_params->ibuf);
9640                         ut_params->ibuf = 0;
9641                 }
9642         }
9643
9644         /* Next session create should fail */
9645         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9646                         sessions[i], &ut_params->auth_xform,
9647                         ts_params->session_priv_mpool);
9648         TEST_ASSERT_NULL(sessions[i],
9649                         "Session creation succeeded unexpectedly!");
9650
9651         for (i = 0; i < MAX_NB_SESSIONS; i++) {
9652                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
9653                                 sessions[i]);
9654                 rte_cryptodev_sym_session_free(sessions[i]);
9655         }
9656
9657         rte_free(sessions);
9658
9659         return TEST_SUCCESS;
9660 }
9661
9662 struct multi_session_params {
9663         struct crypto_unittest_params ut_params;
9664         uint8_t *cipher_key;
9665         uint8_t *hmac_key;
9666         const uint8_t *cipher;
9667         const uint8_t *digest;
9668         uint8_t *iv;
9669 };
9670
9671 #define MB_SESSION_NUMBER 3
9672
9673 static int
9674 test_multi_session_random_usage(void)
9675 {
9676         struct crypto_testsuite_params *ts_params = &testsuite_params;
9677         struct rte_cryptodev_info dev_info;
9678         struct rte_cryptodev_sym_session **sessions;
9679         uint32_t i, j;
9680         struct multi_session_params ut_paramz[] = {
9681
9682                 {
9683                         .cipher_key = ms_aes_cbc_key0,
9684                         .hmac_key = ms_hmac_key0,
9685                         .cipher = ms_aes_cbc_cipher0,
9686                         .digest = ms_hmac_digest0,
9687                         .iv = ms_aes_cbc_iv0
9688                 },
9689                 {
9690                         .cipher_key = ms_aes_cbc_key1,
9691                         .hmac_key = ms_hmac_key1,
9692                         .cipher = ms_aes_cbc_cipher1,
9693                         .digest = ms_hmac_digest1,
9694                         .iv = ms_aes_cbc_iv1
9695                 },
9696                 {
9697                         .cipher_key = ms_aes_cbc_key2,
9698                         .hmac_key = ms_hmac_key2,
9699                         .cipher = ms_aes_cbc_cipher2,
9700                         .digest = ms_hmac_digest2,
9701                         .iv = ms_aes_cbc_iv2
9702                 },
9703
9704         };
9705
9706         /* Verify the capabilities */
9707         struct rte_cryptodev_sym_capability_idx cap_idx;
9708         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9709         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
9710         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9711                         &cap_idx) == NULL)
9712                 return -ENOTSUP;
9713         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9714         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
9715         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9716                         &cap_idx) == NULL)
9717                 return -ENOTSUP;
9718
9719         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9720
9721         sessions = rte_malloc(NULL,
9722                         (sizeof(struct rte_cryptodev_sym_session *)
9723                                         * MAX_NB_SESSIONS) + 1, 0);
9724
9725         for (i = 0; i < MB_SESSION_NUMBER; i++) {
9726                 sessions[i] = rte_cryptodev_sym_session_create(
9727                                 ts_params->session_mpool);
9728
9729                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
9730                                 sizeof(struct crypto_unittest_params));
9731
9732                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
9733                                 &ut_paramz[i].ut_params,
9734                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
9735
9736                 /* Create multiple crypto sessions*/
9737                 rte_cryptodev_sym_session_init(
9738                                 ts_params->valid_devs[0],
9739                                 sessions[i],
9740                                 &ut_paramz[i].ut_params.auth_xform,
9741                                 ts_params->session_priv_mpool);
9742
9743                 TEST_ASSERT_NOT_NULL(sessions[i],
9744                                 "Session creation failed at session number %u",
9745                                 i);
9746
9747         }
9748
9749         srand(time(NULL));
9750         for (i = 0; i < 40000; i++) {
9751
9752                 j = rand() % MB_SESSION_NUMBER;
9753
9754                 TEST_ASSERT_SUCCESS(
9755                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
9756                                         sessions[j],
9757                                         &ut_paramz[j].ut_params,
9758                                         ts_params, ut_paramz[j].cipher,
9759                                         ut_paramz[j].digest,
9760                                         ut_paramz[j].iv),
9761                         "Failed to perform decrypt on request number %u.", i);
9762
9763                 if (ut_paramz[j].ut_params.op)
9764                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
9765
9766                 /*
9767                  * free mbuf - both obuf and ibuf are usually the same,
9768                  * so check if they point at the same address is necessary,
9769                  * to avoid freeing the mbuf twice.
9770                  */
9771                 if (ut_paramz[j].ut_params.obuf) {
9772                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
9773                         if (ut_paramz[j].ut_params.ibuf
9774                                         == ut_paramz[j].ut_params.obuf)
9775                                 ut_paramz[j].ut_params.ibuf = 0;
9776                         ut_paramz[j].ut_params.obuf = 0;
9777                 }
9778                 if (ut_paramz[j].ut_params.ibuf) {
9779                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
9780                         ut_paramz[j].ut_params.ibuf = 0;
9781                 }
9782         }
9783
9784         for (i = 0; i < MB_SESSION_NUMBER; i++) {
9785                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
9786                                 sessions[i]);
9787                 rte_cryptodev_sym_session_free(sessions[i]);
9788         }
9789
9790         rte_free(sessions);
9791
9792         return TEST_SUCCESS;
9793 }
9794
9795 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
9796                         0xab, 0xab, 0xab, 0xab,
9797                         0xab, 0xab, 0xab, 0xab,
9798                         0xab, 0xab, 0xab, 0xab};
9799
9800 static int
9801 test_null_invalid_operation(void)
9802 {
9803         struct crypto_testsuite_params *ts_params = &testsuite_params;
9804         struct crypto_unittest_params *ut_params = &unittest_params;
9805         int ret;
9806
9807         /* This test is for NULL PMD only */
9808         if (gbl_driver_id != rte_cryptodev_driver_id_get(
9809                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
9810                 return -ENOTSUP;
9811
9812         /* Setup Cipher Parameters */
9813         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9814         ut_params->cipher_xform.next = NULL;
9815
9816         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
9817         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9818
9819         ut_params->sess = rte_cryptodev_sym_session_create(
9820                         ts_params->session_mpool);
9821
9822         /* Create Crypto session*/
9823         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9824                         ut_params->sess, &ut_params->cipher_xform,
9825                         ts_params->session_priv_mpool);
9826         TEST_ASSERT(ret < 0,
9827                         "Session creation succeeded unexpectedly");
9828
9829
9830         /* Setup HMAC Parameters */
9831         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9832         ut_params->auth_xform.next = NULL;
9833
9834         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
9835         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9836
9837         ut_params->sess = rte_cryptodev_sym_session_create(
9838                         ts_params->session_mpool);
9839
9840         /* Create Crypto session*/
9841         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9842                         ut_params->sess, &ut_params->auth_xform,
9843                         ts_params->session_priv_mpool);
9844         TEST_ASSERT(ret < 0,
9845                         "Session creation succeeded unexpectedly");
9846
9847         return TEST_SUCCESS;
9848 }
9849
9850
9851 #define NULL_BURST_LENGTH (32)
9852
9853 static int
9854 test_null_burst_operation(void)
9855 {
9856         struct crypto_testsuite_params *ts_params = &testsuite_params;
9857         struct crypto_unittest_params *ut_params = &unittest_params;
9858
9859         unsigned i, burst_len = NULL_BURST_LENGTH;
9860
9861         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
9862         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
9863
9864         /* This test is for NULL PMD only */
9865         if (gbl_driver_id != rte_cryptodev_driver_id_get(
9866                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
9867                 return -ENOTSUP;
9868
9869         /* Setup Cipher Parameters */
9870         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9871         ut_params->cipher_xform.next = &ut_params->auth_xform;
9872
9873         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
9874         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9875
9876         /* Setup HMAC Parameters */
9877         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9878         ut_params->auth_xform.next = NULL;
9879
9880         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
9881         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
9882
9883         ut_params->sess = rte_cryptodev_sym_session_create(
9884                         ts_params->session_mpool);
9885
9886         /* Create Crypto session*/
9887         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9888                         ut_params->sess, &ut_params->cipher_xform,
9889                         ts_params->session_priv_mpool);
9890         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9891
9892         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
9893                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
9894                         burst_len, "failed to generate burst of crypto ops");
9895
9896         /* Generate an operation for each mbuf in burst */
9897         for (i = 0; i < burst_len; i++) {
9898                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9899
9900                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
9901
9902                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
9903                                 sizeof(unsigned));
9904                 *data = i;
9905
9906                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
9907
9908                 burst[i]->sym->m_src = m;
9909         }
9910
9911         /* Process crypto operation */
9912         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
9913                         0, burst, burst_len),
9914                         burst_len,
9915                         "Error enqueuing burst");
9916
9917         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
9918                         0, burst_dequeued, burst_len),
9919                         burst_len,
9920                         "Error dequeuing burst");
9921
9922
9923         for (i = 0; i < burst_len; i++) {
9924                 TEST_ASSERT_EQUAL(
9925                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
9926                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
9927                                         uint32_t *),
9928                         "data not as expected");
9929
9930                 rte_pktmbuf_free(burst[i]->sym->m_src);
9931                 rte_crypto_op_free(burst[i]);
9932         }
9933
9934         return TEST_SUCCESS;
9935 }
9936
9937 static void
9938 generate_gmac_large_plaintext(uint8_t *data)
9939 {
9940         uint16_t i;
9941
9942         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
9943                 memcpy(&data[i], &data[0], 32);
9944 }
9945
9946 static int
9947 create_gmac_operation(enum rte_crypto_auth_operation op,
9948                 const struct gmac_test_data *tdata)
9949 {
9950         struct crypto_testsuite_params *ts_params = &testsuite_params;
9951         struct crypto_unittest_params *ut_params = &unittest_params;
9952         struct rte_crypto_sym_op *sym_op;
9953
9954         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9955
9956         /* Generate Crypto op data structure */
9957         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9958                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9959         TEST_ASSERT_NOT_NULL(ut_params->op,
9960                         "Failed to allocate symmetric crypto operation struct");
9961
9962         sym_op = ut_params->op->sym;
9963
9964         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
9965                         ut_params->ibuf, tdata->gmac_tag.len);
9966         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
9967                         "no room to append digest");
9968
9969         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
9970                         ut_params->ibuf, plaintext_pad_len);
9971
9972         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
9973                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
9974                                 tdata->gmac_tag.len);
9975                 debug_hexdump(stdout, "digest:",
9976                                 sym_op->auth.digest.data,
9977                                 tdata->gmac_tag.len);
9978         }
9979
9980         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
9981                         uint8_t *, IV_OFFSET);
9982
9983         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
9984
9985         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
9986
9987         sym_op->cipher.data.length = 0;
9988         sym_op->cipher.data.offset = 0;
9989
9990         sym_op->auth.data.offset = 0;
9991         sym_op->auth.data.length = tdata->plaintext.len;
9992
9993         return 0;
9994 }
9995
9996 static int create_gmac_session(uint8_t dev_id,
9997                 const struct gmac_test_data *tdata,
9998                 enum rte_crypto_auth_operation auth_op)
9999 {
10000         uint8_t auth_key[tdata->key.len];
10001
10002         struct crypto_testsuite_params *ts_params = &testsuite_params;
10003         struct crypto_unittest_params *ut_params = &unittest_params;
10004
10005         memcpy(auth_key, tdata->key.data, tdata->key.len);
10006
10007         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10008         ut_params->auth_xform.next = NULL;
10009
10010         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
10011         ut_params->auth_xform.auth.op = auth_op;
10012         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
10013         ut_params->auth_xform.auth.key.length = tdata->key.len;
10014         ut_params->auth_xform.auth.key.data = auth_key;
10015         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
10016         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
10017
10018
10019         ut_params->sess = rte_cryptodev_sym_session_create(
10020                         ts_params->session_mpool);
10021
10022         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
10023                         &ut_params->auth_xform,
10024                         ts_params->session_priv_mpool);
10025
10026         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10027
10028         return 0;
10029 }
10030
10031 static int
10032 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
10033 {
10034         struct crypto_testsuite_params *ts_params = &testsuite_params;
10035         struct crypto_unittest_params *ut_params = &unittest_params;
10036
10037         int retval;
10038
10039         uint8_t *auth_tag, *plaintext;
10040         uint16_t plaintext_pad_len;
10041
10042         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
10043                               "No GMAC length in the source data");
10044
10045         /* Verify the capabilities */
10046         struct rte_cryptodev_sym_capability_idx cap_idx;
10047         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10048         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
10049         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10050                         &cap_idx) == NULL)
10051                 return -ENOTSUP;
10052
10053         retval = create_gmac_session(ts_params->valid_devs[0],
10054                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
10055
10056         if (retval < 0)
10057                 return retval;
10058
10059         if (tdata->plaintext.len > MBUF_SIZE)
10060                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10061         else
10062                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10063         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10064                         "Failed to allocate input buffer in mempool");
10065
10066         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10067                         rte_pktmbuf_tailroom(ut_params->ibuf));
10068
10069         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10070         /*
10071          * Runtime generate the large plain text instead of use hard code
10072          * plain text vector. It is done to avoid create huge source file
10073          * with the test vector.
10074          */
10075         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
10076                 generate_gmac_large_plaintext(tdata->plaintext.data);
10077
10078         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10079                                 plaintext_pad_len);
10080         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10081
10082         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
10083         debug_hexdump(stdout, "plaintext:", plaintext,
10084                         tdata->plaintext.len);
10085
10086         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
10087                         tdata);
10088
10089         if (retval < 0)
10090                 return retval;
10091
10092         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10093
10094         ut_params->op->sym->m_src = ut_params->ibuf;
10095
10096         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10097                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10098                         ut_params->op);
10099         else
10100                 TEST_ASSERT_NOT_NULL(
10101                         process_crypto_request(ts_params->valid_devs[0],
10102                         ut_params->op), "failed to process sym crypto op");
10103
10104         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10105                         "crypto op processing failed");
10106
10107         if (ut_params->op->sym->m_dst) {
10108                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10109                                 uint8_t *, plaintext_pad_len);
10110         } else {
10111                 auth_tag = plaintext + plaintext_pad_len;
10112         }
10113
10114         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
10115
10116         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10117                         auth_tag,
10118                         tdata->gmac_tag.data,
10119                         tdata->gmac_tag.len,
10120                         "GMAC Generated auth tag not as expected");
10121
10122         return 0;
10123 }
10124
10125 static int
10126 test_AES_GMAC_authentication_test_case_1(void)
10127 {
10128         return test_AES_GMAC_authentication(&gmac_test_case_1);
10129 }
10130
10131 static int
10132 test_AES_GMAC_authentication_test_case_2(void)
10133 {
10134         return test_AES_GMAC_authentication(&gmac_test_case_2);
10135 }
10136
10137 static int
10138 test_AES_GMAC_authentication_test_case_3(void)
10139 {
10140         return test_AES_GMAC_authentication(&gmac_test_case_3);
10141 }
10142
10143 static int
10144 test_AES_GMAC_authentication_test_case_4(void)
10145 {
10146         return test_AES_GMAC_authentication(&gmac_test_case_4);
10147 }
10148
10149 static int
10150 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
10151 {
10152         struct crypto_testsuite_params *ts_params = &testsuite_params;
10153         struct crypto_unittest_params *ut_params = &unittest_params;
10154         int retval;
10155         uint32_t plaintext_pad_len;
10156         uint8_t *plaintext;
10157
10158         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
10159                               "No GMAC length in the source data");
10160
10161         /* Verify the capabilities */
10162         struct rte_cryptodev_sym_capability_idx cap_idx;
10163         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10164         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
10165         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10166                         &cap_idx) == NULL)
10167                 return -ENOTSUP;
10168
10169         retval = create_gmac_session(ts_params->valid_devs[0],
10170                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
10171
10172         if (retval < 0)
10173                 return retval;
10174
10175         if (tdata->plaintext.len > MBUF_SIZE)
10176                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10177         else
10178                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10179         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10180                         "Failed to allocate input buffer in mempool");
10181
10182         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10183                         rte_pktmbuf_tailroom(ut_params->ibuf));
10184
10185         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10186
10187         /*
10188          * Runtime generate the large plain text instead of use hard code
10189          * plain text vector. It is done to avoid create huge source file
10190          * with the test vector.
10191          */
10192         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
10193                 generate_gmac_large_plaintext(tdata->plaintext.data);
10194
10195         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10196                                 plaintext_pad_len);
10197         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10198
10199         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
10200         debug_hexdump(stdout, "plaintext:", plaintext,
10201                         tdata->plaintext.len);
10202
10203         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
10204                         tdata);
10205
10206         if (retval < 0)
10207                 return retval;
10208
10209         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10210
10211         ut_params->op->sym->m_src = ut_params->ibuf;
10212
10213         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10214                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10215                         ut_params->op);
10216         else
10217                 TEST_ASSERT_NOT_NULL(
10218                         process_crypto_request(ts_params->valid_devs[0],
10219                         ut_params->op), "failed to process sym crypto op");
10220
10221         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10222                         "crypto op processing failed");
10223
10224         return 0;
10225
10226 }
10227
10228 static int
10229 test_AES_GMAC_authentication_verify_test_case_1(void)
10230 {
10231         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
10232 }
10233
10234 static int
10235 test_AES_GMAC_authentication_verify_test_case_2(void)
10236 {
10237         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
10238 }
10239
10240 static int
10241 test_AES_GMAC_authentication_verify_test_case_3(void)
10242 {
10243         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
10244 }
10245
10246 static int
10247 test_AES_GMAC_authentication_verify_test_case_4(void)
10248 {
10249         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
10250 }
10251
10252 struct test_crypto_vector {
10253         enum rte_crypto_cipher_algorithm crypto_algo;
10254         unsigned int cipher_offset;
10255         unsigned int cipher_len;
10256
10257         struct {
10258                 uint8_t data[64];
10259                 unsigned int len;
10260         } cipher_key;
10261
10262         struct {
10263                 uint8_t data[64];
10264                 unsigned int len;
10265         } iv;
10266
10267         struct {
10268                 const uint8_t *data;
10269                 unsigned int len;
10270         } plaintext;
10271
10272         struct {
10273                 const uint8_t *data;
10274                 unsigned int len;
10275         } ciphertext;
10276
10277         enum rte_crypto_auth_algorithm auth_algo;
10278         unsigned int auth_offset;
10279
10280         struct {
10281                 uint8_t data[128];
10282                 unsigned int len;
10283         } auth_key;
10284
10285         struct {
10286                 const uint8_t *data;
10287                 unsigned int len;
10288         } aad;
10289
10290         struct {
10291                 uint8_t data[128];
10292                 unsigned int len;
10293         } digest;
10294 };
10295
10296 static const struct test_crypto_vector
10297 hmac_sha1_test_crypto_vector = {
10298         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
10299         .plaintext = {
10300                 .data = plaintext_hash,
10301                 .len = 512
10302         },
10303         .auth_key = {
10304                 .data = {
10305                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
10306                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
10307                         0xDE, 0xF4, 0xDE, 0xAD
10308                 },
10309                 .len = 20
10310         },
10311         .digest = {
10312                 .data = {
10313                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
10314                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
10315                         0x3F, 0x91, 0x64, 0x59
10316                 },
10317                 .len = 20
10318         }
10319 };
10320
10321 static const struct test_crypto_vector
10322 aes128_gmac_test_vector = {
10323         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
10324         .plaintext = {
10325                 .data = plaintext_hash,
10326                 .len = 512
10327         },
10328         .iv = {
10329                 .data = {
10330                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
10331                         0x08, 0x09, 0x0A, 0x0B
10332                 },
10333                 .len = 12
10334         },
10335         .auth_key = {
10336                 .data = {
10337                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
10338                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
10339                 },
10340                 .len = 16
10341         },
10342         .digest = {
10343                 .data = {
10344                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
10345                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
10346                 },
10347                 .len = 16
10348         }
10349 };
10350
10351 static const struct test_crypto_vector
10352 aes128cbc_hmac_sha1_test_vector = {
10353         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
10354         .cipher_offset = 0,
10355         .cipher_len = 512,
10356         .cipher_key = {
10357                 .data = {
10358                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
10359                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
10360                 },
10361                 .len = 16
10362         },
10363         .iv = {
10364                 .data = {
10365                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
10366                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
10367                 },
10368                 .len = 16
10369         },
10370         .plaintext = {
10371                 .data = plaintext_hash,
10372                 .len = 512
10373         },
10374         .ciphertext = {
10375                 .data = ciphertext512_aes128cbc,
10376                 .len = 512
10377         },
10378         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
10379         .auth_offset = 0,
10380         .auth_key = {
10381                 .data = {
10382                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
10383                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
10384                         0xDE, 0xF4, 0xDE, 0xAD
10385                 },
10386                 .len = 20
10387         },
10388         .digest = {
10389                 .data = {
10390                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
10391                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
10392                         0x18, 0x8C, 0x1D, 0x32
10393                 },
10394                 .len = 20
10395         }
10396 };
10397
10398 static const struct test_crypto_vector
10399 aes128cbc_hmac_sha1_aad_test_vector = {
10400         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
10401         .cipher_offset = 8,
10402         .cipher_len = 496,
10403         .cipher_key = {
10404                 .data = {
10405                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
10406                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
10407                 },
10408                 .len = 16
10409         },
10410         .iv = {
10411                 .data = {
10412                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
10413                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
10414                 },
10415                 .len = 16
10416         },
10417         .plaintext = {
10418                 .data = plaintext_hash,
10419                 .len = 512
10420         },
10421         .ciphertext = {
10422                 .data = ciphertext512_aes128cbc_aad,
10423                 .len = 512
10424         },
10425         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
10426         .auth_offset = 0,
10427         .auth_key = {
10428                 .data = {
10429                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
10430                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
10431                         0xDE, 0xF4, 0xDE, 0xAD
10432                 },
10433                 .len = 20
10434         },
10435         .digest = {
10436                 .data = {
10437                         0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
10438                         0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
10439                         0x62, 0x0F, 0xFB, 0x10
10440                 },
10441                 .len = 20
10442         }
10443 };
10444
10445 static void
10446 data_corruption(uint8_t *data)
10447 {
10448         data[0] += 1;
10449 }
10450
10451 static void
10452 tag_corruption(uint8_t *data, unsigned int tag_offset)
10453 {
10454         data[tag_offset] += 1;
10455 }
10456
10457 static int
10458 create_auth_session(struct crypto_unittest_params *ut_params,
10459                 uint8_t dev_id,
10460                 const struct test_crypto_vector *reference,
10461                 enum rte_crypto_auth_operation auth_op)
10462 {
10463         struct crypto_testsuite_params *ts_params = &testsuite_params;
10464         uint8_t auth_key[reference->auth_key.len + 1];
10465
10466         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10467
10468         /* Setup Authentication Parameters */
10469         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10470         ut_params->auth_xform.auth.op = auth_op;
10471         ut_params->auth_xform.next = NULL;
10472         ut_params->auth_xform.auth.algo = reference->auth_algo;
10473         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10474         ut_params->auth_xform.auth.key.data = auth_key;
10475         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10476
10477         /* Create Crypto session*/
10478         ut_params->sess = rte_cryptodev_sym_session_create(
10479                         ts_params->session_mpool);
10480
10481         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
10482                                 &ut_params->auth_xform,
10483                                 ts_params->session_priv_mpool);
10484
10485         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10486
10487         return 0;
10488 }
10489
10490 static int
10491 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
10492                 uint8_t dev_id,
10493                 const struct test_crypto_vector *reference,
10494                 enum rte_crypto_auth_operation auth_op,
10495                 enum rte_crypto_cipher_operation cipher_op)
10496 {
10497         struct crypto_testsuite_params *ts_params = &testsuite_params;
10498         uint8_t cipher_key[reference->cipher_key.len + 1];
10499         uint8_t auth_key[reference->auth_key.len + 1];
10500
10501         memcpy(cipher_key, reference->cipher_key.data,
10502                         reference->cipher_key.len);
10503         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10504
10505         /* Setup Authentication Parameters */
10506         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10507         ut_params->auth_xform.auth.op = auth_op;
10508         ut_params->auth_xform.auth.algo = reference->auth_algo;
10509         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10510         ut_params->auth_xform.auth.key.data = auth_key;
10511         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10512
10513         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
10514                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
10515                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
10516         } else {
10517                 ut_params->auth_xform.next = &ut_params->cipher_xform;
10518
10519                 /* Setup Cipher Parameters */
10520                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10521                 ut_params->cipher_xform.next = NULL;
10522                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
10523                 ut_params->cipher_xform.cipher.op = cipher_op;
10524                 ut_params->cipher_xform.cipher.key.data = cipher_key;
10525                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
10526                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10527                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
10528         }
10529
10530         /* Create Crypto session*/
10531         ut_params->sess = rte_cryptodev_sym_session_create(
10532                         ts_params->session_mpool);
10533
10534         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
10535                                 &ut_params->auth_xform,
10536                                 ts_params->session_priv_mpool);
10537
10538         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10539
10540         return 0;
10541 }
10542
10543 static int
10544 create_auth_operation(struct crypto_testsuite_params *ts_params,
10545                 struct crypto_unittest_params *ut_params,
10546                 const struct test_crypto_vector *reference,
10547                 unsigned int auth_generate)
10548 {
10549         /* Generate Crypto op data structure */
10550         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10551                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10552         TEST_ASSERT_NOT_NULL(ut_params->op,
10553                         "Failed to allocate pktmbuf offload");
10554
10555         /* Set crypto operation data parameters */
10556         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10557
10558         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10559
10560         /* set crypto operation source mbuf */
10561         sym_op->m_src = ut_params->ibuf;
10562
10563         /* digest */
10564         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10565                         ut_params->ibuf, reference->digest.len);
10566
10567         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10568                         "no room to append auth tag");
10569
10570         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10571                         ut_params->ibuf, reference->plaintext.len);
10572
10573         if (auth_generate)
10574                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
10575         else
10576                 memcpy(sym_op->auth.digest.data,
10577                                 reference->digest.data,
10578                                 reference->digest.len);
10579
10580         debug_hexdump(stdout, "digest:",
10581                         sym_op->auth.digest.data,
10582                         reference->digest.len);
10583
10584         sym_op->auth.data.length = reference->plaintext.len;
10585         sym_op->auth.data.offset = 0;
10586
10587         return 0;
10588 }
10589
10590 static int
10591 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
10592                 struct crypto_unittest_params *ut_params,
10593                 const struct test_crypto_vector *reference,
10594                 unsigned int auth_generate)
10595 {
10596         /* Generate Crypto op data structure */
10597         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10598                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10599         TEST_ASSERT_NOT_NULL(ut_params->op,
10600                         "Failed to allocate pktmbuf offload");
10601
10602         /* Set crypto operation data parameters */
10603         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10604
10605         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10606
10607         /* set crypto operation source mbuf */
10608         sym_op->m_src = ut_params->ibuf;
10609
10610         /* digest */
10611         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10612                         ut_params->ibuf, reference->digest.len);
10613
10614         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10615                         "no room to append auth tag");
10616
10617         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10618                         ut_params->ibuf, reference->ciphertext.len);
10619
10620         if (auth_generate)
10621                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
10622         else
10623                 memcpy(sym_op->auth.digest.data,
10624                                 reference->digest.data,
10625                                 reference->digest.len);
10626
10627         debug_hexdump(stdout, "digest:",
10628                         sym_op->auth.digest.data,
10629                         reference->digest.len);
10630
10631         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
10632                         reference->iv.data, reference->iv.len);
10633
10634         sym_op->cipher.data.length = 0;
10635         sym_op->cipher.data.offset = 0;
10636
10637         sym_op->auth.data.length = reference->plaintext.len;
10638         sym_op->auth.data.offset = 0;
10639
10640         return 0;
10641 }
10642
10643 static int
10644 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
10645                 struct crypto_unittest_params *ut_params,
10646                 const struct test_crypto_vector *reference,
10647                 unsigned int auth_generate)
10648 {
10649         /* Generate Crypto op data structure */
10650         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10651                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10652         TEST_ASSERT_NOT_NULL(ut_params->op,
10653                         "Failed to allocate pktmbuf offload");
10654
10655         /* Set crypto operation data parameters */
10656         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10657
10658         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10659
10660         /* set crypto operation source mbuf */
10661         sym_op->m_src = ut_params->ibuf;
10662
10663         /* digest */
10664         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10665                         ut_params->ibuf, reference->digest.len);
10666
10667         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10668                         "no room to append auth tag");
10669
10670         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10671                         ut_params->ibuf, reference->ciphertext.len);
10672
10673         if (auth_generate)
10674                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
10675         else
10676                 memcpy(sym_op->auth.digest.data,
10677                                 reference->digest.data,
10678                                 reference->digest.len);
10679
10680         debug_hexdump(stdout, "digest:",
10681                         sym_op->auth.digest.data,
10682                         reference->digest.len);
10683
10684         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
10685                         reference->iv.data, reference->iv.len);
10686
10687         sym_op->cipher.data.length = reference->cipher_len;
10688         sym_op->cipher.data.offset = reference->cipher_offset;
10689
10690         sym_op->auth.data.length = reference->plaintext.len;
10691         sym_op->auth.data.offset = reference->auth_offset;
10692
10693         return 0;
10694 }
10695
10696 static int
10697 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
10698                 struct crypto_unittest_params *ut_params,
10699                 const struct test_crypto_vector *reference)
10700 {
10701         return create_auth_operation(ts_params, ut_params, reference, 0);
10702 }
10703
10704 static int
10705 create_auth_verify_GMAC_operation(
10706                 struct crypto_testsuite_params *ts_params,
10707                 struct crypto_unittest_params *ut_params,
10708                 const struct test_crypto_vector *reference)
10709 {
10710         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
10711 }
10712
10713 static int
10714 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
10715                 struct crypto_unittest_params *ut_params,
10716                 const struct test_crypto_vector *reference)
10717 {
10718         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
10719 }
10720
10721 static int
10722 test_authentication_verify_fail_when_data_corruption(
10723                 struct crypto_testsuite_params *ts_params,
10724                 struct crypto_unittest_params *ut_params,
10725                 const struct test_crypto_vector *reference,
10726                 unsigned int data_corrupted)
10727 {
10728         int retval;
10729
10730         uint8_t *plaintext;
10731
10732         /* Verify the capabilities */
10733         struct rte_cryptodev_sym_capability_idx cap_idx;
10734         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10735         cap_idx.algo.auth = reference->auth_algo;
10736         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10737                         &cap_idx) == NULL)
10738                 return -ENOTSUP;
10739
10740         /* Create session */
10741         retval = create_auth_session(ut_params,
10742                         ts_params->valid_devs[0],
10743                         reference,
10744                         RTE_CRYPTO_AUTH_OP_VERIFY);
10745         if (retval < 0)
10746                 return retval;
10747
10748         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10749         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10750                         "Failed to allocate input buffer in mempool");
10751
10752         /* clear mbuf payload */
10753         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10754                         rte_pktmbuf_tailroom(ut_params->ibuf));
10755
10756         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10757                         reference->plaintext.len);
10758         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10759         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
10760
10761         debug_hexdump(stdout, "plaintext:", plaintext,
10762                 reference->plaintext.len);
10763
10764         /* Create operation */
10765         retval = create_auth_verify_operation(ts_params, ut_params, reference);
10766
10767         if (retval < 0)
10768                 return retval;
10769
10770         if (data_corrupted)
10771                 data_corruption(plaintext);
10772         else
10773                 tag_corruption(plaintext, reference->plaintext.len);
10774
10775         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
10776                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10777                         ut_params->op);
10778                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
10779                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10780                         "authentication not failed");
10781         } else {
10782                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10783                         ut_params->op);
10784                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
10785         }
10786
10787         return 0;
10788 }
10789
10790 static int
10791 test_authentication_verify_GMAC_fail_when_corruption(
10792                 struct crypto_testsuite_params *ts_params,
10793                 struct crypto_unittest_params *ut_params,
10794                 const struct test_crypto_vector *reference,
10795                 unsigned int data_corrupted)
10796 {
10797         int retval;
10798         uint8_t *plaintext;
10799
10800         /* Verify the capabilities */
10801         struct rte_cryptodev_sym_capability_idx cap_idx;
10802         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10803         cap_idx.algo.auth = reference->auth_algo;
10804         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10805                         &cap_idx) == NULL)
10806                 return -ENOTSUP;
10807
10808         /* Create session */
10809         retval = create_auth_cipher_session(ut_params,
10810                         ts_params->valid_devs[0],
10811                         reference,
10812                         RTE_CRYPTO_AUTH_OP_VERIFY,
10813                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
10814         if (retval < 0)
10815                 return retval;
10816
10817         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10818         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10819                         "Failed to allocate input buffer in mempool");
10820
10821         /* clear mbuf payload */
10822         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10823                         rte_pktmbuf_tailroom(ut_params->ibuf));
10824
10825         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10826                         reference->plaintext.len);
10827         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10828         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
10829
10830         debug_hexdump(stdout, "plaintext:", plaintext,
10831                 reference->plaintext.len);
10832
10833         /* Create operation */
10834         retval = create_auth_verify_GMAC_operation(ts_params,
10835                         ut_params,
10836                         reference);
10837
10838         if (retval < 0)
10839                 return retval;
10840
10841         if (data_corrupted)
10842                 data_corruption(plaintext);
10843         else
10844                 tag_corruption(plaintext, reference->aad.len);
10845
10846         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
10847                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10848                         ut_params->op);
10849                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
10850                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10851                         "authentication not failed");
10852         } else {
10853                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10854                         ut_params->op);
10855                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
10856         }
10857
10858         return 0;
10859 }
10860
10861 static int
10862 test_authenticated_decryption_fail_when_corruption(
10863                 struct crypto_testsuite_params *ts_params,
10864                 struct crypto_unittest_params *ut_params,
10865                 const struct test_crypto_vector *reference,
10866                 unsigned int data_corrupted)
10867 {
10868         int retval;
10869
10870         uint8_t *ciphertext;
10871
10872         /* Verify the capabilities */
10873         struct rte_cryptodev_sym_capability_idx cap_idx;
10874         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10875         cap_idx.algo.auth = reference->auth_algo;
10876         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10877                         &cap_idx) == NULL)
10878                 return -ENOTSUP;
10879         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10880         cap_idx.algo.cipher = reference->crypto_algo;
10881         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10882                         &cap_idx) == NULL)
10883                 return -ENOTSUP;
10884
10885         /* Create session */
10886         retval = create_auth_cipher_session(ut_params,
10887                         ts_params->valid_devs[0],
10888                         reference,
10889                         RTE_CRYPTO_AUTH_OP_VERIFY,
10890                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
10891         if (retval < 0)
10892                 return retval;
10893
10894         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10895         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10896                         "Failed to allocate input buffer in mempool");
10897
10898         /* clear mbuf payload */
10899         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10900                         rte_pktmbuf_tailroom(ut_params->ibuf));
10901
10902         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10903                         reference->ciphertext.len);
10904         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
10905         memcpy(ciphertext, reference->ciphertext.data,
10906                         reference->ciphertext.len);
10907
10908         /* Create operation */
10909         retval = create_cipher_auth_verify_operation(ts_params,
10910                         ut_params,
10911                         reference);
10912
10913         if (retval < 0)
10914                 return retval;
10915
10916         if (data_corrupted)
10917                 data_corruption(ciphertext);
10918         else
10919                 tag_corruption(ciphertext, reference->ciphertext.len);
10920
10921         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
10922                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10923                         ut_params->op);
10924                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
10925                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10926                         "authentication not failed");
10927         } else {
10928                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
10929                         ut_params->op);
10930                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
10931         }
10932
10933         return 0;
10934 }
10935
10936 static int
10937 test_authenticated_encryt_with_esn(
10938                 struct crypto_testsuite_params *ts_params,
10939                 struct crypto_unittest_params *ut_params,
10940                 const struct test_crypto_vector *reference)
10941 {
10942         int retval;
10943
10944         uint8_t *authciphertext, *plaintext, *auth_tag;
10945         uint16_t plaintext_pad_len;
10946         uint8_t cipher_key[reference->cipher_key.len + 1];
10947         uint8_t auth_key[reference->auth_key.len + 1];
10948
10949         /* Verify the capabilities */
10950         struct rte_cryptodev_sym_capability_idx cap_idx;
10951         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10952         cap_idx.algo.auth = reference->auth_algo;
10953         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10954                         &cap_idx) == NULL)
10955                 return -ENOTSUP;
10956         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10957         cap_idx.algo.cipher = reference->crypto_algo;
10958         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10959                         &cap_idx) == NULL)
10960                 return -ENOTSUP;
10961
10962         /* Create session */
10963         memcpy(cipher_key, reference->cipher_key.data,
10964                         reference->cipher_key.len);
10965         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
10966
10967         /* Setup Cipher Parameters */
10968         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10969         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
10970         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10971         ut_params->cipher_xform.cipher.key.data = cipher_key;
10972         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
10973         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10974         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
10975
10976         ut_params->cipher_xform.next = &ut_params->auth_xform;
10977
10978         /* Setup Authentication Parameters */
10979         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10980         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10981         ut_params->auth_xform.auth.algo = reference->auth_algo;
10982         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
10983         ut_params->auth_xform.auth.key.data = auth_key;
10984         ut_params->auth_xform.auth.digest_length = reference->digest.len;
10985         ut_params->auth_xform.next = NULL;
10986
10987         /* Create Crypto session*/
10988         ut_params->sess = rte_cryptodev_sym_session_create(
10989                         ts_params->session_mpool);
10990
10991         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10992                                 ut_params->sess,
10993                                 &ut_params->cipher_xform,
10994                                 ts_params->session_priv_mpool);
10995
10996         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10997
10998         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10999         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11000                         "Failed to allocate input buffer in mempool");
11001
11002         /* clear mbuf payload */
11003         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11004                         rte_pktmbuf_tailroom(ut_params->ibuf));
11005
11006         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11007                         reference->plaintext.len);
11008         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11009         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
11010
11011         /* Create operation */
11012         retval = create_cipher_auth_operation(ts_params,
11013                         ut_params,
11014                         reference, 0);
11015
11016         if (retval < 0)
11017                 return retval;
11018
11019         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11020                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11021                         ut_params->op);
11022         else
11023                 ut_params->op = process_crypto_request(
11024                         ts_params->valid_devs[0], ut_params->op);
11025
11026         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
11027
11028         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11029                         "crypto op processing failed");
11030
11031         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
11032
11033         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
11034                         ut_params->op->sym->auth.data.offset);
11035         auth_tag = authciphertext + plaintext_pad_len;
11036         debug_hexdump(stdout, "ciphertext:", authciphertext,
11037                         reference->ciphertext.len);
11038         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
11039
11040         /* Validate obuf */
11041         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11042                         authciphertext,
11043                         reference->ciphertext.data,
11044                         reference->ciphertext.len,
11045                         "Ciphertext data not as expected");
11046
11047         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11048                         auth_tag,
11049                         reference->digest.data,
11050                         reference->digest.len,
11051                         "Generated digest not as expected");
11052
11053         return TEST_SUCCESS;
11054
11055 }
11056
11057 static int
11058 test_authenticated_decrypt_with_esn(
11059                 struct crypto_testsuite_params *ts_params,
11060                 struct crypto_unittest_params *ut_params,
11061                 const struct test_crypto_vector *reference)
11062 {
11063         int retval;
11064
11065         uint8_t *ciphertext;
11066         uint8_t cipher_key[reference->cipher_key.len + 1];
11067         uint8_t auth_key[reference->auth_key.len + 1];
11068
11069         /* Verify the capabilities */
11070         struct rte_cryptodev_sym_capability_idx cap_idx;
11071         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11072         cap_idx.algo.auth = reference->auth_algo;
11073         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11074                         &cap_idx) == NULL)
11075                 return -ENOTSUP;
11076         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11077         cap_idx.algo.cipher = reference->crypto_algo;
11078         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11079                         &cap_idx) == NULL)
11080                 return -ENOTSUP;
11081
11082         /* Create session */
11083         memcpy(cipher_key, reference->cipher_key.data,
11084                         reference->cipher_key.len);
11085         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
11086
11087         /* Setup Authentication Parameters */
11088         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11089         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
11090         ut_params->auth_xform.auth.algo = reference->auth_algo;
11091         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
11092         ut_params->auth_xform.auth.key.data = auth_key;
11093         ut_params->auth_xform.auth.digest_length = reference->digest.len;
11094         ut_params->auth_xform.next = &ut_params->cipher_xform;
11095
11096         /* Setup Cipher Parameters */
11097         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11098         ut_params->cipher_xform.next = NULL;
11099         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
11100         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
11101         ut_params->cipher_xform.cipher.key.data = cipher_key;
11102         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
11103         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11104         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
11105
11106         /* Create Crypto session*/
11107         ut_params->sess = rte_cryptodev_sym_session_create(
11108                         ts_params->session_mpool);
11109
11110         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11111                                 ut_params->sess,
11112                                 &ut_params->auth_xform,
11113                                 ts_params->session_priv_mpool);
11114
11115         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11116
11117         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11118         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11119                         "Failed to allocate input buffer in mempool");
11120
11121         /* clear mbuf payload */
11122         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11123                         rte_pktmbuf_tailroom(ut_params->ibuf));
11124
11125         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11126                         reference->ciphertext.len);
11127         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
11128         memcpy(ciphertext, reference->ciphertext.data,
11129                         reference->ciphertext.len);
11130
11131         /* Create operation */
11132         retval = create_cipher_auth_verify_operation(ts_params,
11133                         ut_params,
11134                         reference);
11135
11136         if (retval < 0)
11137                 return retval;
11138
11139         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11140                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11141                         ut_params->op);
11142         else
11143                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
11144                         ut_params->op);
11145
11146         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
11147         TEST_ASSERT_EQUAL(ut_params->op->status,
11148                         RTE_CRYPTO_OP_STATUS_SUCCESS,
11149                         "crypto op processing passed");
11150
11151         ut_params->obuf = ut_params->op->sym->m_src;
11152         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
11153
11154         return 0;
11155 }
11156
11157 static int
11158 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
11159                 const struct aead_test_data *tdata,
11160                 void *digest_mem, uint64_t digest_phys)
11161 {
11162         struct crypto_testsuite_params *ts_params = &testsuite_params;
11163         struct crypto_unittest_params *ut_params = &unittest_params;
11164
11165         const unsigned int auth_tag_len = tdata->auth_tag.len;
11166         const unsigned int iv_len = tdata->iv.len;
11167         unsigned int aad_len = tdata->aad.len;
11168         unsigned int aad_len_pad = 0;
11169
11170         /* Generate Crypto op data structure */
11171         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11172                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11173         TEST_ASSERT_NOT_NULL(ut_params->op,
11174                 "Failed to allocate symmetric crypto operation struct");
11175
11176         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11177
11178         sym_op->aead.digest.data = digest_mem;
11179
11180         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
11181                         "no room to append digest");
11182
11183         sym_op->aead.digest.phys_addr = digest_phys;
11184
11185         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
11186                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
11187                                 auth_tag_len);
11188                 debug_hexdump(stdout, "digest:",
11189                                 sym_op->aead.digest.data,
11190                                 auth_tag_len);
11191         }
11192
11193         /* Append aad data */
11194         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
11195                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11196                                 uint8_t *, IV_OFFSET);
11197
11198                 /* Copy IV 1 byte after the IV pointer, according to the API */
11199                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
11200
11201                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
11202
11203                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
11204                                 ut_params->ibuf, aad_len);
11205                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
11206                                 "no room to prepend aad");
11207                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
11208                                 ut_params->ibuf);
11209
11210                 memset(sym_op->aead.aad.data, 0, aad_len);
11211                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
11212                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
11213
11214                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
11215                 debug_hexdump(stdout, "aad:",
11216                                 sym_op->aead.aad.data, aad_len);
11217         } else {
11218                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11219                                 uint8_t *, IV_OFFSET);
11220
11221                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
11222
11223                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
11224
11225                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
11226                                 ut_params->ibuf, aad_len_pad);
11227                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
11228                                 "no room to prepend aad");
11229                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
11230                                 ut_params->ibuf);
11231
11232                 memset(sym_op->aead.aad.data, 0, aad_len);
11233                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
11234
11235                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
11236                 debug_hexdump(stdout, "aad:",
11237                                 sym_op->aead.aad.data, aad_len);
11238         }
11239
11240         sym_op->aead.data.length = tdata->plaintext.len;
11241         sym_op->aead.data.offset = aad_len_pad;
11242
11243         return 0;
11244 }
11245
11246 #define SGL_MAX_NO      16
11247
11248 static int
11249 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
11250                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
11251 {
11252         struct crypto_testsuite_params *ts_params = &testsuite_params;
11253         struct crypto_unittest_params *ut_params = &unittest_params;
11254         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
11255         int retval;
11256         int to_trn = 0;
11257         int to_trn_tbl[SGL_MAX_NO];
11258         int segs = 1;
11259         unsigned int trn_data = 0;
11260         uint8_t *plaintext, *ciphertext, *auth_tag;
11261         struct rte_cryptodev_info dev_info;
11262
11263         /* Verify the capabilities */
11264         struct rte_cryptodev_sym_capability_idx cap_idx;
11265         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11266         cap_idx.algo.aead = tdata->algo;
11267         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11268                         &cap_idx) == NULL)
11269                 return -ENOTSUP;
11270
11271         /* OOP not supported with CPU crypto */
11272         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11273                 return -ENOTSUP;
11274
11275         /* Detailed check for the particular SGL support flag */
11276         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11277         if (!oop) {
11278                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
11279                 if (sgl_in && (!(dev_info.feature_flags &
11280                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
11281                         return -ENOTSUP;
11282         } else {
11283                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
11284                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
11285                                 tdata->plaintext.len;
11286                 if (sgl_in && !sgl_out) {
11287                         if (!(dev_info.feature_flags &
11288                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
11289                                 return -ENOTSUP;
11290                 } else if (!sgl_in && sgl_out) {
11291                         if (!(dev_info.feature_flags &
11292                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
11293                                 return -ENOTSUP;
11294                 } else if (sgl_in && sgl_out) {
11295                         if (!(dev_info.feature_flags &
11296                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
11297                                 return -ENOTSUP;
11298                 }
11299         }
11300
11301         if (fragsz > tdata->plaintext.len)
11302                 fragsz = tdata->plaintext.len;
11303
11304         uint16_t plaintext_len = fragsz;
11305         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
11306
11307         if (fragsz_oop > tdata->plaintext.len)
11308                 frag_size_oop = tdata->plaintext.len;
11309
11310         int ecx = 0;
11311         void *digest_mem = NULL;
11312
11313         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
11314
11315         if (tdata->plaintext.len % fragsz != 0) {
11316                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
11317                         return 1;
11318         }       else {
11319                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
11320                         return 1;
11321         }
11322
11323         /*
11324          * For out-op-place we need to alloc another mbuf
11325          */
11326         if (oop) {
11327                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11328                 rte_pktmbuf_append(ut_params->obuf,
11329                                 frag_size_oop + prepend_len);
11330                 buf_oop = ut_params->obuf;
11331         }
11332
11333         /* Create AEAD session */
11334         retval = create_aead_session(ts_params->valid_devs[0],
11335                         tdata->algo,
11336                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
11337                         tdata->key.data, tdata->key.len,
11338                         tdata->aad.len, tdata->auth_tag.len,
11339                         tdata->iv.len);
11340         if (retval < 0)
11341                 return retval;
11342
11343         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11344
11345         /* clear mbuf payload */
11346         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11347                         rte_pktmbuf_tailroom(ut_params->ibuf));
11348
11349         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11350                         plaintext_len);
11351
11352         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
11353
11354         trn_data += plaintext_len;
11355
11356         buf = ut_params->ibuf;
11357
11358         /*
11359          * Loop until no more fragments
11360          */
11361
11362         while (trn_data < tdata->plaintext.len) {
11363                 ++segs;
11364                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
11365                                 (tdata->plaintext.len - trn_data) : fragsz;
11366
11367                 to_trn_tbl[ecx++] = to_trn;
11368
11369                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11370                 buf = buf->next;
11371
11372                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
11373                                 rte_pktmbuf_tailroom(buf));
11374
11375                 /* OOP */
11376                 if (oop && !fragsz_oop) {
11377                         buf_last_oop = buf_oop->next =
11378                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
11379                         buf_oop = buf_oop->next;
11380                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
11381                                         0, rte_pktmbuf_tailroom(buf_oop));
11382                         rte_pktmbuf_append(buf_oop, to_trn);
11383                 }
11384
11385                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
11386                                 to_trn);
11387
11388                 memcpy(plaintext, tdata->plaintext.data + trn_data,
11389                                 to_trn);
11390                 trn_data += to_trn;
11391                 if (trn_data  == tdata->plaintext.len) {
11392                         if (oop) {
11393                                 if (!fragsz_oop)
11394                                         digest_mem = rte_pktmbuf_append(buf_oop,
11395                                                 tdata->auth_tag.len);
11396                         } else
11397                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
11398                                         tdata->auth_tag.len);
11399                 }
11400         }
11401
11402         uint64_t digest_phys = 0;
11403
11404         ut_params->ibuf->nb_segs = segs;
11405
11406         segs = 1;
11407         if (fragsz_oop && oop) {
11408                 to_trn = 0;
11409                 ecx = 0;
11410
11411                 if (frag_size_oop == tdata->plaintext.len) {
11412                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
11413                                 tdata->auth_tag.len);
11414
11415                         digest_phys = rte_pktmbuf_iova_offset(
11416                                         ut_params->obuf,
11417                                         tdata->plaintext.len + prepend_len);
11418                 }
11419
11420                 trn_data = frag_size_oop;
11421                 while (trn_data < tdata->plaintext.len) {
11422                         ++segs;
11423                         to_trn =
11424                                 (tdata->plaintext.len - trn_data <
11425                                                 frag_size_oop) ?
11426                                 (tdata->plaintext.len - trn_data) :
11427                                                 frag_size_oop;
11428
11429                         to_trn_tbl[ecx++] = to_trn;
11430
11431                         buf_last_oop = buf_oop->next =
11432                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
11433                         buf_oop = buf_oop->next;
11434                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
11435                                         0, rte_pktmbuf_tailroom(buf_oop));
11436                         rte_pktmbuf_append(buf_oop, to_trn);
11437
11438                         trn_data += to_trn;
11439
11440                         if (trn_data  == tdata->plaintext.len) {
11441                                 digest_mem = rte_pktmbuf_append(buf_oop,
11442                                         tdata->auth_tag.len);
11443                         }
11444                 }
11445
11446                 ut_params->obuf->nb_segs = segs;
11447         }
11448
11449         /*
11450          * Place digest at the end of the last buffer
11451          */
11452         if (!digest_phys)
11453                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11454         if (oop && buf_last_oop)
11455                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
11456
11457         if (!digest_mem && !oop) {
11458                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11459                                 + tdata->auth_tag.len);
11460                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11461                                 tdata->plaintext.len);
11462         }
11463
11464         /* Create AEAD operation */
11465         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
11466                         tdata, digest_mem, digest_phys);
11467
11468         if (retval < 0)
11469                 return retval;
11470
11471         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11472
11473         ut_params->op->sym->m_src = ut_params->ibuf;
11474         if (oop)
11475                 ut_params->op->sym->m_dst = ut_params->obuf;
11476
11477         /* Process crypto operation */
11478         if (oop == IN_PLACE &&
11479                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11480                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
11481         else
11482                 TEST_ASSERT_NOT_NULL(
11483                         process_crypto_request(ts_params->valid_devs[0],
11484                         ut_params->op), "failed to process sym crypto op");
11485
11486         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11487                         "crypto op processing failed");
11488
11489
11490         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
11491                         uint8_t *, prepend_len);
11492         if (oop) {
11493                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11494                                 uint8_t *, prepend_len);
11495         }
11496
11497         if (fragsz_oop)
11498                 fragsz = fragsz_oop;
11499
11500         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11501                         ciphertext,
11502                         tdata->ciphertext.data,
11503                         fragsz,
11504                         "Ciphertext data not as expected");
11505
11506         buf = ut_params->op->sym->m_src->next;
11507         if (oop)
11508                 buf = ut_params->op->sym->m_dst->next;
11509
11510         unsigned int off = fragsz;
11511
11512         ecx = 0;
11513         while (buf) {
11514                 ciphertext = rte_pktmbuf_mtod(buf,
11515                                 uint8_t *);
11516
11517                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
11518                                 ciphertext,
11519                                 tdata->ciphertext.data + off,
11520                                 to_trn_tbl[ecx],
11521                                 "Ciphertext data not as expected");
11522
11523                 off += to_trn_tbl[ecx++];
11524                 buf = buf->next;
11525         }
11526
11527         auth_tag = digest_mem;
11528         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11529                         auth_tag,
11530                         tdata->auth_tag.data,
11531                         tdata->auth_tag.len,
11532                         "Generated auth tag not as expected");
11533
11534         return 0;
11535 }
11536
11537 static int
11538 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
11539 {
11540         return test_authenticated_encryption_SGL(
11541                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
11542 }
11543
11544 static int
11545 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
11546 {
11547         return test_authenticated_encryption_SGL(
11548                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
11549 }
11550
11551 static int
11552 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
11553 {
11554         return test_authenticated_encryption_SGL(
11555                         &gcm_test_case_8, OUT_OF_PLACE, 400,
11556                         gcm_test_case_8.plaintext.len);
11557 }
11558
11559 static int
11560 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
11561 {
11562         /* This test is not for OPENSSL PMD */
11563         if (gbl_driver_id == rte_cryptodev_driver_id_get(
11564                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
11565                 return -ENOTSUP;
11566
11567         return test_authenticated_encryption_SGL(
11568                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
11569 }
11570
11571 static int
11572 test_authentication_verify_fail_when_data_corrupted(
11573                 struct crypto_testsuite_params *ts_params,
11574                 struct crypto_unittest_params *ut_params,
11575                 const struct test_crypto_vector *reference)
11576 {
11577         return test_authentication_verify_fail_when_data_corruption(
11578                         ts_params, ut_params, reference, 1);
11579 }
11580
11581 static int
11582 test_authentication_verify_fail_when_tag_corrupted(
11583                 struct crypto_testsuite_params *ts_params,
11584                 struct crypto_unittest_params *ut_params,
11585                 const struct test_crypto_vector *reference)
11586 {
11587         return test_authentication_verify_fail_when_data_corruption(
11588                         ts_params, ut_params, reference, 0);
11589 }
11590
11591 static int
11592 test_authentication_verify_GMAC_fail_when_data_corrupted(
11593                 struct crypto_testsuite_params *ts_params,
11594                 struct crypto_unittest_params *ut_params,
11595                 const struct test_crypto_vector *reference)
11596 {
11597         return test_authentication_verify_GMAC_fail_when_corruption(
11598                         ts_params, ut_params, reference, 1);
11599 }
11600
11601 static int
11602 test_authentication_verify_GMAC_fail_when_tag_corrupted(
11603                 struct crypto_testsuite_params *ts_params,
11604                 struct crypto_unittest_params *ut_params,
11605                 const struct test_crypto_vector *reference)
11606 {
11607         return test_authentication_verify_GMAC_fail_when_corruption(
11608                         ts_params, ut_params, reference, 0);
11609 }
11610
11611 static int
11612 test_authenticated_decryption_fail_when_data_corrupted(
11613                 struct crypto_testsuite_params *ts_params,
11614                 struct crypto_unittest_params *ut_params,
11615                 const struct test_crypto_vector *reference)
11616 {
11617         return test_authenticated_decryption_fail_when_corruption(
11618                         ts_params, ut_params, reference, 1);
11619 }
11620
11621 static int
11622 test_authenticated_decryption_fail_when_tag_corrupted(
11623                 struct crypto_testsuite_params *ts_params,
11624                 struct crypto_unittest_params *ut_params,
11625                 const struct test_crypto_vector *reference)
11626 {
11627         return test_authenticated_decryption_fail_when_corruption(
11628                         ts_params, ut_params, reference, 0);
11629 }
11630
11631 static int
11632 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
11633 {
11634         return test_authentication_verify_fail_when_data_corrupted(
11635                         &testsuite_params, &unittest_params,
11636                         &hmac_sha1_test_crypto_vector);
11637 }
11638
11639 static int
11640 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
11641 {
11642         return test_authentication_verify_fail_when_tag_corrupted(
11643                         &testsuite_params, &unittest_params,
11644                         &hmac_sha1_test_crypto_vector);
11645 }
11646
11647 static int
11648 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
11649 {
11650         return test_authentication_verify_GMAC_fail_when_data_corrupted(
11651                         &testsuite_params, &unittest_params,
11652                         &aes128_gmac_test_vector);
11653 }
11654
11655 static int
11656 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
11657 {
11658         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
11659                         &testsuite_params, &unittest_params,
11660                         &aes128_gmac_test_vector);
11661 }
11662
11663 static int
11664 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
11665 {
11666         return test_authenticated_decryption_fail_when_data_corrupted(
11667                         &testsuite_params,
11668                         &unittest_params,
11669                         &aes128cbc_hmac_sha1_test_vector);
11670 }
11671
11672 static int
11673 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
11674 {
11675         return test_authenticated_decryption_fail_when_tag_corrupted(
11676                         &testsuite_params,
11677                         &unittest_params,
11678                         &aes128cbc_hmac_sha1_test_vector);
11679 }
11680
11681 static int
11682 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
11683 {
11684         return test_authenticated_encryt_with_esn(
11685                         &testsuite_params,
11686                         &unittest_params,
11687                         &aes128cbc_hmac_sha1_aad_test_vector);
11688 }
11689
11690 static int
11691 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
11692 {
11693         return test_authenticated_decrypt_with_esn(
11694                         &testsuite_params,
11695                         &unittest_params,
11696                         &aes128cbc_hmac_sha1_aad_test_vector);
11697 }
11698
11699 static int
11700 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
11701 {
11702         return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
11703 }
11704
11705 static int
11706 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
11707 {
11708         return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
11709 }
11710
11711 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
11712
11713 /* global AESNI worker IDs for the scheduler test */
11714 uint8_t aesni_ids[2];
11715
11716 static int
11717 test_scheduler_attach_slave_op(void)
11718 {
11719         struct crypto_testsuite_params *ts_params = &testsuite_params;
11720         uint8_t sched_id = ts_params->valid_devs[0];
11721         uint32_t nb_devs, i, nb_devs_attached = 0;
11722         int ret;
11723         char vdev_name[32];
11724
11725         /* create 2 AESNI_MB if necessary */
11726         nb_devs = rte_cryptodev_device_count_by_driver(
11727                         rte_cryptodev_driver_id_get(
11728                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
11729         if (nb_devs < 2) {
11730                 for (i = nb_devs; i < 2; i++) {
11731                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
11732                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
11733                                         i);
11734                         ret = rte_vdev_init(vdev_name, NULL);
11735
11736                         TEST_ASSERT(ret == 0,
11737                                 "Failed to create instance %u of"
11738                                 " pmd : %s",
11739                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
11740                 }
11741         }
11742
11743         /* attach 2 AESNI_MB cdevs */
11744         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
11745                         i++) {
11746                 struct rte_cryptodev_info info;
11747                 unsigned int session_size;
11748
11749                 rte_cryptodev_info_get(i, &info);
11750                 if (info.driver_id != rte_cryptodev_driver_id_get(
11751                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
11752                         continue;
11753
11754                 session_size = rte_cryptodev_sym_get_private_session_size(i);
11755                 /*
11756                  * Create the session mempool again, since now there are new devices
11757                  * to use the mempool.
11758                  */
11759                 if (ts_params->session_mpool) {
11760                         rte_mempool_free(ts_params->session_mpool);
11761                         ts_params->session_mpool = NULL;
11762                 }
11763                 if (ts_params->session_priv_mpool) {
11764                         rte_mempool_free(ts_params->session_priv_mpool);
11765                         ts_params->session_priv_mpool = NULL;
11766                 }
11767
11768                 if (info.sym.max_nb_sessions != 0 &&
11769                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
11770                         RTE_LOG(ERR, USER1,
11771                                         "Device does not support "
11772                                         "at least %u sessions\n",
11773                                         MAX_NB_SESSIONS);
11774                         return TEST_FAILED;
11775                 }
11776                 /*
11777                  * Create mempool with maximum number of sessions,
11778                  * to include the session headers
11779                  */
11780                 if (ts_params->session_mpool == NULL) {
11781                         ts_params->session_mpool =
11782                                 rte_cryptodev_sym_session_pool_create(
11783                                                 "test_sess_mp",
11784                                                 MAX_NB_SESSIONS, 0, 0, 0,
11785                                                 SOCKET_ID_ANY);
11786                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
11787                                         "session mempool allocation failed");
11788                 }
11789
11790                 /*
11791                  * Create mempool with maximum number of sessions,
11792                  * to include device specific session private data
11793                  */
11794                 if (ts_params->session_priv_mpool == NULL) {
11795                         ts_params->session_priv_mpool = rte_mempool_create(
11796                                         "test_sess_mp_priv",
11797                                         MAX_NB_SESSIONS,
11798                                         session_size,
11799                                         0, 0, NULL, NULL, NULL,
11800                                         NULL, SOCKET_ID_ANY,
11801                                         0);
11802
11803                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
11804                                         "session mempool allocation failed");
11805                 }
11806
11807                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
11808                 ts_params->qp_conf.mp_session_private =
11809                                 ts_params->session_priv_mpool;
11810
11811                 ret = rte_cryptodev_scheduler_worker_attach(sched_id,
11812                                 (uint8_t)i);
11813
11814                 TEST_ASSERT(ret == 0,
11815                         "Failed to attach device %u of pmd : %s", i,
11816                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
11817
11818                 aesni_ids[nb_devs_attached] = (uint8_t)i;
11819
11820                 nb_devs_attached++;
11821         }
11822
11823         return 0;
11824 }
11825
11826 static int
11827 test_scheduler_detach_slave_op(void)
11828 {
11829         struct crypto_testsuite_params *ts_params = &testsuite_params;
11830         uint8_t sched_id = ts_params->valid_devs[0];
11831         uint32_t i;
11832         int ret;
11833
11834         for (i = 0; i < 2; i++) {
11835                 ret = rte_cryptodev_scheduler_worker_detach(sched_id,
11836                                 aesni_ids[i]);
11837                 TEST_ASSERT(ret == 0,
11838                         "Failed to detach device %u", aesni_ids[i]);
11839         }
11840
11841         return 0;
11842 }
11843
11844 static int
11845 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
11846 {
11847         struct crypto_testsuite_params *ts_params = &testsuite_params;
11848         uint8_t sched_id = ts_params->valid_devs[0];
11849         /* set mode */
11850         return rte_cryptodev_scheduler_mode_set(sched_id,
11851                 scheduler_mode);
11852 }
11853
11854 static int
11855 test_scheduler_mode_roundrobin_op(void)
11856 {
11857         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
11858                         0, "Failed to set roundrobin mode");
11859         return 0;
11860
11861 }
11862
11863 static int
11864 test_scheduler_mode_multicore_op(void)
11865 {
11866         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
11867                         0, "Failed to set multicore mode");
11868
11869         return 0;
11870 }
11871
11872 static int
11873 test_scheduler_mode_failover_op(void)
11874 {
11875         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
11876                         0, "Failed to set failover mode");
11877
11878         return 0;
11879 }
11880
11881 static int
11882 test_scheduler_mode_pkt_size_distr_op(void)
11883 {
11884         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
11885                         0, "Failed to set pktsize mode");
11886
11887         return 0;
11888 }
11889
11890 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
11891         .suite_name = "Crypto Device Scheduler Unit Test Suite",
11892         .setup = testsuite_setup,
11893         .teardown = testsuite_teardown,
11894         .unit_test_cases = {
11895                 /* Multi Core */
11896                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11897                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op),
11898                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11899                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11900                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11901                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11902
11903                 /* Round Robin */
11904                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11905                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op),
11906                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11907                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11908                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11909                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11910
11911                 /* Fail over */
11912                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11913                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op),
11914                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11915                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11916                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11917                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11918
11919                 /* PKT SIZE */
11920                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
11921                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op),
11922                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11923                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11924                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11925                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
11926
11927                 TEST_CASES_END() /**< NULL terminate unit test array */
11928         }
11929 };
11930
11931 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
11932
11933 static struct unit_test_suite cryptodev_testsuite  = {
11934         .suite_name = "Crypto Unit Test Suite",
11935         .setup = testsuite_setup,
11936         .teardown = testsuite_teardown,
11937         .unit_test_cases = {
11938                 TEST_CASE_ST(ut_setup, ut_teardown,
11939                                 test_device_configure_invalid_dev_id),
11940                 TEST_CASE_ST(ut_setup, ut_teardown,
11941                                 test_queue_pair_descriptor_setup),
11942                 TEST_CASE_ST(ut_setup, ut_teardown,
11943                                 test_device_configure_invalid_queue_pair_ids),
11944
11945                 TEST_CASE_ST(ut_setup, ut_teardown,
11946                                 test_multi_session),
11947                 TEST_CASE_ST(ut_setup, ut_teardown,
11948                                 test_multi_session_random_usage),
11949
11950                 TEST_CASE_ST(ut_setup, ut_teardown,
11951                         test_null_invalid_operation),
11952                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
11953
11954                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
11955                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
11956                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
11957                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
11958                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all),
11959                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all),
11960                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all),
11961                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
11962                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
11963
11964                 /** AES CCM Authenticated Encryption 128 bits key */
11965                 TEST_CASE_ST(ut_setup, ut_teardown,
11966                         test_AES_CCM_authenticated_encryption_test_case_128_1),
11967                 TEST_CASE_ST(ut_setup, ut_teardown,
11968                         test_AES_CCM_authenticated_encryption_test_case_128_2),
11969                 TEST_CASE_ST(ut_setup, ut_teardown,
11970                         test_AES_CCM_authenticated_encryption_test_case_128_3),
11971
11972                 /** AES CCM Authenticated Decryption 128 bits key*/
11973                 TEST_CASE_ST(ut_setup, ut_teardown,
11974                         test_AES_CCM_authenticated_decryption_test_case_128_1),
11975                 TEST_CASE_ST(ut_setup, ut_teardown,
11976                         test_AES_CCM_authenticated_decryption_test_case_128_2),
11977                 TEST_CASE_ST(ut_setup, ut_teardown,
11978                         test_AES_CCM_authenticated_decryption_test_case_128_3),
11979
11980                 /** AES CCM Authenticated Encryption 192 bits key */
11981                 TEST_CASE_ST(ut_setup, ut_teardown,
11982                         test_AES_CCM_authenticated_encryption_test_case_192_1),
11983                 TEST_CASE_ST(ut_setup, ut_teardown,
11984                         test_AES_CCM_authenticated_encryption_test_case_192_2),
11985                 TEST_CASE_ST(ut_setup, ut_teardown,
11986                         test_AES_CCM_authenticated_encryption_test_case_192_3),
11987
11988                 /** AES CCM Authenticated Decryption 192 bits key*/
11989                 TEST_CASE_ST(ut_setup, ut_teardown,
11990                         test_AES_CCM_authenticated_decryption_test_case_192_1),
11991                 TEST_CASE_ST(ut_setup, ut_teardown,
11992                         test_AES_CCM_authenticated_decryption_test_case_192_2),
11993                 TEST_CASE_ST(ut_setup, ut_teardown,
11994                         test_AES_CCM_authenticated_decryption_test_case_192_3),
11995
11996                 /** AES CCM Authenticated Encryption 256 bits key */
11997                 TEST_CASE_ST(ut_setup, ut_teardown,
11998                         test_AES_CCM_authenticated_encryption_test_case_256_1),
11999                 TEST_CASE_ST(ut_setup, ut_teardown,
12000                         test_AES_CCM_authenticated_encryption_test_case_256_2),
12001                 TEST_CASE_ST(ut_setup, ut_teardown,
12002                         test_AES_CCM_authenticated_encryption_test_case_256_3),
12003
12004                 /** AES CCM Authenticated Decryption 256 bits key*/
12005                 TEST_CASE_ST(ut_setup, ut_teardown,
12006                         test_AES_CCM_authenticated_decryption_test_case_256_1),
12007                 TEST_CASE_ST(ut_setup, ut_teardown,
12008                         test_AES_CCM_authenticated_decryption_test_case_256_2),
12009                 TEST_CASE_ST(ut_setup, ut_teardown,
12010                         test_AES_CCM_authenticated_decryption_test_case_256_3),
12011
12012                 /** AES GCM Authenticated Encryption */
12013                 TEST_CASE_ST(ut_setup, ut_teardown,
12014                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
12015                 TEST_CASE_ST(ut_setup, ut_teardown,
12016                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
12017                 TEST_CASE_ST(ut_setup, ut_teardown,
12018                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
12019                 TEST_CASE_ST(ut_setup, ut_teardown,
12020                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
12021                 TEST_CASE_ST(ut_setup, ut_teardown,
12022                         test_AES_GCM_authenticated_encryption_test_case_1),
12023                 TEST_CASE_ST(ut_setup, ut_teardown,
12024                         test_AES_GCM_authenticated_encryption_test_case_2),
12025                 TEST_CASE_ST(ut_setup, ut_teardown,
12026                         test_AES_GCM_authenticated_encryption_test_case_3),
12027                 TEST_CASE_ST(ut_setup, ut_teardown,
12028                         test_AES_GCM_authenticated_encryption_test_case_4),
12029                 TEST_CASE_ST(ut_setup, ut_teardown,
12030                         test_AES_GCM_authenticated_encryption_test_case_5),
12031                 TEST_CASE_ST(ut_setup, ut_teardown,
12032                         test_AES_GCM_authenticated_encryption_test_case_6),
12033                 TEST_CASE_ST(ut_setup, ut_teardown,
12034                         test_AES_GCM_authenticated_encryption_test_case_7),
12035                 TEST_CASE_ST(ut_setup, ut_teardown,
12036                         test_AES_GCM_authenticated_encryption_test_case_8),
12037                 TEST_CASE_ST(ut_setup, ut_teardown,
12038                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
12039
12040                 /** AES GCM Authenticated Decryption */
12041                 TEST_CASE_ST(ut_setup, ut_teardown,
12042                         test_AES_GCM_authenticated_decryption_test_case_1),
12043                 TEST_CASE_ST(ut_setup, ut_teardown,
12044                         test_AES_GCM_authenticated_decryption_test_case_2),
12045                 TEST_CASE_ST(ut_setup, ut_teardown,
12046                         test_AES_GCM_authenticated_decryption_test_case_3),
12047                 TEST_CASE_ST(ut_setup, ut_teardown,
12048                         test_AES_GCM_authenticated_decryption_test_case_4),
12049                 TEST_CASE_ST(ut_setup, ut_teardown,
12050                         test_AES_GCM_authenticated_decryption_test_case_5),
12051                 TEST_CASE_ST(ut_setup, ut_teardown,
12052                         test_AES_GCM_authenticated_decryption_test_case_6),
12053                 TEST_CASE_ST(ut_setup, ut_teardown,
12054                         test_AES_GCM_authenticated_decryption_test_case_7),
12055                 TEST_CASE_ST(ut_setup, ut_teardown,
12056                         test_AES_GCM_authenticated_decryption_test_case_8),
12057                 TEST_CASE_ST(ut_setup, ut_teardown,
12058                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
12059
12060                 /** AES GCM Authenticated Encryption 192 bits key */
12061                 TEST_CASE_ST(ut_setup, ut_teardown,
12062                         test_AES_GCM_auth_encryption_test_case_192_1),
12063                 TEST_CASE_ST(ut_setup, ut_teardown,
12064                         test_AES_GCM_auth_encryption_test_case_192_2),
12065                 TEST_CASE_ST(ut_setup, ut_teardown,
12066                         test_AES_GCM_auth_encryption_test_case_192_3),
12067                 TEST_CASE_ST(ut_setup, ut_teardown,
12068                         test_AES_GCM_auth_encryption_test_case_192_4),
12069                 TEST_CASE_ST(ut_setup, ut_teardown,
12070                         test_AES_GCM_auth_encryption_test_case_192_5),
12071                 TEST_CASE_ST(ut_setup, ut_teardown,
12072                         test_AES_GCM_auth_encryption_test_case_192_6),
12073                 TEST_CASE_ST(ut_setup, ut_teardown,
12074                         test_AES_GCM_auth_encryption_test_case_192_7),
12075
12076                 /** AES GCM Authenticated Decryption 192 bits key */
12077                 TEST_CASE_ST(ut_setup, ut_teardown,
12078                         test_AES_GCM_auth_decryption_test_case_192_1),
12079                 TEST_CASE_ST(ut_setup, ut_teardown,
12080                         test_AES_GCM_auth_decryption_test_case_192_2),
12081                 TEST_CASE_ST(ut_setup, ut_teardown,
12082                         test_AES_GCM_auth_decryption_test_case_192_3),
12083                 TEST_CASE_ST(ut_setup, ut_teardown,
12084                         test_AES_GCM_auth_decryption_test_case_192_4),
12085                 TEST_CASE_ST(ut_setup, ut_teardown,
12086                         test_AES_GCM_auth_decryption_test_case_192_5),
12087                 TEST_CASE_ST(ut_setup, ut_teardown,
12088                         test_AES_GCM_auth_decryption_test_case_192_6),
12089                 TEST_CASE_ST(ut_setup, ut_teardown,
12090                         test_AES_GCM_auth_decryption_test_case_192_7),
12091
12092                 /** AES GCM Authenticated Encryption 256 bits key */
12093                 TEST_CASE_ST(ut_setup, ut_teardown,
12094                         test_AES_GCM_auth_encryption_test_case_256_1),
12095                 TEST_CASE_ST(ut_setup, ut_teardown,
12096                         test_AES_GCM_auth_encryption_test_case_256_2),
12097                 TEST_CASE_ST(ut_setup, ut_teardown,
12098                         test_AES_GCM_auth_encryption_test_case_256_3),
12099                 TEST_CASE_ST(ut_setup, ut_teardown,
12100                         test_AES_GCM_auth_encryption_test_case_256_4),
12101                 TEST_CASE_ST(ut_setup, ut_teardown,
12102                         test_AES_GCM_auth_encryption_test_case_256_5),
12103                 TEST_CASE_ST(ut_setup, ut_teardown,
12104                         test_AES_GCM_auth_encryption_test_case_256_6),
12105                 TEST_CASE_ST(ut_setup, ut_teardown,
12106                         test_AES_GCM_auth_encryption_test_case_256_7),
12107
12108                 /** AES GCM Authenticated Decryption 256 bits key */
12109                 TEST_CASE_ST(ut_setup, ut_teardown,
12110                         test_AES_GCM_auth_decryption_test_case_256_1),
12111                 TEST_CASE_ST(ut_setup, ut_teardown,
12112                         test_AES_GCM_auth_decryption_test_case_256_2),
12113                 TEST_CASE_ST(ut_setup, ut_teardown,
12114                         test_AES_GCM_auth_decryption_test_case_256_3),
12115                 TEST_CASE_ST(ut_setup, ut_teardown,
12116                         test_AES_GCM_auth_decryption_test_case_256_4),
12117                 TEST_CASE_ST(ut_setup, ut_teardown,
12118                         test_AES_GCM_auth_decryption_test_case_256_5),
12119                 TEST_CASE_ST(ut_setup, ut_teardown,
12120                         test_AES_GCM_auth_decryption_test_case_256_6),
12121                 TEST_CASE_ST(ut_setup, ut_teardown,
12122                         test_AES_GCM_auth_decryption_test_case_256_7),
12123
12124                 /** AES GCM Authenticated Encryption big aad size */
12125                 TEST_CASE_ST(ut_setup, ut_teardown,
12126                         test_AES_GCM_auth_encryption_test_case_aad_1),
12127                 TEST_CASE_ST(ut_setup, ut_teardown,
12128                         test_AES_GCM_auth_encryption_test_case_aad_2),
12129
12130                 /** AES GCM Authenticated Decryption big aad size */
12131                 TEST_CASE_ST(ut_setup, ut_teardown,
12132                         test_AES_GCM_auth_decryption_test_case_aad_1),
12133                 TEST_CASE_ST(ut_setup, ut_teardown,
12134                         test_AES_GCM_auth_decryption_test_case_aad_2),
12135
12136                 /** Out of place tests */
12137                 TEST_CASE_ST(ut_setup, ut_teardown,
12138                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
12139                 TEST_CASE_ST(ut_setup, ut_teardown,
12140                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
12141
12142                 /** Session-less tests */
12143                 TEST_CASE_ST(ut_setup, ut_teardown,
12144                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
12145                 TEST_CASE_ST(ut_setup, ut_teardown,
12146                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
12147
12148                 /** AES GMAC Authentication */
12149                 TEST_CASE_ST(ut_setup, ut_teardown,
12150                         test_AES_GMAC_authentication_test_case_1),
12151                 TEST_CASE_ST(ut_setup, ut_teardown,
12152                         test_AES_GMAC_authentication_verify_test_case_1),
12153                 TEST_CASE_ST(ut_setup, ut_teardown,
12154                         test_AES_GMAC_authentication_test_case_2),
12155                 TEST_CASE_ST(ut_setup, ut_teardown,
12156                         test_AES_GMAC_authentication_verify_test_case_2),
12157                 TEST_CASE_ST(ut_setup, ut_teardown,
12158                         test_AES_GMAC_authentication_test_case_3),
12159                 TEST_CASE_ST(ut_setup, ut_teardown,
12160                         test_AES_GMAC_authentication_verify_test_case_3),
12161                 TEST_CASE_ST(ut_setup, ut_teardown,
12162                         test_AES_GMAC_authentication_test_case_4),
12163                 TEST_CASE_ST(ut_setup, ut_teardown,
12164                         test_AES_GMAC_authentication_verify_test_case_4),
12165                 /** Chacha20-Poly1305 */
12166                 TEST_CASE_ST(ut_setup, ut_teardown,
12167                         test_chacha20_poly1305_encrypt_test_case_rfc8439),
12168                 TEST_CASE_ST(ut_setup, ut_teardown,
12169                         test_chacha20_poly1305_decrypt_test_case_rfc8439),
12170                 /** SNOW 3G encrypt only (UEA2) */
12171                 TEST_CASE_ST(ut_setup, ut_teardown,
12172                         test_snow3g_encryption_test_case_1),
12173                 TEST_CASE_ST(ut_setup, ut_teardown,
12174                         test_snow3g_encryption_test_case_2),
12175                 TEST_CASE_ST(ut_setup, ut_teardown,
12176                         test_snow3g_encryption_test_case_3),
12177                 TEST_CASE_ST(ut_setup, ut_teardown,
12178                         test_snow3g_encryption_test_case_4),
12179                 TEST_CASE_ST(ut_setup, ut_teardown,
12180                         test_snow3g_encryption_test_case_5),
12181
12182                 TEST_CASE_ST(ut_setup, ut_teardown,
12183                         test_snow3g_encryption_test_case_1_oop),
12184                 TEST_CASE_ST(ut_setup, ut_teardown,
12185                         test_snow3g_encryption_test_case_1_oop_sgl),
12186                 TEST_CASE_ST(ut_setup, ut_teardown,
12187                         test_snow3g_encryption_test_case_1_offset_oop),
12188                 TEST_CASE_ST(ut_setup, ut_teardown,
12189                         test_snow3g_decryption_test_case_1_oop),
12190
12191                 /** SNOW 3G generate auth, then encrypt (UEA2) */
12192                 TEST_CASE_ST(ut_setup, ut_teardown,
12193                         test_snow3g_auth_cipher_test_case_1),
12194                 TEST_CASE_ST(ut_setup, ut_teardown,
12195                         test_snow3g_auth_cipher_test_case_2),
12196                 TEST_CASE_ST(ut_setup, ut_teardown,
12197                         test_snow3g_auth_cipher_test_case_2_oop),
12198                 TEST_CASE_ST(ut_setup, ut_teardown,
12199                         test_snow3g_auth_cipher_part_digest_enc),
12200                 TEST_CASE_ST(ut_setup, ut_teardown,
12201                         test_snow3g_auth_cipher_part_digest_enc_oop),
12202                 TEST_CASE_ST(ut_setup, ut_teardown,
12203                         test_snow3g_auth_cipher_test_case_3_sgl),
12204                 TEST_CASE_ST(ut_setup, ut_teardown,
12205                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
12206                 TEST_CASE_ST(ut_setup, ut_teardown,
12207                         test_snow3g_auth_cipher_part_digest_enc_sgl),
12208                 TEST_CASE_ST(ut_setup, ut_teardown,
12209                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
12210
12211                 /** SNOW 3G decrypt (UEA2), then verify auth */
12212                 TEST_CASE_ST(ut_setup, ut_teardown,
12213                         test_snow3g_auth_cipher_verify_test_case_1),
12214                 TEST_CASE_ST(ut_setup, ut_teardown,
12215                         test_snow3g_auth_cipher_verify_test_case_2),
12216                 TEST_CASE_ST(ut_setup, ut_teardown,
12217                         test_snow3g_auth_cipher_verify_test_case_2_oop),
12218                 TEST_CASE_ST(ut_setup, ut_teardown,
12219                         test_snow3g_auth_cipher_verify_part_digest_enc),
12220                 TEST_CASE_ST(ut_setup, ut_teardown,
12221                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
12222                 TEST_CASE_ST(ut_setup, ut_teardown,
12223                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
12224                 TEST_CASE_ST(ut_setup, ut_teardown,
12225                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
12226                 TEST_CASE_ST(ut_setup, ut_teardown,
12227                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
12228                 TEST_CASE_ST(ut_setup, ut_teardown,
12229                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
12230
12231                 /** SNOW 3G decrypt only (UEA2) */
12232                 TEST_CASE_ST(ut_setup, ut_teardown,
12233                         test_snow3g_decryption_test_case_1),
12234                 TEST_CASE_ST(ut_setup, ut_teardown,
12235                         test_snow3g_decryption_test_case_2),
12236                 TEST_CASE_ST(ut_setup, ut_teardown,
12237                         test_snow3g_decryption_test_case_3),
12238                 TEST_CASE_ST(ut_setup, ut_teardown,
12239                         test_snow3g_decryption_test_case_4),
12240                 TEST_CASE_ST(ut_setup, ut_teardown,
12241                         test_snow3g_decryption_test_case_5),
12242                 TEST_CASE_ST(ut_setup, ut_teardown,
12243                         test_snow3g_decryption_with_digest_test_case_1),
12244                 TEST_CASE_ST(ut_setup, ut_teardown,
12245                         test_snow3g_hash_generate_test_case_1),
12246                 TEST_CASE_ST(ut_setup, ut_teardown,
12247                         test_snow3g_hash_generate_test_case_2),
12248                 TEST_CASE_ST(ut_setup, ut_teardown,
12249                         test_snow3g_hash_generate_test_case_3),
12250                 /* Tests with buffers which length is not byte-aligned */
12251                 TEST_CASE_ST(ut_setup, ut_teardown,
12252                         test_snow3g_hash_generate_test_case_4),
12253                 TEST_CASE_ST(ut_setup, ut_teardown,
12254                         test_snow3g_hash_generate_test_case_5),
12255                 TEST_CASE_ST(ut_setup, ut_teardown,
12256                         test_snow3g_hash_generate_test_case_6),
12257                 TEST_CASE_ST(ut_setup, ut_teardown,
12258                         test_snow3g_hash_verify_test_case_1),
12259                 TEST_CASE_ST(ut_setup, ut_teardown,
12260                         test_snow3g_hash_verify_test_case_2),
12261                 TEST_CASE_ST(ut_setup, ut_teardown,
12262                         test_snow3g_hash_verify_test_case_3),
12263                 /* Tests with buffers which length is not byte-aligned */
12264                 TEST_CASE_ST(ut_setup, ut_teardown,
12265                         test_snow3g_hash_verify_test_case_4),
12266                 TEST_CASE_ST(ut_setup, ut_teardown,
12267                         test_snow3g_hash_verify_test_case_5),
12268                 TEST_CASE_ST(ut_setup, ut_teardown,
12269                         test_snow3g_hash_verify_test_case_6),
12270                 TEST_CASE_ST(ut_setup, ut_teardown,
12271                         test_snow3g_cipher_auth_test_case_1),
12272                 TEST_CASE_ST(ut_setup, ut_teardown,
12273                         test_snow3g_auth_cipher_with_digest_test_case_1),
12274
12275                 /** ZUC encrypt only (EEA3) */
12276                 TEST_CASE_ST(ut_setup, ut_teardown,
12277                         test_zuc_encryption_test_case_1),
12278                 TEST_CASE_ST(ut_setup, ut_teardown,
12279                         test_zuc_encryption_test_case_2),
12280                 TEST_CASE_ST(ut_setup, ut_teardown,
12281                         test_zuc_encryption_test_case_3),
12282                 TEST_CASE_ST(ut_setup, ut_teardown,
12283                         test_zuc_encryption_test_case_4),
12284                 TEST_CASE_ST(ut_setup, ut_teardown,
12285                         test_zuc_encryption_test_case_5),
12286                 TEST_CASE_ST(ut_setup, ut_teardown,
12287                         test_zuc_encryption_test_case_6_sgl),
12288
12289                 /** ZUC authenticate (EIA3) */
12290                 TEST_CASE_ST(ut_setup, ut_teardown,
12291                         test_zuc_hash_generate_test_case_1),
12292                 TEST_CASE_ST(ut_setup, ut_teardown,
12293                         test_zuc_hash_generate_test_case_2),
12294                 TEST_CASE_ST(ut_setup, ut_teardown,
12295                         test_zuc_hash_generate_test_case_3),
12296                 TEST_CASE_ST(ut_setup, ut_teardown,
12297                         test_zuc_hash_generate_test_case_4),
12298                 TEST_CASE_ST(ut_setup, ut_teardown,
12299                         test_zuc_hash_generate_test_case_5),
12300                 TEST_CASE_ST(ut_setup, ut_teardown,
12301                         test_zuc_hash_generate_test_case_6),
12302                 TEST_CASE_ST(ut_setup, ut_teardown,
12303                         test_zuc_hash_generate_test_case_7),
12304                 TEST_CASE_ST(ut_setup, ut_teardown,
12305                         test_zuc_hash_generate_test_case_8),
12306
12307                 /** ZUC alg-chain (EEA3/EIA3) */
12308                 TEST_CASE_ST(ut_setup, ut_teardown,
12309                         test_zuc_cipher_auth_test_case_1),
12310                 TEST_CASE_ST(ut_setup, ut_teardown,
12311                         test_zuc_cipher_auth_test_case_2),
12312
12313                 /** ZUC generate auth, then encrypt (EEA3) */
12314                 TEST_CASE_ST(ut_setup, ut_teardown,
12315                         test_zuc_auth_cipher_test_case_1),
12316                 TEST_CASE_ST(ut_setup, ut_teardown,
12317                         test_zuc_auth_cipher_test_case_1_oop),
12318                 TEST_CASE_ST(ut_setup, ut_teardown,
12319                         test_zuc_auth_cipher_test_case_1_sgl),
12320                 TEST_CASE_ST(ut_setup, ut_teardown,
12321                         test_zuc_auth_cipher_test_case_1_oop_sgl),
12322
12323                 /** ZUC decrypt (EEA3), then verify auth */
12324                 TEST_CASE_ST(ut_setup, ut_teardown,
12325                         test_zuc_auth_cipher_verify_test_case_1),
12326                 TEST_CASE_ST(ut_setup, ut_teardown,
12327                         test_zuc_auth_cipher_verify_test_case_1_oop),
12328                 TEST_CASE_ST(ut_setup, ut_teardown,
12329                         test_zuc_auth_cipher_verify_test_case_1_sgl),
12330                 TEST_CASE_ST(ut_setup, ut_teardown,
12331                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
12332
12333                 /** HMAC_MD5 Authentication */
12334                 TEST_CASE_ST(ut_setup, ut_teardown,
12335                         test_MD5_HMAC_generate_case_1),
12336                 TEST_CASE_ST(ut_setup, ut_teardown,
12337                         test_MD5_HMAC_verify_case_1),
12338                 TEST_CASE_ST(ut_setup, ut_teardown,
12339                         test_MD5_HMAC_generate_case_2),
12340                 TEST_CASE_ST(ut_setup, ut_teardown,
12341                         test_MD5_HMAC_verify_case_2),
12342
12343                 /** KASUMI hash only (UIA1) */
12344                 TEST_CASE_ST(ut_setup, ut_teardown,
12345                         test_kasumi_hash_generate_test_case_1),
12346                 TEST_CASE_ST(ut_setup, ut_teardown,
12347                         test_kasumi_hash_generate_test_case_2),
12348                 TEST_CASE_ST(ut_setup, ut_teardown,
12349                         test_kasumi_hash_generate_test_case_3),
12350                 TEST_CASE_ST(ut_setup, ut_teardown,
12351                         test_kasumi_hash_generate_test_case_4),
12352                 TEST_CASE_ST(ut_setup, ut_teardown,
12353                         test_kasumi_hash_generate_test_case_5),
12354                 TEST_CASE_ST(ut_setup, ut_teardown,
12355                         test_kasumi_hash_generate_test_case_6),
12356
12357                 TEST_CASE_ST(ut_setup, ut_teardown,
12358                         test_kasumi_hash_verify_test_case_1),
12359                 TEST_CASE_ST(ut_setup, ut_teardown,
12360                         test_kasumi_hash_verify_test_case_2),
12361                 TEST_CASE_ST(ut_setup, ut_teardown,
12362                         test_kasumi_hash_verify_test_case_3),
12363                 TEST_CASE_ST(ut_setup, ut_teardown,
12364                         test_kasumi_hash_verify_test_case_4),
12365                 TEST_CASE_ST(ut_setup, ut_teardown,
12366                         test_kasumi_hash_verify_test_case_5),
12367
12368                 /** KASUMI encrypt only (UEA1) */
12369                 TEST_CASE_ST(ut_setup, ut_teardown,
12370                         test_kasumi_encryption_test_case_1),
12371                 TEST_CASE_ST(ut_setup, ut_teardown,
12372                         test_kasumi_encryption_test_case_1_sgl),
12373                 TEST_CASE_ST(ut_setup, ut_teardown,
12374                         test_kasumi_encryption_test_case_1_oop),
12375                 TEST_CASE_ST(ut_setup, ut_teardown,
12376                         test_kasumi_encryption_test_case_1_oop_sgl),
12377                 TEST_CASE_ST(ut_setup, ut_teardown,
12378                         test_kasumi_encryption_test_case_2),
12379                 TEST_CASE_ST(ut_setup, ut_teardown,
12380                         test_kasumi_encryption_test_case_3),
12381                 TEST_CASE_ST(ut_setup, ut_teardown,
12382                         test_kasumi_encryption_test_case_4),
12383                 TEST_CASE_ST(ut_setup, ut_teardown,
12384                         test_kasumi_encryption_test_case_5),
12385
12386                 /** KASUMI decrypt only (UEA1) */
12387                 TEST_CASE_ST(ut_setup, ut_teardown,
12388                         test_kasumi_decryption_test_case_1),
12389                 TEST_CASE_ST(ut_setup, ut_teardown,
12390                         test_kasumi_decryption_test_case_2),
12391                 TEST_CASE_ST(ut_setup, ut_teardown,
12392                         test_kasumi_decryption_test_case_3),
12393                 TEST_CASE_ST(ut_setup, ut_teardown,
12394                         test_kasumi_decryption_test_case_4),
12395                 TEST_CASE_ST(ut_setup, ut_teardown,
12396                         test_kasumi_decryption_test_case_5),
12397                 TEST_CASE_ST(ut_setup, ut_teardown,
12398                         test_kasumi_decryption_test_case_1_oop),
12399
12400                 TEST_CASE_ST(ut_setup, ut_teardown,
12401                         test_kasumi_cipher_auth_test_case_1),
12402
12403                 /** KASUMI generate auth, then encrypt (F8) */
12404                 TEST_CASE_ST(ut_setup, ut_teardown,
12405                         test_kasumi_auth_cipher_test_case_1),
12406                 TEST_CASE_ST(ut_setup, ut_teardown,
12407                         test_kasumi_auth_cipher_test_case_2),
12408                 TEST_CASE_ST(ut_setup, ut_teardown,
12409                         test_kasumi_auth_cipher_test_case_2_oop),
12410                 TEST_CASE_ST(ut_setup, ut_teardown,
12411                         test_kasumi_auth_cipher_test_case_2_sgl),
12412                 TEST_CASE_ST(ut_setup, ut_teardown,
12413                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
12414
12415                 /** KASUMI decrypt (F8), then verify auth */
12416                 TEST_CASE_ST(ut_setup, ut_teardown,
12417                         test_kasumi_auth_cipher_verify_test_case_1),
12418                 TEST_CASE_ST(ut_setup, ut_teardown,
12419                         test_kasumi_auth_cipher_verify_test_case_2),
12420                 TEST_CASE_ST(ut_setup, ut_teardown,
12421                         test_kasumi_auth_cipher_verify_test_case_2_oop),
12422                 TEST_CASE_ST(ut_setup, ut_teardown,
12423                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
12424                 TEST_CASE_ST(ut_setup, ut_teardown,
12425                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
12426
12427                 /** ESN Testcase */
12428                 TEST_CASE_ST(ut_setup, ut_teardown,
12429                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
12430                 TEST_CASE_ST(ut_setup, ut_teardown,
12431                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
12432
12433                 /** Negative tests */
12434                 TEST_CASE_ST(ut_setup, ut_teardown,
12435                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12436                 TEST_CASE_ST(ut_setup, ut_teardown,
12437                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12438                 TEST_CASE_ST(ut_setup, ut_teardown,
12439                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
12440                 TEST_CASE_ST(ut_setup, ut_teardown,
12441                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
12442                 TEST_CASE_ST(ut_setup, ut_teardown,
12443                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
12444                 TEST_CASE_ST(ut_setup, ut_teardown,
12445                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
12446                 TEST_CASE_ST(ut_setup, ut_teardown,
12447                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
12448                 TEST_CASE_ST(ut_setup, ut_teardown,
12449                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
12450                 TEST_CASE_ST(ut_setup, ut_teardown,
12451                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
12452                 TEST_CASE_ST(ut_setup, ut_teardown,
12453                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
12454                 TEST_CASE_ST(ut_setup, ut_teardown,
12455                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
12456                 TEST_CASE_ST(ut_setup, ut_teardown,
12457                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
12458                 TEST_CASE_ST(ut_setup, ut_teardown,
12459                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
12460                 TEST_CASE_ST(ut_setup, ut_teardown,
12461                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
12462                 TEST_CASE_ST(ut_setup, ut_teardown,
12463                         authentication_verify_AES128_GMAC_fail_data_corrupt),
12464                 TEST_CASE_ST(ut_setup, ut_teardown,
12465                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
12466                 TEST_CASE_ST(ut_setup, ut_teardown,
12467                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12468                 TEST_CASE_ST(ut_setup, ut_teardown,
12469                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12470
12471                 /** Mixed CIPHER + HASH algorithms */
12472                 /** AUTH AES CMAC + CIPHER AES CTR */
12473                 TEST_CASE_ST(ut_setup, ut_teardown,
12474                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
12475                 TEST_CASE_ST(ut_setup, ut_teardown,
12476                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
12477                 TEST_CASE_ST(ut_setup, ut_teardown,
12478                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
12479                 TEST_CASE_ST(ut_setup, ut_teardown,
12480                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
12481                 TEST_CASE_ST(ut_setup, ut_teardown,
12482                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
12483                 TEST_CASE_ST(ut_setup, ut_teardown,
12484                        test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
12485                 TEST_CASE_ST(ut_setup, ut_teardown,
12486                        test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
12487                 TEST_CASE_ST(ut_setup, ut_teardown,
12488                    test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
12489
12490                 /** AUTH ZUC + CIPHER SNOW3G */
12491                 TEST_CASE_ST(ut_setup, ut_teardown,
12492                         test_auth_zuc_cipher_snow_test_case_1),
12493                 TEST_CASE_ST(ut_setup, ut_teardown,
12494                         test_verify_auth_zuc_cipher_snow_test_case_1),
12495                 /** AUTH AES CMAC + CIPHER SNOW3G */
12496                 TEST_CASE_ST(ut_setup, ut_teardown,
12497                         test_auth_aes_cmac_cipher_snow_test_case_1),
12498                 TEST_CASE_ST(ut_setup, ut_teardown,
12499                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
12500                 /** AUTH ZUC + CIPHER AES CTR */
12501                 TEST_CASE_ST(ut_setup, ut_teardown,
12502                         test_auth_zuc_cipher_aes_ctr_test_case_1),
12503                 TEST_CASE_ST(ut_setup, ut_teardown,
12504                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
12505                 /** AUTH SNOW3G + CIPHER AES CTR */
12506                 TEST_CASE_ST(ut_setup, ut_teardown,
12507                         test_auth_snow_cipher_aes_ctr_test_case_1),
12508                 TEST_CASE_ST(ut_setup, ut_teardown,
12509                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
12510                 /** AUTH SNOW3G + CIPHER ZUC */
12511                 TEST_CASE_ST(ut_setup, ut_teardown,
12512                         test_auth_snow_cipher_zuc_test_case_1),
12513                 TEST_CASE_ST(ut_setup, ut_teardown,
12514                         test_verify_auth_snow_cipher_zuc_test_case_1),
12515                 /** AUTH AES CMAC + CIPHER ZUC */
12516                 TEST_CASE_ST(ut_setup, ut_teardown,
12517                         test_auth_aes_cmac_cipher_zuc_test_case_1),
12518                 TEST_CASE_ST(ut_setup, ut_teardown,
12519                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
12520
12521                 /** AUTH NULL + CIPHER SNOW3G */
12522                 TEST_CASE_ST(ut_setup, ut_teardown,
12523                         test_auth_null_cipher_snow_test_case_1),
12524                 TEST_CASE_ST(ut_setup, ut_teardown,
12525                         test_verify_auth_null_cipher_snow_test_case_1),
12526                 /** AUTH NULL + CIPHER ZUC */
12527                 TEST_CASE_ST(ut_setup, ut_teardown,
12528                         test_auth_null_cipher_zuc_test_case_1),
12529                 TEST_CASE_ST(ut_setup, ut_teardown,
12530                         test_verify_auth_null_cipher_zuc_test_case_1),
12531                 /** AUTH SNOW3G + CIPHER NULL */
12532                 TEST_CASE_ST(ut_setup, ut_teardown,
12533                         test_auth_snow_cipher_null_test_case_1),
12534                 TEST_CASE_ST(ut_setup, ut_teardown,
12535                         test_verify_auth_snow_cipher_null_test_case_1),
12536                 /** AUTH ZUC + CIPHER NULL */
12537                 TEST_CASE_ST(ut_setup, ut_teardown,
12538                         test_auth_zuc_cipher_null_test_case_1),
12539                 TEST_CASE_ST(ut_setup, ut_teardown,
12540                         test_verify_auth_zuc_cipher_null_test_case_1),
12541                 /** AUTH NULL + CIPHER AES CTR */
12542                 TEST_CASE_ST(ut_setup, ut_teardown,
12543                         test_auth_null_cipher_aes_ctr_test_case_1),
12544                 TEST_CASE_ST(ut_setup, ut_teardown,
12545                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
12546                 /** AUTH AES CMAC + CIPHER NULL */
12547                 TEST_CASE_ST(ut_setup, ut_teardown,
12548                         test_auth_aes_cmac_cipher_null_test_case_1),
12549                 TEST_CASE_ST(ut_setup, ut_teardown,
12550                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
12551
12552 #ifdef RTE_LIBRTE_SECURITY
12553                 TEST_CASE_ST(ut_setup_security, ut_teardown,
12554                         test_PDCP_PROTO_all),
12555                 TEST_CASE_ST(ut_setup_security, ut_teardown,
12556                         test_DOCSIS_PROTO_all),
12557 #endif
12558                 TEST_CASES_END() /**< NULL terminate unit test array */
12559         }
12560 };
12561
12562 static struct unit_test_suite cryptodev_virtio_testsuite = {
12563         .suite_name = "Crypto VIRTIO Unit Test Suite",
12564         .setup = testsuite_setup,
12565         .teardown = testsuite_teardown,
12566         .unit_test_cases = {
12567                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12568
12569                 TEST_CASES_END() /**< NULL terminate unit test array */
12570         }
12571 };
12572
12573 static struct unit_test_suite cryptodev_caam_jr_testsuite  = {
12574         .suite_name = "Crypto CAAM JR Unit Test Suite",
12575         .setup = testsuite_setup,
12576         .teardown = testsuite_teardown,
12577         .unit_test_cases = {
12578                 TEST_CASE_ST(ut_setup, ut_teardown,
12579                              test_device_configure_invalid_dev_id),
12580                 TEST_CASE_ST(ut_setup, ut_teardown,
12581                              test_multi_session),
12582
12583                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12584                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12585                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12586                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12587                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12588
12589                 TEST_CASES_END() /**< NULL terminate unit test array */
12590         }
12591 };
12592
12593 static struct unit_test_suite cryptodev_armv8_testsuite  = {
12594         .suite_name = "Crypto Device ARMv8 Unit Test Suite",
12595         .setup = testsuite_setup,
12596         .teardown = testsuite_teardown,
12597         .unit_test_cases = {
12598                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12599
12600                 /** Negative tests */
12601                 TEST_CASE_ST(ut_setup, ut_teardown,
12602                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12603                 TEST_CASE_ST(ut_setup, ut_teardown,
12604                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12605
12606                 TEST_CASES_END() /**< NULL terminate unit test array */
12607         }
12608 };
12609
12610 static struct unit_test_suite cryptodev_mrvl_testsuite  = {
12611         .suite_name = "Crypto Device Marvell Component Test Suite",
12612         .setup = testsuite_setup,
12613         .teardown = testsuite_teardown,
12614         .unit_test_cases = {
12615                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
12616                 TEST_CASE_ST(ut_setup, ut_teardown,
12617                                 test_multi_session_random_usage),
12618                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12619                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12620                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12621                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12622                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12623
12624                 /** Negative tests */
12625                 TEST_CASE_ST(ut_setup, ut_teardown,
12626                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12627                 TEST_CASE_ST(ut_setup, ut_teardown,
12628                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12629                 TEST_CASE_ST(ut_setup, ut_teardown,
12630                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12631                 TEST_CASE_ST(ut_setup, ut_teardown,
12632                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12633
12634                 TEST_CASES_END() /**< NULL terminate unit test array */
12635         }
12636 };
12637
12638 static struct unit_test_suite cryptodev_ccp_testsuite  = {
12639         .suite_name = "Crypto Device CCP Unit Test Suite",
12640         .setup = testsuite_setup,
12641         .teardown = testsuite_teardown,
12642         .unit_test_cases = {
12643                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
12644                 TEST_CASE_ST(ut_setup, ut_teardown,
12645                                 test_multi_session_random_usage),
12646                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12647                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12648                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12649                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12650                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12651
12652                 /** Negative tests */
12653                 TEST_CASE_ST(ut_setup, ut_teardown,
12654                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
12655                 TEST_CASE_ST(ut_setup, ut_teardown,
12656                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
12657                 TEST_CASE_ST(ut_setup, ut_teardown,
12658                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
12659                 TEST_CASE_ST(ut_setup, ut_teardown,
12660                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
12661
12662                 TEST_CASES_END() /**< NULL terminate unit test array */
12663         }
12664 };
12665
12666 static int
12667 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
12668 {
12669         gbl_driver_id = rte_cryptodev_driver_id_get(
12670                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
12671
12672         if (gbl_driver_id == -1) {
12673                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
12674                 return TEST_SKIPPED;
12675         }
12676
12677         return unit_test_suite_runner(&cryptodev_testsuite);
12678 }
12679
12680 static int
12681 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
12682 {
12683         gbl_driver_id = rte_cryptodev_driver_id_get(
12684                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
12685
12686         if (gbl_driver_id == -1) {
12687                 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded.\n");
12688                 return TEST_FAILED;
12689         }
12690
12691         return unit_test_suite_runner(&cryptodev_virtio_testsuite);
12692 }
12693
12694 static int
12695 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
12696 {
12697         gbl_driver_id = rte_cryptodev_driver_id_get(
12698                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
12699
12700         if (gbl_driver_id == -1) {
12701                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
12702                 return TEST_SKIPPED;
12703         }
12704
12705         return unit_test_suite_runner(&cryptodev_testsuite);
12706 }
12707
12708 static int
12709 test_cryptodev_cpu_aesni_mb(void)
12710 {
12711         int32_t rc;
12712         enum rte_security_session_action_type at;
12713
12714         gbl_driver_id = rte_cryptodev_driver_id_get(
12715                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
12716
12717         if (gbl_driver_id == -1) {
12718                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
12719                 return TEST_SKIPPED;
12720         }
12721
12722         at = gbl_action_type;
12723         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
12724         rc = unit_test_suite_runner(&cryptodev_testsuite);
12725         gbl_action_type = at;
12726         return rc;
12727 }
12728
12729 static int
12730 test_cryptodev_openssl(void)
12731 {
12732         gbl_driver_id = rte_cryptodev_driver_id_get(
12733                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
12734
12735         if (gbl_driver_id == -1) {
12736                 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
12737                 return TEST_SKIPPED;
12738         }
12739
12740         return unit_test_suite_runner(&cryptodev_testsuite);
12741 }
12742
12743 static int
12744 test_cryptodev_aesni_gcm(void)
12745 {
12746         gbl_driver_id = rte_cryptodev_driver_id_get(
12747                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
12748
12749         if (gbl_driver_id == -1) {
12750                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n");
12751                 return TEST_SKIPPED;
12752         }
12753
12754         return unit_test_suite_runner(&cryptodev_testsuite);
12755 }
12756
12757 static int
12758 test_cryptodev_cpu_aesni_gcm(void)
12759 {
12760         int32_t rc;
12761         enum rte_security_session_action_type at;
12762
12763         gbl_driver_id = rte_cryptodev_driver_id_get(
12764                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
12765
12766         if (gbl_driver_id == -1) {
12767                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n");
12768                 return TEST_SKIPPED;
12769         }
12770
12771         at = gbl_action_type;
12772         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
12773         rc = unit_test_suite_runner(&cryptodev_testsuite);
12774         gbl_action_type = at;
12775         return rc;
12776 }
12777
12778 static int
12779 test_cryptodev_null(void)
12780 {
12781         gbl_driver_id = rte_cryptodev_driver_id_get(
12782                         RTE_STR(CRYPTODEV_NAME_NULL_PMD));
12783
12784         if (gbl_driver_id == -1) {
12785                 RTE_LOG(ERR, USER1, "NULL PMD must be loaded.\n");
12786                 return TEST_SKIPPED;
12787         }
12788
12789         return unit_test_suite_runner(&cryptodev_testsuite);
12790 }
12791
12792 static int
12793 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
12794 {
12795         gbl_driver_id = rte_cryptodev_driver_id_get(
12796                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
12797
12798         if (gbl_driver_id == -1) {
12799                 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded.\n");
12800                 return TEST_SKIPPED;
12801         }
12802
12803         return unit_test_suite_runner(&cryptodev_testsuite);
12804 }
12805
12806 static int
12807 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
12808 {
12809         gbl_driver_id = rte_cryptodev_driver_id_get(
12810                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
12811
12812         if (gbl_driver_id == -1) {
12813                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n");
12814                 return TEST_SKIPPED;
12815         }
12816
12817         return unit_test_suite_runner(&cryptodev_testsuite);
12818 }
12819
12820 static int
12821 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
12822 {
12823         gbl_driver_id = rte_cryptodev_driver_id_get(
12824                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
12825
12826         if (gbl_driver_id == -1) {
12827                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n");
12828                 return TEST_SKIPPED;
12829         }
12830
12831         return unit_test_suite_runner(&cryptodev_testsuite);
12832 }
12833
12834 static int
12835 test_cryptodev_armv8(void)
12836 {
12837         gbl_driver_id = rte_cryptodev_driver_id_get(
12838                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
12839
12840         if (gbl_driver_id == -1) {
12841                 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded.\n");
12842                 return TEST_SKIPPED;
12843         }
12844
12845         return unit_test_suite_runner(&cryptodev_armv8_testsuite);
12846 }
12847
12848 static int
12849 test_cryptodev_mrvl(void)
12850 {
12851         gbl_driver_id = rte_cryptodev_driver_id_get(
12852                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
12853
12854         if (gbl_driver_id == -1) {
12855                 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded.\n");
12856                 return TEST_SKIPPED;
12857         }
12858
12859         return unit_test_suite_runner(&cryptodev_mrvl_testsuite);
12860 }
12861
12862 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
12863
12864 static int
12865 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
12866 {
12867         gbl_driver_id = rte_cryptodev_driver_id_get(
12868                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
12869
12870         if (gbl_driver_id == -1) {
12871                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
12872                 return TEST_SKIPPED;
12873         }
12874
12875         if (rte_cryptodev_driver_id_get(
12876                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
12877                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
12878                 return TEST_SKIPPED;
12879 }
12880         return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
12881 }
12882
12883 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
12884
12885 #endif
12886
12887 static int
12888 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
12889 {
12890         gbl_driver_id = rte_cryptodev_driver_id_get(
12891                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
12892
12893         if (gbl_driver_id == -1) {
12894                 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded.\n");
12895                 return TEST_SKIPPED;
12896         }
12897
12898         return unit_test_suite_runner(&cryptodev_testsuite);
12899 }
12900
12901 static int
12902 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
12903 {
12904         gbl_driver_id = rte_cryptodev_driver_id_get(
12905                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
12906
12907         if (gbl_driver_id == -1) {
12908                 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded.\n");
12909                 return TEST_SKIPPED;
12910         }
12911
12912         return unit_test_suite_runner(&cryptodev_testsuite);
12913 }
12914
12915 static int
12916 test_cryptodev_ccp(void)
12917 {
12918         gbl_driver_id = rte_cryptodev_driver_id_get(
12919                         RTE_STR(CRYPTODEV_NAME_CCP_PMD));
12920
12921         if (gbl_driver_id == -1) {
12922                 RTE_LOG(ERR, USER1, "CCP PMD must be loaded.\n");
12923                 return TEST_FAILED;
12924         }
12925
12926         return unit_test_suite_runner(&cryptodev_ccp_testsuite);
12927 }
12928
12929 static int
12930 test_cryptodev_octeontx(void)
12931 {
12932         gbl_driver_id = rte_cryptodev_driver_id_get(
12933                         RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
12934         if (gbl_driver_id == -1) {
12935                 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
12936                 return TEST_FAILED;
12937         }
12938         return unit_test_suite_runner(&cryptodev_testsuite);
12939 }
12940
12941 static int
12942 test_cryptodev_octeontx2(void)
12943 {
12944         gbl_driver_id = rte_cryptodev_driver_id_get(
12945                         RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
12946         if (gbl_driver_id == -1) {
12947                 RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded.\n");
12948                 return TEST_FAILED;
12949         }
12950         return unit_test_suite_runner(&cryptodev_testsuite);
12951 }
12952
12953 static int
12954 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/)
12955 {
12956         gbl_driver_id = rte_cryptodev_driver_id_get(
12957                         RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
12958
12959         if (gbl_driver_id == -1) {
12960                 RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded.\n");
12961                 return TEST_FAILED;
12962         }
12963
12964         return unit_test_suite_runner(&cryptodev_caam_jr_testsuite);
12965 }
12966
12967 static int
12968 test_cryptodev_nitrox(void)
12969 {
12970         gbl_driver_id = rte_cryptodev_driver_id_get(
12971                         RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
12972
12973         if (gbl_driver_id == -1) {
12974                 RTE_LOG(ERR, USER1, "NITROX PMD must be loaded.\n");
12975                 return TEST_FAILED;
12976         }
12977
12978         return unit_test_suite_runner(&cryptodev_testsuite);
12979 }
12980
12981 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
12982 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
12983 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
12984         test_cryptodev_cpu_aesni_mb);
12985 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
12986 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
12987 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
12988         test_cryptodev_cpu_aesni_gcm);
12989 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
12990 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
12991 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
12992 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
12993 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
12994 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
12995 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
12996 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
12997 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
12998 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
12999 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
13000 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
13001 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
13002 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);