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