2fa720d7b2e46b7763e756006a37216ee471a0b9
[dpdk.git] / app / test / test_cryptodev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation
3  * Copyright 2020 NXP
4  */
5
6 #include <time.h>
7
8 #include <rte_common.h>
9 #include <rte_hexdump.h>
10 #include <rte_mbuf.h>
11 #include <rte_malloc.h>
12 #include <rte_memcpy.h>
13 #include <rte_pause.h>
14 #include <rte_bus_vdev.h>
15 #include <rte_ether.h>
16
17 #include <rte_crypto.h>
18 #include <rte_cryptodev.h>
19 #include <rte_cryptodev_pmd.h>
20 #include <rte_string_fns.h>
21
22 #ifdef RTE_CRYPTO_SCHEDULER
23 #include <rte_cryptodev_scheduler.h>
24 #include <rte_cryptodev_scheduler_operations.h>
25 #endif
26
27 #include <rte_lcore.h>
28
29 #include "test.h"
30 #include "test_cryptodev.h"
31
32 #include "test_cryptodev_blockcipher.h"
33 #include "test_cryptodev_aes_test_vectors.h"
34 #include "test_cryptodev_des_test_vectors.h"
35 #include "test_cryptodev_hash_test_vectors.h"
36 #include "test_cryptodev_kasumi_test_vectors.h"
37 #include "test_cryptodev_kasumi_hash_test_vectors.h"
38 #include "test_cryptodev_snow3g_test_vectors.h"
39 #include "test_cryptodev_snow3g_hash_test_vectors.h"
40 #include "test_cryptodev_zuc_test_vectors.h"
41 #include "test_cryptodev_aead_test_vectors.h"
42 #include "test_cryptodev_hmac_test_vectors.h"
43 #include "test_cryptodev_mixed_test_vectors.h"
44 #ifdef RTE_LIB_SECURITY
45 #include "test_cryptodev_security_pdcp_test_vectors.h"
46 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
47 #include "test_cryptodev_security_pdcp_test_func.h"
48 #include "test_cryptodev_security_docsis_test_vectors.h"
49
50 #define SDAP_DISABLED   0
51 #define SDAP_ENABLED    1
52 #endif
53
54 #define VDEV_ARGS_SIZE 100
55 #define MAX_NB_SESSIONS 4
56
57 #define MAX_DRV_SERVICE_CTX_SIZE 256
58
59 #define MAX_RAW_DEQUEUE_COUNT   65535
60
61 #define IN_PLACE 0
62 #define OUT_OF_PLACE 1
63
64 #ifndef ARRAY_SIZE
65 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
66 #endif
67
68 static int gbl_driver_id;
69
70 static enum rte_security_session_action_type gbl_action_type =
71         RTE_SECURITY_ACTION_TYPE_NONE;
72
73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
74
75 struct crypto_unittest_params {
76         struct rte_crypto_sym_xform cipher_xform;
77         struct rte_crypto_sym_xform auth_xform;
78         struct rte_crypto_sym_xform aead_xform;
79 #ifdef RTE_LIB_SECURITY
80         struct rte_security_docsis_xform docsis_xform;
81 #endif
82
83         union {
84                 struct rte_cryptodev_sym_session *sess;
85 #ifdef RTE_LIB_SECURITY
86                 struct rte_security_session *sec_session;
87 #endif
88         };
89 #ifdef RTE_LIB_SECURITY
90         enum rte_security_session_action_type type;
91 #endif
92         struct rte_crypto_op *op;
93
94         struct rte_mbuf *obuf, *ibuf;
95
96         uint8_t *digest;
97 };
98
99 #define ALIGN_POW2_ROUNDUP(num, align) \
100         (((num) + (align) - 1) & ~((align) - 1))
101
102 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)  \
103         for (j = 0; j < num_child_ts; index++, j++)                     \
104                 parent_ts.unit_test_suites[index] = child_ts[j]
105
106 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)   \
107         for (j = 0; j < num_blk_types; index++, j++)                            \
108                 parent_ts.unit_test_suites[index] =                             \
109                                 build_blockcipher_test_suite(blk_types[j])
110
111 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)             \
112         for (j = index; j < index + num_blk_types; j++)                         \
113                 free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
114
115 /*
116  * Forward declarations.
117  */
118 static int
119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
120                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
121                 uint8_t *hmac_key);
122
123 static int
124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
125                 struct crypto_unittest_params *ut_params,
126                 struct crypto_testsuite_params *ts_param,
127                 const uint8_t *cipher,
128                 const uint8_t *digest,
129                 const uint8_t *iv);
130
131 static struct rte_mbuf *
132 setup_test_string(struct rte_mempool *mpool,
133                 const char *string, size_t len, uint8_t blocksize)
134 {
135         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
136         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
137
138         if (m) {
139                 char *dst;
140
141                 memset(m->buf_addr, 0, m->buf_len);
142                 dst = rte_pktmbuf_append(m, t_len);
143                 if (!dst) {
144                         rte_pktmbuf_free(m);
145                         return NULL;
146                 }
147                 if (string != NULL)
148                         rte_memcpy(dst, string, t_len);
149                 else
150                         memset(dst, 0, t_len);
151         }
152
153         return m;
154 }
155
156 /* Get number of bytes in X bits (rounding up) */
157 static uint32_t
158 ceil_byte_length(uint32_t num_bits)
159 {
160         if (num_bits % 8)
161                 return ((num_bits >> 3) + 1);
162         else
163                 return (num_bits >> 3);
164 }
165
166 static void
167 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused,
168                 uint8_t is_op_success)
169 {
170         struct rte_crypto_op *op = user_data;
171         op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
172                         RTE_CRYPTO_OP_STATUS_ERROR;
173 }
174
175 void
176 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
177                 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
178                 uint8_t len_in_bits, uint8_t cipher_iv_len)
179 {
180         struct rte_crypto_sym_op *sop = op->sym;
181         struct rte_crypto_op *ret_op = NULL;
182         struct rte_crypto_vec data_vec[UINT8_MAX];
183         struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
184         union rte_crypto_sym_ofs ofs;
185         struct rte_crypto_sym_vec vec;
186         struct rte_crypto_sgl sgl;
187         uint32_t max_len;
188         union rte_cryptodev_session_ctx sess;
189         uint32_t count = 0;
190         struct rte_crypto_raw_dp_ctx *ctx;
191         uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
192                         auth_len = 0;
193         int32_t n;
194         uint32_t n_success;
195         int ctx_service_size;
196         int32_t status = 0;
197         int enqueue_status, dequeue_status;
198
199         ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
200         if (ctx_service_size < 0) {
201                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
202                 return;
203         }
204
205         ctx = malloc(ctx_service_size);
206         if (!ctx) {
207                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
208                 return;
209         }
210
211         /* Both are enums, setting crypto_sess will suit any session type */
212         sess.crypto_sess = op->sym->session;
213
214         if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
215                         op->sess_type, sess, 0) < 0) {
216                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
217                 goto exit;
218         }
219
220         cipher_iv.iova = 0;
221         cipher_iv.va = NULL;
222         aad_auth_iv.iova = 0;
223         aad_auth_iv.va = NULL;
224         digest.iova = 0;
225         digest.va = NULL;
226         sgl.vec = data_vec;
227         vec.num = 1;
228         vec.sgl = &sgl;
229         vec.iv = &cipher_iv;
230         vec.digest = &digest;
231         vec.aad = &aad_auth_iv;
232         vec.status = &status;
233
234         ofs.raw = 0;
235
236         if (is_cipher && is_auth) {
237                 cipher_offset = sop->cipher.data.offset;
238                 cipher_len = sop->cipher.data.length;
239                 auth_offset = sop->auth.data.offset;
240                 auth_len = sop->auth.data.length;
241                 max_len = RTE_MAX(cipher_offset + cipher_len,
242                                 auth_offset + auth_len);
243                 if (len_in_bits) {
244                         max_len = max_len >> 3;
245                         cipher_offset = cipher_offset >> 3;
246                         auth_offset = auth_offset >> 3;
247                         cipher_len = cipher_len >> 3;
248                         auth_len = auth_len >> 3;
249                 }
250                 ofs.ofs.cipher.head = cipher_offset;
251                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
252                 ofs.ofs.auth.head = auth_offset;
253                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
254                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
255                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
256                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
257                                 op, void *, IV_OFFSET + cipher_iv_len);
258                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
259                                 cipher_iv_len);
260                 digest.va = (void *)sop->auth.digest.data;
261                 digest.iova = sop->auth.digest.phys_addr;
262
263         } else if (is_cipher) {
264                 cipher_offset = sop->cipher.data.offset;
265                 cipher_len = sop->cipher.data.length;
266                 max_len = cipher_len + cipher_offset;
267                 if (len_in_bits) {
268                         max_len = max_len >> 3;
269                         cipher_offset = cipher_offset >> 3;
270                         cipher_len = cipher_len >> 3;
271                 }
272                 ofs.ofs.cipher.head = cipher_offset;
273                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
274                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
275                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
276
277         } else if (is_auth) {
278                 auth_offset = sop->auth.data.offset;
279                 auth_len = sop->auth.data.length;
280                 max_len = auth_len + auth_offset;
281                 if (len_in_bits) {
282                         max_len = max_len >> 3;
283                         auth_offset = auth_offset >> 3;
284                         auth_len = auth_len >> 3;
285                 }
286                 ofs.ofs.auth.head = auth_offset;
287                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
288                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
289                                 op, void *, IV_OFFSET + cipher_iv_len);
290                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
291                                 cipher_iv_len);
292                 digest.va = (void *)sop->auth.digest.data;
293                 digest.iova = sop->auth.digest.phys_addr;
294
295         } else { /* aead */
296                 cipher_offset = sop->aead.data.offset;
297                 cipher_len = sop->aead.data.length;
298                 max_len = cipher_len + cipher_offset;
299                 if (len_in_bits) {
300                         max_len = max_len >> 3;
301                         cipher_offset = cipher_offset >> 3;
302                         cipher_len = cipher_len >> 3;
303                 }
304                 ofs.ofs.cipher.head = cipher_offset;
305                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
306                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
307                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
308                 aad_auth_iv.va = (void *)sop->aead.aad.data;
309                 aad_auth_iv.iova = sop->aead.aad.phys_addr;
310                 digest.va = (void *)sop->aead.digest.data;
311                 digest.iova = sop->aead.digest.phys_addr;
312         }
313
314         n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
315                         data_vec, RTE_DIM(data_vec));
316         if (n < 0 || n > sop->m_src->nb_segs) {
317                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
318                 goto exit;
319         }
320
321         sgl.num = n;
322
323         if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
324                         &enqueue_status) < 1) {
325                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
326                 goto exit;
327         }
328
329         if (enqueue_status == 0) {
330                 status = rte_cryptodev_raw_enqueue_done(ctx, 1);
331                 if (status < 0) {
332                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
333                         goto exit;
334                 }
335         } else if (enqueue_status < 0) {
336                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
337                 goto exit;
338         }
339
340         n = n_success = 0;
341         while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
342                 n = rte_cryptodev_raw_dequeue_burst(ctx,
343                         NULL, 1, post_process_raw_dp_op,
344                                 (void **)&ret_op, 0, &n_success,
345                                 &dequeue_status);
346                 if (dequeue_status < 0) {
347                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
348                         goto exit;
349                 }
350                 if (n == 0)
351                         rte_pause();
352         }
353
354         if (n == 1 && dequeue_status == 0) {
355                 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
356                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
357                         goto exit;
358                 }
359         }
360
361         op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
362                         n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
363                                         RTE_CRYPTO_OP_STATUS_SUCCESS;
364
365 exit:
366         free(ctx);
367 }
368
369 static void
370 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
371 {
372         int32_t n, st;
373         struct rte_crypto_sym_op *sop;
374         union rte_crypto_sym_ofs ofs;
375         struct rte_crypto_sgl sgl;
376         struct rte_crypto_sym_vec symvec;
377         struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
378         struct rte_crypto_vec vec[UINT8_MAX];
379
380         sop = op->sym;
381
382         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
383                 sop->aead.data.length, vec, RTE_DIM(vec));
384
385         if (n < 0 || n != sop->m_src->nb_segs) {
386                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
387                 return;
388         }
389
390         sgl.vec = vec;
391         sgl.num = n;
392         symvec.sgl = &sgl;
393         symvec.iv = &iv_ptr;
394         symvec.digest = &digest_ptr;
395         symvec.aad = &aad_ptr;
396         symvec.status = &st;
397         symvec.num = 1;
398
399         /* for CPU crypto the IOVA address is not required */
400         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
401         digest_ptr.va = (void *)sop->aead.digest.data;
402         aad_ptr.va = (void *)sop->aead.aad.data;
403
404         ofs.raw = 0;
405
406         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
407                 &symvec);
408
409         if (n != 1)
410                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
411         else
412                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
413 }
414
415 static void
416 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
417 {
418         int32_t n, st;
419         struct rte_crypto_sym_op *sop;
420         union rte_crypto_sym_ofs ofs;
421         struct rte_crypto_sgl sgl;
422         struct rte_crypto_sym_vec symvec;
423         struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
424         struct rte_crypto_vec vec[UINT8_MAX];
425
426         sop = op->sym;
427
428         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
429                 sop->auth.data.length, vec, RTE_DIM(vec));
430
431         if (n < 0 || n != sop->m_src->nb_segs) {
432                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
433                 return;
434         }
435
436         sgl.vec = vec;
437         sgl.num = n;
438         symvec.sgl = &sgl;
439         symvec.iv = &iv_ptr;
440         symvec.digest = &digest_ptr;
441         symvec.status = &st;
442         symvec.num = 1;
443
444         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
445         digest_ptr.va = (void *)sop->auth.digest.data;
446
447         ofs.raw = 0;
448         ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
449         ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
450                 (sop->cipher.data.offset + sop->cipher.data.length);
451
452         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
453                 &symvec);
454
455         if (n != 1)
456                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
457         else
458                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
459 }
460
461 static struct rte_crypto_op *
462 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
463 {
464
465         RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
466
467         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
468                 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
469                 return NULL;
470         }
471
472         op = NULL;
473
474         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
475                 rte_pause();
476
477         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
478                 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
479                 return NULL;
480         }
481
482         return op;
483 }
484
485 static struct crypto_testsuite_params testsuite_params = { NULL };
486 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
487 static struct crypto_unittest_params unittest_params;
488
489 static int
490 testsuite_setup(void)
491 {
492         struct crypto_testsuite_params *ts_params = &testsuite_params;
493         struct rte_cryptodev_info info;
494         uint32_t i = 0, nb_devs, dev_id;
495         uint16_t qp_id;
496
497         memset(ts_params, 0, sizeof(*ts_params));
498
499         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
500         if (ts_params->mbuf_pool == NULL) {
501                 /* Not already created so create */
502                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
503                                 "CRYPTO_MBUFPOOL",
504                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
505                                 rte_socket_id());
506                 if (ts_params->mbuf_pool == NULL) {
507                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
508                         return TEST_FAILED;
509                 }
510         }
511
512         ts_params->large_mbuf_pool = rte_mempool_lookup(
513                         "CRYPTO_LARGE_MBUFPOOL");
514         if (ts_params->large_mbuf_pool == NULL) {
515                 /* Not already created so create */
516                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
517                                 "CRYPTO_LARGE_MBUFPOOL",
518                                 1, 0, 0, UINT16_MAX,
519                                 rte_socket_id());
520                 if (ts_params->large_mbuf_pool == NULL) {
521                         RTE_LOG(ERR, USER1,
522                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
523                         return TEST_FAILED;
524                 }
525         }
526
527         ts_params->op_mpool = rte_crypto_op_pool_create(
528                         "MBUF_CRYPTO_SYM_OP_POOL",
529                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
530                         NUM_MBUFS, MBUF_CACHE_SIZE,
531                         DEFAULT_NUM_XFORMS *
532                         sizeof(struct rte_crypto_sym_xform) +
533                         MAXIMUM_IV_LENGTH,
534                         rte_socket_id());
535         if (ts_params->op_mpool == NULL) {
536                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
537                 return TEST_FAILED;
538         }
539
540         nb_devs = rte_cryptodev_count();
541         if (nb_devs < 1) {
542                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
543                 return TEST_SKIPPED;
544         }
545
546         if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
547                 RTE_LOG(WARNING, USER1, "No %s devices found?\n",
548                                 rte_cryptodev_driver_name_get(gbl_driver_id));
549                 return TEST_SKIPPED;
550         }
551
552         /* Create list of valid crypto devs */
553         for (i = 0; i < nb_devs; i++) {
554                 rte_cryptodev_info_get(i, &info);
555                 if (info.driver_id == gbl_driver_id)
556                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
557         }
558
559         if (ts_params->valid_dev_count < 1)
560                 return TEST_FAILED;
561
562         /* Set up all the qps on the first of the valid devices found */
563
564         dev_id = ts_params->valid_devs[0];
565
566         rte_cryptodev_info_get(dev_id, &info);
567
568         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
569         ts_params->conf.socket_id = SOCKET_ID_ANY;
570         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
571
572         unsigned int session_size =
573                 rte_cryptodev_sym_get_private_session_size(dev_id);
574
575 #ifdef RTE_LIB_SECURITY
576         unsigned int security_session_size = rte_security_session_get_size(
577                         rte_cryptodev_get_sec_ctx(dev_id));
578
579         if (session_size < security_session_size)
580                 session_size = security_session_size;
581 #endif
582         /*
583          * Create mempool with maximum number of sessions.
584          */
585         if (info.sym.max_nb_sessions != 0 &&
586                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
587                 RTE_LOG(ERR, USER1, "Device does not support "
588                                 "at least %u sessions\n",
589                                 MAX_NB_SESSIONS);
590                 return TEST_FAILED;
591         }
592
593         ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
594                         "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
595                         SOCKET_ID_ANY);
596         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
597                         "session mempool allocation failed");
598
599         ts_params->session_priv_mpool = rte_mempool_create(
600                         "test_sess_mp_priv",
601                         MAX_NB_SESSIONS,
602                         session_size,
603                         0, 0, NULL, NULL, NULL,
604                         NULL, SOCKET_ID_ANY,
605                         0);
606         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
607                         "session mempool allocation failed");
608
609
610
611         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
612                         &ts_params->conf),
613                         "Failed to configure cryptodev %u with %u qps",
614                         dev_id, ts_params->conf.nb_queue_pairs);
615
616         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
617         ts_params->qp_conf.mp_session = ts_params->session_mpool;
618         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
619
620         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
621                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
622                         dev_id, qp_id, &ts_params->qp_conf,
623                         rte_cryptodev_socket_id(dev_id)),
624                         "Failed to setup queue pair %u on cryptodev %u",
625                         qp_id, dev_id);
626         }
627
628         return TEST_SUCCESS;
629 }
630
631 static void
632 testsuite_teardown(void)
633 {
634         struct crypto_testsuite_params *ts_params = &testsuite_params;
635         int res;
636
637         if (ts_params->mbuf_pool != NULL) {
638                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
639                 rte_mempool_avail_count(ts_params->mbuf_pool));
640         }
641
642         if (ts_params->op_mpool != NULL) {
643                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
644                 rte_mempool_avail_count(ts_params->op_mpool));
645         }
646
647         /* Free session mempools */
648         if (ts_params->session_priv_mpool != NULL) {
649                 rte_mempool_free(ts_params->session_priv_mpool);
650                 ts_params->session_priv_mpool = NULL;
651         }
652
653         if (ts_params->session_mpool != NULL) {
654                 rte_mempool_free(ts_params->session_mpool);
655                 ts_params->session_mpool = NULL;
656         }
657
658         res = rte_cryptodev_close(ts_params->valid_devs[0]);
659         if (res)
660                 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
661 }
662
663 static int
664 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
665                 const int *algs, uint16_t num_algs)
666 {
667         uint8_t dev_id = testsuite_params.valid_devs[0];
668         bool some_alg_supported = FALSE;
669         uint16_t i;
670
671         for (i = 0; i < num_algs && !some_alg_supported; i++) {
672                 struct rte_cryptodev_sym_capability_idx alg = {
673                         type, {algs[i]}
674                 };
675                 if (rte_cryptodev_sym_capability_get(dev_id,
676                                 &alg) != NULL)
677                         some_alg_supported = TRUE;
678         }
679         if (!some_alg_supported)
680                 return TEST_SKIPPED;
681
682         return 0;
683 }
684
685 int
686 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
687                 uint16_t num_ciphers)
688 {
689         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
690                         (const int *) ciphers, num_ciphers);
691 }
692
693 int
694 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
695                 uint16_t num_auths)
696 {
697         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
698                         (const int *) auths, num_auths);
699 }
700
701 int
702 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
703                 uint16_t num_aeads)
704 {
705         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
706                         (const int *) aeads, num_aeads);
707 }
708
709 static int
710 null_testsuite_setup(void)
711 {
712         struct crypto_testsuite_params *ts_params = &testsuite_params;
713         uint8_t dev_id = ts_params->valid_devs[0];
714         struct rte_cryptodev_info dev_info;
715         const enum rte_crypto_cipher_algorithm ciphers[] = {
716                 RTE_CRYPTO_CIPHER_NULL
717         };
718         const enum rte_crypto_auth_algorithm auths[] = {
719                 RTE_CRYPTO_AUTH_NULL
720         };
721
722         rte_cryptodev_info_get(dev_id, &dev_info);
723
724         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
725                 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
726                                 "testsuite not met\n");
727                 return TEST_SKIPPED;
728         }
729
730         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
731                         && check_auth_capabilities_supported(auths,
732                         RTE_DIM(auths)) != 0) {
733                 RTE_LOG(INFO, USER1, "Capability requirements for NULL "
734                                 "testsuite not met\n");
735                 return TEST_SKIPPED;
736         }
737
738         return 0;
739 }
740
741 static int
742 crypto_gen_testsuite_setup(void)
743 {
744         struct crypto_testsuite_params *ts_params = &testsuite_params;
745         uint8_t dev_id = ts_params->valid_devs[0];
746         struct rte_cryptodev_info dev_info;
747
748         rte_cryptodev_info_get(dev_id, &dev_info);
749
750         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
751                 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
752                                 "testsuite not met\n");
753                 return TEST_SKIPPED;
754         }
755
756         return 0;
757 }
758
759 #ifdef RTE_LIB_SECURITY
760 static int
761 pdcp_proto_testsuite_setup(void)
762 {
763         struct crypto_testsuite_params *ts_params = &testsuite_params;
764         uint8_t dev_id = ts_params->valid_devs[0];
765         struct rte_cryptodev_info dev_info;
766         const enum rte_crypto_cipher_algorithm ciphers[] = {
767                 RTE_CRYPTO_CIPHER_NULL,
768                 RTE_CRYPTO_CIPHER_AES_CTR,
769                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
770                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
771         };
772         const enum rte_crypto_auth_algorithm auths[] = {
773                 RTE_CRYPTO_AUTH_NULL,
774                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
775                 RTE_CRYPTO_AUTH_AES_CMAC,
776                 RTE_CRYPTO_AUTH_ZUC_EIA3
777         };
778
779         rte_cryptodev_info_get(dev_id, &dev_info);
780
781         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
782                         !(dev_info.feature_flags &
783                         RTE_CRYPTODEV_FF_SECURITY)) {
784                 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
785                                 "testsuite not met\n");
786                 return TEST_SKIPPED;
787         }
788
789         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
790                         && check_auth_capabilities_supported(auths,
791                         RTE_DIM(auths)) != 0) {
792                 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
793                                 "testsuite not met\n");
794                 return TEST_SKIPPED;
795         }
796
797         return 0;
798 }
799
800 static int
801 docsis_proto_testsuite_setup(void)
802 {
803         struct crypto_testsuite_params *ts_params = &testsuite_params;
804         uint8_t dev_id = ts_params->valid_devs[0];
805         struct rte_cryptodev_info dev_info;
806         const enum rte_crypto_cipher_algorithm ciphers[] = {
807                 RTE_CRYPTO_CIPHER_AES_DOCSISBPI
808         };
809
810         rte_cryptodev_info_get(dev_id, &dev_info);
811
812         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
813                         !(dev_info.feature_flags &
814                         RTE_CRYPTODEV_FF_SECURITY)) {
815                 RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis "
816                                 "Proto testsuite not met\n");
817                 return TEST_SKIPPED;
818         }
819
820         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
821                 RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto "
822                                 "testsuite not met\n");
823                 return TEST_SKIPPED;
824         }
825
826         return 0;
827 }
828 #endif
829
830 static int
831 aes_ccm_auth_testsuite_setup(void)
832 {
833         struct crypto_testsuite_params *ts_params = &testsuite_params;
834         uint8_t dev_id = ts_params->valid_devs[0];
835         struct rte_cryptodev_info dev_info;
836         const enum rte_crypto_aead_algorithm aeads[] = {
837                 RTE_CRYPTO_AEAD_AES_CCM
838         };
839
840         rte_cryptodev_info_get(dev_id, &dev_info);
841
842         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
843                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
844                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
845                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
846                                 "testsuite not met\n");
847                 return TEST_SKIPPED;
848         }
849
850         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
851                 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
852                                 "testsuite not met\n");
853                 return TEST_SKIPPED;
854         }
855
856         return 0;
857 }
858
859 static int
860 aes_gcm_auth_testsuite_setup(void)
861 {
862         struct crypto_testsuite_params *ts_params = &testsuite_params;
863         uint8_t dev_id = ts_params->valid_devs[0];
864         struct rte_cryptodev_info dev_info;
865         const enum rte_crypto_aead_algorithm aeads[] = {
866                 RTE_CRYPTO_AEAD_AES_GCM
867         };
868
869         rte_cryptodev_info_get(dev_id, &dev_info);
870
871         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
872                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
873                                 "testsuite not met\n");
874                 return TEST_SKIPPED;
875         }
876
877         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
878                 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
879                                 "testsuite not met\n");
880                 return TEST_SKIPPED;
881         }
882
883         return 0;
884 }
885
886 static int
887 aes_gmac_auth_testsuite_setup(void)
888 {
889         struct crypto_testsuite_params *ts_params = &testsuite_params;
890         uint8_t dev_id = ts_params->valid_devs[0];
891         struct rte_cryptodev_info dev_info;
892         const enum rte_crypto_auth_algorithm auths[] = {
893                 RTE_CRYPTO_AUTH_AES_GMAC
894         };
895
896         rte_cryptodev_info_get(dev_id, &dev_info);
897
898         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
899                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
900                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
901                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
902                                 "testsuite not met\n");
903                 return TEST_SKIPPED;
904         }
905
906         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
907                 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
908                                 "testsuite not met\n");
909                 return TEST_SKIPPED;
910         }
911
912         return 0;
913 }
914
915 static int
916 chacha20_poly1305_testsuite_setup(void)
917 {
918         struct crypto_testsuite_params *ts_params = &testsuite_params;
919         uint8_t dev_id = ts_params->valid_devs[0];
920         struct rte_cryptodev_info dev_info;
921         const enum rte_crypto_aead_algorithm aeads[] = {
922                 RTE_CRYPTO_AEAD_CHACHA20_POLY1305
923         };
924
925         rte_cryptodev_info_get(dev_id, &dev_info);
926
927         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
928                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
929                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
930                 RTE_LOG(INFO, USER1, "Feature flag requirements for "
931                                 "Chacha20-Poly1305 testsuite not met\n");
932                 return TEST_SKIPPED;
933         }
934
935         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
936                 RTE_LOG(INFO, USER1, "Capability requirements for "
937                                 "Chacha20-Poly1305 testsuite not met\n");
938                 return TEST_SKIPPED;
939         }
940
941         return 0;
942 }
943
944 static int
945 snow3g_testsuite_setup(void)
946 {
947         struct crypto_testsuite_params *ts_params = &testsuite_params;
948         uint8_t dev_id = ts_params->valid_devs[0];
949         struct rte_cryptodev_info dev_info;
950         const enum rte_crypto_cipher_algorithm ciphers[] = {
951                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
952
953         };
954         const enum rte_crypto_auth_algorithm auths[] = {
955                 RTE_CRYPTO_AUTH_SNOW3G_UIA2
956         };
957
958         rte_cryptodev_info_get(dev_id, &dev_info);
959
960         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
961                 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
962                                 "testsuite not met\n");
963                 return TEST_SKIPPED;
964         }
965
966         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
967                         && check_auth_capabilities_supported(auths,
968                         RTE_DIM(auths)) != 0) {
969                 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
970                                 "testsuite not met\n");
971                 return TEST_SKIPPED;
972         }
973
974         return 0;
975 }
976
977 static int
978 zuc_testsuite_setup(void)
979 {
980         struct crypto_testsuite_params *ts_params = &testsuite_params;
981         uint8_t dev_id = ts_params->valid_devs[0];
982         struct rte_cryptodev_info dev_info;
983         const enum rte_crypto_cipher_algorithm ciphers[] = {
984                 RTE_CRYPTO_CIPHER_ZUC_EEA3
985         };
986         const enum rte_crypto_auth_algorithm auths[] = {
987                 RTE_CRYPTO_AUTH_ZUC_EIA3
988         };
989
990         rte_cryptodev_info_get(dev_id, &dev_info);
991
992         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
993                 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
994                                 "testsuite not met\n");
995                 return TEST_SKIPPED;
996         }
997
998         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
999                         && check_auth_capabilities_supported(auths,
1000                         RTE_DIM(auths)) != 0) {
1001                 RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1002                                 "testsuite not met\n");
1003                 return TEST_SKIPPED;
1004         }
1005
1006         return 0;
1007 }
1008
1009 static int
1010 hmac_md5_auth_testsuite_setup(void)
1011 {
1012         struct crypto_testsuite_params *ts_params = &testsuite_params;
1013         uint8_t dev_id = ts_params->valid_devs[0];
1014         struct rte_cryptodev_info dev_info;
1015         const enum rte_crypto_auth_algorithm auths[] = {
1016                 RTE_CRYPTO_AUTH_MD5_HMAC
1017         };
1018
1019         rte_cryptodev_info_get(dev_id, &dev_info);
1020
1021         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1022                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1023                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1024                 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1025                                 "Auth testsuite not met\n");
1026                 return TEST_SKIPPED;
1027         }
1028
1029         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1030                 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1031                                 "testsuite not met\n");
1032                 return TEST_SKIPPED;
1033         }
1034
1035         return 0;
1036 }
1037
1038 static int
1039 kasumi_testsuite_setup(void)
1040 {
1041         struct crypto_testsuite_params *ts_params = &testsuite_params;
1042         uint8_t dev_id = ts_params->valid_devs[0];
1043         struct rte_cryptodev_info dev_info;
1044         const enum rte_crypto_cipher_algorithm ciphers[] = {
1045                 RTE_CRYPTO_CIPHER_KASUMI_F8
1046         };
1047         const enum rte_crypto_auth_algorithm auths[] = {
1048                 RTE_CRYPTO_AUTH_KASUMI_F9
1049         };
1050
1051         rte_cryptodev_info_get(dev_id, &dev_info);
1052
1053         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1054                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1055                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1056                 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1057                                 "testsuite not met\n");
1058                 return TEST_SKIPPED;
1059         }
1060
1061         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1062                         && check_auth_capabilities_supported(auths,
1063                         RTE_DIM(auths)) != 0) {
1064                 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1065                                 "testsuite not met\n");
1066                 return TEST_SKIPPED;
1067         }
1068
1069         return 0;
1070 }
1071
1072 static int
1073 negative_aes_gcm_testsuite_setup(void)
1074 {
1075         struct crypto_testsuite_params *ts_params = &testsuite_params;
1076         uint8_t dev_id = ts_params->valid_devs[0];
1077         struct rte_cryptodev_info dev_info;
1078         const enum rte_crypto_aead_algorithm aeads[] = {
1079                 RTE_CRYPTO_AEAD_AES_GCM
1080         };
1081
1082         rte_cryptodev_info_get(dev_id, &dev_info);
1083
1084         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1085                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1086                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1087                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1088                                 "AES GCM testsuite not met\n");
1089                 return TEST_SKIPPED;
1090         }
1091
1092         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1093                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1094                                 "AES GCM testsuite not met\n");
1095                 return TEST_SKIPPED;
1096         }
1097
1098         return 0;
1099 }
1100
1101 static int
1102 negative_aes_gmac_testsuite_setup(void)
1103 {
1104         struct crypto_testsuite_params *ts_params = &testsuite_params;
1105         uint8_t dev_id = ts_params->valid_devs[0];
1106         struct rte_cryptodev_info dev_info;
1107         const enum rte_crypto_auth_algorithm auths[] = {
1108                 RTE_CRYPTO_AUTH_AES_GMAC
1109         };
1110
1111         rte_cryptodev_info_get(dev_id, &dev_info);
1112
1113         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1114                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1115                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1116                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1117                                 "AES GMAC testsuite not met\n");
1118                 return TEST_SKIPPED;
1119         }
1120
1121         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1122                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1123                                 "AES GMAC testsuite not met\n");
1124                 return TEST_SKIPPED;
1125         }
1126
1127         return 0;
1128 }
1129
1130 static int
1131 mixed_cipher_hash_testsuite_setup(void)
1132 {
1133         struct crypto_testsuite_params *ts_params = &testsuite_params;
1134         uint8_t dev_id = ts_params->valid_devs[0];
1135         struct rte_cryptodev_info dev_info;
1136         uint64_t feat_flags;
1137         const enum rte_crypto_cipher_algorithm ciphers[] = {
1138                 RTE_CRYPTO_CIPHER_NULL,
1139                 RTE_CRYPTO_CIPHER_AES_CTR,
1140                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
1141                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1142         };
1143         const enum rte_crypto_auth_algorithm auths[] = {
1144                 RTE_CRYPTO_AUTH_NULL,
1145                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1146                 RTE_CRYPTO_AUTH_AES_CMAC,
1147                 RTE_CRYPTO_AUTH_ZUC_EIA3
1148         };
1149
1150         rte_cryptodev_info_get(dev_id, &dev_info);
1151         feat_flags = dev_info.feature_flags;
1152
1153         if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1154                         (global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1155                 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1156                                 "Cipher Hash testsuite not met\n");
1157                 return TEST_SKIPPED;
1158         }
1159
1160         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1161                         && check_auth_capabilities_supported(auths,
1162                         RTE_DIM(auths)) != 0) {
1163                 RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1164                                 "Cipher Hash testsuite not met\n");
1165                 return TEST_SKIPPED;
1166         }
1167
1168         return 0;
1169 }
1170
1171 static int
1172 esn_testsuite_setup(void)
1173 {
1174         struct crypto_testsuite_params *ts_params = &testsuite_params;
1175         uint8_t dev_id = ts_params->valid_devs[0];
1176         struct rte_cryptodev_info dev_info;
1177         const enum rte_crypto_cipher_algorithm ciphers[] = {
1178                 RTE_CRYPTO_CIPHER_AES_CBC
1179         };
1180         const enum rte_crypto_auth_algorithm auths[] = {
1181                 RTE_CRYPTO_AUTH_SHA1_HMAC
1182         };
1183
1184         rte_cryptodev_info_get(dev_id, &dev_info);
1185
1186         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1187                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1188                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1189                 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1190                                 "testsuite not met\n");
1191                 return TEST_SKIPPED;
1192         }
1193
1194         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1195                         && check_auth_capabilities_supported(auths,
1196                         RTE_DIM(auths)) != 0) {
1197                 RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1198                                 "testsuite not met\n");
1199                 return TEST_SKIPPED;
1200         }
1201
1202         return 0;
1203 }
1204
1205 static int
1206 multi_session_testsuite_setup(void)
1207 {
1208         struct crypto_testsuite_params *ts_params = &testsuite_params;
1209         uint8_t dev_id = ts_params->valid_devs[0];
1210         struct rte_cryptodev_info dev_info;
1211         const enum rte_crypto_cipher_algorithm ciphers[] = {
1212                 RTE_CRYPTO_CIPHER_AES_CBC
1213         };
1214         const enum rte_crypto_auth_algorithm auths[] = {
1215                 RTE_CRYPTO_AUTH_SHA512_HMAC
1216         };
1217
1218         rte_cryptodev_info_get(dev_id, &dev_info);
1219
1220         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1221                 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1222                                 "Session testsuite not met\n");
1223                 return TEST_SKIPPED;
1224         }
1225
1226         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1227                         && check_auth_capabilities_supported(auths,
1228                         RTE_DIM(auths)) != 0) {
1229                 RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1230                                 "Session testsuite not met\n");
1231                 return TEST_SKIPPED;
1232         }
1233
1234         return 0;
1235 }
1236
1237 static int
1238 negative_hmac_sha1_testsuite_setup(void)
1239 {
1240         struct crypto_testsuite_params *ts_params = &testsuite_params;
1241         uint8_t dev_id = ts_params->valid_devs[0];
1242         struct rte_cryptodev_info dev_info;
1243         const enum rte_crypto_cipher_algorithm ciphers[] = {
1244                 RTE_CRYPTO_CIPHER_AES_CBC
1245         };
1246         const enum rte_crypto_auth_algorithm auths[] = {
1247                 RTE_CRYPTO_AUTH_SHA1_HMAC
1248         };
1249
1250         rte_cryptodev_info_get(dev_id, &dev_info);
1251
1252         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1253                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1254                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1255                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1256                                 "HMAC SHA1 testsuite not met\n");
1257                 return TEST_SKIPPED;
1258         }
1259
1260         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1261                         && check_auth_capabilities_supported(auths,
1262                         RTE_DIM(auths)) != 0) {
1263                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1264                                 "HMAC SHA1 testsuite not met\n");
1265                 return TEST_SKIPPED;
1266         }
1267
1268         return 0;
1269 }
1270
1271 static int
1272 dev_configure_and_start(uint64_t ff_disable)
1273 {
1274         struct crypto_testsuite_params *ts_params = &testsuite_params;
1275         struct crypto_unittest_params *ut_params = &unittest_params;
1276
1277         uint16_t qp_id;
1278
1279         /* Clear unit test parameters before running test */
1280         memset(ut_params, 0, sizeof(*ut_params));
1281
1282         /* Reconfigure device to default parameters */
1283         ts_params->conf.socket_id = SOCKET_ID_ANY;
1284         ts_params->conf.ff_disable = ff_disable;
1285         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1286         ts_params->qp_conf.mp_session = ts_params->session_mpool;
1287         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1288
1289         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1290                         &ts_params->conf),
1291                         "Failed to configure cryptodev %u",
1292                         ts_params->valid_devs[0]);
1293
1294         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1295                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1296                         ts_params->valid_devs[0], qp_id,
1297                         &ts_params->qp_conf,
1298                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1299                         "Failed to setup queue pair %u on cryptodev %u",
1300                         qp_id, ts_params->valid_devs[0]);
1301         }
1302
1303
1304         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1305
1306         /* Start the device */
1307         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1308                         "Failed to start cryptodev %u",
1309                         ts_params->valid_devs[0]);
1310
1311         return TEST_SUCCESS;
1312 }
1313
1314 int
1315 ut_setup(void)
1316 {
1317         /* Configure and start the device with security feature disabled */
1318         return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1319 }
1320
1321 static int
1322 ut_setup_security(void)
1323 {
1324         /* Configure and start the device with no features disabled */
1325         return dev_configure_and_start(0);
1326 }
1327
1328 void
1329 ut_teardown(void)
1330 {
1331         struct crypto_testsuite_params *ts_params = &testsuite_params;
1332         struct crypto_unittest_params *ut_params = &unittest_params;
1333         struct rte_cryptodev_stats stats;
1334
1335         /* free crypto session structure */
1336 #ifdef RTE_LIB_SECURITY
1337         if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1338                 if (ut_params->sec_session) {
1339                         rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1340                                                 (ts_params->valid_devs[0]),
1341                                                 ut_params->sec_session);
1342                         ut_params->sec_session = NULL;
1343                 }
1344         } else
1345 #endif
1346         {
1347                 if (ut_params->sess) {
1348                         rte_cryptodev_sym_session_clear(
1349                                         ts_params->valid_devs[0],
1350                                         ut_params->sess);
1351                         rte_cryptodev_sym_session_free(ut_params->sess);
1352                         ut_params->sess = NULL;
1353                 }
1354         }
1355
1356         /* free crypto operation structure */
1357         if (ut_params->op)
1358                 rte_crypto_op_free(ut_params->op);
1359
1360         /*
1361          * free mbuf - both obuf and ibuf are usually the same,
1362          * so check if they point at the same address is necessary,
1363          * to avoid freeing the mbuf twice.
1364          */
1365         if (ut_params->obuf) {
1366                 rte_pktmbuf_free(ut_params->obuf);
1367                 if (ut_params->ibuf == ut_params->obuf)
1368                         ut_params->ibuf = 0;
1369                 ut_params->obuf = 0;
1370         }
1371         if (ut_params->ibuf) {
1372                 rte_pktmbuf_free(ut_params->ibuf);
1373                 ut_params->ibuf = 0;
1374         }
1375
1376         if (ts_params->mbuf_pool != NULL)
1377                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1378                         rte_mempool_avail_count(ts_params->mbuf_pool));
1379
1380         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1381
1382         /* Stop the device */
1383         rte_cryptodev_stop(ts_params->valid_devs[0]);
1384 }
1385
1386 static int
1387 test_device_configure_invalid_dev_id(void)
1388 {
1389         struct crypto_testsuite_params *ts_params = &testsuite_params;
1390         uint16_t dev_id, num_devs = 0;
1391
1392         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1393                         "Need at least %d devices for test", 1);
1394
1395         /* valid dev_id values */
1396         dev_id = ts_params->valid_devs[0];
1397
1398         /* Stop the device in case it's started so it can be configured */
1399         rte_cryptodev_stop(dev_id);
1400
1401         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1402                         "Failed test for rte_cryptodev_configure: "
1403                         "invalid dev_num %u", dev_id);
1404
1405         /* invalid dev_id values */
1406         dev_id = num_devs;
1407
1408         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1409                         "Failed test for rte_cryptodev_configure: "
1410                         "invalid dev_num %u", dev_id);
1411
1412         dev_id = 0xff;
1413
1414         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1415                         "Failed test for rte_cryptodev_configure:"
1416                         "invalid dev_num %u", dev_id);
1417
1418         return TEST_SUCCESS;
1419 }
1420
1421 static int
1422 test_device_configure_invalid_queue_pair_ids(void)
1423 {
1424         struct crypto_testsuite_params *ts_params = &testsuite_params;
1425         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1426
1427         /* Stop the device in case it's started so it can be configured */
1428         rte_cryptodev_stop(ts_params->valid_devs[0]);
1429
1430         /* valid - max value queue pairs */
1431         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1432
1433         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1434                         &ts_params->conf),
1435                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1436                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1437
1438         /* valid - one queue pairs */
1439         ts_params->conf.nb_queue_pairs = 1;
1440
1441         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1442                         &ts_params->conf),
1443                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1444                         ts_params->valid_devs[0],
1445                         ts_params->conf.nb_queue_pairs);
1446
1447
1448         /* invalid - zero queue pairs */
1449         ts_params->conf.nb_queue_pairs = 0;
1450
1451         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1452                         &ts_params->conf),
1453                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1454                         " invalid qps: %u",
1455                         ts_params->valid_devs[0],
1456                         ts_params->conf.nb_queue_pairs);
1457
1458
1459         /* invalid - max value supported by field queue pairs */
1460         ts_params->conf.nb_queue_pairs = UINT16_MAX;
1461
1462         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1463                         &ts_params->conf),
1464                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1465                         " invalid qps: %u",
1466                         ts_params->valid_devs[0],
1467                         ts_params->conf.nb_queue_pairs);
1468
1469
1470         /* invalid - max value + 1 queue pairs */
1471         ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1472
1473         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1474                         &ts_params->conf),
1475                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1476                         " invalid qps: %u",
1477                         ts_params->valid_devs[0],
1478                         ts_params->conf.nb_queue_pairs);
1479
1480         /* revert to original testsuite value */
1481         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1482
1483         return TEST_SUCCESS;
1484 }
1485
1486 static int
1487 test_queue_pair_descriptor_setup(void)
1488 {
1489         struct crypto_testsuite_params *ts_params = &testsuite_params;
1490         struct rte_cryptodev_qp_conf qp_conf = {
1491                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
1492         };
1493         uint16_t qp_id;
1494
1495         /* Stop the device in case it's started so it can be configured */
1496         rte_cryptodev_stop(ts_params->valid_devs[0]);
1497
1498         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1499                         &ts_params->conf),
1500                         "Failed to configure cryptodev %u",
1501                         ts_params->valid_devs[0]);
1502
1503         /*
1504          * Test various ring sizes on this device. memzones can't be
1505          * freed so are re-used if ring is released and re-created.
1506          */
1507         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1508         qp_conf.mp_session = ts_params->session_mpool;
1509         qp_conf.mp_session_private = ts_params->session_priv_mpool;
1510
1511         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1512                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1513                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1514                                 rte_cryptodev_socket_id(
1515                                                 ts_params->valid_devs[0])),
1516                                 "Failed test for "
1517                                 "rte_cryptodev_queue_pair_setup: num_inflights "
1518                                 "%u on qp %u on cryptodev %u",
1519                                 qp_conf.nb_descriptors, qp_id,
1520                                 ts_params->valid_devs[0]);
1521         }
1522
1523         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1524
1525         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1526                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1527                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1528                                 rte_cryptodev_socket_id(
1529                                                 ts_params->valid_devs[0])),
1530                                 "Failed test for"
1531                                 " rte_cryptodev_queue_pair_setup: num_inflights"
1532                                 " %u on qp %u on cryptodev %u",
1533                                 qp_conf.nb_descriptors, qp_id,
1534                                 ts_params->valid_devs[0]);
1535         }
1536
1537         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1538
1539         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1540                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1541                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1542                                 rte_cryptodev_socket_id(
1543                                                 ts_params->valid_devs[0])),
1544                                 "Failed test for "
1545                                 "rte_cryptodev_queue_pair_setup: num_inflights"
1546                                 " %u on qp %u on cryptodev %u",
1547                                 qp_conf.nb_descriptors, qp_id,
1548                                 ts_params->valid_devs[0]);
1549         }
1550
1551         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1552
1553         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1554                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1555                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1556                                 rte_cryptodev_socket_id(
1557                                                 ts_params->valid_devs[0])),
1558                                 "Failed test for"
1559                                 " rte_cryptodev_queue_pair_setup:"
1560                                 "num_inflights %u on qp %u on cryptodev %u",
1561                                 qp_conf.nb_descriptors, qp_id,
1562                                 ts_params->valid_devs[0]);
1563         }
1564
1565         /* test invalid queue pair id */
1566         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
1567
1568         qp_id = ts_params->conf.nb_queue_pairs;         /*invalid */
1569
1570         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1571                         ts_params->valid_devs[0],
1572                         qp_id, &qp_conf,
1573                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1574                         "Failed test for rte_cryptodev_queue_pair_setup:"
1575                         "invalid qp %u on cryptodev %u",
1576                         qp_id, ts_params->valid_devs[0]);
1577
1578         qp_id = 0xffff; /*invalid*/
1579
1580         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1581                         ts_params->valid_devs[0],
1582                         qp_id, &qp_conf,
1583                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1584                         "Failed test for rte_cryptodev_queue_pair_setup:"
1585                         "invalid qp %u on cryptodev %u",
1586                         qp_id, ts_params->valid_devs[0]);
1587
1588         return TEST_SUCCESS;
1589 }
1590
1591 /* ***** Plaintext data for tests ***** */
1592
1593 const char catch_22_quote_1[] =
1594                 "There was only one catch and that was Catch-22, which "
1595                 "specified that a concern for one's safety in the face of "
1596                 "dangers that were real and immediate was the process of a "
1597                 "rational mind. Orr was crazy and could be grounded. All he "
1598                 "had to do was ask; and as soon as he did, he would no longer "
1599                 "be crazy and would have to fly more missions. Orr would be "
1600                 "crazy to fly more missions and sane if he didn't, but if he "
1601                 "was sane he had to fly them. If he flew them he was crazy "
1602                 "and didn't have to; but if he didn't want to he was sane and "
1603                 "had to. Yossarian was moved very deeply by the absolute "
1604                 "simplicity of this clause of Catch-22 and let out a "
1605                 "respectful whistle. \"That's some catch, that Catch-22\", he "
1606                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
1607
1608 const char catch_22_quote[] =
1609                 "What a lousy earth! He wondered how many people were "
1610                 "destitute that same night even in his own prosperous country, "
1611                 "how many homes were shanties, how many husbands were drunk "
1612                 "and wives socked, and how many children were bullied, abused, "
1613                 "or abandoned. How many families hungered for food they could "
1614                 "not afford to buy? How many hearts were broken? How many "
1615                 "suicides would take place that same night, how many people "
1616                 "would go insane? How many cockroaches and landlords would "
1617                 "triumph? How many winners were losers, successes failures, "
1618                 "and rich men poor men? How many wise guys were stupid? How "
1619                 "many happy endings were unhappy endings? How many honest men "
1620                 "were liars, brave men cowards, loyal men traitors, how many "
1621                 "sainted men were corrupt, how many people in positions of "
1622                 "trust had sold their souls to bodyguards, how many had never "
1623                 "had souls? How many straight-and-narrow paths were crooked "
1624                 "paths? How many best families were worst families and how "
1625                 "many good people were bad people? When you added them all up "
1626                 "and then subtracted, you might be left with only the children, "
1627                 "and perhaps with Albert Einstein and an old violinist or "
1628                 "sculptor somewhere.";
1629
1630 #define QUOTE_480_BYTES         (480)
1631 #define QUOTE_512_BYTES         (512)
1632 #define QUOTE_768_BYTES         (768)
1633 #define QUOTE_1024_BYTES        (1024)
1634
1635
1636
1637 /* ***** SHA1 Hash Tests ***** */
1638
1639 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
1640
1641 static uint8_t hmac_sha1_key[] = {
1642         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1643         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1644         0xDE, 0xF4, 0xDE, 0xAD };
1645
1646 /* ***** SHA224 Hash Tests ***** */
1647
1648 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
1649
1650
1651 /* ***** AES-CBC Cipher Tests ***** */
1652
1653 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
1654 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
1655
1656 static uint8_t aes_cbc_key[] = {
1657         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1658         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1659
1660 static uint8_t aes_cbc_iv[] = {
1661         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1662         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1663
1664
1665 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1666
1667 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1668         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1669         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1670         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1671         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1672         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1673         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1674         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1675         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1676         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1677         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1678         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1679         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1680         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1681         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1682         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1683         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1684         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1685         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1686         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1687         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1688         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1689         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1690         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1691         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1692         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1693         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1694         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1695         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1696         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1697         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1698         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1699         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1700         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1701         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1702         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1703         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1704         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1705         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1706         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1707         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1708         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1709         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1710         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1711         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1712         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1713         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1714         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1715         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1716         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1717         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1718         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1719         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1720         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1721         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1722         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1723         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1724         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1725         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1726         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1727         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1728         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1729         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1730         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1731         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1732 };
1733
1734 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1735         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1736         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1737         0x18, 0x8c, 0x1d, 0x32
1738 };
1739
1740
1741 /* Multisession Vector context Test */
1742 /*Begin Session 0 */
1743 static uint8_t ms_aes_cbc_key0[] = {
1744         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1745         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1746 };
1747
1748 static uint8_t ms_aes_cbc_iv0[] = {
1749         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1750         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1751 };
1752
1753 static const uint8_t ms_aes_cbc_cipher0[] = {
1754                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1755                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1756                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1757                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1758                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1759                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1760                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1761                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1762                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1763                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1764                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1765                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1766                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1767                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1768                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1769                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1770                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1771                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1772                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1773                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1774                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1775                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1776                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1777                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1778                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1779                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1780                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1781                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1782                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1783                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1784                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1785                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1786                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1787                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1788                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1789                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1790                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1791                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1792                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1793                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1794                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1795                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1796                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1797                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1798                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1799                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1800                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1801                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1802                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1803                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1804                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1805                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1806                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1807                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1808                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1809                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1810                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1811                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1812                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1813                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1814                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1815                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1816                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1817                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1818 };
1819
1820
1821 static  uint8_t ms_hmac_key0[] = {
1822                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1823                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1824                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1825                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1826                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1827                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1828                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1829                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1830 };
1831
1832 static const uint8_t ms_hmac_digest0[] = {
1833                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1834                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1835                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1836                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1837                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1838                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1839                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1840                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1841                 };
1842
1843 /* End Session 0 */
1844 /* Begin session 1 */
1845
1846 static  uint8_t ms_aes_cbc_key1[] = {
1847                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1848                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1849 };
1850
1851 static  uint8_t ms_aes_cbc_iv1[] = {
1852         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1853         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1854 };
1855
1856 static const uint8_t ms_aes_cbc_cipher1[] = {
1857                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1858                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1859                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1860                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1861                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1862                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1863                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1864                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1865                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1866                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1867                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1868                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1869                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1870                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1871                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1872                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1873                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1874                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1875                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1876                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1877                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1878                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1879                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1880                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1881                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1882                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1883                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1884                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1885                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1886                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1887                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1888                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1889                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1890                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1891                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1892                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1893                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1894                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1895                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1896                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1897                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1898                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1899                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1900                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1901                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1902                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1903                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1904                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1905                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1906                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1907                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1908                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1909                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1910                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1911                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1912                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1913                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1914                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1915                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1916                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1917                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1918                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1919                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1920                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1921
1922 };
1923
1924 static uint8_t ms_hmac_key1[] = {
1925                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1926                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1927                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1928                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1929                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1930                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1931                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1932                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1933 };
1934
1935 static const uint8_t ms_hmac_digest1[] = {
1936                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1937                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1938                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1939                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1940                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1941                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1942                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1943                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1944 };
1945 /* End Session 1  */
1946 /* Begin Session 2 */
1947 static  uint8_t ms_aes_cbc_key2[] = {
1948                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1949                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1950 };
1951
1952 static  uint8_t ms_aes_cbc_iv2[] = {
1953                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1954                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1955 };
1956
1957 static const uint8_t ms_aes_cbc_cipher2[] = {
1958                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1959                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1960                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1961                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1962                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1963                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1964                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1965                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1966                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1967                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1968                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1969                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1970                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1971                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1972                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1973                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1974                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1975                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1976                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1977                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1978                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1979                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1980                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1981                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1982                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1983                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1984                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1985                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1986                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1987                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1988                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1989                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1990                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1991                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1992                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1993                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1994                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1995                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1996                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1997                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1998                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1999                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2000                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2001                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2002                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2003                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2004                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2005                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2006                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2007                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2008                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2009                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2010                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2011                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2012                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2013                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2014                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2015                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2016                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2017                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2018                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2019                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2020                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2021                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2022 };
2023
2024 static  uint8_t ms_hmac_key2[] = {
2025                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2026                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2027                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2028                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2029                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2030                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2031                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2032                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2033 };
2034
2035 static const uint8_t ms_hmac_digest2[] = {
2036                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2037                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2038                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2039                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2040                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2041                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2042                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2043                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2044 };
2045
2046 /* End Session 2 */
2047
2048
2049 static int
2050 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2051 {
2052         struct crypto_testsuite_params *ts_params = &testsuite_params;
2053         struct crypto_unittest_params *ut_params = &unittest_params;
2054
2055         /* Verify the capabilities */
2056         struct rte_cryptodev_sym_capability_idx cap_idx;
2057         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2058         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2059         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2060                         &cap_idx) == NULL)
2061                 return TEST_SKIPPED;
2062         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2063         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2064         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2065                         &cap_idx) == NULL)
2066                 return TEST_SKIPPED;
2067
2068         /* Generate test mbuf data and space for digest */
2069         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2070                         catch_22_quote, QUOTE_512_BYTES, 0);
2071
2072         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2073                         DIGEST_BYTE_LENGTH_SHA1);
2074         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2075
2076         /* Setup Cipher Parameters */
2077         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2078         ut_params->cipher_xform.next = &ut_params->auth_xform;
2079
2080         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2081         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2082         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2083         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2084         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2085         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2086
2087         /* Setup HMAC Parameters */
2088         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2089
2090         ut_params->auth_xform.next = NULL;
2091
2092         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2093         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2094         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2095         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2096         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2097
2098         ut_params->sess = rte_cryptodev_sym_session_create(
2099                         ts_params->session_mpool);
2100
2101         /* Create crypto session*/
2102         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2103                         ut_params->sess, &ut_params->cipher_xform,
2104                         ts_params->session_priv_mpool);
2105         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2106
2107         /* Generate crypto op data structure */
2108         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2109                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2110         TEST_ASSERT_NOT_NULL(ut_params->op,
2111                         "Failed to allocate symmetric crypto operation struct");
2112
2113         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2114
2115         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2116
2117         /* set crypto operation source mbuf */
2118         sym_op->m_src = ut_params->ibuf;
2119
2120         /* Set crypto operation authentication parameters */
2121         sym_op->auth.digest.data = ut_params->digest;
2122         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2123                         ut_params->ibuf, QUOTE_512_BYTES);
2124
2125         sym_op->auth.data.offset = 0;
2126         sym_op->auth.data.length = QUOTE_512_BYTES;
2127
2128         /* Copy IV at the end of the crypto operation */
2129         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2130                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2131
2132         /* Set crypto operation cipher parameters */
2133         sym_op->cipher.data.offset = 0;
2134         sym_op->cipher.data.length = QUOTE_512_BYTES;
2135
2136         /* Process crypto operation */
2137         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2138                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2139                         ut_params->op);
2140         else
2141                 TEST_ASSERT_NOT_NULL(
2142                         process_crypto_request(ts_params->valid_devs[0],
2143                                 ut_params->op),
2144                                 "failed to process sym crypto op");
2145
2146         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2147                         "crypto op processing failed");
2148
2149         /* Validate obuf */
2150         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2151                         uint8_t *);
2152
2153         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2154                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2155                         QUOTE_512_BYTES,
2156                         "ciphertext data not as expected");
2157
2158         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2159
2160         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2161                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2162                         gbl_driver_id == rte_cryptodev_driver_id_get(
2163                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2164                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2165                                         DIGEST_BYTE_LENGTH_SHA1,
2166                         "Generated digest data not as expected");
2167
2168         return TEST_SUCCESS;
2169 }
2170
2171 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2172
2173 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2174
2175 static uint8_t hmac_sha512_key[] = {
2176         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2177         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2178         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2179         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2180         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2181         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2182         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2183         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2184
2185 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2186         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2187         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2188         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2189         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2190         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2191         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2192         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2193         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2194
2195
2196
2197 static int
2198 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2199                 struct crypto_unittest_params *ut_params,
2200                 uint8_t *cipher_key,
2201                 uint8_t *hmac_key);
2202
2203 static int
2204 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2205                 struct crypto_unittest_params *ut_params,
2206                 struct crypto_testsuite_params *ts_params,
2207                 const uint8_t *cipher,
2208                 const uint8_t *digest,
2209                 const uint8_t *iv);
2210
2211
2212 static int
2213 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2214                 struct crypto_unittest_params *ut_params,
2215                 uint8_t *cipher_key,
2216                 uint8_t *hmac_key)
2217 {
2218
2219         /* Setup Cipher Parameters */
2220         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2221         ut_params->cipher_xform.next = NULL;
2222
2223         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2224         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2225         ut_params->cipher_xform.cipher.key.data = cipher_key;
2226         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2227         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2228         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2229
2230         /* Setup HMAC Parameters */
2231         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2232         ut_params->auth_xform.next = &ut_params->cipher_xform;
2233
2234         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2235         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2236         ut_params->auth_xform.auth.key.data = hmac_key;
2237         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2238         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2239
2240         return TEST_SUCCESS;
2241 }
2242
2243
2244 static int
2245 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2246                 struct crypto_unittest_params *ut_params,
2247                 struct crypto_testsuite_params *ts_params,
2248                 const uint8_t *cipher,
2249                 const uint8_t *digest,
2250                 const uint8_t *iv)
2251 {
2252         /* Generate test mbuf data and digest */
2253         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2254                         (const char *)
2255                         cipher,
2256                         QUOTE_512_BYTES, 0);
2257
2258         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2259                         DIGEST_BYTE_LENGTH_SHA512);
2260         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2261
2262         rte_memcpy(ut_params->digest,
2263                         digest,
2264                         DIGEST_BYTE_LENGTH_SHA512);
2265
2266         /* Generate Crypto op data structure */
2267         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2268                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2269         TEST_ASSERT_NOT_NULL(ut_params->op,
2270                         "Failed to allocate symmetric crypto operation struct");
2271
2272         rte_crypto_op_attach_sym_session(ut_params->op, sess);
2273
2274         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2275
2276         /* set crypto operation source mbuf */
2277         sym_op->m_src = ut_params->ibuf;
2278
2279         sym_op->auth.digest.data = ut_params->digest;
2280         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2281                         ut_params->ibuf, QUOTE_512_BYTES);
2282
2283         sym_op->auth.data.offset = 0;
2284         sym_op->auth.data.length = QUOTE_512_BYTES;
2285
2286         /* Copy IV at the end of the crypto operation */
2287         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2288                         iv, CIPHER_IV_LENGTH_AES_CBC);
2289
2290         sym_op->cipher.data.offset = 0;
2291         sym_op->cipher.data.length = QUOTE_512_BYTES;
2292
2293         /* Process crypto operation */
2294         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2295                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2296                         ut_params->op);
2297         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2298                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2299                                 ut_params->op, 1, 1, 0, 0);
2300         else
2301                 TEST_ASSERT_NOT_NULL(
2302                                 process_crypto_request(ts_params->valid_devs[0],
2303                                         ut_params->op),
2304                                         "failed to process sym crypto op");
2305
2306         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2307                         "crypto op processing failed");
2308
2309         ut_params->obuf = ut_params->op->sym->m_src;
2310
2311         /* Validate obuf */
2312         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2313                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2314                         catch_22_quote,
2315                         QUOTE_512_BYTES,
2316                         "Plaintext data not as expected");
2317
2318         /* Validate obuf */
2319         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2320                         "Digest verification failed");
2321
2322         return TEST_SUCCESS;
2323 }
2324
2325 /* ***** SNOW 3G Tests ***** */
2326 static int
2327 create_wireless_algo_hash_session(uint8_t dev_id,
2328         const uint8_t *key, const uint8_t key_len,
2329         const uint8_t iv_len, const uint8_t auth_len,
2330         enum rte_crypto_auth_operation op,
2331         enum rte_crypto_auth_algorithm algo)
2332 {
2333         uint8_t hash_key[key_len];
2334         int status;
2335
2336         struct crypto_testsuite_params *ts_params = &testsuite_params;
2337         struct crypto_unittest_params *ut_params = &unittest_params;
2338
2339         memcpy(hash_key, key, key_len);
2340
2341         debug_hexdump(stdout, "key:", key, key_len);
2342
2343         /* Setup Authentication Parameters */
2344         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2345         ut_params->auth_xform.next = NULL;
2346
2347         ut_params->auth_xform.auth.op = op;
2348         ut_params->auth_xform.auth.algo = algo;
2349         ut_params->auth_xform.auth.key.length = key_len;
2350         ut_params->auth_xform.auth.key.data = hash_key;
2351         ut_params->auth_xform.auth.digest_length = auth_len;
2352         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2353         ut_params->auth_xform.auth.iv.length = iv_len;
2354         ut_params->sess = rte_cryptodev_sym_session_create(
2355                         ts_params->session_mpool);
2356
2357         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2358                         &ut_params->auth_xform,
2359                         ts_params->session_priv_mpool);
2360         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2361         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2362         return 0;
2363 }
2364
2365 static int
2366 create_wireless_algo_cipher_session(uint8_t dev_id,
2367                         enum rte_crypto_cipher_operation op,
2368                         enum rte_crypto_cipher_algorithm algo,
2369                         const uint8_t *key, const uint8_t key_len,
2370                         uint8_t iv_len)
2371 {
2372         uint8_t cipher_key[key_len];
2373         int status;
2374         struct crypto_testsuite_params *ts_params = &testsuite_params;
2375         struct crypto_unittest_params *ut_params = &unittest_params;
2376
2377         memcpy(cipher_key, key, key_len);
2378
2379         /* Setup Cipher Parameters */
2380         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2381         ut_params->cipher_xform.next = NULL;
2382
2383         ut_params->cipher_xform.cipher.algo = algo;
2384         ut_params->cipher_xform.cipher.op = op;
2385         ut_params->cipher_xform.cipher.key.data = cipher_key;
2386         ut_params->cipher_xform.cipher.key.length = key_len;
2387         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2388         ut_params->cipher_xform.cipher.iv.length = iv_len;
2389
2390         debug_hexdump(stdout, "key:", key, key_len);
2391
2392         /* Create Crypto session */
2393         ut_params->sess = rte_cryptodev_sym_session_create(
2394                         ts_params->session_mpool);
2395
2396         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2397                         &ut_params->cipher_xform,
2398                         ts_params->session_priv_mpool);
2399         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2400         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2401         return 0;
2402 }
2403
2404 static int
2405 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2406                         unsigned int cipher_len,
2407                         unsigned int cipher_offset)
2408 {
2409         struct crypto_testsuite_params *ts_params = &testsuite_params;
2410         struct crypto_unittest_params *ut_params = &unittest_params;
2411
2412         /* Generate Crypto op data structure */
2413         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2414                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2415         TEST_ASSERT_NOT_NULL(ut_params->op,
2416                                 "Failed to allocate pktmbuf offload");
2417
2418         /* Set crypto operation data parameters */
2419         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2420
2421         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2422
2423         /* set crypto operation source mbuf */
2424         sym_op->m_src = ut_params->ibuf;
2425
2426         /* iv */
2427         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2428                         iv, iv_len);
2429         sym_op->cipher.data.length = cipher_len;
2430         sym_op->cipher.data.offset = cipher_offset;
2431         return 0;
2432 }
2433
2434 static int
2435 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2436                         unsigned int cipher_len,
2437                         unsigned int cipher_offset)
2438 {
2439         struct crypto_testsuite_params *ts_params = &testsuite_params;
2440         struct crypto_unittest_params *ut_params = &unittest_params;
2441
2442         /* Generate Crypto op data structure */
2443         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2444                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2445         TEST_ASSERT_NOT_NULL(ut_params->op,
2446                                 "Failed to allocate pktmbuf offload");
2447
2448         /* Set crypto operation data parameters */
2449         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2450
2451         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2452
2453         /* set crypto operation source mbuf */
2454         sym_op->m_src = ut_params->ibuf;
2455         sym_op->m_dst = ut_params->obuf;
2456
2457         /* iv */
2458         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2459                         iv, iv_len);
2460         sym_op->cipher.data.length = cipher_len;
2461         sym_op->cipher.data.offset = cipher_offset;
2462         return 0;
2463 }
2464
2465 static int
2466 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2467                 enum rte_crypto_cipher_operation cipher_op,
2468                 enum rte_crypto_auth_operation auth_op,
2469                 enum rte_crypto_auth_algorithm auth_algo,
2470                 enum rte_crypto_cipher_algorithm cipher_algo,
2471                 const uint8_t *key, uint8_t key_len,
2472                 uint8_t auth_iv_len, uint8_t auth_len,
2473                 uint8_t cipher_iv_len)
2474
2475 {
2476         uint8_t cipher_auth_key[key_len];
2477         int status;
2478
2479         struct crypto_testsuite_params *ts_params = &testsuite_params;
2480         struct crypto_unittest_params *ut_params = &unittest_params;
2481
2482         memcpy(cipher_auth_key, key, key_len);
2483
2484         /* Setup Authentication Parameters */
2485         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2486         ut_params->auth_xform.next = NULL;
2487
2488         ut_params->auth_xform.auth.op = auth_op;
2489         ut_params->auth_xform.auth.algo = auth_algo;
2490         ut_params->auth_xform.auth.key.length = key_len;
2491         /* Hash key = cipher key */
2492         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2493         ut_params->auth_xform.auth.digest_length = auth_len;
2494         /* Auth IV will be after cipher IV */
2495         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2496         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2497
2498         /* Setup Cipher Parameters */
2499         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2500         ut_params->cipher_xform.next = &ut_params->auth_xform;
2501
2502         ut_params->cipher_xform.cipher.algo = cipher_algo;
2503         ut_params->cipher_xform.cipher.op = cipher_op;
2504         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2505         ut_params->cipher_xform.cipher.key.length = key_len;
2506         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2507         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2508
2509         debug_hexdump(stdout, "key:", key, key_len);
2510
2511         /* Create Crypto session*/
2512         ut_params->sess = rte_cryptodev_sym_session_create(
2513                         ts_params->session_mpool);
2514         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2515
2516         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2517                         &ut_params->cipher_xform,
2518                         ts_params->session_priv_mpool);
2519         if (status == -ENOTSUP)
2520                 return TEST_SKIPPED;
2521
2522         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2523         return 0;
2524 }
2525
2526 static int
2527 create_wireless_cipher_auth_session(uint8_t dev_id,
2528                 enum rte_crypto_cipher_operation cipher_op,
2529                 enum rte_crypto_auth_operation auth_op,
2530                 enum rte_crypto_auth_algorithm auth_algo,
2531                 enum rte_crypto_cipher_algorithm cipher_algo,
2532                 const struct wireless_test_data *tdata)
2533 {
2534         const uint8_t key_len = tdata->key.len;
2535         uint8_t cipher_auth_key[key_len];
2536         int status;
2537
2538         struct crypto_testsuite_params *ts_params = &testsuite_params;
2539         struct crypto_unittest_params *ut_params = &unittest_params;
2540         const uint8_t *key = tdata->key.data;
2541         const uint8_t auth_len = tdata->digest.len;
2542         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2543         uint8_t auth_iv_len = tdata->auth_iv.len;
2544
2545         memcpy(cipher_auth_key, key, key_len);
2546
2547         /* Setup Authentication Parameters */
2548         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2549         ut_params->auth_xform.next = NULL;
2550
2551         ut_params->auth_xform.auth.op = auth_op;
2552         ut_params->auth_xform.auth.algo = auth_algo;
2553         ut_params->auth_xform.auth.key.length = key_len;
2554         /* Hash key = cipher key */
2555         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2556         ut_params->auth_xform.auth.digest_length = auth_len;
2557         /* Auth IV will be after cipher IV */
2558         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2559         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2560
2561         /* Setup Cipher Parameters */
2562         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2563         ut_params->cipher_xform.next = &ut_params->auth_xform;
2564
2565         ut_params->cipher_xform.cipher.algo = cipher_algo;
2566         ut_params->cipher_xform.cipher.op = cipher_op;
2567         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2568         ut_params->cipher_xform.cipher.key.length = key_len;
2569         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2570         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2571
2572
2573         debug_hexdump(stdout, "key:", key, key_len);
2574
2575         /* Create Crypto session*/
2576         ut_params->sess = rte_cryptodev_sym_session_create(
2577                         ts_params->session_mpool);
2578
2579         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2580                         &ut_params->cipher_xform,
2581                         ts_params->session_priv_mpool);
2582         if (status == -ENOTSUP)
2583                 return TEST_SKIPPED;
2584
2585         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2586         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2587         return 0;
2588 }
2589
2590 static int
2591 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2592                 const struct wireless_test_data *tdata)
2593 {
2594         return create_wireless_cipher_auth_session(dev_id,
2595                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2596                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2597                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2598 }
2599
2600 static int
2601 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2602                 enum rte_crypto_cipher_operation cipher_op,
2603                 enum rte_crypto_auth_operation auth_op,
2604                 enum rte_crypto_auth_algorithm auth_algo,
2605                 enum rte_crypto_cipher_algorithm cipher_algo,
2606                 const uint8_t *key, const uint8_t key_len,
2607                 uint8_t auth_iv_len, uint8_t auth_len,
2608                 uint8_t cipher_iv_len)
2609 {
2610         uint8_t auth_cipher_key[key_len];
2611         int status;
2612         struct crypto_testsuite_params *ts_params = &testsuite_params;
2613         struct crypto_unittest_params *ut_params = &unittest_params;
2614
2615         memcpy(auth_cipher_key, key, key_len);
2616
2617         /* Setup Authentication Parameters */
2618         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2619         ut_params->auth_xform.auth.op = auth_op;
2620         ut_params->auth_xform.next = &ut_params->cipher_xform;
2621         ut_params->auth_xform.auth.algo = auth_algo;
2622         ut_params->auth_xform.auth.key.length = key_len;
2623         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2624         ut_params->auth_xform.auth.digest_length = auth_len;
2625         /* Auth IV will be after cipher IV */
2626         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2627         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2628
2629         /* Setup Cipher Parameters */
2630         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2631         ut_params->cipher_xform.next = NULL;
2632         ut_params->cipher_xform.cipher.algo = cipher_algo;
2633         ut_params->cipher_xform.cipher.op = cipher_op;
2634         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2635         ut_params->cipher_xform.cipher.key.length = key_len;
2636         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2637         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2638
2639         debug_hexdump(stdout, "key:", key, key_len);
2640
2641         /* Create Crypto session*/
2642         ut_params->sess = rte_cryptodev_sym_session_create(
2643                         ts_params->session_mpool);
2644         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2645
2646         if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2647                 ut_params->auth_xform.next = NULL;
2648                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2649                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2650                                 &ut_params->cipher_xform,
2651                                 ts_params->session_priv_mpool);
2652
2653         } else
2654                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2655                                 &ut_params->auth_xform,
2656                                 ts_params->session_priv_mpool);
2657
2658         if (status == -ENOTSUP)
2659                 return TEST_SKIPPED;
2660
2661         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2662
2663         return 0;
2664 }
2665
2666 static int
2667 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2668                 unsigned int auth_tag_len,
2669                 const uint8_t *iv, unsigned int iv_len,
2670                 unsigned int data_pad_len,
2671                 enum rte_crypto_auth_operation op,
2672                 unsigned int auth_len, unsigned int auth_offset)
2673 {
2674         struct crypto_testsuite_params *ts_params = &testsuite_params;
2675
2676         struct crypto_unittest_params *ut_params = &unittest_params;
2677
2678         /* Generate Crypto op data structure */
2679         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2680                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2681         TEST_ASSERT_NOT_NULL(ut_params->op,
2682                 "Failed to allocate pktmbuf offload");
2683
2684         /* Set crypto operation data parameters */
2685         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2686
2687         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2688
2689         /* set crypto operation source mbuf */
2690         sym_op->m_src = ut_params->ibuf;
2691
2692         /* iv */
2693         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2694                         iv, iv_len);
2695         /* digest */
2696         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2697                                         ut_params->ibuf, auth_tag_len);
2698
2699         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2700                                 "no room to append auth tag");
2701         ut_params->digest = sym_op->auth.digest.data;
2702         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2703                         ut_params->ibuf, data_pad_len);
2704         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2705                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2706         else
2707                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2708
2709         debug_hexdump(stdout, "digest:",
2710                 sym_op->auth.digest.data,
2711                 auth_tag_len);
2712
2713         sym_op->auth.data.length = auth_len;
2714         sym_op->auth.data.offset = auth_offset;
2715
2716         return 0;
2717 }
2718
2719 static int
2720 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2721         enum rte_crypto_auth_operation op)
2722 {
2723         struct crypto_testsuite_params *ts_params = &testsuite_params;
2724         struct crypto_unittest_params *ut_params = &unittest_params;
2725
2726         const uint8_t *auth_tag = tdata->digest.data;
2727         const unsigned int auth_tag_len = tdata->digest.len;
2728         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2729         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2730
2731         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2732         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2733         const uint8_t *auth_iv = tdata->auth_iv.data;
2734         const uint8_t auth_iv_len = tdata->auth_iv.len;
2735         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2736         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2737
2738         /* Generate Crypto op data structure */
2739         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2740                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2741         TEST_ASSERT_NOT_NULL(ut_params->op,
2742                         "Failed to allocate pktmbuf offload");
2743         /* Set crypto operation data parameters */
2744         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2745
2746         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2747
2748         /* set crypto operation source mbuf */
2749         sym_op->m_src = ut_params->ibuf;
2750
2751         /* digest */
2752         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2753                         ut_params->ibuf, auth_tag_len);
2754
2755         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2756                         "no room to append auth tag");
2757         ut_params->digest = sym_op->auth.digest.data;
2758         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2759                         ut_params->ibuf, data_pad_len);
2760         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2761                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2762         else
2763                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2764
2765         debug_hexdump(stdout, "digest:",
2766                 sym_op->auth.digest.data,
2767                 auth_tag_len);
2768
2769         /* Copy cipher and auth IVs at the end of the crypto operation */
2770         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2771                                                 IV_OFFSET);
2772         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2773         iv_ptr += cipher_iv_len;
2774         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2775
2776         sym_op->cipher.data.length = cipher_len;
2777         sym_op->cipher.data.offset = 0;
2778         sym_op->auth.data.length = auth_len;
2779         sym_op->auth.data.offset = 0;
2780
2781         return 0;
2782 }
2783
2784 static int
2785 create_zuc_cipher_hash_generate_operation(
2786                 const struct wireless_test_data *tdata)
2787 {
2788         return create_wireless_cipher_hash_operation(tdata,
2789                 RTE_CRYPTO_AUTH_OP_GENERATE);
2790 }
2791
2792 static int
2793 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2794                 const unsigned auth_tag_len,
2795                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2796                 unsigned data_pad_len,
2797                 enum rte_crypto_auth_operation op,
2798                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2799                 const unsigned cipher_len, const unsigned cipher_offset,
2800                 const unsigned auth_len, const unsigned auth_offset)
2801 {
2802         struct crypto_testsuite_params *ts_params = &testsuite_params;
2803         struct crypto_unittest_params *ut_params = &unittest_params;
2804
2805         enum rte_crypto_cipher_algorithm cipher_algo =
2806                         ut_params->cipher_xform.cipher.algo;
2807         enum rte_crypto_auth_algorithm auth_algo =
2808                         ut_params->auth_xform.auth.algo;
2809
2810         /* Generate Crypto op data structure */
2811         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2812                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2813         TEST_ASSERT_NOT_NULL(ut_params->op,
2814                         "Failed to allocate pktmbuf offload");
2815         /* Set crypto operation data parameters */
2816         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2817
2818         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2819
2820         /* set crypto operation source mbuf */
2821         sym_op->m_src = ut_params->ibuf;
2822
2823         /* digest */
2824         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2825                         ut_params->ibuf, auth_tag_len);
2826
2827         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2828                         "no room to append auth tag");
2829         ut_params->digest = sym_op->auth.digest.data;
2830
2831         if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2832                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2833                                 ut_params->ibuf, data_pad_len);
2834         } else {
2835                 struct rte_mbuf *m = ut_params->ibuf;
2836                 unsigned int offset = data_pad_len;
2837
2838                 while (offset > m->data_len && m->next != NULL) {
2839                         offset -= m->data_len;
2840                         m = m->next;
2841                 }
2842                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2843                         m, offset);
2844         }
2845
2846         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2847                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2848         else
2849                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2850
2851         debug_hexdump(stdout, "digest:",
2852                 sym_op->auth.digest.data,
2853                 auth_tag_len);
2854
2855         /* Copy cipher and auth IVs at the end of the crypto operation */
2856         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2857                                                 IV_OFFSET);
2858         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2859         iv_ptr += cipher_iv_len;
2860         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2861
2862         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2863                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2864                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2865                 sym_op->cipher.data.length = cipher_len;
2866                 sym_op->cipher.data.offset = cipher_offset;
2867         } else {
2868                 sym_op->cipher.data.length = cipher_len >> 3;
2869                 sym_op->cipher.data.offset = cipher_offset >> 3;
2870         }
2871
2872         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2873                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2874                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2875                 sym_op->auth.data.length = auth_len;
2876                 sym_op->auth.data.offset = auth_offset;
2877         } else {
2878                 sym_op->auth.data.length = auth_len >> 3;
2879                 sym_op->auth.data.offset = auth_offset >> 3;
2880         }
2881
2882         return 0;
2883 }
2884
2885 static int
2886 create_wireless_algo_auth_cipher_operation(
2887                 const uint8_t *auth_tag, unsigned int auth_tag_len,
2888                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2889                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2890                 unsigned int data_pad_len,
2891                 unsigned int cipher_len, unsigned int cipher_offset,
2892                 unsigned int auth_len, unsigned int auth_offset,
2893                 uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2894 {
2895         struct crypto_testsuite_params *ts_params = &testsuite_params;
2896         struct crypto_unittest_params *ut_params = &unittest_params;
2897
2898         enum rte_crypto_cipher_algorithm cipher_algo =
2899                         ut_params->cipher_xform.cipher.algo;
2900         enum rte_crypto_auth_algorithm auth_algo =
2901                         ut_params->auth_xform.auth.algo;
2902
2903         /* Generate Crypto op data structure */
2904         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2905                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2906         TEST_ASSERT_NOT_NULL(ut_params->op,
2907                         "Failed to allocate pktmbuf offload");
2908
2909         /* Set crypto operation data parameters */
2910         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2911
2912         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2913
2914         /* set crypto operation mbufs */
2915         sym_op->m_src = ut_params->ibuf;
2916         if (op_mode == OUT_OF_PLACE)
2917                 sym_op->m_dst = ut_params->obuf;
2918
2919         /* digest */
2920         if (!do_sgl) {
2921                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2922                         (op_mode == IN_PLACE ?
2923                                 ut_params->ibuf : ut_params->obuf),
2924                         uint8_t *, data_pad_len);
2925                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2926                         (op_mode == IN_PLACE ?
2927                                 ut_params->ibuf : ut_params->obuf),
2928                         data_pad_len);
2929                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2930         } else {
2931                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2932                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2933                                 sym_op->m_src : sym_op->m_dst);
2934                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2935                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2936                         sgl_buf = sgl_buf->next;
2937                 }
2938                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2939                                 uint8_t *, remaining_off);
2940                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2941                                 remaining_off);
2942                 memset(sym_op->auth.digest.data, 0, remaining_off);
2943                 while (sgl_buf->next != NULL) {
2944                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2945                                 0, rte_pktmbuf_data_len(sgl_buf));
2946                         sgl_buf = sgl_buf->next;
2947                 }
2948         }
2949
2950         /* Copy digest for the verification */
2951         if (verify)
2952                 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2953
2954         /* Copy cipher and auth IVs at the end of the crypto operation */
2955         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
2956                         ut_params->op, uint8_t *, IV_OFFSET);
2957
2958         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2959         iv_ptr += cipher_iv_len;
2960         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2961
2962         /* Only copy over the offset data needed from src to dst in OOP,
2963          * if the auth and cipher offsets are not aligned
2964          */
2965         if (op_mode == OUT_OF_PLACE) {
2966                 if (cipher_offset > auth_offset)
2967                         rte_memcpy(
2968                                 rte_pktmbuf_mtod_offset(
2969                                         sym_op->m_dst,
2970                                         uint8_t *, auth_offset >> 3),
2971                                 rte_pktmbuf_mtod_offset(
2972                                         sym_op->m_src,
2973                                         uint8_t *, auth_offset >> 3),
2974                                 ((cipher_offset >> 3) - (auth_offset >> 3)));
2975         }
2976
2977         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2978                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2979                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2980                 sym_op->cipher.data.length = cipher_len;
2981                 sym_op->cipher.data.offset = cipher_offset;
2982         } else {
2983                 sym_op->cipher.data.length = cipher_len >> 3;
2984                 sym_op->cipher.data.offset = cipher_offset >> 3;
2985         }
2986
2987         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2988                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2989                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2990                 sym_op->auth.data.length = auth_len;
2991                 sym_op->auth.data.offset = auth_offset;
2992         } else {
2993                 sym_op->auth.data.length = auth_len >> 3;
2994                 sym_op->auth.data.offset = auth_offset >> 3;
2995         }
2996
2997         return 0;
2998 }
2999
3000 static int
3001 test_snow3g_authentication(const struct snow3g_hash_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         unsigned plaintext_pad_len;
3008         unsigned plaintext_len;
3009         uint8_t *plaintext;
3010         struct rte_cryptodev_info dev_info;
3011
3012         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3013         uint64_t feat_flags = dev_info.feature_flags;
3014
3015         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3016                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3017                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3018                 return TEST_SKIPPED;
3019         }
3020
3021         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3022                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3023                 printf("Device doesn't support RAW data-path APIs.\n");
3024                 return TEST_SKIPPED;
3025         }
3026
3027         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3028                 return TEST_SKIPPED;
3029
3030         /* Verify the capabilities */
3031         struct rte_cryptodev_sym_capability_idx cap_idx;
3032         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3033         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3034         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3035                         &cap_idx) == NULL)
3036                 return TEST_SKIPPED;
3037
3038         /* Create SNOW 3G session */
3039         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3040                         tdata->key.data, tdata->key.len,
3041                         tdata->auth_iv.len, tdata->digest.len,
3042                         RTE_CRYPTO_AUTH_OP_GENERATE,
3043                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3044         if (retval < 0)
3045                 return retval;
3046
3047         /* alloc mbuf and set payload */
3048         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3049
3050         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3051         rte_pktmbuf_tailroom(ut_params->ibuf));
3052
3053         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3054         /* Append data which is padded to a multiple of */
3055         /* the algorithms block size */
3056         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3057         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3058                                 plaintext_pad_len);
3059         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3060
3061         /* Create SNOW 3G operation */
3062         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3063                         tdata->auth_iv.data, tdata->auth_iv.len,
3064                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3065                         tdata->validAuthLenInBits.len,
3066                         0);
3067         if (retval < 0)
3068                 return retval;
3069
3070         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3071                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3072                                 ut_params->op, 0, 1, 1, 0);
3073         else
3074                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3075                                 ut_params->op);
3076         ut_params->obuf = ut_params->op->sym->m_src;
3077         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3078         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3079                         + plaintext_pad_len;
3080
3081         /* Validate obuf */
3082         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3083         ut_params->digest,
3084         tdata->digest.data,
3085         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3086         "SNOW 3G Generated auth tag not as expected");
3087
3088         return 0;
3089 }
3090
3091 static int
3092 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3093 {
3094         struct crypto_testsuite_params *ts_params = &testsuite_params;
3095         struct crypto_unittest_params *ut_params = &unittest_params;
3096
3097         int retval;
3098         unsigned plaintext_pad_len;
3099         unsigned plaintext_len;
3100         uint8_t *plaintext;
3101         struct rte_cryptodev_info dev_info;
3102
3103         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3104         uint64_t feat_flags = dev_info.feature_flags;
3105
3106         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3107                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3108                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3109                 return TEST_SKIPPED;
3110         }
3111
3112         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3113                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3114                 printf("Device doesn't support RAW data-path APIs.\n");
3115                 return TEST_SKIPPED;
3116         }
3117
3118         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3119                 return TEST_SKIPPED;
3120
3121         /* Verify the capabilities */
3122         struct rte_cryptodev_sym_capability_idx cap_idx;
3123         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3124         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3125         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3126                         &cap_idx) == NULL)
3127                 return TEST_SKIPPED;
3128
3129         /* Create SNOW 3G session */
3130         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3131                                 tdata->key.data, tdata->key.len,
3132                                 tdata->auth_iv.len, tdata->digest.len,
3133                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3134                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3135         if (retval < 0)
3136                 return retval;
3137         /* alloc mbuf and set payload */
3138         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3139
3140         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3141         rte_pktmbuf_tailroom(ut_params->ibuf));
3142
3143         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3144         /* Append data which is padded to a multiple of */
3145         /* the algorithms block size */
3146         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3147         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3148                                 plaintext_pad_len);
3149         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3150
3151         /* Create SNOW 3G operation */
3152         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3153                         tdata->digest.len,
3154                         tdata->auth_iv.data, tdata->auth_iv.len,
3155                         plaintext_pad_len,
3156                         RTE_CRYPTO_AUTH_OP_VERIFY,
3157                         tdata->validAuthLenInBits.len,
3158                         0);
3159         if (retval < 0)
3160                 return retval;
3161
3162         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3163                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3164                                 ut_params->op, 0, 1, 1, 0);
3165         else
3166                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3167                                 ut_params->op);
3168         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3169         ut_params->obuf = ut_params->op->sym->m_src;
3170         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3171                                 + plaintext_pad_len;
3172
3173         /* Validate obuf */
3174         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3175                 return 0;
3176         else
3177                 return -1;
3178
3179         return 0;
3180 }
3181
3182 static int
3183 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3184 {
3185         struct crypto_testsuite_params *ts_params = &testsuite_params;
3186         struct crypto_unittest_params *ut_params = &unittest_params;
3187
3188         int retval;
3189         unsigned plaintext_pad_len;
3190         unsigned plaintext_len;
3191         uint8_t *plaintext;
3192         struct rte_cryptodev_info dev_info;
3193
3194         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3195         uint64_t feat_flags = dev_info.feature_flags;
3196
3197         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3198                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3199                 printf("Device doesn't support RAW data-path APIs.\n");
3200                 return TEST_SKIPPED;
3201         }
3202
3203         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3204                 return TEST_SKIPPED;
3205
3206         /* Verify the capabilities */
3207         struct rte_cryptodev_sym_capability_idx cap_idx;
3208         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3209         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3210         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3211                         &cap_idx) == NULL)
3212                 return TEST_SKIPPED;
3213
3214         /* Create KASUMI session */
3215         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3216                         tdata->key.data, tdata->key.len,
3217                         0, tdata->digest.len,
3218                         RTE_CRYPTO_AUTH_OP_GENERATE,
3219                         RTE_CRYPTO_AUTH_KASUMI_F9);
3220         if (retval < 0)
3221                 return retval;
3222
3223         /* alloc mbuf and set payload */
3224         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3225
3226         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3227         rte_pktmbuf_tailroom(ut_params->ibuf));
3228
3229         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3230         /* Append data which is padded to a multiple of */
3231         /* the algorithms block size */
3232         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3233         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3234                                 plaintext_pad_len);
3235         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3236
3237         /* Create KASUMI operation */
3238         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3239                         NULL, 0,
3240                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3241                         tdata->plaintext.len,
3242                         0);
3243         if (retval < 0)
3244                 return retval;
3245
3246         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3247                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3248                         ut_params->op);
3249         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3250                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3251                                 ut_params->op, 0, 1, 1, 0);
3252         else
3253                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3254                         ut_params->op);
3255
3256         ut_params->obuf = ut_params->op->sym->m_src;
3257         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3258         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3259                         + plaintext_pad_len;
3260
3261         /* Validate obuf */
3262         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3263         ut_params->digest,
3264         tdata->digest.data,
3265         DIGEST_BYTE_LENGTH_KASUMI_F9,
3266         "KASUMI Generated auth tag not as expected");
3267
3268         return 0;
3269 }
3270
3271 static int
3272 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3273 {
3274         struct crypto_testsuite_params *ts_params = &testsuite_params;
3275         struct crypto_unittest_params *ut_params = &unittest_params;
3276
3277         int retval;
3278         unsigned plaintext_pad_len;
3279         unsigned plaintext_len;
3280         uint8_t *plaintext;
3281         struct rte_cryptodev_info dev_info;
3282
3283         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3284         uint64_t feat_flags = dev_info.feature_flags;
3285
3286         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3287                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3288                 printf("Device doesn't support RAW data-path APIs.\n");
3289                 return TEST_SKIPPED;
3290         }
3291
3292         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3293                 return TEST_SKIPPED;
3294
3295         /* Verify the capabilities */
3296         struct rte_cryptodev_sym_capability_idx cap_idx;
3297         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3298         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3299         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3300                         &cap_idx) == NULL)
3301                 return TEST_SKIPPED;
3302
3303         /* Create KASUMI session */
3304         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3305                                 tdata->key.data, tdata->key.len,
3306                                 0, tdata->digest.len,
3307                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3308                                 RTE_CRYPTO_AUTH_KASUMI_F9);
3309         if (retval < 0)
3310                 return retval;
3311         /* alloc mbuf and set payload */
3312         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3313
3314         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3315         rte_pktmbuf_tailroom(ut_params->ibuf));
3316
3317         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3318         /* Append data which is padded to a multiple */
3319         /* of the algorithms block size */
3320         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3321         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3322                                 plaintext_pad_len);
3323         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3324
3325         /* Create KASUMI operation */
3326         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3327                         tdata->digest.len,
3328                         NULL, 0,
3329                         plaintext_pad_len,
3330                         RTE_CRYPTO_AUTH_OP_VERIFY,
3331                         tdata->plaintext.len,
3332                         0);
3333         if (retval < 0)
3334                 return retval;
3335
3336         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3337                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3338                                 ut_params->op, 0, 1, 1, 0);
3339         else
3340                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3341                                 ut_params->op);
3342         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3343         ut_params->obuf = ut_params->op->sym->m_src;
3344         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3345                                 + plaintext_pad_len;
3346
3347         /* Validate obuf */
3348         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3349                 return 0;
3350         else
3351                 return -1;
3352
3353         return 0;
3354 }
3355
3356 static int
3357 test_snow3g_hash_generate_test_case_1(void)
3358 {
3359         return test_snow3g_authentication(&snow3g_hash_test_case_1);
3360 }
3361
3362 static int
3363 test_snow3g_hash_generate_test_case_2(void)
3364 {
3365         return test_snow3g_authentication(&snow3g_hash_test_case_2);
3366 }
3367
3368 static int
3369 test_snow3g_hash_generate_test_case_3(void)
3370 {
3371         return test_snow3g_authentication(&snow3g_hash_test_case_3);
3372 }
3373
3374 static int
3375 test_snow3g_hash_generate_test_case_4(void)
3376 {
3377         return test_snow3g_authentication(&snow3g_hash_test_case_4);
3378 }
3379
3380 static int
3381 test_snow3g_hash_generate_test_case_5(void)
3382 {
3383         return test_snow3g_authentication(&snow3g_hash_test_case_5);
3384 }
3385
3386 static int
3387 test_snow3g_hash_generate_test_case_6(void)
3388 {
3389         return test_snow3g_authentication(&snow3g_hash_test_case_6);
3390 }
3391
3392 static int
3393 test_snow3g_hash_verify_test_case_1(void)
3394 {
3395         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3396
3397 }
3398
3399 static int
3400 test_snow3g_hash_verify_test_case_2(void)
3401 {
3402         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3403 }
3404
3405 static int
3406 test_snow3g_hash_verify_test_case_3(void)
3407 {
3408         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3409 }
3410
3411 static int
3412 test_snow3g_hash_verify_test_case_4(void)
3413 {
3414         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3415 }
3416
3417 static int
3418 test_snow3g_hash_verify_test_case_5(void)
3419 {
3420         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3421 }
3422
3423 static int
3424 test_snow3g_hash_verify_test_case_6(void)
3425 {
3426         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3427 }
3428
3429 static int
3430 test_kasumi_hash_generate_test_case_1(void)
3431 {
3432         return test_kasumi_authentication(&kasumi_hash_test_case_1);
3433 }
3434
3435 static int
3436 test_kasumi_hash_generate_test_case_2(void)
3437 {
3438         return test_kasumi_authentication(&kasumi_hash_test_case_2);
3439 }
3440
3441 static int
3442 test_kasumi_hash_generate_test_case_3(void)
3443 {
3444         return test_kasumi_authentication(&kasumi_hash_test_case_3);
3445 }
3446
3447 static int
3448 test_kasumi_hash_generate_test_case_4(void)
3449 {
3450         return test_kasumi_authentication(&kasumi_hash_test_case_4);
3451 }
3452
3453 static int
3454 test_kasumi_hash_generate_test_case_5(void)
3455 {
3456         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3457 }
3458
3459 static int
3460 test_kasumi_hash_generate_test_case_6(void)
3461 {
3462         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3463 }
3464
3465 static int
3466 test_kasumi_hash_verify_test_case_1(void)
3467 {
3468         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3469 }
3470
3471 static int
3472 test_kasumi_hash_verify_test_case_2(void)
3473 {
3474         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3475 }
3476
3477 static int
3478 test_kasumi_hash_verify_test_case_3(void)
3479 {
3480         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3481 }
3482
3483 static int
3484 test_kasumi_hash_verify_test_case_4(void)
3485 {
3486         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3487 }
3488
3489 static int
3490 test_kasumi_hash_verify_test_case_5(void)
3491 {
3492         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3493 }
3494
3495 static int
3496 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3497 {
3498         struct crypto_testsuite_params *ts_params = &testsuite_params;
3499         struct crypto_unittest_params *ut_params = &unittest_params;
3500
3501         int retval;
3502         uint8_t *plaintext, *ciphertext;
3503         unsigned plaintext_pad_len;
3504         unsigned plaintext_len;
3505         struct rte_cryptodev_info dev_info;
3506
3507         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3508         uint64_t feat_flags = dev_info.feature_flags;
3509
3510         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3511                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3512                 printf("Device doesn't support RAW data-path APIs.\n");
3513                 return TEST_SKIPPED;
3514         }
3515
3516         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3517                 return TEST_SKIPPED;
3518
3519         /* Verify the capabilities */
3520         struct rte_cryptodev_sym_capability_idx cap_idx;
3521         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3522         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3523         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3524                         &cap_idx) == NULL)
3525                 return TEST_SKIPPED;
3526
3527         /* Create KASUMI session */
3528         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3529                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3530                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3531                                         tdata->key.data, tdata->key.len,
3532                                         tdata->cipher_iv.len);
3533         if (retval < 0)
3534                 return retval;
3535
3536         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3537
3538         /* Clear mbuf payload */
3539         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3540                rte_pktmbuf_tailroom(ut_params->ibuf));
3541
3542         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3543         /* Append data which is padded to a multiple */
3544         /* of the algorithms block size */
3545         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3546         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3547                                 plaintext_pad_len);
3548         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3549
3550         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3551
3552         /* Create KASUMI operation */
3553         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3554                                 tdata->cipher_iv.len,
3555                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3556                                 tdata->validCipherOffsetInBits.len);
3557         if (retval < 0)
3558                 return retval;
3559
3560         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3561                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3562                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3563         else
3564                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3565                                 ut_params->op);
3566         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3567
3568         ut_params->obuf = ut_params->op->sym->m_dst;
3569         if (ut_params->obuf)
3570                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3571         else
3572                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3573
3574         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3575
3576         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3577                                 (tdata->validCipherOffsetInBits.len >> 3);
3578         /* Validate obuf */
3579         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3580                 ciphertext,
3581                 reference_ciphertext,
3582                 tdata->validCipherLenInBits.len,
3583                 "KASUMI Ciphertext data not as expected");
3584         return 0;
3585 }
3586
3587 static int
3588 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3589 {
3590         struct crypto_testsuite_params *ts_params = &testsuite_params;
3591         struct crypto_unittest_params *ut_params = &unittest_params;
3592
3593         int retval;
3594
3595         unsigned int plaintext_pad_len;
3596         unsigned int plaintext_len;
3597
3598         uint8_t buffer[10000];
3599         const uint8_t *ciphertext;
3600
3601         struct rte_cryptodev_info dev_info;
3602
3603         /* Verify the capabilities */
3604         struct rte_cryptodev_sym_capability_idx cap_idx;
3605         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3606         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3607         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3608                         &cap_idx) == NULL)
3609                 return TEST_SKIPPED;
3610
3611         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3612
3613         uint64_t feat_flags = dev_info.feature_flags;
3614
3615         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3616                 printf("Device doesn't support in-place scatter-gather. "
3617                                 "Test Skipped.\n");
3618                 return TEST_SKIPPED;
3619         }
3620
3621         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3622                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3623                 printf("Device doesn't support RAW data-path APIs.\n");
3624                 return TEST_SKIPPED;
3625         }
3626
3627         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3628                 return TEST_SKIPPED;
3629
3630         /* Create KASUMI session */
3631         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3632                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3633                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3634                                         tdata->key.data, tdata->key.len,
3635                                         tdata->cipher_iv.len);
3636         if (retval < 0)
3637                 return retval;
3638
3639         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3640
3641
3642         /* Append data which is padded to a multiple */
3643         /* of the algorithms block size */
3644         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3645
3646         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3647                         plaintext_pad_len, 10, 0);
3648
3649         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3650
3651         /* Create KASUMI operation */
3652         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3653                                 tdata->cipher_iv.len,
3654                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3655                                 tdata->validCipherOffsetInBits.len);
3656         if (retval < 0)
3657                 return retval;
3658
3659         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3660                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3661                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3662         else
3663                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3664                                                 ut_params->op);
3665         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3666
3667         ut_params->obuf = ut_params->op->sym->m_dst;
3668
3669         if (ut_params->obuf)
3670                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3671                                 plaintext_len, buffer);
3672         else
3673                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3674                                 tdata->validCipherOffsetInBits.len >> 3,
3675                                 plaintext_len, buffer);
3676
3677         /* Validate obuf */
3678         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3679
3680         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3681                                 (tdata->validCipherOffsetInBits.len >> 3);
3682         /* Validate obuf */
3683         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3684                 ciphertext,
3685                 reference_ciphertext,
3686                 tdata->validCipherLenInBits.len,
3687                 "KASUMI Ciphertext data not as expected");
3688         return 0;
3689 }
3690
3691 static int
3692 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3693 {
3694         struct crypto_testsuite_params *ts_params = &testsuite_params;
3695         struct crypto_unittest_params *ut_params = &unittest_params;
3696
3697         int retval;
3698         uint8_t *plaintext, *ciphertext;
3699         unsigned plaintext_pad_len;
3700         unsigned plaintext_len;
3701
3702         /* Verify the capabilities */
3703         struct rte_cryptodev_sym_capability_idx cap_idx;
3704         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3705         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3706         /* Data-path service does not support OOP */
3707         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3708                         &cap_idx) == NULL)
3709                 return TEST_SKIPPED;
3710
3711         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3712                 return TEST_SKIPPED;
3713
3714         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3715                 return TEST_SKIPPED;
3716
3717         /* Create KASUMI session */
3718         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3719                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3720                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3721                                         tdata->key.data, tdata->key.len,
3722                                         tdata->cipher_iv.len);
3723         if (retval < 0)
3724                 return retval;
3725
3726         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3727         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3728
3729         /* Clear mbuf payload */
3730         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3731                rte_pktmbuf_tailroom(ut_params->ibuf));
3732
3733         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3734         /* Append data which is padded to a multiple */
3735         /* of the algorithms block size */
3736         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3737         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3738                                 plaintext_pad_len);
3739         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3740         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3741
3742         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3743
3744         /* Create KASUMI operation */
3745         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3746                                 tdata->cipher_iv.len,
3747                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3748                                 tdata->validCipherOffsetInBits.len);
3749         if (retval < 0)
3750                 return retval;
3751
3752         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3753                                                 ut_params->op);
3754         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3755
3756         ut_params->obuf = ut_params->op->sym->m_dst;
3757         if (ut_params->obuf)
3758                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3759         else
3760                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3761
3762         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3763
3764         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3765                                 (tdata->validCipherOffsetInBits.len >> 3);
3766         /* Validate obuf */
3767         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3768                 ciphertext,
3769                 reference_ciphertext,
3770                 tdata->validCipherLenInBits.len,
3771                 "KASUMI Ciphertext data not as expected");
3772         return 0;
3773 }
3774
3775 static int
3776 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3777 {
3778         struct crypto_testsuite_params *ts_params = &testsuite_params;
3779         struct crypto_unittest_params *ut_params = &unittest_params;
3780
3781         int retval;
3782         unsigned int plaintext_pad_len;
3783         unsigned int plaintext_len;
3784
3785         const uint8_t *ciphertext;
3786         uint8_t buffer[2048];
3787
3788         struct rte_cryptodev_info dev_info;
3789
3790         /* Verify the capabilities */
3791         struct rte_cryptodev_sym_capability_idx cap_idx;
3792         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3793         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3794         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3795                         &cap_idx) == NULL)
3796                 return TEST_SKIPPED;
3797
3798         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3799                 return TEST_SKIPPED;
3800
3801         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3802                 return TEST_SKIPPED;
3803
3804         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3805
3806         uint64_t feat_flags = dev_info.feature_flags;
3807         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3808                 printf("Device doesn't support out-of-place scatter-gather "
3809                                 "in both input and output mbufs. "
3810                                 "Test Skipped.\n");
3811                 return TEST_SKIPPED;
3812         }
3813
3814         /* Create KASUMI session */
3815         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3816                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3817                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3818                                         tdata->key.data, tdata->key.len,
3819                                         tdata->cipher_iv.len);
3820         if (retval < 0)
3821                 return retval;
3822
3823         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3824         /* Append data which is padded to a multiple */
3825         /* of the algorithms block size */
3826         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3827
3828         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3829                         plaintext_pad_len, 10, 0);
3830         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3831                         plaintext_pad_len, 3, 0);
3832
3833         /* Append data which is padded to a multiple */
3834         /* of the algorithms block size */
3835         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3836
3837         /* Create KASUMI operation */
3838         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3839                                 tdata->cipher_iv.len,
3840                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3841                                 tdata->validCipherOffsetInBits.len);
3842         if (retval < 0)
3843                 return retval;
3844
3845         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3846                                                 ut_params->op);
3847         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3848
3849         ut_params->obuf = ut_params->op->sym->m_dst;
3850         if (ut_params->obuf)
3851                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3852                                 plaintext_pad_len, buffer);
3853         else
3854                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3855                                 tdata->validCipherOffsetInBits.len >> 3,
3856                                 plaintext_pad_len, buffer);
3857
3858         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3859                                 (tdata->validCipherOffsetInBits.len >> 3);
3860         /* Validate obuf */
3861         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3862                 ciphertext,
3863                 reference_ciphertext,
3864                 tdata->validCipherLenInBits.len,
3865                 "KASUMI Ciphertext data not as expected");
3866         return 0;
3867 }
3868
3869
3870 static int
3871 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3872 {
3873         struct crypto_testsuite_params *ts_params = &testsuite_params;
3874         struct crypto_unittest_params *ut_params = &unittest_params;
3875
3876         int retval;
3877         uint8_t *ciphertext, *plaintext;
3878         unsigned ciphertext_pad_len;
3879         unsigned ciphertext_len;
3880
3881         /* Verify the capabilities */
3882         struct rte_cryptodev_sym_capability_idx cap_idx;
3883         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3884         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3885         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3886                         &cap_idx) == NULL)
3887                 return TEST_SKIPPED;
3888
3889         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3890                 return TEST_SKIPPED;
3891
3892         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3893                 return TEST_SKIPPED;
3894
3895         /* Create KASUMI session */
3896         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3897                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3898                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3899                                         tdata->key.data, tdata->key.len,
3900                                         tdata->cipher_iv.len);
3901         if (retval < 0)
3902                 return retval;
3903
3904         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3905         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3906
3907         /* Clear mbuf payload */
3908         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3909                rte_pktmbuf_tailroom(ut_params->ibuf));
3910
3911         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3912         /* Append data which is padded to a multiple */
3913         /* of the algorithms block size */
3914         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3915         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3916                                 ciphertext_pad_len);
3917         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3918         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3919
3920         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3921
3922         /* Create KASUMI operation */
3923         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3924                                 tdata->cipher_iv.len,
3925                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3926                                 tdata->validCipherOffsetInBits.len);
3927         if (retval < 0)
3928                 return retval;
3929
3930         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3931                                                 ut_params->op);
3932         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3933
3934         ut_params->obuf = ut_params->op->sym->m_dst;
3935         if (ut_params->obuf)
3936                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3937         else
3938                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3939
3940         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3941
3942         const uint8_t *reference_plaintext = tdata->plaintext.data +
3943                                 (tdata->validCipherOffsetInBits.len >> 3);
3944         /* Validate obuf */
3945         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3946                 plaintext,
3947                 reference_plaintext,
3948                 tdata->validCipherLenInBits.len,
3949                 "KASUMI Plaintext data not as expected");
3950         return 0;
3951 }
3952
3953 static int
3954 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3955 {
3956         struct crypto_testsuite_params *ts_params = &testsuite_params;
3957         struct crypto_unittest_params *ut_params = &unittest_params;
3958
3959         int retval;
3960         uint8_t *ciphertext, *plaintext;
3961         unsigned ciphertext_pad_len;
3962         unsigned ciphertext_len;
3963         struct rte_cryptodev_info dev_info;
3964
3965         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3966         uint64_t feat_flags = dev_info.feature_flags;
3967
3968         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3969                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3970                 printf("Device doesn't support RAW data-path APIs.\n");
3971                 return TEST_SKIPPED;
3972         }
3973
3974         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3975                 return TEST_SKIPPED;
3976
3977         /* Verify the capabilities */
3978         struct rte_cryptodev_sym_capability_idx cap_idx;
3979         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3980         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3981         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3982                         &cap_idx) == NULL)
3983                 return TEST_SKIPPED;
3984
3985         /* Create KASUMI session */
3986         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3987                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3988                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3989                                         tdata->key.data, tdata->key.len,
3990                                         tdata->cipher_iv.len);
3991         if (retval < 0)
3992                 return retval;
3993
3994         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3995
3996         /* Clear mbuf payload */
3997         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3998                rte_pktmbuf_tailroom(ut_params->ibuf));
3999
4000         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4001         /* Append data which is padded to a multiple */
4002         /* of the algorithms block size */
4003         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4004         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4005                                 ciphertext_pad_len);
4006         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4007
4008         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4009
4010         /* Create KASUMI operation */
4011         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4012                                         tdata->cipher_iv.len,
4013                                         tdata->ciphertext.len,
4014                                         tdata->validCipherOffsetInBits.len);
4015         if (retval < 0)
4016                 return retval;
4017
4018         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4019                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4020                                 ut_params->op, 1, 0, 1, 0);
4021         else
4022                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4023                                                 ut_params->op);
4024         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4025
4026         ut_params->obuf = ut_params->op->sym->m_dst;
4027         if (ut_params->obuf)
4028                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4029         else
4030                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4031
4032         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4033
4034         const uint8_t *reference_plaintext = tdata->plaintext.data +
4035                                 (tdata->validCipherOffsetInBits.len >> 3);
4036         /* Validate obuf */
4037         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4038                 plaintext,
4039                 reference_plaintext,
4040                 tdata->validCipherLenInBits.len,
4041                 "KASUMI Plaintext data not as expected");
4042         return 0;
4043 }
4044
4045 static int
4046 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4047 {
4048         struct crypto_testsuite_params *ts_params = &testsuite_params;
4049         struct crypto_unittest_params *ut_params = &unittest_params;
4050
4051         int retval;
4052         uint8_t *plaintext, *ciphertext;
4053         unsigned plaintext_pad_len;
4054         unsigned plaintext_len;
4055         struct rte_cryptodev_info dev_info;
4056
4057         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4058         uint64_t feat_flags = dev_info.feature_flags;
4059
4060         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4061                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4062                 printf("Device doesn't support RAW data-path APIs.\n");
4063                 return TEST_SKIPPED;
4064         }
4065
4066         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4067                 return TEST_SKIPPED;
4068
4069         /* Verify the capabilities */
4070         struct rte_cryptodev_sym_capability_idx cap_idx;
4071         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4072         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4073         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4074                         &cap_idx) == NULL)
4075                 return TEST_SKIPPED;
4076
4077         /* Create SNOW 3G session */
4078         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4079                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4080                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4081                                         tdata->key.data, tdata->key.len,
4082                                         tdata->cipher_iv.len);
4083         if (retval < 0)
4084                 return retval;
4085
4086         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4087
4088         /* Clear mbuf payload */
4089         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4090                rte_pktmbuf_tailroom(ut_params->ibuf));
4091
4092         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4093         /* Append data which is padded to a multiple of */
4094         /* the algorithms block size */
4095         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4096         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4097                                 plaintext_pad_len);
4098         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4099
4100         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4101
4102         /* Create SNOW 3G operation */
4103         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4104                                         tdata->cipher_iv.len,
4105                                         tdata->validCipherLenInBits.len,
4106                                         0);
4107         if (retval < 0)
4108                 return retval;
4109
4110         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4111                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4112                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4113         else
4114                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4115                                                 ut_params->op);
4116         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4117
4118         ut_params->obuf = ut_params->op->sym->m_dst;
4119         if (ut_params->obuf)
4120                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4121         else
4122                 ciphertext = plaintext;
4123
4124         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4125
4126         /* Validate obuf */
4127         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4128                 ciphertext,
4129                 tdata->ciphertext.data,
4130                 tdata->validDataLenInBits.len,
4131                 "SNOW 3G Ciphertext data not as expected");
4132         return 0;
4133 }
4134
4135
4136 static int
4137 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4138 {
4139         struct crypto_testsuite_params *ts_params = &testsuite_params;
4140         struct crypto_unittest_params *ut_params = &unittest_params;
4141         uint8_t *plaintext, *ciphertext;
4142
4143         int retval;
4144         unsigned plaintext_pad_len;
4145         unsigned plaintext_len;
4146
4147         /* Verify the capabilities */
4148         struct rte_cryptodev_sym_capability_idx cap_idx;
4149         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4150         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4151         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4152                         &cap_idx) == NULL)
4153                 return TEST_SKIPPED;
4154
4155         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4156                 return TEST_SKIPPED;
4157
4158         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4159                 return TEST_SKIPPED;
4160
4161         /* Create SNOW 3G session */
4162         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4163                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4164                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4165                                         tdata->key.data, tdata->key.len,
4166                                         tdata->cipher_iv.len);
4167         if (retval < 0)
4168                 return retval;
4169
4170         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4171         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4172
4173         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4174                         "Failed to allocate input buffer in mempool");
4175         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4176                         "Failed to allocate output buffer in mempool");
4177
4178         /* Clear mbuf payload */
4179         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4180                rte_pktmbuf_tailroom(ut_params->ibuf));
4181
4182         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4183         /* Append data which is padded to a multiple of */
4184         /* the algorithms block size */
4185         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4186         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4187                                 plaintext_pad_len);
4188         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4189         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4190
4191         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4192
4193         /* Create SNOW 3G operation */
4194         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4195                                         tdata->cipher_iv.len,
4196                                         tdata->validCipherLenInBits.len,
4197                                         0);
4198         if (retval < 0)
4199                 return retval;
4200
4201         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4202                                                 ut_params->op);
4203         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4204
4205         ut_params->obuf = ut_params->op->sym->m_dst;
4206         if (ut_params->obuf)
4207                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4208         else
4209                 ciphertext = plaintext;
4210
4211         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4212
4213         /* Validate obuf */
4214         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4215                 ciphertext,
4216                 tdata->ciphertext.data,
4217                 tdata->validDataLenInBits.len,
4218                 "SNOW 3G Ciphertext data not as expected");
4219         return 0;
4220 }
4221
4222 static int
4223 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4224 {
4225         struct crypto_testsuite_params *ts_params = &testsuite_params;
4226         struct crypto_unittest_params *ut_params = &unittest_params;
4227
4228         int retval;
4229         unsigned int plaintext_pad_len;
4230         unsigned int plaintext_len;
4231         uint8_t buffer[10000];
4232         const uint8_t *ciphertext;
4233
4234         struct rte_cryptodev_info dev_info;
4235
4236         /* Verify the capabilities */
4237         struct rte_cryptodev_sym_capability_idx cap_idx;
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 TEST_SKIPPED;
4243
4244         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4245                 return TEST_SKIPPED;
4246
4247         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4248                 return TEST_SKIPPED;
4249
4250         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4251
4252         uint64_t feat_flags = dev_info.feature_flags;
4253
4254         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4255                 printf("Device doesn't support out-of-place scatter-gather "
4256                                 "in both input and output mbufs. "
4257                                 "Test Skipped.\n");
4258                 return TEST_SKIPPED;
4259         }
4260
4261         /* Create SNOW 3G session */
4262         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4263                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4264                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4265                                         tdata->key.data, tdata->key.len,
4266                                         tdata->cipher_iv.len);
4267         if (retval < 0)
4268                 return retval;
4269
4270         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4271         /* Append data which is padded to a multiple of */
4272         /* the algorithms block size */
4273         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4274
4275         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4276                         plaintext_pad_len, 10, 0);
4277         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4278                         plaintext_pad_len, 3, 0);
4279
4280         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4281                         "Failed to allocate input buffer in mempool");
4282         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4283                         "Failed to allocate output buffer in mempool");
4284
4285         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4286
4287         /* Create SNOW 3G operation */
4288         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4289                                         tdata->cipher_iv.len,
4290                                         tdata->validCipherLenInBits.len,
4291                                         0);
4292         if (retval < 0)
4293                 return retval;
4294
4295         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4296                                                 ut_params->op);
4297         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4298
4299         ut_params->obuf = ut_params->op->sym->m_dst;
4300         if (ut_params->obuf)
4301                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4302                                 plaintext_len, buffer);
4303         else
4304                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4305                                 plaintext_len, buffer);
4306
4307         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4308
4309         /* Validate obuf */
4310         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4311                 ciphertext,
4312                 tdata->ciphertext.data,
4313                 tdata->validDataLenInBits.len,
4314                 "SNOW 3G Ciphertext data not as expected");
4315
4316         return 0;
4317 }
4318
4319 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4320 static void
4321 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4322 {
4323         uint8_t curr_byte, prev_byte;
4324         uint32_t length_in_bytes = ceil_byte_length(length + offset);
4325         uint8_t lower_byte_mask = (1 << offset) - 1;
4326         unsigned i;
4327
4328         prev_byte = buffer[0];
4329         buffer[0] >>= offset;
4330
4331         for (i = 1; i < length_in_bytes; i++) {
4332                 curr_byte = buffer[i];
4333                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4334                                 (curr_byte >> offset);
4335                 prev_byte = curr_byte;
4336         }
4337 }
4338
4339 static int
4340 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4341 {
4342         struct crypto_testsuite_params *ts_params = &testsuite_params;
4343         struct crypto_unittest_params *ut_params = &unittest_params;
4344         uint8_t *plaintext, *ciphertext;
4345         int retval;
4346         uint32_t plaintext_len;
4347         uint32_t plaintext_pad_len;
4348         uint8_t extra_offset = 4;
4349         uint8_t *expected_ciphertext_shifted;
4350         struct rte_cryptodev_info dev_info;
4351
4352         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4353         uint64_t feat_flags = dev_info.feature_flags;
4354
4355         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4356                         ((tdata->validDataLenInBits.len % 8) != 0)) {
4357                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4358                 return TEST_SKIPPED;
4359         }
4360
4361         /* Verify the capabilities */
4362         struct rte_cryptodev_sym_capability_idx cap_idx;
4363         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4364         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4365         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4366                         &cap_idx) == NULL)
4367                 return TEST_SKIPPED;
4368
4369         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4370                 return TEST_SKIPPED;
4371
4372         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4373                 return TEST_SKIPPED;
4374
4375         /* Create SNOW 3G session */
4376         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4377                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4378                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4379                                         tdata->key.data, tdata->key.len,
4380                                         tdata->cipher_iv.len);
4381         if (retval < 0)
4382                 return retval;
4383
4384         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4385         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4386
4387         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4388                         "Failed to allocate input buffer in mempool");
4389         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4390                         "Failed to allocate output buffer in mempool");
4391
4392         /* Clear mbuf payload */
4393         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4394                rte_pktmbuf_tailroom(ut_params->ibuf));
4395
4396         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4397         /*
4398          * Append data which is padded to a
4399          * multiple of the algorithms block size
4400          */
4401         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4402
4403         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4404                                                 plaintext_pad_len);
4405
4406         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4407
4408         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4409         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4410
4411 #ifdef RTE_APP_TEST_DEBUG
4412         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4413 #endif
4414         /* Create SNOW 3G operation */
4415         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4416                                         tdata->cipher_iv.len,
4417                                         tdata->validCipherLenInBits.len,
4418                                         extra_offset);
4419         if (retval < 0)
4420                 return retval;
4421
4422         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4423                                                 ut_params->op);
4424         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4425
4426         ut_params->obuf = ut_params->op->sym->m_dst;
4427         if (ut_params->obuf)
4428                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4429         else
4430                 ciphertext = plaintext;
4431
4432 #ifdef RTE_APP_TEST_DEBUG
4433         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4434 #endif
4435
4436         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4437
4438         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4439                         "failed to reserve memory for ciphertext shifted\n");
4440
4441         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4442                         ceil_byte_length(tdata->ciphertext.len));
4443         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4444                         extra_offset);
4445         /* Validate obuf */
4446         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4447                 ciphertext,
4448                 expected_ciphertext_shifted,
4449                 tdata->validDataLenInBits.len,
4450                 extra_offset,
4451                 "SNOW 3G Ciphertext data not as expected");
4452         return 0;
4453 }
4454
4455 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4456 {
4457         struct crypto_testsuite_params *ts_params = &testsuite_params;
4458         struct crypto_unittest_params *ut_params = &unittest_params;
4459
4460         int retval;
4461
4462         uint8_t *plaintext, *ciphertext;
4463         unsigned ciphertext_pad_len;
4464         unsigned ciphertext_len;
4465         struct rte_cryptodev_info dev_info;
4466
4467         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4468         uint64_t feat_flags = dev_info.feature_flags;
4469
4470         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4471                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4472                 printf("Device doesn't support RAW data-path APIs.\n");
4473                 return TEST_SKIPPED;
4474         }
4475
4476         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4477                 return TEST_SKIPPED;
4478
4479         /* Verify the capabilities */
4480         struct rte_cryptodev_sym_capability_idx cap_idx;
4481         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4482         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4483         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4484                         &cap_idx) == NULL)
4485                 return TEST_SKIPPED;
4486
4487         /* Create SNOW 3G session */
4488         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4489                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4490                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4491                                         tdata->key.data, tdata->key.len,
4492                                         tdata->cipher_iv.len);
4493         if (retval < 0)
4494                 return retval;
4495
4496         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4497
4498         /* Clear mbuf payload */
4499         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4500                rte_pktmbuf_tailroom(ut_params->ibuf));
4501
4502         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4503         /* Append data which is padded to a multiple of */
4504         /* the algorithms block size */
4505         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4506         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4507                                 ciphertext_pad_len);
4508         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4509
4510         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4511
4512         /* Create SNOW 3G operation */
4513         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4514                                         tdata->cipher_iv.len,
4515                                         tdata->validCipherLenInBits.len,
4516                                         tdata->cipher.offset_bits);
4517         if (retval < 0)
4518                 return retval;
4519
4520         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4521                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4522                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4523         else
4524                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4525                                                 ut_params->op);
4526         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4527         ut_params->obuf = ut_params->op->sym->m_dst;
4528         if (ut_params->obuf)
4529                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4530         else
4531                 plaintext = ciphertext;
4532
4533         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4534
4535         /* Validate obuf */
4536         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4537                                 tdata->plaintext.data,
4538                                 tdata->validDataLenInBits.len,
4539                                 "SNOW 3G Plaintext data not as expected");
4540         return 0;
4541 }
4542
4543 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4544 {
4545         struct crypto_testsuite_params *ts_params = &testsuite_params;
4546         struct crypto_unittest_params *ut_params = &unittest_params;
4547
4548         int retval;
4549
4550         uint8_t *plaintext, *ciphertext;
4551         unsigned ciphertext_pad_len;
4552         unsigned ciphertext_len;
4553
4554         /* Verify the capabilities */
4555         struct rte_cryptodev_sym_capability_idx cap_idx;
4556         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4557         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4558         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4559                         &cap_idx) == NULL)
4560                 return TEST_SKIPPED;
4561
4562         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4563                 return TEST_SKIPPED;
4564
4565         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4566                 return TEST_SKIPPED;
4567
4568         /* Create SNOW 3G session */
4569         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4570                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4571                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4572                                         tdata->key.data, tdata->key.len,
4573                                         tdata->cipher_iv.len);
4574         if (retval < 0)
4575                 return retval;
4576
4577         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4578         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4579
4580         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4581                         "Failed to allocate input buffer");
4582         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4583                         "Failed to allocate output buffer");
4584
4585         /* Clear mbuf payload */
4586         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4587                rte_pktmbuf_tailroom(ut_params->ibuf));
4588
4589         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4590                        rte_pktmbuf_tailroom(ut_params->obuf));
4591
4592         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4593         /* Append data which is padded to a multiple of */
4594         /* the algorithms block size */
4595         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4596         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4597                                 ciphertext_pad_len);
4598         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4599         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4600
4601         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4602
4603         /* Create SNOW 3G operation */
4604         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4605                                         tdata->cipher_iv.len,
4606                                         tdata->validCipherLenInBits.len,
4607                                         0);
4608         if (retval < 0)
4609                 return retval;
4610
4611         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4612                                                 ut_params->op);
4613         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4614         ut_params->obuf = ut_params->op->sym->m_dst;
4615         if (ut_params->obuf)
4616                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4617         else
4618                 plaintext = ciphertext;
4619
4620         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4621
4622         /* Validate obuf */
4623         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4624                                 tdata->plaintext.data,
4625                                 tdata->validDataLenInBits.len,
4626                                 "SNOW 3G Plaintext data not as expected");
4627         return 0;
4628 }
4629
4630 static int
4631 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4632 {
4633         struct crypto_testsuite_params *ts_params = &testsuite_params;
4634         struct crypto_unittest_params *ut_params = &unittest_params;
4635
4636         int retval;
4637
4638         uint8_t *plaintext, *ciphertext;
4639         unsigned int plaintext_pad_len;
4640         unsigned int plaintext_len;
4641
4642         struct rte_cryptodev_info dev_info;
4643         struct rte_cryptodev_sym_capability_idx cap_idx;
4644
4645         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4646         uint64_t feat_flags = dev_info.feature_flags;
4647
4648         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4649                         ((tdata->validAuthLenInBits.len % 8 != 0) ||
4650                         (tdata->validDataLenInBits.len % 8 != 0))) {
4651                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4652                 return TEST_SKIPPED;
4653         }
4654
4655         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4656                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4657                 printf("Device doesn't support RAW data-path APIs.\n");
4658                 return TEST_SKIPPED;
4659         }
4660
4661         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4662                 return TEST_SKIPPED;
4663
4664         /* Check if device supports ZUC EEA3 */
4665         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4666         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4667
4668         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4669                         &cap_idx) == NULL)
4670                 return TEST_SKIPPED;
4671
4672         /* Check if device supports ZUC EIA3 */
4673         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4674         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4675
4676         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4677                         &cap_idx) == NULL)
4678                 return TEST_SKIPPED;
4679
4680         /* Create ZUC session */
4681         retval = create_zuc_cipher_auth_encrypt_generate_session(
4682                         ts_params->valid_devs[0],
4683                         tdata);
4684         if (retval != 0)
4685                 return retval;
4686         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4687
4688         /* clear mbuf payload */
4689         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4690                         rte_pktmbuf_tailroom(ut_params->ibuf));
4691
4692         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4693         /* Append data which is padded to a multiple of */
4694         /* the algorithms block size */
4695         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4696         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4697                                 plaintext_pad_len);
4698         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4699
4700         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4701
4702         /* Create ZUC operation */
4703         retval = create_zuc_cipher_hash_generate_operation(tdata);
4704         if (retval < 0)
4705                 return retval;
4706
4707         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4708                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4709                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4710         else
4711                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4712                         ut_params->op);
4713         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4714         ut_params->obuf = ut_params->op->sym->m_src;
4715         if (ut_params->obuf)
4716                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4717         else
4718                 ciphertext = plaintext;
4719
4720         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4721         /* Validate obuf */
4722         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4723                         ciphertext,
4724                         tdata->ciphertext.data,
4725                         tdata->validDataLenInBits.len,
4726                         "ZUC Ciphertext data not as expected");
4727
4728         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4729             + plaintext_pad_len;
4730
4731         /* Validate obuf */
4732         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4733                         ut_params->digest,
4734                         tdata->digest.data,
4735                         4,
4736                         "ZUC Generated auth tag not as expected");
4737         return 0;
4738 }
4739
4740 static int
4741 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4742 {
4743         struct crypto_testsuite_params *ts_params = &testsuite_params;
4744         struct crypto_unittest_params *ut_params = &unittest_params;
4745
4746         int retval;
4747
4748         uint8_t *plaintext, *ciphertext;
4749         unsigned plaintext_pad_len;
4750         unsigned plaintext_len;
4751         struct rte_cryptodev_info dev_info;
4752
4753         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4754         uint64_t feat_flags = dev_info.feature_flags;
4755
4756         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4757                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4758                 printf("Device doesn't support RAW data-path APIs.\n");
4759                 return TEST_SKIPPED;
4760         }
4761
4762         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4763                 return TEST_SKIPPED;
4764
4765         /* Verify the capabilities */
4766         struct rte_cryptodev_sym_capability_idx cap_idx;
4767         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4768         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4769         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4770                         &cap_idx) == NULL)
4771                 return TEST_SKIPPED;
4772         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4773         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4774         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4775                         &cap_idx) == NULL)
4776                 return TEST_SKIPPED;
4777
4778         /* Create SNOW 3G session */
4779         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4780                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4781                         RTE_CRYPTO_AUTH_OP_GENERATE,
4782                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4783                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4784                         tdata->key.data, tdata->key.len,
4785                         tdata->auth_iv.len, tdata->digest.len,
4786                         tdata->cipher_iv.len);
4787         if (retval != 0)
4788                 return retval;
4789         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4790
4791         /* clear mbuf payload */
4792         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4793                         rte_pktmbuf_tailroom(ut_params->ibuf));
4794
4795         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4796         /* Append data which is padded to a multiple of */
4797         /* the algorithms block size */
4798         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4799         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4800                                 plaintext_pad_len);
4801         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4802
4803         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4804
4805         /* Create SNOW 3G operation */
4806         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4807                         tdata->digest.len, tdata->auth_iv.data,
4808                         tdata->auth_iv.len,
4809                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4810                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4811                         tdata->validCipherLenInBits.len,
4812                         0,
4813                         tdata->validAuthLenInBits.len,
4814                         0
4815                         );
4816         if (retval < 0)
4817                 return retval;
4818
4819         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4820                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4821                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4822         else
4823                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4824                         ut_params->op);
4825         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4826         ut_params->obuf = ut_params->op->sym->m_src;
4827         if (ut_params->obuf)
4828                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4829         else
4830                 ciphertext = plaintext;
4831
4832         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4833         /* Validate obuf */
4834         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4835                         ciphertext,
4836                         tdata->ciphertext.data,
4837                         tdata->validDataLenInBits.len,
4838                         "SNOW 3G Ciphertext data not as expected");
4839
4840         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4841             + plaintext_pad_len;
4842
4843         /* Validate obuf */
4844         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4845                         ut_params->digest,
4846                         tdata->digest.data,
4847                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4848                         "SNOW 3G Generated auth tag not as expected");
4849         return 0;
4850 }
4851
4852 static int
4853 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4854         uint8_t op_mode, uint8_t verify)
4855 {
4856         struct crypto_testsuite_params *ts_params = &testsuite_params;
4857         struct crypto_unittest_params *ut_params = &unittest_params;
4858
4859         int retval;
4860
4861         uint8_t *plaintext = NULL, *ciphertext = NULL;
4862         unsigned int plaintext_pad_len;
4863         unsigned int plaintext_len;
4864         unsigned int ciphertext_pad_len;
4865         unsigned int ciphertext_len;
4866
4867         struct rte_cryptodev_info dev_info;
4868
4869         /* Verify the capabilities */
4870         struct rte_cryptodev_sym_capability_idx cap_idx;
4871         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4872         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4873         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4874                         &cap_idx) == NULL)
4875                 return TEST_SKIPPED;
4876         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4877         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4878         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4879                         &cap_idx) == NULL)
4880                 return TEST_SKIPPED;
4881
4882         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4883                 return TEST_SKIPPED;
4884
4885         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4886
4887         uint64_t feat_flags = dev_info.feature_flags;
4888
4889         if (op_mode == OUT_OF_PLACE) {
4890                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4891                         printf("Device doesn't support digest encrypted.\n");
4892                         return TEST_SKIPPED;
4893                 }
4894                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4895                         return TEST_SKIPPED;
4896         }
4897
4898         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4899                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4900                 printf("Device doesn't support RAW data-path APIs.\n");
4901                 return TEST_SKIPPED;
4902         }
4903
4904         /* Create SNOW 3G session */
4905         retval = create_wireless_algo_auth_cipher_session(
4906                         ts_params->valid_devs[0],
4907                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4908                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4909                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4910                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4911                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4912                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4913                         tdata->key.data, tdata->key.len,
4914                         tdata->auth_iv.len, tdata->digest.len,
4915                         tdata->cipher_iv.len);
4916         if (retval != 0)
4917                 return retval;
4918
4919         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4920         if (op_mode == OUT_OF_PLACE)
4921                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4922
4923         /* clear mbuf payload */
4924         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4925                 rte_pktmbuf_tailroom(ut_params->ibuf));
4926         if (op_mode == OUT_OF_PLACE)
4927                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4928                         rte_pktmbuf_tailroom(ut_params->obuf));
4929
4930         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4931         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4932         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4933         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4934
4935         if (verify) {
4936                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4937                                         ciphertext_pad_len);
4938                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4939                 if (op_mode == OUT_OF_PLACE)
4940                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4941                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4942                         ciphertext_len);
4943         } else {
4944                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4945                                         plaintext_pad_len);
4946                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4947                 if (op_mode == OUT_OF_PLACE)
4948                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4949                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4950         }
4951
4952         /* Create SNOW 3G operation */
4953         retval = create_wireless_algo_auth_cipher_operation(
4954                 tdata->digest.data, tdata->digest.len,
4955                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4956                 tdata->auth_iv.data, tdata->auth_iv.len,
4957                 (tdata->digest.offset_bytes == 0 ?
4958                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4959                         : tdata->digest.offset_bytes),
4960                 tdata->validCipherLenInBits.len,
4961                 tdata->cipher.offset_bits,
4962                 tdata->validAuthLenInBits.len,
4963                 tdata->auth.offset_bits,
4964                 op_mode, 0, verify);
4965
4966         if (retval < 0)
4967                 return retval;
4968
4969         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4970                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4971                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4972         else
4973                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4974                         ut_params->op);
4975
4976         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4977
4978         ut_params->obuf = (op_mode == IN_PLACE ?
4979                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4980
4981         if (verify) {
4982                 if (ut_params->obuf)
4983                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4984                                                         uint8_t *);
4985                 else
4986                         plaintext = ciphertext +
4987                                 (tdata->cipher.offset_bits >> 3);
4988
4989                 debug_hexdump(stdout, "plaintext:", plaintext,
4990                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4991                 debug_hexdump(stdout, "plaintext expected:",
4992                         tdata->plaintext.data,
4993                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4994         } else {
4995                 if (ut_params->obuf)
4996                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4997                                                         uint8_t *);
4998                 else
4999                         ciphertext = plaintext;
5000
5001                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5002                         ciphertext_len);
5003                 debug_hexdump(stdout, "ciphertext expected:",
5004                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5005
5006                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5007                         + (tdata->digest.offset_bytes == 0 ?
5008                 plaintext_pad_len : tdata->digest.offset_bytes);
5009
5010                 debug_hexdump(stdout, "digest:", ut_params->digest,
5011                         tdata->digest.len);
5012                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5013                                 tdata->digest.len);
5014         }
5015
5016         /* Validate obuf */
5017         if (verify) {
5018                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5019                         plaintext,
5020                         tdata->plaintext.data,
5021                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5022                          (tdata->digest.len << 3)),
5023                         tdata->cipher.offset_bits,
5024                         "SNOW 3G Plaintext data not as expected");
5025         } else {
5026                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5027                         ciphertext,
5028                         tdata->ciphertext.data,
5029                         (tdata->validDataLenInBits.len -
5030                          tdata->cipher.offset_bits),
5031                         tdata->cipher.offset_bits,
5032                         "SNOW 3G Ciphertext data not as expected");
5033
5034                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5035                         ut_params->digest,
5036                         tdata->digest.data,
5037                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5038                         "SNOW 3G Generated auth tag not as expected");
5039         }
5040         return 0;
5041 }
5042
5043 static int
5044 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5045         uint8_t op_mode, uint8_t verify)
5046 {
5047         struct crypto_testsuite_params *ts_params = &testsuite_params;
5048         struct crypto_unittest_params *ut_params = &unittest_params;
5049
5050         int retval;
5051
5052         const uint8_t *plaintext = NULL;
5053         const uint8_t *ciphertext = NULL;
5054         const uint8_t *digest = NULL;
5055         unsigned int plaintext_pad_len;
5056         unsigned int plaintext_len;
5057         unsigned int ciphertext_pad_len;
5058         unsigned int ciphertext_len;
5059         uint8_t buffer[10000];
5060         uint8_t digest_buffer[10000];
5061
5062         struct rte_cryptodev_info dev_info;
5063
5064         /* Verify the capabilities */
5065         struct rte_cryptodev_sym_capability_idx cap_idx;
5066         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5067         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5068         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5069                         &cap_idx) == NULL)
5070                 return TEST_SKIPPED;
5071         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5072         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5073         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5074                         &cap_idx) == NULL)
5075                 return TEST_SKIPPED;
5076
5077         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5078                 return TEST_SKIPPED;
5079
5080         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5081
5082         uint64_t feat_flags = dev_info.feature_flags;
5083
5084         if (op_mode == IN_PLACE) {
5085                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5086                         printf("Device doesn't support in-place scatter-gather "
5087                                         "in both input and output mbufs.\n");
5088                         return TEST_SKIPPED;
5089                 }
5090                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5091                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5092                         printf("Device doesn't support RAW data-path APIs.\n");
5093                         return TEST_SKIPPED;
5094                 }
5095         } else {
5096                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5097                         return TEST_SKIPPED;
5098                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5099                         printf("Device doesn't support out-of-place scatter-gather "
5100                                         "in both input and output mbufs.\n");
5101                         return TEST_SKIPPED;
5102                 }
5103                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5104                         printf("Device doesn't support digest encrypted.\n");
5105                         return TEST_SKIPPED;
5106                 }
5107         }
5108
5109         /* Create SNOW 3G session */
5110         retval = create_wireless_algo_auth_cipher_session(
5111                         ts_params->valid_devs[0],
5112                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5113                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5114                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5115                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5116                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5117                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5118                         tdata->key.data, tdata->key.len,
5119                         tdata->auth_iv.len, tdata->digest.len,
5120                         tdata->cipher_iv.len);
5121
5122         if (retval != 0)
5123                 return retval;
5124
5125         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5126         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5127         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5128         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5129
5130         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5131                         plaintext_pad_len, 15, 0);
5132         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5133                         "Failed to allocate input buffer in mempool");
5134
5135         if (op_mode == OUT_OF_PLACE) {
5136                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5137                                 plaintext_pad_len, 15, 0);
5138                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5139                                 "Failed to allocate output buffer in mempool");
5140         }
5141
5142         if (verify) {
5143                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5144                         tdata->ciphertext.data);
5145                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5146                                         ciphertext_len, buffer);
5147                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5148                         ciphertext_len);
5149         } else {
5150                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5151                         tdata->plaintext.data);
5152                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5153                                         plaintext_len, buffer);
5154                 debug_hexdump(stdout, "plaintext:", plaintext,
5155                         plaintext_len);
5156         }
5157         memset(buffer, 0, sizeof(buffer));
5158
5159         /* Create SNOW 3G operation */
5160         retval = create_wireless_algo_auth_cipher_operation(
5161                 tdata->digest.data, tdata->digest.len,
5162                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5163                 tdata->auth_iv.data, tdata->auth_iv.len,
5164                 (tdata->digest.offset_bytes == 0 ?
5165                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5166                         : tdata->digest.offset_bytes),
5167                 tdata->validCipherLenInBits.len,
5168                 tdata->cipher.offset_bits,
5169                 tdata->validAuthLenInBits.len,
5170                 tdata->auth.offset_bits,
5171                 op_mode, 1, verify);
5172
5173         if (retval < 0)
5174                 return retval;
5175
5176         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5177                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5178                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5179         else
5180                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5181                         ut_params->op);
5182
5183         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5184
5185         ut_params->obuf = (op_mode == IN_PLACE ?
5186                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5187
5188         if (verify) {
5189                 if (ut_params->obuf)
5190                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5191                                         plaintext_len, buffer);
5192                 else
5193                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5194                                         plaintext_len, buffer);
5195
5196                 debug_hexdump(stdout, "plaintext:", plaintext,
5197                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5198                 debug_hexdump(stdout, "plaintext expected:",
5199                         tdata->plaintext.data,
5200                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5201         } else {
5202                 if (ut_params->obuf)
5203                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5204                                         ciphertext_len, buffer);
5205                 else
5206                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5207                                         ciphertext_len, buffer);
5208
5209                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5210                         ciphertext_len);
5211                 debug_hexdump(stdout, "ciphertext expected:",
5212                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5213
5214                 if (ut_params->obuf)
5215                         digest = rte_pktmbuf_read(ut_params->obuf,
5216                                 (tdata->digest.offset_bytes == 0 ?
5217                                 plaintext_pad_len : tdata->digest.offset_bytes),
5218                                 tdata->digest.len, digest_buffer);
5219                 else
5220                         digest = rte_pktmbuf_read(ut_params->ibuf,
5221                                 (tdata->digest.offset_bytes == 0 ?
5222                                 plaintext_pad_len : tdata->digest.offset_bytes),
5223                                 tdata->digest.len, digest_buffer);
5224
5225                 debug_hexdump(stdout, "digest:", digest,
5226                         tdata->digest.len);
5227                 debug_hexdump(stdout, "digest expected:",
5228                         tdata->digest.data, tdata->digest.len);
5229         }
5230
5231         /* Validate obuf */
5232         if (verify) {
5233                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5234                         plaintext,
5235                         tdata->plaintext.data,
5236                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5237                          (tdata->digest.len << 3)),
5238                         tdata->cipher.offset_bits,
5239                         "SNOW 3G Plaintext data not as expected");
5240         } else {
5241                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5242                         ciphertext,
5243                         tdata->ciphertext.data,
5244                         (tdata->validDataLenInBits.len -
5245                          tdata->cipher.offset_bits),
5246                         tdata->cipher.offset_bits,
5247                         "SNOW 3G Ciphertext data not as expected");
5248
5249                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5250                         digest,
5251                         tdata->digest.data,
5252                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5253                         "SNOW 3G Generated auth tag not as expected");
5254         }
5255         return 0;
5256 }
5257
5258 static int
5259 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5260         uint8_t op_mode, uint8_t verify)
5261 {
5262         struct crypto_testsuite_params *ts_params = &testsuite_params;
5263         struct crypto_unittest_params *ut_params = &unittest_params;
5264
5265         int retval;
5266
5267         uint8_t *plaintext = NULL, *ciphertext = NULL;
5268         unsigned int plaintext_pad_len;
5269         unsigned int plaintext_len;
5270         unsigned int ciphertext_pad_len;
5271         unsigned int ciphertext_len;
5272
5273         struct rte_cryptodev_info dev_info;
5274
5275         /* Verify the capabilities */
5276         struct rte_cryptodev_sym_capability_idx cap_idx;
5277         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5278         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5279         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5280                         &cap_idx) == NULL)
5281                 return TEST_SKIPPED;
5282         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5283         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5284         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5285                         &cap_idx) == NULL)
5286                 return TEST_SKIPPED;
5287
5288         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5289
5290         uint64_t feat_flags = dev_info.feature_flags;
5291
5292         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5293                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5294                 printf("Device doesn't support RAW data-path APIs.\n");
5295                 return TEST_SKIPPED;
5296         }
5297
5298         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5299                 return TEST_SKIPPED;
5300
5301         if (op_mode == OUT_OF_PLACE) {
5302                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5303                         return TEST_SKIPPED;
5304                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5305                         printf("Device doesn't support digest encrypted.\n");
5306                         return TEST_SKIPPED;
5307                 }
5308         }
5309
5310         /* Create KASUMI session */
5311         retval = create_wireless_algo_auth_cipher_session(
5312                         ts_params->valid_devs[0],
5313                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5314                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5315                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5316                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5317                         RTE_CRYPTO_AUTH_KASUMI_F9,
5318                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5319                         tdata->key.data, tdata->key.len,
5320                         0, tdata->digest.len,
5321                         tdata->cipher_iv.len);
5322
5323         if (retval != 0)
5324                 return retval;
5325
5326         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5327         if (op_mode == OUT_OF_PLACE)
5328                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5329
5330         /* clear mbuf payload */
5331         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5332                 rte_pktmbuf_tailroom(ut_params->ibuf));
5333         if (op_mode == OUT_OF_PLACE)
5334                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5335                         rte_pktmbuf_tailroom(ut_params->obuf));
5336
5337         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5338         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5339         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5340         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5341
5342         if (verify) {
5343                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5344                                         ciphertext_pad_len);
5345                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5346                 if (op_mode == OUT_OF_PLACE)
5347                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5348                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5349                         ciphertext_len);
5350         } else {
5351                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5352                                         plaintext_pad_len);
5353                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5354                 if (op_mode == OUT_OF_PLACE)
5355                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5356                 debug_hexdump(stdout, "plaintext:", plaintext,
5357                         plaintext_len);
5358         }
5359
5360         /* Create KASUMI operation */
5361         retval = create_wireless_algo_auth_cipher_operation(
5362                 tdata->digest.data, tdata->digest.len,
5363                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5364                 NULL, 0,
5365                 (tdata->digest.offset_bytes == 0 ?
5366                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5367                         : tdata->digest.offset_bytes),
5368                 tdata->validCipherLenInBits.len,
5369                 tdata->validCipherOffsetInBits.len,
5370                 tdata->validAuthLenInBits.len,
5371                 0,
5372                 op_mode, 0, verify);
5373
5374         if (retval < 0)
5375                 return retval;
5376
5377         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5378                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5379                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5380         else
5381                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5382                         ut_params->op);
5383
5384         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5385
5386         ut_params->obuf = (op_mode == IN_PLACE ?
5387                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5388
5389
5390         if (verify) {
5391                 if (ut_params->obuf)
5392                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5393                                                         uint8_t *);
5394                 else
5395                         plaintext = ciphertext;
5396
5397                 debug_hexdump(stdout, "plaintext:", plaintext,
5398                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5399                 debug_hexdump(stdout, "plaintext expected:",
5400                         tdata->plaintext.data,
5401                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5402         } else {
5403                 if (ut_params->obuf)
5404                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5405                                                         uint8_t *);
5406                 else
5407                         ciphertext = plaintext;
5408
5409                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5410                         ciphertext_len);
5411                 debug_hexdump(stdout, "ciphertext expected:",
5412                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5413
5414                 ut_params->digest = rte_pktmbuf_mtod(
5415                         ut_params->obuf, uint8_t *) +
5416                         (tdata->digest.offset_bytes == 0 ?
5417                         plaintext_pad_len : tdata->digest.offset_bytes);
5418
5419                 debug_hexdump(stdout, "digest:", ut_params->digest,
5420                         tdata->digest.len);
5421                 debug_hexdump(stdout, "digest expected:",
5422                         tdata->digest.data, tdata->digest.len);
5423         }
5424
5425         /* Validate obuf */
5426         if (verify) {
5427                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5428                         plaintext,
5429                         tdata->plaintext.data,
5430                         tdata->plaintext.len >> 3,
5431                         "KASUMI Plaintext data not as expected");
5432         } else {
5433                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5434                         ciphertext,
5435                         tdata->ciphertext.data,
5436                         tdata->ciphertext.len >> 3,
5437                         "KASUMI Ciphertext data not as expected");
5438
5439                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5440                         ut_params->digest,
5441                         tdata->digest.data,
5442                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5443                         "KASUMI Generated auth tag not as expected");
5444         }
5445         return 0;
5446 }
5447
5448 static int
5449 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5450         uint8_t op_mode, uint8_t verify)
5451 {
5452         struct crypto_testsuite_params *ts_params = &testsuite_params;
5453         struct crypto_unittest_params *ut_params = &unittest_params;
5454
5455         int retval;
5456
5457         const uint8_t *plaintext = NULL;
5458         const uint8_t *ciphertext = NULL;
5459         const uint8_t *digest = NULL;
5460         unsigned int plaintext_pad_len;
5461         unsigned int plaintext_len;
5462         unsigned int ciphertext_pad_len;
5463         unsigned int ciphertext_len;
5464         uint8_t buffer[10000];
5465         uint8_t digest_buffer[10000];
5466
5467         struct rte_cryptodev_info dev_info;
5468
5469         /* Verify the capabilities */
5470         struct rte_cryptodev_sym_capability_idx cap_idx;
5471         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5472         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5473         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5474                         &cap_idx) == NULL)
5475                 return TEST_SKIPPED;
5476         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5477         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5478         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5479                         &cap_idx) == NULL)
5480                 return TEST_SKIPPED;
5481
5482         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5483                 return TEST_SKIPPED;
5484
5485         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5486
5487         uint64_t feat_flags = dev_info.feature_flags;
5488
5489         if (op_mode == IN_PLACE) {
5490                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5491                         printf("Device doesn't support in-place scatter-gather "
5492                                         "in both input and output mbufs.\n");
5493                         return TEST_SKIPPED;
5494                 }
5495                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5496                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5497                         printf("Device doesn't support RAW data-path APIs.\n");
5498                         return TEST_SKIPPED;
5499                 }
5500         } else {
5501                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5502                         return TEST_SKIPPED;
5503                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5504                         printf("Device doesn't support out-of-place scatter-gather "
5505                                         "in both input and output mbufs.\n");
5506                         return TEST_SKIPPED;
5507                 }
5508                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5509                         printf("Device doesn't support digest encrypted.\n");
5510                         return TEST_SKIPPED;
5511                 }
5512         }
5513
5514         /* Create KASUMI session */
5515         retval = create_wireless_algo_auth_cipher_session(
5516                         ts_params->valid_devs[0],
5517                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5518                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5519                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5520                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5521                         RTE_CRYPTO_AUTH_KASUMI_F9,
5522                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5523                         tdata->key.data, tdata->key.len,
5524                         0, tdata->digest.len,
5525                         tdata->cipher_iv.len);
5526
5527         if (retval != 0)
5528                 return retval;
5529
5530         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5531         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5532         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5533         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5534
5535         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5536                         plaintext_pad_len, 15, 0);
5537         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5538                         "Failed to allocate input buffer in mempool");
5539
5540         if (op_mode == OUT_OF_PLACE) {
5541                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5542                                 plaintext_pad_len, 15, 0);
5543                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5544                                 "Failed to allocate output buffer in mempool");
5545         }
5546
5547         if (verify) {
5548                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5549                         tdata->ciphertext.data);
5550                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5551                                         ciphertext_len, buffer);
5552                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5553                         ciphertext_len);
5554         } else {
5555                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5556                         tdata->plaintext.data);
5557                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5558                                         plaintext_len, buffer);
5559                 debug_hexdump(stdout, "plaintext:", plaintext,
5560                         plaintext_len);
5561         }
5562         memset(buffer, 0, sizeof(buffer));
5563
5564         /* Create KASUMI operation */
5565         retval = create_wireless_algo_auth_cipher_operation(
5566                 tdata->digest.data, tdata->digest.len,
5567                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5568                 NULL, 0,
5569                 (tdata->digest.offset_bytes == 0 ?
5570                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5571                         : tdata->digest.offset_bytes),
5572                 tdata->validCipherLenInBits.len,
5573                 tdata->validCipherOffsetInBits.len,
5574                 tdata->validAuthLenInBits.len,
5575                 0,
5576                 op_mode, 1, verify);
5577
5578         if (retval < 0)
5579                 return retval;
5580
5581         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5582                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5583                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5584         else
5585                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5586                         ut_params->op);
5587
5588         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5589
5590         ut_params->obuf = (op_mode == IN_PLACE ?
5591                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5592
5593         if (verify) {
5594                 if (ut_params->obuf)
5595                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5596                                         plaintext_len, buffer);
5597                 else
5598                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5599                                         plaintext_len, buffer);
5600
5601                 debug_hexdump(stdout, "plaintext:", plaintext,
5602                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5603                 debug_hexdump(stdout, "plaintext expected:",
5604                         tdata->plaintext.data,
5605                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5606         } else {
5607                 if (ut_params->obuf)
5608                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5609                                         ciphertext_len, buffer);
5610                 else
5611                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5612                                         ciphertext_len, buffer);
5613
5614                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5615                         ciphertext_len);
5616                 debug_hexdump(stdout, "ciphertext expected:",
5617                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5618
5619                 if (ut_params->obuf)
5620                         digest = rte_pktmbuf_read(ut_params->obuf,
5621                                 (tdata->digest.offset_bytes == 0 ?
5622                                 plaintext_pad_len : tdata->digest.offset_bytes),
5623                                 tdata->digest.len, digest_buffer);
5624                 else
5625                         digest = rte_pktmbuf_read(ut_params->ibuf,
5626                                 (tdata->digest.offset_bytes == 0 ?
5627                                 plaintext_pad_len : tdata->digest.offset_bytes),
5628                                 tdata->digest.len, digest_buffer);
5629
5630                 debug_hexdump(stdout, "digest:", digest,
5631                         tdata->digest.len);
5632                 debug_hexdump(stdout, "digest expected:",
5633                         tdata->digest.data, tdata->digest.len);
5634         }
5635
5636         /* Validate obuf */
5637         if (verify) {
5638                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5639                         plaintext,
5640                         tdata->plaintext.data,
5641                         tdata->plaintext.len >> 3,
5642                         "KASUMI Plaintext data not as expected");
5643         } else {
5644                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5645                         ciphertext,
5646                         tdata->ciphertext.data,
5647                         tdata->validDataLenInBits.len,
5648                         "KASUMI Ciphertext data not as expected");
5649
5650                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5651                         digest,
5652                         tdata->digest.data,
5653                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5654                         "KASUMI Generated auth tag not as expected");
5655         }
5656         return 0;
5657 }
5658
5659 static int
5660 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5661 {
5662         struct crypto_testsuite_params *ts_params = &testsuite_params;
5663         struct crypto_unittest_params *ut_params = &unittest_params;
5664
5665         int retval;
5666
5667         uint8_t *plaintext, *ciphertext;
5668         unsigned plaintext_pad_len;
5669         unsigned plaintext_len;
5670         struct rte_cryptodev_info dev_info;
5671
5672         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5673         uint64_t feat_flags = dev_info.feature_flags;
5674
5675         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5676                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5677                 printf("Device doesn't support RAW data-path APIs.\n");
5678                 return TEST_SKIPPED;
5679         }
5680
5681         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5682                 return TEST_SKIPPED;
5683
5684         /* Verify the capabilities */
5685         struct rte_cryptodev_sym_capability_idx cap_idx;
5686         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5687         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5688         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5689                         &cap_idx) == NULL)
5690                 return TEST_SKIPPED;
5691         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5692         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5693         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5694                         &cap_idx) == NULL)
5695                 return TEST_SKIPPED;
5696
5697         /* Create KASUMI session */
5698         retval = create_wireless_algo_cipher_auth_session(
5699                         ts_params->valid_devs[0],
5700                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5701                         RTE_CRYPTO_AUTH_OP_GENERATE,
5702                         RTE_CRYPTO_AUTH_KASUMI_F9,
5703                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5704                         tdata->key.data, tdata->key.len,
5705                         0, tdata->digest.len,
5706                         tdata->cipher_iv.len);
5707         if (retval != 0)
5708                 return retval;
5709
5710         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5711
5712         /* clear mbuf payload */
5713         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5714                         rte_pktmbuf_tailroom(ut_params->ibuf));
5715
5716         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5717         /* Append data which is padded to a multiple of */
5718         /* the algorithms block size */
5719         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5720         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5721                                 plaintext_pad_len);
5722         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5723
5724         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5725
5726         /* Create KASUMI operation */
5727         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5728                                 tdata->digest.len, NULL, 0,
5729                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5730                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5731                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5732                                 tdata->validCipherOffsetInBits.len,
5733                                 tdata->validAuthLenInBits.len,
5734                                 0
5735                                 );
5736         if (retval < 0)
5737                 return retval;
5738
5739         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5740                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5741                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5742         else
5743                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5744                         ut_params->op);
5745         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5746
5747         if (ut_params->op->sym->m_dst)
5748                 ut_params->obuf = ut_params->op->sym->m_dst;
5749         else
5750                 ut_params->obuf = ut_params->op->sym->m_src;
5751
5752         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5753                                 tdata->validCipherOffsetInBits.len >> 3);
5754
5755         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5756                         + plaintext_pad_len;
5757
5758         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5759                                 (tdata->validCipherOffsetInBits.len >> 3);
5760         /* Validate obuf */
5761         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5762                 ciphertext,
5763                 reference_ciphertext,
5764                 tdata->validCipherLenInBits.len,
5765                 "KASUMI Ciphertext data not as expected");
5766
5767         /* Validate obuf */
5768         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5769                 ut_params->digest,
5770                 tdata->digest.data,
5771                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5772                 "KASUMI Generated auth tag not as expected");
5773         return 0;
5774 }
5775
5776 static int
5777 test_zuc_encryption(const struct wireless_test_data *tdata)
5778 {
5779         struct crypto_testsuite_params *ts_params = &testsuite_params;
5780         struct crypto_unittest_params *ut_params = &unittest_params;
5781
5782         int retval;
5783         uint8_t *plaintext, *ciphertext;
5784         unsigned plaintext_pad_len;
5785         unsigned plaintext_len;
5786         struct rte_cryptodev_info dev_info;
5787
5788         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5789         uint64_t feat_flags = dev_info.feature_flags;
5790
5791         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5792                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5793                 printf("Device doesn't support RAW data-path APIs.\n");
5794                 return TEST_SKIPPED;
5795         }
5796
5797         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5798                 return TEST_SKIPPED;
5799
5800         struct rte_cryptodev_sym_capability_idx cap_idx;
5801
5802         /* Check if device supports ZUC EEA3 */
5803         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5804         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5805
5806         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5807                         &cap_idx) == NULL)
5808                 return TEST_SKIPPED;
5809
5810         /* Create ZUC session */
5811         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5812                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5813                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5814                                         tdata->key.data, tdata->key.len,
5815                                         tdata->cipher_iv.len);
5816         if (retval < 0)
5817                 return retval;
5818
5819         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5820
5821         /* Clear mbuf payload */
5822         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5823                rte_pktmbuf_tailroom(ut_params->ibuf));
5824
5825         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5826         /* Append data which is padded to a multiple */
5827         /* of the algorithms block size */
5828         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5829         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5830                                 plaintext_pad_len);
5831         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5832
5833         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5834
5835         /* Create ZUC operation */
5836         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5837                                         tdata->cipher_iv.len,
5838                                         tdata->plaintext.len,
5839                                         0);
5840         if (retval < 0)
5841                 return retval;
5842
5843         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5844                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5845                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5846         else
5847                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5848                                                 ut_params->op);
5849         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5850
5851         ut_params->obuf = ut_params->op->sym->m_dst;
5852         if (ut_params->obuf)
5853                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5854         else
5855                 ciphertext = plaintext;
5856
5857         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5858
5859         /* Validate obuf */
5860         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5861                 ciphertext,
5862                 tdata->ciphertext.data,
5863                 tdata->validCipherLenInBits.len,
5864                 "ZUC Ciphertext data not as expected");
5865         return 0;
5866 }
5867
5868 static int
5869 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5870 {
5871         struct crypto_testsuite_params *ts_params = &testsuite_params;
5872         struct crypto_unittest_params *ut_params = &unittest_params;
5873
5874         int retval;
5875
5876         unsigned int plaintext_pad_len;
5877         unsigned int plaintext_len;
5878         const uint8_t *ciphertext;
5879         uint8_t ciphertext_buffer[2048];
5880         struct rte_cryptodev_info dev_info;
5881
5882         struct rte_cryptodev_sym_capability_idx cap_idx;
5883
5884         /* Check if device supports ZUC EEA3 */
5885         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5886         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5887
5888         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5889                         &cap_idx) == NULL)
5890                 return TEST_SKIPPED;
5891
5892         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5893                 return TEST_SKIPPED;
5894
5895         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5896
5897         uint64_t feat_flags = dev_info.feature_flags;
5898
5899         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5900                 printf("Device doesn't support in-place scatter-gather. "
5901                                 "Test Skipped.\n");
5902                 return TEST_SKIPPED;
5903         }
5904
5905         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5906                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5907                 printf("Device doesn't support RAW data-path APIs.\n");
5908                 return TEST_SKIPPED;
5909         }
5910
5911         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5912
5913         /* Append data which is padded to a multiple */
5914         /* of the algorithms block size */
5915         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5916
5917         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5918                         plaintext_pad_len, 10, 0);
5919
5920         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5921                         tdata->plaintext.data);
5922
5923         /* Create ZUC session */
5924         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5925                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5926                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5927                         tdata->key.data, tdata->key.len,
5928                         tdata->cipher_iv.len);
5929         if (retval < 0)
5930                 return retval;
5931
5932         /* Clear mbuf payload */
5933
5934         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5935
5936         /* Create ZUC operation */
5937         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5938                         tdata->cipher_iv.len, tdata->plaintext.len,
5939                         0);
5940         if (retval < 0)
5941                 return retval;
5942
5943         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5944                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5945                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5946         else
5947                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5948                                                 ut_params->op);
5949         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5950
5951         ut_params->obuf = ut_params->op->sym->m_dst;
5952         if (ut_params->obuf)
5953                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
5954                         0, plaintext_len, ciphertext_buffer);
5955         else
5956                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
5957                         0, plaintext_len, ciphertext_buffer);
5958
5959         /* Validate obuf */
5960         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5961
5962         /* Validate obuf */
5963         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5964                 ciphertext,
5965                 tdata->ciphertext.data,
5966                 tdata->validCipherLenInBits.len,
5967                 "ZUC Ciphertext data not as expected");
5968
5969         return 0;
5970 }
5971
5972 static int
5973 test_zuc_authentication(const struct wireless_test_data *tdata)
5974 {
5975         struct crypto_testsuite_params *ts_params = &testsuite_params;
5976         struct crypto_unittest_params *ut_params = &unittest_params;
5977
5978         int retval;
5979         unsigned plaintext_pad_len;
5980         unsigned plaintext_len;
5981         uint8_t *plaintext;
5982
5983         struct rte_cryptodev_sym_capability_idx cap_idx;
5984         struct rte_cryptodev_info dev_info;
5985
5986         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5987         uint64_t feat_flags = dev_info.feature_flags;
5988
5989         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
5990                         (tdata->validAuthLenInBits.len % 8 != 0)) {
5991                 printf("Device doesn't support NON-Byte Aligned Data.\n");
5992                 return TEST_SKIPPED;
5993         }
5994
5995         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5996                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5997                 printf("Device doesn't support RAW data-path APIs.\n");
5998                 return TEST_SKIPPED;
5999         }
6000
6001         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6002                 return TEST_SKIPPED;
6003
6004         /* Check if device supports ZUC EIA3 */
6005         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6006         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6007
6008         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6009                         &cap_idx) == NULL)
6010                 return TEST_SKIPPED;
6011
6012         /* Create ZUC session */
6013         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6014                         tdata->key.data, tdata->key.len,
6015                         tdata->auth_iv.len, tdata->digest.len,
6016                         RTE_CRYPTO_AUTH_OP_GENERATE,
6017                         RTE_CRYPTO_AUTH_ZUC_EIA3);
6018         if (retval < 0)
6019                 return retval;
6020
6021         /* alloc mbuf and set payload */
6022         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6023
6024         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6025         rte_pktmbuf_tailroom(ut_params->ibuf));
6026
6027         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6028         /* Append data which is padded to a multiple of */
6029         /* the algorithms block size */
6030         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6031         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6032                                 plaintext_pad_len);
6033         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6034
6035         /* Create ZUC operation */
6036         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6037                         tdata->auth_iv.data, tdata->auth_iv.len,
6038                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6039                         tdata->validAuthLenInBits.len,
6040                         0);
6041         if (retval < 0)
6042                 return retval;
6043
6044         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6045                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6046                                 ut_params->op, 0, 1, 1, 0);
6047         else
6048                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6049                                 ut_params->op);
6050         ut_params->obuf = ut_params->op->sym->m_src;
6051         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6052         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6053                         + plaintext_pad_len;
6054
6055         /* Validate obuf */
6056         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6057         ut_params->digest,
6058         tdata->digest.data,
6059         tdata->digest.len,
6060         "ZUC Generated auth tag not as expected");
6061
6062         return 0;
6063 }
6064
6065 static int
6066 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6067         uint8_t op_mode, uint8_t verify)
6068 {
6069         struct crypto_testsuite_params *ts_params = &testsuite_params;
6070         struct crypto_unittest_params *ut_params = &unittest_params;
6071
6072         int retval;
6073
6074         uint8_t *plaintext = NULL, *ciphertext = NULL;
6075         unsigned int plaintext_pad_len;
6076         unsigned int plaintext_len;
6077         unsigned int ciphertext_pad_len;
6078         unsigned int ciphertext_len;
6079
6080         struct rte_cryptodev_info dev_info;
6081         struct rte_cryptodev_sym_capability_idx cap_idx;
6082
6083         /* Check if device supports ZUC EIA3 */
6084         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6085         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6086
6087         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6088                         &cap_idx) == NULL)
6089                 return TEST_SKIPPED;
6090
6091         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6092
6093         uint64_t feat_flags = dev_info.feature_flags;
6094
6095         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6096                 printf("Device doesn't support digest encrypted.\n");
6097                 return TEST_SKIPPED;
6098         }
6099         if (op_mode == IN_PLACE) {
6100                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6101                         printf("Device doesn't support in-place scatter-gather "
6102                                         "in both input and output mbufs.\n");
6103                         return TEST_SKIPPED;
6104                 }
6105
6106                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6107                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6108                         printf("Device doesn't support RAW data-path APIs.\n");
6109                         return TEST_SKIPPED;
6110                 }
6111         } else {
6112                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6113                         return TEST_SKIPPED;
6114                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6115                         printf("Device doesn't support out-of-place scatter-gather "
6116                                         "in both input and output mbufs.\n");
6117                         return TEST_SKIPPED;
6118                 }
6119         }
6120
6121         /* Create ZUC session */
6122         retval = create_wireless_algo_auth_cipher_session(
6123                         ts_params->valid_devs[0],
6124                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6125                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6126                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6127                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6128                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6129                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6130                         tdata->key.data, tdata->key.len,
6131                         tdata->auth_iv.len, tdata->digest.len,
6132                         tdata->cipher_iv.len);
6133
6134         if (retval != 0)
6135                 return retval;
6136
6137         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6138         if (op_mode == OUT_OF_PLACE)
6139                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6140
6141         /* clear mbuf payload */
6142         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6143                 rte_pktmbuf_tailroom(ut_params->ibuf));
6144         if (op_mode == OUT_OF_PLACE)
6145                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6146                         rte_pktmbuf_tailroom(ut_params->obuf));
6147
6148         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6149         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6150         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6151         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6152
6153         if (verify) {
6154                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6155                                         ciphertext_pad_len);
6156                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6157                 if (op_mode == OUT_OF_PLACE)
6158                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6159                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6160                         ciphertext_len);
6161         } else {
6162                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6163                                         plaintext_pad_len);
6164                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6165                 if (op_mode == OUT_OF_PLACE)
6166                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6167                 debug_hexdump(stdout, "plaintext:", plaintext,
6168                         plaintext_len);
6169         }
6170
6171         /* Create ZUC operation */
6172         retval = create_wireless_algo_auth_cipher_operation(
6173                 tdata->digest.data, tdata->digest.len,
6174                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6175                 tdata->auth_iv.data, tdata->auth_iv.len,
6176                 (tdata->digest.offset_bytes == 0 ?
6177                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6178                         : tdata->digest.offset_bytes),
6179                 tdata->validCipherLenInBits.len,
6180                 tdata->validCipherOffsetInBits.len,
6181                 tdata->validAuthLenInBits.len,
6182                 0,
6183                 op_mode, 0, verify);
6184
6185         if (retval < 0)
6186                 return retval;
6187
6188         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6189                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6190                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6191         else
6192                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6193                         ut_params->op);
6194
6195         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6196
6197         ut_params->obuf = (op_mode == IN_PLACE ?
6198                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6199
6200
6201         if (verify) {
6202                 if (ut_params->obuf)
6203                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6204                                                         uint8_t *);
6205                 else
6206                         plaintext = ciphertext;
6207
6208                 debug_hexdump(stdout, "plaintext:", plaintext,
6209                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6210                 debug_hexdump(stdout, "plaintext expected:",
6211                         tdata->plaintext.data,
6212                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6213         } else {
6214                 if (ut_params->obuf)
6215                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6216                                                         uint8_t *);
6217                 else
6218                         ciphertext = plaintext;
6219
6220                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6221                         ciphertext_len);
6222                 debug_hexdump(stdout, "ciphertext expected:",
6223                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6224
6225                 ut_params->digest = rte_pktmbuf_mtod(
6226                         ut_params->obuf, uint8_t *) +
6227                         (tdata->digest.offset_bytes == 0 ?
6228                         plaintext_pad_len : tdata->digest.offset_bytes);
6229
6230                 debug_hexdump(stdout, "digest:", ut_params->digest,
6231                         tdata->digest.len);
6232                 debug_hexdump(stdout, "digest expected:",
6233                         tdata->digest.data, tdata->digest.len);
6234         }
6235
6236         /* Validate obuf */
6237         if (verify) {
6238                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6239                         plaintext,
6240                         tdata->plaintext.data,
6241                         tdata->plaintext.len >> 3,
6242                         "ZUC Plaintext data not as expected");
6243         } else {
6244                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6245                         ciphertext,
6246                         tdata->ciphertext.data,
6247                         tdata->ciphertext.len >> 3,
6248                         "ZUC Ciphertext data not as expected");
6249
6250                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6251                         ut_params->digest,
6252                         tdata->digest.data,
6253                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6254                         "ZUC Generated auth tag not as expected");
6255         }
6256         return 0;
6257 }
6258
6259 static int
6260 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6261         uint8_t op_mode, uint8_t verify)
6262 {
6263         struct crypto_testsuite_params *ts_params = &testsuite_params;
6264         struct crypto_unittest_params *ut_params = &unittest_params;
6265
6266         int retval;
6267
6268         const uint8_t *plaintext = NULL;
6269         const uint8_t *ciphertext = NULL;
6270         const uint8_t *digest = NULL;
6271         unsigned int plaintext_pad_len;
6272         unsigned int plaintext_len;
6273         unsigned int ciphertext_pad_len;
6274         unsigned int ciphertext_len;
6275         uint8_t buffer[10000];
6276         uint8_t digest_buffer[10000];
6277
6278         struct rte_cryptodev_info dev_info;
6279         struct rte_cryptodev_sym_capability_idx cap_idx;
6280
6281         /* Check if device supports ZUC EIA3 */
6282         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6283         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6284
6285         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6286                         &cap_idx) == NULL)
6287                 return TEST_SKIPPED;
6288
6289         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6290
6291         uint64_t feat_flags = dev_info.feature_flags;
6292
6293         if (op_mode == IN_PLACE) {
6294                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6295                         printf("Device doesn't support in-place scatter-gather "
6296                                         "in both input and output mbufs.\n");
6297                         return TEST_SKIPPED;
6298                 }
6299
6300                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6301                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6302                         printf("Device doesn't support RAW data-path APIs.\n");
6303                         return TEST_SKIPPED;
6304                 }
6305         } else {
6306                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6307                         return TEST_SKIPPED;
6308                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6309                         printf("Device doesn't support out-of-place scatter-gather "
6310                                         "in both input and output mbufs.\n");
6311                         return TEST_SKIPPED;
6312                 }
6313                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6314                         printf("Device doesn't support digest encrypted.\n");
6315                         return TEST_SKIPPED;
6316                 }
6317         }
6318
6319         /* Create ZUC session */
6320         retval = create_wireless_algo_auth_cipher_session(
6321                         ts_params->valid_devs[0],
6322                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6323                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6324                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6325                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6326                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6327                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6328                         tdata->key.data, tdata->key.len,
6329                         tdata->auth_iv.len, tdata->digest.len,
6330                         tdata->cipher_iv.len);
6331
6332         if (retval != 0)
6333                 return retval;
6334
6335         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6336         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6337         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6338         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6339
6340         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6341                         plaintext_pad_len, 15, 0);
6342         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6343                         "Failed to allocate input buffer in mempool");
6344
6345         if (op_mode == OUT_OF_PLACE) {
6346                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6347                                 plaintext_pad_len, 15, 0);
6348                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6349                                 "Failed to allocate output buffer in mempool");
6350         }
6351
6352         if (verify) {
6353                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6354                         tdata->ciphertext.data);
6355                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6356                                         ciphertext_len, buffer);
6357                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6358                         ciphertext_len);
6359         } else {
6360                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6361                         tdata->plaintext.data);
6362                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6363                                         plaintext_len, buffer);
6364                 debug_hexdump(stdout, "plaintext:", plaintext,
6365                         plaintext_len);
6366         }
6367         memset(buffer, 0, sizeof(buffer));
6368
6369         /* Create ZUC operation */
6370         retval = create_wireless_algo_auth_cipher_operation(
6371                 tdata->digest.data, tdata->digest.len,
6372                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6373                 NULL, 0,
6374                 (tdata->digest.offset_bytes == 0 ?
6375                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6376                         : tdata->digest.offset_bytes),
6377                 tdata->validCipherLenInBits.len,
6378                 tdata->validCipherOffsetInBits.len,
6379                 tdata->validAuthLenInBits.len,
6380                 0,
6381                 op_mode, 1, verify);
6382
6383         if (retval < 0)
6384                 return retval;
6385
6386         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6387                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6388                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6389         else
6390                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6391                         ut_params->op);
6392
6393         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6394
6395         ut_params->obuf = (op_mode == IN_PLACE ?
6396                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6397
6398         if (verify) {
6399                 if (ut_params->obuf)
6400                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6401                                         plaintext_len, buffer);
6402                 else
6403                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6404                                         plaintext_len, buffer);
6405
6406                 debug_hexdump(stdout, "plaintext:", plaintext,
6407                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6408                 debug_hexdump(stdout, "plaintext expected:",
6409                         tdata->plaintext.data,
6410                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6411         } else {
6412                 if (ut_params->obuf)
6413                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6414                                         ciphertext_len, buffer);
6415                 else
6416                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6417                                         ciphertext_len, buffer);
6418
6419                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6420                         ciphertext_len);
6421                 debug_hexdump(stdout, "ciphertext expected:",
6422                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6423
6424                 if (ut_params->obuf)
6425                         digest = rte_pktmbuf_read(ut_params->obuf,
6426                                 (tdata->digest.offset_bytes == 0 ?
6427                                 plaintext_pad_len : tdata->digest.offset_bytes),
6428                                 tdata->digest.len, digest_buffer);
6429                 else
6430                         digest = rte_pktmbuf_read(ut_params->ibuf,
6431                                 (tdata->digest.offset_bytes == 0 ?
6432                                 plaintext_pad_len : tdata->digest.offset_bytes),
6433                                 tdata->digest.len, digest_buffer);
6434
6435                 debug_hexdump(stdout, "digest:", digest,
6436                         tdata->digest.len);
6437                 debug_hexdump(stdout, "digest expected:",
6438                         tdata->digest.data, tdata->digest.len);
6439         }
6440
6441         /* Validate obuf */
6442         if (verify) {
6443                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6444                         plaintext,
6445                         tdata->plaintext.data,
6446                         tdata->plaintext.len >> 3,
6447                         "ZUC Plaintext data not as expected");
6448         } else {
6449                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6450                         ciphertext,
6451                         tdata->ciphertext.data,
6452                         tdata->validDataLenInBits.len,
6453                         "ZUC Ciphertext data not as expected");
6454
6455                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6456                         digest,
6457                         tdata->digest.data,
6458                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6459                         "ZUC Generated auth tag not as expected");
6460         }
6461         return 0;
6462 }
6463
6464 static int
6465 test_kasumi_encryption_test_case_1(void)
6466 {
6467         return test_kasumi_encryption(&kasumi_test_case_1);
6468 }
6469
6470 static int
6471 test_kasumi_encryption_test_case_1_sgl(void)
6472 {
6473         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6474 }
6475
6476 static int
6477 test_kasumi_encryption_test_case_1_oop(void)
6478 {
6479         return test_kasumi_encryption_oop(&kasumi_test_case_1);
6480 }
6481
6482 static int
6483 test_kasumi_encryption_test_case_1_oop_sgl(void)
6484 {
6485         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6486 }
6487
6488 static int
6489 test_kasumi_encryption_test_case_2(void)
6490 {
6491         return test_kasumi_encryption(&kasumi_test_case_2);
6492 }
6493
6494 static int
6495 test_kasumi_encryption_test_case_3(void)
6496 {
6497         return test_kasumi_encryption(&kasumi_test_case_3);
6498 }
6499
6500 static int
6501 test_kasumi_encryption_test_case_4(void)
6502 {
6503         return test_kasumi_encryption(&kasumi_test_case_4);
6504 }
6505
6506 static int
6507 test_kasumi_encryption_test_case_5(void)
6508 {
6509         return test_kasumi_encryption(&kasumi_test_case_5);
6510 }
6511
6512 static int
6513 test_kasumi_decryption_test_case_1(void)
6514 {
6515         return test_kasumi_decryption(&kasumi_test_case_1);
6516 }
6517
6518 static int
6519 test_kasumi_decryption_test_case_1_oop(void)
6520 {
6521         return test_kasumi_decryption_oop(&kasumi_test_case_1);
6522 }
6523
6524 static int
6525 test_kasumi_decryption_test_case_2(void)
6526 {
6527         return test_kasumi_decryption(&kasumi_test_case_2);
6528 }
6529
6530 static int
6531 test_kasumi_decryption_test_case_3(void)
6532 {
6533         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6534         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6535                 return TEST_SKIPPED;
6536         return test_kasumi_decryption(&kasumi_test_case_3);
6537 }
6538
6539 static int
6540 test_kasumi_decryption_test_case_4(void)
6541 {
6542         return test_kasumi_decryption(&kasumi_test_case_4);
6543 }
6544
6545 static int
6546 test_kasumi_decryption_test_case_5(void)
6547 {
6548         return test_kasumi_decryption(&kasumi_test_case_5);
6549 }
6550 static int
6551 test_snow3g_encryption_test_case_1(void)
6552 {
6553         return test_snow3g_encryption(&snow3g_test_case_1);
6554 }
6555
6556 static int
6557 test_snow3g_encryption_test_case_1_oop(void)
6558 {
6559         return test_snow3g_encryption_oop(&snow3g_test_case_1);
6560 }
6561
6562 static int
6563 test_snow3g_encryption_test_case_1_oop_sgl(void)
6564 {
6565         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6566 }
6567
6568
6569 static int
6570 test_snow3g_encryption_test_case_1_offset_oop(void)
6571 {
6572         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6573 }
6574
6575 static int
6576 test_snow3g_encryption_test_case_2(void)
6577 {
6578         return test_snow3g_encryption(&snow3g_test_case_2);
6579 }
6580
6581 static int
6582 test_snow3g_encryption_test_case_3(void)
6583 {
6584         return test_snow3g_encryption(&snow3g_test_case_3);
6585 }
6586
6587 static int
6588 test_snow3g_encryption_test_case_4(void)
6589 {
6590         return test_snow3g_encryption(&snow3g_test_case_4);
6591 }
6592
6593 static int
6594 test_snow3g_encryption_test_case_5(void)
6595 {
6596         return test_snow3g_encryption(&snow3g_test_case_5);
6597 }
6598
6599 static int
6600 test_snow3g_decryption_test_case_1(void)
6601 {
6602         return test_snow3g_decryption(&snow3g_test_case_1);
6603 }
6604
6605 static int
6606 test_snow3g_decryption_test_case_1_oop(void)
6607 {
6608         return test_snow3g_decryption_oop(&snow3g_test_case_1);
6609 }
6610
6611 static int
6612 test_snow3g_decryption_test_case_2(void)
6613 {
6614         return test_snow3g_decryption(&snow3g_test_case_2);
6615 }
6616
6617 static int
6618 test_snow3g_decryption_test_case_3(void)
6619 {
6620         return test_snow3g_decryption(&snow3g_test_case_3);
6621 }
6622
6623 static int
6624 test_snow3g_decryption_test_case_4(void)
6625 {
6626         return test_snow3g_decryption(&snow3g_test_case_4);
6627 }
6628
6629 static int
6630 test_snow3g_decryption_test_case_5(void)
6631 {
6632         return test_snow3g_decryption(&snow3g_test_case_5);
6633 }
6634
6635 /*
6636  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6637  * Pattern digest from snow3g_test_data must be allocated as
6638  * 4 last bytes in plaintext.
6639  */
6640 static void
6641 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6642                 struct snow3g_hash_test_data *output)
6643 {
6644         if ((pattern != NULL) && (output != NULL)) {
6645                 output->key.len = pattern->key.len;
6646
6647                 memcpy(output->key.data,
6648                 pattern->key.data, pattern->key.len);
6649
6650                 output->auth_iv.len = pattern->auth_iv.len;
6651
6652                 memcpy(output->auth_iv.data,
6653                 pattern->auth_iv.data, pattern->auth_iv.len);
6654
6655                 output->plaintext.len = pattern->plaintext.len;
6656
6657                 memcpy(output->plaintext.data,
6658                 pattern->plaintext.data, pattern->plaintext.len >> 3);
6659
6660                 output->digest.len = pattern->digest.len;
6661
6662                 memcpy(output->digest.data,
6663                 &pattern->plaintext.data[pattern->digest.offset_bytes],
6664                 pattern->digest.len);
6665
6666                 output->validAuthLenInBits.len =
6667                 pattern->validAuthLenInBits.len;
6668         }
6669 }
6670
6671 /*
6672  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6673  */
6674 static int
6675 test_snow3g_decryption_with_digest_test_case_1(void)
6676 {
6677         struct snow3g_hash_test_data snow3g_hash_data;
6678         struct rte_cryptodev_info dev_info;
6679         struct crypto_testsuite_params *ts_params = &testsuite_params;
6680
6681         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6682         uint64_t feat_flags = dev_info.feature_flags;
6683
6684         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6685                 printf("Device doesn't support encrypted digest operations.\n");
6686                 return TEST_SKIPPED;
6687         }
6688
6689         /*
6690          * Function prepare data for hash veryfication test case.
6691          * Digest is allocated in 4 last bytes in plaintext, pattern.
6692          */
6693         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6694
6695         return test_snow3g_decryption(&snow3g_test_case_7) &
6696                         test_snow3g_authentication_verify(&snow3g_hash_data);
6697 }
6698
6699 static int
6700 test_snow3g_cipher_auth_test_case_1(void)
6701 {
6702         return test_snow3g_cipher_auth(&snow3g_test_case_3);
6703 }
6704
6705 static int
6706 test_snow3g_auth_cipher_test_case_1(void)
6707 {
6708         return test_snow3g_auth_cipher(
6709                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6710 }
6711
6712 static int
6713 test_snow3g_auth_cipher_test_case_2(void)
6714 {
6715         return test_snow3g_auth_cipher(
6716                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6717 }
6718
6719 static int
6720 test_snow3g_auth_cipher_test_case_2_oop(void)
6721 {
6722         return test_snow3g_auth_cipher(
6723                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6724 }
6725
6726 static int
6727 test_snow3g_auth_cipher_part_digest_enc(void)
6728 {
6729         return test_snow3g_auth_cipher(
6730                 &snow3g_auth_cipher_partial_digest_encryption,
6731                         IN_PLACE, 0);
6732 }
6733
6734 static int
6735 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6736 {
6737         return test_snow3g_auth_cipher(
6738                 &snow3g_auth_cipher_partial_digest_encryption,
6739                         OUT_OF_PLACE, 0);
6740 }
6741
6742 static int
6743 test_snow3g_auth_cipher_test_case_3_sgl(void)
6744 {
6745         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6746         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6747                 return TEST_SKIPPED;
6748         return test_snow3g_auth_cipher_sgl(
6749                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6750 }
6751
6752 static int
6753 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6754 {
6755         return test_snow3g_auth_cipher_sgl(
6756                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6757 }
6758
6759 static int
6760 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6761 {
6762         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6763         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6764                 return TEST_SKIPPED;
6765         return test_snow3g_auth_cipher_sgl(
6766                 &snow3g_auth_cipher_partial_digest_encryption,
6767                         IN_PLACE, 0);
6768 }
6769
6770 static int
6771 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6772 {
6773         return test_snow3g_auth_cipher_sgl(
6774                 &snow3g_auth_cipher_partial_digest_encryption,
6775                         OUT_OF_PLACE, 0);
6776 }
6777
6778 static int
6779 test_snow3g_auth_cipher_verify_test_case_1(void)
6780 {
6781         return test_snow3g_auth_cipher(
6782                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6783 }
6784
6785 static int
6786 test_snow3g_auth_cipher_verify_test_case_2(void)
6787 {
6788         return test_snow3g_auth_cipher(
6789                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6790 }
6791
6792 static int
6793 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6794 {
6795         return test_snow3g_auth_cipher(
6796                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6797 }
6798
6799 static int
6800 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6801 {
6802         return test_snow3g_auth_cipher(
6803                 &snow3g_auth_cipher_partial_digest_encryption,
6804                         IN_PLACE, 1);
6805 }
6806
6807 static int
6808 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6809 {
6810         return test_snow3g_auth_cipher(
6811                 &snow3g_auth_cipher_partial_digest_encryption,
6812                         OUT_OF_PLACE, 1);
6813 }
6814
6815 static int
6816 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6817 {
6818         return test_snow3g_auth_cipher_sgl(
6819                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6820 }
6821
6822 static int
6823 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6824 {
6825         return test_snow3g_auth_cipher_sgl(
6826                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6827 }
6828
6829 static int
6830 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6831 {
6832         return test_snow3g_auth_cipher_sgl(
6833                 &snow3g_auth_cipher_partial_digest_encryption,
6834                         IN_PLACE, 1);
6835 }
6836
6837 static int
6838 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6839 {
6840         return test_snow3g_auth_cipher_sgl(
6841                 &snow3g_auth_cipher_partial_digest_encryption,
6842                         OUT_OF_PLACE, 1);
6843 }
6844
6845 static int
6846 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6847 {
6848         return test_snow3g_auth_cipher(
6849                 &snow3g_test_case_7, IN_PLACE, 0);
6850 }
6851
6852 static int
6853 test_kasumi_auth_cipher_test_case_1(void)
6854 {
6855         return test_kasumi_auth_cipher(
6856                 &kasumi_test_case_3, IN_PLACE, 0);
6857 }
6858
6859 static int
6860 test_kasumi_auth_cipher_test_case_2(void)
6861 {
6862         return test_kasumi_auth_cipher(
6863                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6864 }
6865
6866 static int
6867 test_kasumi_auth_cipher_test_case_2_oop(void)
6868 {
6869         return test_kasumi_auth_cipher(
6870                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6871 }
6872
6873 static int
6874 test_kasumi_auth_cipher_test_case_2_sgl(void)
6875 {
6876         return test_kasumi_auth_cipher_sgl(
6877                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6878 }
6879
6880 static int
6881 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6882 {
6883         return test_kasumi_auth_cipher_sgl(
6884                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6885 }
6886
6887 static int
6888 test_kasumi_auth_cipher_verify_test_case_1(void)
6889 {
6890         return test_kasumi_auth_cipher(
6891                 &kasumi_test_case_3, IN_PLACE, 1);
6892 }
6893
6894 static int
6895 test_kasumi_auth_cipher_verify_test_case_2(void)
6896 {
6897         return test_kasumi_auth_cipher(
6898                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6899 }
6900
6901 static int
6902 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6903 {
6904         return test_kasumi_auth_cipher(
6905                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6906 }
6907
6908 static int
6909 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6910 {
6911         return test_kasumi_auth_cipher_sgl(
6912                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6913 }
6914
6915 static int
6916 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6917 {
6918         return test_kasumi_auth_cipher_sgl(
6919                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6920 }
6921
6922 static int
6923 test_kasumi_cipher_auth_test_case_1(void)
6924 {
6925         return test_kasumi_cipher_auth(&kasumi_test_case_6);
6926 }
6927
6928 static int
6929 test_zuc_encryption_test_case_1(void)
6930 {
6931         return test_zuc_encryption(&zuc_test_case_cipher_193b);
6932 }
6933
6934 static int
6935 test_zuc_encryption_test_case_2(void)
6936 {
6937         return test_zuc_encryption(&zuc_test_case_cipher_800b);
6938 }
6939
6940 static int
6941 test_zuc_encryption_test_case_3(void)
6942 {
6943         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
6944 }
6945
6946 static int
6947 test_zuc_encryption_test_case_4(void)
6948 {
6949         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
6950 }
6951
6952 static int
6953 test_zuc_encryption_test_case_5(void)
6954 {
6955         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
6956 }
6957
6958 static int
6959 test_zuc_encryption_test_case_6_sgl(void)
6960 {
6961         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
6962 }
6963
6964 static int
6965 test_zuc_hash_generate_test_case_1(void)
6966 {
6967         return test_zuc_authentication(&zuc_test_case_auth_1b);
6968 }
6969
6970 static int
6971 test_zuc_hash_generate_test_case_2(void)
6972 {
6973         return test_zuc_authentication(&zuc_test_case_auth_90b);
6974 }
6975
6976 static int
6977 test_zuc_hash_generate_test_case_3(void)
6978 {
6979         return test_zuc_authentication(&zuc_test_case_auth_577b);
6980 }
6981
6982 static int
6983 test_zuc_hash_generate_test_case_4(void)
6984 {
6985         return test_zuc_authentication(&zuc_test_case_auth_2079b);
6986 }
6987
6988 static int
6989 test_zuc_hash_generate_test_case_5(void)
6990 {
6991         return test_zuc_authentication(&zuc_test_auth_5670b);
6992 }
6993
6994 static int
6995 test_zuc_hash_generate_test_case_6(void)
6996 {
6997         return test_zuc_authentication(&zuc_test_case_auth_128b);
6998 }
6999
7000 static int
7001 test_zuc_hash_generate_test_case_7(void)
7002 {
7003         return test_zuc_authentication(&zuc_test_case_auth_2080b);
7004 }
7005
7006 static int
7007 test_zuc_hash_generate_test_case_8(void)
7008 {
7009         return test_zuc_authentication(&zuc_test_case_auth_584b);
7010 }
7011
7012 static int
7013 test_zuc_cipher_auth_test_case_1(void)
7014 {
7015         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7016 }
7017
7018 static int
7019 test_zuc_cipher_auth_test_case_2(void)
7020 {
7021         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7022 }
7023
7024 static int
7025 test_zuc_auth_cipher_test_case_1(void)
7026 {
7027         return test_zuc_auth_cipher(
7028                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7029 }
7030
7031 static int
7032 test_zuc_auth_cipher_test_case_1_oop(void)
7033 {
7034         return test_zuc_auth_cipher(
7035                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7036 }
7037
7038 static int
7039 test_zuc_auth_cipher_test_case_1_sgl(void)
7040 {
7041         return test_zuc_auth_cipher_sgl(
7042                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7043 }
7044
7045 static int
7046 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7047 {
7048         return test_zuc_auth_cipher_sgl(
7049                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7050 }
7051
7052 static int
7053 test_zuc_auth_cipher_verify_test_case_1(void)
7054 {
7055         return test_zuc_auth_cipher(
7056                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7057 }
7058
7059 static int
7060 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7061 {
7062         return test_zuc_auth_cipher(
7063                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7064 }
7065
7066 static int
7067 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7068 {
7069         return test_zuc_auth_cipher_sgl(
7070                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7071 }
7072
7073 static int
7074 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7075 {
7076         return test_zuc_auth_cipher_sgl(
7077                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7078 }
7079
7080 static int
7081 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7082 {
7083         uint8_t dev_id = testsuite_params.valid_devs[0];
7084
7085         struct rte_cryptodev_sym_capability_idx cap_idx;
7086
7087         /* Check if device supports particular cipher algorithm */
7088         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7089         cap_idx.algo.cipher = tdata->cipher_algo;
7090         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7091                 return TEST_SKIPPED;
7092
7093         /* Check if device supports particular hash algorithm */
7094         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7095         cap_idx.algo.auth = tdata->auth_algo;
7096         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7097                 return TEST_SKIPPED;
7098
7099         return 0;
7100 }
7101
7102 static int
7103 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7104         uint8_t op_mode, uint8_t verify)
7105 {
7106         struct crypto_testsuite_params *ts_params = &testsuite_params;
7107         struct crypto_unittest_params *ut_params = &unittest_params;
7108
7109         int retval;
7110
7111         uint8_t *plaintext = NULL, *ciphertext = NULL;
7112         unsigned int plaintext_pad_len;
7113         unsigned int plaintext_len;
7114         unsigned int ciphertext_pad_len;
7115         unsigned int ciphertext_len;
7116
7117         struct rte_cryptodev_info dev_info;
7118         struct rte_crypto_op *op;
7119
7120         /* Check if device supports particular algorithms separately */
7121         if (test_mixed_check_if_unsupported(tdata))
7122                 return TEST_SKIPPED;
7123         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7124                 return TEST_SKIPPED;
7125
7126         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7127
7128         uint64_t feat_flags = dev_info.feature_flags;
7129
7130         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7131                 printf("Device doesn't support digest encrypted.\n");
7132                 return TEST_SKIPPED;
7133         }
7134
7135         /* Create the session */
7136         if (verify)
7137                 retval = create_wireless_algo_cipher_auth_session(
7138                                 ts_params->valid_devs[0],
7139                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7140                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7141                                 tdata->auth_algo,
7142                                 tdata->cipher_algo,
7143                                 tdata->auth_key.data, tdata->auth_key.len,
7144                                 tdata->auth_iv.len, tdata->digest_enc.len,
7145                                 tdata->cipher_iv.len);
7146         else
7147                 retval = create_wireless_algo_auth_cipher_session(
7148                                 ts_params->valid_devs[0],
7149                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7150                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7151                                 tdata->auth_algo,
7152                                 tdata->cipher_algo,
7153                                 tdata->auth_key.data, tdata->auth_key.len,
7154                                 tdata->auth_iv.len, tdata->digest_enc.len,
7155                                 tdata->cipher_iv.len);
7156         if (retval != 0)
7157                 return retval;
7158
7159         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7160         if (op_mode == OUT_OF_PLACE)
7161                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7162
7163         /* clear mbuf payload */
7164         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7165                 rte_pktmbuf_tailroom(ut_params->ibuf));
7166         if (op_mode == OUT_OF_PLACE) {
7167
7168                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7169                                 rte_pktmbuf_tailroom(ut_params->obuf));
7170         }
7171
7172         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7173         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7174         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7175         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7176
7177         if (verify) {
7178                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7179                                 ciphertext_pad_len);
7180                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7181                 if (op_mode == OUT_OF_PLACE)
7182                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7183                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7184                                 ciphertext_len);
7185         } else {
7186                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7187                                 plaintext_pad_len);
7188                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7189                 if (op_mode == OUT_OF_PLACE)
7190                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7191                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7192         }
7193
7194         /* Create the operation */
7195         retval = create_wireless_algo_auth_cipher_operation(
7196                         tdata->digest_enc.data, tdata->digest_enc.len,
7197                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7198                         tdata->auth_iv.data, tdata->auth_iv.len,
7199                         (tdata->digest_enc.offset == 0 ?
7200                                 plaintext_pad_len
7201                                 : tdata->digest_enc.offset),
7202                         tdata->validCipherLen.len_bits,
7203                         tdata->cipher.offset_bits,
7204                         tdata->validAuthLen.len_bits,
7205                         tdata->auth.offset_bits,
7206                         op_mode, 0, verify);
7207
7208         if (retval < 0)
7209                 return retval;
7210
7211         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7212
7213         /* Check if the op failed because the device doesn't */
7214         /* support this particular combination of algorithms */
7215         if (op == NULL && ut_params->op->status ==
7216                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7217                 printf("Device doesn't support this mixed combination. "
7218                                 "Test Skipped.\n");
7219                 return TEST_SKIPPED;
7220         }
7221         ut_params->op = op;
7222
7223         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7224
7225         ut_params->obuf = (op_mode == IN_PLACE ?
7226                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7227
7228         if (verify) {
7229                 if (ut_params->obuf)
7230                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7231                                                         uint8_t *);
7232                 else
7233                         plaintext = ciphertext +
7234                                         (tdata->cipher.offset_bits >> 3);
7235
7236                 debug_hexdump(stdout, "plaintext:", plaintext,
7237                                 tdata->plaintext.len_bits >> 3);
7238                 debug_hexdump(stdout, "plaintext expected:",
7239                                 tdata->plaintext.data,
7240                                 tdata->plaintext.len_bits >> 3);
7241         } else {
7242                 if (ut_params->obuf)
7243                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7244                                         uint8_t *);
7245                 else
7246                         ciphertext = plaintext;
7247
7248                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7249                                 ciphertext_len);
7250                 debug_hexdump(stdout, "ciphertext expected:",
7251                                 tdata->ciphertext.data,
7252                                 tdata->ciphertext.len_bits >> 3);
7253
7254                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7255                                 + (tdata->digest_enc.offset == 0 ?
7256                 plaintext_pad_len : tdata->digest_enc.offset);
7257
7258                 debug_hexdump(stdout, "digest:", ut_params->digest,
7259                                 tdata->digest_enc.len);
7260                 debug_hexdump(stdout, "digest expected:",
7261                                 tdata->digest_enc.data,
7262                                 tdata->digest_enc.len);
7263         }
7264
7265         /* Validate obuf */
7266         if (verify) {
7267                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7268                                 plaintext,
7269                                 tdata->plaintext.data,
7270                                 tdata->plaintext.len_bits >> 3,
7271                                 "Plaintext data not as expected");
7272         } else {
7273                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7274                                 ciphertext,
7275                                 tdata->ciphertext.data,
7276                                 tdata->validDataLen.len_bits,
7277                                 "Ciphertext data not as expected");
7278
7279                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7280                                 ut_params->digest,
7281                                 tdata->digest_enc.data,
7282                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7283                                 "Generated auth tag not as expected");
7284         }
7285
7286         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7287                         "crypto op processing failed");
7288
7289         return 0;
7290 }
7291
7292 static int
7293 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7294         uint8_t op_mode, uint8_t verify)
7295 {
7296         struct crypto_testsuite_params *ts_params = &testsuite_params;
7297         struct crypto_unittest_params *ut_params = &unittest_params;
7298
7299         int retval;
7300
7301         const uint8_t *plaintext = NULL;
7302         const uint8_t *ciphertext = NULL;
7303         const uint8_t *digest = NULL;
7304         unsigned int plaintext_pad_len;
7305         unsigned int plaintext_len;
7306         unsigned int ciphertext_pad_len;
7307         unsigned int ciphertext_len;
7308         uint8_t buffer[10000];
7309         uint8_t digest_buffer[10000];
7310
7311         struct rte_cryptodev_info dev_info;
7312         struct rte_crypto_op *op;
7313
7314         /* Check if device supports particular algorithms */
7315         if (test_mixed_check_if_unsupported(tdata))
7316                 return TEST_SKIPPED;
7317         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7318                 return TEST_SKIPPED;
7319
7320         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7321
7322         uint64_t feat_flags = dev_info.feature_flags;
7323
7324         if (op_mode == IN_PLACE) {
7325                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7326                         printf("Device doesn't support in-place scatter-gather "
7327                                         "in both input and output mbufs.\n");
7328                         return TEST_SKIPPED;
7329                 }
7330         } else {
7331                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7332                         printf("Device doesn't support out-of-place scatter-gather "
7333                                         "in both input and output mbufs.\n");
7334                         return TEST_SKIPPED;
7335                 }
7336                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7337                         printf("Device doesn't support digest encrypted.\n");
7338                         return TEST_SKIPPED;
7339                 }
7340         }
7341
7342         /* Create the session */
7343         if (verify)
7344                 retval = create_wireless_algo_cipher_auth_session(
7345                                 ts_params->valid_devs[0],
7346                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7347                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7348                                 tdata->auth_algo,
7349                                 tdata->cipher_algo,
7350                                 tdata->auth_key.data, tdata->auth_key.len,
7351                                 tdata->auth_iv.len, tdata->digest_enc.len,
7352                                 tdata->cipher_iv.len);
7353         else
7354                 retval = create_wireless_algo_auth_cipher_session(
7355                                 ts_params->valid_devs[0],
7356                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7357                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7358                                 tdata->auth_algo,
7359                                 tdata->cipher_algo,
7360                                 tdata->auth_key.data, tdata->auth_key.len,
7361                                 tdata->auth_iv.len, tdata->digest_enc.len,
7362                                 tdata->cipher_iv.len);
7363         if (retval != 0)
7364                 return retval;
7365
7366         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7367         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7368         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7369         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7370
7371         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7372                         ciphertext_pad_len, 15, 0);
7373         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7374                         "Failed to allocate input buffer in mempool");
7375
7376         if (op_mode == OUT_OF_PLACE) {
7377                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7378                                 plaintext_pad_len, 15, 0);
7379                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
7380                                 "Failed to allocate output buffer in mempool");
7381         }
7382
7383         if (verify) {
7384                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7385                         tdata->ciphertext.data);
7386                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7387                                         ciphertext_len, buffer);
7388                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7389                         ciphertext_len);
7390         } else {
7391                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7392                         tdata->plaintext.data);
7393                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7394                                         plaintext_len, buffer);
7395                 debug_hexdump(stdout, "plaintext:", plaintext,
7396                         plaintext_len);
7397         }
7398         memset(buffer, 0, sizeof(buffer));
7399
7400         /* Create the operation */
7401         retval = create_wireless_algo_auth_cipher_operation(
7402                         tdata->digest_enc.data, tdata->digest_enc.len,
7403                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7404                         tdata->auth_iv.data, tdata->auth_iv.len,
7405                         (tdata->digest_enc.offset == 0 ?
7406                                 plaintext_pad_len
7407                                 : tdata->digest_enc.offset),
7408                         tdata->validCipherLen.len_bits,
7409                         tdata->cipher.offset_bits,
7410                         tdata->validAuthLen.len_bits,
7411                         tdata->auth.offset_bits,
7412                         op_mode, 1, verify);
7413
7414         if (retval < 0)
7415                 return retval;
7416
7417         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7418
7419         /* Check if the op failed because the device doesn't */
7420         /* support this particular combination of algorithms */
7421         if (op == NULL && ut_params->op->status ==
7422                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7423                 printf("Device doesn't support this mixed combination. "
7424                                 "Test Skipped.\n");
7425                 return TEST_SKIPPED;
7426         }
7427         ut_params->op = op;
7428
7429         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7430
7431         ut_params->obuf = (op_mode == IN_PLACE ?
7432                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7433
7434         if (verify) {
7435                 if (ut_params->obuf)
7436                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7437                                         plaintext_len, buffer);
7438                 else
7439                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7440                                         plaintext_len, buffer);
7441
7442                 debug_hexdump(stdout, "plaintext:", plaintext,
7443                                 (tdata->plaintext.len_bits >> 3) -
7444                                 tdata->digest_enc.len);
7445                 debug_hexdump(stdout, "plaintext expected:",
7446                                 tdata->plaintext.data,
7447                                 (tdata->plaintext.len_bits >> 3) -
7448                                 tdata->digest_enc.len);
7449         } else {
7450                 if (ut_params->obuf)
7451                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7452                                         ciphertext_len, buffer);
7453                 else
7454                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7455                                         ciphertext_len, buffer);
7456
7457                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7458                         ciphertext_len);
7459                 debug_hexdump(stdout, "ciphertext expected:",
7460                         tdata->ciphertext.data,
7461                         tdata->ciphertext.len_bits >> 3);
7462
7463                 if (ut_params->obuf)
7464                         digest = rte_pktmbuf_read(ut_params->obuf,
7465                                         (tdata->digest_enc.offset == 0 ?
7466                                                 plaintext_pad_len :
7467                                                 tdata->digest_enc.offset),
7468                                         tdata->digest_enc.len, digest_buffer);
7469                 else
7470                         digest = rte_pktmbuf_read(ut_params->ibuf,
7471                                         (tdata->digest_enc.offset == 0 ?
7472                                                 plaintext_pad_len :
7473                                                 tdata->digest_enc.offset),
7474                                         tdata->digest_enc.len, digest_buffer);
7475
7476                 debug_hexdump(stdout, "digest:", digest,
7477                                 tdata->digest_enc.len);
7478                 debug_hexdump(stdout, "digest expected:",
7479                                 tdata->digest_enc.data, tdata->digest_enc.len);
7480         }
7481
7482         /* Validate obuf */
7483         if (verify) {
7484                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7485                                 plaintext,
7486                                 tdata->plaintext.data,
7487                                 tdata->plaintext.len_bits >> 3,
7488                                 "Plaintext data not as expected");
7489         } else {
7490                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7491                                 ciphertext,
7492                                 tdata->ciphertext.data,
7493                                 tdata->validDataLen.len_bits,
7494                                 "Ciphertext data not as expected");
7495                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7496                                 digest,
7497                                 tdata->digest_enc.data,
7498                                 tdata->digest_enc.len,
7499                                 "Generated auth tag not as expected");
7500         }
7501
7502         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7503                         "crypto op processing failed");
7504
7505         return 0;
7506 }
7507
7508 /** AUTH AES CMAC + CIPHER AES CTR */
7509
7510 static int
7511 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7512 {
7513         return test_mixed_auth_cipher(
7514                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7515 }
7516
7517 static int
7518 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7519 {
7520         return test_mixed_auth_cipher(
7521                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7522 }
7523
7524 static int
7525 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7526 {
7527         return test_mixed_auth_cipher_sgl(
7528                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7529 }
7530
7531 static int
7532 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7533 {
7534         return test_mixed_auth_cipher_sgl(
7535                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7536 }
7537
7538 static int
7539 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7540 {
7541         return test_mixed_auth_cipher(
7542                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7543 }
7544
7545 static int
7546 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7547 {
7548         return test_mixed_auth_cipher(
7549                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7550 }
7551
7552 static int
7553 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7554 {
7555         return test_mixed_auth_cipher_sgl(
7556                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7557 }
7558
7559 static int
7560 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7561 {
7562         return test_mixed_auth_cipher_sgl(
7563                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7564 }
7565
7566 /** MIXED AUTH + CIPHER */
7567
7568 static int
7569 test_auth_zuc_cipher_snow_test_case_1(void)
7570 {
7571         return test_mixed_auth_cipher(
7572                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7573 }
7574
7575 static int
7576 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7577 {
7578         return test_mixed_auth_cipher(
7579                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7580 }
7581
7582 static int
7583 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7584 {
7585         return test_mixed_auth_cipher(
7586                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7587 }
7588
7589 static int
7590 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7591 {
7592         return test_mixed_auth_cipher(
7593                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7594 }
7595
7596 static int
7597 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7598 {
7599         return test_mixed_auth_cipher(
7600                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7601 }
7602
7603 static int
7604 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7605 {
7606         return test_mixed_auth_cipher(
7607                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7608 }
7609
7610 static int
7611 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7612 {
7613         return test_mixed_auth_cipher(
7614                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7615 }
7616
7617 static int
7618 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7619 {
7620         return test_mixed_auth_cipher(
7621                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7622 }
7623
7624 static int
7625 test_auth_snow_cipher_zuc_test_case_1(void)
7626 {
7627         return test_mixed_auth_cipher(
7628                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7629 }
7630
7631 static int
7632 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7633 {
7634         return test_mixed_auth_cipher(
7635                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7636 }
7637
7638 static int
7639 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7640 {
7641         return test_mixed_auth_cipher(
7642                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7643 }
7644
7645 static int
7646 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7647 {
7648         return test_mixed_auth_cipher(
7649                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7650 }
7651
7652 static int
7653 test_auth_null_cipher_snow_test_case_1(void)
7654 {
7655         return test_mixed_auth_cipher(
7656                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7657 }
7658
7659 static int
7660 test_verify_auth_null_cipher_snow_test_case_1(void)
7661 {
7662         return test_mixed_auth_cipher(
7663                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7664 }
7665
7666 static int
7667 test_auth_null_cipher_zuc_test_case_1(void)
7668 {
7669         return test_mixed_auth_cipher(
7670                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7671 }
7672
7673 static int
7674 test_verify_auth_null_cipher_zuc_test_case_1(void)
7675 {
7676         return test_mixed_auth_cipher(
7677                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7678 }
7679
7680 static int
7681 test_auth_snow_cipher_null_test_case_1(void)
7682 {
7683         return test_mixed_auth_cipher(
7684                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7685 }
7686
7687 static int
7688 test_verify_auth_snow_cipher_null_test_case_1(void)
7689 {
7690         return test_mixed_auth_cipher(
7691                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7692 }
7693
7694 static int
7695 test_auth_zuc_cipher_null_test_case_1(void)
7696 {
7697         return test_mixed_auth_cipher(
7698                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7699 }
7700
7701 static int
7702 test_verify_auth_zuc_cipher_null_test_case_1(void)
7703 {
7704         return test_mixed_auth_cipher(
7705                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7706 }
7707
7708 static int
7709 test_auth_null_cipher_aes_ctr_test_case_1(void)
7710 {
7711         return test_mixed_auth_cipher(
7712                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7713 }
7714
7715 static int
7716 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7717 {
7718         return test_mixed_auth_cipher(
7719                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7720 }
7721
7722 static int
7723 test_auth_aes_cmac_cipher_null_test_case_1(void)
7724 {
7725         return test_mixed_auth_cipher(
7726                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7727 }
7728
7729 static int
7730 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7731 {
7732         return test_mixed_auth_cipher(
7733                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7734 }
7735
7736 /* ***** AEAD algorithm Tests ***** */
7737
7738 static int
7739 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7740                 enum rte_crypto_aead_operation op,
7741                 const uint8_t *key, const uint8_t key_len,
7742                 const uint16_t aad_len, const uint8_t auth_len,
7743                 uint8_t iv_len)
7744 {
7745         uint8_t aead_key[key_len];
7746
7747         struct crypto_testsuite_params *ts_params = &testsuite_params;
7748         struct crypto_unittest_params *ut_params = &unittest_params;
7749
7750         memcpy(aead_key, key, key_len);
7751
7752         /* Setup AEAD Parameters */
7753         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7754         ut_params->aead_xform.next = NULL;
7755         ut_params->aead_xform.aead.algo = algo;
7756         ut_params->aead_xform.aead.op = op;
7757         ut_params->aead_xform.aead.key.data = aead_key;
7758         ut_params->aead_xform.aead.key.length = key_len;
7759         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7760         ut_params->aead_xform.aead.iv.length = iv_len;
7761         ut_params->aead_xform.aead.digest_length = auth_len;
7762         ut_params->aead_xform.aead.aad_length = aad_len;
7763
7764         debug_hexdump(stdout, "key:", key, key_len);
7765
7766         /* Create Crypto session*/
7767         ut_params->sess = rte_cryptodev_sym_session_create(
7768                         ts_params->session_mpool);
7769
7770         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7771                         &ut_params->aead_xform,
7772                         ts_params->session_priv_mpool);
7773
7774         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7775
7776         return 0;
7777 }
7778
7779 static int
7780 create_aead_xform(struct rte_crypto_op *op,
7781                 enum rte_crypto_aead_algorithm algo,
7782                 enum rte_crypto_aead_operation aead_op,
7783                 uint8_t *key, const uint8_t key_len,
7784                 const uint8_t aad_len, const uint8_t auth_len,
7785                 uint8_t iv_len)
7786 {
7787         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7788                         "failed to allocate space for crypto transform");
7789
7790         struct rte_crypto_sym_op *sym_op = op->sym;
7791
7792         /* Setup AEAD Parameters */
7793         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7794         sym_op->xform->next = NULL;
7795         sym_op->xform->aead.algo = algo;
7796         sym_op->xform->aead.op = aead_op;
7797         sym_op->xform->aead.key.data = key;
7798         sym_op->xform->aead.key.length = key_len;
7799         sym_op->xform->aead.iv.offset = IV_OFFSET;
7800         sym_op->xform->aead.iv.length = iv_len;
7801         sym_op->xform->aead.digest_length = auth_len;
7802         sym_op->xform->aead.aad_length = aad_len;
7803
7804         debug_hexdump(stdout, "key:", key, key_len);
7805
7806         return 0;
7807 }
7808
7809 static int
7810 create_aead_operation(enum rte_crypto_aead_operation op,
7811                 const struct aead_test_data *tdata)
7812 {
7813         struct crypto_testsuite_params *ts_params = &testsuite_params;
7814         struct crypto_unittest_params *ut_params = &unittest_params;
7815
7816         uint8_t *plaintext, *ciphertext;
7817         unsigned int aad_pad_len, plaintext_pad_len;
7818
7819         /* Generate Crypto op data structure */
7820         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7821                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7822         TEST_ASSERT_NOT_NULL(ut_params->op,
7823                         "Failed to allocate symmetric crypto operation struct");
7824
7825         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7826
7827         /* Append aad data */
7828         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7829                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7830                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7831                                 aad_pad_len);
7832                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7833                                 "no room to append aad");
7834
7835                 sym_op->aead.aad.phys_addr =
7836                                 rte_pktmbuf_iova(ut_params->ibuf);
7837                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
7838                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7839                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7840                         tdata->aad.len);
7841
7842                 /* Append IV at the end of the crypto operation*/
7843                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7844                                 uint8_t *, IV_OFFSET);
7845
7846                 /* Copy IV 1 byte after the IV pointer, according to the API */
7847                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7848                 debug_hexdump(stdout, "iv:", iv_ptr,
7849                         tdata->iv.len);
7850         } else {
7851                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7852                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7853                                 aad_pad_len);
7854                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7855                                 "no room to append aad");
7856
7857                 sym_op->aead.aad.phys_addr =
7858                                 rte_pktmbuf_iova(ut_params->ibuf);
7859                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7860                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7861                         tdata->aad.len);
7862
7863                 /* Append IV at the end of the crypto operation*/
7864                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7865                                 uint8_t *, IV_OFFSET);
7866
7867                 if (tdata->iv.len == 0) {
7868                         rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7869                         debug_hexdump(stdout, "iv:", iv_ptr,
7870                                 AES_GCM_J0_LENGTH);
7871                 } else {
7872                         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7873                         debug_hexdump(stdout, "iv:", iv_ptr,
7874                                 tdata->iv.len);
7875                 }
7876         }
7877
7878         /* Append plaintext/ciphertext */
7879         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7880                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7881                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7882                                 plaintext_pad_len);
7883                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7884
7885                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7886                 debug_hexdump(stdout, "plaintext:", plaintext,
7887                                 tdata->plaintext.len);
7888
7889                 if (ut_params->obuf) {
7890                         ciphertext = (uint8_t *)rte_pktmbuf_append(
7891                                         ut_params->obuf,
7892                                         plaintext_pad_len + aad_pad_len);
7893                         TEST_ASSERT_NOT_NULL(ciphertext,
7894                                         "no room to append ciphertext");
7895
7896                         memset(ciphertext + aad_pad_len, 0,
7897                                         tdata->ciphertext.len);
7898                 }
7899         } else {
7900                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7901                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7902                                 plaintext_pad_len);
7903                 TEST_ASSERT_NOT_NULL(ciphertext,
7904                                 "no room to append ciphertext");
7905
7906                 memcpy(ciphertext, tdata->ciphertext.data,
7907                                 tdata->ciphertext.len);
7908                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7909                                 tdata->ciphertext.len);
7910
7911                 if (ut_params->obuf) {
7912                         plaintext = (uint8_t *)rte_pktmbuf_append(
7913                                         ut_params->obuf,
7914                                         plaintext_pad_len + aad_pad_len);
7915                         TEST_ASSERT_NOT_NULL(plaintext,
7916                                         "no room to append plaintext");
7917
7918                         memset(plaintext + aad_pad_len, 0,
7919                                         tdata->plaintext.len);
7920                 }
7921         }
7922
7923         /* Append digest data */
7924         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7925                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7926                                 ut_params->obuf ? ut_params->obuf :
7927                                                 ut_params->ibuf,
7928                                                 tdata->auth_tag.len);
7929                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7930                                 "no room to append digest");
7931                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
7932                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7933                                 ut_params->obuf ? ut_params->obuf :
7934                                                 ut_params->ibuf,
7935                                                 plaintext_pad_len +
7936                                                 aad_pad_len);
7937         } else {
7938                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7939                                 ut_params->ibuf, tdata->auth_tag.len);
7940                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7941                                 "no room to append digest");
7942                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7943                                 ut_params->ibuf,
7944                                 plaintext_pad_len + aad_pad_len);
7945
7946                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
7947                         tdata->auth_tag.len);
7948                 debug_hexdump(stdout, "digest:",
7949                         sym_op->aead.digest.data,
7950                         tdata->auth_tag.len);
7951         }
7952
7953         sym_op->aead.data.length = tdata->plaintext.len;
7954         sym_op->aead.data.offset = aad_pad_len;
7955
7956         return 0;
7957 }
7958
7959 static int
7960 test_authenticated_encryption(const struct aead_test_data *tdata)
7961 {
7962         struct crypto_testsuite_params *ts_params = &testsuite_params;
7963         struct crypto_unittest_params *ut_params = &unittest_params;
7964
7965         int retval;
7966         uint8_t *ciphertext, *auth_tag;
7967         uint16_t plaintext_pad_len;
7968         uint32_t i;
7969         struct rte_cryptodev_info dev_info;
7970
7971         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7972         uint64_t feat_flags = dev_info.feature_flags;
7973
7974         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
7975                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
7976                 printf("Device doesn't support RAW data-path APIs.\n");
7977                 return TEST_SKIPPED;
7978         }
7979
7980         /* Verify the capabilities */
7981         struct rte_cryptodev_sym_capability_idx cap_idx;
7982         const struct rte_cryptodev_symmetric_capability *capability;
7983         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7984         cap_idx.algo.aead = tdata->algo;
7985         capability = rte_cryptodev_sym_capability_get(
7986                         ts_params->valid_devs[0], &cap_idx);
7987         if (capability == NULL)
7988                 return TEST_SKIPPED;
7989         if (rte_cryptodev_sym_capability_check_aead(
7990                         capability, tdata->key.len, tdata->auth_tag.len,
7991                         tdata->aad.len, tdata->iv.len))
7992                 return TEST_SKIPPED;
7993
7994         /* Create AEAD session */
7995         retval = create_aead_session(ts_params->valid_devs[0],
7996                         tdata->algo,
7997                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
7998                         tdata->key.data, tdata->key.len,
7999                         tdata->aad.len, tdata->auth_tag.len,
8000                         tdata->iv.len);
8001         if (retval < 0)
8002                 return retval;
8003
8004         if (tdata->aad.len > MBUF_SIZE) {
8005                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8006                 /* Populate full size of add data */
8007                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8008                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8009         } else
8010                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8011
8012         /* clear mbuf payload */
8013         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8014                         rte_pktmbuf_tailroom(ut_params->ibuf));
8015
8016         /* Create AEAD operation */
8017         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8018         if (retval < 0)
8019                 return retval;
8020
8021         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8022
8023         ut_params->op->sym->m_src = ut_params->ibuf;
8024
8025         /* Process crypto operation */
8026         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8027                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8028         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8029                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8030                                 ut_params->op, 0, 0, 0, 0);
8031         else
8032                 TEST_ASSERT_NOT_NULL(
8033                         process_crypto_request(ts_params->valid_devs[0],
8034                         ut_params->op), "failed to process sym crypto op");
8035
8036         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8037                         "crypto op processing failed");
8038
8039         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8040
8041         if (ut_params->op->sym->m_dst) {
8042                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8043                                 uint8_t *);
8044                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8045                                 uint8_t *, plaintext_pad_len);
8046         } else {
8047                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8048                                 uint8_t *,
8049                                 ut_params->op->sym->cipher.data.offset);
8050                 auth_tag = ciphertext + plaintext_pad_len;
8051         }
8052
8053         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8054         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8055
8056         /* Validate obuf */
8057         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8058                         ciphertext,
8059                         tdata->ciphertext.data,
8060                         tdata->ciphertext.len,
8061                         "Ciphertext data not as expected");
8062
8063         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8064                         auth_tag,
8065                         tdata->auth_tag.data,
8066                         tdata->auth_tag.len,
8067                         "Generated auth tag not as expected");
8068
8069         return 0;
8070
8071 }
8072
8073 #ifdef RTE_LIB_SECURITY
8074 static int
8075 security_proto_supported(enum rte_security_session_action_type action,
8076         enum rte_security_session_protocol proto)
8077 {
8078         struct crypto_testsuite_params *ts_params = &testsuite_params;
8079
8080         const struct rte_security_capability *capabilities;
8081         const struct rte_security_capability *capability;
8082         uint16_t i = 0;
8083
8084         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8085                                 rte_cryptodev_get_sec_ctx(
8086                                 ts_params->valid_devs[0]);
8087
8088
8089         capabilities = rte_security_capabilities_get(ctx);
8090
8091         if (capabilities == NULL)
8092                 return -ENOTSUP;
8093
8094         while ((capability = &capabilities[i++])->action !=
8095                         RTE_SECURITY_ACTION_TYPE_NONE) {
8096                 if (capability->action == action &&
8097                                 capability->protocol == proto)
8098                         return 0;
8099         }
8100
8101         return -ENOTSUP;
8102 }
8103
8104 /* Basic algorithm run function for async inplace mode.
8105  * Creates a session from input parameters and runs one operation
8106  * on input_vec. Checks the output of the crypto operation against
8107  * output_vec.
8108  */
8109 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8110                            enum rte_crypto_auth_operation opa,
8111                            const uint8_t *input_vec, unsigned int input_vec_len,
8112                            const uint8_t *output_vec,
8113                            unsigned int output_vec_len,
8114                            enum rte_crypto_cipher_algorithm cipher_alg,
8115                            const uint8_t *cipher_key, uint32_t cipher_key_len,
8116                            enum rte_crypto_auth_algorithm auth_alg,
8117                            const uint8_t *auth_key, uint32_t auth_key_len,
8118                            uint8_t bearer, enum rte_security_pdcp_domain domain,
8119                            uint8_t packet_direction, uint8_t sn_size,
8120                            uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8121 {
8122         struct crypto_testsuite_params *ts_params = &testsuite_params;
8123         struct crypto_unittest_params *ut_params = &unittest_params;
8124         uint8_t *plaintext;
8125         int ret = TEST_SUCCESS;
8126         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8127                                 rte_cryptodev_get_sec_ctx(
8128                                 ts_params->valid_devs[0]);
8129
8130         /* Verify the capabilities */
8131         struct rte_security_capability_idx sec_cap_idx;
8132
8133         sec_cap_idx.action = ut_params->type;
8134         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8135         sec_cap_idx.pdcp.domain = domain;
8136         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8137                 return TEST_SKIPPED;
8138
8139         /* Generate test mbuf data */
8140         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8141
8142         /* clear mbuf payload */
8143         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8144                         rte_pktmbuf_tailroom(ut_params->ibuf));
8145
8146         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8147                                                   input_vec_len);
8148         memcpy(plaintext, input_vec, input_vec_len);
8149
8150         /* Out of place support */
8151         if (oop) {
8152                 /*
8153                  * For out-op-place we need to alloc another mbuf
8154                  */
8155                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8156                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8157         }
8158
8159         /* Setup Cipher Parameters */
8160         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8161         ut_params->cipher_xform.cipher.algo = cipher_alg;
8162         ut_params->cipher_xform.cipher.op = opc;
8163         ut_params->cipher_xform.cipher.key.data = cipher_key;
8164         ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8165         ut_params->cipher_xform.cipher.iv.length =
8166                                 packet_direction ? 4 : 0;
8167         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8168
8169         /* Setup HMAC Parameters if ICV header is required */
8170         if (auth_alg != 0) {
8171                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8172                 ut_params->auth_xform.next = NULL;
8173                 ut_params->auth_xform.auth.algo = auth_alg;
8174                 ut_params->auth_xform.auth.op = opa;
8175                 ut_params->auth_xform.auth.key.data = auth_key;
8176                 ut_params->auth_xform.auth.key.length = auth_key_len;
8177
8178                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8179         } else {
8180                 ut_params->cipher_xform.next = NULL;
8181         }
8182
8183         struct rte_security_session_conf sess_conf = {
8184                 .action_type = ut_params->type,
8185                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8186                 {.pdcp = {
8187                         .bearer = bearer,
8188                         .domain = domain,
8189                         .pkt_dir = packet_direction,
8190                         .sn_size = sn_size,
8191                         .hfn = packet_direction ? 0 : hfn,
8192                         /**
8193                          * hfn can be set as pdcp_test_hfn[i]
8194                          * if hfn_ovrd is not set. Here, PDCP
8195                          * packet direction is just used to
8196                          * run half of the cases with session
8197                          * HFN and other half with per packet
8198                          * HFN.
8199                          */
8200                         .hfn_threshold = hfn_threshold,
8201                         .hfn_ovrd = packet_direction ? 1 : 0,
8202                         .sdap_enabled = sdap,
8203                 } },
8204                 .crypto_xform = &ut_params->cipher_xform
8205         };
8206
8207         /* Create security session */
8208         ut_params->sec_session = rte_security_session_create(ctx,
8209                                 &sess_conf, ts_params->session_mpool,
8210                                 ts_params->session_priv_mpool);
8211
8212         if (!ut_params->sec_session) {
8213                 printf("TestCase %s()-%d line %d failed %s: ",
8214                         __func__, i, __LINE__, "Failed to allocate session");
8215                 ret = TEST_FAILED;
8216                 goto on_err;
8217         }
8218
8219         /* Generate crypto op data structure */
8220         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8221                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8222         if (!ut_params->op) {
8223                 printf("TestCase %s()-%d line %d failed %s: ",
8224                         __func__, i, __LINE__,
8225                         "Failed to allocate symmetric crypto operation struct");
8226                 ret = TEST_FAILED;
8227                 goto on_err;
8228         }
8229
8230         uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8231                                         uint32_t *, IV_OFFSET);
8232         *per_pkt_hfn = packet_direction ? hfn : 0;
8233
8234         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8235
8236         /* set crypto operation source mbuf */
8237         ut_params->op->sym->m_src = ut_params->ibuf;
8238         if (oop)
8239                 ut_params->op->sym->m_dst = ut_params->obuf;
8240
8241         /* Process crypto operation */
8242         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8243                 == NULL) {
8244                 printf("TestCase %s()-%d line %d failed %s: ",
8245                         __func__, i, __LINE__,
8246                         "failed to process sym crypto op");
8247                 ret = TEST_FAILED;
8248                 goto on_err;
8249         }
8250
8251         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8252                 printf("TestCase %s()-%d line %d failed %s: ",
8253                         __func__, i, __LINE__, "crypto op processing failed");
8254                 ret = TEST_FAILED;
8255                 goto on_err;
8256         }
8257
8258         /* Validate obuf */
8259         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8260                         uint8_t *);
8261         if (oop) {
8262                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8263                                 uint8_t *);
8264         }
8265
8266         if (memcmp(ciphertext, output_vec, output_vec_len)) {
8267                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8268                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8269                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8270                 ret = TEST_FAILED;
8271                 goto on_err;
8272         }
8273
8274 on_err:
8275         rte_crypto_op_free(ut_params->op);
8276         ut_params->op = NULL;
8277
8278         if (ut_params->sec_session)
8279                 rte_security_session_destroy(ctx, ut_params->sec_session);
8280         ut_params->sec_session = NULL;
8281
8282         rte_pktmbuf_free(ut_params->ibuf);
8283         ut_params->ibuf = NULL;
8284         if (oop) {
8285                 rte_pktmbuf_free(ut_params->obuf);
8286                 ut_params->obuf = NULL;
8287         }
8288
8289         return ret;
8290 }
8291
8292 static int
8293 test_pdcp_proto_SGL(int i, int oop,
8294         enum rte_crypto_cipher_operation opc,
8295         enum rte_crypto_auth_operation opa,
8296         uint8_t *input_vec,
8297         unsigned int input_vec_len,
8298         uint8_t *output_vec,
8299         unsigned int output_vec_len,
8300         uint32_t fragsz,
8301         uint32_t fragsz_oop)
8302 {
8303         struct crypto_testsuite_params *ts_params = &testsuite_params;
8304         struct crypto_unittest_params *ut_params = &unittest_params;
8305         uint8_t *plaintext;
8306         struct rte_mbuf *buf, *buf_oop = NULL;
8307         int ret = TEST_SUCCESS;
8308         int to_trn = 0;
8309         int to_trn_tbl[16];
8310         int segs = 1;
8311         unsigned int trn_data = 0;
8312         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8313                                 rte_cryptodev_get_sec_ctx(
8314                                 ts_params->valid_devs[0]);
8315
8316         /* Verify the capabilities */
8317         struct rte_security_capability_idx sec_cap_idx;
8318
8319         sec_cap_idx.action = ut_params->type;
8320         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8321         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8322         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8323                 return TEST_SKIPPED;
8324
8325         if (fragsz > input_vec_len)
8326                 fragsz = input_vec_len;
8327
8328         uint16_t plaintext_len = fragsz;
8329         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8330
8331         if (fragsz_oop > output_vec_len)
8332                 frag_size_oop = output_vec_len;
8333
8334         int ecx = 0;
8335         if (input_vec_len % fragsz != 0) {
8336                 if (input_vec_len / fragsz + 1 > 16)
8337                         return 1;
8338         } else if (input_vec_len / fragsz > 16)
8339                 return 1;
8340
8341         /* Out of place support */
8342         if (oop) {
8343                 /*
8344                  * For out-op-place we need to alloc another mbuf
8345                  */
8346                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8347                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8348                 buf_oop = ut_params->obuf;
8349         }
8350
8351         /* Generate test mbuf data */
8352         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8353
8354         /* clear mbuf payload */
8355         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8356                         rte_pktmbuf_tailroom(ut_params->ibuf));
8357
8358         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8359                                                   plaintext_len);
8360         memcpy(plaintext, input_vec, plaintext_len);
8361         trn_data += plaintext_len;
8362
8363         buf = ut_params->ibuf;
8364
8365         /*
8366          * Loop until no more fragments
8367          */
8368
8369         while (trn_data < input_vec_len) {
8370                 ++segs;
8371                 to_trn = (input_vec_len - trn_data < fragsz) ?
8372                                 (input_vec_len - trn_data) : fragsz;
8373
8374                 to_trn_tbl[ecx++] = to_trn;
8375
8376                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8377                 buf = buf->next;
8378
8379                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8380                                 rte_pktmbuf_tailroom(buf));
8381
8382                 /* OOP */
8383                 if (oop && !fragsz_oop) {
8384                         buf_oop->next =
8385                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8386                         buf_oop = buf_oop->next;
8387                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8388                                         0, rte_pktmbuf_tailroom(buf_oop));
8389                         rte_pktmbuf_append(buf_oop, to_trn);
8390                 }
8391
8392                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8393                                 to_trn);
8394
8395                 memcpy(plaintext, input_vec + trn_data, to_trn);
8396                 trn_data += to_trn;
8397         }
8398
8399         ut_params->ibuf->nb_segs = segs;
8400
8401         segs = 1;
8402         if (fragsz_oop && oop) {
8403                 to_trn = 0;
8404                 ecx = 0;
8405
8406                 trn_data = frag_size_oop;
8407                 while (trn_data < output_vec_len) {
8408                         ++segs;
8409                         to_trn =
8410                                 (output_vec_len - trn_data <
8411                                                 frag_size_oop) ?
8412                                 (output_vec_len - trn_data) :
8413                                                 frag_size_oop;
8414
8415                         to_trn_tbl[ecx++] = to_trn;
8416
8417                         buf_oop->next =
8418                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
8419                         buf_oop = buf_oop->next;
8420                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8421                                         0, rte_pktmbuf_tailroom(buf_oop));
8422                         rte_pktmbuf_append(buf_oop, to_trn);
8423
8424                         trn_data += to_trn;
8425                 }
8426                 ut_params->obuf->nb_segs = segs;
8427         }
8428
8429         /* Setup Cipher Parameters */
8430         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8431         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8432         ut_params->cipher_xform.cipher.op = opc;
8433         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8434         ut_params->cipher_xform.cipher.key.length =
8435                                         pdcp_test_params[i].cipher_key_len;
8436         ut_params->cipher_xform.cipher.iv.length = 0;
8437
8438         /* Setup HMAC Parameters if ICV header is required */
8439         if (pdcp_test_params[i].auth_alg != 0) {
8440                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8441                 ut_params->auth_xform.next = NULL;
8442                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8443                 ut_params->auth_xform.auth.op = opa;
8444                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8445                 ut_params->auth_xform.auth.key.length =
8446                                         pdcp_test_params[i].auth_key_len;
8447
8448                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8449         } else {
8450                 ut_params->cipher_xform.next = NULL;
8451         }
8452
8453         struct rte_security_session_conf sess_conf = {
8454                 .action_type = ut_params->type,
8455                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8456                 {.pdcp = {
8457                         .bearer = pdcp_test_bearer[i],
8458                         .domain = pdcp_test_params[i].domain,
8459                         .pkt_dir = pdcp_test_packet_direction[i],
8460                         .sn_size = pdcp_test_data_sn_size[i],
8461                         .hfn = pdcp_test_hfn[i],
8462                         .hfn_threshold = pdcp_test_hfn_threshold[i],
8463                         .hfn_ovrd = 0,
8464                 } },
8465                 .crypto_xform = &ut_params->cipher_xform
8466         };
8467
8468         /* Create security session */
8469         ut_params->sec_session = rte_security_session_create(ctx,
8470                                 &sess_conf, ts_params->session_mpool,
8471                                 ts_params->session_priv_mpool);
8472
8473         if (!ut_params->sec_session) {
8474                 printf("TestCase %s()-%d line %d failed %s: ",
8475                         __func__, i, __LINE__, "Failed to allocate session");
8476                 ret = TEST_FAILED;
8477                 goto on_err;
8478         }
8479
8480         /* Generate crypto op data structure */
8481         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8482                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8483         if (!ut_params->op) {
8484                 printf("TestCase %s()-%d line %d failed %s: ",
8485                         __func__, i, __LINE__,
8486                         "Failed to allocate symmetric crypto operation struct");
8487                 ret = TEST_FAILED;
8488                 goto on_err;
8489         }
8490
8491         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8492
8493         /* set crypto operation source mbuf */
8494         ut_params->op->sym->m_src = ut_params->ibuf;
8495         if (oop)
8496                 ut_params->op->sym->m_dst = ut_params->obuf;
8497
8498         /* Process crypto operation */
8499         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8500                 == NULL) {
8501                 printf("TestCase %s()-%d line %d failed %s: ",
8502                         __func__, i, __LINE__,
8503                         "failed to process sym crypto op");
8504                 ret = TEST_FAILED;
8505                 goto on_err;
8506         }
8507
8508         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8509                 printf("TestCase %s()-%d line %d failed %s: ",
8510                         __func__, i, __LINE__, "crypto op processing failed");
8511                 ret = TEST_FAILED;
8512                 goto on_err;
8513         }
8514
8515         /* Validate obuf */
8516         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8517                         uint8_t *);
8518         if (oop) {
8519                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8520                                 uint8_t *);
8521         }
8522         if (fragsz_oop)
8523                 fragsz = frag_size_oop;
8524         if (memcmp(ciphertext, output_vec, fragsz)) {
8525                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8526                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8527                 rte_hexdump(stdout, "reference", output_vec, fragsz);
8528                 ret = TEST_FAILED;
8529                 goto on_err;
8530         }
8531
8532         buf = ut_params->op->sym->m_src->next;
8533         if (oop)
8534                 buf = ut_params->op->sym->m_dst->next;
8535
8536         unsigned int off = fragsz;
8537
8538         ecx = 0;
8539         while (buf) {
8540                 ciphertext = rte_pktmbuf_mtod(buf,
8541                                 uint8_t *);
8542                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8543                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8544                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8545                         rte_hexdump(stdout, "reference", output_vec + off,
8546                                         to_trn_tbl[ecx]);
8547                         ret = TEST_FAILED;
8548                         goto on_err;
8549                 }
8550                 off += to_trn_tbl[ecx++];
8551                 buf = buf->next;
8552         }
8553 on_err:
8554         rte_crypto_op_free(ut_params->op);
8555         ut_params->op = NULL;
8556
8557         if (ut_params->sec_session)
8558                 rte_security_session_destroy(ctx, ut_params->sec_session);
8559         ut_params->sec_session = NULL;
8560
8561         rte_pktmbuf_free(ut_params->ibuf);
8562         ut_params->ibuf = NULL;
8563         if (oop) {
8564                 rte_pktmbuf_free(ut_params->obuf);
8565                 ut_params->obuf = NULL;
8566         }
8567
8568         return ret;
8569 }
8570
8571 int
8572 test_pdcp_proto_cplane_encap(int i)
8573 {
8574         return test_pdcp_proto(
8575                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8576                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8577                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8578                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8579                 pdcp_test_params[i].cipher_key_len,
8580                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8581                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8582                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8583                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8584                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8585 }
8586
8587 int
8588 test_pdcp_proto_uplane_encap(int i)
8589 {
8590         return test_pdcp_proto(
8591                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8592                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8593                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8594                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8595                 pdcp_test_params[i].cipher_key_len,
8596                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8597                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8598                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8599                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8600                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8601 }
8602
8603 int
8604 test_pdcp_proto_uplane_encap_with_int(int i)
8605 {
8606         return test_pdcp_proto(
8607                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8608                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8609                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8610                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8611                 pdcp_test_params[i].cipher_key_len,
8612                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8613                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8614                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8615                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8616                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8617 }
8618
8619 int
8620 test_pdcp_proto_cplane_decap(int i)
8621 {
8622         return test_pdcp_proto(
8623                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8624                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8625                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8626                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8627                 pdcp_test_params[i].cipher_key_len,
8628                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8629                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8630                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8631                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8632                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8633 }
8634
8635 int
8636 test_pdcp_proto_uplane_decap(int i)
8637 {
8638         return test_pdcp_proto(
8639                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8640                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8641                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8642                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8643                 pdcp_test_params[i].cipher_key_len,
8644                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8645                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8646                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8647                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8648                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8649 }
8650
8651 int
8652 test_pdcp_proto_uplane_decap_with_int(int i)
8653 {
8654         return test_pdcp_proto(
8655                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8656                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8657                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8658                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8659                 pdcp_test_params[i].cipher_key_len,
8660                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8661                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8662                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8663                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8664                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8665 }
8666
8667 static int
8668 test_PDCP_PROTO_SGL_in_place_32B(void)
8669 {
8670         /* i can be used for running any PDCP case
8671          * In this case it is uplane 12-bit AES-SNOW DL encap
8672          */
8673         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8674         return test_pdcp_proto_SGL(i, IN_PLACE,
8675                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8676                         RTE_CRYPTO_AUTH_OP_GENERATE,
8677                         pdcp_test_data_in[i],
8678                         pdcp_test_data_in_len[i],
8679                         pdcp_test_data_out[i],
8680                         pdcp_test_data_in_len[i]+4,
8681                         32, 0);
8682 }
8683 static int
8684 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8685 {
8686         /* i can be used for running any PDCP case
8687          * In this case it is uplane 18-bit NULL-NULL DL encap
8688          */
8689         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8690         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8691                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8692                         RTE_CRYPTO_AUTH_OP_GENERATE,
8693                         pdcp_test_data_in[i],
8694                         pdcp_test_data_in_len[i],
8695                         pdcp_test_data_out[i],
8696                         pdcp_test_data_in_len[i]+4,
8697                         32, 128);
8698 }
8699 static int
8700 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8701 {
8702         /* i can be used for running any PDCP case
8703          * In this case it is uplane 18-bit AES DL encap
8704          */
8705         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8706                         + DOWNLINK;
8707         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8708                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8709                         RTE_CRYPTO_AUTH_OP_GENERATE,
8710                         pdcp_test_data_in[i],
8711                         pdcp_test_data_in_len[i],
8712                         pdcp_test_data_out[i],
8713                         pdcp_test_data_in_len[i],
8714                         32, 40);
8715 }
8716 static int
8717 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8718 {
8719         /* i can be used for running any PDCP case
8720          * In this case it is cplane 12-bit AES-ZUC DL encap
8721          */
8722         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8723         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8724                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8725                         RTE_CRYPTO_AUTH_OP_GENERATE,
8726                         pdcp_test_data_in[i],
8727                         pdcp_test_data_in_len[i],
8728                         pdcp_test_data_out[i],
8729                         pdcp_test_data_in_len[i]+4,
8730                         128, 32);
8731 }
8732
8733 static int
8734 test_PDCP_SDAP_PROTO_encap_all(void)
8735 {
8736         int i = 0, size = 0;
8737         int err, all_err = TEST_SUCCESS;
8738         const struct pdcp_sdap_test *cur_test;
8739
8740         size = ARRAY_SIZE(list_pdcp_sdap_tests);
8741
8742         for (i = 0; i < size; i++) {
8743                 cur_test = &list_pdcp_sdap_tests[i];
8744                 err = test_pdcp_proto(
8745                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8746                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8747                         cur_test->in_len, cur_test->data_out,
8748                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8749                         cur_test->param.cipher_alg, cur_test->cipher_key,
8750                         cur_test->param.cipher_key_len,
8751                         cur_test->param.auth_alg,
8752                         cur_test->auth_key, cur_test->param.auth_key_len,
8753                         cur_test->bearer, cur_test->param.domain,
8754                         cur_test->packet_direction, cur_test->sn_size,
8755                         cur_test->hfn,
8756                         cur_test->hfn_threshold, SDAP_ENABLED);
8757                 if (err) {
8758                         printf("\t%d) %s: Encapsulation failed\n",
8759                                         cur_test->test_idx,
8760                                         cur_test->param.name);
8761                         err = TEST_FAILED;
8762                 } else {
8763                         printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8764                                         cur_test->param.name);
8765                         err = TEST_SUCCESS;
8766                 }
8767                 all_err += err;
8768         }
8769
8770         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8771
8772         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8773 }
8774
8775 static int
8776 test_PDCP_SDAP_PROTO_decap_all(void)
8777 {
8778         int i = 0, size = 0;
8779         int err, all_err = TEST_SUCCESS;
8780         const struct pdcp_sdap_test *cur_test;
8781
8782         size = ARRAY_SIZE(list_pdcp_sdap_tests);
8783
8784         for (i = 0; i < size; i++) {
8785                 cur_test = &list_pdcp_sdap_tests[i];
8786                 err = test_pdcp_proto(
8787                         i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8788                         RTE_CRYPTO_AUTH_OP_VERIFY,
8789                         cur_test->data_out,
8790                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8791                         cur_test->data_in, cur_test->in_len,
8792                         cur_test->param.cipher_alg,
8793                         cur_test->cipher_key, cur_test->param.cipher_key_len,
8794                         cur_test->param.auth_alg, cur_test->auth_key,
8795                         cur_test->param.auth_key_len, cur_test->bearer,
8796                         cur_test->param.domain, cur_test->packet_direction,
8797                         cur_test->sn_size, cur_test->hfn,
8798                         cur_test->hfn_threshold, SDAP_ENABLED);
8799                 if (err) {
8800                         printf("\t%d) %s: Decapsulation failed\n",
8801                                         cur_test->test_idx,
8802                                         cur_test->param.name);
8803                         err = TEST_FAILED;
8804                 } else {
8805                         printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8806                                         cur_test->param.name);
8807                         err = TEST_SUCCESS;
8808                 }
8809                 all_err += err;
8810         }
8811
8812         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8813
8814         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8815 }
8816
8817 static int
8818 test_PDCP_PROTO_all(void)
8819 {
8820         struct crypto_testsuite_params *ts_params = &testsuite_params;
8821         struct crypto_unittest_params *ut_params = &unittest_params;
8822         struct rte_cryptodev_info dev_info;
8823         int status;
8824
8825         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8826         uint64_t feat_flags = dev_info.feature_flags;
8827
8828         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8829                 return TEST_SKIPPED;
8830
8831         /* Set action type */
8832         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8833                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8834                 gbl_action_type;
8835
8836         if (security_proto_supported(ut_params->type,
8837                         RTE_SECURITY_PROTOCOL_PDCP) < 0)
8838                 return TEST_SKIPPED;
8839
8840         status = test_PDCP_PROTO_cplane_encap_all();
8841         status += test_PDCP_PROTO_cplane_decap_all();
8842         status += test_PDCP_PROTO_uplane_encap_all();
8843         status += test_PDCP_PROTO_uplane_decap_all();
8844         status += test_PDCP_PROTO_SGL_in_place_32B();
8845         status += test_PDCP_PROTO_SGL_oop_32B_128B();
8846         status += test_PDCP_PROTO_SGL_oop_32B_40B();
8847         status += test_PDCP_PROTO_SGL_oop_128B_32B();
8848         status += test_PDCP_SDAP_PROTO_encap_all();
8849         status += test_PDCP_SDAP_PROTO_decap_all();
8850
8851         if (status)
8852                 return TEST_FAILED;
8853         else
8854                 return TEST_SUCCESS;
8855 }
8856
8857 static int
8858 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
8859 {
8860         struct crypto_testsuite_params *ts_params = &testsuite_params;
8861         struct crypto_unittest_params *ut_params = &unittest_params;
8862         uint8_t *plaintext, *ciphertext;
8863         uint8_t *iv_ptr;
8864         int32_t cipher_len, crc_len;
8865         uint32_t crc_data_len;
8866         int ret = TEST_SUCCESS;
8867
8868         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8869                                         rte_cryptodev_get_sec_ctx(
8870                                                 ts_params->valid_devs[0]);
8871
8872         /* Verify the capabilities */
8873         struct rte_security_capability_idx sec_cap_idx;
8874         const struct rte_security_capability *sec_cap;
8875         const struct rte_cryptodev_capabilities *crypto_cap;
8876         const struct rte_cryptodev_symmetric_capability *sym_cap;
8877         int j = 0;
8878
8879         sec_cap_idx.action = ut_params->type;
8880         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8881         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
8882
8883         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8884         if (sec_cap == NULL)
8885                 return TEST_SKIPPED;
8886
8887         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8888                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8889                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8890                                 crypto_cap->sym.xform_type ==
8891                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
8892                                 crypto_cap->sym.cipher.algo ==
8893                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8894                         sym_cap = &crypto_cap->sym;
8895                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8896                                                 d_td->key.len,
8897                                                 d_td->iv.len) == 0)
8898                                 break;
8899                 }
8900         }
8901
8902         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8903                 return TEST_SKIPPED;
8904
8905         /* Setup source mbuf payload */
8906         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8907         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8908                         rte_pktmbuf_tailroom(ut_params->ibuf));
8909
8910         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8911                         d_td->ciphertext.len);
8912
8913         memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
8914
8915         /* Setup cipher session parameters */
8916         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8917         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8918         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
8919         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8920         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8921         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8922         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8923         ut_params->cipher_xform.next = NULL;
8924
8925         /* Setup DOCSIS session parameters */
8926         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
8927
8928         struct rte_security_session_conf sess_conf = {
8929                 .action_type = ut_params->type,
8930                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8931                 .docsis = ut_params->docsis_xform,
8932                 .crypto_xform = &ut_params->cipher_xform,
8933         };
8934
8935         /* Create security session */
8936         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
8937                                         ts_params->session_mpool,
8938                                         ts_params->session_priv_mpool);
8939
8940         if (!ut_params->sec_session) {
8941                 printf("TestCase %s(%d) line %d: %s\n",
8942                         __func__, i, __LINE__, "failed to allocate session");
8943                 ret = TEST_FAILED;
8944                 goto on_err;
8945         }
8946
8947         /* Generate crypto op data structure */
8948         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8949                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8950         if (!ut_params->op) {
8951                 printf("TestCase %s(%d) line %d: %s\n",
8952                         __func__, i, __LINE__,
8953                         "failed to allocate symmetric crypto operation");
8954                 ret = TEST_FAILED;
8955                 goto on_err;
8956         }
8957
8958         /* Setup CRC operation parameters */
8959         crc_len = d_td->ciphertext.no_crc == false ?
8960                         (d_td->ciphertext.len -
8961                                 d_td->ciphertext.crc_offset -
8962                                 RTE_ETHER_CRC_LEN) :
8963                         0;
8964         crc_len = crc_len > 0 ? crc_len : 0;
8965         crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
8966         ut_params->op->sym->auth.data.length = crc_len;
8967         ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
8968
8969         /* Setup cipher operation parameters */
8970         cipher_len = d_td->ciphertext.no_cipher == false ?
8971                         (d_td->ciphertext.len -
8972                                 d_td->ciphertext.cipher_offset) :
8973                         0;
8974         cipher_len = cipher_len > 0 ? cipher_len : 0;
8975         ut_params->op->sym->cipher.data.length = cipher_len;
8976         ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
8977
8978         /* Setup cipher IV */
8979         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
8980         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
8981
8982         /* Attach session to operation */
8983         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8984
8985         /* Set crypto operation mbufs */
8986         ut_params->op->sym->m_src = ut_params->ibuf;
8987         ut_params->op->sym->m_dst = NULL;
8988
8989         /* Process crypto operation */
8990         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
8991                         NULL) {
8992                 printf("TestCase %s(%d) line %d: %s\n",
8993                         __func__, i, __LINE__,
8994                         "failed to process security crypto op");
8995                 ret = TEST_FAILED;
8996                 goto on_err;
8997         }
8998
8999         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9000                 printf("TestCase %s(%d) line %d: %s\n",
9001                         __func__, i, __LINE__, "crypto op processing failed");
9002                 ret = TEST_FAILED;
9003                 goto on_err;
9004         }
9005
9006         /* Validate plaintext */
9007         plaintext = ciphertext;
9008
9009         if (memcmp(plaintext, d_td->plaintext.data,
9010                         d_td->plaintext.len - crc_data_len)) {
9011                 printf("TestCase %s(%d) line %d: %s\n",
9012                         __func__, i, __LINE__, "plaintext not as expected\n");
9013                 rte_hexdump(stdout, "expected", d_td->plaintext.data,
9014                                 d_td->plaintext.len);
9015                 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9016                 ret = TEST_FAILED;
9017                 goto on_err;
9018         }
9019
9020 on_err:
9021         rte_crypto_op_free(ut_params->op);
9022         ut_params->op = NULL;
9023
9024         if (ut_params->sec_session)
9025                 rte_security_session_destroy(ctx, ut_params->sec_session);
9026         ut_params->sec_session = NULL;
9027
9028         rte_pktmbuf_free(ut_params->ibuf);
9029         ut_params->ibuf = NULL;
9030
9031         return ret;
9032 }
9033
9034 static int
9035 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9036 {
9037         struct crypto_testsuite_params *ts_params = &testsuite_params;
9038         struct crypto_unittest_params *ut_params = &unittest_params;
9039         uint8_t *plaintext, *ciphertext;
9040         uint8_t *iv_ptr;
9041         int32_t cipher_len, crc_len;
9042         int ret = TEST_SUCCESS;
9043
9044         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9045                                         rte_cryptodev_get_sec_ctx(
9046                                                 ts_params->valid_devs[0]);
9047
9048         /* Verify the capabilities */
9049         struct rte_security_capability_idx sec_cap_idx;
9050         const struct rte_security_capability *sec_cap;
9051         const struct rte_cryptodev_capabilities *crypto_cap;
9052         const struct rte_cryptodev_symmetric_capability *sym_cap;
9053         int j = 0;
9054
9055         sec_cap_idx.action = ut_params->type;
9056         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9057         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9058
9059         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9060         if (sec_cap == NULL)
9061                 return TEST_SKIPPED;
9062
9063         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9064                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9065                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9066                                 crypto_cap->sym.xform_type ==
9067                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9068                                 crypto_cap->sym.cipher.algo ==
9069                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9070                         sym_cap = &crypto_cap->sym;
9071                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9072                                                 d_td->key.len,
9073                                                 d_td->iv.len) == 0)
9074                                 break;
9075                 }
9076         }
9077
9078         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9079                 return TEST_SKIPPED;
9080
9081         /* Setup source mbuf payload */
9082         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9083         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9084                         rte_pktmbuf_tailroom(ut_params->ibuf));
9085
9086         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9087                         d_td->plaintext.len);
9088
9089         memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9090
9091         /* Setup cipher session parameters */
9092         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9093         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9094         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9095         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9096         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9097         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9098         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9099         ut_params->cipher_xform.next = NULL;
9100
9101         /* Setup DOCSIS session parameters */
9102         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9103
9104         struct rte_security_session_conf sess_conf = {
9105                 .action_type = ut_params->type,
9106                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9107                 .docsis = ut_params->docsis_xform,
9108                 .crypto_xform = &ut_params->cipher_xform,
9109         };
9110
9111         /* Create security session */
9112         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9113                                         ts_params->session_mpool,
9114                                         ts_params->session_priv_mpool);
9115
9116         if (!ut_params->sec_session) {
9117                 printf("TestCase %s(%d) line %d: %s\n",
9118                         __func__, i, __LINE__, "failed to allocate session");
9119                 ret = TEST_FAILED;
9120                 goto on_err;
9121         }
9122
9123         /* Generate crypto op data structure */
9124         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9125                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9126         if (!ut_params->op) {
9127                 printf("TestCase %s(%d) line %d: %s\n",
9128                         __func__, i, __LINE__,
9129                         "failed to allocate security crypto operation");
9130                 ret = TEST_FAILED;
9131                 goto on_err;
9132         }
9133
9134         /* Setup CRC operation parameters */
9135         crc_len = d_td->plaintext.no_crc == false ?
9136                         (d_td->plaintext.len -
9137                                 d_td->plaintext.crc_offset -
9138                                 RTE_ETHER_CRC_LEN) :
9139                         0;
9140         crc_len = crc_len > 0 ? crc_len : 0;
9141         ut_params->op->sym->auth.data.length = crc_len;
9142         ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9143
9144         /* Setup cipher operation parameters */
9145         cipher_len = d_td->plaintext.no_cipher == false ?
9146                         (d_td->plaintext.len -
9147                                 d_td->plaintext.cipher_offset) :
9148                         0;
9149         cipher_len = cipher_len > 0 ? cipher_len : 0;
9150         ut_params->op->sym->cipher.data.length = cipher_len;
9151         ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9152
9153         /* Setup cipher IV */
9154         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9155         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9156
9157         /* Attach session to operation */
9158         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9159
9160         /* Set crypto operation mbufs */
9161         ut_params->op->sym->m_src = ut_params->ibuf;
9162         ut_params->op->sym->m_dst = NULL;
9163
9164         /* Process crypto operation */
9165         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9166                         NULL) {
9167                 printf("TestCase %s(%d) line %d: %s\n",
9168                         __func__, i, __LINE__,
9169                         "failed to process security crypto op");
9170                 ret = TEST_FAILED;
9171                 goto on_err;
9172         }
9173
9174         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9175                 printf("TestCase %s(%d) line %d: %s\n",
9176                         __func__, i, __LINE__, "crypto op processing failed");
9177                 ret = TEST_FAILED;
9178                 goto on_err;
9179         }
9180
9181         /* Validate ciphertext */
9182         ciphertext = plaintext;
9183
9184         if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9185                 printf("TestCase %s(%d) line %d: %s\n",
9186                         __func__, i, __LINE__, "ciphertext not as expected\n");
9187                 rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9188                                 d_td->ciphertext.len);
9189                 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9190                 ret = TEST_FAILED;
9191                 goto on_err;
9192         }
9193
9194 on_err:
9195         rte_crypto_op_free(ut_params->op);
9196         ut_params->op = NULL;
9197
9198         if (ut_params->sec_session)
9199                 rte_security_session_destroy(ctx, ut_params->sec_session);
9200         ut_params->sec_session = NULL;
9201
9202         rte_pktmbuf_free(ut_params->ibuf);
9203         ut_params->ibuf = NULL;
9204
9205         return ret;
9206 }
9207
9208 #define TEST_DOCSIS_COUNT(func) do {                    \
9209         int ret = func;                                 \
9210         if (ret == TEST_SUCCESS)  {                     \
9211                 printf("\t%2d)", n++);                  \
9212                 printf("+++++ PASSED:" #func"\n");      \
9213                 p++;                                    \
9214         } else if (ret == TEST_SKIPPED) {               \
9215                 printf("\t%2d)", n++);                  \
9216                 printf("~~~~~ SKIPPED:" #func"\n");     \
9217                 s++;                                    \
9218         } else {                                        \
9219                 printf("\t%2d)", n++);                  \
9220                 printf("----- FAILED:" #func"\n");      \
9221                 f++;                                    \
9222         }                                               \
9223 } while (0)
9224
9225 static int
9226 test_DOCSIS_PROTO_uplink_all(void)
9227 {
9228         int p = 0, s = 0, f = 0, n = 0;
9229
9230         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9231         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9232         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9233         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9234         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9235         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9236         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9237         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9238         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9239         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9240         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9241         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9242         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9243         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9244         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9245         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9246         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9247         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9248         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9249         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9250         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9251         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9252         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9253         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9254         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9255         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9256
9257         if (f)
9258                 printf("## %s: %d passed out of %d (%d skipped)\n",
9259                         __func__, p, n, s);
9260
9261         return f;
9262 };
9263
9264 static int
9265 test_DOCSIS_PROTO_downlink_all(void)
9266 {
9267         int p = 0, s = 0, f = 0, n = 0;
9268
9269         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9270         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9271         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9272         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9273         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9274         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9275         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9276         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9277         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9278         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9279         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9280         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9281         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9282         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9283         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9284         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9285         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9286         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9287         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9288         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9289         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9290         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9291         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9292         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9293         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9294         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9295
9296         if (f)
9297                 printf("## %s: %d passed out of %d (%d skipped)\n",
9298                         __func__, p, n, s);
9299
9300         return f;
9301 };
9302
9303 static int
9304 test_DOCSIS_PROTO_all(void)
9305 {
9306         struct crypto_testsuite_params *ts_params = &testsuite_params;
9307         struct crypto_unittest_params *ut_params = &unittest_params;
9308         struct rte_cryptodev_info dev_info;
9309         int status;
9310
9311         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9312         uint64_t feat_flags = dev_info.feature_flags;
9313
9314         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9315                 return TEST_SKIPPED;
9316
9317         /* Set action type */
9318         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9319                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9320                 gbl_action_type;
9321
9322         if (security_proto_supported(ut_params->type,
9323                         RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9324                 return TEST_SKIPPED;
9325
9326         status = test_DOCSIS_PROTO_uplink_all();
9327         status += test_DOCSIS_PROTO_downlink_all();
9328
9329         if (status)
9330                 return TEST_FAILED;
9331         else
9332                 return TEST_SUCCESS;
9333 }
9334 #endif
9335
9336 static int
9337 test_AES_GCM_authenticated_encryption_test_case_1(void)
9338 {
9339         return test_authenticated_encryption(&gcm_test_case_1);
9340 }
9341
9342 static int
9343 test_AES_GCM_authenticated_encryption_test_case_2(void)
9344 {
9345         return test_authenticated_encryption(&gcm_test_case_2);
9346 }
9347
9348 static int
9349 test_AES_GCM_authenticated_encryption_test_case_3(void)
9350 {
9351         return test_authenticated_encryption(&gcm_test_case_3);
9352 }
9353
9354 static int
9355 test_AES_GCM_authenticated_encryption_test_case_4(void)
9356 {
9357         return test_authenticated_encryption(&gcm_test_case_4);
9358 }
9359
9360 static int
9361 test_AES_GCM_authenticated_encryption_test_case_5(void)
9362 {
9363         return test_authenticated_encryption(&gcm_test_case_5);
9364 }
9365
9366 static int
9367 test_AES_GCM_authenticated_encryption_test_case_6(void)
9368 {
9369         return test_authenticated_encryption(&gcm_test_case_6);
9370 }
9371
9372 static int
9373 test_AES_GCM_authenticated_encryption_test_case_7(void)
9374 {
9375         return test_authenticated_encryption(&gcm_test_case_7);
9376 }
9377
9378 static int
9379 test_AES_GCM_authenticated_encryption_test_case_8(void)
9380 {
9381         return test_authenticated_encryption(&gcm_test_case_8);
9382 }
9383
9384 static int
9385 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9386 {
9387         return test_authenticated_encryption(&gcm_J0_test_case_1);
9388 }
9389
9390 static int
9391 test_AES_GCM_auth_encryption_test_case_192_1(void)
9392 {
9393         return test_authenticated_encryption(&gcm_test_case_192_1);
9394 }
9395
9396 static int
9397 test_AES_GCM_auth_encryption_test_case_192_2(void)
9398 {
9399         return test_authenticated_encryption(&gcm_test_case_192_2);
9400 }
9401
9402 static int
9403 test_AES_GCM_auth_encryption_test_case_192_3(void)
9404 {
9405         return test_authenticated_encryption(&gcm_test_case_192_3);
9406 }
9407
9408 static int
9409 test_AES_GCM_auth_encryption_test_case_192_4(void)
9410 {
9411         return test_authenticated_encryption(&gcm_test_case_192_4);
9412 }
9413
9414 static int
9415 test_AES_GCM_auth_encryption_test_case_192_5(void)
9416 {
9417         return test_authenticated_encryption(&gcm_test_case_192_5);
9418 }
9419
9420 static int
9421 test_AES_GCM_auth_encryption_test_case_192_6(void)
9422 {
9423         return test_authenticated_encryption(&gcm_test_case_192_6);
9424 }
9425
9426 static int
9427 test_AES_GCM_auth_encryption_test_case_192_7(void)
9428 {
9429         return test_authenticated_encryption(&gcm_test_case_192_7);
9430 }
9431
9432 static int
9433 test_AES_GCM_auth_encryption_test_case_256_1(void)
9434 {
9435         return test_authenticated_encryption(&gcm_test_case_256_1);
9436 }
9437
9438 static int
9439 test_AES_GCM_auth_encryption_test_case_256_2(void)
9440 {
9441         return test_authenticated_encryption(&gcm_test_case_256_2);
9442 }
9443
9444 static int
9445 test_AES_GCM_auth_encryption_test_case_256_3(void)
9446 {
9447         return test_authenticated_encryption(&gcm_test_case_256_3);
9448 }
9449
9450 static int
9451 test_AES_GCM_auth_encryption_test_case_256_4(void)
9452 {
9453         return test_authenticated_encryption(&gcm_test_case_256_4);
9454 }
9455
9456 static int
9457 test_AES_GCM_auth_encryption_test_case_256_5(void)
9458 {
9459         return test_authenticated_encryption(&gcm_test_case_256_5);
9460 }
9461
9462 static int
9463 test_AES_GCM_auth_encryption_test_case_256_6(void)
9464 {
9465         return test_authenticated_encryption(&gcm_test_case_256_6);
9466 }
9467
9468 static int
9469 test_AES_GCM_auth_encryption_test_case_256_7(void)
9470 {
9471         return test_authenticated_encryption(&gcm_test_case_256_7);
9472 }
9473
9474 static int
9475 test_AES_GCM_auth_encryption_test_case_aad_1(void)
9476 {
9477         return test_authenticated_encryption(&gcm_test_case_aad_1);
9478 }
9479
9480 static int
9481 test_AES_GCM_auth_encryption_test_case_aad_2(void)
9482 {
9483         return test_authenticated_encryption(&gcm_test_case_aad_2);
9484 }
9485
9486 static int
9487 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
9488 {
9489         struct aead_test_data tdata;
9490         int res;
9491
9492         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9493         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9494         tdata.iv.data[0] += 1;
9495         res = test_authenticated_encryption(&tdata);
9496         if (res == TEST_SKIPPED)
9497                 return res;
9498         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9499         return TEST_SUCCESS;
9500 }
9501
9502 static int
9503 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
9504 {
9505         struct aead_test_data tdata;
9506         int res;
9507
9508         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9509         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9510         tdata.plaintext.data[0] += 1;
9511         res = test_authenticated_encryption(&tdata);
9512         if (res == TEST_SKIPPED)
9513                 return res;
9514         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9515         return TEST_SUCCESS;
9516 }
9517
9518 static int
9519 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
9520 {
9521         struct aead_test_data tdata;
9522         int res;
9523
9524         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9525         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9526         tdata.ciphertext.data[0] += 1;
9527         res = test_authenticated_encryption(&tdata);
9528         if (res == TEST_SKIPPED)
9529                 return res;
9530         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9531         return TEST_SUCCESS;
9532 }
9533
9534 static int
9535 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
9536 {
9537         struct aead_test_data tdata;
9538         int res;
9539
9540         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9541         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9542         tdata.aad.len += 1;
9543         res = test_authenticated_encryption(&tdata);
9544         if (res == TEST_SKIPPED)
9545                 return res;
9546         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9547         return TEST_SUCCESS;
9548 }
9549
9550 static int
9551 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
9552 {
9553         struct aead_test_data tdata;
9554         uint8_t aad[gcm_test_case_7.aad.len];
9555         int res;
9556
9557         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9558         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9559         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9560         aad[0] += 1;
9561         tdata.aad.data = aad;
9562         res = test_authenticated_encryption(&tdata);
9563         if (res == TEST_SKIPPED)
9564                 return res;
9565         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9566         return TEST_SUCCESS;
9567 }
9568
9569 static int
9570 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
9571 {
9572         struct aead_test_data tdata;
9573         int res;
9574
9575         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9576         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9577         tdata.auth_tag.data[0] += 1;
9578         res = test_authenticated_encryption(&tdata);
9579         if (res == TEST_SKIPPED)
9580                 return res;
9581         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9582         return TEST_SUCCESS;
9583 }
9584
9585 static int
9586 test_authenticated_decryption(const struct aead_test_data *tdata)
9587 {
9588         struct crypto_testsuite_params *ts_params = &testsuite_params;
9589         struct crypto_unittest_params *ut_params = &unittest_params;
9590
9591         int retval;
9592         uint8_t *plaintext;
9593         uint32_t i;
9594         struct rte_cryptodev_info dev_info;
9595
9596         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9597         uint64_t feat_flags = dev_info.feature_flags;
9598
9599         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9600                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9601                 printf("Device doesn't support RAW data-path APIs.\n");
9602                 return TEST_SKIPPED;
9603         }
9604
9605         /* Verify the capabilities */
9606         struct rte_cryptodev_sym_capability_idx cap_idx;
9607         const struct rte_cryptodev_symmetric_capability *capability;
9608         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9609         cap_idx.algo.aead = tdata->algo;
9610         capability = rte_cryptodev_sym_capability_get(
9611                         ts_params->valid_devs[0], &cap_idx);
9612         if (capability == NULL)
9613                 return TEST_SKIPPED;
9614         if (rte_cryptodev_sym_capability_check_aead(
9615                         capability, tdata->key.len, tdata->auth_tag.len,
9616                         tdata->aad.len, tdata->iv.len))
9617                 return TEST_SKIPPED;
9618
9619         /* Create AEAD session */
9620         retval = create_aead_session(ts_params->valid_devs[0],
9621                         tdata->algo,
9622                         RTE_CRYPTO_AEAD_OP_DECRYPT,
9623                         tdata->key.data, tdata->key.len,
9624                         tdata->aad.len, tdata->auth_tag.len,
9625                         tdata->iv.len);
9626         if (retval < 0)
9627                 return retval;
9628
9629         /* alloc mbuf and set payload */
9630         if (tdata->aad.len > MBUF_SIZE) {
9631                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9632                 /* Populate full size of add data */
9633                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
9634                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
9635         } else
9636                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9637
9638         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9639                         rte_pktmbuf_tailroom(ut_params->ibuf));
9640
9641         /* Create AEAD operation */
9642         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9643         if (retval < 0)
9644                 return retval;
9645
9646         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9647
9648         ut_params->op->sym->m_src = ut_params->ibuf;
9649
9650         /* Process crypto operation */
9651         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9652                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
9653         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9654                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9655                                 ut_params->op, 0, 0, 0, 0);
9656         else
9657                 TEST_ASSERT_NOT_NULL(
9658                         process_crypto_request(ts_params->valid_devs[0],
9659                         ut_params->op), "failed to process sym crypto op");
9660
9661         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9662                         "crypto op processing failed");
9663
9664         if (ut_params->op->sym->m_dst)
9665                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9666                                 uint8_t *);
9667         else
9668                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
9669                                 uint8_t *,
9670                                 ut_params->op->sym->cipher.data.offset);
9671
9672         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9673
9674         /* Validate obuf */
9675         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9676                         plaintext,
9677                         tdata->plaintext.data,
9678                         tdata->plaintext.len,
9679                         "Plaintext data not as expected");
9680
9681         TEST_ASSERT_EQUAL(ut_params->op->status,
9682                         RTE_CRYPTO_OP_STATUS_SUCCESS,
9683                         "Authentication failed");
9684
9685         return 0;
9686 }
9687
9688 static int
9689 test_AES_GCM_authenticated_decryption_test_case_1(void)
9690 {
9691         return test_authenticated_decryption(&gcm_test_case_1);
9692 }
9693
9694 static int
9695 test_AES_GCM_authenticated_decryption_test_case_2(void)
9696 {
9697         return test_authenticated_decryption(&gcm_test_case_2);
9698 }
9699
9700 static int
9701 test_AES_GCM_authenticated_decryption_test_case_3(void)
9702 {
9703         return test_authenticated_decryption(&gcm_test_case_3);
9704 }
9705
9706 static int
9707 test_AES_GCM_authenticated_decryption_test_case_4(void)
9708 {
9709         return test_authenticated_decryption(&gcm_test_case_4);
9710 }
9711
9712 static int
9713 test_AES_GCM_authenticated_decryption_test_case_5(void)
9714 {
9715         return test_authenticated_decryption(&gcm_test_case_5);
9716 }
9717
9718 static int
9719 test_AES_GCM_authenticated_decryption_test_case_6(void)
9720 {
9721         return test_authenticated_decryption(&gcm_test_case_6);
9722 }
9723
9724 static int
9725 test_AES_GCM_authenticated_decryption_test_case_7(void)
9726 {
9727         return test_authenticated_decryption(&gcm_test_case_7);
9728 }
9729
9730 static int
9731 test_AES_GCM_authenticated_decryption_test_case_8(void)
9732 {
9733         return test_authenticated_decryption(&gcm_test_case_8);
9734 }
9735
9736 static int
9737 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
9738 {
9739         return test_authenticated_decryption(&gcm_J0_test_case_1);
9740 }
9741
9742 static int
9743 test_AES_GCM_auth_decryption_test_case_192_1(void)
9744 {
9745         return test_authenticated_decryption(&gcm_test_case_192_1);
9746 }
9747
9748 static int
9749 test_AES_GCM_auth_decryption_test_case_192_2(void)
9750 {
9751         return test_authenticated_decryption(&gcm_test_case_192_2);
9752 }
9753
9754 static int
9755 test_AES_GCM_auth_decryption_test_case_192_3(void)
9756 {
9757         return test_authenticated_decryption(&gcm_test_case_192_3);
9758 }
9759
9760 static int
9761 test_AES_GCM_auth_decryption_test_case_192_4(void)
9762 {
9763         return test_authenticated_decryption(&gcm_test_case_192_4);
9764 }
9765
9766 static int
9767 test_AES_GCM_auth_decryption_test_case_192_5(void)
9768 {
9769         return test_authenticated_decryption(&gcm_test_case_192_5);
9770 }
9771
9772 static int
9773 test_AES_GCM_auth_decryption_test_case_192_6(void)
9774 {
9775         return test_authenticated_decryption(&gcm_test_case_192_6);
9776 }
9777
9778 static int
9779 test_AES_GCM_auth_decryption_test_case_192_7(void)
9780 {
9781         return test_authenticated_decryption(&gcm_test_case_192_7);
9782 }
9783
9784 static int
9785 test_AES_GCM_auth_decryption_test_case_256_1(void)
9786 {
9787         return test_authenticated_decryption(&gcm_test_case_256_1);
9788 }
9789
9790 static int
9791 test_AES_GCM_auth_decryption_test_case_256_2(void)
9792 {
9793         return test_authenticated_decryption(&gcm_test_case_256_2);
9794 }
9795
9796 static int
9797 test_AES_GCM_auth_decryption_test_case_256_3(void)
9798 {
9799         return test_authenticated_decryption(&gcm_test_case_256_3);
9800 }
9801
9802 static int
9803 test_AES_GCM_auth_decryption_test_case_256_4(void)
9804 {
9805         return test_authenticated_decryption(&gcm_test_case_256_4);
9806 }
9807
9808 static int
9809 test_AES_GCM_auth_decryption_test_case_256_5(void)
9810 {
9811         return test_authenticated_decryption(&gcm_test_case_256_5);
9812 }
9813
9814 static int
9815 test_AES_GCM_auth_decryption_test_case_256_6(void)
9816 {
9817         return test_authenticated_decryption(&gcm_test_case_256_6);
9818 }
9819
9820 static int
9821 test_AES_GCM_auth_decryption_test_case_256_7(void)
9822 {
9823         return test_authenticated_decryption(&gcm_test_case_256_7);
9824 }
9825
9826 static int
9827 test_AES_GCM_auth_decryption_test_case_aad_1(void)
9828 {
9829         return test_authenticated_decryption(&gcm_test_case_aad_1);
9830 }
9831
9832 static int
9833 test_AES_GCM_auth_decryption_test_case_aad_2(void)
9834 {
9835         return test_authenticated_decryption(&gcm_test_case_aad_2);
9836 }
9837
9838 static int
9839 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
9840 {
9841         struct aead_test_data tdata;
9842         int res;
9843
9844         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9845         tdata.iv.data[0] += 1;
9846         res = test_authenticated_decryption(&tdata);
9847         if (res == TEST_SKIPPED)
9848                 return res;
9849         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9850         return TEST_SUCCESS;
9851 }
9852
9853 static int
9854 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
9855 {
9856         struct aead_test_data tdata;
9857         int res;
9858
9859         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9860         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9861         tdata.plaintext.data[0] += 1;
9862         res = test_authenticated_decryption(&tdata);
9863         if (res == TEST_SKIPPED)
9864                 return res;
9865         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9866         return TEST_SUCCESS;
9867 }
9868
9869 static int
9870 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
9871 {
9872         struct aead_test_data tdata;
9873         int res;
9874
9875         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9876         tdata.ciphertext.data[0] += 1;
9877         res = test_authenticated_decryption(&tdata);
9878         if (res == TEST_SKIPPED)
9879                 return res;
9880         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9881         return TEST_SUCCESS;
9882 }
9883
9884 static int
9885 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
9886 {
9887         struct aead_test_data tdata;
9888         int res;
9889
9890         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9891         tdata.aad.len += 1;
9892         res = test_authenticated_decryption(&tdata);
9893         if (res == TEST_SKIPPED)
9894                 return res;
9895         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9896         return TEST_SUCCESS;
9897 }
9898
9899 static int
9900 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
9901 {
9902         struct aead_test_data tdata;
9903         uint8_t aad[gcm_test_case_7.aad.len];
9904         int res;
9905
9906         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9907         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9908         aad[0] += 1;
9909         tdata.aad.data = aad;
9910         res = test_authenticated_decryption(&tdata);
9911         if (res == TEST_SKIPPED)
9912                 return res;
9913         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9914         return TEST_SUCCESS;
9915 }
9916
9917 static int
9918 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
9919 {
9920         struct aead_test_data tdata;
9921         int res;
9922
9923         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9924         tdata.auth_tag.data[0] += 1;
9925         res = test_authenticated_decryption(&tdata);
9926         if (res == TEST_SKIPPED)
9927                 return res;
9928         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
9929         return TEST_SUCCESS;
9930 }
9931
9932 static int
9933 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
9934 {
9935         struct crypto_testsuite_params *ts_params = &testsuite_params;
9936         struct crypto_unittest_params *ut_params = &unittest_params;
9937
9938         int retval;
9939         uint8_t *ciphertext, *auth_tag;
9940         uint16_t plaintext_pad_len;
9941
9942         /* Verify the capabilities */
9943         struct rte_cryptodev_sym_capability_idx cap_idx;
9944         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9945         cap_idx.algo.aead = tdata->algo;
9946         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9947                         &cap_idx) == NULL)
9948                 return TEST_SKIPPED;
9949
9950         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9951                 return TEST_SKIPPED;
9952
9953         /* not supported with CPU crypto */
9954         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9955                 return TEST_SKIPPED;
9956
9957         /* Create AEAD session */
9958         retval = create_aead_session(ts_params->valid_devs[0],
9959                         tdata->algo,
9960                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
9961                         tdata->key.data, tdata->key.len,
9962                         tdata->aad.len, tdata->auth_tag.len,
9963                         tdata->iv.len);
9964         if (retval < 0)
9965                 return retval;
9966
9967         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9968         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9969
9970         /* clear mbuf payload */
9971         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9972                         rte_pktmbuf_tailroom(ut_params->ibuf));
9973         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
9974                         rte_pktmbuf_tailroom(ut_params->obuf));
9975
9976         /* Create AEAD operation */
9977         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
9978         if (retval < 0)
9979                 return retval;
9980
9981         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9982
9983         ut_params->op->sym->m_src = ut_params->ibuf;
9984         ut_params->op->sym->m_dst = ut_params->obuf;
9985
9986         /* Process crypto operation */
9987         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9988                         ut_params->op), "failed to process sym crypto op");
9989
9990         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9991                         "crypto op processing failed");
9992
9993         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9994
9995         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
9996                         ut_params->op->sym->cipher.data.offset);
9997         auth_tag = ciphertext + plaintext_pad_len;
9998
9999         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10000         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10001
10002         /* Validate obuf */
10003         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10004                         ciphertext,
10005                         tdata->ciphertext.data,
10006                         tdata->ciphertext.len,
10007                         "Ciphertext data not as expected");
10008
10009         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10010                         auth_tag,
10011                         tdata->auth_tag.data,
10012                         tdata->auth_tag.len,
10013                         "Generated auth tag not as expected");
10014
10015         return 0;
10016
10017 }
10018
10019 static int
10020 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10021 {
10022         return test_authenticated_encryption_oop(&gcm_test_case_5);
10023 }
10024
10025 static int
10026 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10027 {
10028         struct crypto_testsuite_params *ts_params = &testsuite_params;
10029         struct crypto_unittest_params *ut_params = &unittest_params;
10030
10031         int retval;
10032         uint8_t *plaintext;
10033
10034         /* Verify the capabilities */
10035         struct rte_cryptodev_sym_capability_idx cap_idx;
10036         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10037         cap_idx.algo.aead = tdata->algo;
10038         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10039                         &cap_idx) == NULL)
10040                 return TEST_SKIPPED;
10041
10042         /* not supported with CPU crypto and raw data-path APIs*/
10043         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10044                         global_api_test_type == CRYPTODEV_RAW_API_TEST)
10045                 return TEST_SKIPPED;
10046
10047         /* Create AEAD session */
10048         retval = create_aead_session(ts_params->valid_devs[0],
10049                         tdata->algo,
10050                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10051                         tdata->key.data, tdata->key.len,
10052                         tdata->aad.len, tdata->auth_tag.len,
10053                         tdata->iv.len);
10054         if (retval < 0)
10055                 return retval;
10056
10057         /* alloc mbuf and set payload */
10058         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10059         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10060
10061         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10062                         rte_pktmbuf_tailroom(ut_params->ibuf));
10063         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10064                         rte_pktmbuf_tailroom(ut_params->obuf));
10065
10066         /* Create AEAD operation */
10067         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10068         if (retval < 0)
10069                 return retval;
10070
10071         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10072
10073         ut_params->op->sym->m_src = ut_params->ibuf;
10074         ut_params->op->sym->m_dst = ut_params->obuf;
10075
10076         /* Process crypto operation */
10077         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10078                         ut_params->op), "failed to process sym crypto op");
10079
10080         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10081                         "crypto op processing failed");
10082
10083         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10084                         ut_params->op->sym->cipher.data.offset);
10085
10086         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10087
10088         /* Validate obuf */
10089         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10090                         plaintext,
10091                         tdata->plaintext.data,
10092                         tdata->plaintext.len,
10093                         "Plaintext data not as expected");
10094
10095         TEST_ASSERT_EQUAL(ut_params->op->status,
10096                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10097                         "Authentication failed");
10098         return 0;
10099 }
10100
10101 static int
10102 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10103 {
10104         return test_authenticated_decryption_oop(&gcm_test_case_5);
10105 }
10106
10107 static int
10108 test_authenticated_encryption_sessionless(
10109                 const struct aead_test_data *tdata)
10110 {
10111         struct crypto_testsuite_params *ts_params = &testsuite_params;
10112         struct crypto_unittest_params *ut_params = &unittest_params;
10113
10114         int retval;
10115         uint8_t *ciphertext, *auth_tag;
10116         uint16_t plaintext_pad_len;
10117         uint8_t key[tdata->key.len + 1];
10118         struct rte_cryptodev_info dev_info;
10119
10120         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10121         uint64_t feat_flags = dev_info.feature_flags;
10122
10123         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10124                 printf("Device doesn't support Sessionless ops.\n");
10125                 return TEST_SKIPPED;
10126         }
10127
10128         /* not supported with CPU crypto */
10129         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10130                 return TEST_SKIPPED;
10131
10132         /* Verify the capabilities */
10133         struct rte_cryptodev_sym_capability_idx cap_idx;
10134         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10135         cap_idx.algo.aead = tdata->algo;
10136         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10137                         &cap_idx) == NULL)
10138                 return TEST_SKIPPED;
10139
10140         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10141
10142         /* clear mbuf payload */
10143         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10144                         rte_pktmbuf_tailroom(ut_params->ibuf));
10145
10146         /* Create AEAD operation */
10147         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10148         if (retval < 0)
10149                 return retval;
10150
10151         /* Create GCM xform */
10152         memcpy(key, tdata->key.data, tdata->key.len);
10153         retval = create_aead_xform(ut_params->op,
10154                         tdata->algo,
10155                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10156                         key, tdata->key.len,
10157                         tdata->aad.len, tdata->auth_tag.len,
10158                         tdata->iv.len);
10159         if (retval < 0)
10160                 return retval;
10161
10162         ut_params->op->sym->m_src = ut_params->ibuf;
10163
10164         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10165                         RTE_CRYPTO_OP_SESSIONLESS,
10166                         "crypto op session type not sessionless");
10167
10168         /* Process crypto operation */
10169         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10170                         ut_params->op), "failed to process sym crypto op");
10171
10172         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10173
10174         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10175                         "crypto op status not success");
10176
10177         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10178
10179         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10180                         ut_params->op->sym->cipher.data.offset);
10181         auth_tag = ciphertext + plaintext_pad_len;
10182
10183         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10184         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10185
10186         /* Validate obuf */
10187         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10188                         ciphertext,
10189                         tdata->ciphertext.data,
10190                         tdata->ciphertext.len,
10191                         "Ciphertext data not as expected");
10192
10193         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10194                         auth_tag,
10195                         tdata->auth_tag.data,
10196                         tdata->auth_tag.len,
10197                         "Generated auth tag not as expected");
10198
10199         return 0;
10200
10201 }
10202
10203 static int
10204 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10205 {
10206         return test_authenticated_encryption_sessionless(
10207                         &gcm_test_case_5);
10208 }
10209
10210 static int
10211 test_authenticated_decryption_sessionless(
10212                 const struct aead_test_data *tdata)
10213 {
10214         struct crypto_testsuite_params *ts_params = &testsuite_params;
10215         struct crypto_unittest_params *ut_params = &unittest_params;
10216
10217         int retval;
10218         uint8_t *plaintext;
10219         uint8_t key[tdata->key.len + 1];
10220         struct rte_cryptodev_info dev_info;
10221
10222         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10223         uint64_t feat_flags = dev_info.feature_flags;
10224
10225         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10226                 printf("Device doesn't support Sessionless ops.\n");
10227                 return TEST_SKIPPED;
10228         }
10229
10230         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10231                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10232                 printf("Device doesn't support RAW data-path APIs.\n");
10233                 return TEST_SKIPPED;
10234         }
10235
10236         /* not supported with CPU crypto */
10237         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10238                 return TEST_SKIPPED;
10239
10240         /* Verify the capabilities */
10241         struct rte_cryptodev_sym_capability_idx cap_idx;
10242         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10243         cap_idx.algo.aead = tdata->algo;
10244         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10245                         &cap_idx) == NULL)
10246                 return TEST_SKIPPED;
10247
10248         /* alloc mbuf and set payload */
10249         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10250
10251         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10252                         rte_pktmbuf_tailroom(ut_params->ibuf));
10253
10254         /* Create AEAD operation */
10255         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10256         if (retval < 0)
10257                 return retval;
10258
10259         /* Create AEAD xform */
10260         memcpy(key, tdata->key.data, tdata->key.len);
10261         retval = create_aead_xform(ut_params->op,
10262                         tdata->algo,
10263                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10264                         key, tdata->key.len,
10265                         tdata->aad.len, tdata->auth_tag.len,
10266                         tdata->iv.len);
10267         if (retval < 0)
10268                 return retval;
10269
10270         ut_params->op->sym->m_src = ut_params->ibuf;
10271
10272         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10273                         RTE_CRYPTO_OP_SESSIONLESS,
10274                         "crypto op session type not sessionless");
10275
10276         /* Process crypto operation */
10277         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10278                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10279                                 ut_params->op, 0, 0, 0, 0);
10280         else
10281                 TEST_ASSERT_NOT_NULL(process_crypto_request(
10282                         ts_params->valid_devs[0], ut_params->op),
10283                                 "failed to process sym crypto op");
10284
10285         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10286
10287         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10288                         "crypto op status not success");
10289
10290         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10291                         ut_params->op->sym->cipher.data.offset);
10292
10293         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10294
10295         /* Validate obuf */
10296         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10297                         plaintext,
10298                         tdata->plaintext.data,
10299                         tdata->plaintext.len,
10300                         "Plaintext data not as expected");
10301
10302         TEST_ASSERT_EQUAL(ut_params->op->status,
10303                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10304                         "Authentication failed");
10305         return 0;
10306 }
10307
10308 static int
10309 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
10310 {
10311         return test_authenticated_decryption_sessionless(
10312                         &gcm_test_case_5);
10313 }
10314
10315 static int
10316 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
10317 {
10318         return test_authenticated_encryption(&ccm_test_case_128_1);
10319 }
10320
10321 static int
10322 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
10323 {
10324         return test_authenticated_encryption(&ccm_test_case_128_2);
10325 }
10326
10327 static int
10328 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
10329 {
10330         return test_authenticated_encryption(&ccm_test_case_128_3);
10331 }
10332
10333 static int
10334 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
10335 {
10336         return test_authenticated_decryption(&ccm_test_case_128_1);
10337 }
10338
10339 static int
10340 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
10341 {
10342         return test_authenticated_decryption(&ccm_test_case_128_2);
10343 }
10344
10345 static int
10346 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10347 {
10348         return test_authenticated_decryption(&ccm_test_case_128_3);
10349 }
10350
10351 static int
10352 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10353 {
10354         return test_authenticated_encryption(&ccm_test_case_192_1);
10355 }
10356
10357 static int
10358 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10359 {
10360         return test_authenticated_encryption(&ccm_test_case_192_2);
10361 }
10362
10363 static int
10364 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10365 {
10366         return test_authenticated_encryption(&ccm_test_case_192_3);
10367 }
10368
10369 static int
10370 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10371 {
10372         return test_authenticated_decryption(&ccm_test_case_192_1);
10373 }
10374
10375 static int
10376 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10377 {
10378         return test_authenticated_decryption(&ccm_test_case_192_2);
10379 }
10380
10381 static int
10382 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10383 {
10384         return test_authenticated_decryption(&ccm_test_case_192_3);
10385 }
10386
10387 static int
10388 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
10389 {
10390         return test_authenticated_encryption(&ccm_test_case_256_1);
10391 }
10392
10393 static int
10394 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
10395 {
10396         return test_authenticated_encryption(&ccm_test_case_256_2);
10397 }
10398
10399 static int
10400 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
10401 {
10402         return test_authenticated_encryption(&ccm_test_case_256_3);
10403 }
10404
10405 static int
10406 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
10407 {
10408         return test_authenticated_decryption(&ccm_test_case_256_1);
10409 }
10410
10411 static int
10412 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
10413 {
10414         return test_authenticated_decryption(&ccm_test_case_256_2);
10415 }
10416
10417 static int
10418 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
10419 {
10420         return test_authenticated_decryption(&ccm_test_case_256_3);
10421 }
10422
10423 static int
10424 test_stats(void)
10425 {
10426         struct crypto_testsuite_params *ts_params = &testsuite_params;
10427         struct rte_cryptodev_stats stats;
10428
10429         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10430                 return TEST_SKIPPED;
10431
10432         /* Verify the capabilities */
10433         struct rte_cryptodev_sym_capability_idx cap_idx;
10434         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10435         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
10436         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10437                         &cap_idx) == NULL)
10438                 return TEST_SKIPPED;
10439         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10440         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10441         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10442                         &cap_idx) == NULL)
10443                 return TEST_SKIPPED;
10444
10445         if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
10446                         == -ENOTSUP)
10447                 return TEST_SKIPPED;
10448
10449         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10450         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
10451                         &stats) == -ENODEV),
10452                 "rte_cryptodev_stats_get invalid dev failed");
10453         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
10454                 "rte_cryptodev_stats_get invalid Param failed");
10455
10456         /* Test expected values */
10457         test_AES_CBC_HMAC_SHA1_encrypt_digest();
10458         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10459                         &stats),
10460                 "rte_cryptodev_stats_get failed");
10461         TEST_ASSERT((stats.enqueued_count == 1),
10462                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10463         TEST_ASSERT((stats.dequeued_count == 1),
10464                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10465         TEST_ASSERT((stats.enqueue_err_count == 0),
10466                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10467         TEST_ASSERT((stats.dequeue_err_count == 0),
10468                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10469
10470         /* invalid device but should ignore and not reset device stats*/
10471         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
10472         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10473                         &stats),
10474                 "rte_cryptodev_stats_get failed");
10475         TEST_ASSERT((stats.enqueued_count == 1),
10476                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10477
10478         /* check that a valid reset clears stats */
10479         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10480         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10481                         &stats),
10482                                           "rte_cryptodev_stats_get failed");
10483         TEST_ASSERT((stats.enqueued_count == 0),
10484                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10485         TEST_ASSERT((stats.dequeued_count == 0),
10486                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10487
10488         return TEST_SUCCESS;
10489 }
10490
10491 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
10492                                    struct crypto_unittest_params *ut_params,
10493                                    enum rte_crypto_auth_operation op,
10494                                    const struct HMAC_MD5_vector *test_case)
10495 {
10496         uint8_t key[64];
10497
10498         memcpy(key, test_case->key.data, test_case->key.len);
10499
10500         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10501         ut_params->auth_xform.next = NULL;
10502         ut_params->auth_xform.auth.op = op;
10503
10504         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
10505
10506         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
10507         ut_params->auth_xform.auth.key.length = test_case->key.len;
10508         ut_params->auth_xform.auth.key.data = key;
10509
10510         ut_params->sess = rte_cryptodev_sym_session_create(
10511                         ts_params->session_mpool);
10512
10513         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10514                         ut_params->sess, &ut_params->auth_xform,
10515                         ts_params->session_priv_mpool);
10516
10517         if (ut_params->sess == NULL)
10518                 return TEST_FAILED;
10519
10520         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10521
10522         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10523                         rte_pktmbuf_tailroom(ut_params->ibuf));
10524
10525         return 0;
10526 }
10527
10528 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
10529                               const struct HMAC_MD5_vector *test_case,
10530                               uint8_t **plaintext)
10531 {
10532         uint16_t plaintext_pad_len;
10533
10534         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10535
10536         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10537                                 16);
10538
10539         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10540                         plaintext_pad_len);
10541         memcpy(*plaintext, test_case->plaintext.data,
10542                         test_case->plaintext.len);
10543
10544         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10545                         ut_params->ibuf, MD5_DIGEST_LEN);
10546         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10547                         "no room to append digest");
10548         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10549                         ut_params->ibuf, plaintext_pad_len);
10550
10551         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10552                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
10553                            test_case->auth_tag.len);
10554         }
10555
10556         sym_op->auth.data.offset = 0;
10557         sym_op->auth.data.length = test_case->plaintext.len;
10558
10559         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10560         ut_params->op->sym->m_src = ut_params->ibuf;
10561
10562         return 0;
10563 }
10564
10565 static int
10566 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
10567 {
10568         uint16_t plaintext_pad_len;
10569         uint8_t *plaintext, *auth_tag;
10570
10571         struct crypto_testsuite_params *ts_params = &testsuite_params;
10572         struct crypto_unittest_params *ut_params = &unittest_params;
10573         struct rte_cryptodev_info dev_info;
10574
10575         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10576         uint64_t feat_flags = dev_info.feature_flags;
10577
10578         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10579                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10580                 printf("Device doesn't support RAW data-path APIs.\n");
10581                 return TEST_SKIPPED;
10582         }
10583
10584         /* Verify the capabilities */
10585         struct rte_cryptodev_sym_capability_idx cap_idx;
10586         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10587         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10588         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10589                         &cap_idx) == NULL)
10590                 return TEST_SKIPPED;
10591
10592         if (MD5_HMAC_create_session(ts_params, ut_params,
10593                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
10594                 return TEST_FAILED;
10595
10596         /* Generate Crypto op data structure */
10597         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10598                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10599         TEST_ASSERT_NOT_NULL(ut_params->op,
10600                         "Failed to allocate symmetric crypto operation struct");
10601
10602         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10603                                 16);
10604
10605         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10606                 return TEST_FAILED;
10607
10608         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10609                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10610                         ut_params->op);
10611         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10612                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10613                                 ut_params->op, 0, 1, 0, 0);
10614         else
10615                 TEST_ASSERT_NOT_NULL(
10616                         process_crypto_request(ts_params->valid_devs[0],
10617                                 ut_params->op),
10618                                 "failed to process sym crypto op");
10619
10620         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10621                         "crypto op processing failed");
10622
10623         if (ut_params->op->sym->m_dst) {
10624                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10625                                 uint8_t *, plaintext_pad_len);
10626         } else {
10627                 auth_tag = plaintext + plaintext_pad_len;
10628         }
10629
10630         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10631                         auth_tag,
10632                         test_case->auth_tag.data,
10633                         test_case->auth_tag.len,
10634                         "HMAC_MD5 generated tag not as expected");
10635
10636         return TEST_SUCCESS;
10637 }
10638
10639 static int
10640 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
10641 {
10642         uint8_t *plaintext;
10643
10644         struct crypto_testsuite_params *ts_params = &testsuite_params;
10645         struct crypto_unittest_params *ut_params = &unittest_params;
10646         struct rte_cryptodev_info dev_info;
10647
10648         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10649         uint64_t feat_flags = dev_info.feature_flags;
10650
10651         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10652                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10653                 printf("Device doesn't support RAW data-path APIs.\n");
10654                 return TEST_SKIPPED;
10655         }
10656
10657         /* Verify the capabilities */
10658         struct rte_cryptodev_sym_capability_idx cap_idx;
10659         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10660         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10661         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10662                         &cap_idx) == NULL)
10663                 return TEST_SKIPPED;
10664
10665         if (MD5_HMAC_create_session(ts_params, ut_params,
10666                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
10667                 return TEST_FAILED;
10668         }
10669
10670         /* Generate Crypto op data structure */
10671         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10672                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10673         TEST_ASSERT_NOT_NULL(ut_params->op,
10674                         "Failed to allocate symmetric crypto operation struct");
10675
10676         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10677                 return TEST_FAILED;
10678
10679         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10680                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10681                         ut_params->op);
10682         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10683                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10684                                 ut_params->op, 0, 1, 0, 0);
10685         else
10686                 TEST_ASSERT_NOT_NULL(
10687                         process_crypto_request(ts_params->valid_devs[0],
10688                                 ut_params->op),
10689                                 "failed to process sym crypto op");
10690
10691         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10692                         "HMAC_MD5 crypto op processing failed");
10693
10694         return TEST_SUCCESS;
10695 }
10696
10697 static int
10698 test_MD5_HMAC_generate_case_1(void)
10699 {
10700         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
10701 }
10702
10703 static int
10704 test_MD5_HMAC_verify_case_1(void)
10705 {
10706         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
10707 }
10708
10709 static int
10710 test_MD5_HMAC_generate_case_2(void)
10711 {
10712         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
10713 }
10714
10715 static int
10716 test_MD5_HMAC_verify_case_2(void)
10717 {
10718         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
10719 }
10720
10721 static int
10722 test_multi_session(void)
10723 {
10724         struct crypto_testsuite_params *ts_params = &testsuite_params;
10725         struct crypto_unittest_params *ut_params = &unittest_params;
10726
10727         struct rte_cryptodev_info dev_info;
10728         struct rte_cryptodev_sym_session **sessions;
10729
10730         uint16_t i;
10731
10732         /* Verify the capabilities */
10733         struct rte_cryptodev_sym_capability_idx cap_idx;
10734         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10735         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10736         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10737                         &cap_idx) == NULL)
10738                 return TEST_SKIPPED;
10739         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10740         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10741         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10742                         &cap_idx) == NULL)
10743                 return TEST_SKIPPED;
10744
10745         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
10746                         aes_cbc_key, hmac_sha512_key);
10747
10748
10749         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10750
10751         sessions = rte_malloc(NULL,
10752                         sizeof(struct rte_cryptodev_sym_session *) *
10753                         (MAX_NB_SESSIONS + 1), 0);
10754
10755         /* Create multiple crypto sessions*/
10756         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10757
10758                 sessions[i] = rte_cryptodev_sym_session_create(
10759                                 ts_params->session_mpool);
10760
10761                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10762                                 sessions[i], &ut_params->auth_xform,
10763                                 ts_params->session_priv_mpool);
10764                 TEST_ASSERT_NOT_NULL(sessions[i],
10765                                 "Session creation failed at session number %u",
10766                                 i);
10767
10768                 /* Attempt to send a request on each session */
10769                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
10770                         sessions[i],
10771                         ut_params,
10772                         ts_params,
10773                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
10774                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
10775                         aes_cbc_iv),
10776                         "Failed to perform decrypt on request number %u.", i);
10777                 /* free crypto operation structure */
10778                 if (ut_params->op)
10779                         rte_crypto_op_free(ut_params->op);
10780
10781                 /*
10782                  * free mbuf - both obuf and ibuf are usually the same,
10783                  * so check if they point at the same address is necessary,
10784                  * to avoid freeing the mbuf twice.
10785                  */
10786                 if (ut_params->obuf) {
10787                         rte_pktmbuf_free(ut_params->obuf);
10788                         if (ut_params->ibuf == ut_params->obuf)
10789                                 ut_params->ibuf = 0;
10790                         ut_params->obuf = 0;
10791                 }
10792                 if (ut_params->ibuf) {
10793                         rte_pktmbuf_free(ut_params->ibuf);
10794                         ut_params->ibuf = 0;
10795                 }
10796         }
10797
10798         sessions[i] = NULL;
10799         /* Next session create should fail */
10800         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10801                         sessions[i], &ut_params->auth_xform,
10802                         ts_params->session_priv_mpool);
10803         TEST_ASSERT_NULL(sessions[i],
10804                         "Session creation succeeded unexpectedly!");
10805
10806         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10807                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10808                                 sessions[i]);
10809                 rte_cryptodev_sym_session_free(sessions[i]);
10810         }
10811
10812         rte_free(sessions);
10813
10814         return TEST_SUCCESS;
10815 }
10816
10817 struct multi_session_params {
10818         struct crypto_unittest_params ut_params;
10819         uint8_t *cipher_key;
10820         uint8_t *hmac_key;
10821         const uint8_t *cipher;
10822         const uint8_t *digest;
10823         uint8_t *iv;
10824 };
10825
10826 #define MB_SESSION_NUMBER 3
10827
10828 static int
10829 test_multi_session_random_usage(void)
10830 {
10831         struct crypto_testsuite_params *ts_params = &testsuite_params;
10832         struct rte_cryptodev_info dev_info;
10833         struct rte_cryptodev_sym_session **sessions;
10834         uint32_t i, j;
10835         struct multi_session_params ut_paramz[] = {
10836
10837                 {
10838                         .cipher_key = ms_aes_cbc_key0,
10839                         .hmac_key = ms_hmac_key0,
10840                         .cipher = ms_aes_cbc_cipher0,
10841                         .digest = ms_hmac_digest0,
10842                         .iv = ms_aes_cbc_iv0
10843                 },
10844                 {
10845                         .cipher_key = ms_aes_cbc_key1,
10846                         .hmac_key = ms_hmac_key1,
10847                         .cipher = ms_aes_cbc_cipher1,
10848                         .digest = ms_hmac_digest1,
10849                         .iv = ms_aes_cbc_iv1
10850                 },
10851                 {
10852                         .cipher_key = ms_aes_cbc_key2,
10853                         .hmac_key = ms_hmac_key2,
10854                         .cipher = ms_aes_cbc_cipher2,
10855                         .digest = ms_hmac_digest2,
10856                         .iv = ms_aes_cbc_iv2
10857                 },
10858
10859         };
10860
10861         /* Verify the capabilities */
10862         struct rte_cryptodev_sym_capability_idx cap_idx;
10863         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10864         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10865         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10866                         &cap_idx) == NULL)
10867                 return TEST_SKIPPED;
10868         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10869         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10870         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10871                         &cap_idx) == NULL)
10872                 return TEST_SKIPPED;
10873
10874         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10875
10876         sessions = rte_malloc(NULL,
10877                         (sizeof(struct rte_cryptodev_sym_session *)
10878                                         * MAX_NB_SESSIONS) + 1, 0);
10879
10880         for (i = 0; i < MB_SESSION_NUMBER; i++) {
10881                 sessions[i] = rte_cryptodev_sym_session_create(
10882                                 ts_params->session_mpool);
10883
10884                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
10885                                 sizeof(struct crypto_unittest_params));
10886
10887                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
10888                                 &ut_paramz[i].ut_params,
10889                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
10890
10891                 /* Create multiple crypto sessions*/
10892                 rte_cryptodev_sym_session_init(
10893                                 ts_params->valid_devs[0],
10894                                 sessions[i],
10895                                 &ut_paramz[i].ut_params.auth_xform,
10896                                 ts_params->session_priv_mpool);
10897
10898                 TEST_ASSERT_NOT_NULL(sessions[i],
10899                                 "Session creation failed at session number %u",
10900                                 i);
10901
10902         }
10903
10904         srand(time(NULL));
10905         for (i = 0; i < 40000; i++) {
10906
10907                 j = rand() % MB_SESSION_NUMBER;
10908
10909                 TEST_ASSERT_SUCCESS(
10910                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
10911                                         sessions[j],
10912                                         &ut_paramz[j].ut_params,
10913                                         ts_params, ut_paramz[j].cipher,
10914                                         ut_paramz[j].digest,
10915                                         ut_paramz[j].iv),
10916                         "Failed to perform decrypt on request number %u.", i);
10917
10918                 if (ut_paramz[j].ut_params.op)
10919                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
10920
10921                 /*
10922                  * free mbuf - both obuf and ibuf are usually the same,
10923                  * so check if they point at the same address is necessary,
10924                  * to avoid freeing the mbuf twice.
10925                  */
10926                 if (ut_paramz[j].ut_params.obuf) {
10927                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
10928                         if (ut_paramz[j].ut_params.ibuf
10929                                         == ut_paramz[j].ut_params.obuf)
10930                                 ut_paramz[j].ut_params.ibuf = 0;
10931                         ut_paramz[j].ut_params.obuf = 0;
10932                 }
10933                 if (ut_paramz[j].ut_params.ibuf) {
10934                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
10935                         ut_paramz[j].ut_params.ibuf = 0;
10936                 }
10937         }
10938
10939         for (i = 0; i < MB_SESSION_NUMBER; i++) {
10940                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10941                                 sessions[i]);
10942                 rte_cryptodev_sym_session_free(sessions[i]);
10943         }
10944
10945         rte_free(sessions);
10946
10947         return TEST_SUCCESS;
10948 }
10949
10950 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
10951                         0xab, 0xab, 0xab, 0xab,
10952                         0xab, 0xab, 0xab, 0xab,
10953                         0xab, 0xab, 0xab, 0xab};
10954
10955 static int
10956 test_null_invalid_operation(void)
10957 {
10958         struct crypto_testsuite_params *ts_params = &testsuite_params;
10959         struct crypto_unittest_params *ut_params = &unittest_params;
10960         int ret;
10961
10962         /* This test is for NULL PMD only */
10963         if (gbl_driver_id != rte_cryptodev_driver_id_get(
10964                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
10965                 return TEST_SKIPPED;
10966
10967         /* Setup Cipher Parameters */
10968         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10969         ut_params->cipher_xform.next = NULL;
10970
10971         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
10972         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10973
10974         ut_params->sess = rte_cryptodev_sym_session_create(
10975                         ts_params->session_mpool);
10976
10977         /* Create Crypto session*/
10978         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10979                         ut_params->sess, &ut_params->cipher_xform,
10980                         ts_params->session_priv_mpool);
10981         TEST_ASSERT(ret < 0,
10982                         "Session creation succeeded unexpectedly");
10983
10984
10985         /* Setup HMAC Parameters */
10986         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10987         ut_params->auth_xform.next = NULL;
10988
10989         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
10990         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10991
10992         ut_params->sess = rte_cryptodev_sym_session_create(
10993                         ts_params->session_mpool);
10994
10995         /* Create Crypto session*/
10996         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10997                         ut_params->sess, &ut_params->auth_xform,
10998                         ts_params->session_priv_mpool);
10999         TEST_ASSERT(ret < 0,
11000                         "Session creation succeeded unexpectedly");
11001
11002         return TEST_SUCCESS;
11003 }
11004
11005
11006 #define NULL_BURST_LENGTH (32)
11007
11008 static int
11009 test_null_burst_operation(void)
11010 {
11011         struct crypto_testsuite_params *ts_params = &testsuite_params;
11012         struct crypto_unittest_params *ut_params = &unittest_params;
11013
11014         unsigned i, burst_len = NULL_BURST_LENGTH;
11015
11016         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11017         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11018
11019         /* This test is for NULL PMD only */
11020         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11021                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11022                 return TEST_SKIPPED;
11023
11024         /* Setup Cipher Parameters */
11025         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11026         ut_params->cipher_xform.next = &ut_params->auth_xform;
11027
11028         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11029         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11030
11031         /* Setup HMAC Parameters */
11032         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11033         ut_params->auth_xform.next = NULL;
11034
11035         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11036         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11037
11038         ut_params->sess = rte_cryptodev_sym_session_create(
11039                         ts_params->session_mpool);
11040
11041         /* Create Crypto session*/
11042         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11043                         ut_params->sess, &ut_params->cipher_xform,
11044                         ts_params->session_priv_mpool);
11045         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11046
11047         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11048                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11049                         burst_len, "failed to generate burst of crypto ops");
11050
11051         /* Generate an operation for each mbuf in burst */
11052         for (i = 0; i < burst_len; i++) {
11053                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11054
11055                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11056
11057                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11058                                 sizeof(unsigned));
11059                 *data = i;
11060
11061                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11062
11063                 burst[i]->sym->m_src = m;
11064         }
11065
11066         /* Process crypto operation */
11067         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11068                         0, burst, burst_len),
11069                         burst_len,
11070                         "Error enqueuing burst");
11071
11072         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11073                         0, burst_dequeued, burst_len),
11074                         burst_len,
11075                         "Error dequeuing burst");
11076
11077
11078         for (i = 0; i < burst_len; i++) {
11079                 TEST_ASSERT_EQUAL(
11080                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11081                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11082                                         uint32_t *),
11083                         "data not as expected");
11084
11085                 rte_pktmbuf_free(burst[i]->sym->m_src);
11086                 rte_crypto_op_free(burst[i]);
11087         }
11088
11089         return TEST_SUCCESS;
11090 }
11091
11092 static uint16_t
11093 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11094                   uint16_t nb_ops, void *user_param)
11095 {
11096         RTE_SET_USED(dev_id);
11097         RTE_SET_USED(qp_id);
11098         RTE_SET_USED(ops);
11099         RTE_SET_USED(user_param);
11100
11101         printf("crypto enqueue callback called\n");
11102         return nb_ops;
11103 }
11104
11105 static uint16_t
11106 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11107                   uint16_t nb_ops, void *user_param)
11108 {
11109         RTE_SET_USED(dev_id);
11110         RTE_SET_USED(qp_id);
11111         RTE_SET_USED(ops);
11112         RTE_SET_USED(user_param);
11113
11114         printf("crypto dequeue callback called\n");
11115         return nb_ops;
11116 }
11117
11118 /*
11119  * Thread using enqueue/dequeue callback with RCU.
11120  */
11121 static int
11122 test_enqdeq_callback_thread(void *arg)
11123 {
11124         RTE_SET_USED(arg);
11125         /* DP thread calls rte_cryptodev_enqueue_burst()/
11126          * rte_cryptodev_dequeue_burst() and invokes callback.
11127          */
11128         test_null_burst_operation();
11129         return 0;
11130 }
11131
11132 static int
11133 test_enq_callback_setup(void)
11134 {
11135         struct crypto_testsuite_params *ts_params = &testsuite_params;
11136         struct rte_cryptodev_info dev_info;
11137         struct rte_cryptodev_qp_conf qp_conf = {
11138                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11139         };
11140
11141         struct rte_cryptodev_cb *cb;
11142         uint16_t qp_id = 0;
11143
11144         /* Stop the device in case it's started so it can be configured */
11145         rte_cryptodev_stop(ts_params->valid_devs[0]);
11146
11147         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11148
11149         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11150                         &ts_params->conf),
11151                         "Failed to configure cryptodev %u",
11152                         ts_params->valid_devs[0]);
11153
11154         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11155         qp_conf.mp_session = ts_params->session_mpool;
11156         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11157
11158         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11159                         ts_params->valid_devs[0], qp_id, &qp_conf,
11160                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11161                         "Failed test for "
11162                         "rte_cryptodev_queue_pair_setup: num_inflights "
11163                         "%u on qp %u on cryptodev %u",
11164                         qp_conf.nb_descriptors, qp_id,
11165                         ts_params->valid_devs[0]);
11166
11167         /* Test with invalid crypto device */
11168         cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11169                         qp_id, test_enq_callback, NULL);
11170         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11171                         "cryptodev %u did not fail",
11172                         qp_id, RTE_CRYPTO_MAX_DEVS);
11173
11174         /* Test with invalid queue pair */
11175         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11176                         dev_info.max_nb_queue_pairs + 1,
11177                         test_enq_callback, NULL);
11178         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11179                         "cryptodev %u did not fail",
11180                         dev_info.max_nb_queue_pairs + 1,
11181                         ts_params->valid_devs[0]);
11182
11183         /* Test with NULL callback */
11184         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11185                         qp_id, NULL, NULL);
11186         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11187                         "cryptodev %u did not fail",
11188                         qp_id, ts_params->valid_devs[0]);
11189
11190         /* Test with valid configuration */
11191         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11192                         qp_id, test_enq_callback, NULL);
11193         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11194                         "qp %u on cryptodev %u",
11195                         qp_id, ts_params->valid_devs[0]);
11196
11197         rte_cryptodev_start(ts_params->valid_devs[0]);
11198
11199         /* Launch a thread */
11200         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11201                                 rte_get_next_lcore(-1, 1, 0));
11202
11203         /* Wait until reader exited. */
11204         rte_eal_mp_wait_lcore();
11205
11206         /* Test with invalid crypto device */
11207         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11208                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11209                         "Expected call to fail as crypto device is invalid");
11210
11211         /* Test with invalid queue pair */
11212         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11213                         ts_params->valid_devs[0],
11214                         dev_info.max_nb_queue_pairs + 1, cb),
11215                         "Expected call to fail as queue pair is invalid");
11216
11217         /* Test with NULL callback */
11218         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11219                         ts_params->valid_devs[0], qp_id, NULL),
11220                         "Expected call to fail as callback is NULL");
11221
11222         /* Test with valid configuration */
11223         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11224                         ts_params->valid_devs[0], qp_id, cb),
11225                         "Failed test to remove callback on "
11226                         "qp %u on cryptodev %u",
11227                         qp_id, ts_params->valid_devs[0]);
11228
11229         return TEST_SUCCESS;
11230 }
11231
11232 static int
11233 test_deq_callback_setup(void)
11234 {
11235         struct crypto_testsuite_params *ts_params = &testsuite_params;
11236         struct rte_cryptodev_info dev_info;
11237         struct rte_cryptodev_qp_conf qp_conf = {
11238                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11239         };
11240
11241         struct rte_cryptodev_cb *cb;
11242         uint16_t qp_id = 0;
11243
11244         /* Stop the device in case it's started so it can be configured */
11245         rte_cryptodev_stop(ts_params->valid_devs[0]);
11246
11247         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11248
11249         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11250                         &ts_params->conf),
11251                         "Failed to configure cryptodev %u",
11252                         ts_params->valid_devs[0]);
11253
11254         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11255         qp_conf.mp_session = ts_params->session_mpool;
11256         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11257
11258         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11259                         ts_params->valid_devs[0], qp_id, &qp_conf,
11260                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11261                         "Failed test for "
11262                         "rte_cryptodev_queue_pair_setup: num_inflights "
11263                         "%u on qp %u on cryptodev %u",
11264                         qp_conf.nb_descriptors, qp_id,
11265                         ts_params->valid_devs[0]);
11266
11267         /* Test with invalid crypto device */
11268         cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11269                         qp_id, test_deq_callback, NULL);
11270         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11271                         "cryptodev %u did not fail",
11272                         qp_id, RTE_CRYPTO_MAX_DEVS);
11273
11274         /* Test with invalid queue pair */
11275         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11276                         dev_info.max_nb_queue_pairs + 1,
11277                         test_deq_callback, NULL);
11278         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11279                         "cryptodev %u did not fail",
11280                         dev_info.max_nb_queue_pairs + 1,
11281                         ts_params->valid_devs[0]);
11282
11283         /* Test with NULL callback */
11284         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11285                         qp_id, NULL, NULL);
11286         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11287                         "cryptodev %u did not fail",
11288                         qp_id, ts_params->valid_devs[0]);
11289
11290         /* Test with valid configuration */
11291         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11292                         qp_id, test_deq_callback, NULL);
11293         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11294                         "qp %u on cryptodev %u",
11295                         qp_id, ts_params->valid_devs[0]);
11296
11297         rte_cryptodev_start(ts_params->valid_devs[0]);
11298
11299         /* Launch a thread */
11300         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11301                                 rte_get_next_lcore(-1, 1, 0));
11302
11303         /* Wait until reader exited. */
11304         rte_eal_mp_wait_lcore();
11305
11306         /* Test with invalid crypto device */
11307         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11308                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11309                         "Expected call to fail as crypto device is invalid");
11310
11311         /* Test with invalid queue pair */
11312         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11313                         ts_params->valid_devs[0],
11314                         dev_info.max_nb_queue_pairs + 1, cb),
11315                         "Expected call to fail as queue pair is invalid");
11316
11317         /* Test with NULL callback */
11318         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11319                         ts_params->valid_devs[0], qp_id, NULL),
11320                         "Expected call to fail as callback is NULL");
11321
11322         /* Test with valid configuration */
11323         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
11324                         ts_params->valid_devs[0], qp_id, cb),
11325                         "Failed test to remove callback on "
11326                         "qp %u on cryptodev %u",
11327                         qp_id, ts_params->valid_devs[0]);
11328
11329         return TEST_SUCCESS;
11330 }
11331
11332 static void
11333 generate_gmac_large_plaintext(uint8_t *data)
11334 {
11335         uint16_t i;
11336
11337         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
11338                 memcpy(&data[i], &data[0], 32);
11339 }
11340
11341 static int
11342 create_gmac_operation(enum rte_crypto_auth_operation op,
11343                 const struct gmac_test_data *tdata)
11344 {
11345         struct crypto_testsuite_params *ts_params = &testsuite_params;
11346         struct crypto_unittest_params *ut_params = &unittest_params;
11347         struct rte_crypto_sym_op *sym_op;
11348
11349         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11350
11351         /* Generate Crypto op data structure */
11352         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11353                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11354         TEST_ASSERT_NOT_NULL(ut_params->op,
11355                         "Failed to allocate symmetric crypto operation struct");
11356
11357         sym_op = ut_params->op->sym;
11358
11359         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11360                         ut_params->ibuf, tdata->gmac_tag.len);
11361         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11362                         "no room to append digest");
11363
11364         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11365                         ut_params->ibuf, plaintext_pad_len);
11366
11367         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11368                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11369                                 tdata->gmac_tag.len);
11370                 debug_hexdump(stdout, "digest:",
11371                                 sym_op->auth.digest.data,
11372                                 tdata->gmac_tag.len);
11373         }
11374
11375         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11376                         uint8_t *, IV_OFFSET);
11377
11378         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11379
11380         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11381
11382         sym_op->cipher.data.length = 0;
11383         sym_op->cipher.data.offset = 0;
11384
11385         sym_op->auth.data.offset = 0;
11386         sym_op->auth.data.length = tdata->plaintext.len;
11387
11388         return 0;
11389 }
11390
11391 static int
11392 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
11393                 const struct gmac_test_data *tdata,
11394                 void *digest_mem, uint64_t digest_phys)
11395 {
11396         struct crypto_testsuite_params *ts_params = &testsuite_params;
11397         struct crypto_unittest_params *ut_params = &unittest_params;
11398         struct rte_crypto_sym_op *sym_op;
11399
11400         /* Generate Crypto op data structure */
11401         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11402                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11403         TEST_ASSERT_NOT_NULL(ut_params->op,
11404                         "Failed to allocate symmetric crypto operation struct");
11405
11406         sym_op = ut_params->op->sym;
11407
11408         sym_op->auth.digest.data = digest_mem;
11409         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11410                         "no room to append digest");
11411
11412         sym_op->auth.digest.phys_addr = digest_phys;
11413
11414         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11415                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11416                                 tdata->gmac_tag.len);
11417                 debug_hexdump(stdout, "digest:",
11418                                 sym_op->auth.digest.data,
11419                                 tdata->gmac_tag.len);
11420         }
11421
11422         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11423                         uint8_t *, IV_OFFSET);
11424
11425         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11426
11427         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11428
11429         sym_op->cipher.data.length = 0;
11430         sym_op->cipher.data.offset = 0;
11431
11432         sym_op->auth.data.offset = 0;
11433         sym_op->auth.data.length = tdata->plaintext.len;
11434
11435         return 0;
11436 }
11437
11438 static int create_gmac_session(uint8_t dev_id,
11439                 const struct gmac_test_data *tdata,
11440                 enum rte_crypto_auth_operation auth_op)
11441 {
11442         uint8_t auth_key[tdata->key.len];
11443
11444         struct crypto_testsuite_params *ts_params = &testsuite_params;
11445         struct crypto_unittest_params *ut_params = &unittest_params;
11446
11447         memcpy(auth_key, tdata->key.data, tdata->key.len);
11448
11449         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11450         ut_params->auth_xform.next = NULL;
11451
11452         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
11453         ut_params->auth_xform.auth.op = auth_op;
11454         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
11455         ut_params->auth_xform.auth.key.length = tdata->key.len;
11456         ut_params->auth_xform.auth.key.data = auth_key;
11457         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11458         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
11459
11460
11461         ut_params->sess = rte_cryptodev_sym_session_create(
11462                         ts_params->session_mpool);
11463
11464         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11465                         &ut_params->auth_xform,
11466                         ts_params->session_priv_mpool);
11467
11468         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11469
11470         return 0;
11471 }
11472
11473 static int
11474 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
11475 {
11476         struct crypto_testsuite_params *ts_params = &testsuite_params;
11477         struct crypto_unittest_params *ut_params = &unittest_params;
11478         struct rte_cryptodev_info dev_info;
11479
11480         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11481         uint64_t feat_flags = dev_info.feature_flags;
11482
11483         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11484                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11485                 printf("Device doesn't support RAW data-path APIs.\n");
11486                 return TEST_SKIPPED;
11487         }
11488
11489         int retval;
11490
11491         uint8_t *auth_tag, *plaintext;
11492         uint16_t plaintext_pad_len;
11493
11494         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11495                               "No GMAC length in the source data");
11496
11497         /* Verify the capabilities */
11498         struct rte_cryptodev_sym_capability_idx cap_idx;
11499         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11500         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11501         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11502                         &cap_idx) == NULL)
11503                 return TEST_SKIPPED;
11504
11505         retval = create_gmac_session(ts_params->valid_devs[0],
11506                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11507
11508         if (retval < 0)
11509                 return retval;
11510
11511         if (tdata->plaintext.len > MBUF_SIZE)
11512                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11513         else
11514                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11515         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11516                         "Failed to allocate input buffer in mempool");
11517
11518         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11519                         rte_pktmbuf_tailroom(ut_params->ibuf));
11520
11521         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11522         /*
11523          * Runtime generate the large plain text instead of use hard code
11524          * plain text vector. It is done to avoid create huge source file
11525          * with the test vector.
11526          */
11527         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11528                 generate_gmac_large_plaintext(tdata->plaintext.data);
11529
11530         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11531                                 plaintext_pad_len);
11532         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11533
11534         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11535         debug_hexdump(stdout, "plaintext:", plaintext,
11536                         tdata->plaintext.len);
11537
11538         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
11539                         tdata);
11540
11541         if (retval < 0)
11542                 return retval;
11543
11544         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11545
11546         ut_params->op->sym->m_src = ut_params->ibuf;
11547
11548         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11549                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11550                         ut_params->op);
11551         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11552                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11553                                 ut_params->op, 0, 1, 0, 0);
11554         else
11555                 TEST_ASSERT_NOT_NULL(
11556                         process_crypto_request(ts_params->valid_devs[0],
11557                         ut_params->op), "failed to process sym crypto op");
11558
11559         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11560                         "crypto op processing failed");
11561
11562         if (ut_params->op->sym->m_dst) {
11563                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11564                                 uint8_t *, plaintext_pad_len);
11565         } else {
11566                 auth_tag = plaintext + plaintext_pad_len;
11567         }
11568
11569         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11570
11571         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11572                         auth_tag,
11573                         tdata->gmac_tag.data,
11574                         tdata->gmac_tag.len,
11575                         "GMAC Generated auth tag not as expected");
11576
11577         return 0;
11578 }
11579
11580 static int
11581 test_AES_GMAC_authentication_test_case_1(void)
11582 {
11583         return test_AES_GMAC_authentication(&gmac_test_case_1);
11584 }
11585
11586 static int
11587 test_AES_GMAC_authentication_test_case_2(void)
11588 {
11589         return test_AES_GMAC_authentication(&gmac_test_case_2);
11590 }
11591
11592 static int
11593 test_AES_GMAC_authentication_test_case_3(void)
11594 {
11595         return test_AES_GMAC_authentication(&gmac_test_case_3);
11596 }
11597
11598 static int
11599 test_AES_GMAC_authentication_test_case_4(void)
11600 {
11601         return test_AES_GMAC_authentication(&gmac_test_case_4);
11602 }
11603
11604 static int
11605 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
11606 {
11607         struct crypto_testsuite_params *ts_params = &testsuite_params;
11608         struct crypto_unittest_params *ut_params = &unittest_params;
11609         int retval;
11610         uint32_t plaintext_pad_len;
11611         uint8_t *plaintext;
11612         struct rte_cryptodev_info dev_info;
11613
11614         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11615         uint64_t feat_flags = dev_info.feature_flags;
11616
11617         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11618                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11619                 printf("Device doesn't support RAW data-path APIs.\n");
11620                 return TEST_SKIPPED;
11621         }
11622
11623         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11624                               "No GMAC length in the source data");
11625
11626         /* Verify the capabilities */
11627         struct rte_cryptodev_sym_capability_idx cap_idx;
11628         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11629         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11630         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11631                         &cap_idx) == NULL)
11632                 return TEST_SKIPPED;
11633
11634         retval = create_gmac_session(ts_params->valid_devs[0],
11635                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
11636
11637         if (retval < 0)
11638                 return retval;
11639
11640         if (tdata->plaintext.len > MBUF_SIZE)
11641                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11642         else
11643                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11644         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11645                         "Failed to allocate input buffer in mempool");
11646
11647         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11648                         rte_pktmbuf_tailroom(ut_params->ibuf));
11649
11650         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11651
11652         /*
11653          * Runtime generate the large plain text instead of use hard code
11654          * plain text vector. It is done to avoid create huge source file
11655          * with the test vector.
11656          */
11657         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11658                 generate_gmac_large_plaintext(tdata->plaintext.data);
11659
11660         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11661                                 plaintext_pad_len);
11662         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11663
11664         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11665         debug_hexdump(stdout, "plaintext:", plaintext,
11666                         tdata->plaintext.len);
11667
11668         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
11669                         tdata);
11670
11671         if (retval < 0)
11672                 return retval;
11673
11674         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11675
11676         ut_params->op->sym->m_src = ut_params->ibuf;
11677
11678         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11679                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11680                         ut_params->op);
11681         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11682                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11683                                 ut_params->op, 0, 1, 0, 0);
11684         else
11685                 TEST_ASSERT_NOT_NULL(
11686                         process_crypto_request(ts_params->valid_devs[0],
11687                         ut_params->op), "failed to process sym crypto op");
11688
11689         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11690                         "crypto op processing failed");
11691
11692         return 0;
11693
11694 }
11695
11696 static int
11697 test_AES_GMAC_authentication_verify_test_case_1(void)
11698 {
11699         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
11700 }
11701
11702 static int
11703 test_AES_GMAC_authentication_verify_test_case_2(void)
11704 {
11705         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
11706 }
11707
11708 static int
11709 test_AES_GMAC_authentication_verify_test_case_3(void)
11710 {
11711         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
11712 }
11713
11714 static int
11715 test_AES_GMAC_authentication_verify_test_case_4(void)
11716 {
11717         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
11718 }
11719
11720 static int
11721 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
11722                                 uint32_t fragsz)
11723 {
11724         struct crypto_testsuite_params *ts_params = &testsuite_params;
11725         struct crypto_unittest_params *ut_params = &unittest_params;
11726         struct rte_cryptodev_info dev_info;
11727         uint64_t feature_flags;
11728         unsigned int trn_data = 0;
11729         void *digest_mem = NULL;
11730         uint32_t segs = 1;
11731         unsigned int to_trn = 0;
11732         struct rte_mbuf *buf = NULL;
11733         uint8_t *auth_tag, *plaintext;
11734         int retval;
11735
11736         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11737                               "No GMAC length in the source data");
11738
11739         /* Verify the capabilities */
11740         struct rte_cryptodev_sym_capability_idx cap_idx;
11741         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11742         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11743         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11744                         &cap_idx) == NULL)
11745                 return TEST_SKIPPED;
11746
11747         /* Check for any input SGL support */
11748         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11749         feature_flags = dev_info.feature_flags;
11750
11751         if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
11752                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
11753                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
11754                 return TEST_SKIPPED;
11755
11756         if (fragsz > tdata->plaintext.len)
11757                 fragsz = tdata->plaintext.len;
11758
11759         uint16_t plaintext_len = fragsz;
11760
11761         retval = create_gmac_session(ts_params->valid_devs[0],
11762                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11763
11764         if (retval < 0)
11765                 return retval;
11766
11767         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11768         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11769                         "Failed to allocate input buffer in mempool");
11770
11771         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11772                         rte_pktmbuf_tailroom(ut_params->ibuf));
11773
11774         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11775                                 plaintext_len);
11776         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11777
11778         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
11779
11780         trn_data += plaintext_len;
11781
11782         buf = ut_params->ibuf;
11783
11784         /*
11785          * Loop until no more fragments
11786          */
11787
11788         while (trn_data < tdata->plaintext.len) {
11789                 ++segs;
11790                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
11791                                 (tdata->plaintext.len - trn_data) : fragsz;
11792
11793                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11794                 buf = buf->next;
11795
11796                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
11797                                 rte_pktmbuf_tailroom(buf));
11798
11799                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
11800                                 to_trn);
11801
11802                 memcpy(plaintext, tdata->plaintext.data + trn_data,
11803                                 to_trn);
11804                 trn_data += to_trn;
11805                 if (trn_data  == tdata->plaintext.len)
11806                         digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
11807                                         tdata->gmac_tag.len);
11808         }
11809         ut_params->ibuf->nb_segs = segs;
11810
11811         /*
11812          * Place digest at the end of the last buffer
11813          */
11814         uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11815
11816         if (!digest_mem) {
11817                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11818                                 + tdata->gmac_tag.len);
11819                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11820                                 tdata->plaintext.len);
11821         }
11822
11823         retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
11824                         tdata, digest_mem, digest_phys);
11825
11826         if (retval < 0)
11827                 return retval;
11828
11829         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11830
11831         ut_params->op->sym->m_src = ut_params->ibuf;
11832
11833         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11834                 return TEST_SKIPPED;
11835
11836         TEST_ASSERT_NOT_NULL(
11837                 process_crypto_request(ts_params->valid_devs[0],
11838                 ut_params->op), "failed to process sym crypto op");
11839
11840         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11841                         "crypto op processing failed");
11842
11843         auth_tag = digest_mem;
11844         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11845         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11846                         auth_tag,
11847                         tdata->gmac_tag.data,
11848                         tdata->gmac_tag.len,
11849                         "GMAC Generated auth tag not as expected");
11850
11851         return 0;
11852 }
11853
11854 /* Segment size not multiple of block size (16B) */
11855 static int
11856 test_AES_GMAC_authentication_SGL_40B(void)
11857 {
11858         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
11859 }
11860
11861 static int
11862 test_AES_GMAC_authentication_SGL_80B(void)
11863 {
11864         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
11865 }
11866
11867 static int
11868 test_AES_GMAC_authentication_SGL_2048B(void)
11869 {
11870         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
11871 }
11872
11873 /* Segment size not multiple of block size (16B) */
11874 static int
11875 test_AES_GMAC_authentication_SGL_2047B(void)
11876 {
11877         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
11878 }
11879
11880 struct test_crypto_vector {
11881         enum rte_crypto_cipher_algorithm crypto_algo;
11882         unsigned int cipher_offset;
11883         unsigned int cipher_len;
11884
11885         struct {
11886                 uint8_t data[64];
11887                 unsigned int len;
11888         } cipher_key;
11889
11890         struct {
11891                 uint8_t data[64];
11892                 unsigned int len;
11893         } iv;
11894
11895         struct {
11896                 const uint8_t *data;
11897                 unsigned int len;
11898         } plaintext;
11899
11900         struct {
11901                 const uint8_t *data;
11902                 unsigned int len;
11903         } ciphertext;
11904
11905         enum rte_crypto_auth_algorithm auth_algo;
11906         unsigned int auth_offset;
11907
11908         struct {
11909                 uint8_t data[128];
11910                 unsigned int len;
11911         } auth_key;
11912
11913         struct {
11914                 const uint8_t *data;
11915                 unsigned int len;
11916         } aad;
11917
11918         struct {
11919                 uint8_t data[128];
11920                 unsigned int len;
11921         } digest;
11922 };
11923
11924 static const struct test_crypto_vector
11925 hmac_sha1_test_crypto_vector = {
11926         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11927         .plaintext = {
11928                 .data = plaintext_hash,
11929                 .len = 512
11930         },
11931         .auth_key = {
11932                 .data = {
11933                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11934                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11935                         0xDE, 0xF4, 0xDE, 0xAD
11936                 },
11937                 .len = 20
11938         },
11939         .digest = {
11940                 .data = {
11941                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
11942                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
11943                         0x3F, 0x91, 0x64, 0x59
11944                 },
11945                 .len = 20
11946         }
11947 };
11948
11949 static const struct test_crypto_vector
11950 aes128_gmac_test_vector = {
11951         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
11952         .plaintext = {
11953                 .data = plaintext_hash,
11954                 .len = 512
11955         },
11956         .iv = {
11957                 .data = {
11958                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11959                         0x08, 0x09, 0x0A, 0x0B
11960                 },
11961                 .len = 12
11962         },
11963         .auth_key = {
11964                 .data = {
11965                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
11966                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
11967                 },
11968                 .len = 16
11969         },
11970         .digest = {
11971                 .data = {
11972                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
11973                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
11974                 },
11975                 .len = 16
11976         }
11977 };
11978
11979 static const struct test_crypto_vector
11980 aes128cbc_hmac_sha1_test_vector = {
11981         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
11982         .cipher_offset = 0,
11983         .cipher_len = 512,
11984         .cipher_key = {
11985                 .data = {
11986                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
11987                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
11988                 },
11989                 .len = 16
11990         },
11991         .iv = {
11992                 .data = {
11993                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11994                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
11995                 },
11996                 .len = 16
11997         },
11998         .plaintext = {
11999                 .data = plaintext_hash,
12000                 .len = 512
12001         },
12002         .ciphertext = {
12003                 .data = ciphertext512_aes128cbc,
12004                 .len = 512
12005         },
12006         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12007         .auth_offset = 0,
12008         .auth_key = {
12009                 .data = {
12010                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12011                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12012                         0xDE, 0xF4, 0xDE, 0xAD
12013                 },
12014                 .len = 20
12015         },
12016         .digest = {
12017                 .data = {
12018                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12019                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12020                         0x18, 0x8C, 0x1D, 0x32
12021                 },
12022                 .len = 20
12023         }
12024 };
12025
12026 static const struct test_crypto_vector
12027 aes128cbc_hmac_sha1_aad_test_vector = {
12028         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12029         .cipher_offset = 8,
12030         .cipher_len = 496,
12031         .cipher_key = {
12032                 .data = {
12033                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12034                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12035                 },
12036                 .len = 16
12037         },
12038         .iv = {
12039                 .data = {
12040                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12041                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12042                 },
12043                 .len = 16
12044         },
12045         .plaintext = {
12046                 .data = plaintext_hash,
12047                 .len = 512
12048         },
12049         .ciphertext = {
12050                 .data = ciphertext512_aes128cbc_aad,
12051                 .len = 512
12052         },
12053         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12054         .auth_offset = 0,
12055         .auth_key = {
12056                 .data = {
12057                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12058                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12059                         0xDE, 0xF4, 0xDE, 0xAD
12060                 },
12061                 .len = 20
12062         },
12063         .digest = {
12064                 .data = {
12065                         0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12066                         0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12067                         0x62, 0x0F, 0xFB, 0x10
12068                 },
12069                 .len = 20
12070         }
12071 };
12072
12073 static void
12074 data_corruption(uint8_t *data)
12075 {
12076         data[0] += 1;
12077 }
12078
12079 static void
12080 tag_corruption(uint8_t *data, unsigned int tag_offset)
12081 {
12082         data[tag_offset] += 1;
12083 }
12084
12085 static int
12086 create_auth_session(struct crypto_unittest_params *ut_params,
12087                 uint8_t dev_id,
12088                 const struct test_crypto_vector *reference,
12089                 enum rte_crypto_auth_operation auth_op)
12090 {
12091         struct crypto_testsuite_params *ts_params = &testsuite_params;
12092         uint8_t auth_key[reference->auth_key.len + 1];
12093
12094         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12095
12096         /* Setup Authentication Parameters */
12097         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12098         ut_params->auth_xform.auth.op = auth_op;
12099         ut_params->auth_xform.next = NULL;
12100         ut_params->auth_xform.auth.algo = reference->auth_algo;
12101         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12102         ut_params->auth_xform.auth.key.data = auth_key;
12103         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12104
12105         /* Create Crypto session*/
12106         ut_params->sess = rte_cryptodev_sym_session_create(
12107                         ts_params->session_mpool);
12108
12109         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12110                                 &ut_params->auth_xform,
12111                                 ts_params->session_priv_mpool);
12112
12113         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12114
12115         return 0;
12116 }
12117
12118 static int
12119 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12120                 uint8_t dev_id,
12121                 const struct test_crypto_vector *reference,
12122                 enum rte_crypto_auth_operation auth_op,
12123                 enum rte_crypto_cipher_operation cipher_op)
12124 {
12125         struct crypto_testsuite_params *ts_params = &testsuite_params;
12126         uint8_t cipher_key[reference->cipher_key.len + 1];
12127         uint8_t auth_key[reference->auth_key.len + 1];
12128
12129         memcpy(cipher_key, reference->cipher_key.data,
12130                         reference->cipher_key.len);
12131         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12132
12133         /* Setup Authentication Parameters */
12134         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12135         ut_params->auth_xform.auth.op = auth_op;
12136         ut_params->auth_xform.auth.algo = reference->auth_algo;
12137         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12138         ut_params->auth_xform.auth.key.data = auth_key;
12139         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12140
12141         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12142                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12143                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
12144         } else {
12145                 ut_params->auth_xform.next = &ut_params->cipher_xform;
12146
12147                 /* Setup Cipher Parameters */
12148                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12149                 ut_params->cipher_xform.next = NULL;
12150                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12151                 ut_params->cipher_xform.cipher.op = cipher_op;
12152                 ut_params->cipher_xform.cipher.key.data = cipher_key;
12153                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12154                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12155                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12156         }
12157
12158         /* Create Crypto session*/
12159         ut_params->sess = rte_cryptodev_sym_session_create(
12160                         ts_params->session_mpool);
12161
12162         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12163                                 &ut_params->auth_xform,
12164                                 ts_params->session_priv_mpool);
12165
12166         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12167
12168         return 0;
12169 }
12170
12171 static int
12172 create_auth_operation(struct crypto_testsuite_params *ts_params,
12173                 struct crypto_unittest_params *ut_params,
12174                 const struct test_crypto_vector *reference,
12175                 unsigned int auth_generate)
12176 {
12177         /* Generate Crypto op data structure */
12178         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12179                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12180         TEST_ASSERT_NOT_NULL(ut_params->op,
12181                         "Failed to allocate pktmbuf offload");
12182
12183         /* Set crypto operation data parameters */
12184         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12185
12186         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12187
12188         /* set crypto operation source mbuf */
12189         sym_op->m_src = ut_params->ibuf;
12190
12191         /* digest */
12192         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12193                         ut_params->ibuf, reference->digest.len);
12194
12195         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12196                         "no room to append auth tag");
12197
12198         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12199                         ut_params->ibuf, reference->plaintext.len);
12200
12201         if (auth_generate)
12202                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12203         else
12204                 memcpy(sym_op->auth.digest.data,
12205                                 reference->digest.data,
12206                                 reference->digest.len);
12207
12208         debug_hexdump(stdout, "digest:",
12209                         sym_op->auth.digest.data,
12210                         reference->digest.len);
12211
12212         sym_op->auth.data.length = reference->plaintext.len;
12213         sym_op->auth.data.offset = 0;
12214
12215         return 0;
12216 }
12217
12218 static int
12219 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12220                 struct crypto_unittest_params *ut_params,
12221                 const struct test_crypto_vector *reference,
12222                 unsigned int auth_generate)
12223 {
12224         /* Generate Crypto op data structure */
12225         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12226                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12227         TEST_ASSERT_NOT_NULL(ut_params->op,
12228                         "Failed to allocate pktmbuf offload");
12229
12230         /* Set crypto operation data parameters */
12231         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12232
12233         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12234
12235         /* set crypto operation source mbuf */
12236         sym_op->m_src = ut_params->ibuf;
12237
12238         /* digest */
12239         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12240                         ut_params->ibuf, reference->digest.len);
12241
12242         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12243                         "no room to append auth tag");
12244
12245         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12246                         ut_params->ibuf, reference->ciphertext.len);
12247
12248         if (auth_generate)
12249                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12250         else
12251                 memcpy(sym_op->auth.digest.data,
12252                                 reference->digest.data,
12253                                 reference->digest.len);
12254
12255         debug_hexdump(stdout, "digest:",
12256                         sym_op->auth.digest.data,
12257                         reference->digest.len);
12258
12259         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12260                         reference->iv.data, reference->iv.len);
12261
12262         sym_op->cipher.data.length = 0;
12263         sym_op->cipher.data.offset = 0;
12264
12265         sym_op->auth.data.length = reference->plaintext.len;
12266         sym_op->auth.data.offset = 0;
12267
12268         return 0;
12269 }
12270
12271 static int
12272 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12273                 struct crypto_unittest_params *ut_params,
12274                 const struct test_crypto_vector *reference,
12275                 unsigned int auth_generate)
12276 {
12277         /* Generate Crypto op data structure */
12278         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12279                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12280         TEST_ASSERT_NOT_NULL(ut_params->op,
12281                         "Failed to allocate pktmbuf offload");
12282
12283         /* Set crypto operation data parameters */
12284         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12285
12286         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12287
12288         /* set crypto operation source mbuf */
12289         sym_op->m_src = ut_params->ibuf;
12290
12291         /* digest */
12292         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12293                         ut_params->ibuf, reference->digest.len);
12294
12295         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12296                         "no room to append auth tag");
12297
12298         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12299                         ut_params->ibuf, reference->ciphertext.len);
12300
12301         if (auth_generate)
12302                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12303         else
12304                 memcpy(sym_op->auth.digest.data,
12305                                 reference->digest.data,
12306                                 reference->digest.len);
12307
12308         debug_hexdump(stdout, "digest:",
12309                         sym_op->auth.digest.data,
12310                         reference->digest.len);
12311
12312         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12313                         reference->iv.data, reference->iv.len);
12314
12315         sym_op->cipher.data.length = reference->cipher_len;
12316         sym_op->cipher.data.offset = reference->cipher_offset;
12317
12318         sym_op->auth.data.length = reference->plaintext.len;
12319         sym_op->auth.data.offset = reference->auth_offset;
12320
12321         return 0;
12322 }
12323
12324 static int
12325 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12326                 struct crypto_unittest_params *ut_params,
12327                 const struct test_crypto_vector *reference)
12328 {
12329         return create_auth_operation(ts_params, ut_params, reference, 0);
12330 }
12331
12332 static int
12333 create_auth_verify_GMAC_operation(
12334                 struct crypto_testsuite_params *ts_params,
12335                 struct crypto_unittest_params *ut_params,
12336                 const struct test_crypto_vector *reference)
12337 {
12338         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
12339 }
12340
12341 static int
12342 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12343                 struct crypto_unittest_params *ut_params,
12344                 const struct test_crypto_vector *reference)
12345 {
12346         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12347 }
12348
12349 static int
12350 test_authentication_verify_fail_when_data_corruption(
12351                 struct crypto_testsuite_params *ts_params,
12352                 struct crypto_unittest_params *ut_params,
12353                 const struct test_crypto_vector *reference,
12354                 unsigned int data_corrupted)
12355 {
12356         int retval;
12357
12358         uint8_t *plaintext;
12359         struct rte_cryptodev_info dev_info;
12360
12361         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12362         uint64_t feat_flags = dev_info.feature_flags;
12363
12364         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12365                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12366                 printf("Device doesn't support RAW data-path APIs.\n");
12367                 return TEST_SKIPPED;
12368         }
12369
12370         /* Verify the capabilities */
12371         struct rte_cryptodev_sym_capability_idx cap_idx;
12372         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12373         cap_idx.algo.auth = reference->auth_algo;
12374         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12375                         &cap_idx) == NULL)
12376                 return TEST_SKIPPED;
12377
12378
12379         /* Create session */
12380         retval = create_auth_session(ut_params,
12381                         ts_params->valid_devs[0],
12382                         reference,
12383                         RTE_CRYPTO_AUTH_OP_VERIFY);
12384         if (retval < 0)
12385                 return retval;
12386
12387         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12388         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12389                         "Failed to allocate input buffer in mempool");
12390
12391         /* clear mbuf payload */
12392         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12393                         rte_pktmbuf_tailroom(ut_params->ibuf));
12394
12395         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12396                         reference->plaintext.len);
12397         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12398         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12399
12400         debug_hexdump(stdout, "plaintext:", plaintext,
12401                 reference->plaintext.len);
12402
12403         /* Create operation */
12404         retval = create_auth_verify_operation(ts_params, ut_params, reference);
12405
12406         if (retval < 0)
12407                 return retval;
12408
12409         if (data_corrupted)
12410                 data_corruption(plaintext);
12411         else
12412                 tag_corruption(plaintext, reference->plaintext.len);
12413
12414         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12415                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12416                         ut_params->op);
12417                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12418                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12419                         "authentication not failed");
12420         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12421                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12422                                 ut_params->op, 0, 1, 0, 0);
12423         else {
12424                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12425                         ut_params->op);
12426                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12427         }
12428
12429         return 0;
12430 }
12431
12432 static int
12433 test_authentication_verify_GMAC_fail_when_corruption(
12434                 struct crypto_testsuite_params *ts_params,
12435                 struct crypto_unittest_params *ut_params,
12436                 const struct test_crypto_vector *reference,
12437                 unsigned int data_corrupted)
12438 {
12439         int retval;
12440         uint8_t *plaintext;
12441         struct rte_cryptodev_info dev_info;
12442
12443         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12444         uint64_t feat_flags = dev_info.feature_flags;
12445
12446         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12447                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12448                 printf("Device doesn't support RAW data-path APIs.\n");
12449                 return TEST_SKIPPED;
12450         }
12451
12452         /* Verify the capabilities */
12453         struct rte_cryptodev_sym_capability_idx cap_idx;
12454         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12455         cap_idx.algo.auth = reference->auth_algo;
12456         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12457                         &cap_idx) == NULL)
12458                 return TEST_SKIPPED;
12459
12460         /* Create session */
12461         retval = create_auth_cipher_session(ut_params,
12462                         ts_params->valid_devs[0],
12463                         reference,
12464                         RTE_CRYPTO_AUTH_OP_VERIFY,
12465                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12466         if (retval < 0)
12467                 return retval;
12468
12469         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12470         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12471                         "Failed to allocate input buffer in mempool");
12472
12473         /* clear mbuf payload */
12474         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12475                         rte_pktmbuf_tailroom(ut_params->ibuf));
12476
12477         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12478                         reference->plaintext.len);
12479         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12480         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12481
12482         debug_hexdump(stdout, "plaintext:", plaintext,
12483                 reference->plaintext.len);
12484
12485         /* Create operation */
12486         retval = create_auth_verify_GMAC_operation(ts_params,
12487                         ut_params,
12488                         reference);
12489
12490         if (retval < 0)
12491                 return retval;
12492
12493         if (data_corrupted)
12494                 data_corruption(plaintext);
12495         else
12496                 tag_corruption(plaintext, reference->aad.len);
12497
12498         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12499                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12500                         ut_params->op);
12501                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12502                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12503                         "authentication not failed");
12504         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12505                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12506                                 ut_params->op, 0, 1, 0, 0);
12507         else {
12508                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12509                         ut_params->op);
12510                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12511         }
12512
12513         return 0;
12514 }
12515
12516 static int
12517 test_authenticated_decryption_fail_when_corruption(
12518                 struct crypto_testsuite_params *ts_params,
12519                 struct crypto_unittest_params *ut_params,
12520                 const struct test_crypto_vector *reference,
12521                 unsigned int data_corrupted)
12522 {
12523         int retval;
12524
12525         uint8_t *ciphertext;
12526         struct rte_cryptodev_info dev_info;
12527
12528         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12529         uint64_t feat_flags = dev_info.feature_flags;
12530
12531         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12532                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12533                 printf("Device doesn't support RAW data-path APIs.\n");
12534                 return TEST_SKIPPED;
12535         }
12536
12537         /* Verify the capabilities */
12538         struct rte_cryptodev_sym_capability_idx cap_idx;
12539         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12540         cap_idx.algo.auth = reference->auth_algo;
12541         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12542                         &cap_idx) == NULL)
12543                 return TEST_SKIPPED;
12544         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12545         cap_idx.algo.cipher = reference->crypto_algo;
12546         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12547                         &cap_idx) == NULL)
12548                 return TEST_SKIPPED;
12549
12550         /* Create session */
12551         retval = create_auth_cipher_session(ut_params,
12552                         ts_params->valid_devs[0],
12553                         reference,
12554                         RTE_CRYPTO_AUTH_OP_VERIFY,
12555                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12556         if (retval < 0)
12557                 return retval;
12558
12559         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12560         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12561                         "Failed to allocate input buffer in mempool");
12562
12563         /* clear mbuf payload */
12564         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12565                         rte_pktmbuf_tailroom(ut_params->ibuf));
12566
12567         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12568                         reference->ciphertext.len);
12569         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12570         memcpy(ciphertext, reference->ciphertext.data,
12571                         reference->ciphertext.len);
12572
12573         /* Create operation */
12574         retval = create_cipher_auth_verify_operation(ts_params,
12575                         ut_params,
12576                         reference);
12577
12578         if (retval < 0)
12579                 return retval;
12580
12581         if (data_corrupted)
12582                 data_corruption(ciphertext);
12583         else
12584                 tag_corruption(ciphertext, reference->ciphertext.len);
12585
12586         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12587                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12588                         ut_params->op);
12589                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12590                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12591                         "authentication not failed");
12592         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12593                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12594                                 ut_params->op, 1, 1, 0, 0);
12595         else {
12596                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12597                         ut_params->op);
12598                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12599         }
12600
12601         return 0;
12602 }
12603
12604 static int
12605 test_authenticated_encrypt_with_esn(
12606                 struct crypto_testsuite_params *ts_params,
12607                 struct crypto_unittest_params *ut_params,
12608                 const struct test_crypto_vector *reference)
12609 {
12610         int retval;
12611
12612         uint8_t *authciphertext, *plaintext, *auth_tag;
12613         uint16_t plaintext_pad_len;
12614         uint8_t cipher_key[reference->cipher_key.len + 1];
12615         uint8_t auth_key[reference->auth_key.len + 1];
12616         struct rte_cryptodev_info dev_info;
12617
12618         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12619         uint64_t feat_flags = dev_info.feature_flags;
12620
12621         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12622                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12623                 printf("Device doesn't support RAW data-path APIs.\n");
12624                 return TEST_SKIPPED;
12625         }
12626
12627         /* Verify the capabilities */
12628         struct rte_cryptodev_sym_capability_idx cap_idx;
12629         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12630         cap_idx.algo.auth = reference->auth_algo;
12631         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12632                         &cap_idx) == NULL)
12633                 return TEST_SKIPPED;
12634         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12635         cap_idx.algo.cipher = reference->crypto_algo;
12636         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12637                         &cap_idx) == NULL)
12638                 return TEST_SKIPPED;
12639
12640         /* Create session */
12641         memcpy(cipher_key, reference->cipher_key.data,
12642                         reference->cipher_key.len);
12643         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12644
12645         /* Setup Cipher Parameters */
12646         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12647         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12648         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12649         ut_params->cipher_xform.cipher.key.data = cipher_key;
12650         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12651         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12652         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12653
12654         ut_params->cipher_xform.next = &ut_params->auth_xform;
12655
12656         /* Setup Authentication Parameters */
12657         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12658         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12659         ut_params->auth_xform.auth.algo = reference->auth_algo;
12660         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12661         ut_params->auth_xform.auth.key.data = auth_key;
12662         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12663         ut_params->auth_xform.next = NULL;
12664
12665         /* Create Crypto session*/
12666         ut_params->sess = rte_cryptodev_sym_session_create(
12667                         ts_params->session_mpool);
12668
12669         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12670                                 ut_params->sess,
12671                                 &ut_params->cipher_xform,
12672                                 ts_params->session_priv_mpool);
12673
12674         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12675
12676         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12677         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12678                         "Failed to allocate input buffer in mempool");
12679
12680         /* clear mbuf payload */
12681         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12682                         rte_pktmbuf_tailroom(ut_params->ibuf));
12683
12684         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12685                         reference->plaintext.len);
12686         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12687         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12688
12689         /* Create operation */
12690         retval = create_cipher_auth_operation(ts_params,
12691                         ut_params,
12692                         reference, 0);
12693
12694         if (retval < 0)
12695                 return retval;
12696
12697         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12698                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12699                         ut_params->op);
12700         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12701                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12702                                 ut_params->op, 1, 1, 0, 0);
12703         else
12704                 ut_params->op = process_crypto_request(
12705                         ts_params->valid_devs[0], ut_params->op);
12706
12707         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
12708
12709         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12710                         "crypto op processing failed");
12711
12712         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
12713
12714         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
12715                         ut_params->op->sym->auth.data.offset);
12716         auth_tag = authciphertext + plaintext_pad_len;
12717         debug_hexdump(stdout, "ciphertext:", authciphertext,
12718                         reference->ciphertext.len);
12719         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
12720
12721         /* Validate obuf */
12722         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12723                         authciphertext,
12724                         reference->ciphertext.data,
12725                         reference->ciphertext.len,
12726                         "Ciphertext data not as expected");
12727
12728         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12729                         auth_tag,
12730                         reference->digest.data,
12731                         reference->digest.len,
12732                         "Generated digest not as expected");
12733
12734         return TEST_SUCCESS;
12735
12736 }
12737
12738 static int
12739 test_authenticated_decrypt_with_esn(
12740                 struct crypto_testsuite_params *ts_params,
12741                 struct crypto_unittest_params *ut_params,
12742                 const struct test_crypto_vector *reference)
12743 {
12744         int retval;
12745
12746         uint8_t *ciphertext;
12747         uint8_t cipher_key[reference->cipher_key.len + 1];
12748         uint8_t auth_key[reference->auth_key.len + 1];
12749         struct rte_cryptodev_info dev_info;
12750
12751         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12752         uint64_t feat_flags = dev_info.feature_flags;
12753
12754         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12755                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12756                 printf("Device doesn't support RAW data-path APIs.\n");
12757                 return TEST_SKIPPED;
12758         }
12759
12760         /* Verify the capabilities */
12761         struct rte_cryptodev_sym_capability_idx cap_idx;
12762         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12763         cap_idx.algo.auth = reference->auth_algo;
12764         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12765                         &cap_idx) == NULL)
12766                 return TEST_SKIPPED;
12767         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12768         cap_idx.algo.cipher = reference->crypto_algo;
12769         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12770                         &cap_idx) == NULL)
12771                 return TEST_SKIPPED;
12772
12773         /* Create session */
12774         memcpy(cipher_key, reference->cipher_key.data,
12775                         reference->cipher_key.len);
12776         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12777
12778         /* Setup Authentication Parameters */
12779         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12780         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
12781         ut_params->auth_xform.auth.algo = reference->auth_algo;
12782         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12783         ut_params->auth_xform.auth.key.data = auth_key;
12784         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12785         ut_params->auth_xform.next = &ut_params->cipher_xform;
12786
12787         /* Setup Cipher Parameters */
12788         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12789         ut_params->cipher_xform.next = NULL;
12790         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12791         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
12792         ut_params->cipher_xform.cipher.key.data = cipher_key;
12793         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12794         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12795         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12796
12797         /* Create Crypto session*/
12798         ut_params->sess = rte_cryptodev_sym_session_create(
12799                         ts_params->session_mpool);
12800
12801         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12802                                 ut_params->sess,
12803                                 &ut_params->auth_xform,
12804                                 ts_params->session_priv_mpool);
12805
12806         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12807
12808         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12809         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12810                         "Failed to allocate input buffer in mempool");
12811
12812         /* clear mbuf payload */
12813         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12814                         rte_pktmbuf_tailroom(ut_params->ibuf));
12815
12816         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12817                         reference->ciphertext.len);
12818         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12819         memcpy(ciphertext, reference->ciphertext.data,
12820                         reference->ciphertext.len);
12821
12822         /* Create operation */
12823         retval = create_cipher_auth_verify_operation(ts_params,
12824                         ut_params,
12825                         reference);
12826
12827         if (retval < 0)
12828                 return retval;
12829
12830         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12831                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12832                         ut_params->op);
12833         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12834                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12835                                 ut_params->op, 1, 1, 0, 0);
12836         else
12837                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12838                         ut_params->op);
12839
12840         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
12841         TEST_ASSERT_EQUAL(ut_params->op->status,
12842                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12843                         "crypto op processing passed");
12844
12845         ut_params->obuf = ut_params->op->sym->m_src;
12846         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
12847
12848         return 0;
12849 }
12850
12851 static int
12852 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
12853                 const struct aead_test_data *tdata,
12854                 void *digest_mem, uint64_t digest_phys)
12855 {
12856         struct crypto_testsuite_params *ts_params = &testsuite_params;
12857         struct crypto_unittest_params *ut_params = &unittest_params;
12858
12859         const unsigned int auth_tag_len = tdata->auth_tag.len;
12860         const unsigned int iv_len = tdata->iv.len;
12861         unsigned int aad_len = tdata->aad.len;
12862         unsigned int aad_len_pad = 0;
12863
12864         /* Generate Crypto op data structure */
12865         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12866                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12867         TEST_ASSERT_NOT_NULL(ut_params->op,
12868                 "Failed to allocate symmetric crypto operation struct");
12869
12870         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12871
12872         sym_op->aead.digest.data = digest_mem;
12873
12874         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
12875                         "no room to append digest");
12876
12877         sym_op->aead.digest.phys_addr = digest_phys;
12878
12879         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
12880                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
12881                                 auth_tag_len);
12882                 debug_hexdump(stdout, "digest:",
12883                                 sym_op->aead.digest.data,
12884                                 auth_tag_len);
12885         }
12886
12887         /* Append aad data */
12888         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
12889                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12890                                 uint8_t *, IV_OFFSET);
12891
12892                 /* Copy IV 1 byte after the IV pointer, according to the API */
12893                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
12894
12895                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
12896
12897                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12898                                 ut_params->ibuf, aad_len);
12899                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12900                                 "no room to prepend aad");
12901                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12902                                 ut_params->ibuf);
12903
12904                 memset(sym_op->aead.aad.data, 0, aad_len);
12905                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
12906                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12907
12908                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12909                 debug_hexdump(stdout, "aad:",
12910                                 sym_op->aead.aad.data, aad_len);
12911         } else {
12912                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12913                                 uint8_t *, IV_OFFSET);
12914
12915                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
12916
12917                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
12918
12919                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12920                                 ut_params->ibuf, aad_len_pad);
12921                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12922                                 "no room to prepend aad");
12923                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12924                                 ut_params->ibuf);
12925
12926                 memset(sym_op->aead.aad.data, 0, aad_len);
12927                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12928
12929                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12930                 debug_hexdump(stdout, "aad:",
12931                                 sym_op->aead.aad.data, aad_len);
12932         }
12933
12934         sym_op->aead.data.length = tdata->plaintext.len;
12935         sym_op->aead.data.offset = aad_len_pad;
12936
12937         return 0;
12938 }
12939
12940 #define SGL_MAX_NO      16
12941
12942 static int
12943 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
12944                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
12945 {
12946         struct crypto_testsuite_params *ts_params = &testsuite_params;
12947         struct crypto_unittest_params *ut_params = &unittest_params;
12948         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
12949         int retval;
12950         int to_trn = 0;
12951         int to_trn_tbl[SGL_MAX_NO];
12952         int segs = 1;
12953         unsigned int trn_data = 0;
12954         uint8_t *plaintext, *ciphertext, *auth_tag;
12955         struct rte_cryptodev_info dev_info;
12956
12957         /* Verify the capabilities */
12958         struct rte_cryptodev_sym_capability_idx cap_idx;
12959         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
12960         cap_idx.algo.aead = tdata->algo;
12961         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12962                         &cap_idx) == NULL)
12963                 return TEST_SKIPPED;
12964
12965         /* OOP not supported with CPU crypto */
12966         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12967                 return TEST_SKIPPED;
12968
12969         /* Detailed check for the particular SGL support flag */
12970         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12971         if (!oop) {
12972                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
12973                 if (sgl_in && (!(dev_info.feature_flags &
12974                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
12975                         return TEST_SKIPPED;
12976
12977                 uint64_t feat_flags = dev_info.feature_flags;
12978
12979                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12980                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12981                         printf("Device doesn't support RAW data-path APIs.\n");
12982                         return TEST_SKIPPED;
12983                 }
12984         } else {
12985                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
12986                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
12987                                 tdata->plaintext.len;
12988                 /* Raw data path API does not support OOP */
12989                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12990                         return TEST_SKIPPED;
12991                 if (sgl_in && !sgl_out) {
12992                         if (!(dev_info.feature_flags &
12993                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
12994                                 return TEST_SKIPPED;
12995                 } else if (!sgl_in && sgl_out) {
12996                         if (!(dev_info.feature_flags &
12997                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
12998                                 return TEST_SKIPPED;
12999                 } else if (sgl_in && sgl_out) {
13000                         if (!(dev_info.feature_flags &
13001                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13002                                 return TEST_SKIPPED;
13003                 }
13004         }
13005
13006         if (fragsz > tdata->plaintext.len)
13007                 fragsz = tdata->plaintext.len;
13008
13009         uint16_t plaintext_len = fragsz;
13010         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13011
13012         if (fragsz_oop > tdata->plaintext.len)
13013                 frag_size_oop = tdata->plaintext.len;
13014
13015         int ecx = 0;
13016         void *digest_mem = NULL;
13017
13018         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13019
13020         if (tdata->plaintext.len % fragsz != 0) {
13021                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13022                         return 1;
13023         }       else {
13024                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13025                         return 1;
13026         }
13027
13028         /*
13029          * For out-op-place we need to alloc another mbuf
13030          */
13031         if (oop) {
13032                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13033                 rte_pktmbuf_append(ut_params->obuf,
13034                                 frag_size_oop + prepend_len);
13035                 buf_oop = ut_params->obuf;
13036         }
13037
13038         /* Create AEAD session */
13039         retval = create_aead_session(ts_params->valid_devs[0],
13040                         tdata->algo,
13041                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
13042                         tdata->key.data, tdata->key.len,
13043                         tdata->aad.len, tdata->auth_tag.len,
13044                         tdata->iv.len);
13045         if (retval < 0)
13046                 return retval;
13047
13048         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13049
13050         /* clear mbuf payload */
13051         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13052                         rte_pktmbuf_tailroom(ut_params->ibuf));
13053
13054         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13055                         plaintext_len);
13056
13057         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13058
13059         trn_data += plaintext_len;
13060
13061         buf = ut_params->ibuf;
13062
13063         /*
13064          * Loop until no more fragments
13065          */
13066
13067         while (trn_data < tdata->plaintext.len) {
13068                 ++segs;
13069                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13070                                 (tdata->plaintext.len - trn_data) : fragsz;
13071
13072                 to_trn_tbl[ecx++] = to_trn;
13073
13074                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13075                 buf = buf->next;
13076
13077                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13078                                 rte_pktmbuf_tailroom(buf));
13079
13080                 /* OOP */
13081                 if (oop && !fragsz_oop) {
13082                         buf_last_oop = buf_oop->next =
13083                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13084                         buf_oop = buf_oop->next;
13085                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13086                                         0, rte_pktmbuf_tailroom(buf_oop));
13087                         rte_pktmbuf_append(buf_oop, to_trn);
13088                 }
13089
13090                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13091                                 to_trn);
13092
13093                 memcpy(plaintext, tdata->plaintext.data + trn_data,
13094                                 to_trn);
13095                 trn_data += to_trn;
13096                 if (trn_data  == tdata->plaintext.len) {
13097                         if (oop) {
13098                                 if (!fragsz_oop)
13099                                         digest_mem = rte_pktmbuf_append(buf_oop,
13100                                                 tdata->auth_tag.len);
13101                         } else
13102                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13103                                         tdata->auth_tag.len);
13104                 }
13105         }
13106
13107         uint64_t digest_phys = 0;
13108
13109         ut_params->ibuf->nb_segs = segs;
13110
13111         segs = 1;
13112         if (fragsz_oop && oop) {
13113                 to_trn = 0;
13114                 ecx = 0;
13115
13116                 if (frag_size_oop == tdata->plaintext.len) {
13117                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
13118                                 tdata->auth_tag.len);
13119
13120                         digest_phys = rte_pktmbuf_iova_offset(
13121                                         ut_params->obuf,
13122                                         tdata->plaintext.len + prepend_len);
13123                 }
13124
13125                 trn_data = frag_size_oop;
13126                 while (trn_data < tdata->plaintext.len) {
13127                         ++segs;
13128                         to_trn =
13129                                 (tdata->plaintext.len - trn_data <
13130                                                 frag_size_oop) ?
13131                                 (tdata->plaintext.len - trn_data) :
13132                                                 frag_size_oop;
13133
13134                         to_trn_tbl[ecx++] = to_trn;
13135
13136                         buf_last_oop = buf_oop->next =
13137                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13138                         buf_oop = buf_oop->next;
13139                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13140                                         0, rte_pktmbuf_tailroom(buf_oop));
13141                         rte_pktmbuf_append(buf_oop, to_trn);
13142
13143                         trn_data += to_trn;
13144
13145                         if (trn_data  == tdata->plaintext.len) {
13146                                 digest_mem = rte_pktmbuf_append(buf_oop,
13147                                         tdata->auth_tag.len);
13148                         }
13149                 }
13150
13151                 ut_params->obuf->nb_segs = segs;
13152         }
13153
13154         /*
13155          * Place digest at the end of the last buffer
13156          */
13157         if (!digest_phys)
13158                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13159         if (oop && buf_last_oop)
13160                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13161
13162         if (!digest_mem && !oop) {
13163                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13164                                 + tdata->auth_tag.len);
13165                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13166                                 tdata->plaintext.len);
13167         }
13168
13169         /* Create AEAD operation */
13170         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13171                         tdata, digest_mem, digest_phys);
13172
13173         if (retval < 0)
13174                 return retval;
13175
13176         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13177
13178         ut_params->op->sym->m_src = ut_params->ibuf;
13179         if (oop)
13180                 ut_params->op->sym->m_dst = ut_params->obuf;
13181
13182         /* Process crypto operation */
13183         if (oop == IN_PLACE &&
13184                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13185                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13186         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13187                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13188                                 ut_params->op, 0, 0, 0, 0);
13189         else
13190                 TEST_ASSERT_NOT_NULL(
13191                         process_crypto_request(ts_params->valid_devs[0],
13192                         ut_params->op), "failed to process sym crypto op");
13193
13194         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13195                         "crypto op processing failed");
13196
13197
13198         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13199                         uint8_t *, prepend_len);
13200         if (oop) {
13201                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13202                                 uint8_t *, prepend_len);
13203         }
13204
13205         if (fragsz_oop)
13206                 fragsz = fragsz_oop;
13207
13208         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13209                         ciphertext,
13210                         tdata->ciphertext.data,
13211                         fragsz,
13212                         "Ciphertext data not as expected");
13213
13214         buf = ut_params->op->sym->m_src->next;
13215         if (oop)
13216                 buf = ut_params->op->sym->m_dst->next;
13217
13218         unsigned int off = fragsz;
13219
13220         ecx = 0;
13221         while (buf) {
13222                 ciphertext = rte_pktmbuf_mtod(buf,
13223                                 uint8_t *);
13224
13225                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
13226                                 ciphertext,
13227                                 tdata->ciphertext.data + off,
13228                                 to_trn_tbl[ecx],
13229                                 "Ciphertext data not as expected");
13230
13231                 off += to_trn_tbl[ecx++];
13232                 buf = buf->next;
13233         }
13234
13235         auth_tag = digest_mem;
13236         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13237                         auth_tag,
13238                         tdata->auth_tag.data,
13239                         tdata->auth_tag.len,
13240                         "Generated auth tag not as expected");
13241
13242         return 0;
13243 }
13244
13245 static int
13246 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13247 {
13248         return test_authenticated_encryption_SGL(
13249                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13250 }
13251
13252 static int
13253 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13254 {
13255         return test_authenticated_encryption_SGL(
13256                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13257 }
13258
13259 static int
13260 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13261 {
13262         return test_authenticated_encryption_SGL(
13263                         &gcm_test_case_8, OUT_OF_PLACE, 400,
13264                         gcm_test_case_8.plaintext.len);
13265 }
13266
13267 static int
13268 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13269 {
13270         /* This test is not for OPENSSL PMD */
13271         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13272                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13273                 return TEST_SKIPPED;
13274
13275         return test_authenticated_encryption_SGL(
13276                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13277 }
13278
13279 static int
13280 test_authentication_verify_fail_when_data_corrupted(
13281                 struct crypto_testsuite_params *ts_params,
13282                 struct crypto_unittest_params *ut_params,
13283                 const struct test_crypto_vector *reference)
13284 {
13285         return test_authentication_verify_fail_when_data_corruption(
13286                         ts_params, ut_params, reference, 1);
13287 }
13288
13289 static int
13290 test_authentication_verify_fail_when_tag_corrupted(
13291                 struct crypto_testsuite_params *ts_params,
13292                 struct crypto_unittest_params *ut_params,
13293                 const struct test_crypto_vector *reference)
13294 {
13295         return test_authentication_verify_fail_when_data_corruption(
13296                         ts_params, ut_params, reference, 0);
13297 }
13298
13299 static int
13300 test_authentication_verify_GMAC_fail_when_data_corrupted(
13301                 struct crypto_testsuite_params *ts_params,
13302                 struct crypto_unittest_params *ut_params,
13303                 const struct test_crypto_vector *reference)
13304 {
13305         return test_authentication_verify_GMAC_fail_when_corruption(
13306                         ts_params, ut_params, reference, 1);
13307 }
13308
13309 static int
13310 test_authentication_verify_GMAC_fail_when_tag_corrupted(
13311                 struct crypto_testsuite_params *ts_params,
13312                 struct crypto_unittest_params *ut_params,
13313                 const struct test_crypto_vector *reference)
13314 {
13315         return test_authentication_verify_GMAC_fail_when_corruption(
13316                         ts_params, ut_params, reference, 0);
13317 }
13318
13319 static int
13320 test_authenticated_decryption_fail_when_data_corrupted(
13321                 struct crypto_testsuite_params *ts_params,
13322                 struct crypto_unittest_params *ut_params,
13323                 const struct test_crypto_vector *reference)
13324 {
13325         return test_authenticated_decryption_fail_when_corruption(
13326                         ts_params, ut_params, reference, 1);
13327 }
13328
13329 static int
13330 test_authenticated_decryption_fail_when_tag_corrupted(
13331                 struct crypto_testsuite_params *ts_params,
13332                 struct crypto_unittest_params *ut_params,
13333                 const struct test_crypto_vector *reference)
13334 {
13335         return test_authenticated_decryption_fail_when_corruption(
13336                         ts_params, ut_params, reference, 0);
13337 }
13338
13339 static int
13340 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
13341 {
13342         return test_authentication_verify_fail_when_data_corrupted(
13343                         &testsuite_params, &unittest_params,
13344                         &hmac_sha1_test_crypto_vector);
13345 }
13346
13347 static int
13348 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13349 {
13350         return test_authentication_verify_fail_when_tag_corrupted(
13351                         &testsuite_params, &unittest_params,
13352                         &hmac_sha1_test_crypto_vector);
13353 }
13354
13355 static int
13356 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
13357 {
13358         return test_authentication_verify_GMAC_fail_when_data_corrupted(
13359                         &testsuite_params, &unittest_params,
13360                         &aes128_gmac_test_vector);
13361 }
13362
13363 static int
13364 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
13365 {
13366         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
13367                         &testsuite_params, &unittest_params,
13368                         &aes128_gmac_test_vector);
13369 }
13370
13371 static int
13372 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
13373 {
13374         return test_authenticated_decryption_fail_when_data_corrupted(
13375                         &testsuite_params,
13376                         &unittest_params,
13377                         &aes128cbc_hmac_sha1_test_vector);
13378 }
13379
13380 static int
13381 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
13382 {
13383         return test_authenticated_decryption_fail_when_tag_corrupted(
13384                         &testsuite_params,
13385                         &unittest_params,
13386                         &aes128cbc_hmac_sha1_test_vector);
13387 }
13388
13389 static int
13390 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13391 {
13392         return test_authenticated_encrypt_with_esn(
13393                         &testsuite_params,
13394                         &unittest_params,
13395                         &aes128cbc_hmac_sha1_aad_test_vector);
13396 }
13397
13398 static int
13399 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13400 {
13401         return test_authenticated_decrypt_with_esn(
13402                         &testsuite_params,
13403                         &unittest_params,
13404                         &aes128cbc_hmac_sha1_aad_test_vector);
13405 }
13406
13407 static int
13408 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
13409 {
13410         return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
13411 }
13412
13413 static int
13414 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
13415 {
13416         return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
13417 }
13418
13419 #ifdef RTE_CRYPTO_SCHEDULER
13420
13421 /* global AESNI worker IDs for the scheduler test */
13422 uint8_t aesni_ids[2];
13423
13424 static int
13425 scheduler_testsuite_setup(void)
13426 {
13427         uint32_t i = 0;
13428         int32_t nb_devs, ret;
13429         char vdev_args[VDEV_ARGS_SIZE] = {""};
13430         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
13431                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
13432         uint16_t worker_core_count = 0;
13433         uint16_t socket_id = 0;
13434
13435         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13436                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
13437
13438                 /* Identify the Worker Cores
13439                  * Use 2 worker cores for the device args
13440                  */
13441                 RTE_LCORE_FOREACH_WORKER(i) {
13442                         if (worker_core_count > 1)
13443                                 break;
13444                         snprintf(vdev_args, sizeof(vdev_args),
13445                                         "%s%d", temp_str, i);
13446                         strcpy(temp_str, vdev_args);
13447                         strlcat(temp_str, ";", sizeof(temp_str));
13448                         worker_core_count++;
13449                         socket_id = rte_lcore_to_socket_id(i);
13450                 }
13451                 if (worker_core_count != 2) {
13452                         RTE_LOG(ERR, USER1,
13453                                 "Cryptodev scheduler test require at least "
13454                                 "two worker cores to run. "
13455                                 "Please use the correct coremask.\n");
13456                         return TEST_FAILED;
13457                 }
13458                 strcpy(temp_str, vdev_args);
13459                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
13460                                 temp_str, socket_id);
13461                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
13462                 nb_devs = rte_cryptodev_device_count_by_driver(
13463                                 rte_cryptodev_driver_id_get(
13464                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
13465                 if (nb_devs < 1) {
13466                         ret = rte_vdev_init(
13467                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
13468                                         vdev_args);
13469                         TEST_ASSERT(ret == 0,
13470                                 "Failed to create instance %u of pmd : %s",
13471                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13472                 }
13473         }
13474         return testsuite_setup();
13475 }
13476
13477 static int
13478 test_scheduler_attach_worker_op(void)
13479 {
13480         struct crypto_testsuite_params *ts_params = &testsuite_params;
13481         uint8_t sched_id = ts_params->valid_devs[0];
13482         uint32_t nb_devs, i, nb_devs_attached = 0;
13483         int ret;
13484         char vdev_name[32];
13485
13486         /* create 2 AESNI_MB if necessary */
13487         nb_devs = rte_cryptodev_device_count_by_driver(
13488                         rte_cryptodev_driver_id_get(
13489                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
13490         if (nb_devs < 2) {
13491                 for (i = nb_devs; i < 2; i++) {
13492                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
13493                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
13494                                         i);
13495                         ret = rte_vdev_init(vdev_name, NULL);
13496
13497                         TEST_ASSERT(ret == 0,
13498                                 "Failed to create instance %u of"
13499                                 " pmd : %s",
13500                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13501                 }
13502         }
13503
13504         /* attach 2 AESNI_MB cdevs */
13505         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
13506                         i++) {
13507                 struct rte_cryptodev_info info;
13508                 unsigned int session_size;
13509
13510                 rte_cryptodev_info_get(i, &info);
13511                 if (info.driver_id != rte_cryptodev_driver_id_get(
13512                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
13513                         continue;
13514
13515                 session_size = rte_cryptodev_sym_get_private_session_size(i);
13516                 /*
13517                  * Create the session mempool again, since now there are new devices
13518                  * to use the mempool.
13519                  */
13520                 if (ts_params->session_mpool) {
13521                         rte_mempool_free(ts_params->session_mpool);
13522                         ts_params->session_mpool = NULL;
13523                 }
13524                 if (ts_params->session_priv_mpool) {
13525                         rte_mempool_free(ts_params->session_priv_mpool);
13526                         ts_params->session_priv_mpool = NULL;
13527                 }
13528
13529                 if (info.sym.max_nb_sessions != 0 &&
13530                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
13531                         RTE_LOG(ERR, USER1,
13532                                         "Device does not support "
13533                                         "at least %u sessions\n",
13534                                         MAX_NB_SESSIONS);
13535                         return TEST_FAILED;
13536                 }
13537                 /*
13538                  * Create mempool with maximum number of sessions,
13539                  * to include the session headers
13540                  */
13541                 if (ts_params->session_mpool == NULL) {
13542                         ts_params->session_mpool =
13543                                 rte_cryptodev_sym_session_pool_create(
13544                                                 "test_sess_mp",
13545                                                 MAX_NB_SESSIONS, 0, 0, 0,
13546                                                 SOCKET_ID_ANY);
13547                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
13548                                         "session mempool allocation failed");
13549                 }
13550
13551                 /*
13552                  * Create mempool with maximum number of sessions,
13553                  * to include device specific session private data
13554                  */
13555                 if (ts_params->session_priv_mpool == NULL) {
13556                         ts_params->session_priv_mpool = rte_mempool_create(
13557                                         "test_sess_mp_priv",
13558                                         MAX_NB_SESSIONS,
13559                                         session_size,
13560                                         0, 0, NULL, NULL, NULL,
13561                                         NULL, SOCKET_ID_ANY,
13562                                         0);
13563
13564                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
13565                                         "session mempool allocation failed");
13566                 }
13567
13568                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
13569                 ts_params->qp_conf.mp_session_private =
13570                                 ts_params->session_priv_mpool;
13571
13572                 ret = rte_cryptodev_scheduler_worker_attach(sched_id,
13573                                 (uint8_t)i);
13574
13575                 TEST_ASSERT(ret == 0,
13576                         "Failed to attach device %u of pmd : %s", i,
13577                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13578
13579                 aesni_ids[nb_devs_attached] = (uint8_t)i;
13580
13581                 nb_devs_attached++;
13582         }
13583
13584         return 0;
13585 }
13586
13587 static int
13588 test_scheduler_detach_worker_op(void)
13589 {
13590         struct crypto_testsuite_params *ts_params = &testsuite_params;
13591         uint8_t sched_id = ts_params->valid_devs[0];
13592         uint32_t i;
13593         int ret;
13594
13595         for (i = 0; i < 2; i++) {
13596                 ret = rte_cryptodev_scheduler_worker_detach(sched_id,
13597                                 aesni_ids[i]);
13598                 TEST_ASSERT(ret == 0,
13599                         "Failed to detach device %u", aesni_ids[i]);
13600         }
13601
13602         return 0;
13603 }
13604
13605 static int
13606 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
13607 {
13608         struct crypto_testsuite_params *ts_params = &testsuite_params;
13609         uint8_t sched_id = ts_params->valid_devs[0];
13610         /* set mode */
13611         return rte_cryptodev_scheduler_mode_set(sched_id,
13612                 scheduler_mode);
13613 }
13614
13615 static int
13616 test_scheduler_mode_roundrobin_op(void)
13617 {
13618         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
13619                         0, "Failed to set roundrobin mode");
13620         return 0;
13621
13622 }
13623
13624 static int
13625 test_scheduler_mode_multicore_op(void)
13626 {
13627         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
13628                         0, "Failed to set multicore mode");
13629
13630         return 0;
13631 }
13632
13633 static int
13634 test_scheduler_mode_failover_op(void)
13635 {
13636         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
13637                         0, "Failed to set failover mode");
13638
13639         return 0;
13640 }
13641
13642 static int
13643 test_scheduler_mode_pkt_size_distr_op(void)
13644 {
13645         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
13646                         0, "Failed to set pktsize mode");
13647
13648         return 0;
13649 }
13650
13651 static int
13652 scheduler_multicore_testsuite_setup(void)
13653 {
13654         if (test_scheduler_attach_worker_op() < 0)
13655                 return TEST_SKIPPED;
13656         if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
13657                 return TEST_SKIPPED;
13658         return 0;
13659 }
13660
13661 static int
13662 scheduler_roundrobin_testsuite_setup(void)
13663 {
13664         if (test_scheduler_attach_worker_op() < 0)
13665                 return TEST_SKIPPED;
13666         if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
13667                 return TEST_SKIPPED;
13668         return 0;
13669 }
13670
13671 static int
13672 scheduler_failover_testsuite_setup(void)
13673 {
13674         if (test_scheduler_attach_worker_op() < 0)
13675                 return TEST_SKIPPED;
13676         if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
13677                 return TEST_SKIPPED;
13678         return 0;
13679 }
13680
13681 static int
13682 scheduler_pkt_size_distr_testsuite_setup(void)
13683 {
13684         if (test_scheduler_attach_worker_op() < 0)
13685                 return TEST_SKIPPED;
13686         if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
13687                 return TEST_SKIPPED;
13688         return 0;
13689 }
13690
13691 static void
13692 scheduler_mode_testsuite_teardown(void)
13693 {
13694         test_scheduler_detach_worker_op();
13695 }
13696
13697 #endif /* RTE_CRYPTO_SCHEDULER */
13698
13699 static struct unit_test_suite end_testsuite = {
13700         .suite_name = NULL,
13701         .setup = NULL,
13702         .teardown = NULL,
13703         .unit_test_suites = NULL
13704 };
13705
13706 #ifdef RTE_LIB_SECURITY
13707 static struct unit_test_suite pdcp_proto_testsuite  = {
13708         .suite_name = "PDCP Proto Unit Test Suite",
13709         .setup = pdcp_proto_testsuite_setup,
13710         .unit_test_cases = {
13711                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13712                         test_PDCP_PROTO_all),
13713                 TEST_CASES_END() /**< NULL terminate unit test array */
13714         }
13715 };
13716
13717 static struct unit_test_suite docsis_proto_testsuite  = {
13718         .suite_name = "Docsis Proto Unit Test Suite",
13719         .setup = docsis_proto_testsuite_setup,
13720         .unit_test_cases = {
13721                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13722                         test_DOCSIS_PROTO_all),
13723                 TEST_CASES_END() /**< NULL terminate unit test array */
13724         }
13725 };
13726 #endif
13727
13728 static struct unit_test_suite cryptodev_gen_testsuite  = {
13729         .suite_name = "Crypto General Unit Test Suite",
13730         .setup = crypto_gen_testsuite_setup,
13731         .unit_test_cases = {
13732                 TEST_CASE_ST(ut_setup, ut_teardown,
13733                                 test_device_configure_invalid_dev_id),
13734                 TEST_CASE_ST(ut_setup, ut_teardown,
13735                                 test_queue_pair_descriptor_setup),
13736                 TEST_CASE_ST(ut_setup, ut_teardown,
13737                                 test_device_configure_invalid_queue_pair_ids),
13738                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
13739                 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
13740                 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
13741                 TEST_CASES_END() /**< NULL terminate unit test array */
13742         }
13743 };
13744
13745 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
13746         .suite_name = "Negative HMAC SHA1 Unit Test Suite",
13747         .setup = negative_hmac_sha1_testsuite_setup,
13748         .unit_test_cases = {
13749                 /** Negative tests */
13750                 TEST_CASE_ST(ut_setup, ut_teardown,
13751                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13752                 TEST_CASE_ST(ut_setup, ut_teardown,
13753                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13754                 TEST_CASE_ST(ut_setup, ut_teardown,
13755                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13756                 TEST_CASE_ST(ut_setup, ut_teardown,
13757                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13758
13759                 TEST_CASES_END() /**< NULL terminate unit test array */
13760         }
13761 };
13762
13763 static struct unit_test_suite cryptodev_multi_session_testsuite = {
13764         .suite_name = "Multi Session Unit Test Suite",
13765         .setup = multi_session_testsuite_setup,
13766         .unit_test_cases = {
13767                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13768                 TEST_CASE_ST(ut_setup, ut_teardown,
13769                                 test_multi_session_random_usage),
13770
13771                 TEST_CASES_END() /**< NULL terminate unit test array */
13772         }
13773 };
13774
13775 static struct unit_test_suite cryptodev_null_testsuite  = {
13776         .suite_name = "NULL Test Suite",
13777         .setup = null_testsuite_setup,
13778         .unit_test_cases = {
13779                 TEST_CASE_ST(ut_setup, ut_teardown,
13780                         test_null_invalid_operation),
13781                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
13782                 TEST_CASES_END()
13783         }
13784 };
13785
13786 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
13787         .suite_name = "AES CCM Authenticated Test Suite",
13788         .setup = aes_ccm_auth_testsuite_setup,
13789         .unit_test_cases = {
13790                 /** AES CCM Authenticated Encryption 128 bits key*/
13791                 TEST_CASE_ST(ut_setup, ut_teardown,
13792                         test_AES_CCM_authenticated_encryption_test_case_128_1),
13793                 TEST_CASE_ST(ut_setup, ut_teardown,
13794                         test_AES_CCM_authenticated_encryption_test_case_128_2),
13795                 TEST_CASE_ST(ut_setup, ut_teardown,
13796                         test_AES_CCM_authenticated_encryption_test_case_128_3),
13797
13798                 /** AES CCM Authenticated Decryption 128 bits key*/
13799                 TEST_CASE_ST(ut_setup, ut_teardown,
13800                         test_AES_CCM_authenticated_decryption_test_case_128_1),
13801                 TEST_CASE_ST(ut_setup, ut_teardown,
13802                         test_AES_CCM_authenticated_decryption_test_case_128_2),
13803                 TEST_CASE_ST(ut_setup, ut_teardown,
13804                         test_AES_CCM_authenticated_decryption_test_case_128_3),
13805
13806                 /** AES CCM Authenticated Encryption 192 bits key */
13807                 TEST_CASE_ST(ut_setup, ut_teardown,
13808                         test_AES_CCM_authenticated_encryption_test_case_192_1),
13809                 TEST_CASE_ST(ut_setup, ut_teardown,
13810                         test_AES_CCM_authenticated_encryption_test_case_192_2),
13811                 TEST_CASE_ST(ut_setup, ut_teardown,
13812                         test_AES_CCM_authenticated_encryption_test_case_192_3),
13813
13814                 /** AES CCM Authenticated Decryption 192 bits key*/
13815                 TEST_CASE_ST(ut_setup, ut_teardown,
13816                         test_AES_CCM_authenticated_decryption_test_case_192_1),
13817                 TEST_CASE_ST(ut_setup, ut_teardown,
13818                         test_AES_CCM_authenticated_decryption_test_case_192_2),
13819                 TEST_CASE_ST(ut_setup, ut_teardown,
13820                         test_AES_CCM_authenticated_decryption_test_case_192_3),
13821
13822                 /** AES CCM Authenticated Encryption 256 bits key */
13823                 TEST_CASE_ST(ut_setup, ut_teardown,
13824                         test_AES_CCM_authenticated_encryption_test_case_256_1),
13825                 TEST_CASE_ST(ut_setup, ut_teardown,
13826                         test_AES_CCM_authenticated_encryption_test_case_256_2),
13827                 TEST_CASE_ST(ut_setup, ut_teardown,
13828                         test_AES_CCM_authenticated_encryption_test_case_256_3),
13829
13830                 /** AES CCM Authenticated Decryption 256 bits key*/
13831                 TEST_CASE_ST(ut_setup, ut_teardown,
13832                         test_AES_CCM_authenticated_decryption_test_case_256_1),
13833                 TEST_CASE_ST(ut_setup, ut_teardown,
13834                         test_AES_CCM_authenticated_decryption_test_case_256_2),
13835                 TEST_CASE_ST(ut_setup, ut_teardown,
13836                         test_AES_CCM_authenticated_decryption_test_case_256_3),
13837                 TEST_CASES_END()
13838         }
13839 };
13840
13841 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
13842         .suite_name = "AES GCM Authenticated Test Suite",
13843         .setup = aes_gcm_auth_testsuite_setup,
13844         .unit_test_cases = {
13845                 /** AES GCM Authenticated Encryption */
13846                 TEST_CASE_ST(ut_setup, ut_teardown,
13847                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
13848                 TEST_CASE_ST(ut_setup, ut_teardown,
13849                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
13850                 TEST_CASE_ST(ut_setup, ut_teardown,
13851                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
13852                 TEST_CASE_ST(ut_setup, ut_teardown,
13853                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
13854                 TEST_CASE_ST(ut_setup, ut_teardown,
13855                         test_AES_GCM_authenticated_encryption_test_case_1),
13856                 TEST_CASE_ST(ut_setup, ut_teardown,
13857                         test_AES_GCM_authenticated_encryption_test_case_2),
13858                 TEST_CASE_ST(ut_setup, ut_teardown,
13859                         test_AES_GCM_authenticated_encryption_test_case_3),
13860                 TEST_CASE_ST(ut_setup, ut_teardown,
13861                         test_AES_GCM_authenticated_encryption_test_case_4),
13862                 TEST_CASE_ST(ut_setup, ut_teardown,
13863                         test_AES_GCM_authenticated_encryption_test_case_5),
13864                 TEST_CASE_ST(ut_setup, ut_teardown,
13865                         test_AES_GCM_authenticated_encryption_test_case_6),
13866                 TEST_CASE_ST(ut_setup, ut_teardown,
13867                         test_AES_GCM_authenticated_encryption_test_case_7),
13868                 TEST_CASE_ST(ut_setup, ut_teardown,
13869                         test_AES_GCM_authenticated_encryption_test_case_8),
13870                 TEST_CASE_ST(ut_setup, ut_teardown,
13871                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
13872
13873                 /** AES GCM Authenticated Decryption */
13874                 TEST_CASE_ST(ut_setup, ut_teardown,
13875                         test_AES_GCM_authenticated_decryption_test_case_1),
13876                 TEST_CASE_ST(ut_setup, ut_teardown,
13877                         test_AES_GCM_authenticated_decryption_test_case_2),
13878                 TEST_CASE_ST(ut_setup, ut_teardown,
13879                         test_AES_GCM_authenticated_decryption_test_case_3),
13880                 TEST_CASE_ST(ut_setup, ut_teardown,
13881                         test_AES_GCM_authenticated_decryption_test_case_4),
13882                 TEST_CASE_ST(ut_setup, ut_teardown,
13883                         test_AES_GCM_authenticated_decryption_test_case_5),
13884                 TEST_CASE_ST(ut_setup, ut_teardown,
13885                         test_AES_GCM_authenticated_decryption_test_case_6),
13886                 TEST_CASE_ST(ut_setup, ut_teardown,
13887                         test_AES_GCM_authenticated_decryption_test_case_7),
13888                 TEST_CASE_ST(ut_setup, ut_teardown,
13889                         test_AES_GCM_authenticated_decryption_test_case_8),
13890                 TEST_CASE_ST(ut_setup, ut_teardown,
13891                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
13892
13893                 /** AES GCM Authenticated Encryption 192 bits key */
13894                 TEST_CASE_ST(ut_setup, ut_teardown,
13895                         test_AES_GCM_auth_encryption_test_case_192_1),
13896                 TEST_CASE_ST(ut_setup, ut_teardown,
13897                         test_AES_GCM_auth_encryption_test_case_192_2),
13898                 TEST_CASE_ST(ut_setup, ut_teardown,
13899                         test_AES_GCM_auth_encryption_test_case_192_3),
13900                 TEST_CASE_ST(ut_setup, ut_teardown,
13901                         test_AES_GCM_auth_encryption_test_case_192_4),
13902                 TEST_CASE_ST(ut_setup, ut_teardown,
13903                         test_AES_GCM_auth_encryption_test_case_192_5),
13904                 TEST_CASE_ST(ut_setup, ut_teardown,
13905                         test_AES_GCM_auth_encryption_test_case_192_6),
13906                 TEST_CASE_ST(ut_setup, ut_teardown,
13907                         test_AES_GCM_auth_encryption_test_case_192_7),
13908
13909                 /** AES GCM Authenticated Decryption 192 bits key */
13910                 TEST_CASE_ST(ut_setup, ut_teardown,
13911                         test_AES_GCM_auth_decryption_test_case_192_1),
13912                 TEST_CASE_ST(ut_setup, ut_teardown,
13913                         test_AES_GCM_auth_decryption_test_case_192_2),
13914                 TEST_CASE_ST(ut_setup, ut_teardown,
13915                         test_AES_GCM_auth_decryption_test_case_192_3),
13916                 TEST_CASE_ST(ut_setup, ut_teardown,
13917                         test_AES_GCM_auth_decryption_test_case_192_4),
13918                 TEST_CASE_ST(ut_setup, ut_teardown,
13919                         test_AES_GCM_auth_decryption_test_case_192_5),
13920                 TEST_CASE_ST(ut_setup, ut_teardown,
13921                         test_AES_GCM_auth_decryption_test_case_192_6),
13922                 TEST_CASE_ST(ut_setup, ut_teardown,
13923                         test_AES_GCM_auth_decryption_test_case_192_7),
13924
13925                 /** AES GCM Authenticated Encryption 256 bits key */
13926                 TEST_CASE_ST(ut_setup, ut_teardown,
13927                         test_AES_GCM_auth_encryption_test_case_256_1),
13928                 TEST_CASE_ST(ut_setup, ut_teardown,
13929                         test_AES_GCM_auth_encryption_test_case_256_2),
13930                 TEST_CASE_ST(ut_setup, ut_teardown,
13931                         test_AES_GCM_auth_encryption_test_case_256_3),
13932                 TEST_CASE_ST(ut_setup, ut_teardown,
13933                         test_AES_GCM_auth_encryption_test_case_256_4),
13934                 TEST_CASE_ST(ut_setup, ut_teardown,
13935                         test_AES_GCM_auth_encryption_test_case_256_5),
13936                 TEST_CASE_ST(ut_setup, ut_teardown,
13937                         test_AES_GCM_auth_encryption_test_case_256_6),
13938                 TEST_CASE_ST(ut_setup, ut_teardown,
13939                         test_AES_GCM_auth_encryption_test_case_256_7),
13940
13941                 /** AES GCM Authenticated Decryption 256 bits key */
13942                 TEST_CASE_ST(ut_setup, ut_teardown,
13943                         test_AES_GCM_auth_decryption_test_case_256_1),
13944                 TEST_CASE_ST(ut_setup, ut_teardown,
13945                         test_AES_GCM_auth_decryption_test_case_256_2),
13946                 TEST_CASE_ST(ut_setup, ut_teardown,
13947                         test_AES_GCM_auth_decryption_test_case_256_3),
13948                 TEST_CASE_ST(ut_setup, ut_teardown,
13949                         test_AES_GCM_auth_decryption_test_case_256_4),
13950                 TEST_CASE_ST(ut_setup, ut_teardown,
13951                         test_AES_GCM_auth_decryption_test_case_256_5),
13952                 TEST_CASE_ST(ut_setup, ut_teardown,
13953                         test_AES_GCM_auth_decryption_test_case_256_6),
13954                 TEST_CASE_ST(ut_setup, ut_teardown,
13955                         test_AES_GCM_auth_decryption_test_case_256_7),
13956
13957                 /** AES GCM Authenticated Encryption big aad size */
13958                 TEST_CASE_ST(ut_setup, ut_teardown,
13959                         test_AES_GCM_auth_encryption_test_case_aad_1),
13960                 TEST_CASE_ST(ut_setup, ut_teardown,
13961                         test_AES_GCM_auth_encryption_test_case_aad_2),
13962
13963                 /** AES GCM Authenticated Decryption big aad size */
13964                 TEST_CASE_ST(ut_setup, ut_teardown,
13965                         test_AES_GCM_auth_decryption_test_case_aad_1),
13966                 TEST_CASE_ST(ut_setup, ut_teardown,
13967                         test_AES_GCM_auth_decryption_test_case_aad_2),
13968
13969                 /** Out of place tests */
13970                 TEST_CASE_ST(ut_setup, ut_teardown,
13971                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
13972                 TEST_CASE_ST(ut_setup, ut_teardown,
13973                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
13974
13975                 /** Session-less tests */
13976                 TEST_CASE_ST(ut_setup, ut_teardown,
13977                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
13978                 TEST_CASE_ST(ut_setup, ut_teardown,
13979                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
13980
13981                 TEST_CASES_END()
13982         }
13983 };
13984
13985 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
13986         .suite_name = "AES GMAC Authentication Test Suite",
13987         .setup = aes_gmac_auth_testsuite_setup,
13988         .unit_test_cases = {
13989                 TEST_CASE_ST(ut_setup, ut_teardown,
13990                         test_AES_GMAC_authentication_test_case_1),
13991                 TEST_CASE_ST(ut_setup, ut_teardown,
13992                         test_AES_GMAC_authentication_verify_test_case_1),
13993                 TEST_CASE_ST(ut_setup, ut_teardown,
13994                         test_AES_GMAC_authentication_test_case_2),
13995                 TEST_CASE_ST(ut_setup, ut_teardown,
13996                         test_AES_GMAC_authentication_verify_test_case_2),
13997                 TEST_CASE_ST(ut_setup, ut_teardown,
13998                         test_AES_GMAC_authentication_test_case_3),
13999                 TEST_CASE_ST(ut_setup, ut_teardown,
14000                         test_AES_GMAC_authentication_verify_test_case_3),
14001                 TEST_CASE_ST(ut_setup, ut_teardown,
14002                         test_AES_GMAC_authentication_test_case_4),
14003                 TEST_CASE_ST(ut_setup, ut_teardown,
14004                         test_AES_GMAC_authentication_verify_test_case_4),
14005                 TEST_CASE_ST(ut_setup, ut_teardown,
14006                         test_AES_GMAC_authentication_SGL_40B),
14007                 TEST_CASE_ST(ut_setup, ut_teardown,
14008                         test_AES_GMAC_authentication_SGL_80B),
14009                 TEST_CASE_ST(ut_setup, ut_teardown,
14010                         test_AES_GMAC_authentication_SGL_2048B),
14011                 TEST_CASE_ST(ut_setup, ut_teardown,
14012                         test_AES_GMAC_authentication_SGL_2047B),
14013
14014                 TEST_CASES_END()
14015         }
14016 };
14017
14018 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14019         .suite_name = "Chacha20-Poly1305 Test Suite",
14020         .setup = chacha20_poly1305_testsuite_setup,
14021         .unit_test_cases = {
14022                 TEST_CASE_ST(ut_setup, ut_teardown,
14023                         test_chacha20_poly1305_encrypt_test_case_rfc8439),
14024                 TEST_CASE_ST(ut_setup, ut_teardown,
14025                         test_chacha20_poly1305_decrypt_test_case_rfc8439),
14026                 TEST_CASES_END()
14027         }
14028 };
14029
14030 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14031         .suite_name = "SNOW 3G Test Suite",
14032         .setup = snow3g_testsuite_setup,
14033         .unit_test_cases = {
14034                 /** SNOW 3G encrypt only (UEA2) */
14035                 TEST_CASE_ST(ut_setup, ut_teardown,
14036                         test_snow3g_encryption_test_case_1),
14037                 TEST_CASE_ST(ut_setup, ut_teardown,
14038                         test_snow3g_encryption_test_case_2),
14039                 TEST_CASE_ST(ut_setup, ut_teardown,
14040                         test_snow3g_encryption_test_case_3),
14041                 TEST_CASE_ST(ut_setup, ut_teardown,
14042                         test_snow3g_encryption_test_case_4),
14043                 TEST_CASE_ST(ut_setup, ut_teardown,
14044                         test_snow3g_encryption_test_case_5),
14045
14046                 TEST_CASE_ST(ut_setup, ut_teardown,
14047                         test_snow3g_encryption_test_case_1_oop),
14048                 TEST_CASE_ST(ut_setup, ut_teardown,
14049                         test_snow3g_encryption_test_case_1_oop_sgl),
14050                 TEST_CASE_ST(ut_setup, ut_teardown,
14051                         test_snow3g_encryption_test_case_1_offset_oop),
14052                 TEST_CASE_ST(ut_setup, ut_teardown,
14053                         test_snow3g_decryption_test_case_1_oop),
14054
14055                 /** SNOW 3G generate auth, then encrypt (UEA2) */
14056                 TEST_CASE_ST(ut_setup, ut_teardown,
14057                         test_snow3g_auth_cipher_test_case_1),
14058                 TEST_CASE_ST(ut_setup, ut_teardown,
14059                         test_snow3g_auth_cipher_test_case_2),
14060                 TEST_CASE_ST(ut_setup, ut_teardown,
14061                         test_snow3g_auth_cipher_test_case_2_oop),
14062                 TEST_CASE_ST(ut_setup, ut_teardown,
14063                         test_snow3g_auth_cipher_part_digest_enc),
14064                 TEST_CASE_ST(ut_setup, ut_teardown,
14065                         test_snow3g_auth_cipher_part_digest_enc_oop),
14066                 TEST_CASE_ST(ut_setup, ut_teardown,
14067                         test_snow3g_auth_cipher_test_case_3_sgl),
14068                 TEST_CASE_ST(ut_setup, ut_teardown,
14069                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
14070                 TEST_CASE_ST(ut_setup, ut_teardown,
14071                         test_snow3g_auth_cipher_part_digest_enc_sgl),
14072                 TEST_CASE_ST(ut_setup, ut_teardown,
14073                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14074
14075                 /** SNOW 3G decrypt (UEA2), then verify auth */
14076                 TEST_CASE_ST(ut_setup, ut_teardown,
14077                         test_snow3g_auth_cipher_verify_test_case_1),
14078                 TEST_CASE_ST(ut_setup, ut_teardown,
14079                         test_snow3g_auth_cipher_verify_test_case_2),
14080                 TEST_CASE_ST(ut_setup, ut_teardown,
14081                         test_snow3g_auth_cipher_verify_test_case_2_oop),
14082                 TEST_CASE_ST(ut_setup, ut_teardown,
14083                         test_snow3g_auth_cipher_verify_part_digest_enc),
14084                 TEST_CASE_ST(ut_setup, ut_teardown,
14085                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14086                 TEST_CASE_ST(ut_setup, ut_teardown,
14087                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
14088                 TEST_CASE_ST(ut_setup, ut_teardown,
14089                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14090                 TEST_CASE_ST(ut_setup, ut_teardown,
14091                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14092                 TEST_CASE_ST(ut_setup, ut_teardown,
14093                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14094
14095                 /** SNOW 3G decrypt only (UEA2) */
14096                 TEST_CASE_ST(ut_setup, ut_teardown,
14097                         test_snow3g_decryption_test_case_1),
14098                 TEST_CASE_ST(ut_setup, ut_teardown,
14099                         test_snow3g_decryption_test_case_2),
14100                 TEST_CASE_ST(ut_setup, ut_teardown,
14101                         test_snow3g_decryption_test_case_3),
14102                 TEST_CASE_ST(ut_setup, ut_teardown,
14103                         test_snow3g_decryption_test_case_4),
14104                 TEST_CASE_ST(ut_setup, ut_teardown,
14105                         test_snow3g_decryption_test_case_5),
14106                 TEST_CASE_ST(ut_setup, ut_teardown,
14107                         test_snow3g_decryption_with_digest_test_case_1),
14108                 TEST_CASE_ST(ut_setup, ut_teardown,
14109                         test_snow3g_hash_generate_test_case_1),
14110                 TEST_CASE_ST(ut_setup, ut_teardown,
14111                         test_snow3g_hash_generate_test_case_2),
14112                 TEST_CASE_ST(ut_setup, ut_teardown,
14113                         test_snow3g_hash_generate_test_case_3),
14114
14115                 /* Tests with buffers which length is not byte-aligned */
14116                 TEST_CASE_ST(ut_setup, ut_teardown,
14117                         test_snow3g_hash_generate_test_case_4),
14118                 TEST_CASE_ST(ut_setup, ut_teardown,
14119                         test_snow3g_hash_generate_test_case_5),
14120                 TEST_CASE_ST(ut_setup, ut_teardown,
14121                         test_snow3g_hash_generate_test_case_6),
14122                 TEST_CASE_ST(ut_setup, ut_teardown,
14123                         test_snow3g_hash_verify_test_case_1),
14124                 TEST_CASE_ST(ut_setup, ut_teardown,
14125                         test_snow3g_hash_verify_test_case_2),
14126                 TEST_CASE_ST(ut_setup, ut_teardown,
14127                         test_snow3g_hash_verify_test_case_3),
14128
14129                 /* Tests with buffers which length is not byte-aligned */
14130                 TEST_CASE_ST(ut_setup, ut_teardown,
14131                         test_snow3g_hash_verify_test_case_4),
14132                 TEST_CASE_ST(ut_setup, ut_teardown,
14133                         test_snow3g_hash_verify_test_case_5),
14134                 TEST_CASE_ST(ut_setup, ut_teardown,
14135                         test_snow3g_hash_verify_test_case_6),
14136                 TEST_CASE_ST(ut_setup, ut_teardown,
14137                         test_snow3g_cipher_auth_test_case_1),
14138                 TEST_CASE_ST(ut_setup, ut_teardown,
14139                         test_snow3g_auth_cipher_with_digest_test_case_1),
14140                 TEST_CASES_END()
14141         }
14142 };
14143
14144 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14145         .suite_name = "ZUC Test Suite",
14146         .setup = zuc_testsuite_setup,
14147         .unit_test_cases = {
14148                 /** ZUC encrypt only (EEA3) */
14149                 TEST_CASE_ST(ut_setup, ut_teardown,
14150                         test_zuc_encryption_test_case_1),
14151                 TEST_CASE_ST(ut_setup, ut_teardown,
14152                         test_zuc_encryption_test_case_2),
14153                 TEST_CASE_ST(ut_setup, ut_teardown,
14154                         test_zuc_encryption_test_case_3),
14155                 TEST_CASE_ST(ut_setup, ut_teardown,
14156                         test_zuc_encryption_test_case_4),
14157                 TEST_CASE_ST(ut_setup, ut_teardown,
14158                         test_zuc_encryption_test_case_5),
14159                 TEST_CASE_ST(ut_setup, ut_teardown,
14160                         test_zuc_encryption_test_case_6_sgl),
14161
14162                 /** ZUC authenticate (EIA3) */
14163                 TEST_CASE_ST(ut_setup, ut_teardown,
14164                         test_zuc_hash_generate_test_case_1),
14165                 TEST_CASE_ST(ut_setup, ut_teardown,
14166                         test_zuc_hash_generate_test_case_2),
14167                 TEST_CASE_ST(ut_setup, ut_teardown,
14168                         test_zuc_hash_generate_test_case_3),
14169                 TEST_CASE_ST(ut_setup, ut_teardown,
14170                         test_zuc_hash_generate_test_case_4),
14171                 TEST_CASE_ST(ut_setup, ut_teardown,
14172                         test_zuc_hash_generate_test_case_5),
14173                 TEST_CASE_ST(ut_setup, ut_teardown,
14174                         test_zuc_hash_generate_test_case_6),
14175                 TEST_CASE_ST(ut_setup, ut_teardown,
14176                         test_zuc_hash_generate_test_case_7),
14177                 TEST_CASE_ST(ut_setup, ut_teardown,
14178                         test_zuc_hash_generate_test_case_8),
14179
14180                 /** ZUC alg-chain (EEA3/EIA3) */
14181                 TEST_CASE_ST(ut_setup, ut_teardown,
14182                         test_zuc_cipher_auth_test_case_1),
14183                 TEST_CASE_ST(ut_setup, ut_teardown,
14184                         test_zuc_cipher_auth_test_case_2),
14185
14186                 /** ZUC generate auth, then encrypt (EEA3) */
14187                 TEST_CASE_ST(ut_setup, ut_teardown,
14188                         test_zuc_auth_cipher_test_case_1),
14189                 TEST_CASE_ST(ut_setup, ut_teardown,
14190                         test_zuc_auth_cipher_test_case_1_oop),
14191                 TEST_CASE_ST(ut_setup, ut_teardown,
14192                         test_zuc_auth_cipher_test_case_1_sgl),
14193                 TEST_CASE_ST(ut_setup, ut_teardown,
14194                         test_zuc_auth_cipher_test_case_1_oop_sgl),
14195
14196                 /** ZUC decrypt (EEA3), then verify auth */
14197                 TEST_CASE_ST(ut_setup, ut_teardown,
14198                         test_zuc_auth_cipher_verify_test_case_1),
14199                 TEST_CASE_ST(ut_setup, ut_teardown,
14200                         test_zuc_auth_cipher_verify_test_case_1_oop),
14201                 TEST_CASE_ST(ut_setup, ut_teardown,
14202                         test_zuc_auth_cipher_verify_test_case_1_sgl),
14203                 TEST_CASE_ST(ut_setup, ut_teardown,
14204                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
14205                 TEST_CASES_END()
14206         }
14207 };
14208
14209 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
14210         .suite_name = "HMAC_MD5 Authentication Test Suite",
14211         .setup = hmac_md5_auth_testsuite_setup,
14212         .unit_test_cases = {
14213                 TEST_CASE_ST(ut_setup, ut_teardown,
14214                         test_MD5_HMAC_generate_case_1),
14215                 TEST_CASE_ST(ut_setup, ut_teardown,
14216                         test_MD5_HMAC_verify_case_1),
14217                 TEST_CASE_ST(ut_setup, ut_teardown,
14218                         test_MD5_HMAC_generate_case_2),
14219                 TEST_CASE_ST(ut_setup, ut_teardown,
14220                         test_MD5_HMAC_verify_case_2),
14221                 TEST_CASES_END()
14222         }
14223 };
14224
14225 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
14226         .suite_name = "Kasumi Test Suite",
14227         .setup = kasumi_testsuite_setup,
14228         .unit_test_cases = {
14229                 /** KASUMI hash only (UIA1) */
14230                 TEST_CASE_ST(ut_setup, ut_teardown,
14231                         test_kasumi_hash_generate_test_case_1),
14232                 TEST_CASE_ST(ut_setup, ut_teardown,
14233                         test_kasumi_hash_generate_test_case_2),
14234                 TEST_CASE_ST(ut_setup, ut_teardown,
14235                         test_kasumi_hash_generate_test_case_3),
14236                 TEST_CASE_ST(ut_setup, ut_teardown,
14237                         test_kasumi_hash_generate_test_case_4),
14238                 TEST_CASE_ST(ut_setup, ut_teardown,
14239                         test_kasumi_hash_generate_test_case_5),
14240                 TEST_CASE_ST(ut_setup, ut_teardown,
14241                         test_kasumi_hash_generate_test_case_6),
14242
14243                 TEST_CASE_ST(ut_setup, ut_teardown,
14244                         test_kasumi_hash_verify_test_case_1),
14245                 TEST_CASE_ST(ut_setup, ut_teardown,
14246                         test_kasumi_hash_verify_test_case_2),
14247                 TEST_CASE_ST(ut_setup, ut_teardown,
14248                         test_kasumi_hash_verify_test_case_3),
14249                 TEST_CASE_ST(ut_setup, ut_teardown,
14250                         test_kasumi_hash_verify_test_case_4),
14251                 TEST_CASE_ST(ut_setup, ut_teardown,
14252                         test_kasumi_hash_verify_test_case_5),
14253
14254                 /** KASUMI encrypt only (UEA1) */
14255                 TEST_CASE_ST(ut_setup, ut_teardown,
14256                         test_kasumi_encryption_test_case_1),
14257                 TEST_CASE_ST(ut_setup, ut_teardown,
14258                         test_kasumi_encryption_test_case_1_sgl),
14259                 TEST_CASE_ST(ut_setup, ut_teardown,
14260                         test_kasumi_encryption_test_case_1_oop),
14261                 TEST_CASE_ST(ut_setup, ut_teardown,
14262                         test_kasumi_encryption_test_case_1_oop_sgl),
14263                 TEST_CASE_ST(ut_setup, ut_teardown,
14264                         test_kasumi_encryption_test_case_2),
14265                 TEST_CASE_ST(ut_setup, ut_teardown,
14266                         test_kasumi_encryption_test_case_3),
14267                 TEST_CASE_ST(ut_setup, ut_teardown,
14268                         test_kasumi_encryption_test_case_4),
14269                 TEST_CASE_ST(ut_setup, ut_teardown,
14270                         test_kasumi_encryption_test_case_5),
14271
14272                 /** KASUMI decrypt only (UEA1) */
14273                 TEST_CASE_ST(ut_setup, ut_teardown,
14274                         test_kasumi_decryption_test_case_1),
14275                 TEST_CASE_ST(ut_setup, ut_teardown,
14276                         test_kasumi_decryption_test_case_2),
14277                 TEST_CASE_ST(ut_setup, ut_teardown,
14278                         test_kasumi_decryption_test_case_3),
14279                 TEST_CASE_ST(ut_setup, ut_teardown,
14280                         test_kasumi_decryption_test_case_4),
14281                 TEST_CASE_ST(ut_setup, ut_teardown,
14282                         test_kasumi_decryption_test_case_5),
14283                 TEST_CASE_ST(ut_setup, ut_teardown,
14284                         test_kasumi_decryption_test_case_1_oop),
14285
14286                 TEST_CASE_ST(ut_setup, ut_teardown,
14287                         test_kasumi_cipher_auth_test_case_1),
14288
14289                 /** KASUMI generate auth, then encrypt (F8) */
14290                 TEST_CASE_ST(ut_setup, ut_teardown,
14291                         test_kasumi_auth_cipher_test_case_1),
14292                 TEST_CASE_ST(ut_setup, ut_teardown,
14293                         test_kasumi_auth_cipher_test_case_2),
14294                 TEST_CASE_ST(ut_setup, ut_teardown,
14295                         test_kasumi_auth_cipher_test_case_2_oop),
14296                 TEST_CASE_ST(ut_setup, ut_teardown,
14297                         test_kasumi_auth_cipher_test_case_2_sgl),
14298                 TEST_CASE_ST(ut_setup, ut_teardown,
14299                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
14300
14301                 /** KASUMI decrypt (F8), then verify auth */
14302                 TEST_CASE_ST(ut_setup, ut_teardown,
14303                         test_kasumi_auth_cipher_verify_test_case_1),
14304                 TEST_CASE_ST(ut_setup, ut_teardown,
14305                         test_kasumi_auth_cipher_verify_test_case_2),
14306                 TEST_CASE_ST(ut_setup, ut_teardown,
14307                         test_kasumi_auth_cipher_verify_test_case_2_oop),
14308                 TEST_CASE_ST(ut_setup, ut_teardown,
14309                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
14310                 TEST_CASE_ST(ut_setup, ut_teardown,
14311                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
14312
14313                 TEST_CASES_END()
14314         }
14315 };
14316
14317 static struct unit_test_suite cryptodev_esn_testsuite  = {
14318         .suite_name = "ESN Test Suite",
14319         .setup = esn_testsuite_setup,
14320         .unit_test_cases = {
14321                 TEST_CASE_ST(ut_setup, ut_teardown,
14322                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
14323                 TEST_CASE_ST(ut_setup, ut_teardown,
14324                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
14325                 TEST_CASES_END()
14326         }
14327 };
14328
14329 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
14330         .suite_name = "Negative AES GCM Test Suite",
14331         .setup = negative_aes_gcm_testsuite_setup,
14332         .unit_test_cases = {
14333                 TEST_CASE_ST(ut_setup, ut_teardown,
14334                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
14335                 TEST_CASE_ST(ut_setup, ut_teardown,
14336                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
14337                 TEST_CASE_ST(ut_setup, ut_teardown,
14338                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
14339                 TEST_CASE_ST(ut_setup, ut_teardown,
14340                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
14341                 TEST_CASE_ST(ut_setup, ut_teardown,
14342                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
14343                 TEST_CASE_ST(ut_setup, ut_teardown,
14344                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
14345                 TEST_CASE_ST(ut_setup, ut_teardown,
14346                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
14347                 TEST_CASE_ST(ut_setup, ut_teardown,
14348                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
14349                 TEST_CASE_ST(ut_setup, ut_teardown,
14350                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
14351                 TEST_CASE_ST(ut_setup, ut_teardown,
14352                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
14353                 TEST_CASE_ST(ut_setup, ut_teardown,
14354                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
14355                 TEST_CASE_ST(ut_setup, ut_teardown,
14356                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
14357
14358                 TEST_CASES_END()
14359         }
14360 };
14361
14362 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
14363         .suite_name = "Negative AES GMAC Test Suite",
14364         .setup = negative_aes_gmac_testsuite_setup,
14365         .unit_test_cases = {
14366                 TEST_CASE_ST(ut_setup, ut_teardown,
14367                         authentication_verify_AES128_GMAC_fail_data_corrupt),
14368                 TEST_CASE_ST(ut_setup, ut_teardown,
14369                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
14370
14371                 TEST_CASES_END()
14372         }
14373 };
14374
14375 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
14376         .suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
14377         .setup = mixed_cipher_hash_testsuite_setup,
14378         .unit_test_cases = {
14379                 /** AUTH AES CMAC + CIPHER AES CTR */
14380                 TEST_CASE_ST(ut_setup, ut_teardown,
14381                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
14382                 TEST_CASE_ST(ut_setup, ut_teardown,
14383                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14384                 TEST_CASE_ST(ut_setup, ut_teardown,
14385                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14386                 TEST_CASE_ST(ut_setup, ut_teardown,
14387                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14388                 TEST_CASE_ST(ut_setup, ut_teardown,
14389                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
14390                 TEST_CASE_ST(ut_setup, ut_teardown,
14391                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14392                 TEST_CASE_ST(ut_setup, ut_teardown,
14393                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14394                 TEST_CASE_ST(ut_setup, ut_teardown,
14395                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14396
14397                 /** AUTH ZUC + CIPHER SNOW3G */
14398                 TEST_CASE_ST(ut_setup, ut_teardown,
14399                         test_auth_zuc_cipher_snow_test_case_1),
14400                 TEST_CASE_ST(ut_setup, ut_teardown,
14401                         test_verify_auth_zuc_cipher_snow_test_case_1),
14402                 /** AUTH AES CMAC + CIPHER SNOW3G */
14403                 TEST_CASE_ST(ut_setup, ut_teardown,
14404                         test_auth_aes_cmac_cipher_snow_test_case_1),
14405                 TEST_CASE_ST(ut_setup, ut_teardown,
14406                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
14407                 /** AUTH ZUC + CIPHER AES CTR */
14408                 TEST_CASE_ST(ut_setup, ut_teardown,
14409                         test_auth_zuc_cipher_aes_ctr_test_case_1),
14410                 TEST_CASE_ST(ut_setup, ut_teardown,
14411                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
14412                 /** AUTH SNOW3G + CIPHER AES CTR */
14413                 TEST_CASE_ST(ut_setup, ut_teardown,
14414                         test_auth_snow_cipher_aes_ctr_test_case_1),
14415                 TEST_CASE_ST(ut_setup, ut_teardown,
14416                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
14417                 /** AUTH SNOW3G + CIPHER ZUC */
14418                 TEST_CASE_ST(ut_setup, ut_teardown,
14419                         test_auth_snow_cipher_zuc_test_case_1),
14420                 TEST_CASE_ST(ut_setup, ut_teardown,
14421                         test_verify_auth_snow_cipher_zuc_test_case_1),
14422                 /** AUTH AES CMAC + CIPHER ZUC */
14423                 TEST_CASE_ST(ut_setup, ut_teardown,
14424                         test_auth_aes_cmac_cipher_zuc_test_case_1),
14425                 TEST_CASE_ST(ut_setup, ut_teardown,
14426                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
14427
14428                 /** AUTH NULL + CIPHER SNOW3G */
14429                 TEST_CASE_ST(ut_setup, ut_teardown,
14430                         test_auth_null_cipher_snow_test_case_1),
14431                 TEST_CASE_ST(ut_setup, ut_teardown,
14432                         test_verify_auth_null_cipher_snow_test_case_1),
14433                 /** AUTH NULL + CIPHER ZUC */
14434                 TEST_CASE_ST(ut_setup, ut_teardown,
14435                         test_auth_null_cipher_zuc_test_case_1),
14436                 TEST_CASE_ST(ut_setup, ut_teardown,
14437                         test_verify_auth_null_cipher_zuc_test_case_1),
14438                 /** AUTH SNOW3G + CIPHER NULL */
14439                 TEST_CASE_ST(ut_setup, ut_teardown,
14440                         test_auth_snow_cipher_null_test_case_1),
14441                 TEST_CASE_ST(ut_setup, ut_teardown,
14442                         test_verify_auth_snow_cipher_null_test_case_1),
14443                 /** AUTH ZUC + CIPHER NULL */
14444                 TEST_CASE_ST(ut_setup, ut_teardown,
14445                         test_auth_zuc_cipher_null_test_case_1),
14446                 TEST_CASE_ST(ut_setup, ut_teardown,
14447                         test_verify_auth_zuc_cipher_null_test_case_1),
14448                 /** AUTH NULL + CIPHER AES CTR */
14449                 TEST_CASE_ST(ut_setup, ut_teardown,
14450                         test_auth_null_cipher_aes_ctr_test_case_1),
14451                 TEST_CASE_ST(ut_setup, ut_teardown,
14452                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
14453                 /** AUTH AES CMAC + CIPHER NULL */
14454                 TEST_CASE_ST(ut_setup, ut_teardown,
14455                         test_auth_aes_cmac_cipher_null_test_case_1),
14456                 TEST_CASE_ST(ut_setup, ut_teardown,
14457                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
14458                 TEST_CASES_END()
14459         }
14460 };
14461
14462 static int
14463 run_cryptodev_testsuite(const char *pmd_name)
14464 {
14465         uint8_t ret, j, i = 0, blk_start_idx = 0;
14466         const enum blockcipher_test_type blk_suites[] = {
14467                 BLKCIPHER_AES_CHAIN_TYPE,
14468                 BLKCIPHER_AES_CIPHERONLY_TYPE,
14469                 BLKCIPHER_AES_DOCSIS_TYPE,
14470                 BLKCIPHER_3DES_CHAIN_TYPE,
14471                 BLKCIPHER_3DES_CIPHERONLY_TYPE,
14472                 BLKCIPHER_DES_CIPHERONLY_TYPE,
14473                 BLKCIPHER_DES_DOCSIS_TYPE,
14474                 BLKCIPHER_AUTHONLY_TYPE};
14475         struct unit_test_suite *static_suites[] = {
14476                 &cryptodev_multi_session_testsuite,
14477                 &cryptodev_null_testsuite,
14478                 &cryptodev_aes_ccm_auth_testsuite,
14479                 &cryptodev_aes_gcm_auth_testsuite,
14480                 &cryptodev_aes_gmac_auth_testsuite,
14481                 &cryptodev_snow3g_testsuite,
14482                 &cryptodev_chacha20_poly1305_testsuite,
14483                 &cryptodev_zuc_testsuite,
14484                 &cryptodev_hmac_md5_auth_testsuite,
14485                 &cryptodev_kasumi_testsuite,
14486                 &cryptodev_esn_testsuite,
14487                 &cryptodev_negative_aes_gcm_testsuite,
14488                 &cryptodev_negative_aes_gmac_testsuite,
14489                 &cryptodev_mixed_cipher_hash_testsuite,
14490                 &cryptodev_negative_hmac_sha1_testsuite,
14491                 &cryptodev_gen_testsuite,
14492 #ifdef RTE_LIB_SECURITY
14493                 &pdcp_proto_testsuite,
14494                 &docsis_proto_testsuite,
14495 #endif
14496                 &end_testsuite
14497         };
14498         static struct unit_test_suite ts = {
14499                 .suite_name = "Cryptodev Unit Test Suite",
14500                 .setup = testsuite_setup,
14501                 .teardown = testsuite_teardown,
14502                 .unit_test_cases = {TEST_CASES_END()}
14503         };
14504
14505         gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
14506
14507         if (gbl_driver_id == -1) {
14508                 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
14509                 return TEST_SKIPPED;
14510         }
14511
14512         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
14513                         (RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
14514
14515         ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
14516         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
14517         ret = unit_test_suite_runner(&ts);
14518
14519         FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
14520         free(ts.unit_test_suites);
14521         return ret;
14522 }
14523
14524 static int
14525 test_cryptodev_qat(void)
14526 {
14527         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14528 }
14529
14530 static int
14531 test_cryptodev_virtio(void)
14532 {
14533         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
14534 }
14535
14536 static int
14537 test_cryptodev_aesni_mb(void)
14538 {
14539         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14540 }
14541
14542 static int
14543 test_cryptodev_cpu_aesni_mb(void)
14544 {
14545         int32_t rc;
14546         enum rte_security_session_action_type at = gbl_action_type;
14547         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14548         rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14549         gbl_action_type = at;
14550         return rc;
14551 }
14552
14553 static int
14554 test_cryptodev_openssl(void)
14555 {
14556         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
14557 }
14558
14559 static int
14560 test_cryptodev_aesni_gcm(void)
14561 {
14562         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14563 }
14564
14565 static int
14566 test_cryptodev_cpu_aesni_gcm(void)
14567 {
14568         int32_t rc;
14569         enum rte_security_session_action_type at = gbl_action_type;
14570         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14571         rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14572         gbl_action_type = at;
14573         return rc;
14574 }
14575
14576 static int
14577 test_cryptodev_null(void)
14578 {
14579         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
14580 }
14581
14582 static int
14583 test_cryptodev_sw_snow3g(void)
14584 {
14585         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
14586 }
14587
14588 static int
14589 test_cryptodev_sw_kasumi(void)
14590 {
14591         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
14592 }
14593
14594 static int
14595 test_cryptodev_sw_zuc(void)
14596 {
14597         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
14598 }
14599
14600 static int
14601 test_cryptodev_armv8(void)
14602 {
14603         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
14604 }
14605
14606 static int
14607 test_cryptodev_mrvl(void)
14608 {
14609         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
14610 }
14611
14612 #ifdef RTE_CRYPTO_SCHEDULER
14613
14614 static int
14615 test_cryptodev_scheduler(void)
14616 {
14617         uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
14618         const enum blockcipher_test_type blk_suites[] = {
14619                 BLKCIPHER_AES_CHAIN_TYPE,
14620                 BLKCIPHER_AES_CIPHERONLY_TYPE,
14621                 BLKCIPHER_AUTHONLY_TYPE
14622         };
14623         static struct unit_test_suite scheduler_multicore = {
14624                 .suite_name = "Scheduler Multicore Unit Test Suite",
14625                 .setup = scheduler_multicore_testsuite_setup,
14626                 .teardown = scheduler_mode_testsuite_teardown,
14627                 .unit_test_cases = {TEST_CASES_END()}
14628         };
14629         static struct unit_test_suite scheduler_round_robin = {
14630                 .suite_name = "Scheduler Round Robin Unit Test Suite",
14631                 .setup = scheduler_roundrobin_testsuite_setup,
14632                 .teardown = scheduler_mode_testsuite_teardown,
14633                 .unit_test_cases = {TEST_CASES_END()}
14634         };
14635         static struct unit_test_suite scheduler_failover = {
14636                 .suite_name = "Scheduler Failover Unit Test Suite",
14637                 .setup = scheduler_failover_testsuite_setup,
14638                 .teardown = scheduler_mode_testsuite_teardown,
14639                 .unit_test_cases = {TEST_CASES_END()}
14640         };
14641         static struct unit_test_suite scheduler_pkt_size_distr = {
14642                 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
14643                 .setup = scheduler_pkt_size_distr_testsuite_setup,
14644                 .teardown = scheduler_mode_testsuite_teardown,
14645                 .unit_test_cases = {TEST_CASES_END()}
14646         };
14647         struct unit_test_suite *sched_mode_suites[] = {
14648                 &scheduler_multicore,
14649                 &scheduler_round_robin,
14650                 &scheduler_failover,
14651                 &scheduler_pkt_size_distr
14652         };
14653         static struct unit_test_suite scheduler_config = {
14654                 .suite_name = "Crypto Device Scheduler Config Unit Test Suite",
14655                 .unit_test_cases = {
14656                         TEST_CASE(test_scheduler_attach_worker_op),
14657                         TEST_CASE(test_scheduler_mode_multicore_op),
14658                         TEST_CASE(test_scheduler_mode_roundrobin_op),
14659                         TEST_CASE(test_scheduler_mode_failover_op),
14660                         TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
14661                         TEST_CASE(test_scheduler_detach_worker_op),
14662
14663                         TEST_CASES_END() /**< NULL terminate array */
14664                 }
14665         };
14666         struct unit_test_suite *static_suites[] = {
14667                 &scheduler_config,
14668                 &end_testsuite
14669         };
14670         static struct unit_test_suite ts = {
14671                 .suite_name = "Scheduler Unit Test Suite",
14672                 .setup = scheduler_testsuite_setup,
14673                 .teardown = testsuite_teardown,
14674                 .unit_test_cases = {TEST_CASES_END()}
14675         };
14676
14677         gbl_driver_id = rte_cryptodev_driver_id_get(
14678                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14679
14680         if (gbl_driver_id == -1) {
14681                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
14682                 return TEST_SKIPPED;
14683         }
14684
14685         if (rte_cryptodev_driver_id_get(
14686                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
14687                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
14688                 return TEST_SKIPPED;
14689         }
14690
14691         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
14692                 uint8_t blk_i = 0;
14693                 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
14694                                 (struct unit_test_suite *) *
14695                                 (RTE_DIM(blk_suites) + 1));
14696                 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
14697                                 blk_suites, RTE_DIM(blk_suites));
14698                 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
14699         }
14700
14701         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
14702                         (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
14703         ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
14704                         RTE_DIM(sched_mode_suites));
14705         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
14706         ret = unit_test_suite_runner(&ts);
14707
14708         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
14709                 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
14710                                 (*sched_mode_suites[sched_i]),
14711                                 RTE_DIM(blk_suites));
14712                 free(sched_mode_suites[sched_i]->unit_test_suites);
14713         }
14714         free(ts.unit_test_suites);
14715         return ret;
14716 }
14717
14718 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
14719
14720 #endif
14721
14722 static int
14723 test_cryptodev_dpaa2_sec(void)
14724 {
14725         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
14726 }
14727
14728 static int
14729 test_cryptodev_dpaa_sec(void)
14730 {
14731         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
14732 }
14733
14734 static int
14735 test_cryptodev_ccp(void)
14736 {
14737         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
14738 }
14739
14740 static int
14741 test_cryptodev_octeontx(void)
14742 {
14743         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
14744 }
14745
14746 static int
14747 test_cryptodev_octeontx2(void)
14748 {
14749         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
14750 }
14751
14752 static int
14753 test_cryptodev_caam_jr(void)
14754 {
14755         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
14756 }
14757
14758 static int
14759 test_cryptodev_nitrox(void)
14760 {
14761         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
14762 }
14763
14764 static int
14765 test_cryptodev_bcmfs(void)
14766 {
14767         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
14768 }
14769
14770 static int
14771 test_cryptodev_qat_raw_api(void)
14772 {
14773         int ret;
14774
14775         global_api_test_type = CRYPTODEV_RAW_API_TEST;
14776         ret = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14777         global_api_test_type = CRYPTODEV_API_TEST;
14778
14779         return ret;
14780 }
14781
14782 static int
14783 test_cryptodev_cn9k(void)
14784 {
14785         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
14786 }
14787
14788 static int
14789 test_cryptodev_cn10k(void)
14790 {
14791         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
14792 }
14793
14794 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
14795                 test_cryptodev_qat_raw_api);
14796 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
14797 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
14798 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
14799         test_cryptodev_cpu_aesni_mb);
14800 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
14801 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
14802 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
14803         test_cryptodev_cpu_aesni_gcm);
14804 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
14805 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
14806 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
14807 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
14808 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
14809 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
14810 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
14811 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
14812 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
14813 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
14814 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
14815 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
14816 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
14817 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
14818 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
14819 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
14820 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);