843d07ba3706856544256d0fd6a3f9d0987854d2
[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 static int gbl_driver_id;
65
66 static enum rte_security_session_action_type gbl_action_type =
67         RTE_SECURITY_ACTION_TYPE_NONE;
68
69 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
70
71 struct crypto_unittest_params {
72         struct rte_crypto_sym_xform cipher_xform;
73         struct rte_crypto_sym_xform auth_xform;
74         struct rte_crypto_sym_xform aead_xform;
75 #ifdef RTE_LIB_SECURITY
76         struct rte_security_docsis_xform docsis_xform;
77 #endif
78
79         union {
80                 struct rte_cryptodev_sym_session *sess;
81 #ifdef RTE_LIB_SECURITY
82                 struct rte_security_session *sec_session;
83 #endif
84         };
85 #ifdef RTE_LIB_SECURITY
86         enum rte_security_session_action_type type;
87 #endif
88         struct rte_crypto_op *op;
89
90         struct rte_mbuf *obuf, *ibuf;
91
92         uint8_t *digest;
93 };
94
95 #define ALIGN_POW2_ROUNDUP(num, align) \
96         (((num) + (align) - 1) & ~((align) - 1))
97
98 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)  \
99         for (j = 0; j < num_child_ts; index++, j++)                     \
100                 parent_ts.unit_test_suites[index] = child_ts[j]
101
102 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)   \
103         for (j = 0; j < num_blk_types; index++, j++)                            \
104                 parent_ts.unit_test_suites[index] =                             \
105                                 build_blockcipher_test_suite(blk_types[j])
106
107 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)             \
108         for (j = index; j < index + num_blk_types; j++)                         \
109                 free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
110
111 /*
112  * Forward declarations.
113  */
114 static int
115 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
116                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
117                 uint8_t *hmac_key);
118
119 static int
120 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
121                 struct crypto_unittest_params *ut_params,
122                 struct crypto_testsuite_params *ts_param,
123                 const uint8_t *cipher,
124                 const uint8_t *digest,
125                 const uint8_t *iv);
126
127 static struct rte_mbuf *
128 setup_test_string(struct rte_mempool *mpool,
129                 const char *string, size_t len, uint8_t blocksize)
130 {
131         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
132         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
133
134         if (m) {
135                 char *dst;
136
137                 memset(m->buf_addr, 0, m->buf_len);
138                 dst = rte_pktmbuf_append(m, t_len);
139                 if (!dst) {
140                         rte_pktmbuf_free(m);
141                         return NULL;
142                 }
143                 if (string != NULL)
144                         rte_memcpy(dst, string, t_len);
145                 else
146                         memset(dst, 0, t_len);
147         }
148
149         return m;
150 }
151
152 /* Get number of bytes in X bits (rounding up) */
153 static uint32_t
154 ceil_byte_length(uint32_t num_bits)
155 {
156         if (num_bits % 8)
157                 return ((num_bits >> 3) + 1);
158         else
159                 return (num_bits >> 3);
160 }
161
162 static void
163 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused,
164                 uint8_t is_op_success)
165 {
166         struct rte_crypto_op *op = user_data;
167         op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
168                         RTE_CRYPTO_OP_STATUS_ERROR;
169 }
170
171 void
172 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
173                 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
174                 uint8_t len_in_bits, uint8_t cipher_iv_len)
175 {
176         struct rte_crypto_sym_op *sop = op->sym;
177         struct rte_crypto_op *ret_op = NULL;
178         struct rte_crypto_vec data_vec[UINT8_MAX];
179         struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
180         union rte_crypto_sym_ofs ofs;
181         struct rte_crypto_sym_vec vec;
182         struct rte_crypto_sgl sgl;
183         uint32_t max_len;
184         union rte_cryptodev_session_ctx sess;
185         uint32_t count = 0;
186         struct rte_crypto_raw_dp_ctx *ctx;
187         uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
188                         auth_len = 0;
189         int32_t n;
190         uint32_t n_success;
191         int ctx_service_size;
192         int32_t status = 0;
193         int enqueue_status, dequeue_status;
194
195         ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
196         if (ctx_service_size < 0) {
197                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
198                 return;
199         }
200
201         ctx = malloc(ctx_service_size);
202         if (!ctx) {
203                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
204                 return;
205         }
206
207         /* Both are enums, setting crypto_sess will suit any session type */
208         sess.crypto_sess = op->sym->session;
209
210         if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
211                         op->sess_type, sess, 0) < 0) {
212                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
213                 goto exit;
214         }
215
216         cipher_iv.iova = 0;
217         cipher_iv.va = NULL;
218         aad_auth_iv.iova = 0;
219         aad_auth_iv.va = NULL;
220         digest.iova = 0;
221         digest.va = NULL;
222         sgl.vec = data_vec;
223         vec.num = 1;
224         vec.sgl = &sgl;
225         vec.iv = &cipher_iv;
226         vec.digest = &digest;
227         vec.aad = &aad_auth_iv;
228         vec.status = &status;
229
230         ofs.raw = 0;
231
232         if (is_cipher && is_auth) {
233                 cipher_offset = sop->cipher.data.offset;
234                 cipher_len = sop->cipher.data.length;
235                 auth_offset = sop->auth.data.offset;
236                 auth_len = sop->auth.data.length;
237                 max_len = RTE_MAX(cipher_offset + cipher_len,
238                                 auth_offset + auth_len);
239                 if (len_in_bits) {
240                         max_len = max_len >> 3;
241                         cipher_offset = cipher_offset >> 3;
242                         auth_offset = auth_offset >> 3;
243                         cipher_len = cipher_len >> 3;
244                         auth_len = auth_len >> 3;
245                 }
246                 ofs.ofs.cipher.head = cipher_offset;
247                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
248                 ofs.ofs.auth.head = auth_offset;
249                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
250                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
251                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
252                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
253                                 op, void *, IV_OFFSET + cipher_iv_len);
254                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
255                                 cipher_iv_len);
256                 digest.va = (void *)sop->auth.digest.data;
257                 digest.iova = sop->auth.digest.phys_addr;
258
259         } else if (is_cipher) {
260                 cipher_offset = sop->cipher.data.offset;
261                 cipher_len = sop->cipher.data.length;
262                 max_len = cipher_len + cipher_offset;
263                 if (len_in_bits) {
264                         max_len = max_len >> 3;
265                         cipher_offset = cipher_offset >> 3;
266                         cipher_len = cipher_len >> 3;
267                 }
268                 ofs.ofs.cipher.head = cipher_offset;
269                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
270                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
271                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
272
273         } else if (is_auth) {
274                 auth_offset = sop->auth.data.offset;
275                 auth_len = sop->auth.data.length;
276                 max_len = auth_len + auth_offset;
277                 if (len_in_bits) {
278                         max_len = max_len >> 3;
279                         auth_offset = auth_offset >> 3;
280                         auth_len = auth_len >> 3;
281                 }
282                 ofs.ofs.auth.head = auth_offset;
283                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
284                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
285                                 op, void *, IV_OFFSET + cipher_iv_len);
286                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
287                                 cipher_iv_len);
288                 digest.va = (void *)sop->auth.digest.data;
289                 digest.iova = sop->auth.digest.phys_addr;
290
291         } else { /* aead */
292                 cipher_offset = sop->aead.data.offset;
293                 cipher_len = sop->aead.data.length;
294                 max_len = cipher_len + cipher_offset;
295                 if (len_in_bits) {
296                         max_len = max_len >> 3;
297                         cipher_offset = cipher_offset >> 3;
298                         cipher_len = cipher_len >> 3;
299                 }
300                 ofs.ofs.cipher.head = cipher_offset;
301                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
302                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
303                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
304                 aad_auth_iv.va = (void *)sop->aead.aad.data;
305                 aad_auth_iv.iova = sop->aead.aad.phys_addr;
306                 digest.va = (void *)sop->aead.digest.data;
307                 digest.iova = sop->aead.digest.phys_addr;
308         }
309
310         n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
311                         data_vec, RTE_DIM(data_vec));
312         if (n < 0 || n > sop->m_src->nb_segs) {
313                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
314                 goto exit;
315         }
316
317         sgl.num = n;
318
319         if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
320                         &enqueue_status) < 1) {
321                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
322                 goto exit;
323         }
324
325         if (enqueue_status == 0) {
326                 status = rte_cryptodev_raw_enqueue_done(ctx, 1);
327                 if (status < 0) {
328                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
329                         goto exit;
330                 }
331         } else if (enqueue_status < 0) {
332                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
333                 goto exit;
334         }
335
336         n = n_success = 0;
337         while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
338                 n = rte_cryptodev_raw_dequeue_burst(ctx,
339                         NULL, 1, post_process_raw_dp_op,
340                                 (void **)&ret_op, 0, &n_success,
341                                 &dequeue_status);
342                 if (dequeue_status < 0) {
343                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
344                         goto exit;
345                 }
346                 if (n == 0)
347                         rte_pause();
348         }
349
350         if (n == 1 && dequeue_status == 0) {
351                 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
352                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
353                         goto exit;
354                 }
355         }
356
357         op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
358                         n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
359                                         RTE_CRYPTO_OP_STATUS_SUCCESS;
360
361 exit:
362         free(ctx);
363 }
364
365 static void
366 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
367 {
368         int32_t n, st;
369         struct rte_crypto_sym_op *sop;
370         union rte_crypto_sym_ofs ofs;
371         struct rte_crypto_sgl sgl;
372         struct rte_crypto_sym_vec symvec;
373         struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
374         struct rte_crypto_vec vec[UINT8_MAX];
375
376         sop = op->sym;
377
378         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
379                 sop->aead.data.length, vec, RTE_DIM(vec));
380
381         if (n < 0 || n != sop->m_src->nb_segs) {
382                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
383                 return;
384         }
385
386         sgl.vec = vec;
387         sgl.num = n;
388         symvec.sgl = &sgl;
389         symvec.iv = &iv_ptr;
390         symvec.digest = &digest_ptr;
391         symvec.aad = &aad_ptr;
392         symvec.status = &st;
393         symvec.num = 1;
394
395         /* for CPU crypto the IOVA address is not required */
396         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
397         digest_ptr.va = (void *)sop->aead.digest.data;
398         aad_ptr.va = (void *)sop->aead.aad.data;
399
400         ofs.raw = 0;
401
402         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
403                 &symvec);
404
405         if (n != 1)
406                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
407         else
408                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
409 }
410
411 static void
412 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
413 {
414         int32_t n, st;
415         struct rte_crypto_sym_op *sop;
416         union rte_crypto_sym_ofs ofs;
417         struct rte_crypto_sgl sgl;
418         struct rte_crypto_sym_vec symvec;
419         struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
420         struct rte_crypto_vec vec[UINT8_MAX];
421
422         sop = op->sym;
423
424         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
425                 sop->auth.data.length, vec, RTE_DIM(vec));
426
427         if (n < 0 || n != sop->m_src->nb_segs) {
428                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
429                 return;
430         }
431
432         sgl.vec = vec;
433         sgl.num = n;
434         symvec.sgl = &sgl;
435         symvec.iv = &iv_ptr;
436         symvec.digest = &digest_ptr;
437         symvec.status = &st;
438         symvec.num = 1;
439
440         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
441         digest_ptr.va = (void *)sop->auth.digest.data;
442
443         ofs.raw = 0;
444         ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
445         ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
446                 (sop->cipher.data.offset + sop->cipher.data.length);
447
448         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
449                 &symvec);
450
451         if (n != 1)
452                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
453         else
454                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
455 }
456
457 static struct rte_crypto_op *
458 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
459 {
460
461         RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
462
463         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
464                 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
465                 return NULL;
466         }
467
468         op = NULL;
469
470         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
471                 rte_pause();
472
473         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
474                 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
475                 return NULL;
476         }
477
478         return op;
479 }
480
481 static struct crypto_testsuite_params testsuite_params = { NULL };
482 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
483 static struct crypto_unittest_params unittest_params;
484
485 static int
486 testsuite_setup(void)
487 {
488         struct crypto_testsuite_params *ts_params = &testsuite_params;
489         struct rte_cryptodev_info info;
490         uint32_t i = 0, nb_devs, dev_id;
491         uint16_t qp_id;
492
493         memset(ts_params, 0, sizeof(*ts_params));
494
495         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
496         if (ts_params->mbuf_pool == NULL) {
497                 /* Not already created so create */
498                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
499                                 "CRYPTO_MBUFPOOL",
500                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
501                                 rte_socket_id());
502                 if (ts_params->mbuf_pool == NULL) {
503                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
504                         return TEST_FAILED;
505                 }
506         }
507
508         ts_params->large_mbuf_pool = rte_mempool_lookup(
509                         "CRYPTO_LARGE_MBUFPOOL");
510         if (ts_params->large_mbuf_pool == NULL) {
511                 /* Not already created so create */
512                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
513                                 "CRYPTO_LARGE_MBUFPOOL",
514                                 1, 0, 0, UINT16_MAX,
515                                 rte_socket_id());
516                 if (ts_params->large_mbuf_pool == NULL) {
517                         RTE_LOG(ERR, USER1,
518                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
519                         return TEST_FAILED;
520                 }
521         }
522
523         ts_params->op_mpool = rte_crypto_op_pool_create(
524                         "MBUF_CRYPTO_SYM_OP_POOL",
525                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
526                         NUM_MBUFS, MBUF_CACHE_SIZE,
527                         DEFAULT_NUM_XFORMS *
528                         sizeof(struct rte_crypto_sym_xform) +
529                         MAXIMUM_IV_LENGTH,
530                         rte_socket_id());
531         if (ts_params->op_mpool == NULL) {
532                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
533                 return TEST_FAILED;
534         }
535
536         nb_devs = rte_cryptodev_count();
537         if (nb_devs < 1) {
538                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
539                 return TEST_SKIPPED;
540         }
541
542         if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
543                 RTE_LOG(WARNING, USER1, "No %s devices found?\n",
544                                 rte_cryptodev_driver_name_get(gbl_driver_id));
545                 return TEST_SKIPPED;
546         }
547
548         /* Create list of valid crypto devs */
549         for (i = 0; i < nb_devs; i++) {
550                 rte_cryptodev_info_get(i, &info);
551                 if (info.driver_id == gbl_driver_id)
552                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
553         }
554
555         if (ts_params->valid_dev_count < 1)
556                 return TEST_FAILED;
557
558         /* Set up all the qps on the first of the valid devices found */
559
560         dev_id = ts_params->valid_devs[0];
561
562         rte_cryptodev_info_get(dev_id, &info);
563
564         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
565         ts_params->conf.socket_id = SOCKET_ID_ANY;
566         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
567
568         unsigned int session_size =
569                 rte_cryptodev_sym_get_private_session_size(dev_id);
570
571 #ifdef RTE_LIB_SECURITY
572         unsigned int security_session_size = rte_security_session_get_size(
573                         rte_cryptodev_get_sec_ctx(dev_id));
574
575         if (session_size < security_session_size)
576                 session_size = security_session_size;
577 #endif
578         /*
579          * Create mempool with maximum number of sessions.
580          */
581         if (info.sym.max_nb_sessions != 0 &&
582                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
583                 RTE_LOG(ERR, USER1, "Device does not support "
584                                 "at least %u sessions\n",
585                                 MAX_NB_SESSIONS);
586                 return TEST_FAILED;
587         }
588
589         ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
590                         "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
591                         SOCKET_ID_ANY);
592         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
593                         "session mempool allocation failed");
594
595         ts_params->session_priv_mpool = rte_mempool_create(
596                         "test_sess_mp_priv",
597                         MAX_NB_SESSIONS,
598                         session_size,
599                         0, 0, NULL, NULL, NULL,
600                         NULL, SOCKET_ID_ANY,
601                         0);
602         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
603                         "session mempool allocation failed");
604
605
606
607         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
608                         &ts_params->conf),
609                         "Failed to configure cryptodev %u with %u qps",
610                         dev_id, ts_params->conf.nb_queue_pairs);
611
612         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
613         ts_params->qp_conf.mp_session = ts_params->session_mpool;
614         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
615
616         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
617                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
618                         dev_id, qp_id, &ts_params->qp_conf,
619                         rte_cryptodev_socket_id(dev_id)),
620                         "Failed to setup queue pair %u on cryptodev %u",
621                         qp_id, dev_id);
622         }
623
624         return TEST_SUCCESS;
625 }
626
627 static void
628 testsuite_teardown(void)
629 {
630         struct crypto_testsuite_params *ts_params = &testsuite_params;
631         int res;
632
633         if (ts_params->mbuf_pool != NULL) {
634                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
635                 rte_mempool_avail_count(ts_params->mbuf_pool));
636         }
637
638         if (ts_params->op_mpool != NULL) {
639                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
640                 rte_mempool_avail_count(ts_params->op_mpool));
641         }
642
643         /* Free session mempools */
644         if (ts_params->session_priv_mpool != NULL) {
645                 rte_mempool_free(ts_params->session_priv_mpool);
646                 ts_params->session_priv_mpool = NULL;
647         }
648
649         if (ts_params->session_mpool != NULL) {
650                 rte_mempool_free(ts_params->session_mpool);
651                 ts_params->session_mpool = NULL;
652         }
653
654         res = rte_cryptodev_close(ts_params->valid_devs[0]);
655         if (res)
656                 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
657 }
658
659 static int
660 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
661                 const int *algs, uint16_t num_algs)
662 {
663         uint8_t dev_id = testsuite_params.valid_devs[0];
664         bool some_alg_supported = FALSE;
665         uint16_t i;
666
667         for (i = 0; i < num_algs && !some_alg_supported; i++) {
668                 struct rte_cryptodev_sym_capability_idx alg = {
669                         type, {algs[i]}
670                 };
671                 if (rte_cryptodev_sym_capability_get(dev_id,
672                                 &alg) != NULL)
673                         some_alg_supported = TRUE;
674         }
675         if (!some_alg_supported)
676                 return TEST_SKIPPED;
677
678         return 0;
679 }
680
681 int
682 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
683                 uint16_t num_ciphers)
684 {
685         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
686                         (const int *) ciphers, num_ciphers);
687 }
688
689 int
690 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
691                 uint16_t num_auths)
692 {
693         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
694                         (const int *) auths, num_auths);
695 }
696
697 int
698 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
699                 uint16_t num_aeads)
700 {
701         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
702                         (const int *) aeads, num_aeads);
703 }
704
705 static int
706 null_testsuite_setup(void)
707 {
708         struct crypto_testsuite_params *ts_params = &testsuite_params;
709         uint8_t dev_id = ts_params->valid_devs[0];
710         struct rte_cryptodev_info dev_info;
711         const enum rte_crypto_cipher_algorithm ciphers[] = {
712                 RTE_CRYPTO_CIPHER_NULL
713         };
714         const enum rte_crypto_auth_algorithm auths[] = {
715                 RTE_CRYPTO_AUTH_NULL
716         };
717
718         rte_cryptodev_info_get(dev_id, &dev_info);
719
720         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
721                 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
722                                 "testsuite not met\n");
723                 return TEST_SKIPPED;
724         }
725
726         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
727                         && check_auth_capabilities_supported(auths,
728                         RTE_DIM(auths)) != 0) {
729                 RTE_LOG(INFO, USER1, "Capability requirements for NULL "
730                                 "testsuite not met\n");
731                 return TEST_SKIPPED;
732         }
733
734         return 0;
735 }
736
737 static int
738 crypto_gen_testsuite_setup(void)
739 {
740         struct crypto_testsuite_params *ts_params = &testsuite_params;
741         uint8_t dev_id = ts_params->valid_devs[0];
742         struct rte_cryptodev_info dev_info;
743
744         rte_cryptodev_info_get(dev_id, &dev_info);
745
746         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
747                 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
748                                 "testsuite not met\n");
749                 return TEST_SKIPPED;
750         }
751
752         return 0;
753 }
754
755 #ifdef RTE_LIB_SECURITY
756 static int
757 pdcp_proto_testsuite_setup(void)
758 {
759         struct crypto_testsuite_params *ts_params = &testsuite_params;
760         uint8_t dev_id = ts_params->valid_devs[0];
761         struct rte_cryptodev_info dev_info;
762         const enum rte_crypto_cipher_algorithm ciphers[] = {
763                 RTE_CRYPTO_CIPHER_NULL,
764                 RTE_CRYPTO_CIPHER_AES_CTR,
765                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
766                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
767         };
768         const enum rte_crypto_auth_algorithm auths[] = {
769                 RTE_CRYPTO_AUTH_NULL,
770                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
771                 RTE_CRYPTO_AUTH_AES_CMAC,
772                 RTE_CRYPTO_AUTH_ZUC_EIA3
773         };
774
775         rte_cryptodev_info_get(dev_id, &dev_info);
776
777         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
778                         !(dev_info.feature_flags &
779                         RTE_CRYPTODEV_FF_SECURITY)) {
780                 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
781                                 "testsuite not met\n");
782                 return TEST_SKIPPED;
783         }
784
785         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
786                         && check_auth_capabilities_supported(auths,
787                         RTE_DIM(auths)) != 0) {
788                 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
789                                 "testsuite not met\n");
790                 return TEST_SKIPPED;
791         }
792
793         return 0;
794 }
795
796 static int
797 docsis_proto_testsuite_setup(void)
798 {
799         struct crypto_testsuite_params *ts_params = &testsuite_params;
800         uint8_t dev_id = ts_params->valid_devs[0];
801         struct rte_cryptodev_info dev_info;
802         const enum rte_crypto_cipher_algorithm ciphers[] = {
803                 RTE_CRYPTO_CIPHER_AES_DOCSISBPI
804         };
805
806         rte_cryptodev_info_get(dev_id, &dev_info);
807
808         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
809                         !(dev_info.feature_flags &
810                         RTE_CRYPTODEV_FF_SECURITY)) {
811                 RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis "
812                                 "Proto testsuite not met\n");
813                 return TEST_SKIPPED;
814         }
815
816         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
817                 RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto "
818                                 "testsuite not met\n");
819                 return TEST_SKIPPED;
820         }
821
822         return 0;
823 }
824 #endif
825
826 static int
827 aes_ccm_auth_testsuite_setup(void)
828 {
829         struct crypto_testsuite_params *ts_params = &testsuite_params;
830         uint8_t dev_id = ts_params->valid_devs[0];
831         struct rte_cryptodev_info dev_info;
832         const enum rte_crypto_aead_algorithm aeads[] = {
833                 RTE_CRYPTO_AEAD_AES_CCM
834         };
835
836         rte_cryptodev_info_get(dev_id, &dev_info);
837
838         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
839                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
840                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
841                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
842                                 "testsuite not met\n");
843                 return TEST_SKIPPED;
844         }
845
846         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
847                 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
848                                 "testsuite not met\n");
849                 return TEST_SKIPPED;
850         }
851
852         return 0;
853 }
854
855 static int
856 aes_gcm_auth_testsuite_setup(void)
857 {
858         struct crypto_testsuite_params *ts_params = &testsuite_params;
859         uint8_t dev_id = ts_params->valid_devs[0];
860         struct rte_cryptodev_info dev_info;
861         const enum rte_crypto_aead_algorithm aeads[] = {
862                 RTE_CRYPTO_AEAD_AES_GCM
863         };
864
865         rte_cryptodev_info_get(dev_id, &dev_info);
866
867         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
868                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
869                                 "testsuite not met\n");
870                 return TEST_SKIPPED;
871         }
872
873         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
874                 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
875                                 "testsuite not met\n");
876                 return TEST_SKIPPED;
877         }
878
879         return 0;
880 }
881
882 static int
883 aes_gmac_auth_testsuite_setup(void)
884 {
885         struct crypto_testsuite_params *ts_params = &testsuite_params;
886         uint8_t dev_id = ts_params->valid_devs[0];
887         struct rte_cryptodev_info dev_info;
888         const enum rte_crypto_auth_algorithm auths[] = {
889                 RTE_CRYPTO_AUTH_AES_GMAC
890         };
891
892         rte_cryptodev_info_get(dev_id, &dev_info);
893
894         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
895                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
896                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
897                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
898                                 "testsuite not met\n");
899                 return TEST_SKIPPED;
900         }
901
902         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
903                 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
904                                 "testsuite not met\n");
905                 return TEST_SKIPPED;
906         }
907
908         return 0;
909 }
910
911 static int
912 chacha20_poly1305_testsuite_setup(void)
913 {
914         struct crypto_testsuite_params *ts_params = &testsuite_params;
915         uint8_t dev_id = ts_params->valid_devs[0];
916         struct rte_cryptodev_info dev_info;
917         const enum rte_crypto_aead_algorithm aeads[] = {
918                 RTE_CRYPTO_AEAD_CHACHA20_POLY1305
919         };
920
921         rte_cryptodev_info_get(dev_id, &dev_info);
922
923         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
924                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
925                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
926                 RTE_LOG(INFO, USER1, "Feature flag requirements for "
927                                 "Chacha20-Poly1305 testsuite not met\n");
928                 return TEST_SKIPPED;
929         }
930
931         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
932                 RTE_LOG(INFO, USER1, "Capability requirements for "
933                                 "Chacha20-Poly1305 testsuite not met\n");
934                 return TEST_SKIPPED;
935         }
936
937         return 0;
938 }
939
940 static int
941 snow3g_testsuite_setup(void)
942 {
943         struct crypto_testsuite_params *ts_params = &testsuite_params;
944         uint8_t dev_id = ts_params->valid_devs[0];
945         struct rte_cryptodev_info dev_info;
946         const enum rte_crypto_cipher_algorithm ciphers[] = {
947                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
948
949         };
950         const enum rte_crypto_auth_algorithm auths[] = {
951                 RTE_CRYPTO_AUTH_SNOW3G_UIA2
952         };
953
954         rte_cryptodev_info_get(dev_id, &dev_info);
955
956         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
957                 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
958                                 "testsuite not met\n");
959                 return TEST_SKIPPED;
960         }
961
962         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
963                         && check_auth_capabilities_supported(auths,
964                         RTE_DIM(auths)) != 0) {
965                 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
966                                 "testsuite not met\n");
967                 return TEST_SKIPPED;
968         }
969
970         return 0;
971 }
972
973 static int
974 zuc_testsuite_setup(void)
975 {
976         struct crypto_testsuite_params *ts_params = &testsuite_params;
977         uint8_t dev_id = ts_params->valid_devs[0];
978         struct rte_cryptodev_info dev_info;
979         const enum rte_crypto_cipher_algorithm ciphers[] = {
980                 RTE_CRYPTO_CIPHER_ZUC_EEA3
981         };
982         const enum rte_crypto_auth_algorithm auths[] = {
983                 RTE_CRYPTO_AUTH_ZUC_EIA3
984         };
985
986         rte_cryptodev_info_get(dev_id, &dev_info);
987
988         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
989                 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
990                                 "testsuite not met\n");
991                 return TEST_SKIPPED;
992         }
993
994         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
995                         && check_auth_capabilities_supported(auths,
996                         RTE_DIM(auths)) != 0) {
997                 RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
998                                 "testsuite not met\n");
999                 return TEST_SKIPPED;
1000         }
1001
1002         return 0;
1003 }
1004
1005 static int
1006 hmac_md5_auth_testsuite_setup(void)
1007 {
1008         struct crypto_testsuite_params *ts_params = &testsuite_params;
1009         uint8_t dev_id = ts_params->valid_devs[0];
1010         struct rte_cryptodev_info dev_info;
1011         const enum rte_crypto_auth_algorithm auths[] = {
1012                 RTE_CRYPTO_AUTH_MD5_HMAC
1013         };
1014
1015         rte_cryptodev_info_get(dev_id, &dev_info);
1016
1017         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1018                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1019                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1020                 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1021                                 "Auth testsuite not met\n");
1022                 return TEST_SKIPPED;
1023         }
1024
1025         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1026                 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1027                                 "testsuite not met\n");
1028                 return TEST_SKIPPED;
1029         }
1030
1031         return 0;
1032 }
1033
1034 static int
1035 kasumi_testsuite_setup(void)
1036 {
1037         struct crypto_testsuite_params *ts_params = &testsuite_params;
1038         uint8_t dev_id = ts_params->valid_devs[0];
1039         struct rte_cryptodev_info dev_info;
1040         const enum rte_crypto_cipher_algorithm ciphers[] = {
1041                 RTE_CRYPTO_CIPHER_KASUMI_F8
1042         };
1043         const enum rte_crypto_auth_algorithm auths[] = {
1044                 RTE_CRYPTO_AUTH_KASUMI_F9
1045         };
1046
1047         rte_cryptodev_info_get(dev_id, &dev_info);
1048
1049         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1050                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1051                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1052                 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1053                                 "testsuite not met\n");
1054                 return TEST_SKIPPED;
1055         }
1056
1057         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1058                         && check_auth_capabilities_supported(auths,
1059                         RTE_DIM(auths)) != 0) {
1060                 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1061                                 "testsuite not met\n");
1062                 return TEST_SKIPPED;
1063         }
1064
1065         return 0;
1066 }
1067
1068 static int
1069 negative_aes_gcm_testsuite_setup(void)
1070 {
1071         struct crypto_testsuite_params *ts_params = &testsuite_params;
1072         uint8_t dev_id = ts_params->valid_devs[0];
1073         struct rte_cryptodev_info dev_info;
1074         const enum rte_crypto_aead_algorithm aeads[] = {
1075                 RTE_CRYPTO_AEAD_AES_GCM
1076         };
1077
1078         rte_cryptodev_info_get(dev_id, &dev_info);
1079
1080         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1081                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1082                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1083                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1084                                 "AES GCM testsuite not met\n");
1085                 return TEST_SKIPPED;
1086         }
1087
1088         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1089                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1090                                 "AES GCM testsuite not met\n");
1091                 return TEST_SKIPPED;
1092         }
1093
1094         return 0;
1095 }
1096
1097 static int
1098 negative_aes_gmac_testsuite_setup(void)
1099 {
1100         struct crypto_testsuite_params *ts_params = &testsuite_params;
1101         uint8_t dev_id = ts_params->valid_devs[0];
1102         struct rte_cryptodev_info dev_info;
1103         const enum rte_crypto_auth_algorithm auths[] = {
1104                 RTE_CRYPTO_AUTH_AES_GMAC
1105         };
1106
1107         rte_cryptodev_info_get(dev_id, &dev_info);
1108
1109         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1110                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1111                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1112                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1113                                 "AES GMAC testsuite not met\n");
1114                 return TEST_SKIPPED;
1115         }
1116
1117         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1118                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1119                                 "AES GMAC testsuite not met\n");
1120                 return TEST_SKIPPED;
1121         }
1122
1123         return 0;
1124 }
1125
1126 static int
1127 mixed_cipher_hash_testsuite_setup(void)
1128 {
1129         struct crypto_testsuite_params *ts_params = &testsuite_params;
1130         uint8_t dev_id = ts_params->valid_devs[0];
1131         struct rte_cryptodev_info dev_info;
1132         uint64_t feat_flags;
1133         const enum rte_crypto_cipher_algorithm ciphers[] = {
1134                 RTE_CRYPTO_CIPHER_NULL,
1135                 RTE_CRYPTO_CIPHER_AES_CTR,
1136                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
1137                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1138         };
1139         const enum rte_crypto_auth_algorithm auths[] = {
1140                 RTE_CRYPTO_AUTH_NULL,
1141                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1142                 RTE_CRYPTO_AUTH_AES_CMAC,
1143                 RTE_CRYPTO_AUTH_ZUC_EIA3
1144         };
1145
1146         rte_cryptodev_info_get(dev_id, &dev_info);
1147         feat_flags = dev_info.feature_flags;
1148
1149         if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1150                         (global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1151                 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1152                                 "Cipher Hash testsuite not met\n");
1153                 return TEST_SKIPPED;
1154         }
1155
1156         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1157                         && check_auth_capabilities_supported(auths,
1158                         RTE_DIM(auths)) != 0) {
1159                 RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1160                                 "Cipher Hash testsuite not met\n");
1161                 return TEST_SKIPPED;
1162         }
1163
1164         return 0;
1165 }
1166
1167 static int
1168 esn_testsuite_setup(void)
1169 {
1170         struct crypto_testsuite_params *ts_params = &testsuite_params;
1171         uint8_t dev_id = ts_params->valid_devs[0];
1172         struct rte_cryptodev_info dev_info;
1173         const enum rte_crypto_cipher_algorithm ciphers[] = {
1174                 RTE_CRYPTO_CIPHER_AES_CBC
1175         };
1176         const enum rte_crypto_auth_algorithm auths[] = {
1177                 RTE_CRYPTO_AUTH_SHA1_HMAC
1178         };
1179
1180         rte_cryptodev_info_get(dev_id, &dev_info);
1181
1182         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1183                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1184                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1185                 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1186                                 "testsuite not met\n");
1187                 return TEST_SKIPPED;
1188         }
1189
1190         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1191                         && check_auth_capabilities_supported(auths,
1192                         RTE_DIM(auths)) != 0) {
1193                 RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1194                                 "testsuite not met\n");
1195                 return TEST_SKIPPED;
1196         }
1197
1198         return 0;
1199 }
1200
1201 static int
1202 multi_session_testsuite_setup(void)
1203 {
1204         struct crypto_testsuite_params *ts_params = &testsuite_params;
1205         uint8_t dev_id = ts_params->valid_devs[0];
1206         struct rte_cryptodev_info dev_info;
1207         const enum rte_crypto_cipher_algorithm ciphers[] = {
1208                 RTE_CRYPTO_CIPHER_AES_CBC
1209         };
1210         const enum rte_crypto_auth_algorithm auths[] = {
1211                 RTE_CRYPTO_AUTH_SHA512_HMAC
1212         };
1213
1214         rte_cryptodev_info_get(dev_id, &dev_info);
1215
1216         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1217                 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1218                                 "Session testsuite not met\n");
1219                 return TEST_SKIPPED;
1220         }
1221
1222         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1223                         && check_auth_capabilities_supported(auths,
1224                         RTE_DIM(auths)) != 0) {
1225                 RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1226                                 "Session testsuite not met\n");
1227                 return TEST_SKIPPED;
1228         }
1229
1230         return 0;
1231 }
1232
1233 static int
1234 negative_hmac_sha1_testsuite_setup(void)
1235 {
1236         struct crypto_testsuite_params *ts_params = &testsuite_params;
1237         uint8_t dev_id = ts_params->valid_devs[0];
1238         struct rte_cryptodev_info dev_info;
1239         const enum rte_crypto_cipher_algorithm ciphers[] = {
1240                 RTE_CRYPTO_CIPHER_AES_CBC
1241         };
1242         const enum rte_crypto_auth_algorithm auths[] = {
1243                 RTE_CRYPTO_AUTH_SHA1_HMAC
1244         };
1245
1246         rte_cryptodev_info_get(dev_id, &dev_info);
1247
1248         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1249                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1250                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1251                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1252                                 "HMAC SHA1 testsuite not met\n");
1253                 return TEST_SKIPPED;
1254         }
1255
1256         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1257                         && check_auth_capabilities_supported(auths,
1258                         RTE_DIM(auths)) != 0) {
1259                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1260                                 "HMAC SHA1 testsuite not met\n");
1261                 return TEST_SKIPPED;
1262         }
1263
1264         return 0;
1265 }
1266
1267 static int
1268 dev_configure_and_start(uint64_t ff_disable)
1269 {
1270         struct crypto_testsuite_params *ts_params = &testsuite_params;
1271         struct crypto_unittest_params *ut_params = &unittest_params;
1272
1273         uint16_t qp_id;
1274
1275         /* Clear unit test parameters before running test */
1276         memset(ut_params, 0, sizeof(*ut_params));
1277
1278         /* Reconfigure device to default parameters */
1279         ts_params->conf.socket_id = SOCKET_ID_ANY;
1280         ts_params->conf.ff_disable = ff_disable;
1281         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1282         ts_params->qp_conf.mp_session = ts_params->session_mpool;
1283         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1284
1285         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1286                         &ts_params->conf),
1287                         "Failed to configure cryptodev %u",
1288                         ts_params->valid_devs[0]);
1289
1290         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1291                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1292                         ts_params->valid_devs[0], qp_id,
1293                         &ts_params->qp_conf,
1294                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1295                         "Failed to setup queue pair %u on cryptodev %u",
1296                         qp_id, ts_params->valid_devs[0]);
1297         }
1298
1299
1300         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1301
1302         /* Start the device */
1303         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1304                         "Failed to start cryptodev %u",
1305                         ts_params->valid_devs[0]);
1306
1307         return TEST_SUCCESS;
1308 }
1309
1310 int
1311 ut_setup(void)
1312 {
1313         /* Configure and start the device with security feature disabled */
1314         return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1315 }
1316
1317 static int
1318 ut_setup_security(void)
1319 {
1320         /* Configure and start the device with no features disabled */
1321         return dev_configure_and_start(0);
1322 }
1323
1324 void
1325 ut_teardown(void)
1326 {
1327         struct crypto_testsuite_params *ts_params = &testsuite_params;
1328         struct crypto_unittest_params *ut_params = &unittest_params;
1329         struct rte_cryptodev_stats stats;
1330
1331         /* free crypto session structure */
1332 #ifdef RTE_LIB_SECURITY
1333         if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1334                 if (ut_params->sec_session) {
1335                         rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1336                                                 (ts_params->valid_devs[0]),
1337                                                 ut_params->sec_session);
1338                         ut_params->sec_session = NULL;
1339                 }
1340         } else
1341 #endif
1342         {
1343                 if (ut_params->sess) {
1344                         rte_cryptodev_sym_session_clear(
1345                                         ts_params->valid_devs[0],
1346                                         ut_params->sess);
1347                         rte_cryptodev_sym_session_free(ut_params->sess);
1348                         ut_params->sess = NULL;
1349                 }
1350         }
1351
1352         /* free crypto operation structure */
1353         if (ut_params->op)
1354                 rte_crypto_op_free(ut_params->op);
1355
1356         /*
1357          * free mbuf - both obuf and ibuf are usually the same,
1358          * so check if they point at the same address is necessary,
1359          * to avoid freeing the mbuf twice.
1360          */
1361         if (ut_params->obuf) {
1362                 rte_pktmbuf_free(ut_params->obuf);
1363                 if (ut_params->ibuf == ut_params->obuf)
1364                         ut_params->ibuf = 0;
1365                 ut_params->obuf = 0;
1366         }
1367         if (ut_params->ibuf) {
1368                 rte_pktmbuf_free(ut_params->ibuf);
1369                 ut_params->ibuf = 0;
1370         }
1371
1372         if (ts_params->mbuf_pool != NULL)
1373                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1374                         rte_mempool_avail_count(ts_params->mbuf_pool));
1375
1376         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1377
1378         /* Stop the device */
1379         rte_cryptodev_stop(ts_params->valid_devs[0]);
1380 }
1381
1382 static int
1383 test_device_configure_invalid_dev_id(void)
1384 {
1385         struct crypto_testsuite_params *ts_params = &testsuite_params;
1386         uint16_t dev_id, num_devs = 0;
1387
1388         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1389                         "Need at least %d devices for test", 1);
1390
1391         /* valid dev_id values */
1392         dev_id = ts_params->valid_devs[0];
1393
1394         /* Stop the device in case it's started so it can be configured */
1395         rte_cryptodev_stop(dev_id);
1396
1397         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1398                         "Failed test for rte_cryptodev_configure: "
1399                         "invalid dev_num %u", dev_id);
1400
1401         /* invalid dev_id values */
1402         dev_id = num_devs;
1403
1404         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1405                         "Failed test for rte_cryptodev_configure: "
1406                         "invalid dev_num %u", dev_id);
1407
1408         dev_id = 0xff;
1409
1410         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1411                         "Failed test for rte_cryptodev_configure:"
1412                         "invalid dev_num %u", dev_id);
1413
1414         return TEST_SUCCESS;
1415 }
1416
1417 static int
1418 test_device_configure_invalid_queue_pair_ids(void)
1419 {
1420         struct crypto_testsuite_params *ts_params = &testsuite_params;
1421         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1422
1423         /* Stop the device in case it's started so it can be configured */
1424         rte_cryptodev_stop(ts_params->valid_devs[0]);
1425
1426         /* valid - max value queue pairs */
1427         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1428
1429         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1430                         &ts_params->conf),
1431                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1432                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1433
1434         /* valid - one queue pairs */
1435         ts_params->conf.nb_queue_pairs = 1;
1436
1437         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1438                         &ts_params->conf),
1439                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1440                         ts_params->valid_devs[0],
1441                         ts_params->conf.nb_queue_pairs);
1442
1443
1444         /* invalid - zero queue pairs */
1445         ts_params->conf.nb_queue_pairs = 0;
1446
1447         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1448                         &ts_params->conf),
1449                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1450                         " invalid qps: %u",
1451                         ts_params->valid_devs[0],
1452                         ts_params->conf.nb_queue_pairs);
1453
1454
1455         /* invalid - max value supported by field queue pairs */
1456         ts_params->conf.nb_queue_pairs = UINT16_MAX;
1457
1458         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1459                         &ts_params->conf),
1460                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1461                         " invalid qps: %u",
1462                         ts_params->valid_devs[0],
1463                         ts_params->conf.nb_queue_pairs);
1464
1465
1466         /* invalid - max value + 1 queue pairs */
1467         ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1468
1469         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1470                         &ts_params->conf),
1471                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1472                         " invalid qps: %u",
1473                         ts_params->valid_devs[0],
1474                         ts_params->conf.nb_queue_pairs);
1475
1476         /* revert to original testsuite value */
1477         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1478
1479         return TEST_SUCCESS;
1480 }
1481
1482 static int
1483 test_queue_pair_descriptor_setup(void)
1484 {
1485         struct crypto_testsuite_params *ts_params = &testsuite_params;
1486         struct rte_cryptodev_qp_conf qp_conf = {
1487                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
1488         };
1489         uint16_t qp_id;
1490
1491         /* Stop the device in case it's started so it can be configured */
1492         rte_cryptodev_stop(ts_params->valid_devs[0]);
1493
1494         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1495                         &ts_params->conf),
1496                         "Failed to configure cryptodev %u",
1497                         ts_params->valid_devs[0]);
1498
1499         /*
1500          * Test various ring sizes on this device. memzones can't be
1501          * freed so are re-used if ring is released and re-created.
1502          */
1503         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1504         qp_conf.mp_session = ts_params->session_mpool;
1505         qp_conf.mp_session_private = ts_params->session_priv_mpool;
1506
1507         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1508                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1509                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1510                                 rte_cryptodev_socket_id(
1511                                                 ts_params->valid_devs[0])),
1512                                 "Failed test for "
1513                                 "rte_cryptodev_queue_pair_setup: num_inflights "
1514                                 "%u on qp %u on cryptodev %u",
1515                                 qp_conf.nb_descriptors, qp_id,
1516                                 ts_params->valid_devs[0]);
1517         }
1518
1519         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1520
1521         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1522                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1523                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1524                                 rte_cryptodev_socket_id(
1525                                                 ts_params->valid_devs[0])),
1526                                 "Failed test for"
1527                                 " rte_cryptodev_queue_pair_setup: num_inflights"
1528                                 " %u on qp %u on cryptodev %u",
1529                                 qp_conf.nb_descriptors, qp_id,
1530                                 ts_params->valid_devs[0]);
1531         }
1532
1533         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1534
1535         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1536                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1537                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1538                                 rte_cryptodev_socket_id(
1539                                                 ts_params->valid_devs[0])),
1540                                 "Failed test for "
1541                                 "rte_cryptodev_queue_pair_setup: num_inflights"
1542                                 " %u on qp %u on cryptodev %u",
1543                                 qp_conf.nb_descriptors, qp_id,
1544                                 ts_params->valid_devs[0]);
1545         }
1546
1547         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1548
1549         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1550                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1551                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1552                                 rte_cryptodev_socket_id(
1553                                                 ts_params->valid_devs[0])),
1554                                 "Failed test for"
1555                                 " rte_cryptodev_queue_pair_setup:"
1556                                 "num_inflights %u on qp %u on cryptodev %u",
1557                                 qp_conf.nb_descriptors, qp_id,
1558                                 ts_params->valid_devs[0]);
1559         }
1560
1561         /* test invalid queue pair id */
1562         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
1563
1564         qp_id = ts_params->conf.nb_queue_pairs;         /*invalid */
1565
1566         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1567                         ts_params->valid_devs[0],
1568                         qp_id, &qp_conf,
1569                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1570                         "Failed test for rte_cryptodev_queue_pair_setup:"
1571                         "invalid qp %u on cryptodev %u",
1572                         qp_id, ts_params->valid_devs[0]);
1573
1574         qp_id = 0xffff; /*invalid*/
1575
1576         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1577                         ts_params->valid_devs[0],
1578                         qp_id, &qp_conf,
1579                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1580                         "Failed test for rte_cryptodev_queue_pair_setup:"
1581                         "invalid qp %u on cryptodev %u",
1582                         qp_id, ts_params->valid_devs[0]);
1583
1584         return TEST_SUCCESS;
1585 }
1586
1587 /* ***** Plaintext data for tests ***** */
1588
1589 const char catch_22_quote_1[] =
1590                 "There was only one catch and that was Catch-22, which "
1591                 "specified that a concern for one's safety in the face of "
1592                 "dangers that were real and immediate was the process of a "
1593                 "rational mind. Orr was crazy and could be grounded. All he "
1594                 "had to do was ask; and as soon as he did, he would no longer "
1595                 "be crazy and would have to fly more missions. Orr would be "
1596                 "crazy to fly more missions and sane if he didn't, but if he "
1597                 "was sane he had to fly them. If he flew them he was crazy "
1598                 "and didn't have to; but if he didn't want to he was sane and "
1599                 "had to. Yossarian was moved very deeply by the absolute "
1600                 "simplicity of this clause of Catch-22 and let out a "
1601                 "respectful whistle. \"That's some catch, that Catch-22\", he "
1602                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
1603
1604 const char catch_22_quote[] =
1605                 "What a lousy earth! He wondered how many people were "
1606                 "destitute that same night even in his own prosperous country, "
1607                 "how many homes were shanties, how many husbands were drunk "
1608                 "and wives socked, and how many children were bullied, abused, "
1609                 "or abandoned. How many families hungered for food they could "
1610                 "not afford to buy? How many hearts were broken? How many "
1611                 "suicides would take place that same night, how many people "
1612                 "would go insane? How many cockroaches and landlords would "
1613                 "triumph? How many winners were losers, successes failures, "
1614                 "and rich men poor men? How many wise guys were stupid? How "
1615                 "many happy endings were unhappy endings? How many honest men "
1616                 "were liars, brave men cowards, loyal men traitors, how many "
1617                 "sainted men were corrupt, how many people in positions of "
1618                 "trust had sold their souls to bodyguards, how many had never "
1619                 "had souls? How many straight-and-narrow paths were crooked "
1620                 "paths? How many best families were worst families and how "
1621                 "many good people were bad people? When you added them all up "
1622                 "and then subtracted, you might be left with only the children, "
1623                 "and perhaps with Albert Einstein and an old violinist or "
1624                 "sculptor somewhere.";
1625
1626 #define QUOTE_480_BYTES         (480)
1627 #define QUOTE_512_BYTES         (512)
1628 #define QUOTE_768_BYTES         (768)
1629 #define QUOTE_1024_BYTES        (1024)
1630
1631
1632
1633 /* ***** SHA1 Hash Tests ***** */
1634
1635 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
1636
1637 static uint8_t hmac_sha1_key[] = {
1638         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1639         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1640         0xDE, 0xF4, 0xDE, 0xAD };
1641
1642 /* ***** SHA224 Hash Tests ***** */
1643
1644 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
1645
1646
1647 /* ***** AES-CBC Cipher Tests ***** */
1648
1649 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
1650 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
1651
1652 static uint8_t aes_cbc_key[] = {
1653         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1654         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1655
1656 static uint8_t aes_cbc_iv[] = {
1657         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1658         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1659
1660
1661 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1662
1663 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1664         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1665         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1666         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1667         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1668         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1669         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1670         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1671         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1672         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1673         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1674         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1675         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1676         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1677         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1678         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1679         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1680         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1681         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1682         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1683         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1684         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1685         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1686         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1687         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1688         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1689         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1690         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1691         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1692         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1693         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1694         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1695         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1696         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1697         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1698         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1699         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1700         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1701         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1702         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1703         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1704         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1705         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1706         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1707         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1708         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1709         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1710         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1711         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1712         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1713         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1714         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1715         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1716         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1717         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1718         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1719         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1720         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1721         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1722         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1723         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1724         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1725         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1726         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1727         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1728 };
1729
1730 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1731         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1732         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1733         0x18, 0x8c, 0x1d, 0x32
1734 };
1735
1736
1737 /* Multisession Vector context Test */
1738 /*Begin Session 0 */
1739 static uint8_t ms_aes_cbc_key0[] = {
1740         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1741         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1742 };
1743
1744 static uint8_t ms_aes_cbc_iv0[] = {
1745         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1746         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1747 };
1748
1749 static const uint8_t ms_aes_cbc_cipher0[] = {
1750                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1751                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1752                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1753                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1754                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1755                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1756                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1757                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1758                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1759                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1760                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1761                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1762                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1763                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1764                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1765                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1766                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1767                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1768                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1769                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1770                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1771                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1772                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1773                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1774                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1775                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1776                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1777                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1778                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1779                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1780                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1781                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1782                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1783                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1784                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1785                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1786                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1787                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1788                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1789                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1790                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1791                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1792                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1793                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1794                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1795                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1796                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1797                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1798                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1799                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1800                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1801                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1802                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1803                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1804                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1805                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1806                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1807                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1808                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1809                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1810                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1811                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1812                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1813                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1814 };
1815
1816
1817 static  uint8_t ms_hmac_key0[] = {
1818                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1819                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1820                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1821                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1822                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1823                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1824                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1825                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1826 };
1827
1828 static const uint8_t ms_hmac_digest0[] = {
1829                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1830                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1831                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1832                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1833                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1834                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1835                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1836                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1837                 };
1838
1839 /* End Session 0 */
1840 /* Begin session 1 */
1841
1842 static  uint8_t ms_aes_cbc_key1[] = {
1843                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1844                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1845 };
1846
1847 static  uint8_t ms_aes_cbc_iv1[] = {
1848         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1849         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1850 };
1851
1852 static const uint8_t ms_aes_cbc_cipher1[] = {
1853                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1854                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1855                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1856                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1857                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1858                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1859                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1860                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1861                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1862                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1863                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1864                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1865                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1866                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1867                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1868                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1869                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1870                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1871                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1872                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1873                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1874                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1875                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1876                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1877                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1878                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1879                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1880                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1881                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1882                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1883                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1884                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1885                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1886                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1887                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1888                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1889                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1890                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1891                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1892                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1893                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1894                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1895                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1896                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1897                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1898                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1899                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1900                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1901                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1902                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1903                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1904                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1905                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1906                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1907                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1908                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1909                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1910                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1911                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1912                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1913                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1914                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1915                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1916                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1917
1918 };
1919
1920 static uint8_t ms_hmac_key1[] = {
1921                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1922                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1923                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1924                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1925                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1926                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1927                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1928                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1929 };
1930
1931 static const uint8_t ms_hmac_digest1[] = {
1932                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1933                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1934                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1935                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1936                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1937                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1938                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1939                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1940 };
1941 /* End Session 1  */
1942 /* Begin Session 2 */
1943 static  uint8_t ms_aes_cbc_key2[] = {
1944                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1945                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1946 };
1947
1948 static  uint8_t ms_aes_cbc_iv2[] = {
1949                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1950                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1951 };
1952
1953 static const uint8_t ms_aes_cbc_cipher2[] = {
1954                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1955                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1956                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1957                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1958                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1959                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1960                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1961                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1962                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1963                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1964                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1965                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1966                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1967                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1968                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1969                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1970                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1971                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1972                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1973                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1974                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1975                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1976                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1977                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1978                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1979                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1980                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1981                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1982                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1983                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1984                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1985                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1986                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1987                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1988                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1989                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1990                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1991                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1992                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1993                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1994                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1995                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1996                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1997                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1998                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1999                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2000                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2001                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2002                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2003                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2004                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2005                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2006                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2007                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2008                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2009                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2010                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2011                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2012                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2013                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2014                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2015                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2016                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2017                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2018 };
2019
2020 static  uint8_t ms_hmac_key2[] = {
2021                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2022                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2023                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2024                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2025                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2026                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2027                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2028                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2029 };
2030
2031 static const uint8_t ms_hmac_digest2[] = {
2032                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2033                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2034                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2035                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2036                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2037                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2038                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2039                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2040 };
2041
2042 /* End Session 2 */
2043
2044
2045 static int
2046 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2047 {
2048         struct crypto_testsuite_params *ts_params = &testsuite_params;
2049         struct crypto_unittest_params *ut_params = &unittest_params;
2050
2051         /* Verify the capabilities */
2052         struct rte_cryptodev_sym_capability_idx cap_idx;
2053         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2054         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2055         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2056                         &cap_idx) == NULL)
2057                 return TEST_SKIPPED;
2058         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2059         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2060         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2061                         &cap_idx) == NULL)
2062                 return TEST_SKIPPED;
2063
2064         /* Generate test mbuf data and space for digest */
2065         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2066                         catch_22_quote, QUOTE_512_BYTES, 0);
2067
2068         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2069                         DIGEST_BYTE_LENGTH_SHA1);
2070         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2071
2072         /* Setup Cipher Parameters */
2073         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2074         ut_params->cipher_xform.next = &ut_params->auth_xform;
2075
2076         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2077         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2078         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2079         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2080         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2081         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2082
2083         /* Setup HMAC Parameters */
2084         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2085
2086         ut_params->auth_xform.next = NULL;
2087
2088         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2089         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2090         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2091         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2092         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2093
2094         ut_params->sess = rte_cryptodev_sym_session_create(
2095                         ts_params->session_mpool);
2096
2097         /* Create crypto session*/
2098         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2099                         ut_params->sess, &ut_params->cipher_xform,
2100                         ts_params->session_priv_mpool);
2101         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2102
2103         /* Generate crypto op data structure */
2104         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2105                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2106         TEST_ASSERT_NOT_NULL(ut_params->op,
2107                         "Failed to allocate symmetric crypto operation struct");
2108
2109         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2110
2111         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2112
2113         /* set crypto operation source mbuf */
2114         sym_op->m_src = ut_params->ibuf;
2115
2116         /* Set crypto operation authentication parameters */
2117         sym_op->auth.digest.data = ut_params->digest;
2118         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2119                         ut_params->ibuf, QUOTE_512_BYTES);
2120
2121         sym_op->auth.data.offset = 0;
2122         sym_op->auth.data.length = QUOTE_512_BYTES;
2123
2124         /* Copy IV at the end of the crypto operation */
2125         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2126                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2127
2128         /* Set crypto operation cipher parameters */
2129         sym_op->cipher.data.offset = 0;
2130         sym_op->cipher.data.length = QUOTE_512_BYTES;
2131
2132         /* Process crypto operation */
2133         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2134                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2135                         ut_params->op);
2136         else
2137                 TEST_ASSERT_NOT_NULL(
2138                         process_crypto_request(ts_params->valid_devs[0],
2139                                 ut_params->op),
2140                                 "failed to process sym crypto op");
2141
2142         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2143                         "crypto op processing failed");
2144
2145         /* Validate obuf */
2146         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2147                         uint8_t *);
2148
2149         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2150                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2151                         QUOTE_512_BYTES,
2152                         "ciphertext data not as expected");
2153
2154         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2155
2156         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2157                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2158                         gbl_driver_id == rte_cryptodev_driver_id_get(
2159                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2160                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2161                                         DIGEST_BYTE_LENGTH_SHA1,
2162                         "Generated digest data not as expected");
2163
2164         return TEST_SUCCESS;
2165 }
2166
2167 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2168
2169 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2170
2171 static uint8_t hmac_sha512_key[] = {
2172         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2173         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2174         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2175         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2176         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2177         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2178         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2179         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2180
2181 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2182         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2183         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2184         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2185         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2186         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2187         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2188         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2189         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2190
2191
2192
2193 static int
2194 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2195                 struct crypto_unittest_params *ut_params,
2196                 uint8_t *cipher_key,
2197                 uint8_t *hmac_key);
2198
2199 static int
2200 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2201                 struct crypto_unittest_params *ut_params,
2202                 struct crypto_testsuite_params *ts_params,
2203                 const uint8_t *cipher,
2204                 const uint8_t *digest,
2205                 const uint8_t *iv);
2206
2207
2208 static int
2209 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2210                 struct crypto_unittest_params *ut_params,
2211                 uint8_t *cipher_key,
2212                 uint8_t *hmac_key)
2213 {
2214
2215         /* Setup Cipher Parameters */
2216         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2217         ut_params->cipher_xform.next = NULL;
2218
2219         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2220         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2221         ut_params->cipher_xform.cipher.key.data = cipher_key;
2222         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2223         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2224         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2225
2226         /* Setup HMAC Parameters */
2227         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2228         ut_params->auth_xform.next = &ut_params->cipher_xform;
2229
2230         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2231         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2232         ut_params->auth_xform.auth.key.data = hmac_key;
2233         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2234         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2235
2236         return TEST_SUCCESS;
2237 }
2238
2239
2240 static int
2241 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2242                 struct crypto_unittest_params *ut_params,
2243                 struct crypto_testsuite_params *ts_params,
2244                 const uint8_t *cipher,
2245                 const uint8_t *digest,
2246                 const uint8_t *iv)
2247 {
2248         /* Generate test mbuf data and digest */
2249         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2250                         (const char *)
2251                         cipher,
2252                         QUOTE_512_BYTES, 0);
2253
2254         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2255                         DIGEST_BYTE_LENGTH_SHA512);
2256         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2257
2258         rte_memcpy(ut_params->digest,
2259                         digest,
2260                         DIGEST_BYTE_LENGTH_SHA512);
2261
2262         /* Generate Crypto op data structure */
2263         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2264                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2265         TEST_ASSERT_NOT_NULL(ut_params->op,
2266                         "Failed to allocate symmetric crypto operation struct");
2267
2268         rte_crypto_op_attach_sym_session(ut_params->op, sess);
2269
2270         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2271
2272         /* set crypto operation source mbuf */
2273         sym_op->m_src = ut_params->ibuf;
2274
2275         sym_op->auth.digest.data = ut_params->digest;
2276         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2277                         ut_params->ibuf, QUOTE_512_BYTES);
2278
2279         sym_op->auth.data.offset = 0;
2280         sym_op->auth.data.length = QUOTE_512_BYTES;
2281
2282         /* Copy IV at the end of the crypto operation */
2283         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2284                         iv, CIPHER_IV_LENGTH_AES_CBC);
2285
2286         sym_op->cipher.data.offset = 0;
2287         sym_op->cipher.data.length = QUOTE_512_BYTES;
2288
2289         /* Process crypto operation */
2290         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2291                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2292                         ut_params->op);
2293         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2294                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2295                                 ut_params->op, 1, 1, 0, 0);
2296         else
2297                 TEST_ASSERT_NOT_NULL(
2298                                 process_crypto_request(ts_params->valid_devs[0],
2299                                         ut_params->op),
2300                                         "failed to process sym crypto op");
2301
2302         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2303                         "crypto op processing failed");
2304
2305         ut_params->obuf = ut_params->op->sym->m_src;
2306
2307         /* Validate obuf */
2308         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2309                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2310                         catch_22_quote,
2311                         QUOTE_512_BYTES,
2312                         "Plaintext data not as expected");
2313
2314         /* Validate obuf */
2315         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2316                         "Digest verification failed");
2317
2318         return TEST_SUCCESS;
2319 }
2320
2321 /* ***** SNOW 3G Tests ***** */
2322 static int
2323 create_wireless_algo_hash_session(uint8_t dev_id,
2324         const uint8_t *key, const uint8_t key_len,
2325         const uint8_t iv_len, const uint8_t auth_len,
2326         enum rte_crypto_auth_operation op,
2327         enum rte_crypto_auth_algorithm algo)
2328 {
2329         uint8_t hash_key[key_len];
2330         int status;
2331
2332         struct crypto_testsuite_params *ts_params = &testsuite_params;
2333         struct crypto_unittest_params *ut_params = &unittest_params;
2334
2335         memcpy(hash_key, key, key_len);
2336
2337         debug_hexdump(stdout, "key:", key, key_len);
2338
2339         /* Setup Authentication Parameters */
2340         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2341         ut_params->auth_xform.next = NULL;
2342
2343         ut_params->auth_xform.auth.op = op;
2344         ut_params->auth_xform.auth.algo = algo;
2345         ut_params->auth_xform.auth.key.length = key_len;
2346         ut_params->auth_xform.auth.key.data = hash_key;
2347         ut_params->auth_xform.auth.digest_length = auth_len;
2348         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2349         ut_params->auth_xform.auth.iv.length = iv_len;
2350         ut_params->sess = rte_cryptodev_sym_session_create(
2351                         ts_params->session_mpool);
2352
2353         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2354                         &ut_params->auth_xform,
2355                         ts_params->session_priv_mpool);
2356         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2357         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2358         return 0;
2359 }
2360
2361 static int
2362 create_wireless_algo_cipher_session(uint8_t dev_id,
2363                         enum rte_crypto_cipher_operation op,
2364                         enum rte_crypto_cipher_algorithm algo,
2365                         const uint8_t *key, const uint8_t key_len,
2366                         uint8_t iv_len)
2367 {
2368         uint8_t cipher_key[key_len];
2369         int status;
2370         struct crypto_testsuite_params *ts_params = &testsuite_params;
2371         struct crypto_unittest_params *ut_params = &unittest_params;
2372
2373         memcpy(cipher_key, key, key_len);
2374
2375         /* Setup Cipher Parameters */
2376         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2377         ut_params->cipher_xform.next = NULL;
2378
2379         ut_params->cipher_xform.cipher.algo = algo;
2380         ut_params->cipher_xform.cipher.op = op;
2381         ut_params->cipher_xform.cipher.key.data = cipher_key;
2382         ut_params->cipher_xform.cipher.key.length = key_len;
2383         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2384         ut_params->cipher_xform.cipher.iv.length = iv_len;
2385
2386         debug_hexdump(stdout, "key:", key, key_len);
2387
2388         /* Create Crypto session */
2389         ut_params->sess = rte_cryptodev_sym_session_create(
2390                         ts_params->session_mpool);
2391
2392         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2393                         &ut_params->cipher_xform,
2394                         ts_params->session_priv_mpool);
2395         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2396         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2397         return 0;
2398 }
2399
2400 static int
2401 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2402                         unsigned int cipher_len,
2403                         unsigned int cipher_offset)
2404 {
2405         struct crypto_testsuite_params *ts_params = &testsuite_params;
2406         struct crypto_unittest_params *ut_params = &unittest_params;
2407
2408         /* Generate Crypto op data structure */
2409         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2410                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2411         TEST_ASSERT_NOT_NULL(ut_params->op,
2412                                 "Failed to allocate pktmbuf offload");
2413
2414         /* Set crypto operation data parameters */
2415         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2416
2417         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2418
2419         /* set crypto operation source mbuf */
2420         sym_op->m_src = ut_params->ibuf;
2421
2422         /* iv */
2423         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2424                         iv, iv_len);
2425         sym_op->cipher.data.length = cipher_len;
2426         sym_op->cipher.data.offset = cipher_offset;
2427         return 0;
2428 }
2429
2430 static int
2431 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2432                         unsigned int cipher_len,
2433                         unsigned int cipher_offset)
2434 {
2435         struct crypto_testsuite_params *ts_params = &testsuite_params;
2436         struct crypto_unittest_params *ut_params = &unittest_params;
2437
2438         /* Generate Crypto op data structure */
2439         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2440                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2441         TEST_ASSERT_NOT_NULL(ut_params->op,
2442                                 "Failed to allocate pktmbuf offload");
2443
2444         /* Set crypto operation data parameters */
2445         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2446
2447         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2448
2449         /* set crypto operation source mbuf */
2450         sym_op->m_src = ut_params->ibuf;
2451         sym_op->m_dst = ut_params->obuf;
2452
2453         /* iv */
2454         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2455                         iv, iv_len);
2456         sym_op->cipher.data.length = cipher_len;
2457         sym_op->cipher.data.offset = cipher_offset;
2458         return 0;
2459 }
2460
2461 static int
2462 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2463                 enum rte_crypto_cipher_operation cipher_op,
2464                 enum rte_crypto_auth_operation auth_op,
2465                 enum rte_crypto_auth_algorithm auth_algo,
2466                 enum rte_crypto_cipher_algorithm cipher_algo,
2467                 const uint8_t *key, uint8_t key_len,
2468                 uint8_t auth_iv_len, uint8_t auth_len,
2469                 uint8_t cipher_iv_len)
2470
2471 {
2472         uint8_t cipher_auth_key[key_len];
2473         int status;
2474
2475         struct crypto_testsuite_params *ts_params = &testsuite_params;
2476         struct crypto_unittest_params *ut_params = &unittest_params;
2477
2478         memcpy(cipher_auth_key, key, key_len);
2479
2480         /* Setup Authentication Parameters */
2481         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2482         ut_params->auth_xform.next = NULL;
2483
2484         ut_params->auth_xform.auth.op = auth_op;
2485         ut_params->auth_xform.auth.algo = auth_algo;
2486         ut_params->auth_xform.auth.key.length = key_len;
2487         /* Hash key = cipher key */
2488         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2489         ut_params->auth_xform.auth.digest_length = auth_len;
2490         /* Auth IV will be after cipher IV */
2491         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2492         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2493
2494         /* Setup Cipher Parameters */
2495         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2496         ut_params->cipher_xform.next = &ut_params->auth_xform;
2497
2498         ut_params->cipher_xform.cipher.algo = cipher_algo;
2499         ut_params->cipher_xform.cipher.op = cipher_op;
2500         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2501         ut_params->cipher_xform.cipher.key.length = key_len;
2502         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2503         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2504
2505         debug_hexdump(stdout, "key:", key, key_len);
2506
2507         /* Create Crypto session*/
2508         ut_params->sess = rte_cryptodev_sym_session_create(
2509                         ts_params->session_mpool);
2510         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2511
2512         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2513                         &ut_params->cipher_xform,
2514                         ts_params->session_priv_mpool);
2515         if (status == -ENOTSUP)
2516                 return TEST_SKIPPED;
2517
2518         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2519         return 0;
2520 }
2521
2522 static int
2523 create_wireless_cipher_auth_session(uint8_t dev_id,
2524                 enum rte_crypto_cipher_operation cipher_op,
2525                 enum rte_crypto_auth_operation auth_op,
2526                 enum rte_crypto_auth_algorithm auth_algo,
2527                 enum rte_crypto_cipher_algorithm cipher_algo,
2528                 const struct wireless_test_data *tdata)
2529 {
2530         const uint8_t key_len = tdata->key.len;
2531         uint8_t cipher_auth_key[key_len];
2532         int status;
2533
2534         struct crypto_testsuite_params *ts_params = &testsuite_params;
2535         struct crypto_unittest_params *ut_params = &unittest_params;
2536         const uint8_t *key = tdata->key.data;
2537         const uint8_t auth_len = tdata->digest.len;
2538         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2539         uint8_t auth_iv_len = tdata->auth_iv.len;
2540
2541         memcpy(cipher_auth_key, key, key_len);
2542
2543         /* Setup Authentication Parameters */
2544         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2545         ut_params->auth_xform.next = NULL;
2546
2547         ut_params->auth_xform.auth.op = auth_op;
2548         ut_params->auth_xform.auth.algo = auth_algo;
2549         ut_params->auth_xform.auth.key.length = key_len;
2550         /* Hash key = cipher key */
2551         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2552         ut_params->auth_xform.auth.digest_length = auth_len;
2553         /* Auth IV will be after cipher IV */
2554         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2555         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2556
2557         /* Setup Cipher Parameters */
2558         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2559         ut_params->cipher_xform.next = &ut_params->auth_xform;
2560
2561         ut_params->cipher_xform.cipher.algo = cipher_algo;
2562         ut_params->cipher_xform.cipher.op = cipher_op;
2563         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2564         ut_params->cipher_xform.cipher.key.length = key_len;
2565         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2566         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2567
2568
2569         debug_hexdump(stdout, "key:", key, key_len);
2570
2571         /* Create Crypto session*/
2572         ut_params->sess = rte_cryptodev_sym_session_create(
2573                         ts_params->session_mpool);
2574
2575         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2576                         &ut_params->cipher_xform,
2577                         ts_params->session_priv_mpool);
2578         if (status == -ENOTSUP)
2579                 return TEST_SKIPPED;
2580
2581         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2582         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2583         return 0;
2584 }
2585
2586 static int
2587 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2588                 const struct wireless_test_data *tdata)
2589 {
2590         return create_wireless_cipher_auth_session(dev_id,
2591                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2592                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2593                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2594 }
2595
2596 static int
2597 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2598                 enum rte_crypto_cipher_operation cipher_op,
2599                 enum rte_crypto_auth_operation auth_op,
2600                 enum rte_crypto_auth_algorithm auth_algo,
2601                 enum rte_crypto_cipher_algorithm cipher_algo,
2602                 const uint8_t *key, const uint8_t key_len,
2603                 uint8_t auth_iv_len, uint8_t auth_len,
2604                 uint8_t cipher_iv_len)
2605 {
2606         uint8_t auth_cipher_key[key_len];
2607         int status;
2608         struct crypto_testsuite_params *ts_params = &testsuite_params;
2609         struct crypto_unittest_params *ut_params = &unittest_params;
2610
2611         memcpy(auth_cipher_key, key, key_len);
2612
2613         /* Setup Authentication Parameters */
2614         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2615         ut_params->auth_xform.auth.op = auth_op;
2616         ut_params->auth_xform.next = &ut_params->cipher_xform;
2617         ut_params->auth_xform.auth.algo = auth_algo;
2618         ut_params->auth_xform.auth.key.length = key_len;
2619         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2620         ut_params->auth_xform.auth.digest_length = auth_len;
2621         /* Auth IV will be after cipher IV */
2622         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2623         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2624
2625         /* Setup Cipher Parameters */
2626         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2627         ut_params->cipher_xform.next = NULL;
2628         ut_params->cipher_xform.cipher.algo = cipher_algo;
2629         ut_params->cipher_xform.cipher.op = cipher_op;
2630         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2631         ut_params->cipher_xform.cipher.key.length = key_len;
2632         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2633         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2634
2635         debug_hexdump(stdout, "key:", key, key_len);
2636
2637         /* Create Crypto session*/
2638         ut_params->sess = rte_cryptodev_sym_session_create(
2639                         ts_params->session_mpool);
2640         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2641
2642         if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2643                 ut_params->auth_xform.next = NULL;
2644                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2645                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2646                                 &ut_params->cipher_xform,
2647                                 ts_params->session_priv_mpool);
2648
2649         } else
2650                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2651                                 &ut_params->auth_xform,
2652                                 ts_params->session_priv_mpool);
2653
2654         if (status == -ENOTSUP)
2655                 return TEST_SKIPPED;
2656
2657         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2658
2659         return 0;
2660 }
2661
2662 static int
2663 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2664                 unsigned int auth_tag_len,
2665                 const uint8_t *iv, unsigned int iv_len,
2666                 unsigned int data_pad_len,
2667                 enum rte_crypto_auth_operation op,
2668                 unsigned int auth_len, unsigned int auth_offset)
2669 {
2670         struct crypto_testsuite_params *ts_params = &testsuite_params;
2671
2672         struct crypto_unittest_params *ut_params = &unittest_params;
2673
2674         /* Generate Crypto op data structure */
2675         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2676                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2677         TEST_ASSERT_NOT_NULL(ut_params->op,
2678                 "Failed to allocate pktmbuf offload");
2679
2680         /* Set crypto operation data parameters */
2681         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2682
2683         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2684
2685         /* set crypto operation source mbuf */
2686         sym_op->m_src = ut_params->ibuf;
2687
2688         /* iv */
2689         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2690                         iv, iv_len);
2691         /* digest */
2692         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2693                                         ut_params->ibuf, auth_tag_len);
2694
2695         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2696                                 "no room to append auth tag");
2697         ut_params->digest = sym_op->auth.digest.data;
2698         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2699                         ut_params->ibuf, data_pad_len);
2700         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2701                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2702         else
2703                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2704
2705         debug_hexdump(stdout, "digest:",
2706                 sym_op->auth.digest.data,
2707                 auth_tag_len);
2708
2709         sym_op->auth.data.length = auth_len;
2710         sym_op->auth.data.offset = auth_offset;
2711
2712         return 0;
2713 }
2714
2715 static int
2716 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2717         enum rte_crypto_auth_operation op)
2718 {
2719         struct crypto_testsuite_params *ts_params = &testsuite_params;
2720         struct crypto_unittest_params *ut_params = &unittest_params;
2721
2722         const uint8_t *auth_tag = tdata->digest.data;
2723         const unsigned int auth_tag_len = tdata->digest.len;
2724         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2725         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2726
2727         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2728         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2729         const uint8_t *auth_iv = tdata->auth_iv.data;
2730         const uint8_t auth_iv_len = tdata->auth_iv.len;
2731         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2732         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2733
2734         /* Generate Crypto op data structure */
2735         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2736                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2737         TEST_ASSERT_NOT_NULL(ut_params->op,
2738                         "Failed to allocate pktmbuf offload");
2739         /* Set crypto operation data parameters */
2740         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2741
2742         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2743
2744         /* set crypto operation source mbuf */
2745         sym_op->m_src = ut_params->ibuf;
2746
2747         /* digest */
2748         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2749                         ut_params->ibuf, auth_tag_len);
2750
2751         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2752                         "no room to append auth tag");
2753         ut_params->digest = sym_op->auth.digest.data;
2754         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2755                         ut_params->ibuf, data_pad_len);
2756         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2757                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2758         else
2759                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2760
2761         debug_hexdump(stdout, "digest:",
2762                 sym_op->auth.digest.data,
2763                 auth_tag_len);
2764
2765         /* Copy cipher and auth IVs at the end of the crypto operation */
2766         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2767                                                 IV_OFFSET);
2768         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2769         iv_ptr += cipher_iv_len;
2770         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2771
2772         sym_op->cipher.data.length = cipher_len;
2773         sym_op->cipher.data.offset = 0;
2774         sym_op->auth.data.length = auth_len;
2775         sym_op->auth.data.offset = 0;
2776
2777         return 0;
2778 }
2779
2780 static int
2781 create_zuc_cipher_hash_generate_operation(
2782                 const struct wireless_test_data *tdata)
2783 {
2784         return create_wireless_cipher_hash_operation(tdata,
2785                 RTE_CRYPTO_AUTH_OP_GENERATE);
2786 }
2787
2788 static int
2789 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2790                 const unsigned auth_tag_len,
2791                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2792                 unsigned data_pad_len,
2793                 enum rte_crypto_auth_operation op,
2794                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2795                 const unsigned cipher_len, const unsigned cipher_offset,
2796                 const unsigned auth_len, const unsigned auth_offset)
2797 {
2798         struct crypto_testsuite_params *ts_params = &testsuite_params;
2799         struct crypto_unittest_params *ut_params = &unittest_params;
2800
2801         enum rte_crypto_cipher_algorithm cipher_algo =
2802                         ut_params->cipher_xform.cipher.algo;
2803         enum rte_crypto_auth_algorithm auth_algo =
2804                         ut_params->auth_xform.auth.algo;
2805
2806         /* Generate Crypto op data structure */
2807         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2808                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2809         TEST_ASSERT_NOT_NULL(ut_params->op,
2810                         "Failed to allocate pktmbuf offload");
2811         /* Set crypto operation data parameters */
2812         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2813
2814         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2815
2816         /* set crypto operation source mbuf */
2817         sym_op->m_src = ut_params->ibuf;
2818
2819         /* digest */
2820         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2821                         ut_params->ibuf, auth_tag_len);
2822
2823         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2824                         "no room to append auth tag");
2825         ut_params->digest = sym_op->auth.digest.data;
2826
2827         if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2828                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2829                                 ut_params->ibuf, data_pad_len);
2830         } else {
2831                 struct rte_mbuf *m = ut_params->ibuf;
2832                 unsigned int offset = data_pad_len;
2833
2834                 while (offset > m->data_len && m->next != NULL) {
2835                         offset -= m->data_len;
2836                         m = m->next;
2837                 }
2838                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2839                         m, offset);
2840         }
2841
2842         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2843                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2844         else
2845                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2846
2847         debug_hexdump(stdout, "digest:",
2848                 sym_op->auth.digest.data,
2849                 auth_tag_len);
2850
2851         /* Copy cipher and auth IVs at the end of the crypto operation */
2852         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2853                                                 IV_OFFSET);
2854         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2855         iv_ptr += cipher_iv_len;
2856         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2857
2858         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2859                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2860                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2861                 sym_op->cipher.data.length = cipher_len;
2862                 sym_op->cipher.data.offset = cipher_offset;
2863         } else {
2864                 sym_op->cipher.data.length = cipher_len >> 3;
2865                 sym_op->cipher.data.offset = cipher_offset >> 3;
2866         }
2867
2868         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2869                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2870                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2871                 sym_op->auth.data.length = auth_len;
2872                 sym_op->auth.data.offset = auth_offset;
2873         } else {
2874                 sym_op->auth.data.length = auth_len >> 3;
2875                 sym_op->auth.data.offset = auth_offset >> 3;
2876         }
2877
2878         return 0;
2879 }
2880
2881 static int
2882 create_wireless_algo_auth_cipher_operation(
2883                 const uint8_t *auth_tag, unsigned int auth_tag_len,
2884                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2885                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2886                 unsigned int data_pad_len,
2887                 unsigned int cipher_len, unsigned int cipher_offset,
2888                 unsigned int auth_len, unsigned int auth_offset,
2889                 uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2890 {
2891         struct crypto_testsuite_params *ts_params = &testsuite_params;
2892         struct crypto_unittest_params *ut_params = &unittest_params;
2893
2894         enum rte_crypto_cipher_algorithm cipher_algo =
2895                         ut_params->cipher_xform.cipher.algo;
2896         enum rte_crypto_auth_algorithm auth_algo =
2897                         ut_params->auth_xform.auth.algo;
2898
2899         /* Generate Crypto op data structure */
2900         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2901                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2902         TEST_ASSERT_NOT_NULL(ut_params->op,
2903                         "Failed to allocate pktmbuf offload");
2904
2905         /* Set crypto operation data parameters */
2906         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2907
2908         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2909
2910         /* set crypto operation mbufs */
2911         sym_op->m_src = ut_params->ibuf;
2912         if (op_mode == OUT_OF_PLACE)
2913                 sym_op->m_dst = ut_params->obuf;
2914
2915         /* digest */
2916         if (!do_sgl) {
2917                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2918                         (op_mode == IN_PLACE ?
2919                                 ut_params->ibuf : ut_params->obuf),
2920                         uint8_t *, data_pad_len);
2921                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2922                         (op_mode == IN_PLACE ?
2923                                 ut_params->ibuf : ut_params->obuf),
2924                         data_pad_len);
2925                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2926         } else {
2927                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2928                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2929                                 sym_op->m_src : sym_op->m_dst);
2930                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2931                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2932                         sgl_buf = sgl_buf->next;
2933                 }
2934                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2935                                 uint8_t *, remaining_off);
2936                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2937                                 remaining_off);
2938                 memset(sym_op->auth.digest.data, 0, remaining_off);
2939                 while (sgl_buf->next != NULL) {
2940                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2941                                 0, rte_pktmbuf_data_len(sgl_buf));
2942                         sgl_buf = sgl_buf->next;
2943                 }
2944         }
2945
2946         /* Copy digest for the verification */
2947         if (verify)
2948                 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2949
2950         /* Copy cipher and auth IVs at the end of the crypto operation */
2951         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
2952                         ut_params->op, uint8_t *, IV_OFFSET);
2953
2954         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2955         iv_ptr += cipher_iv_len;
2956         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2957
2958         /* Only copy over the offset data needed from src to dst in OOP,
2959          * if the auth and cipher offsets are not aligned
2960          */
2961         if (op_mode == OUT_OF_PLACE) {
2962                 if (cipher_offset > auth_offset)
2963                         rte_memcpy(
2964                                 rte_pktmbuf_mtod_offset(
2965                                         sym_op->m_dst,
2966                                         uint8_t *, auth_offset >> 3),
2967                                 rte_pktmbuf_mtod_offset(
2968                                         sym_op->m_src,
2969                                         uint8_t *, auth_offset >> 3),
2970                                 ((cipher_offset >> 3) - (auth_offset >> 3)));
2971         }
2972
2973         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2974                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2975                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2976                 sym_op->cipher.data.length = cipher_len;
2977                 sym_op->cipher.data.offset = cipher_offset;
2978         } else {
2979                 sym_op->cipher.data.length = cipher_len >> 3;
2980                 sym_op->cipher.data.offset = cipher_offset >> 3;
2981         }
2982
2983         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2984                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2985                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2986                 sym_op->auth.data.length = auth_len;
2987                 sym_op->auth.data.offset = auth_offset;
2988         } else {
2989                 sym_op->auth.data.length = auth_len >> 3;
2990                 sym_op->auth.data.offset = auth_offset >> 3;
2991         }
2992
2993         return 0;
2994 }
2995
2996 static int
2997 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2998 {
2999         struct crypto_testsuite_params *ts_params = &testsuite_params;
3000         struct crypto_unittest_params *ut_params = &unittest_params;
3001
3002         int retval;
3003         unsigned plaintext_pad_len;
3004         unsigned plaintext_len;
3005         uint8_t *plaintext;
3006         struct rte_cryptodev_info dev_info;
3007
3008         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3009         uint64_t feat_flags = dev_info.feature_flags;
3010
3011         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3012                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3013                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3014                 return TEST_SKIPPED;
3015         }
3016
3017         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3018                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3019                 printf("Device doesn't support RAW data-path APIs.\n");
3020                 return TEST_SKIPPED;
3021         }
3022
3023         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3024                 return TEST_SKIPPED;
3025
3026         /* Verify the capabilities */
3027         struct rte_cryptodev_sym_capability_idx cap_idx;
3028         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3029         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3030         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3031                         &cap_idx) == NULL)
3032                 return TEST_SKIPPED;
3033
3034         /* Create SNOW 3G session */
3035         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3036                         tdata->key.data, tdata->key.len,
3037                         tdata->auth_iv.len, tdata->digest.len,
3038                         RTE_CRYPTO_AUTH_OP_GENERATE,
3039                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3040         if (retval < 0)
3041                 return retval;
3042
3043         /* alloc mbuf and set payload */
3044         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3045
3046         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3047         rte_pktmbuf_tailroom(ut_params->ibuf));
3048
3049         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3050         /* Append data which is padded to a multiple of */
3051         /* the algorithms block size */
3052         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3053         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3054                                 plaintext_pad_len);
3055         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3056
3057         /* Create SNOW 3G operation */
3058         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3059                         tdata->auth_iv.data, tdata->auth_iv.len,
3060                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3061                         tdata->validAuthLenInBits.len,
3062                         0);
3063         if (retval < 0)
3064                 return retval;
3065
3066         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3067                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3068                                 ut_params->op, 0, 1, 1, 0);
3069         else
3070                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3071                                 ut_params->op);
3072         ut_params->obuf = ut_params->op->sym->m_src;
3073         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3074         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3075                         + plaintext_pad_len;
3076
3077         /* Validate obuf */
3078         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3079         ut_params->digest,
3080         tdata->digest.data,
3081         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3082         "SNOW 3G Generated auth tag not as expected");
3083
3084         return 0;
3085 }
3086
3087 static int
3088 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3089 {
3090         struct crypto_testsuite_params *ts_params = &testsuite_params;
3091         struct crypto_unittest_params *ut_params = &unittest_params;
3092
3093         int retval;
3094         unsigned plaintext_pad_len;
3095         unsigned plaintext_len;
3096         uint8_t *plaintext;
3097         struct rte_cryptodev_info dev_info;
3098
3099         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3100         uint64_t feat_flags = dev_info.feature_flags;
3101
3102         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3103                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3104                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3105                 return TEST_SKIPPED;
3106         }
3107
3108         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3109                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3110                 printf("Device doesn't support RAW data-path APIs.\n");
3111                 return TEST_SKIPPED;
3112         }
3113
3114         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3115                 return TEST_SKIPPED;
3116
3117         /* Verify the capabilities */
3118         struct rte_cryptodev_sym_capability_idx cap_idx;
3119         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3120         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3121         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3122                         &cap_idx) == NULL)
3123                 return TEST_SKIPPED;
3124
3125         /* Create SNOW 3G session */
3126         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3127                                 tdata->key.data, tdata->key.len,
3128                                 tdata->auth_iv.len, tdata->digest.len,
3129                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3130                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3131         if (retval < 0)
3132                 return retval;
3133         /* alloc mbuf and set payload */
3134         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3135
3136         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3137         rte_pktmbuf_tailroom(ut_params->ibuf));
3138
3139         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3140         /* Append data which is padded to a multiple of */
3141         /* the algorithms block size */
3142         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3143         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3144                                 plaintext_pad_len);
3145         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3146
3147         /* Create SNOW 3G operation */
3148         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3149                         tdata->digest.len,
3150                         tdata->auth_iv.data, tdata->auth_iv.len,
3151                         plaintext_pad_len,
3152                         RTE_CRYPTO_AUTH_OP_VERIFY,
3153                         tdata->validAuthLenInBits.len,
3154                         0);
3155         if (retval < 0)
3156                 return retval;
3157
3158         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3159                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3160                                 ut_params->op, 0, 1, 1, 0);
3161         else
3162                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3163                                 ut_params->op);
3164         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3165         ut_params->obuf = ut_params->op->sym->m_src;
3166         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3167                                 + plaintext_pad_len;
3168
3169         /* Validate obuf */
3170         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3171                 return 0;
3172         else
3173                 return -1;
3174
3175         return 0;
3176 }
3177
3178 static int
3179 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3180 {
3181         struct crypto_testsuite_params *ts_params = &testsuite_params;
3182         struct crypto_unittest_params *ut_params = &unittest_params;
3183
3184         int retval;
3185         unsigned plaintext_pad_len;
3186         unsigned plaintext_len;
3187         uint8_t *plaintext;
3188         struct rte_cryptodev_info dev_info;
3189
3190         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3191         uint64_t feat_flags = dev_info.feature_flags;
3192
3193         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3194                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3195                 printf("Device doesn't support RAW data-path APIs.\n");
3196                 return TEST_SKIPPED;
3197         }
3198
3199         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3200                 return TEST_SKIPPED;
3201
3202         /* Verify the capabilities */
3203         struct rte_cryptodev_sym_capability_idx cap_idx;
3204         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3205         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3206         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3207                         &cap_idx) == NULL)
3208                 return TEST_SKIPPED;
3209
3210         /* Create KASUMI session */
3211         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3212                         tdata->key.data, tdata->key.len,
3213                         0, tdata->digest.len,
3214                         RTE_CRYPTO_AUTH_OP_GENERATE,
3215                         RTE_CRYPTO_AUTH_KASUMI_F9);
3216         if (retval < 0)
3217                 return retval;
3218
3219         /* alloc mbuf and set payload */
3220         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3221
3222         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3223         rte_pktmbuf_tailroom(ut_params->ibuf));
3224
3225         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3226         /* Append data which is padded to a multiple of */
3227         /* the algorithms block size */
3228         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3229         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3230                                 plaintext_pad_len);
3231         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3232
3233         /* Create KASUMI operation */
3234         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3235                         NULL, 0,
3236                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3237                         tdata->plaintext.len,
3238                         0);
3239         if (retval < 0)
3240                 return retval;
3241
3242         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3243                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3244                         ut_params->op);
3245         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3246                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3247                                 ut_params->op, 0, 1, 1, 0);
3248         else
3249                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3250                         ut_params->op);
3251
3252         ut_params->obuf = ut_params->op->sym->m_src;
3253         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3254         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3255                         + plaintext_pad_len;
3256
3257         /* Validate obuf */
3258         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3259         ut_params->digest,
3260         tdata->digest.data,
3261         DIGEST_BYTE_LENGTH_KASUMI_F9,
3262         "KASUMI Generated auth tag not as expected");
3263
3264         return 0;
3265 }
3266
3267 static int
3268 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3269 {
3270         struct crypto_testsuite_params *ts_params = &testsuite_params;
3271         struct crypto_unittest_params *ut_params = &unittest_params;
3272
3273         int retval;
3274         unsigned plaintext_pad_len;
3275         unsigned plaintext_len;
3276         uint8_t *plaintext;
3277         struct rte_cryptodev_info dev_info;
3278
3279         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3280         uint64_t feat_flags = dev_info.feature_flags;
3281
3282         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3283                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3284                 printf("Device doesn't support RAW data-path APIs.\n");
3285                 return TEST_SKIPPED;
3286         }
3287
3288         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3289                 return TEST_SKIPPED;
3290
3291         /* Verify the capabilities */
3292         struct rte_cryptodev_sym_capability_idx cap_idx;
3293         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3294         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3295         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3296                         &cap_idx) == NULL)
3297                 return TEST_SKIPPED;
3298
3299         /* Create KASUMI session */
3300         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3301                                 tdata->key.data, tdata->key.len,
3302                                 0, tdata->digest.len,
3303                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3304                                 RTE_CRYPTO_AUTH_KASUMI_F9);
3305         if (retval < 0)
3306                 return retval;
3307         /* alloc mbuf and set payload */
3308         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3309
3310         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3311         rte_pktmbuf_tailroom(ut_params->ibuf));
3312
3313         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3314         /* Append data which is padded to a multiple */
3315         /* of the algorithms block size */
3316         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3317         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3318                                 plaintext_pad_len);
3319         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3320
3321         /* Create KASUMI operation */
3322         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3323                         tdata->digest.len,
3324                         NULL, 0,
3325                         plaintext_pad_len,
3326                         RTE_CRYPTO_AUTH_OP_VERIFY,
3327                         tdata->plaintext.len,
3328                         0);
3329         if (retval < 0)
3330                 return retval;
3331
3332         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3333                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3334                                 ut_params->op, 0, 1, 1, 0);
3335         else
3336                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3337                                 ut_params->op);
3338         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3339         ut_params->obuf = ut_params->op->sym->m_src;
3340         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3341                                 + plaintext_pad_len;
3342
3343         /* Validate obuf */
3344         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3345                 return 0;
3346         else
3347                 return -1;
3348
3349         return 0;
3350 }
3351
3352 static int
3353 test_snow3g_hash_generate_test_case_1(void)
3354 {
3355         return test_snow3g_authentication(&snow3g_hash_test_case_1);
3356 }
3357
3358 static int
3359 test_snow3g_hash_generate_test_case_2(void)
3360 {
3361         return test_snow3g_authentication(&snow3g_hash_test_case_2);
3362 }
3363
3364 static int
3365 test_snow3g_hash_generate_test_case_3(void)
3366 {
3367         return test_snow3g_authentication(&snow3g_hash_test_case_3);
3368 }
3369
3370 static int
3371 test_snow3g_hash_generate_test_case_4(void)
3372 {
3373         return test_snow3g_authentication(&snow3g_hash_test_case_4);
3374 }
3375
3376 static int
3377 test_snow3g_hash_generate_test_case_5(void)
3378 {
3379         return test_snow3g_authentication(&snow3g_hash_test_case_5);
3380 }
3381
3382 static int
3383 test_snow3g_hash_generate_test_case_6(void)
3384 {
3385         return test_snow3g_authentication(&snow3g_hash_test_case_6);
3386 }
3387
3388 static int
3389 test_snow3g_hash_verify_test_case_1(void)
3390 {
3391         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3392
3393 }
3394
3395 static int
3396 test_snow3g_hash_verify_test_case_2(void)
3397 {
3398         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3399 }
3400
3401 static int
3402 test_snow3g_hash_verify_test_case_3(void)
3403 {
3404         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3405 }
3406
3407 static int
3408 test_snow3g_hash_verify_test_case_4(void)
3409 {
3410         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3411 }
3412
3413 static int
3414 test_snow3g_hash_verify_test_case_5(void)
3415 {
3416         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3417 }
3418
3419 static int
3420 test_snow3g_hash_verify_test_case_6(void)
3421 {
3422         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3423 }
3424
3425 static int
3426 test_kasumi_hash_generate_test_case_1(void)
3427 {
3428         return test_kasumi_authentication(&kasumi_hash_test_case_1);
3429 }
3430
3431 static int
3432 test_kasumi_hash_generate_test_case_2(void)
3433 {
3434         return test_kasumi_authentication(&kasumi_hash_test_case_2);
3435 }
3436
3437 static int
3438 test_kasumi_hash_generate_test_case_3(void)
3439 {
3440         return test_kasumi_authentication(&kasumi_hash_test_case_3);
3441 }
3442
3443 static int
3444 test_kasumi_hash_generate_test_case_4(void)
3445 {
3446         return test_kasumi_authentication(&kasumi_hash_test_case_4);
3447 }
3448
3449 static int
3450 test_kasumi_hash_generate_test_case_5(void)
3451 {
3452         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3453 }
3454
3455 static int
3456 test_kasumi_hash_generate_test_case_6(void)
3457 {
3458         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3459 }
3460
3461 static int
3462 test_kasumi_hash_verify_test_case_1(void)
3463 {
3464         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3465 }
3466
3467 static int
3468 test_kasumi_hash_verify_test_case_2(void)
3469 {
3470         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3471 }
3472
3473 static int
3474 test_kasumi_hash_verify_test_case_3(void)
3475 {
3476         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3477 }
3478
3479 static int
3480 test_kasumi_hash_verify_test_case_4(void)
3481 {
3482         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3483 }
3484
3485 static int
3486 test_kasumi_hash_verify_test_case_5(void)
3487 {
3488         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3489 }
3490
3491 static int
3492 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3493 {
3494         struct crypto_testsuite_params *ts_params = &testsuite_params;
3495         struct crypto_unittest_params *ut_params = &unittest_params;
3496
3497         int retval;
3498         uint8_t *plaintext, *ciphertext;
3499         unsigned plaintext_pad_len;
3500         unsigned plaintext_len;
3501         struct rte_cryptodev_info dev_info;
3502
3503         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3504         uint64_t feat_flags = dev_info.feature_flags;
3505
3506         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3507                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3508                 printf("Device doesn't support RAW data-path APIs.\n");
3509                 return TEST_SKIPPED;
3510         }
3511
3512         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3513                 return TEST_SKIPPED;
3514
3515         /* Verify the capabilities */
3516         struct rte_cryptodev_sym_capability_idx cap_idx;
3517         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3518         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3519         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3520                         &cap_idx) == NULL)
3521                 return TEST_SKIPPED;
3522
3523         /* Create KASUMI session */
3524         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3525                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3526                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3527                                         tdata->key.data, tdata->key.len,
3528                                         tdata->cipher_iv.len);
3529         if (retval < 0)
3530                 return retval;
3531
3532         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3533
3534         /* Clear mbuf payload */
3535         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3536                rte_pktmbuf_tailroom(ut_params->ibuf));
3537
3538         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3539         /* Append data which is padded to a multiple */
3540         /* of the algorithms block size */
3541         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3542         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3543                                 plaintext_pad_len);
3544         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3545
3546         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3547
3548         /* Create KASUMI operation */
3549         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3550                                 tdata->cipher_iv.len,
3551                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3552                                 tdata->validCipherOffsetInBits.len);
3553         if (retval < 0)
3554                 return retval;
3555
3556         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3557                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3558                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3559         else
3560                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3561                                 ut_params->op);
3562         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3563
3564         ut_params->obuf = ut_params->op->sym->m_dst;
3565         if (ut_params->obuf)
3566                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3567         else
3568                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3569
3570         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3571
3572         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3573                                 (tdata->validCipherOffsetInBits.len >> 3);
3574         /* Validate obuf */
3575         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3576                 ciphertext,
3577                 reference_ciphertext,
3578                 tdata->validCipherLenInBits.len,
3579                 "KASUMI Ciphertext data not as expected");
3580         return 0;
3581 }
3582
3583 static int
3584 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3585 {
3586         struct crypto_testsuite_params *ts_params = &testsuite_params;
3587         struct crypto_unittest_params *ut_params = &unittest_params;
3588
3589         int retval;
3590
3591         unsigned int plaintext_pad_len;
3592         unsigned int plaintext_len;
3593
3594         uint8_t buffer[10000];
3595         const uint8_t *ciphertext;
3596
3597         struct rte_cryptodev_info dev_info;
3598
3599         /* Verify the capabilities */
3600         struct rte_cryptodev_sym_capability_idx cap_idx;
3601         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3602         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3603         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3604                         &cap_idx) == NULL)
3605                 return TEST_SKIPPED;
3606
3607         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3608
3609         uint64_t feat_flags = dev_info.feature_flags;
3610
3611         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3612                 printf("Device doesn't support in-place scatter-gather. "
3613                                 "Test Skipped.\n");
3614                 return TEST_SKIPPED;
3615         }
3616
3617         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3618                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3619                 printf("Device doesn't support RAW data-path APIs.\n");
3620                 return TEST_SKIPPED;
3621         }
3622
3623         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3624                 return TEST_SKIPPED;
3625
3626         /* Create KASUMI session */
3627         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3628                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3629                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3630                                         tdata->key.data, tdata->key.len,
3631                                         tdata->cipher_iv.len);
3632         if (retval < 0)
3633                 return retval;
3634
3635         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3636
3637
3638         /* Append data which is padded to a multiple */
3639         /* of the algorithms block size */
3640         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3641
3642         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3643                         plaintext_pad_len, 10, 0);
3644
3645         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3646
3647         /* Create KASUMI operation */
3648         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3649                                 tdata->cipher_iv.len,
3650                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3651                                 tdata->validCipherOffsetInBits.len);
3652         if (retval < 0)
3653                 return retval;
3654
3655         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3656                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3657                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3658         else
3659                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3660                                                 ut_params->op);
3661         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3662
3663         ut_params->obuf = ut_params->op->sym->m_dst;
3664
3665         if (ut_params->obuf)
3666                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3667                                 plaintext_len, buffer);
3668         else
3669                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3670                                 tdata->validCipherOffsetInBits.len >> 3,
3671                                 plaintext_len, buffer);
3672
3673         /* Validate obuf */
3674         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3675
3676         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3677                                 (tdata->validCipherOffsetInBits.len >> 3);
3678         /* Validate obuf */
3679         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3680                 ciphertext,
3681                 reference_ciphertext,
3682                 tdata->validCipherLenInBits.len,
3683                 "KASUMI Ciphertext data not as expected");
3684         return 0;
3685 }
3686
3687 static int
3688 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3689 {
3690         struct crypto_testsuite_params *ts_params = &testsuite_params;
3691         struct crypto_unittest_params *ut_params = &unittest_params;
3692
3693         int retval;
3694         uint8_t *plaintext, *ciphertext;
3695         unsigned plaintext_pad_len;
3696         unsigned plaintext_len;
3697
3698         /* Verify the capabilities */
3699         struct rte_cryptodev_sym_capability_idx cap_idx;
3700         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3701         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3702         /* Data-path service does not support OOP */
3703         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3704                         &cap_idx) == NULL)
3705                 return TEST_SKIPPED;
3706
3707         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3708                 return TEST_SKIPPED;
3709
3710         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3711                 return TEST_SKIPPED;
3712
3713         /* Create KASUMI session */
3714         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3715                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3716                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3717                                         tdata->key.data, tdata->key.len,
3718                                         tdata->cipher_iv.len);
3719         if (retval < 0)
3720                 return retval;
3721
3722         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3723         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3724
3725         /* Clear mbuf payload */
3726         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3727                rte_pktmbuf_tailroom(ut_params->ibuf));
3728
3729         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3730         /* Append data which is padded to a multiple */
3731         /* of the algorithms block size */
3732         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3733         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3734                                 plaintext_pad_len);
3735         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3736         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3737
3738         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3739
3740         /* Create KASUMI operation */
3741         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3742                                 tdata->cipher_iv.len,
3743                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3744                                 tdata->validCipherOffsetInBits.len);
3745         if (retval < 0)
3746                 return retval;
3747
3748         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3749                                                 ut_params->op);
3750         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3751
3752         ut_params->obuf = ut_params->op->sym->m_dst;
3753         if (ut_params->obuf)
3754                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3755         else
3756                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3757
3758         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3759
3760         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3761                                 (tdata->validCipherOffsetInBits.len >> 3);
3762         /* Validate obuf */
3763         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3764                 ciphertext,
3765                 reference_ciphertext,
3766                 tdata->validCipherLenInBits.len,
3767                 "KASUMI Ciphertext data not as expected");
3768         return 0;
3769 }
3770
3771 static int
3772 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3773 {
3774         struct crypto_testsuite_params *ts_params = &testsuite_params;
3775         struct crypto_unittest_params *ut_params = &unittest_params;
3776
3777         int retval;
3778         unsigned int plaintext_pad_len;
3779         unsigned int plaintext_len;
3780
3781         const uint8_t *ciphertext;
3782         uint8_t buffer[2048];
3783
3784         struct rte_cryptodev_info dev_info;
3785
3786         /* Verify the capabilities */
3787         struct rte_cryptodev_sym_capability_idx cap_idx;
3788         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3789         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3790         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3791                         &cap_idx) == NULL)
3792                 return TEST_SKIPPED;
3793
3794         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3795                 return TEST_SKIPPED;
3796
3797         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3798                 return TEST_SKIPPED;
3799
3800         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3801
3802         uint64_t feat_flags = dev_info.feature_flags;
3803         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3804                 printf("Device doesn't support out-of-place scatter-gather "
3805                                 "in both input and output mbufs. "
3806                                 "Test Skipped.\n");
3807                 return TEST_SKIPPED;
3808         }
3809
3810         /* Create KASUMI session */
3811         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3812                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3813                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3814                                         tdata->key.data, tdata->key.len,
3815                                         tdata->cipher_iv.len);
3816         if (retval < 0)
3817                 return retval;
3818
3819         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3820         /* Append data which is padded to a multiple */
3821         /* of the algorithms block size */
3822         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3823
3824         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3825                         plaintext_pad_len, 10, 0);
3826         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3827                         plaintext_pad_len, 3, 0);
3828
3829         /* Append data which is padded to a multiple */
3830         /* of the algorithms block size */
3831         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3832
3833         /* Create KASUMI operation */
3834         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3835                                 tdata->cipher_iv.len,
3836                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3837                                 tdata->validCipherOffsetInBits.len);
3838         if (retval < 0)
3839                 return retval;
3840
3841         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3842                                                 ut_params->op);
3843         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3844
3845         ut_params->obuf = ut_params->op->sym->m_dst;
3846         if (ut_params->obuf)
3847                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3848                                 plaintext_pad_len, buffer);
3849         else
3850                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3851                                 tdata->validCipherOffsetInBits.len >> 3,
3852                                 plaintext_pad_len, buffer);
3853
3854         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3855                                 (tdata->validCipherOffsetInBits.len >> 3);
3856         /* Validate obuf */
3857         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3858                 ciphertext,
3859                 reference_ciphertext,
3860                 tdata->validCipherLenInBits.len,
3861                 "KASUMI Ciphertext data not as expected");
3862         return 0;
3863 }
3864
3865
3866 static int
3867 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3868 {
3869         struct crypto_testsuite_params *ts_params = &testsuite_params;
3870         struct crypto_unittest_params *ut_params = &unittest_params;
3871
3872         int retval;
3873         uint8_t *ciphertext, *plaintext;
3874         unsigned ciphertext_pad_len;
3875         unsigned ciphertext_len;
3876
3877         /* Verify the capabilities */
3878         struct rte_cryptodev_sym_capability_idx cap_idx;
3879         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3880         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3881         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3882                         &cap_idx) == NULL)
3883                 return TEST_SKIPPED;
3884
3885         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3886                 return TEST_SKIPPED;
3887
3888         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3889                 return TEST_SKIPPED;
3890
3891         /* Create KASUMI session */
3892         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3893                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3894                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3895                                         tdata->key.data, tdata->key.len,
3896                                         tdata->cipher_iv.len);
3897         if (retval < 0)
3898                 return retval;
3899
3900         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3901         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3902
3903         /* Clear mbuf payload */
3904         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3905                rte_pktmbuf_tailroom(ut_params->ibuf));
3906
3907         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3908         /* Append data which is padded to a multiple */
3909         /* of the algorithms block size */
3910         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3911         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3912                                 ciphertext_pad_len);
3913         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3914         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3915
3916         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3917
3918         /* Create KASUMI operation */
3919         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3920                                 tdata->cipher_iv.len,
3921                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3922                                 tdata->validCipherOffsetInBits.len);
3923         if (retval < 0)
3924                 return retval;
3925
3926         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3927                                                 ut_params->op);
3928         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3929
3930         ut_params->obuf = ut_params->op->sym->m_dst;
3931         if (ut_params->obuf)
3932                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3933         else
3934                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3935
3936         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3937
3938         const uint8_t *reference_plaintext = tdata->plaintext.data +
3939                                 (tdata->validCipherOffsetInBits.len >> 3);
3940         /* Validate obuf */
3941         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3942                 plaintext,
3943                 reference_plaintext,
3944                 tdata->validCipherLenInBits.len,
3945                 "KASUMI Plaintext data not as expected");
3946         return 0;
3947 }
3948
3949 static int
3950 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3951 {
3952         struct crypto_testsuite_params *ts_params = &testsuite_params;
3953         struct crypto_unittest_params *ut_params = &unittest_params;
3954
3955         int retval;
3956         uint8_t *ciphertext, *plaintext;
3957         unsigned ciphertext_pad_len;
3958         unsigned ciphertext_len;
3959         struct rte_cryptodev_info dev_info;
3960
3961         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3962         uint64_t feat_flags = dev_info.feature_flags;
3963
3964         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3965                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3966                 printf("Device doesn't support RAW data-path APIs.\n");
3967                 return TEST_SKIPPED;
3968         }
3969
3970         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3971                 return TEST_SKIPPED;
3972
3973         /* Verify the capabilities */
3974         struct rte_cryptodev_sym_capability_idx cap_idx;
3975         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3976         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3977         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3978                         &cap_idx) == NULL)
3979                 return TEST_SKIPPED;
3980
3981         /* Create KASUMI session */
3982         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3983                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3984                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3985                                         tdata->key.data, tdata->key.len,
3986                                         tdata->cipher_iv.len);
3987         if (retval < 0)
3988                 return retval;
3989
3990         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3991
3992         /* Clear mbuf payload */
3993         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3994                rte_pktmbuf_tailroom(ut_params->ibuf));
3995
3996         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3997         /* Append data which is padded to a multiple */
3998         /* of the algorithms block size */
3999         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4000         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4001                                 ciphertext_pad_len);
4002         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4003
4004         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4005
4006         /* Create KASUMI operation */
4007         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4008                                         tdata->cipher_iv.len,
4009                                         tdata->ciphertext.len,
4010                                         tdata->validCipherOffsetInBits.len);
4011         if (retval < 0)
4012                 return retval;
4013
4014         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4015                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4016                                 ut_params->op, 1, 0, 1, 0);
4017         else
4018                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4019                                                 ut_params->op);
4020         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4021
4022         ut_params->obuf = ut_params->op->sym->m_dst;
4023         if (ut_params->obuf)
4024                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4025         else
4026                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4027
4028         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4029
4030         const uint8_t *reference_plaintext = tdata->plaintext.data +
4031                                 (tdata->validCipherOffsetInBits.len >> 3);
4032         /* Validate obuf */
4033         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4034                 plaintext,
4035                 reference_plaintext,
4036                 tdata->validCipherLenInBits.len,
4037                 "KASUMI Plaintext data not as expected");
4038         return 0;
4039 }
4040
4041 static int
4042 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4043 {
4044         struct crypto_testsuite_params *ts_params = &testsuite_params;
4045         struct crypto_unittest_params *ut_params = &unittest_params;
4046
4047         int retval;
4048         uint8_t *plaintext, *ciphertext;
4049         unsigned plaintext_pad_len;
4050         unsigned plaintext_len;
4051         struct rte_cryptodev_info dev_info;
4052
4053         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4054         uint64_t feat_flags = dev_info.feature_flags;
4055
4056         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4057                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4058                 printf("Device doesn't support RAW data-path APIs.\n");
4059                 return TEST_SKIPPED;
4060         }
4061
4062         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4063                 return TEST_SKIPPED;
4064
4065         /* Verify the capabilities */
4066         struct rte_cryptodev_sym_capability_idx cap_idx;
4067         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4068         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4069         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4070                         &cap_idx) == NULL)
4071                 return TEST_SKIPPED;
4072
4073         /* Create SNOW 3G session */
4074         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4075                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4076                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4077                                         tdata->key.data, tdata->key.len,
4078                                         tdata->cipher_iv.len);
4079         if (retval < 0)
4080                 return retval;
4081
4082         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4083
4084         /* Clear mbuf payload */
4085         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4086                rte_pktmbuf_tailroom(ut_params->ibuf));
4087
4088         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4089         /* Append data which is padded to a multiple of */
4090         /* the algorithms block size */
4091         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4092         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4093                                 plaintext_pad_len);
4094         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4095
4096         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4097
4098         /* Create SNOW 3G operation */
4099         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4100                                         tdata->cipher_iv.len,
4101                                         tdata->validCipherLenInBits.len,
4102                                         0);
4103         if (retval < 0)
4104                 return retval;
4105
4106         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4107                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4108                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4109         else
4110                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4111                                                 ut_params->op);
4112         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4113
4114         ut_params->obuf = ut_params->op->sym->m_dst;
4115         if (ut_params->obuf)
4116                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4117         else
4118                 ciphertext = plaintext;
4119
4120         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4121
4122         /* Validate obuf */
4123         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4124                 ciphertext,
4125                 tdata->ciphertext.data,
4126                 tdata->validDataLenInBits.len,
4127                 "SNOW 3G Ciphertext data not as expected");
4128         return 0;
4129 }
4130
4131
4132 static int
4133 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4134 {
4135         struct crypto_testsuite_params *ts_params = &testsuite_params;
4136         struct crypto_unittest_params *ut_params = &unittest_params;
4137         uint8_t *plaintext, *ciphertext;
4138
4139         int retval;
4140         unsigned plaintext_pad_len;
4141         unsigned plaintext_len;
4142
4143         /* Verify the capabilities */
4144         struct rte_cryptodev_sym_capability_idx cap_idx;
4145         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4146         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4147         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4148                         &cap_idx) == NULL)
4149                 return TEST_SKIPPED;
4150
4151         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4152                 return TEST_SKIPPED;
4153
4154         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4155                 return TEST_SKIPPED;
4156
4157         /* Create SNOW 3G session */
4158         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4159                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4160                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4161                                         tdata->key.data, tdata->key.len,
4162                                         tdata->cipher_iv.len);
4163         if (retval < 0)
4164                 return retval;
4165
4166         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4167         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4168
4169         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4170                         "Failed to allocate input buffer in mempool");
4171         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4172                         "Failed to allocate output buffer in mempool");
4173
4174         /* Clear mbuf payload */
4175         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4176                rte_pktmbuf_tailroom(ut_params->ibuf));
4177
4178         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4179         /* Append data which is padded to a multiple of */
4180         /* the algorithms block size */
4181         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4182         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4183                                 plaintext_pad_len);
4184         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4185         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4186
4187         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4188
4189         /* Create SNOW 3G operation */
4190         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4191                                         tdata->cipher_iv.len,
4192                                         tdata->validCipherLenInBits.len,
4193                                         0);
4194         if (retval < 0)
4195                 return retval;
4196
4197         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4198                                                 ut_params->op);
4199         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4200
4201         ut_params->obuf = ut_params->op->sym->m_dst;
4202         if (ut_params->obuf)
4203                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4204         else
4205                 ciphertext = plaintext;
4206
4207         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4208
4209         /* Validate obuf */
4210         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4211                 ciphertext,
4212                 tdata->ciphertext.data,
4213                 tdata->validDataLenInBits.len,
4214                 "SNOW 3G Ciphertext data not as expected");
4215         return 0;
4216 }
4217
4218 static int
4219 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4220 {
4221         struct crypto_testsuite_params *ts_params = &testsuite_params;
4222         struct crypto_unittest_params *ut_params = &unittest_params;
4223
4224         int retval;
4225         unsigned int plaintext_pad_len;
4226         unsigned int plaintext_len;
4227         uint8_t buffer[10000];
4228         const uint8_t *ciphertext;
4229
4230         struct rte_cryptodev_info dev_info;
4231
4232         /* Verify the capabilities */
4233         struct rte_cryptodev_sym_capability_idx cap_idx;
4234         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4235         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4236         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4237                         &cap_idx) == NULL)
4238                 return TEST_SKIPPED;
4239
4240         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4241                 return TEST_SKIPPED;
4242
4243         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4244                 return TEST_SKIPPED;
4245
4246         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4247
4248         uint64_t feat_flags = dev_info.feature_flags;
4249
4250         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4251                 printf("Device doesn't support out-of-place scatter-gather "
4252                                 "in both input and output mbufs. "
4253                                 "Test Skipped.\n");
4254                 return TEST_SKIPPED;
4255         }
4256
4257         /* Create SNOW 3G session */
4258         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4259                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4260                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4261                                         tdata->key.data, tdata->key.len,
4262                                         tdata->cipher_iv.len);
4263         if (retval < 0)
4264                 return retval;
4265
4266         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4267         /* Append data which is padded to a multiple of */
4268         /* the algorithms block size */
4269         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4270
4271         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4272                         plaintext_pad_len, 10, 0);
4273         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4274                         plaintext_pad_len, 3, 0);
4275
4276         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4277                         "Failed to allocate input buffer in mempool");
4278         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4279                         "Failed to allocate output buffer in mempool");
4280
4281         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4282
4283         /* Create SNOW 3G operation */
4284         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4285                                         tdata->cipher_iv.len,
4286                                         tdata->validCipherLenInBits.len,
4287                                         0);
4288         if (retval < 0)
4289                 return retval;
4290
4291         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4292                                                 ut_params->op);
4293         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4294
4295         ut_params->obuf = ut_params->op->sym->m_dst;
4296         if (ut_params->obuf)
4297                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4298                                 plaintext_len, buffer);
4299         else
4300                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4301                                 plaintext_len, buffer);
4302
4303         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4304
4305         /* Validate obuf */
4306         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4307                 ciphertext,
4308                 tdata->ciphertext.data,
4309                 tdata->validDataLenInBits.len,
4310                 "SNOW 3G Ciphertext data not as expected");
4311
4312         return 0;
4313 }
4314
4315 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4316 static void
4317 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4318 {
4319         uint8_t curr_byte, prev_byte;
4320         uint32_t length_in_bytes = ceil_byte_length(length + offset);
4321         uint8_t lower_byte_mask = (1 << offset) - 1;
4322         unsigned i;
4323
4324         prev_byte = buffer[0];
4325         buffer[0] >>= offset;
4326
4327         for (i = 1; i < length_in_bytes; i++) {
4328                 curr_byte = buffer[i];
4329                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4330                                 (curr_byte >> offset);
4331                 prev_byte = curr_byte;
4332         }
4333 }
4334
4335 static int
4336 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4337 {
4338         struct crypto_testsuite_params *ts_params = &testsuite_params;
4339         struct crypto_unittest_params *ut_params = &unittest_params;
4340         uint8_t *plaintext, *ciphertext;
4341         int retval;
4342         uint32_t plaintext_len;
4343         uint32_t plaintext_pad_len;
4344         uint8_t extra_offset = 4;
4345         uint8_t *expected_ciphertext_shifted;
4346         struct rte_cryptodev_info dev_info;
4347
4348         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4349         uint64_t feat_flags = dev_info.feature_flags;
4350
4351         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4352                         ((tdata->validDataLenInBits.len % 8) != 0)) {
4353                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4354                 return TEST_SKIPPED;
4355         }
4356
4357         /* Verify the capabilities */
4358         struct rte_cryptodev_sym_capability_idx cap_idx;
4359         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4360         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4361         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4362                         &cap_idx) == NULL)
4363                 return TEST_SKIPPED;
4364
4365         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4366                 return TEST_SKIPPED;
4367
4368         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4369                 return TEST_SKIPPED;
4370
4371         /* Create SNOW 3G session */
4372         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4373                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4374                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4375                                         tdata->key.data, tdata->key.len,
4376                                         tdata->cipher_iv.len);
4377         if (retval < 0)
4378                 return retval;
4379
4380         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4381         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4382
4383         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4384                         "Failed to allocate input buffer in mempool");
4385         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4386                         "Failed to allocate output buffer in mempool");
4387
4388         /* Clear mbuf payload */
4389         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4390                rte_pktmbuf_tailroom(ut_params->ibuf));
4391
4392         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4393         /*
4394          * Append data which is padded to a
4395          * multiple of the algorithms block size
4396          */
4397         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4398
4399         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4400                                                 plaintext_pad_len);
4401
4402         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4403
4404         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4405         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4406
4407 #ifdef RTE_APP_TEST_DEBUG
4408         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4409 #endif
4410         /* Create SNOW 3G operation */
4411         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4412                                         tdata->cipher_iv.len,
4413                                         tdata->validCipherLenInBits.len,
4414                                         extra_offset);
4415         if (retval < 0)
4416                 return retval;
4417
4418         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4419                                                 ut_params->op);
4420         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4421
4422         ut_params->obuf = ut_params->op->sym->m_dst;
4423         if (ut_params->obuf)
4424                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4425         else
4426                 ciphertext = plaintext;
4427
4428 #ifdef RTE_APP_TEST_DEBUG
4429         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4430 #endif
4431
4432         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4433
4434         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4435                         "failed to reserve memory for ciphertext shifted\n");
4436
4437         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4438                         ceil_byte_length(tdata->ciphertext.len));
4439         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4440                         extra_offset);
4441         /* Validate obuf */
4442         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4443                 ciphertext,
4444                 expected_ciphertext_shifted,
4445                 tdata->validDataLenInBits.len,
4446                 extra_offset,
4447                 "SNOW 3G Ciphertext data not as expected");
4448         return 0;
4449 }
4450
4451 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4452 {
4453         struct crypto_testsuite_params *ts_params = &testsuite_params;
4454         struct crypto_unittest_params *ut_params = &unittest_params;
4455
4456         int retval;
4457
4458         uint8_t *plaintext, *ciphertext;
4459         unsigned ciphertext_pad_len;
4460         unsigned ciphertext_len;
4461         struct rte_cryptodev_info dev_info;
4462
4463         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4464         uint64_t feat_flags = dev_info.feature_flags;
4465
4466         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4467                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4468                 printf("Device doesn't support RAW data-path APIs.\n");
4469                 return TEST_SKIPPED;
4470         }
4471
4472         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4473                 return TEST_SKIPPED;
4474
4475         /* Verify the capabilities */
4476         struct rte_cryptodev_sym_capability_idx cap_idx;
4477         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4478         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4479         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4480                         &cap_idx) == NULL)
4481                 return TEST_SKIPPED;
4482
4483         /* Create SNOW 3G session */
4484         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4485                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4486                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4487                                         tdata->key.data, tdata->key.len,
4488                                         tdata->cipher_iv.len);
4489         if (retval < 0)
4490                 return retval;
4491
4492         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4493
4494         /* Clear mbuf payload */
4495         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4496                rte_pktmbuf_tailroom(ut_params->ibuf));
4497
4498         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4499         /* Append data which is padded to a multiple of */
4500         /* the algorithms block size */
4501         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4502         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4503                                 ciphertext_pad_len);
4504         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4505
4506         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4507
4508         /* Create SNOW 3G operation */
4509         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4510                                         tdata->cipher_iv.len,
4511                                         tdata->validCipherLenInBits.len,
4512                                         tdata->cipher.offset_bits);
4513         if (retval < 0)
4514                 return retval;
4515
4516         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4517                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4518                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4519         else
4520                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4521                                                 ut_params->op);
4522         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4523         ut_params->obuf = ut_params->op->sym->m_dst;
4524         if (ut_params->obuf)
4525                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4526         else
4527                 plaintext = ciphertext;
4528
4529         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4530
4531         /* Validate obuf */
4532         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4533                                 tdata->plaintext.data,
4534                                 tdata->validDataLenInBits.len,
4535                                 "SNOW 3G Plaintext data not as expected");
4536         return 0;
4537 }
4538
4539 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4540 {
4541         struct crypto_testsuite_params *ts_params = &testsuite_params;
4542         struct crypto_unittest_params *ut_params = &unittest_params;
4543
4544         int retval;
4545
4546         uint8_t *plaintext, *ciphertext;
4547         unsigned ciphertext_pad_len;
4548         unsigned ciphertext_len;
4549
4550         /* Verify the capabilities */
4551         struct rte_cryptodev_sym_capability_idx cap_idx;
4552         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4553         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4554         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4555                         &cap_idx) == NULL)
4556                 return TEST_SKIPPED;
4557
4558         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4559                 return TEST_SKIPPED;
4560
4561         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4562                 return TEST_SKIPPED;
4563
4564         /* Create SNOW 3G session */
4565         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4566                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4567                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4568                                         tdata->key.data, tdata->key.len,
4569                                         tdata->cipher_iv.len);
4570         if (retval < 0)
4571                 return retval;
4572
4573         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4574         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4575
4576         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4577                         "Failed to allocate input buffer");
4578         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4579                         "Failed to allocate output buffer");
4580
4581         /* Clear mbuf payload */
4582         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4583                rte_pktmbuf_tailroom(ut_params->ibuf));
4584
4585         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4586                        rte_pktmbuf_tailroom(ut_params->obuf));
4587
4588         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4589         /* Append data which is padded to a multiple of */
4590         /* the algorithms block size */
4591         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4592         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4593                                 ciphertext_pad_len);
4594         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4595         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4596
4597         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4598
4599         /* Create SNOW 3G operation */
4600         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4601                                         tdata->cipher_iv.len,
4602                                         tdata->validCipherLenInBits.len,
4603                                         0);
4604         if (retval < 0)
4605                 return retval;
4606
4607         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4608                                                 ut_params->op);
4609         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4610         ut_params->obuf = ut_params->op->sym->m_dst;
4611         if (ut_params->obuf)
4612                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4613         else
4614                 plaintext = ciphertext;
4615
4616         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4617
4618         /* Validate obuf */
4619         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4620                                 tdata->plaintext.data,
4621                                 tdata->validDataLenInBits.len,
4622                                 "SNOW 3G Plaintext data not as expected");
4623         return 0;
4624 }
4625
4626 static int
4627 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4628 {
4629         struct crypto_testsuite_params *ts_params = &testsuite_params;
4630         struct crypto_unittest_params *ut_params = &unittest_params;
4631
4632         int retval;
4633
4634         uint8_t *plaintext, *ciphertext;
4635         unsigned int plaintext_pad_len;
4636         unsigned int plaintext_len;
4637
4638         struct rte_cryptodev_info dev_info;
4639         struct rte_cryptodev_sym_capability_idx cap_idx;
4640
4641         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4642         uint64_t feat_flags = dev_info.feature_flags;
4643
4644         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4645                         ((tdata->validAuthLenInBits.len % 8 != 0) ||
4646                         (tdata->validDataLenInBits.len % 8 != 0))) {
4647                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4648                 return TEST_SKIPPED;
4649         }
4650
4651         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4652                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4653                 printf("Device doesn't support RAW data-path APIs.\n");
4654                 return TEST_SKIPPED;
4655         }
4656
4657         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4658                 return TEST_SKIPPED;
4659
4660         /* Check if device supports ZUC EEA3 */
4661         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4662         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4663
4664         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4665                         &cap_idx) == NULL)
4666                 return TEST_SKIPPED;
4667
4668         /* Check if device supports ZUC EIA3 */
4669         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4670         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4671
4672         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4673                         &cap_idx) == NULL)
4674                 return TEST_SKIPPED;
4675
4676         /* Create ZUC session */
4677         retval = create_zuc_cipher_auth_encrypt_generate_session(
4678                         ts_params->valid_devs[0],
4679                         tdata);
4680         if (retval != 0)
4681                 return retval;
4682         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4683
4684         /* clear mbuf payload */
4685         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4686                         rte_pktmbuf_tailroom(ut_params->ibuf));
4687
4688         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4689         /* Append data which is padded to a multiple of */
4690         /* the algorithms block size */
4691         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4692         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4693                                 plaintext_pad_len);
4694         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4695
4696         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4697
4698         /* Create ZUC operation */
4699         retval = create_zuc_cipher_hash_generate_operation(tdata);
4700         if (retval < 0)
4701                 return retval;
4702
4703         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4704                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4705                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4706         else
4707                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4708                         ut_params->op);
4709         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4710         ut_params->obuf = ut_params->op->sym->m_src;
4711         if (ut_params->obuf)
4712                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4713         else
4714                 ciphertext = plaintext;
4715
4716         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4717         /* Validate obuf */
4718         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4719                         ciphertext,
4720                         tdata->ciphertext.data,
4721                         tdata->validDataLenInBits.len,
4722                         "ZUC Ciphertext data not as expected");
4723
4724         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4725             + plaintext_pad_len;
4726
4727         /* Validate obuf */
4728         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4729                         ut_params->digest,
4730                         tdata->digest.data,
4731                         4,
4732                         "ZUC Generated auth tag not as expected");
4733         return 0;
4734 }
4735
4736 static int
4737 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4738 {
4739         struct crypto_testsuite_params *ts_params = &testsuite_params;
4740         struct crypto_unittest_params *ut_params = &unittest_params;
4741
4742         int retval;
4743
4744         uint8_t *plaintext, *ciphertext;
4745         unsigned plaintext_pad_len;
4746         unsigned plaintext_len;
4747         struct rte_cryptodev_info dev_info;
4748
4749         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4750         uint64_t feat_flags = dev_info.feature_flags;
4751
4752         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4753                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4754                 printf("Device doesn't support RAW data-path APIs.\n");
4755                 return TEST_SKIPPED;
4756         }
4757
4758         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4759                 return TEST_SKIPPED;
4760
4761         /* Verify the capabilities */
4762         struct rte_cryptodev_sym_capability_idx cap_idx;
4763         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4764         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4765         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4766                         &cap_idx) == NULL)
4767                 return TEST_SKIPPED;
4768         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4769         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4770         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4771                         &cap_idx) == NULL)
4772                 return TEST_SKIPPED;
4773
4774         /* Create SNOW 3G session */
4775         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4776                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4777                         RTE_CRYPTO_AUTH_OP_GENERATE,
4778                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4779                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4780                         tdata->key.data, tdata->key.len,
4781                         tdata->auth_iv.len, tdata->digest.len,
4782                         tdata->cipher_iv.len);
4783         if (retval != 0)
4784                 return retval;
4785         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4786
4787         /* clear mbuf payload */
4788         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4789                         rte_pktmbuf_tailroom(ut_params->ibuf));
4790
4791         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4792         /* Append data which is padded to a multiple of */
4793         /* the algorithms block size */
4794         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4795         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4796                                 plaintext_pad_len);
4797         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4798
4799         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4800
4801         /* Create SNOW 3G operation */
4802         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4803                         tdata->digest.len, tdata->auth_iv.data,
4804                         tdata->auth_iv.len,
4805                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4806                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4807                         tdata->validCipherLenInBits.len,
4808                         0,
4809                         tdata->validAuthLenInBits.len,
4810                         0
4811                         );
4812         if (retval < 0)
4813                 return retval;
4814
4815         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4816                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4817                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4818         else
4819                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4820                         ut_params->op);
4821         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4822         ut_params->obuf = ut_params->op->sym->m_src;
4823         if (ut_params->obuf)
4824                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4825         else
4826                 ciphertext = plaintext;
4827
4828         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4829         /* Validate obuf */
4830         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4831                         ciphertext,
4832                         tdata->ciphertext.data,
4833                         tdata->validDataLenInBits.len,
4834                         "SNOW 3G Ciphertext data not as expected");
4835
4836         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4837             + plaintext_pad_len;
4838
4839         /* Validate obuf */
4840         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4841                         ut_params->digest,
4842                         tdata->digest.data,
4843                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4844                         "SNOW 3G Generated auth tag not as expected");
4845         return 0;
4846 }
4847
4848 static int
4849 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4850         uint8_t op_mode, uint8_t verify)
4851 {
4852         struct crypto_testsuite_params *ts_params = &testsuite_params;
4853         struct crypto_unittest_params *ut_params = &unittest_params;
4854
4855         int retval;
4856
4857         uint8_t *plaintext = NULL, *ciphertext = NULL;
4858         unsigned int plaintext_pad_len;
4859         unsigned int plaintext_len;
4860         unsigned int ciphertext_pad_len;
4861         unsigned int ciphertext_len;
4862
4863         struct rte_cryptodev_info dev_info;
4864
4865         /* Verify the capabilities */
4866         struct rte_cryptodev_sym_capability_idx cap_idx;
4867         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4868         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4869         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4870                         &cap_idx) == NULL)
4871                 return TEST_SKIPPED;
4872         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4873         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4874         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4875                         &cap_idx) == NULL)
4876                 return TEST_SKIPPED;
4877
4878         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4879                 return TEST_SKIPPED;
4880
4881         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4882
4883         uint64_t feat_flags = dev_info.feature_flags;
4884
4885         if (op_mode == OUT_OF_PLACE) {
4886                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4887                         printf("Device doesn't support digest encrypted.\n");
4888                         return TEST_SKIPPED;
4889                 }
4890                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4891                         return TEST_SKIPPED;
4892         }
4893
4894         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4895                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4896                 printf("Device doesn't support RAW data-path APIs.\n");
4897                 return TEST_SKIPPED;
4898         }
4899
4900         /* Create SNOW 3G session */
4901         retval = create_wireless_algo_auth_cipher_session(
4902                         ts_params->valid_devs[0],
4903                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4904                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4905                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4906                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4907                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4908                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4909                         tdata->key.data, tdata->key.len,
4910                         tdata->auth_iv.len, tdata->digest.len,
4911                         tdata->cipher_iv.len);
4912         if (retval != 0)
4913                 return retval;
4914
4915         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4916         if (op_mode == OUT_OF_PLACE)
4917                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4918
4919         /* clear mbuf payload */
4920         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4921                 rte_pktmbuf_tailroom(ut_params->ibuf));
4922         if (op_mode == OUT_OF_PLACE)
4923                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4924                         rte_pktmbuf_tailroom(ut_params->obuf));
4925
4926         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4927         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4928         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4929         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4930
4931         if (verify) {
4932                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4933                                         ciphertext_pad_len);
4934                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4935                 if (op_mode == OUT_OF_PLACE)
4936                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4937                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4938                         ciphertext_len);
4939         } else {
4940                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4941                                         plaintext_pad_len);
4942                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4943                 if (op_mode == OUT_OF_PLACE)
4944                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4945                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4946         }
4947
4948         /* Create SNOW 3G operation */
4949         retval = create_wireless_algo_auth_cipher_operation(
4950                 tdata->digest.data, tdata->digest.len,
4951                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4952                 tdata->auth_iv.data, tdata->auth_iv.len,
4953                 (tdata->digest.offset_bytes == 0 ?
4954                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4955                         : tdata->digest.offset_bytes),
4956                 tdata->validCipherLenInBits.len,
4957                 tdata->cipher.offset_bits,
4958                 tdata->validAuthLenInBits.len,
4959                 tdata->auth.offset_bits,
4960                 op_mode, 0, verify);
4961
4962         if (retval < 0)
4963                 return retval;
4964
4965         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4966                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4967                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4968         else
4969                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4970                         ut_params->op);
4971
4972         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4973
4974         ut_params->obuf = (op_mode == IN_PLACE ?
4975                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4976
4977         if (verify) {
4978                 if (ut_params->obuf)
4979                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4980                                                         uint8_t *);
4981                 else
4982                         plaintext = ciphertext +
4983                                 (tdata->cipher.offset_bits >> 3);
4984
4985                 debug_hexdump(stdout, "plaintext:", plaintext,
4986                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4987                 debug_hexdump(stdout, "plaintext expected:",
4988                         tdata->plaintext.data,
4989                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4990         } else {
4991                 if (ut_params->obuf)
4992                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4993                                                         uint8_t *);
4994                 else
4995                         ciphertext = plaintext;
4996
4997                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4998                         ciphertext_len);
4999                 debug_hexdump(stdout, "ciphertext expected:",
5000                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5001
5002                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5003                         + (tdata->digest.offset_bytes == 0 ?
5004                 plaintext_pad_len : tdata->digest.offset_bytes);
5005
5006                 debug_hexdump(stdout, "digest:", ut_params->digest,
5007                         tdata->digest.len);
5008                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5009                                 tdata->digest.len);
5010         }
5011
5012         /* Validate obuf */
5013         if (verify) {
5014                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5015                         plaintext,
5016                         tdata->plaintext.data,
5017                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5018                          (tdata->digest.len << 3)),
5019                         tdata->cipher.offset_bits,
5020                         "SNOW 3G Plaintext data not as expected");
5021         } else {
5022                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5023                         ciphertext,
5024                         tdata->ciphertext.data,
5025                         (tdata->validDataLenInBits.len -
5026                          tdata->cipher.offset_bits),
5027                         tdata->cipher.offset_bits,
5028                         "SNOW 3G Ciphertext data not as expected");
5029
5030                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5031                         ut_params->digest,
5032                         tdata->digest.data,
5033                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5034                         "SNOW 3G Generated auth tag not as expected");
5035         }
5036         return 0;
5037 }
5038
5039 static int
5040 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5041         uint8_t op_mode, uint8_t verify)
5042 {
5043         struct crypto_testsuite_params *ts_params = &testsuite_params;
5044         struct crypto_unittest_params *ut_params = &unittest_params;
5045
5046         int retval;
5047
5048         const uint8_t *plaintext = NULL;
5049         const uint8_t *ciphertext = NULL;
5050         const uint8_t *digest = NULL;
5051         unsigned int plaintext_pad_len;
5052         unsigned int plaintext_len;
5053         unsigned int ciphertext_pad_len;
5054         unsigned int ciphertext_len;
5055         uint8_t buffer[10000];
5056         uint8_t digest_buffer[10000];
5057
5058         struct rte_cryptodev_info dev_info;
5059
5060         /* Verify the capabilities */
5061         struct rte_cryptodev_sym_capability_idx cap_idx;
5062         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5063         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5064         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5065                         &cap_idx) == NULL)
5066                 return TEST_SKIPPED;
5067         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5068         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5069         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5070                         &cap_idx) == NULL)
5071                 return TEST_SKIPPED;
5072
5073         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5074                 return TEST_SKIPPED;
5075
5076         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5077
5078         uint64_t feat_flags = dev_info.feature_flags;
5079
5080         if (op_mode == IN_PLACE) {
5081                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5082                         printf("Device doesn't support in-place scatter-gather "
5083                                         "in both input and output mbufs.\n");
5084                         return TEST_SKIPPED;
5085                 }
5086                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5087                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5088                         printf("Device doesn't support RAW data-path APIs.\n");
5089                         return TEST_SKIPPED;
5090                 }
5091         } else {
5092                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5093                         return TEST_SKIPPED;
5094                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5095                         printf("Device doesn't support out-of-place scatter-gather "
5096                                         "in both input and output mbufs.\n");
5097                         return TEST_SKIPPED;
5098                 }
5099                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5100                         printf("Device doesn't support digest encrypted.\n");
5101                         return TEST_SKIPPED;
5102                 }
5103         }
5104
5105         /* Create SNOW 3G session */
5106         retval = create_wireless_algo_auth_cipher_session(
5107                         ts_params->valid_devs[0],
5108                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5109                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5110                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5111                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5112                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5113                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5114                         tdata->key.data, tdata->key.len,
5115                         tdata->auth_iv.len, tdata->digest.len,
5116                         tdata->cipher_iv.len);
5117
5118         if (retval != 0)
5119                 return retval;
5120
5121         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5122         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5123         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5124         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5125
5126         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5127                         plaintext_pad_len, 15, 0);
5128         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5129                         "Failed to allocate input buffer in mempool");
5130
5131         if (op_mode == OUT_OF_PLACE) {
5132                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5133                                 plaintext_pad_len, 15, 0);
5134                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5135                                 "Failed to allocate output buffer in mempool");
5136         }
5137
5138         if (verify) {
5139                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5140                         tdata->ciphertext.data);
5141                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5142                                         ciphertext_len, buffer);
5143                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5144                         ciphertext_len);
5145         } else {
5146                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5147                         tdata->plaintext.data);
5148                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5149                                         plaintext_len, buffer);
5150                 debug_hexdump(stdout, "plaintext:", plaintext,
5151                         plaintext_len);
5152         }
5153         memset(buffer, 0, sizeof(buffer));
5154
5155         /* Create SNOW 3G operation */
5156         retval = create_wireless_algo_auth_cipher_operation(
5157                 tdata->digest.data, tdata->digest.len,
5158                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5159                 tdata->auth_iv.data, tdata->auth_iv.len,
5160                 (tdata->digest.offset_bytes == 0 ?
5161                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5162                         : tdata->digest.offset_bytes),
5163                 tdata->validCipherLenInBits.len,
5164                 tdata->cipher.offset_bits,
5165                 tdata->validAuthLenInBits.len,
5166                 tdata->auth.offset_bits,
5167                 op_mode, 1, verify);
5168
5169         if (retval < 0)
5170                 return retval;
5171
5172         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5173                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5174                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5175         else
5176                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5177                         ut_params->op);
5178
5179         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5180
5181         ut_params->obuf = (op_mode == IN_PLACE ?
5182                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5183
5184         if (verify) {
5185                 if (ut_params->obuf)
5186                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5187                                         plaintext_len, buffer);
5188                 else
5189                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5190                                         plaintext_len, buffer);
5191
5192                 debug_hexdump(stdout, "plaintext:", plaintext,
5193                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5194                 debug_hexdump(stdout, "plaintext expected:",
5195                         tdata->plaintext.data,
5196                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5197         } else {
5198                 if (ut_params->obuf)
5199                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5200                                         ciphertext_len, buffer);
5201                 else
5202                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5203                                         ciphertext_len, buffer);
5204
5205                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5206                         ciphertext_len);
5207                 debug_hexdump(stdout, "ciphertext expected:",
5208                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5209
5210                 if (ut_params->obuf)
5211                         digest = rte_pktmbuf_read(ut_params->obuf,
5212                                 (tdata->digest.offset_bytes == 0 ?
5213                                 plaintext_pad_len : tdata->digest.offset_bytes),
5214                                 tdata->digest.len, digest_buffer);
5215                 else
5216                         digest = rte_pktmbuf_read(ut_params->ibuf,
5217                                 (tdata->digest.offset_bytes == 0 ?
5218                                 plaintext_pad_len : tdata->digest.offset_bytes),
5219                                 tdata->digest.len, digest_buffer);
5220
5221                 debug_hexdump(stdout, "digest:", digest,
5222                         tdata->digest.len);
5223                 debug_hexdump(stdout, "digest expected:",
5224                         tdata->digest.data, tdata->digest.len);
5225         }
5226
5227         /* Validate obuf */
5228         if (verify) {
5229                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5230                         plaintext,
5231                         tdata->plaintext.data,
5232                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5233                          (tdata->digest.len << 3)),
5234                         tdata->cipher.offset_bits,
5235                         "SNOW 3G Plaintext data not as expected");
5236         } else {
5237                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5238                         ciphertext,
5239                         tdata->ciphertext.data,
5240                         (tdata->validDataLenInBits.len -
5241                          tdata->cipher.offset_bits),
5242                         tdata->cipher.offset_bits,
5243                         "SNOW 3G Ciphertext data not as expected");
5244
5245                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5246                         digest,
5247                         tdata->digest.data,
5248                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5249                         "SNOW 3G Generated auth tag not as expected");
5250         }
5251         return 0;
5252 }
5253
5254 static int
5255 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5256         uint8_t op_mode, uint8_t verify)
5257 {
5258         struct crypto_testsuite_params *ts_params = &testsuite_params;
5259         struct crypto_unittest_params *ut_params = &unittest_params;
5260
5261         int retval;
5262
5263         uint8_t *plaintext = NULL, *ciphertext = NULL;
5264         unsigned int plaintext_pad_len;
5265         unsigned int plaintext_len;
5266         unsigned int ciphertext_pad_len;
5267         unsigned int ciphertext_len;
5268
5269         struct rte_cryptodev_info dev_info;
5270
5271         /* Verify the capabilities */
5272         struct rte_cryptodev_sym_capability_idx cap_idx;
5273         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5274         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5275         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5276                         &cap_idx) == NULL)
5277                 return TEST_SKIPPED;
5278         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5279         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5280         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5281                         &cap_idx) == NULL)
5282                 return TEST_SKIPPED;
5283
5284         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5285
5286         uint64_t feat_flags = dev_info.feature_flags;
5287
5288         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5289                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5290                 printf("Device doesn't support RAW data-path APIs.\n");
5291                 return TEST_SKIPPED;
5292         }
5293
5294         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5295                 return TEST_SKIPPED;
5296
5297         if (op_mode == OUT_OF_PLACE) {
5298                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5299                         return TEST_SKIPPED;
5300                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5301                         printf("Device doesn't support digest encrypted.\n");
5302                         return TEST_SKIPPED;
5303                 }
5304         }
5305
5306         /* Create KASUMI session */
5307         retval = create_wireless_algo_auth_cipher_session(
5308                         ts_params->valid_devs[0],
5309                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5310                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5311                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5312                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5313                         RTE_CRYPTO_AUTH_KASUMI_F9,
5314                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5315                         tdata->key.data, tdata->key.len,
5316                         0, tdata->digest.len,
5317                         tdata->cipher_iv.len);
5318
5319         if (retval != 0)
5320                 return retval;
5321
5322         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5323         if (op_mode == OUT_OF_PLACE)
5324                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5325
5326         /* clear mbuf payload */
5327         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5328                 rte_pktmbuf_tailroom(ut_params->ibuf));
5329         if (op_mode == OUT_OF_PLACE)
5330                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5331                         rte_pktmbuf_tailroom(ut_params->obuf));
5332
5333         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5334         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5335         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5336         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5337
5338         if (verify) {
5339                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5340                                         ciphertext_pad_len);
5341                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5342                 if (op_mode == OUT_OF_PLACE)
5343                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5344                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5345                         ciphertext_len);
5346         } else {
5347                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5348                                         plaintext_pad_len);
5349                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5350                 if (op_mode == OUT_OF_PLACE)
5351                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5352                 debug_hexdump(stdout, "plaintext:", plaintext,
5353                         plaintext_len);
5354         }
5355
5356         /* Create KASUMI operation */
5357         retval = create_wireless_algo_auth_cipher_operation(
5358                 tdata->digest.data, tdata->digest.len,
5359                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5360                 NULL, 0,
5361                 (tdata->digest.offset_bytes == 0 ?
5362                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5363                         : tdata->digest.offset_bytes),
5364                 tdata->validCipherLenInBits.len,
5365                 tdata->validCipherOffsetInBits.len,
5366                 tdata->validAuthLenInBits.len,
5367                 0,
5368                 op_mode, 0, verify);
5369
5370         if (retval < 0)
5371                 return retval;
5372
5373         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5374                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5375                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5376         else
5377                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5378                         ut_params->op);
5379
5380         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5381
5382         ut_params->obuf = (op_mode == IN_PLACE ?
5383                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5384
5385
5386         if (verify) {
5387                 if (ut_params->obuf)
5388                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5389                                                         uint8_t *);
5390                 else
5391                         plaintext = ciphertext;
5392
5393                 debug_hexdump(stdout, "plaintext:", plaintext,
5394                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5395                 debug_hexdump(stdout, "plaintext expected:",
5396                         tdata->plaintext.data,
5397                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5398         } else {
5399                 if (ut_params->obuf)
5400                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5401                                                         uint8_t *);
5402                 else
5403                         ciphertext = plaintext;
5404
5405                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5406                         ciphertext_len);
5407                 debug_hexdump(stdout, "ciphertext expected:",
5408                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5409
5410                 ut_params->digest = rte_pktmbuf_mtod(
5411                         ut_params->obuf, uint8_t *) +
5412                         (tdata->digest.offset_bytes == 0 ?
5413                         plaintext_pad_len : tdata->digest.offset_bytes);
5414
5415                 debug_hexdump(stdout, "digest:", ut_params->digest,
5416                         tdata->digest.len);
5417                 debug_hexdump(stdout, "digest expected:",
5418                         tdata->digest.data, tdata->digest.len);
5419         }
5420
5421         /* Validate obuf */
5422         if (verify) {
5423                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5424                         plaintext,
5425                         tdata->plaintext.data,
5426                         tdata->plaintext.len >> 3,
5427                         "KASUMI Plaintext data not as expected");
5428         } else {
5429                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5430                         ciphertext,
5431                         tdata->ciphertext.data,
5432                         tdata->ciphertext.len >> 3,
5433                         "KASUMI Ciphertext data not as expected");
5434
5435                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5436                         ut_params->digest,
5437                         tdata->digest.data,
5438                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5439                         "KASUMI Generated auth tag not as expected");
5440         }
5441         return 0;
5442 }
5443
5444 static int
5445 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5446         uint8_t op_mode, uint8_t verify)
5447 {
5448         struct crypto_testsuite_params *ts_params = &testsuite_params;
5449         struct crypto_unittest_params *ut_params = &unittest_params;
5450
5451         int retval;
5452
5453         const uint8_t *plaintext = NULL;
5454         const uint8_t *ciphertext = NULL;
5455         const uint8_t *digest = NULL;
5456         unsigned int plaintext_pad_len;
5457         unsigned int plaintext_len;
5458         unsigned int ciphertext_pad_len;
5459         unsigned int ciphertext_len;
5460         uint8_t buffer[10000];
5461         uint8_t digest_buffer[10000];
5462
5463         struct rte_cryptodev_info dev_info;
5464
5465         /* Verify the capabilities */
5466         struct rte_cryptodev_sym_capability_idx cap_idx;
5467         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5468         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5469         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5470                         &cap_idx) == NULL)
5471                 return TEST_SKIPPED;
5472         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5473         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5474         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5475                         &cap_idx) == NULL)
5476                 return TEST_SKIPPED;
5477
5478         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5479                 return TEST_SKIPPED;
5480
5481         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5482
5483         uint64_t feat_flags = dev_info.feature_flags;
5484
5485         if (op_mode == IN_PLACE) {
5486                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5487                         printf("Device doesn't support in-place scatter-gather "
5488                                         "in both input and output mbufs.\n");
5489                         return TEST_SKIPPED;
5490                 }
5491                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5492                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5493                         printf("Device doesn't support RAW data-path APIs.\n");
5494                         return TEST_SKIPPED;
5495                 }
5496         } else {
5497                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5498                         return TEST_SKIPPED;
5499                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5500                         printf("Device doesn't support out-of-place scatter-gather "
5501                                         "in both input and output mbufs.\n");
5502                         return TEST_SKIPPED;
5503                 }
5504                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5505                         printf("Device doesn't support digest encrypted.\n");
5506                         return TEST_SKIPPED;
5507                 }
5508         }
5509
5510         /* Create KASUMI session */
5511         retval = create_wireless_algo_auth_cipher_session(
5512                         ts_params->valid_devs[0],
5513                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5514                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5515                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5516                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5517                         RTE_CRYPTO_AUTH_KASUMI_F9,
5518                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5519                         tdata->key.data, tdata->key.len,
5520                         0, tdata->digest.len,
5521                         tdata->cipher_iv.len);
5522
5523         if (retval != 0)
5524                 return retval;
5525
5526         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5527         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5528         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5529         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5530
5531         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5532                         plaintext_pad_len, 15, 0);
5533         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5534                         "Failed to allocate input buffer in mempool");
5535
5536         if (op_mode == OUT_OF_PLACE) {
5537                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5538                                 plaintext_pad_len, 15, 0);
5539                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5540                                 "Failed to allocate output buffer in mempool");
5541         }
5542
5543         if (verify) {
5544                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5545                         tdata->ciphertext.data);
5546                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5547                                         ciphertext_len, buffer);
5548                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5549                         ciphertext_len);
5550         } else {
5551                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5552                         tdata->plaintext.data);
5553                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5554                                         plaintext_len, buffer);
5555                 debug_hexdump(stdout, "plaintext:", plaintext,
5556                         plaintext_len);
5557         }
5558         memset(buffer, 0, sizeof(buffer));
5559
5560         /* Create KASUMI operation */
5561         retval = create_wireless_algo_auth_cipher_operation(
5562                 tdata->digest.data, tdata->digest.len,
5563                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5564                 NULL, 0,
5565                 (tdata->digest.offset_bytes == 0 ?
5566                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5567                         : tdata->digest.offset_bytes),
5568                 tdata->validCipherLenInBits.len,
5569                 tdata->validCipherOffsetInBits.len,
5570                 tdata->validAuthLenInBits.len,
5571                 0,
5572                 op_mode, 1, verify);
5573
5574         if (retval < 0)
5575                 return retval;
5576
5577         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5578                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5579                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5580         else
5581                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5582                         ut_params->op);
5583
5584         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5585
5586         ut_params->obuf = (op_mode == IN_PLACE ?
5587                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5588
5589         if (verify) {
5590                 if (ut_params->obuf)
5591                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5592                                         plaintext_len, buffer);
5593                 else
5594                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5595                                         plaintext_len, buffer);
5596
5597                 debug_hexdump(stdout, "plaintext:", plaintext,
5598                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5599                 debug_hexdump(stdout, "plaintext expected:",
5600                         tdata->plaintext.data,
5601                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5602         } else {
5603                 if (ut_params->obuf)
5604                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5605                                         ciphertext_len, buffer);
5606                 else
5607                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5608                                         ciphertext_len, buffer);
5609
5610                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5611                         ciphertext_len);
5612                 debug_hexdump(stdout, "ciphertext expected:",
5613                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5614
5615                 if (ut_params->obuf)
5616                         digest = rte_pktmbuf_read(ut_params->obuf,
5617                                 (tdata->digest.offset_bytes == 0 ?
5618                                 plaintext_pad_len : tdata->digest.offset_bytes),
5619                                 tdata->digest.len, digest_buffer);
5620                 else
5621                         digest = rte_pktmbuf_read(ut_params->ibuf,
5622                                 (tdata->digest.offset_bytes == 0 ?
5623                                 plaintext_pad_len : tdata->digest.offset_bytes),
5624                                 tdata->digest.len, digest_buffer);
5625
5626                 debug_hexdump(stdout, "digest:", digest,
5627                         tdata->digest.len);
5628                 debug_hexdump(stdout, "digest expected:",
5629                         tdata->digest.data, tdata->digest.len);
5630         }
5631
5632         /* Validate obuf */
5633         if (verify) {
5634                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5635                         plaintext,
5636                         tdata->plaintext.data,
5637                         tdata->plaintext.len >> 3,
5638                         "KASUMI Plaintext data not as expected");
5639         } else {
5640                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5641                         ciphertext,
5642                         tdata->ciphertext.data,
5643                         tdata->validDataLenInBits.len,
5644                         "KASUMI Ciphertext data not as expected");
5645
5646                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5647                         digest,
5648                         tdata->digest.data,
5649                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5650                         "KASUMI Generated auth tag not as expected");
5651         }
5652         return 0;
5653 }
5654
5655 static int
5656 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5657 {
5658         struct crypto_testsuite_params *ts_params = &testsuite_params;
5659         struct crypto_unittest_params *ut_params = &unittest_params;
5660
5661         int retval;
5662
5663         uint8_t *plaintext, *ciphertext;
5664         unsigned plaintext_pad_len;
5665         unsigned plaintext_len;
5666         struct rte_cryptodev_info dev_info;
5667
5668         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5669         uint64_t feat_flags = dev_info.feature_flags;
5670
5671         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5672                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5673                 printf("Device doesn't support RAW data-path APIs.\n");
5674                 return TEST_SKIPPED;
5675         }
5676
5677         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5678                 return TEST_SKIPPED;
5679
5680         /* Verify the capabilities */
5681         struct rte_cryptodev_sym_capability_idx cap_idx;
5682         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5683         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5684         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5685                         &cap_idx) == NULL)
5686                 return TEST_SKIPPED;
5687         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5688         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5689         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5690                         &cap_idx) == NULL)
5691                 return TEST_SKIPPED;
5692
5693         /* Create KASUMI session */
5694         retval = create_wireless_algo_cipher_auth_session(
5695                         ts_params->valid_devs[0],
5696                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5697                         RTE_CRYPTO_AUTH_OP_GENERATE,
5698                         RTE_CRYPTO_AUTH_KASUMI_F9,
5699                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5700                         tdata->key.data, tdata->key.len,
5701                         0, tdata->digest.len,
5702                         tdata->cipher_iv.len);
5703         if (retval != 0)
5704                 return retval;
5705
5706         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5707
5708         /* clear mbuf payload */
5709         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5710                         rte_pktmbuf_tailroom(ut_params->ibuf));
5711
5712         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5713         /* Append data which is padded to a multiple of */
5714         /* the algorithms block size */
5715         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5716         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5717                                 plaintext_pad_len);
5718         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5719
5720         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5721
5722         /* Create KASUMI operation */
5723         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5724                                 tdata->digest.len, NULL, 0,
5725                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5726                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5727                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5728                                 tdata->validCipherOffsetInBits.len,
5729                                 tdata->validAuthLenInBits.len,
5730                                 0
5731                                 );
5732         if (retval < 0)
5733                 return retval;
5734
5735         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5736                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5737                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5738         else
5739                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5740                         ut_params->op);
5741         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5742
5743         if (ut_params->op->sym->m_dst)
5744                 ut_params->obuf = ut_params->op->sym->m_dst;
5745         else
5746                 ut_params->obuf = ut_params->op->sym->m_src;
5747
5748         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5749                                 tdata->validCipherOffsetInBits.len >> 3);
5750
5751         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5752                         + plaintext_pad_len;
5753
5754         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5755                                 (tdata->validCipherOffsetInBits.len >> 3);
5756         /* Validate obuf */
5757         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5758                 ciphertext,
5759                 reference_ciphertext,
5760                 tdata->validCipherLenInBits.len,
5761                 "KASUMI Ciphertext data not as expected");
5762
5763         /* Validate obuf */
5764         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5765                 ut_params->digest,
5766                 tdata->digest.data,
5767                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5768                 "KASUMI Generated auth tag not as expected");
5769         return 0;
5770 }
5771
5772 static int
5773 test_zuc_encryption(const struct wireless_test_data *tdata)
5774 {
5775         struct crypto_testsuite_params *ts_params = &testsuite_params;
5776         struct crypto_unittest_params *ut_params = &unittest_params;
5777
5778         int retval;
5779         uint8_t *plaintext, *ciphertext;
5780         unsigned plaintext_pad_len;
5781         unsigned plaintext_len;
5782         struct rte_cryptodev_info dev_info;
5783
5784         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5785         uint64_t feat_flags = dev_info.feature_flags;
5786
5787         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5788                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5789                 printf("Device doesn't support RAW data-path APIs.\n");
5790                 return TEST_SKIPPED;
5791         }
5792
5793         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5794                 return TEST_SKIPPED;
5795
5796         struct rte_cryptodev_sym_capability_idx cap_idx;
5797
5798         /* Check if device supports ZUC EEA3 */
5799         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5800         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5801
5802         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5803                         &cap_idx) == NULL)
5804                 return TEST_SKIPPED;
5805
5806         /* Create ZUC session */
5807         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5808                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5809                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5810                                         tdata->key.data, tdata->key.len,
5811                                         tdata->cipher_iv.len);
5812         if (retval < 0)
5813                 return retval;
5814
5815         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5816
5817         /* Clear mbuf payload */
5818         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5819                rte_pktmbuf_tailroom(ut_params->ibuf));
5820
5821         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5822         /* Append data which is padded to a multiple */
5823         /* of the algorithms block size */
5824         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5825         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5826                                 plaintext_pad_len);
5827         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5828
5829         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5830
5831         /* Create ZUC operation */
5832         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5833                                         tdata->cipher_iv.len,
5834                                         tdata->plaintext.len,
5835                                         0);
5836         if (retval < 0)
5837                 return retval;
5838
5839         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5840                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5841                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5842         else
5843                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5844                                                 ut_params->op);
5845         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5846
5847         ut_params->obuf = ut_params->op->sym->m_dst;
5848         if (ut_params->obuf)
5849                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5850         else
5851                 ciphertext = plaintext;
5852
5853         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5854
5855         /* Validate obuf */
5856         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5857                 ciphertext,
5858                 tdata->ciphertext.data,
5859                 tdata->validCipherLenInBits.len,
5860                 "ZUC Ciphertext data not as expected");
5861         return 0;
5862 }
5863
5864 static int
5865 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5866 {
5867         struct crypto_testsuite_params *ts_params = &testsuite_params;
5868         struct crypto_unittest_params *ut_params = &unittest_params;
5869
5870         int retval;
5871
5872         unsigned int plaintext_pad_len;
5873         unsigned int plaintext_len;
5874         const uint8_t *ciphertext;
5875         uint8_t ciphertext_buffer[2048];
5876         struct rte_cryptodev_info dev_info;
5877
5878         struct rte_cryptodev_sym_capability_idx cap_idx;
5879
5880         /* Check if device supports ZUC EEA3 */
5881         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5882         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5883
5884         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5885                         &cap_idx) == NULL)
5886                 return TEST_SKIPPED;
5887
5888         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5889                 return TEST_SKIPPED;
5890
5891         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5892
5893         uint64_t feat_flags = dev_info.feature_flags;
5894
5895         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5896                 printf("Device doesn't support in-place scatter-gather. "
5897                                 "Test Skipped.\n");
5898                 return TEST_SKIPPED;
5899         }
5900
5901         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5902                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5903                 printf("Device doesn't support RAW data-path APIs.\n");
5904                 return TEST_SKIPPED;
5905         }
5906
5907         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5908
5909         /* Append data which is padded to a multiple */
5910         /* of the algorithms block size */
5911         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5912
5913         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5914                         plaintext_pad_len, 10, 0);
5915
5916         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5917                         tdata->plaintext.data);
5918
5919         /* Create ZUC session */
5920         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5921                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5922                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5923                         tdata->key.data, tdata->key.len,
5924                         tdata->cipher_iv.len);
5925         if (retval < 0)
5926                 return retval;
5927
5928         /* Clear mbuf payload */
5929
5930         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5931
5932         /* Create ZUC operation */
5933         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5934                         tdata->cipher_iv.len, tdata->plaintext.len,
5935                         0);
5936         if (retval < 0)
5937                 return retval;
5938
5939         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5940                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5941                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5942         else
5943                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5944                                                 ut_params->op);
5945         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5946
5947         ut_params->obuf = ut_params->op->sym->m_dst;
5948         if (ut_params->obuf)
5949                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
5950                         0, plaintext_len, ciphertext_buffer);
5951         else
5952                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
5953                         0, plaintext_len, ciphertext_buffer);
5954
5955         /* Validate obuf */
5956         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5957
5958         /* Validate obuf */
5959         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5960                 ciphertext,
5961                 tdata->ciphertext.data,
5962                 tdata->validCipherLenInBits.len,
5963                 "ZUC Ciphertext data not as expected");
5964
5965         return 0;
5966 }
5967
5968 static int
5969 test_zuc_authentication(const struct wireless_test_data *tdata)
5970 {
5971         struct crypto_testsuite_params *ts_params = &testsuite_params;
5972         struct crypto_unittest_params *ut_params = &unittest_params;
5973
5974         int retval;
5975         unsigned plaintext_pad_len;
5976         unsigned plaintext_len;
5977         uint8_t *plaintext;
5978
5979         struct rte_cryptodev_sym_capability_idx cap_idx;
5980         struct rte_cryptodev_info dev_info;
5981
5982         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5983         uint64_t feat_flags = dev_info.feature_flags;
5984
5985         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
5986                         (tdata->validAuthLenInBits.len % 8 != 0)) {
5987                 printf("Device doesn't support NON-Byte Aligned Data.\n");
5988                 return TEST_SKIPPED;
5989         }
5990
5991         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5992                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5993                 printf("Device doesn't support RAW data-path APIs.\n");
5994                 return TEST_SKIPPED;
5995         }
5996
5997         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5998                 return TEST_SKIPPED;
5999
6000         /* Check if device supports ZUC EIA3 */
6001         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6002         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6003
6004         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6005                         &cap_idx) == NULL)
6006                 return TEST_SKIPPED;
6007
6008         /* Create ZUC session */
6009         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6010                         tdata->key.data, tdata->key.len,
6011                         tdata->auth_iv.len, tdata->digest.len,
6012                         RTE_CRYPTO_AUTH_OP_GENERATE,
6013                         RTE_CRYPTO_AUTH_ZUC_EIA3);
6014         if (retval < 0)
6015                 return retval;
6016
6017         /* alloc mbuf and set payload */
6018         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6019
6020         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6021         rte_pktmbuf_tailroom(ut_params->ibuf));
6022
6023         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6024         /* Append data which is padded to a multiple of */
6025         /* the algorithms block size */
6026         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6027         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6028                                 plaintext_pad_len);
6029         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6030
6031         /* Create ZUC operation */
6032         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6033                         tdata->auth_iv.data, tdata->auth_iv.len,
6034                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6035                         tdata->validAuthLenInBits.len,
6036                         0);
6037         if (retval < 0)
6038                 return retval;
6039
6040         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6041                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6042                                 ut_params->op, 0, 1, 1, 0);
6043         else
6044                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6045                                 ut_params->op);
6046         ut_params->obuf = ut_params->op->sym->m_src;
6047         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6048         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6049                         + plaintext_pad_len;
6050
6051         /* Validate obuf */
6052         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6053         ut_params->digest,
6054         tdata->digest.data,
6055         tdata->digest.len,
6056         "ZUC Generated auth tag not as expected");
6057
6058         return 0;
6059 }
6060
6061 static int
6062 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6063         uint8_t op_mode, uint8_t verify)
6064 {
6065         struct crypto_testsuite_params *ts_params = &testsuite_params;
6066         struct crypto_unittest_params *ut_params = &unittest_params;
6067
6068         int retval;
6069
6070         uint8_t *plaintext = NULL, *ciphertext = NULL;
6071         unsigned int plaintext_pad_len;
6072         unsigned int plaintext_len;
6073         unsigned int ciphertext_pad_len;
6074         unsigned int ciphertext_len;
6075
6076         struct rte_cryptodev_info dev_info;
6077         struct rte_cryptodev_sym_capability_idx cap_idx;
6078
6079         /* Check if device supports ZUC EIA3 */
6080         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6081         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6082
6083         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6084                         &cap_idx) == NULL)
6085                 return TEST_SKIPPED;
6086
6087         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6088
6089         uint64_t feat_flags = dev_info.feature_flags;
6090
6091         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6092                 printf("Device doesn't support digest encrypted.\n");
6093                 return TEST_SKIPPED;
6094         }
6095         if (op_mode == IN_PLACE) {
6096                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6097                         printf("Device doesn't support in-place scatter-gather "
6098                                         "in both input and output mbufs.\n");
6099                         return TEST_SKIPPED;
6100                 }
6101
6102                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6103                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6104                         printf("Device doesn't support RAW data-path APIs.\n");
6105                         return TEST_SKIPPED;
6106                 }
6107         } else {
6108                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6109                         return TEST_SKIPPED;
6110                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6111                         printf("Device doesn't support out-of-place scatter-gather "
6112                                         "in both input and output mbufs.\n");
6113                         return TEST_SKIPPED;
6114                 }
6115         }
6116
6117         /* Create ZUC session */
6118         retval = create_wireless_algo_auth_cipher_session(
6119                         ts_params->valid_devs[0],
6120                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6121                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6122                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6123                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6124                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6125                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6126                         tdata->key.data, tdata->key.len,
6127                         tdata->auth_iv.len, tdata->digest.len,
6128                         tdata->cipher_iv.len);
6129
6130         if (retval != 0)
6131                 return retval;
6132
6133         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6134         if (op_mode == OUT_OF_PLACE)
6135                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6136
6137         /* clear mbuf payload */
6138         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6139                 rte_pktmbuf_tailroom(ut_params->ibuf));
6140         if (op_mode == OUT_OF_PLACE)
6141                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6142                         rte_pktmbuf_tailroom(ut_params->obuf));
6143
6144         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6145         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6146         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6147         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6148
6149         if (verify) {
6150                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6151                                         ciphertext_pad_len);
6152                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6153                 if (op_mode == OUT_OF_PLACE)
6154                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6155                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6156                         ciphertext_len);
6157         } else {
6158                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6159                                         plaintext_pad_len);
6160                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6161                 if (op_mode == OUT_OF_PLACE)
6162                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6163                 debug_hexdump(stdout, "plaintext:", plaintext,
6164                         plaintext_len);
6165         }
6166
6167         /* Create ZUC operation */
6168         retval = create_wireless_algo_auth_cipher_operation(
6169                 tdata->digest.data, tdata->digest.len,
6170                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6171                 tdata->auth_iv.data, tdata->auth_iv.len,
6172                 (tdata->digest.offset_bytes == 0 ?
6173                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6174                         : tdata->digest.offset_bytes),
6175                 tdata->validCipherLenInBits.len,
6176                 tdata->validCipherOffsetInBits.len,
6177                 tdata->validAuthLenInBits.len,
6178                 0,
6179                 op_mode, 0, verify);
6180
6181         if (retval < 0)
6182                 return retval;
6183
6184         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6185                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6186                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6187         else
6188                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6189                         ut_params->op);
6190
6191         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6192
6193         ut_params->obuf = (op_mode == IN_PLACE ?
6194                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6195
6196
6197         if (verify) {
6198                 if (ut_params->obuf)
6199                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6200                                                         uint8_t *);
6201                 else
6202                         plaintext = ciphertext;
6203
6204                 debug_hexdump(stdout, "plaintext:", plaintext,
6205                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6206                 debug_hexdump(stdout, "plaintext expected:",
6207                         tdata->plaintext.data,
6208                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6209         } else {
6210                 if (ut_params->obuf)
6211                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6212                                                         uint8_t *);
6213                 else
6214                         ciphertext = plaintext;
6215
6216                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6217                         ciphertext_len);
6218                 debug_hexdump(stdout, "ciphertext expected:",
6219                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6220
6221                 ut_params->digest = rte_pktmbuf_mtod(
6222                         ut_params->obuf, uint8_t *) +
6223                         (tdata->digest.offset_bytes == 0 ?
6224                         plaintext_pad_len : tdata->digest.offset_bytes);
6225
6226                 debug_hexdump(stdout, "digest:", ut_params->digest,
6227                         tdata->digest.len);
6228                 debug_hexdump(stdout, "digest expected:",
6229                         tdata->digest.data, tdata->digest.len);
6230         }
6231
6232         /* Validate obuf */
6233         if (verify) {
6234                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6235                         plaintext,
6236                         tdata->plaintext.data,
6237                         tdata->plaintext.len >> 3,
6238                         "ZUC Plaintext data not as expected");
6239         } else {
6240                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6241                         ciphertext,
6242                         tdata->ciphertext.data,
6243                         tdata->ciphertext.len >> 3,
6244                         "ZUC Ciphertext data not as expected");
6245
6246                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6247                         ut_params->digest,
6248                         tdata->digest.data,
6249                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6250                         "ZUC Generated auth tag not as expected");
6251         }
6252         return 0;
6253 }
6254
6255 static int
6256 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6257         uint8_t op_mode, uint8_t verify)
6258 {
6259         struct crypto_testsuite_params *ts_params = &testsuite_params;
6260         struct crypto_unittest_params *ut_params = &unittest_params;
6261
6262         int retval;
6263
6264         const uint8_t *plaintext = NULL;
6265         const uint8_t *ciphertext = NULL;
6266         const uint8_t *digest = NULL;
6267         unsigned int plaintext_pad_len;
6268         unsigned int plaintext_len;
6269         unsigned int ciphertext_pad_len;
6270         unsigned int ciphertext_len;
6271         uint8_t buffer[10000];
6272         uint8_t digest_buffer[10000];
6273
6274         struct rte_cryptodev_info dev_info;
6275         struct rte_cryptodev_sym_capability_idx cap_idx;
6276
6277         /* Check if device supports ZUC EIA3 */
6278         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6279         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6280
6281         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6282                         &cap_idx) == NULL)
6283                 return TEST_SKIPPED;
6284
6285         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6286
6287         uint64_t feat_flags = dev_info.feature_flags;
6288
6289         if (op_mode == IN_PLACE) {
6290                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6291                         printf("Device doesn't support in-place scatter-gather "
6292                                         "in both input and output mbufs.\n");
6293                         return TEST_SKIPPED;
6294                 }
6295
6296                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6297                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6298                         printf("Device doesn't support RAW data-path APIs.\n");
6299                         return TEST_SKIPPED;
6300                 }
6301         } else {
6302                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6303                         return TEST_SKIPPED;
6304                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6305                         printf("Device doesn't support out-of-place scatter-gather "
6306                                         "in both input and output mbufs.\n");
6307                         return TEST_SKIPPED;
6308                 }
6309                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6310                         printf("Device doesn't support digest encrypted.\n");
6311                         return TEST_SKIPPED;
6312                 }
6313         }
6314
6315         /* Create ZUC session */
6316         retval = create_wireless_algo_auth_cipher_session(
6317                         ts_params->valid_devs[0],
6318                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6319                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6320                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6321                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6322                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6323                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6324                         tdata->key.data, tdata->key.len,
6325                         tdata->auth_iv.len, tdata->digest.len,
6326                         tdata->cipher_iv.len);
6327
6328         if (retval != 0)
6329                 return retval;
6330
6331         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6332         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6333         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6334         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6335
6336         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6337                         plaintext_pad_len, 15, 0);
6338         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6339                         "Failed to allocate input buffer in mempool");
6340
6341         if (op_mode == OUT_OF_PLACE) {
6342                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6343                                 plaintext_pad_len, 15, 0);
6344                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6345                                 "Failed to allocate output buffer in mempool");
6346         }
6347
6348         if (verify) {
6349                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6350                         tdata->ciphertext.data);
6351                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6352                                         ciphertext_len, buffer);
6353                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6354                         ciphertext_len);
6355         } else {
6356                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6357                         tdata->plaintext.data);
6358                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6359                                         plaintext_len, buffer);
6360                 debug_hexdump(stdout, "plaintext:", plaintext,
6361                         plaintext_len);
6362         }
6363         memset(buffer, 0, sizeof(buffer));
6364
6365         /* Create ZUC operation */
6366         retval = create_wireless_algo_auth_cipher_operation(
6367                 tdata->digest.data, tdata->digest.len,
6368                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6369                 NULL, 0,
6370                 (tdata->digest.offset_bytes == 0 ?
6371                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6372                         : tdata->digest.offset_bytes),
6373                 tdata->validCipherLenInBits.len,
6374                 tdata->validCipherOffsetInBits.len,
6375                 tdata->validAuthLenInBits.len,
6376                 0,
6377                 op_mode, 1, verify);
6378
6379         if (retval < 0)
6380                 return retval;
6381
6382         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6383                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6384                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6385         else
6386                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6387                         ut_params->op);
6388
6389         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6390
6391         ut_params->obuf = (op_mode == IN_PLACE ?
6392                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6393
6394         if (verify) {
6395                 if (ut_params->obuf)
6396                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6397                                         plaintext_len, buffer);
6398                 else
6399                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6400                                         plaintext_len, buffer);
6401
6402                 debug_hexdump(stdout, "plaintext:", plaintext,
6403                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6404                 debug_hexdump(stdout, "plaintext expected:",
6405                         tdata->plaintext.data,
6406                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6407         } else {
6408                 if (ut_params->obuf)
6409                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6410                                         ciphertext_len, buffer);
6411                 else
6412                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6413                                         ciphertext_len, buffer);
6414
6415                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6416                         ciphertext_len);
6417                 debug_hexdump(stdout, "ciphertext expected:",
6418                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6419
6420                 if (ut_params->obuf)
6421                         digest = rte_pktmbuf_read(ut_params->obuf,
6422                                 (tdata->digest.offset_bytes == 0 ?
6423                                 plaintext_pad_len : tdata->digest.offset_bytes),
6424                                 tdata->digest.len, digest_buffer);
6425                 else
6426                         digest = rte_pktmbuf_read(ut_params->ibuf,
6427                                 (tdata->digest.offset_bytes == 0 ?
6428                                 plaintext_pad_len : tdata->digest.offset_bytes),
6429                                 tdata->digest.len, digest_buffer);
6430
6431                 debug_hexdump(stdout, "digest:", digest,
6432                         tdata->digest.len);
6433                 debug_hexdump(stdout, "digest expected:",
6434                         tdata->digest.data, tdata->digest.len);
6435         }
6436
6437         /* Validate obuf */
6438         if (verify) {
6439                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6440                         plaintext,
6441                         tdata->plaintext.data,
6442                         tdata->plaintext.len >> 3,
6443                         "ZUC Plaintext data not as expected");
6444         } else {
6445                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6446                         ciphertext,
6447                         tdata->ciphertext.data,
6448                         tdata->validDataLenInBits.len,
6449                         "ZUC Ciphertext data not as expected");
6450
6451                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6452                         digest,
6453                         tdata->digest.data,
6454                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6455                         "ZUC Generated auth tag not as expected");
6456         }
6457         return 0;
6458 }
6459
6460 static int
6461 test_kasumi_encryption_test_case_1(void)
6462 {
6463         return test_kasumi_encryption(&kasumi_test_case_1);
6464 }
6465
6466 static int
6467 test_kasumi_encryption_test_case_1_sgl(void)
6468 {
6469         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6470 }
6471
6472 static int
6473 test_kasumi_encryption_test_case_1_oop(void)
6474 {
6475         return test_kasumi_encryption_oop(&kasumi_test_case_1);
6476 }
6477
6478 static int
6479 test_kasumi_encryption_test_case_1_oop_sgl(void)
6480 {
6481         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6482 }
6483
6484 static int
6485 test_kasumi_encryption_test_case_2(void)
6486 {
6487         return test_kasumi_encryption(&kasumi_test_case_2);
6488 }
6489
6490 static int
6491 test_kasumi_encryption_test_case_3(void)
6492 {
6493         return test_kasumi_encryption(&kasumi_test_case_3);
6494 }
6495
6496 static int
6497 test_kasumi_encryption_test_case_4(void)
6498 {
6499         return test_kasumi_encryption(&kasumi_test_case_4);
6500 }
6501
6502 static int
6503 test_kasumi_encryption_test_case_5(void)
6504 {
6505         return test_kasumi_encryption(&kasumi_test_case_5);
6506 }
6507
6508 static int
6509 test_kasumi_decryption_test_case_1(void)
6510 {
6511         return test_kasumi_decryption(&kasumi_test_case_1);
6512 }
6513
6514 static int
6515 test_kasumi_decryption_test_case_1_oop(void)
6516 {
6517         return test_kasumi_decryption_oop(&kasumi_test_case_1);
6518 }
6519
6520 static int
6521 test_kasumi_decryption_test_case_2(void)
6522 {
6523         return test_kasumi_decryption(&kasumi_test_case_2);
6524 }
6525
6526 static int
6527 test_kasumi_decryption_test_case_3(void)
6528 {
6529         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6530         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6531                 return TEST_SKIPPED;
6532         return test_kasumi_decryption(&kasumi_test_case_3);
6533 }
6534
6535 static int
6536 test_kasumi_decryption_test_case_4(void)
6537 {
6538         return test_kasumi_decryption(&kasumi_test_case_4);
6539 }
6540
6541 static int
6542 test_kasumi_decryption_test_case_5(void)
6543 {
6544         return test_kasumi_decryption(&kasumi_test_case_5);
6545 }
6546 static int
6547 test_snow3g_encryption_test_case_1(void)
6548 {
6549         return test_snow3g_encryption(&snow3g_test_case_1);
6550 }
6551
6552 static int
6553 test_snow3g_encryption_test_case_1_oop(void)
6554 {
6555         return test_snow3g_encryption_oop(&snow3g_test_case_1);
6556 }
6557
6558 static int
6559 test_snow3g_encryption_test_case_1_oop_sgl(void)
6560 {
6561         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6562 }
6563
6564
6565 static int
6566 test_snow3g_encryption_test_case_1_offset_oop(void)
6567 {
6568         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6569 }
6570
6571 static int
6572 test_snow3g_encryption_test_case_2(void)
6573 {
6574         return test_snow3g_encryption(&snow3g_test_case_2);
6575 }
6576
6577 static int
6578 test_snow3g_encryption_test_case_3(void)
6579 {
6580         return test_snow3g_encryption(&snow3g_test_case_3);
6581 }
6582
6583 static int
6584 test_snow3g_encryption_test_case_4(void)
6585 {
6586         return test_snow3g_encryption(&snow3g_test_case_4);
6587 }
6588
6589 static int
6590 test_snow3g_encryption_test_case_5(void)
6591 {
6592         return test_snow3g_encryption(&snow3g_test_case_5);
6593 }
6594
6595 static int
6596 test_snow3g_decryption_test_case_1(void)
6597 {
6598         return test_snow3g_decryption(&snow3g_test_case_1);
6599 }
6600
6601 static int
6602 test_snow3g_decryption_test_case_1_oop(void)
6603 {
6604         return test_snow3g_decryption_oop(&snow3g_test_case_1);
6605 }
6606
6607 static int
6608 test_snow3g_decryption_test_case_2(void)
6609 {
6610         return test_snow3g_decryption(&snow3g_test_case_2);
6611 }
6612
6613 static int
6614 test_snow3g_decryption_test_case_3(void)
6615 {
6616         return test_snow3g_decryption(&snow3g_test_case_3);
6617 }
6618
6619 static int
6620 test_snow3g_decryption_test_case_4(void)
6621 {
6622         return test_snow3g_decryption(&snow3g_test_case_4);
6623 }
6624
6625 static int
6626 test_snow3g_decryption_test_case_5(void)
6627 {
6628         return test_snow3g_decryption(&snow3g_test_case_5);
6629 }
6630
6631 /*
6632  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6633  * Pattern digest from snow3g_test_data must be allocated as
6634  * 4 last bytes in plaintext.
6635  */
6636 static void
6637 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6638                 struct snow3g_hash_test_data *output)
6639 {
6640         if ((pattern != NULL) && (output != NULL)) {
6641                 output->key.len = pattern->key.len;
6642
6643                 memcpy(output->key.data,
6644                 pattern->key.data, pattern->key.len);
6645
6646                 output->auth_iv.len = pattern->auth_iv.len;
6647
6648                 memcpy(output->auth_iv.data,
6649                 pattern->auth_iv.data, pattern->auth_iv.len);
6650
6651                 output->plaintext.len = pattern->plaintext.len;
6652
6653                 memcpy(output->plaintext.data,
6654                 pattern->plaintext.data, pattern->plaintext.len >> 3);
6655
6656                 output->digest.len = pattern->digest.len;
6657
6658                 memcpy(output->digest.data,
6659                 &pattern->plaintext.data[pattern->digest.offset_bytes],
6660                 pattern->digest.len);
6661
6662                 output->validAuthLenInBits.len =
6663                 pattern->validAuthLenInBits.len;
6664         }
6665 }
6666
6667 /*
6668  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6669  */
6670 static int
6671 test_snow3g_decryption_with_digest_test_case_1(void)
6672 {
6673         struct snow3g_hash_test_data snow3g_hash_data;
6674         struct rte_cryptodev_info dev_info;
6675         struct crypto_testsuite_params *ts_params = &testsuite_params;
6676
6677         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6678         uint64_t feat_flags = dev_info.feature_flags;
6679
6680         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6681                 printf("Device doesn't support encrypted digest operations.\n");
6682                 return TEST_SKIPPED;
6683         }
6684
6685         /*
6686          * Function prepare data for hash veryfication test case.
6687          * Digest is allocated in 4 last bytes in plaintext, pattern.
6688          */
6689         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6690
6691         return test_snow3g_decryption(&snow3g_test_case_7) &
6692                         test_snow3g_authentication_verify(&snow3g_hash_data);
6693 }
6694
6695 static int
6696 test_snow3g_cipher_auth_test_case_1(void)
6697 {
6698         return test_snow3g_cipher_auth(&snow3g_test_case_3);
6699 }
6700
6701 static int
6702 test_snow3g_auth_cipher_test_case_1(void)
6703 {
6704         return test_snow3g_auth_cipher(
6705                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6706 }
6707
6708 static int
6709 test_snow3g_auth_cipher_test_case_2(void)
6710 {
6711         return test_snow3g_auth_cipher(
6712                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6713 }
6714
6715 static int
6716 test_snow3g_auth_cipher_test_case_2_oop(void)
6717 {
6718         return test_snow3g_auth_cipher(
6719                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6720 }
6721
6722 static int
6723 test_snow3g_auth_cipher_part_digest_enc(void)
6724 {
6725         return test_snow3g_auth_cipher(
6726                 &snow3g_auth_cipher_partial_digest_encryption,
6727                         IN_PLACE, 0);
6728 }
6729
6730 static int
6731 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6732 {
6733         return test_snow3g_auth_cipher(
6734                 &snow3g_auth_cipher_partial_digest_encryption,
6735                         OUT_OF_PLACE, 0);
6736 }
6737
6738 static int
6739 test_snow3g_auth_cipher_test_case_3_sgl(void)
6740 {
6741         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6742         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6743                 return TEST_SKIPPED;
6744         return test_snow3g_auth_cipher_sgl(
6745                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6746 }
6747
6748 static int
6749 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6750 {
6751         return test_snow3g_auth_cipher_sgl(
6752                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6753 }
6754
6755 static int
6756 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6757 {
6758         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6759         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6760                 return TEST_SKIPPED;
6761         return test_snow3g_auth_cipher_sgl(
6762                 &snow3g_auth_cipher_partial_digest_encryption,
6763                         IN_PLACE, 0);
6764 }
6765
6766 static int
6767 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6768 {
6769         return test_snow3g_auth_cipher_sgl(
6770                 &snow3g_auth_cipher_partial_digest_encryption,
6771                         OUT_OF_PLACE, 0);
6772 }
6773
6774 static int
6775 test_snow3g_auth_cipher_verify_test_case_1(void)
6776 {
6777         return test_snow3g_auth_cipher(
6778                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6779 }
6780
6781 static int
6782 test_snow3g_auth_cipher_verify_test_case_2(void)
6783 {
6784         return test_snow3g_auth_cipher(
6785                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6786 }
6787
6788 static int
6789 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6790 {
6791         return test_snow3g_auth_cipher(
6792                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6793 }
6794
6795 static int
6796 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6797 {
6798         return test_snow3g_auth_cipher(
6799                 &snow3g_auth_cipher_partial_digest_encryption,
6800                         IN_PLACE, 1);
6801 }
6802
6803 static int
6804 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6805 {
6806         return test_snow3g_auth_cipher(
6807                 &snow3g_auth_cipher_partial_digest_encryption,
6808                         OUT_OF_PLACE, 1);
6809 }
6810
6811 static int
6812 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6813 {
6814         return test_snow3g_auth_cipher_sgl(
6815                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6816 }
6817
6818 static int
6819 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6820 {
6821         return test_snow3g_auth_cipher_sgl(
6822                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6823 }
6824
6825 static int
6826 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6827 {
6828         return test_snow3g_auth_cipher_sgl(
6829                 &snow3g_auth_cipher_partial_digest_encryption,
6830                         IN_PLACE, 1);
6831 }
6832
6833 static int
6834 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6835 {
6836         return test_snow3g_auth_cipher_sgl(
6837                 &snow3g_auth_cipher_partial_digest_encryption,
6838                         OUT_OF_PLACE, 1);
6839 }
6840
6841 static int
6842 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6843 {
6844         return test_snow3g_auth_cipher(
6845                 &snow3g_test_case_7, IN_PLACE, 0);
6846 }
6847
6848 static int
6849 test_kasumi_auth_cipher_test_case_1(void)
6850 {
6851         return test_kasumi_auth_cipher(
6852                 &kasumi_test_case_3, IN_PLACE, 0);
6853 }
6854
6855 static int
6856 test_kasumi_auth_cipher_test_case_2(void)
6857 {
6858         return test_kasumi_auth_cipher(
6859                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6860 }
6861
6862 static int
6863 test_kasumi_auth_cipher_test_case_2_oop(void)
6864 {
6865         return test_kasumi_auth_cipher(
6866                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6867 }
6868
6869 static int
6870 test_kasumi_auth_cipher_test_case_2_sgl(void)
6871 {
6872         return test_kasumi_auth_cipher_sgl(
6873                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6874 }
6875
6876 static int
6877 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6878 {
6879         return test_kasumi_auth_cipher_sgl(
6880                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6881 }
6882
6883 static int
6884 test_kasumi_auth_cipher_verify_test_case_1(void)
6885 {
6886         return test_kasumi_auth_cipher(
6887                 &kasumi_test_case_3, IN_PLACE, 1);
6888 }
6889
6890 static int
6891 test_kasumi_auth_cipher_verify_test_case_2(void)
6892 {
6893         return test_kasumi_auth_cipher(
6894                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6895 }
6896
6897 static int
6898 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6899 {
6900         return test_kasumi_auth_cipher(
6901                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6902 }
6903
6904 static int
6905 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6906 {
6907         return test_kasumi_auth_cipher_sgl(
6908                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6909 }
6910
6911 static int
6912 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6913 {
6914         return test_kasumi_auth_cipher_sgl(
6915                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6916 }
6917
6918 static int
6919 test_kasumi_cipher_auth_test_case_1(void)
6920 {
6921         return test_kasumi_cipher_auth(&kasumi_test_case_6);
6922 }
6923
6924 static int
6925 test_zuc_encryption_test_case_1(void)
6926 {
6927         return test_zuc_encryption(&zuc_test_case_cipher_193b);
6928 }
6929
6930 static int
6931 test_zuc_encryption_test_case_2(void)
6932 {
6933         return test_zuc_encryption(&zuc_test_case_cipher_800b);
6934 }
6935
6936 static int
6937 test_zuc_encryption_test_case_3(void)
6938 {
6939         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
6940 }
6941
6942 static int
6943 test_zuc_encryption_test_case_4(void)
6944 {
6945         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
6946 }
6947
6948 static int
6949 test_zuc_encryption_test_case_5(void)
6950 {
6951         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
6952 }
6953
6954 static int
6955 test_zuc_encryption_test_case_6_sgl(void)
6956 {
6957         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
6958 }
6959
6960 static int
6961 test_zuc_hash_generate_test_case_1(void)
6962 {
6963         return test_zuc_authentication(&zuc_test_case_auth_1b);
6964 }
6965
6966 static int
6967 test_zuc_hash_generate_test_case_2(void)
6968 {
6969         return test_zuc_authentication(&zuc_test_case_auth_90b);
6970 }
6971
6972 static int
6973 test_zuc_hash_generate_test_case_3(void)
6974 {
6975         return test_zuc_authentication(&zuc_test_case_auth_577b);
6976 }
6977
6978 static int
6979 test_zuc_hash_generate_test_case_4(void)
6980 {
6981         return test_zuc_authentication(&zuc_test_case_auth_2079b);
6982 }
6983
6984 static int
6985 test_zuc_hash_generate_test_case_5(void)
6986 {
6987         return test_zuc_authentication(&zuc_test_auth_5670b);
6988 }
6989
6990 static int
6991 test_zuc_hash_generate_test_case_6(void)
6992 {
6993         return test_zuc_authentication(&zuc_test_case_auth_128b);
6994 }
6995
6996 static int
6997 test_zuc_hash_generate_test_case_7(void)
6998 {
6999         return test_zuc_authentication(&zuc_test_case_auth_2080b);
7000 }
7001
7002 static int
7003 test_zuc_hash_generate_test_case_8(void)
7004 {
7005         return test_zuc_authentication(&zuc_test_case_auth_584b);
7006 }
7007
7008 static int
7009 test_zuc_cipher_auth_test_case_1(void)
7010 {
7011         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7012 }
7013
7014 static int
7015 test_zuc_cipher_auth_test_case_2(void)
7016 {
7017         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7018 }
7019
7020 static int
7021 test_zuc_auth_cipher_test_case_1(void)
7022 {
7023         return test_zuc_auth_cipher(
7024                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7025 }
7026
7027 static int
7028 test_zuc_auth_cipher_test_case_1_oop(void)
7029 {
7030         return test_zuc_auth_cipher(
7031                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7032 }
7033
7034 static int
7035 test_zuc_auth_cipher_test_case_1_sgl(void)
7036 {
7037         return test_zuc_auth_cipher_sgl(
7038                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7039 }
7040
7041 static int
7042 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7043 {
7044         return test_zuc_auth_cipher_sgl(
7045                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7046 }
7047
7048 static int
7049 test_zuc_auth_cipher_verify_test_case_1(void)
7050 {
7051         return test_zuc_auth_cipher(
7052                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7053 }
7054
7055 static int
7056 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7057 {
7058         return test_zuc_auth_cipher(
7059                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7060 }
7061
7062 static int
7063 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7064 {
7065         return test_zuc_auth_cipher_sgl(
7066                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7067 }
7068
7069 static int
7070 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7071 {
7072         return test_zuc_auth_cipher_sgl(
7073                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7074 }
7075
7076 static int
7077 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7078 {
7079         uint8_t dev_id = testsuite_params.valid_devs[0];
7080
7081         struct rte_cryptodev_sym_capability_idx cap_idx;
7082
7083         /* Check if device supports particular cipher algorithm */
7084         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7085         cap_idx.algo.cipher = tdata->cipher_algo;
7086         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7087                 return TEST_SKIPPED;
7088
7089         /* Check if device supports particular hash algorithm */
7090         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7091         cap_idx.algo.auth = tdata->auth_algo;
7092         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7093                 return TEST_SKIPPED;
7094
7095         return 0;
7096 }
7097
7098 static int
7099 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7100         uint8_t op_mode, uint8_t verify)
7101 {
7102         struct crypto_testsuite_params *ts_params = &testsuite_params;
7103         struct crypto_unittest_params *ut_params = &unittest_params;
7104
7105         int retval;
7106
7107         uint8_t *plaintext = NULL, *ciphertext = NULL;
7108         unsigned int plaintext_pad_len;
7109         unsigned int plaintext_len;
7110         unsigned int ciphertext_pad_len;
7111         unsigned int ciphertext_len;
7112
7113         struct rte_cryptodev_info dev_info;
7114         struct rte_crypto_op *op;
7115
7116         /* Check if device supports particular algorithms separately */
7117         if (test_mixed_check_if_unsupported(tdata))
7118                 return TEST_SKIPPED;
7119         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7120                 return TEST_SKIPPED;
7121
7122         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7123
7124         uint64_t feat_flags = dev_info.feature_flags;
7125
7126         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7127                 printf("Device doesn't support digest encrypted.\n");
7128                 return TEST_SKIPPED;
7129         }
7130
7131         /* Create the session */
7132         if (verify)
7133                 retval = create_wireless_algo_cipher_auth_session(
7134                                 ts_params->valid_devs[0],
7135                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7136                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7137                                 tdata->auth_algo,
7138                                 tdata->cipher_algo,
7139                                 tdata->auth_key.data, tdata->auth_key.len,
7140                                 tdata->auth_iv.len, tdata->digest_enc.len,
7141                                 tdata->cipher_iv.len);
7142         else
7143                 retval = create_wireless_algo_auth_cipher_session(
7144                                 ts_params->valid_devs[0],
7145                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7146                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7147                                 tdata->auth_algo,
7148                                 tdata->cipher_algo,
7149                                 tdata->auth_key.data, tdata->auth_key.len,
7150                                 tdata->auth_iv.len, tdata->digest_enc.len,
7151                                 tdata->cipher_iv.len);
7152         if (retval != 0)
7153                 return retval;
7154
7155         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7156         if (op_mode == OUT_OF_PLACE)
7157                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7158
7159         /* clear mbuf payload */
7160         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7161                 rte_pktmbuf_tailroom(ut_params->ibuf));
7162         if (op_mode == OUT_OF_PLACE) {
7163
7164                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7165                                 rte_pktmbuf_tailroom(ut_params->obuf));
7166         }
7167
7168         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7169         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7170         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7171         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7172
7173         if (verify) {
7174                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7175                                 ciphertext_pad_len);
7176                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7177                 if (op_mode == OUT_OF_PLACE)
7178                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7179                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7180                                 ciphertext_len);
7181         } else {
7182                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7183                                 plaintext_pad_len);
7184                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7185                 if (op_mode == OUT_OF_PLACE)
7186                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7187                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7188         }
7189
7190         /* Create the operation */
7191         retval = create_wireless_algo_auth_cipher_operation(
7192                         tdata->digest_enc.data, tdata->digest_enc.len,
7193                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7194                         tdata->auth_iv.data, tdata->auth_iv.len,
7195                         (tdata->digest_enc.offset == 0 ?
7196                                 plaintext_pad_len
7197                                 : tdata->digest_enc.offset),
7198                         tdata->validCipherLen.len_bits,
7199                         tdata->cipher.offset_bits,
7200                         tdata->validAuthLen.len_bits,
7201                         tdata->auth.offset_bits,
7202                         op_mode, 0, verify);
7203
7204         if (retval < 0)
7205                 return retval;
7206
7207         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7208
7209         /* Check if the op failed because the device doesn't */
7210         /* support this particular combination of algorithms */
7211         if (op == NULL && ut_params->op->status ==
7212                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7213                 printf("Device doesn't support this mixed combination. "
7214                                 "Test Skipped.\n");
7215                 return TEST_SKIPPED;
7216         }
7217         ut_params->op = op;
7218
7219         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7220
7221         ut_params->obuf = (op_mode == IN_PLACE ?
7222                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7223
7224         if (verify) {
7225                 if (ut_params->obuf)
7226                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7227                                                         uint8_t *);
7228                 else
7229                         plaintext = ciphertext +
7230                                         (tdata->cipher.offset_bits >> 3);
7231
7232                 debug_hexdump(stdout, "plaintext:", plaintext,
7233                                 tdata->plaintext.len_bits >> 3);
7234                 debug_hexdump(stdout, "plaintext expected:",
7235                                 tdata->plaintext.data,
7236                                 tdata->plaintext.len_bits >> 3);
7237         } else {
7238                 if (ut_params->obuf)
7239                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7240                                         uint8_t *);
7241                 else
7242                         ciphertext = plaintext;
7243
7244                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7245                                 ciphertext_len);
7246                 debug_hexdump(stdout, "ciphertext expected:",
7247                                 tdata->ciphertext.data,
7248                                 tdata->ciphertext.len_bits >> 3);
7249
7250                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7251                                 + (tdata->digest_enc.offset == 0 ?
7252                 plaintext_pad_len : tdata->digest_enc.offset);
7253
7254                 debug_hexdump(stdout, "digest:", ut_params->digest,
7255                                 tdata->digest_enc.len);
7256                 debug_hexdump(stdout, "digest expected:",
7257                                 tdata->digest_enc.data,
7258                                 tdata->digest_enc.len);
7259         }
7260
7261         /* Validate obuf */
7262         if (verify) {
7263                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7264                                 plaintext,
7265                                 tdata->plaintext.data,
7266                                 tdata->plaintext.len_bits >> 3,
7267                                 "Plaintext data not as expected");
7268         } else {
7269                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7270                                 ciphertext,
7271                                 tdata->ciphertext.data,
7272                                 tdata->validDataLen.len_bits,
7273                                 "Ciphertext data not as expected");
7274
7275                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7276                                 ut_params->digest,
7277                                 tdata->digest_enc.data,
7278                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7279                                 "Generated auth tag not as expected");
7280         }
7281
7282         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7283                         "crypto op processing failed");
7284
7285         return 0;
7286 }
7287
7288 static int
7289 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7290         uint8_t op_mode, uint8_t verify)
7291 {
7292         struct crypto_testsuite_params *ts_params = &testsuite_params;
7293         struct crypto_unittest_params *ut_params = &unittest_params;
7294
7295         int retval;
7296
7297         const uint8_t *plaintext = NULL;
7298         const uint8_t *ciphertext = NULL;
7299         const uint8_t *digest = NULL;
7300         unsigned int plaintext_pad_len;
7301         unsigned int plaintext_len;
7302         unsigned int ciphertext_pad_len;
7303         unsigned int ciphertext_len;
7304         uint8_t buffer[10000];
7305         uint8_t digest_buffer[10000];
7306
7307         struct rte_cryptodev_info dev_info;
7308         struct rte_crypto_op *op;
7309
7310         /* Check if device supports particular algorithms */
7311         if (test_mixed_check_if_unsupported(tdata))
7312                 return TEST_SKIPPED;
7313         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7314                 return TEST_SKIPPED;
7315
7316         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7317
7318         uint64_t feat_flags = dev_info.feature_flags;
7319
7320         if (op_mode == IN_PLACE) {
7321                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7322                         printf("Device doesn't support in-place scatter-gather "
7323                                         "in both input and output mbufs.\n");
7324                         return TEST_SKIPPED;
7325                 }
7326         } else {
7327                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7328                         printf("Device doesn't support out-of-place scatter-gather "
7329                                         "in both input and output mbufs.\n");
7330                         return TEST_SKIPPED;
7331                 }
7332                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7333                         printf("Device doesn't support digest encrypted.\n");
7334                         return TEST_SKIPPED;
7335                 }
7336         }
7337
7338         /* Create the session */
7339         if (verify)
7340                 retval = create_wireless_algo_cipher_auth_session(
7341                                 ts_params->valid_devs[0],
7342                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7343                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7344                                 tdata->auth_algo,
7345                                 tdata->cipher_algo,
7346                                 tdata->auth_key.data, tdata->auth_key.len,
7347                                 tdata->auth_iv.len, tdata->digest_enc.len,
7348                                 tdata->cipher_iv.len);
7349         else
7350                 retval = create_wireless_algo_auth_cipher_session(
7351                                 ts_params->valid_devs[0],
7352                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7353                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7354                                 tdata->auth_algo,
7355                                 tdata->cipher_algo,
7356                                 tdata->auth_key.data, tdata->auth_key.len,
7357                                 tdata->auth_iv.len, tdata->digest_enc.len,
7358                                 tdata->cipher_iv.len);
7359         if (retval != 0)
7360                 return retval;
7361
7362         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7363         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7364         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7365         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7366
7367         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7368                         ciphertext_pad_len, 15, 0);
7369         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7370                         "Failed to allocate input buffer in mempool");
7371
7372         if (op_mode == OUT_OF_PLACE) {
7373                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7374                                 plaintext_pad_len, 15, 0);
7375                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
7376                                 "Failed to allocate output buffer in mempool");
7377         }
7378
7379         if (verify) {
7380                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7381                         tdata->ciphertext.data);
7382                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7383                                         ciphertext_len, buffer);
7384                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7385                         ciphertext_len);
7386         } else {
7387                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7388                         tdata->plaintext.data);
7389                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7390                                         plaintext_len, buffer);
7391                 debug_hexdump(stdout, "plaintext:", plaintext,
7392                         plaintext_len);
7393         }
7394         memset(buffer, 0, sizeof(buffer));
7395
7396         /* Create the operation */
7397         retval = create_wireless_algo_auth_cipher_operation(
7398                         tdata->digest_enc.data, tdata->digest_enc.len,
7399                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7400                         tdata->auth_iv.data, tdata->auth_iv.len,
7401                         (tdata->digest_enc.offset == 0 ?
7402                                 plaintext_pad_len
7403                                 : tdata->digest_enc.offset),
7404                         tdata->validCipherLen.len_bits,
7405                         tdata->cipher.offset_bits,
7406                         tdata->validAuthLen.len_bits,
7407                         tdata->auth.offset_bits,
7408                         op_mode, 1, verify);
7409
7410         if (retval < 0)
7411                 return retval;
7412
7413         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7414
7415         /* Check if the op failed because the device doesn't */
7416         /* support this particular combination of algorithms */
7417         if (op == NULL && ut_params->op->status ==
7418                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7419                 printf("Device doesn't support this mixed combination. "
7420                                 "Test Skipped.\n");
7421                 return TEST_SKIPPED;
7422         }
7423         ut_params->op = op;
7424
7425         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7426
7427         ut_params->obuf = (op_mode == IN_PLACE ?
7428                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7429
7430         if (verify) {
7431                 if (ut_params->obuf)
7432                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7433                                         plaintext_len, buffer);
7434                 else
7435                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7436                                         plaintext_len, buffer);
7437
7438                 debug_hexdump(stdout, "plaintext:", plaintext,
7439                                 (tdata->plaintext.len_bits >> 3) -
7440                                 tdata->digest_enc.len);
7441                 debug_hexdump(stdout, "plaintext expected:",
7442                                 tdata->plaintext.data,
7443                                 (tdata->plaintext.len_bits >> 3) -
7444                                 tdata->digest_enc.len);
7445         } else {
7446                 if (ut_params->obuf)
7447                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7448                                         ciphertext_len, buffer);
7449                 else
7450                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7451                                         ciphertext_len, buffer);
7452
7453                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7454                         ciphertext_len);
7455                 debug_hexdump(stdout, "ciphertext expected:",
7456                         tdata->ciphertext.data,
7457                         tdata->ciphertext.len_bits >> 3);
7458
7459                 if (ut_params->obuf)
7460                         digest = rte_pktmbuf_read(ut_params->obuf,
7461                                         (tdata->digest_enc.offset == 0 ?
7462                                                 plaintext_pad_len :
7463                                                 tdata->digest_enc.offset),
7464                                         tdata->digest_enc.len, digest_buffer);
7465                 else
7466                         digest = rte_pktmbuf_read(ut_params->ibuf,
7467                                         (tdata->digest_enc.offset == 0 ?
7468                                                 plaintext_pad_len :
7469                                                 tdata->digest_enc.offset),
7470                                         tdata->digest_enc.len, digest_buffer);
7471
7472                 debug_hexdump(stdout, "digest:", digest,
7473                                 tdata->digest_enc.len);
7474                 debug_hexdump(stdout, "digest expected:",
7475                                 tdata->digest_enc.data, tdata->digest_enc.len);
7476         }
7477
7478         /* Validate obuf */
7479         if (verify) {
7480                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7481                                 plaintext,
7482                                 tdata->plaintext.data,
7483                                 tdata->plaintext.len_bits >> 3,
7484                                 "Plaintext data not as expected");
7485         } else {
7486                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7487                                 ciphertext,
7488                                 tdata->ciphertext.data,
7489                                 tdata->validDataLen.len_bits,
7490                                 "Ciphertext data not as expected");
7491                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7492                                 digest,
7493                                 tdata->digest_enc.data,
7494                                 tdata->digest_enc.len,
7495                                 "Generated auth tag not as expected");
7496         }
7497
7498         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7499                         "crypto op processing failed");
7500
7501         return 0;
7502 }
7503
7504 /** AUTH AES CMAC + CIPHER AES CTR */
7505
7506 static int
7507 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7508 {
7509         return test_mixed_auth_cipher(
7510                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7511 }
7512
7513 static int
7514 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7515 {
7516         return test_mixed_auth_cipher(
7517                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7518 }
7519
7520 static int
7521 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7522 {
7523         return test_mixed_auth_cipher_sgl(
7524                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7525 }
7526
7527 static int
7528 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7529 {
7530         return test_mixed_auth_cipher_sgl(
7531                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7532 }
7533
7534 static int
7535 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7536 {
7537         return test_mixed_auth_cipher(
7538                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7539 }
7540
7541 static int
7542 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7543 {
7544         return test_mixed_auth_cipher(
7545                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7546 }
7547
7548 static int
7549 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7550 {
7551         return test_mixed_auth_cipher_sgl(
7552                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7553 }
7554
7555 static int
7556 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7557 {
7558         return test_mixed_auth_cipher_sgl(
7559                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7560 }
7561
7562 /** MIXED AUTH + CIPHER */
7563
7564 static int
7565 test_auth_zuc_cipher_snow_test_case_1(void)
7566 {
7567         return test_mixed_auth_cipher(
7568                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7569 }
7570
7571 static int
7572 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7573 {
7574         return test_mixed_auth_cipher(
7575                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7576 }
7577
7578 static int
7579 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7580 {
7581         return test_mixed_auth_cipher(
7582                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7583 }
7584
7585 static int
7586 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7587 {
7588         return test_mixed_auth_cipher(
7589                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7590 }
7591
7592 static int
7593 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7594 {
7595         return test_mixed_auth_cipher(
7596                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7597 }
7598
7599 static int
7600 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7601 {
7602         return test_mixed_auth_cipher(
7603                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7604 }
7605
7606 static int
7607 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7608 {
7609         return test_mixed_auth_cipher(
7610                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7611 }
7612
7613 static int
7614 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7615 {
7616         return test_mixed_auth_cipher(
7617                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7618 }
7619
7620 static int
7621 test_auth_snow_cipher_zuc_test_case_1(void)
7622 {
7623         return test_mixed_auth_cipher(
7624                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7625 }
7626
7627 static int
7628 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7629 {
7630         return test_mixed_auth_cipher(
7631                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7632 }
7633
7634 static int
7635 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7636 {
7637         return test_mixed_auth_cipher(
7638                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7639 }
7640
7641 static int
7642 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7643 {
7644         return test_mixed_auth_cipher(
7645                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7646 }
7647
7648 static int
7649 test_auth_null_cipher_snow_test_case_1(void)
7650 {
7651         return test_mixed_auth_cipher(
7652                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7653 }
7654
7655 static int
7656 test_verify_auth_null_cipher_snow_test_case_1(void)
7657 {
7658         return test_mixed_auth_cipher(
7659                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7660 }
7661
7662 static int
7663 test_auth_null_cipher_zuc_test_case_1(void)
7664 {
7665         return test_mixed_auth_cipher(
7666                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7667 }
7668
7669 static int
7670 test_verify_auth_null_cipher_zuc_test_case_1(void)
7671 {
7672         return test_mixed_auth_cipher(
7673                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7674 }
7675
7676 static int
7677 test_auth_snow_cipher_null_test_case_1(void)
7678 {
7679         return test_mixed_auth_cipher(
7680                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7681 }
7682
7683 static int
7684 test_verify_auth_snow_cipher_null_test_case_1(void)
7685 {
7686         return test_mixed_auth_cipher(
7687                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7688 }
7689
7690 static int
7691 test_auth_zuc_cipher_null_test_case_1(void)
7692 {
7693         return test_mixed_auth_cipher(
7694                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7695 }
7696
7697 static int
7698 test_verify_auth_zuc_cipher_null_test_case_1(void)
7699 {
7700         return test_mixed_auth_cipher(
7701                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7702 }
7703
7704 static int
7705 test_auth_null_cipher_aes_ctr_test_case_1(void)
7706 {
7707         return test_mixed_auth_cipher(
7708                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7709 }
7710
7711 static int
7712 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7713 {
7714         return test_mixed_auth_cipher(
7715                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7716 }
7717
7718 static int
7719 test_auth_aes_cmac_cipher_null_test_case_1(void)
7720 {
7721         return test_mixed_auth_cipher(
7722                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7723 }
7724
7725 static int
7726 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7727 {
7728         return test_mixed_auth_cipher(
7729                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7730 }
7731
7732 /* ***** AEAD algorithm Tests ***** */
7733
7734 static int
7735 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7736                 enum rte_crypto_aead_operation op,
7737                 const uint8_t *key, const uint8_t key_len,
7738                 const uint16_t aad_len, const uint8_t auth_len,
7739                 uint8_t iv_len)
7740 {
7741         uint8_t aead_key[key_len];
7742
7743         struct crypto_testsuite_params *ts_params = &testsuite_params;
7744         struct crypto_unittest_params *ut_params = &unittest_params;
7745
7746         memcpy(aead_key, key, key_len);
7747
7748         /* Setup AEAD Parameters */
7749         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7750         ut_params->aead_xform.next = NULL;
7751         ut_params->aead_xform.aead.algo = algo;
7752         ut_params->aead_xform.aead.op = op;
7753         ut_params->aead_xform.aead.key.data = aead_key;
7754         ut_params->aead_xform.aead.key.length = key_len;
7755         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7756         ut_params->aead_xform.aead.iv.length = iv_len;
7757         ut_params->aead_xform.aead.digest_length = auth_len;
7758         ut_params->aead_xform.aead.aad_length = aad_len;
7759
7760         debug_hexdump(stdout, "key:", key, key_len);
7761
7762         /* Create Crypto session*/
7763         ut_params->sess = rte_cryptodev_sym_session_create(
7764                         ts_params->session_mpool);
7765
7766         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7767                         &ut_params->aead_xform,
7768                         ts_params->session_priv_mpool);
7769
7770         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7771
7772         return 0;
7773 }
7774
7775 static int
7776 create_aead_xform(struct rte_crypto_op *op,
7777                 enum rte_crypto_aead_algorithm algo,
7778                 enum rte_crypto_aead_operation aead_op,
7779                 uint8_t *key, const uint8_t key_len,
7780                 const uint8_t aad_len, const uint8_t auth_len,
7781                 uint8_t iv_len)
7782 {
7783         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7784                         "failed to allocate space for crypto transform");
7785
7786         struct rte_crypto_sym_op *sym_op = op->sym;
7787
7788         /* Setup AEAD Parameters */
7789         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7790         sym_op->xform->next = NULL;
7791         sym_op->xform->aead.algo = algo;
7792         sym_op->xform->aead.op = aead_op;
7793         sym_op->xform->aead.key.data = key;
7794         sym_op->xform->aead.key.length = key_len;
7795         sym_op->xform->aead.iv.offset = IV_OFFSET;
7796         sym_op->xform->aead.iv.length = iv_len;
7797         sym_op->xform->aead.digest_length = auth_len;
7798         sym_op->xform->aead.aad_length = aad_len;
7799
7800         debug_hexdump(stdout, "key:", key, key_len);
7801
7802         return 0;
7803 }
7804
7805 static int
7806 create_aead_operation(enum rte_crypto_aead_operation op,
7807                 const struct aead_test_data *tdata)
7808 {
7809         struct crypto_testsuite_params *ts_params = &testsuite_params;
7810         struct crypto_unittest_params *ut_params = &unittest_params;
7811
7812         uint8_t *plaintext, *ciphertext;
7813         unsigned int aad_pad_len, plaintext_pad_len;
7814
7815         /* Generate Crypto op data structure */
7816         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7817                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7818         TEST_ASSERT_NOT_NULL(ut_params->op,
7819                         "Failed to allocate symmetric crypto operation struct");
7820
7821         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7822
7823         /* Append aad data */
7824         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7825                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7826                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7827                                 aad_pad_len);
7828                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7829                                 "no room to append aad");
7830
7831                 sym_op->aead.aad.phys_addr =
7832                                 rte_pktmbuf_iova(ut_params->ibuf);
7833                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
7834                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7835                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7836                         tdata->aad.len);
7837
7838                 /* Append IV at the end of the crypto operation*/
7839                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7840                                 uint8_t *, IV_OFFSET);
7841
7842                 /* Copy IV 1 byte after the IV pointer, according to the API */
7843                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7844                 debug_hexdump(stdout, "iv:", iv_ptr,
7845                         tdata->iv.len);
7846         } else {
7847                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7848                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7849                                 aad_pad_len);
7850                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7851                                 "no room to append aad");
7852
7853                 sym_op->aead.aad.phys_addr =
7854                                 rte_pktmbuf_iova(ut_params->ibuf);
7855                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7856                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7857                         tdata->aad.len);
7858
7859                 /* Append IV at the end of the crypto operation*/
7860                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7861                                 uint8_t *, IV_OFFSET);
7862
7863                 if (tdata->iv.len == 0) {
7864                         rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7865                         debug_hexdump(stdout, "iv:", iv_ptr,
7866                                 AES_GCM_J0_LENGTH);
7867                 } else {
7868                         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7869                         debug_hexdump(stdout, "iv:", iv_ptr,
7870                                 tdata->iv.len);
7871                 }
7872         }
7873
7874         /* Append plaintext/ciphertext */
7875         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7876                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7877                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7878                                 plaintext_pad_len);
7879                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7880
7881                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7882                 debug_hexdump(stdout, "plaintext:", plaintext,
7883                                 tdata->plaintext.len);
7884
7885                 if (ut_params->obuf) {
7886                         ciphertext = (uint8_t *)rte_pktmbuf_append(
7887                                         ut_params->obuf,
7888                                         plaintext_pad_len + aad_pad_len);
7889                         TEST_ASSERT_NOT_NULL(ciphertext,
7890                                         "no room to append ciphertext");
7891
7892                         memset(ciphertext + aad_pad_len, 0,
7893                                         tdata->ciphertext.len);
7894                 }
7895         } else {
7896                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7897                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7898                                 plaintext_pad_len);
7899                 TEST_ASSERT_NOT_NULL(ciphertext,
7900                                 "no room to append ciphertext");
7901
7902                 memcpy(ciphertext, tdata->ciphertext.data,
7903                                 tdata->ciphertext.len);
7904                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7905                                 tdata->ciphertext.len);
7906
7907                 if (ut_params->obuf) {
7908                         plaintext = (uint8_t *)rte_pktmbuf_append(
7909                                         ut_params->obuf,
7910                                         plaintext_pad_len + aad_pad_len);
7911                         TEST_ASSERT_NOT_NULL(plaintext,
7912                                         "no room to append plaintext");
7913
7914                         memset(plaintext + aad_pad_len, 0,
7915                                         tdata->plaintext.len);
7916                 }
7917         }
7918
7919         /* Append digest data */
7920         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7921                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7922                                 ut_params->obuf ? ut_params->obuf :
7923                                                 ut_params->ibuf,
7924                                                 tdata->auth_tag.len);
7925                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7926                                 "no room to append digest");
7927                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
7928                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7929                                 ut_params->obuf ? ut_params->obuf :
7930                                                 ut_params->ibuf,
7931                                                 plaintext_pad_len +
7932                                                 aad_pad_len);
7933         } else {
7934                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7935                                 ut_params->ibuf, tdata->auth_tag.len);
7936                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7937                                 "no room to append digest");
7938                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7939                                 ut_params->ibuf,
7940                                 plaintext_pad_len + aad_pad_len);
7941
7942                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
7943                         tdata->auth_tag.len);
7944                 debug_hexdump(stdout, "digest:",
7945                         sym_op->aead.digest.data,
7946                         tdata->auth_tag.len);
7947         }
7948
7949         sym_op->aead.data.length = tdata->plaintext.len;
7950         sym_op->aead.data.offset = aad_pad_len;
7951
7952         return 0;
7953 }
7954
7955 static int
7956 test_authenticated_encryption(const struct aead_test_data *tdata)
7957 {
7958         struct crypto_testsuite_params *ts_params = &testsuite_params;
7959         struct crypto_unittest_params *ut_params = &unittest_params;
7960
7961         int retval;
7962         uint8_t *ciphertext, *auth_tag;
7963         uint16_t plaintext_pad_len;
7964         uint32_t i;
7965         struct rte_cryptodev_info dev_info;
7966
7967         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7968         uint64_t feat_flags = dev_info.feature_flags;
7969
7970         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
7971                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
7972                 printf("Device doesn't support RAW data-path APIs.\n");
7973                 return TEST_SKIPPED;
7974         }
7975
7976         /* Verify the capabilities */
7977         struct rte_cryptodev_sym_capability_idx cap_idx;
7978         const struct rte_cryptodev_symmetric_capability *capability;
7979         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7980         cap_idx.algo.aead = tdata->algo;
7981         capability = rte_cryptodev_sym_capability_get(
7982                         ts_params->valid_devs[0], &cap_idx);
7983         if (capability == NULL)
7984                 return TEST_SKIPPED;
7985         if (rte_cryptodev_sym_capability_check_aead(
7986                         capability, tdata->key.len, tdata->auth_tag.len,
7987                         tdata->aad.len, tdata->iv.len))
7988                 return TEST_SKIPPED;
7989
7990         /* Create AEAD session */
7991         retval = create_aead_session(ts_params->valid_devs[0],
7992                         tdata->algo,
7993                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
7994                         tdata->key.data, tdata->key.len,
7995                         tdata->aad.len, tdata->auth_tag.len,
7996                         tdata->iv.len);
7997         if (retval < 0)
7998                 return retval;
7999
8000         if (tdata->aad.len > MBUF_SIZE) {
8001                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8002                 /* Populate full size of add data */
8003                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8004                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8005         } else
8006                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8007
8008         /* clear mbuf payload */
8009         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8010                         rte_pktmbuf_tailroom(ut_params->ibuf));
8011
8012         /* Create AEAD operation */
8013         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8014         if (retval < 0)
8015                 return retval;
8016
8017         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8018
8019         ut_params->op->sym->m_src = ut_params->ibuf;
8020
8021         /* Process crypto operation */
8022         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8023                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8024         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8025                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8026                                 ut_params->op, 0, 0, 0, 0);
8027         else
8028                 TEST_ASSERT_NOT_NULL(
8029                         process_crypto_request(ts_params->valid_devs[0],
8030                         ut_params->op), "failed to process sym crypto op");
8031
8032         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8033                         "crypto op processing failed");
8034
8035         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8036
8037         if (ut_params->op->sym->m_dst) {
8038                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8039                                 uint8_t *);
8040                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8041                                 uint8_t *, plaintext_pad_len);
8042         } else {
8043                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8044                                 uint8_t *,
8045                                 ut_params->op->sym->cipher.data.offset);
8046                 auth_tag = ciphertext + plaintext_pad_len;
8047         }
8048
8049         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8050         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8051
8052         /* Validate obuf */
8053         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8054                         ciphertext,
8055                         tdata->ciphertext.data,
8056                         tdata->ciphertext.len,
8057                         "Ciphertext data not as expected");
8058
8059         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8060                         auth_tag,
8061                         tdata->auth_tag.data,
8062                         tdata->auth_tag.len,
8063                         "Generated auth tag not as expected");
8064
8065         return 0;
8066
8067 }
8068
8069 #ifdef RTE_LIB_SECURITY
8070 static int
8071 security_proto_supported(enum rte_security_session_action_type action,
8072         enum rte_security_session_protocol proto)
8073 {
8074         struct crypto_testsuite_params *ts_params = &testsuite_params;
8075
8076         const struct rte_security_capability *capabilities;
8077         const struct rte_security_capability *capability;
8078         uint16_t i = 0;
8079
8080         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8081                                 rte_cryptodev_get_sec_ctx(
8082                                 ts_params->valid_devs[0]);
8083
8084
8085         capabilities = rte_security_capabilities_get(ctx);
8086
8087         if (capabilities == NULL)
8088                 return -ENOTSUP;
8089
8090         while ((capability = &capabilities[i++])->action !=
8091                         RTE_SECURITY_ACTION_TYPE_NONE) {
8092                 if (capability->action == action &&
8093                                 capability->protocol == proto)
8094                         return 0;
8095         }
8096
8097         return -ENOTSUP;
8098 }
8099
8100 /* Basic algorithm run function for async inplace mode.
8101  * Creates a session from input parameters and runs one operation
8102  * on input_vec. Checks the output of the crypto operation against
8103  * output_vec.
8104  */
8105 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8106                            enum rte_crypto_auth_operation opa,
8107                            const uint8_t *input_vec, unsigned int input_vec_len,
8108                            const uint8_t *output_vec,
8109                            unsigned int output_vec_len,
8110                            enum rte_crypto_cipher_algorithm cipher_alg,
8111                            const uint8_t *cipher_key, uint32_t cipher_key_len,
8112                            enum rte_crypto_auth_algorithm auth_alg,
8113                            const uint8_t *auth_key, uint32_t auth_key_len,
8114                            uint8_t bearer, enum rte_security_pdcp_domain domain,
8115                            uint8_t packet_direction, uint8_t sn_size,
8116                            uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8117 {
8118         struct crypto_testsuite_params *ts_params = &testsuite_params;
8119         struct crypto_unittest_params *ut_params = &unittest_params;
8120         uint8_t *plaintext;
8121         int ret = TEST_SUCCESS;
8122         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8123                                 rte_cryptodev_get_sec_ctx(
8124                                 ts_params->valid_devs[0]);
8125
8126         /* Verify the capabilities */
8127         struct rte_security_capability_idx sec_cap_idx;
8128
8129         sec_cap_idx.action = ut_params->type;
8130         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8131         sec_cap_idx.pdcp.domain = domain;
8132         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8133                 return TEST_SKIPPED;
8134
8135         /* Generate test mbuf data */
8136         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8137
8138         /* clear mbuf payload */
8139         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8140                         rte_pktmbuf_tailroom(ut_params->ibuf));
8141
8142         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8143                                                   input_vec_len);
8144         memcpy(plaintext, input_vec, input_vec_len);
8145
8146         /* Out of place support */
8147         if (oop) {
8148                 /*
8149                  * For out-op-place we need to alloc another mbuf
8150                  */
8151                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8152                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8153         }
8154
8155         /* Setup Cipher Parameters */
8156         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8157         ut_params->cipher_xform.cipher.algo = cipher_alg;
8158         ut_params->cipher_xform.cipher.op = opc;
8159         ut_params->cipher_xform.cipher.key.data = cipher_key;
8160         ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8161         ut_params->cipher_xform.cipher.iv.length =
8162                                 packet_direction ? 4 : 0;
8163         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8164
8165         /* Setup HMAC Parameters if ICV header is required */
8166         if (auth_alg != 0) {
8167                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8168                 ut_params->auth_xform.next = NULL;
8169                 ut_params->auth_xform.auth.algo = auth_alg;
8170                 ut_params->auth_xform.auth.op = opa;
8171                 ut_params->auth_xform.auth.key.data = auth_key;
8172                 ut_params->auth_xform.auth.key.length = auth_key_len;
8173
8174                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8175         } else {
8176                 ut_params->cipher_xform.next = NULL;
8177         }
8178
8179         struct rte_security_session_conf sess_conf = {
8180                 .action_type = ut_params->type,
8181                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8182                 {.pdcp = {
8183                         .bearer = bearer,
8184                         .domain = domain,
8185                         .pkt_dir = packet_direction,
8186                         .sn_size = sn_size,
8187                         .hfn = packet_direction ? 0 : hfn,
8188                         /**
8189                          * hfn can be set as pdcp_test_hfn[i]
8190                          * if hfn_ovrd is not set. Here, PDCP
8191                          * packet direction is just used to
8192                          * run half of the cases with session
8193                          * HFN and other half with per packet
8194                          * HFN.
8195                          */
8196                         .hfn_threshold = hfn_threshold,
8197                         .hfn_ovrd = packet_direction ? 1 : 0,
8198                         .sdap_enabled = sdap,
8199                 } },
8200                 .crypto_xform = &ut_params->cipher_xform
8201         };
8202
8203         /* Create security session */
8204         ut_params->sec_session = rte_security_session_create(ctx,
8205                                 &sess_conf, ts_params->session_mpool,
8206                                 ts_params->session_priv_mpool);
8207
8208         if (!ut_params->sec_session) {
8209                 printf("TestCase %s()-%d line %d failed %s: ",
8210                         __func__, i, __LINE__, "Failed to allocate session");
8211                 ret = TEST_FAILED;
8212                 goto on_err;
8213         }
8214
8215         /* Generate crypto op data structure */
8216         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8217                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8218         if (!ut_params->op) {
8219                 printf("TestCase %s()-%d line %d failed %s: ",
8220                         __func__, i, __LINE__,
8221                         "Failed to allocate symmetric crypto operation struct");
8222                 ret = TEST_FAILED;
8223                 goto on_err;
8224         }
8225
8226         uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8227                                         uint32_t *, IV_OFFSET);
8228         *per_pkt_hfn = packet_direction ? hfn : 0;
8229
8230         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8231
8232         /* set crypto operation source mbuf */
8233         ut_params->op->sym->m_src = ut_params->ibuf;
8234         if (oop)
8235                 ut_params->op->sym->m_dst = ut_params->obuf;
8236
8237         /* Process crypto operation */
8238         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8239                 == NULL) {
8240                 printf("TestCase %s()-%d line %d failed %s: ",
8241                         __func__, i, __LINE__,
8242                         "failed to process sym crypto op");
8243                 ret = TEST_FAILED;
8244                 goto on_err;
8245         }
8246
8247         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8248                 printf("TestCase %s()-%d line %d failed %s: ",
8249                         __func__, i, __LINE__, "crypto op processing failed");
8250                 ret = TEST_FAILED;
8251                 goto on_err;
8252         }
8253
8254         /* Validate obuf */
8255         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8256                         uint8_t *);
8257         if (oop) {
8258                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8259                                 uint8_t *);
8260         }
8261
8262         if (memcmp(ciphertext, output_vec, output_vec_len)) {
8263                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8264                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8265                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8266                 ret = TEST_FAILED;
8267                 goto on_err;
8268         }
8269
8270 on_err:
8271         rte_crypto_op_free(ut_params->op);
8272         ut_params->op = NULL;
8273
8274         if (ut_params->sec_session)
8275                 rte_security_session_destroy(ctx, ut_params->sec_session);
8276         ut_params->sec_session = NULL;
8277
8278         rte_pktmbuf_free(ut_params->ibuf);
8279         ut_params->ibuf = NULL;
8280         if (oop) {
8281                 rte_pktmbuf_free(ut_params->obuf);
8282                 ut_params->obuf = NULL;
8283         }
8284
8285         return ret;
8286 }
8287
8288 static int
8289 test_pdcp_proto_SGL(int i, int oop,
8290         enum rte_crypto_cipher_operation opc,
8291         enum rte_crypto_auth_operation opa,
8292         uint8_t *input_vec,
8293         unsigned int input_vec_len,
8294         uint8_t *output_vec,
8295         unsigned int output_vec_len,
8296         uint32_t fragsz,
8297         uint32_t fragsz_oop)
8298 {
8299         struct crypto_testsuite_params *ts_params = &testsuite_params;
8300         struct crypto_unittest_params *ut_params = &unittest_params;
8301         uint8_t *plaintext;
8302         struct rte_mbuf *buf, *buf_oop = NULL;
8303         int ret = TEST_SUCCESS;
8304         int to_trn = 0;
8305         int to_trn_tbl[16];
8306         int segs = 1;
8307         unsigned int trn_data = 0;
8308         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8309                                 rte_cryptodev_get_sec_ctx(
8310                                 ts_params->valid_devs[0]);
8311
8312         /* Verify the capabilities */
8313         struct rte_security_capability_idx sec_cap_idx;
8314
8315         sec_cap_idx.action = ut_params->type;
8316         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8317         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8318         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8319                 return TEST_SKIPPED;
8320
8321         if (fragsz > input_vec_len)
8322                 fragsz = input_vec_len;
8323
8324         uint16_t plaintext_len = fragsz;
8325         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8326
8327         if (fragsz_oop > output_vec_len)
8328                 frag_size_oop = output_vec_len;
8329
8330         int ecx = 0;
8331         if (input_vec_len % fragsz != 0) {
8332                 if (input_vec_len / fragsz + 1 > 16)
8333                         return 1;
8334         } else if (input_vec_len / fragsz > 16)
8335                 return 1;
8336
8337         /* Out of place support */
8338         if (oop) {
8339                 /*
8340                  * For out-op-place we need to alloc another mbuf
8341                  */
8342                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8343                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8344                 buf_oop = ut_params->obuf;
8345         }
8346
8347         /* Generate test mbuf data */
8348         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8349
8350         /* clear mbuf payload */
8351         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8352                         rte_pktmbuf_tailroom(ut_params->ibuf));
8353
8354         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8355                                                   plaintext_len);
8356         memcpy(plaintext, input_vec, plaintext_len);
8357         trn_data += plaintext_len;
8358
8359         buf = ut_params->ibuf;
8360
8361         /*
8362          * Loop until no more fragments
8363          */
8364
8365         while (trn_data < input_vec_len) {
8366                 ++segs;
8367                 to_trn = (input_vec_len - trn_data < fragsz) ?
8368                                 (input_vec_len - trn_data) : fragsz;
8369
8370                 to_trn_tbl[ecx++] = to_trn;
8371
8372                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8373                 buf = buf->next;
8374
8375                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8376                                 rte_pktmbuf_tailroom(buf));
8377
8378                 /* OOP */
8379                 if (oop && !fragsz_oop) {
8380                         buf_oop->next =
8381                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8382                         buf_oop = buf_oop->next;
8383                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8384                                         0, rte_pktmbuf_tailroom(buf_oop));
8385                         rte_pktmbuf_append(buf_oop, to_trn);
8386                 }
8387
8388                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8389                                 to_trn);
8390
8391                 memcpy(plaintext, input_vec + trn_data, to_trn);
8392                 trn_data += to_trn;
8393         }
8394
8395         ut_params->ibuf->nb_segs = segs;
8396
8397         segs = 1;
8398         if (fragsz_oop && oop) {
8399                 to_trn = 0;
8400                 ecx = 0;
8401
8402                 trn_data = frag_size_oop;
8403                 while (trn_data < output_vec_len) {
8404                         ++segs;
8405                         to_trn =
8406                                 (output_vec_len - trn_data <
8407                                                 frag_size_oop) ?
8408                                 (output_vec_len - trn_data) :
8409                                                 frag_size_oop;
8410
8411                         to_trn_tbl[ecx++] = to_trn;
8412
8413                         buf_oop->next =
8414                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
8415                         buf_oop = buf_oop->next;
8416                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8417                                         0, rte_pktmbuf_tailroom(buf_oop));
8418                         rte_pktmbuf_append(buf_oop, to_trn);
8419
8420                         trn_data += to_trn;
8421                 }
8422                 ut_params->obuf->nb_segs = segs;
8423         }
8424
8425         /* Setup Cipher Parameters */
8426         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8427         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8428         ut_params->cipher_xform.cipher.op = opc;
8429         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8430         ut_params->cipher_xform.cipher.key.length =
8431                                         pdcp_test_params[i].cipher_key_len;
8432         ut_params->cipher_xform.cipher.iv.length = 0;
8433
8434         /* Setup HMAC Parameters if ICV header is required */
8435         if (pdcp_test_params[i].auth_alg != 0) {
8436                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8437                 ut_params->auth_xform.next = NULL;
8438                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8439                 ut_params->auth_xform.auth.op = opa;
8440                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8441                 ut_params->auth_xform.auth.key.length =
8442                                         pdcp_test_params[i].auth_key_len;
8443
8444                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8445         } else {
8446                 ut_params->cipher_xform.next = NULL;
8447         }
8448
8449         struct rte_security_session_conf sess_conf = {
8450                 .action_type = ut_params->type,
8451                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8452                 {.pdcp = {
8453                         .bearer = pdcp_test_bearer[i],
8454                         .domain = pdcp_test_params[i].domain,
8455                         .pkt_dir = pdcp_test_packet_direction[i],
8456                         .sn_size = pdcp_test_data_sn_size[i],
8457                         .hfn = pdcp_test_hfn[i],
8458                         .hfn_threshold = pdcp_test_hfn_threshold[i],
8459                         .hfn_ovrd = 0,
8460                 } },
8461                 .crypto_xform = &ut_params->cipher_xform
8462         };
8463
8464         /* Create security session */
8465         ut_params->sec_session = rte_security_session_create(ctx,
8466                                 &sess_conf, ts_params->session_mpool,
8467                                 ts_params->session_priv_mpool);
8468
8469         if (!ut_params->sec_session) {
8470                 printf("TestCase %s()-%d line %d failed %s: ",
8471                         __func__, i, __LINE__, "Failed to allocate session");
8472                 ret = TEST_FAILED;
8473                 goto on_err;
8474         }
8475
8476         /* Generate crypto op data structure */
8477         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8478                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8479         if (!ut_params->op) {
8480                 printf("TestCase %s()-%d line %d failed %s: ",
8481                         __func__, i, __LINE__,
8482                         "Failed to allocate symmetric crypto operation struct");
8483                 ret = TEST_FAILED;
8484                 goto on_err;
8485         }
8486
8487         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8488
8489         /* set crypto operation source mbuf */
8490         ut_params->op->sym->m_src = ut_params->ibuf;
8491         if (oop)
8492                 ut_params->op->sym->m_dst = ut_params->obuf;
8493
8494         /* Process crypto operation */
8495         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8496                 == NULL) {
8497                 printf("TestCase %s()-%d line %d failed %s: ",
8498                         __func__, i, __LINE__,
8499                         "failed to process sym crypto op");
8500                 ret = TEST_FAILED;
8501                 goto on_err;
8502         }
8503
8504         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8505                 printf("TestCase %s()-%d line %d failed %s: ",
8506                         __func__, i, __LINE__, "crypto op processing failed");
8507                 ret = TEST_FAILED;
8508                 goto on_err;
8509         }
8510
8511         /* Validate obuf */
8512         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8513                         uint8_t *);
8514         if (oop) {
8515                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8516                                 uint8_t *);
8517         }
8518         if (fragsz_oop)
8519                 fragsz = frag_size_oop;
8520         if (memcmp(ciphertext, output_vec, fragsz)) {
8521                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8522                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8523                 rte_hexdump(stdout, "reference", output_vec, fragsz);
8524                 ret = TEST_FAILED;
8525                 goto on_err;
8526         }
8527
8528         buf = ut_params->op->sym->m_src->next;
8529         if (oop)
8530                 buf = ut_params->op->sym->m_dst->next;
8531
8532         unsigned int off = fragsz;
8533
8534         ecx = 0;
8535         while (buf) {
8536                 ciphertext = rte_pktmbuf_mtod(buf,
8537                                 uint8_t *);
8538                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8539                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8540                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8541                         rte_hexdump(stdout, "reference", output_vec + off,
8542                                         to_trn_tbl[ecx]);
8543                         ret = TEST_FAILED;
8544                         goto on_err;
8545                 }
8546                 off += to_trn_tbl[ecx++];
8547                 buf = buf->next;
8548         }
8549 on_err:
8550         rte_crypto_op_free(ut_params->op);
8551         ut_params->op = NULL;
8552
8553         if (ut_params->sec_session)
8554                 rte_security_session_destroy(ctx, ut_params->sec_session);
8555         ut_params->sec_session = NULL;
8556
8557         rte_pktmbuf_free(ut_params->ibuf);
8558         ut_params->ibuf = NULL;
8559         if (oop) {
8560                 rte_pktmbuf_free(ut_params->obuf);
8561                 ut_params->obuf = NULL;
8562         }
8563
8564         return ret;
8565 }
8566
8567 int
8568 test_pdcp_proto_cplane_encap(int i)
8569 {
8570         return test_pdcp_proto(
8571                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8572                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8573                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8574                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8575                 pdcp_test_params[i].cipher_key_len,
8576                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8577                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8578                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8579                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8580                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8581 }
8582
8583 int
8584 test_pdcp_proto_uplane_encap(int i)
8585 {
8586         return test_pdcp_proto(
8587                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8588                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8589                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8590                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8591                 pdcp_test_params[i].cipher_key_len,
8592                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8593                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8594                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8595                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8596                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8597 }
8598
8599 int
8600 test_pdcp_proto_uplane_encap_with_int(int i)
8601 {
8602         return test_pdcp_proto(
8603                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8604                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8605                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8606                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8607                 pdcp_test_params[i].cipher_key_len,
8608                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8609                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8610                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8611                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8612                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8613 }
8614
8615 int
8616 test_pdcp_proto_cplane_decap(int i)
8617 {
8618         return test_pdcp_proto(
8619                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8620                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8621                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8622                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8623                 pdcp_test_params[i].cipher_key_len,
8624                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8625                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8626                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8627                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8628                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8629 }
8630
8631 int
8632 test_pdcp_proto_uplane_decap(int i)
8633 {
8634         return test_pdcp_proto(
8635                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8636                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8637                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8638                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8639                 pdcp_test_params[i].cipher_key_len,
8640                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8641                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8642                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8643                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8644                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8645 }
8646
8647 int
8648 test_pdcp_proto_uplane_decap_with_int(int i)
8649 {
8650         return test_pdcp_proto(
8651                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8652                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8653                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8654                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8655                 pdcp_test_params[i].cipher_key_len,
8656                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8657                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8658                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8659                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8660                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8661 }
8662
8663 static int
8664 test_PDCP_PROTO_SGL_in_place_32B(void)
8665 {
8666         /* i can be used for running any PDCP case
8667          * In this case it is uplane 12-bit AES-SNOW DL encap
8668          */
8669         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8670         return test_pdcp_proto_SGL(i, IN_PLACE,
8671                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8672                         RTE_CRYPTO_AUTH_OP_GENERATE,
8673                         pdcp_test_data_in[i],
8674                         pdcp_test_data_in_len[i],
8675                         pdcp_test_data_out[i],
8676                         pdcp_test_data_in_len[i]+4,
8677                         32, 0);
8678 }
8679 static int
8680 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8681 {
8682         /* i can be used for running any PDCP case
8683          * In this case it is uplane 18-bit NULL-NULL DL encap
8684          */
8685         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8686         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8687                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8688                         RTE_CRYPTO_AUTH_OP_GENERATE,
8689                         pdcp_test_data_in[i],
8690                         pdcp_test_data_in_len[i],
8691                         pdcp_test_data_out[i],
8692                         pdcp_test_data_in_len[i]+4,
8693                         32, 128);
8694 }
8695 static int
8696 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8697 {
8698         /* i can be used for running any PDCP case
8699          * In this case it is uplane 18-bit AES DL encap
8700          */
8701         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8702                         + DOWNLINK;
8703         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8704                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8705                         RTE_CRYPTO_AUTH_OP_GENERATE,
8706                         pdcp_test_data_in[i],
8707                         pdcp_test_data_in_len[i],
8708                         pdcp_test_data_out[i],
8709                         pdcp_test_data_in_len[i],
8710                         32, 40);
8711 }
8712 static int
8713 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8714 {
8715         /* i can be used for running any PDCP case
8716          * In this case it is cplane 12-bit AES-ZUC DL encap
8717          */
8718         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8719         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8720                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8721                         RTE_CRYPTO_AUTH_OP_GENERATE,
8722                         pdcp_test_data_in[i],
8723                         pdcp_test_data_in_len[i],
8724                         pdcp_test_data_out[i],
8725                         pdcp_test_data_in_len[i]+4,
8726                         128, 32);
8727 }
8728
8729 static int
8730 test_PDCP_SDAP_PROTO_encap_all(void)
8731 {
8732         int i = 0, size = 0;
8733         int err, all_err = TEST_SUCCESS;
8734         const struct pdcp_sdap_test *cur_test;
8735
8736         size = RTE_DIM(list_pdcp_sdap_tests);
8737
8738         for (i = 0; i < size; i++) {
8739                 cur_test = &list_pdcp_sdap_tests[i];
8740                 err = test_pdcp_proto(
8741                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8742                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8743                         cur_test->in_len, cur_test->data_out,
8744                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8745                         cur_test->param.cipher_alg, cur_test->cipher_key,
8746                         cur_test->param.cipher_key_len,
8747                         cur_test->param.auth_alg,
8748                         cur_test->auth_key, cur_test->param.auth_key_len,
8749                         cur_test->bearer, cur_test->param.domain,
8750                         cur_test->packet_direction, cur_test->sn_size,
8751                         cur_test->hfn,
8752                         cur_test->hfn_threshold, SDAP_ENABLED);
8753                 if (err) {
8754                         printf("\t%d) %s: Encapsulation failed\n",
8755                                         cur_test->test_idx,
8756                                         cur_test->param.name);
8757                         err = TEST_FAILED;
8758                 } else {
8759                         printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8760                                         cur_test->param.name);
8761                         err = TEST_SUCCESS;
8762                 }
8763                 all_err += err;
8764         }
8765
8766         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8767
8768         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8769 }
8770
8771 static int
8772 test_PDCP_SDAP_PROTO_decap_all(void)
8773 {
8774         int i = 0, size = 0;
8775         int err, all_err = TEST_SUCCESS;
8776         const struct pdcp_sdap_test *cur_test;
8777
8778         size = RTE_DIM(list_pdcp_sdap_tests);
8779
8780         for (i = 0; i < size; i++) {
8781                 cur_test = &list_pdcp_sdap_tests[i];
8782                 err = test_pdcp_proto(
8783                         i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8784                         RTE_CRYPTO_AUTH_OP_VERIFY,
8785                         cur_test->data_out,
8786                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8787                         cur_test->data_in, cur_test->in_len,
8788                         cur_test->param.cipher_alg,
8789                         cur_test->cipher_key, cur_test->param.cipher_key_len,
8790                         cur_test->param.auth_alg, cur_test->auth_key,
8791                         cur_test->param.auth_key_len, cur_test->bearer,
8792                         cur_test->param.domain, cur_test->packet_direction,
8793                         cur_test->sn_size, cur_test->hfn,
8794                         cur_test->hfn_threshold, SDAP_ENABLED);
8795                 if (err) {
8796                         printf("\t%d) %s: Decapsulation failed\n",
8797                                         cur_test->test_idx,
8798                                         cur_test->param.name);
8799                         err = TEST_FAILED;
8800                 } else {
8801                         printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8802                                         cur_test->param.name);
8803                         err = TEST_SUCCESS;
8804                 }
8805                 all_err += err;
8806         }
8807
8808         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8809
8810         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8811 }
8812
8813 static int
8814 test_PDCP_PROTO_all(void)
8815 {
8816         struct crypto_testsuite_params *ts_params = &testsuite_params;
8817         struct crypto_unittest_params *ut_params = &unittest_params;
8818         struct rte_cryptodev_info dev_info;
8819         int status;
8820
8821         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8822         uint64_t feat_flags = dev_info.feature_flags;
8823
8824         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8825                 return TEST_SKIPPED;
8826
8827         /* Set action type */
8828         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8829                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8830                 gbl_action_type;
8831
8832         if (security_proto_supported(ut_params->type,
8833                         RTE_SECURITY_PROTOCOL_PDCP) < 0)
8834                 return TEST_SKIPPED;
8835
8836         status = test_PDCP_PROTO_cplane_encap_all();
8837         status += test_PDCP_PROTO_cplane_decap_all();
8838         status += test_PDCP_PROTO_uplane_encap_all();
8839         status += test_PDCP_PROTO_uplane_decap_all();
8840         status += test_PDCP_PROTO_SGL_in_place_32B();
8841         status += test_PDCP_PROTO_SGL_oop_32B_128B();
8842         status += test_PDCP_PROTO_SGL_oop_32B_40B();
8843         status += test_PDCP_PROTO_SGL_oop_128B_32B();
8844         status += test_PDCP_SDAP_PROTO_encap_all();
8845         status += test_PDCP_SDAP_PROTO_decap_all();
8846
8847         if (status)
8848                 return TEST_FAILED;
8849         else
8850                 return TEST_SUCCESS;
8851 }
8852
8853 static int
8854 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
8855 {
8856         struct crypto_testsuite_params *ts_params = &testsuite_params;
8857         struct crypto_unittest_params *ut_params = &unittest_params;
8858         uint8_t *plaintext, *ciphertext;
8859         uint8_t *iv_ptr;
8860         int32_t cipher_len, crc_len;
8861         uint32_t crc_data_len;
8862         int ret = TEST_SUCCESS;
8863
8864         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8865                                         rte_cryptodev_get_sec_ctx(
8866                                                 ts_params->valid_devs[0]);
8867
8868         /* Verify the capabilities */
8869         struct rte_security_capability_idx sec_cap_idx;
8870         const struct rte_security_capability *sec_cap;
8871         const struct rte_cryptodev_capabilities *crypto_cap;
8872         const struct rte_cryptodev_symmetric_capability *sym_cap;
8873         int j = 0;
8874
8875         sec_cap_idx.action = ut_params->type;
8876         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8877         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
8878
8879         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8880         if (sec_cap == NULL)
8881                 return TEST_SKIPPED;
8882
8883         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8884                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8885                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8886                                 crypto_cap->sym.xform_type ==
8887                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
8888                                 crypto_cap->sym.cipher.algo ==
8889                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8890                         sym_cap = &crypto_cap->sym;
8891                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8892                                                 d_td->key.len,
8893                                                 d_td->iv.len) == 0)
8894                                 break;
8895                 }
8896         }
8897
8898         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8899                 return TEST_SKIPPED;
8900
8901         /* Setup source mbuf payload */
8902         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8903         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8904                         rte_pktmbuf_tailroom(ut_params->ibuf));
8905
8906         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8907                         d_td->ciphertext.len);
8908
8909         memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
8910
8911         /* Setup cipher session parameters */
8912         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8913         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8914         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
8915         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8916         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8917         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8918         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8919         ut_params->cipher_xform.next = NULL;
8920
8921         /* Setup DOCSIS session parameters */
8922         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
8923
8924         struct rte_security_session_conf sess_conf = {
8925                 .action_type = ut_params->type,
8926                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8927                 .docsis = ut_params->docsis_xform,
8928                 .crypto_xform = &ut_params->cipher_xform,
8929         };
8930
8931         /* Create security session */
8932         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
8933                                         ts_params->session_mpool,
8934                                         ts_params->session_priv_mpool);
8935
8936         if (!ut_params->sec_session) {
8937                 printf("TestCase %s(%d) line %d: %s\n",
8938                         __func__, i, __LINE__, "failed to allocate session");
8939                 ret = TEST_FAILED;
8940                 goto on_err;
8941         }
8942
8943         /* Generate crypto op data structure */
8944         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8945                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8946         if (!ut_params->op) {
8947                 printf("TestCase %s(%d) line %d: %s\n",
8948                         __func__, i, __LINE__,
8949                         "failed to allocate symmetric crypto operation");
8950                 ret = TEST_FAILED;
8951                 goto on_err;
8952         }
8953
8954         /* Setup CRC operation parameters */
8955         crc_len = d_td->ciphertext.no_crc == false ?
8956                         (d_td->ciphertext.len -
8957                                 d_td->ciphertext.crc_offset -
8958                                 RTE_ETHER_CRC_LEN) :
8959                         0;
8960         crc_len = crc_len > 0 ? crc_len : 0;
8961         crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
8962         ut_params->op->sym->auth.data.length = crc_len;
8963         ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
8964
8965         /* Setup cipher operation parameters */
8966         cipher_len = d_td->ciphertext.no_cipher == false ?
8967                         (d_td->ciphertext.len -
8968                                 d_td->ciphertext.cipher_offset) :
8969                         0;
8970         cipher_len = cipher_len > 0 ? cipher_len : 0;
8971         ut_params->op->sym->cipher.data.length = cipher_len;
8972         ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
8973
8974         /* Setup cipher IV */
8975         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
8976         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
8977
8978         /* Attach session to operation */
8979         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8980
8981         /* Set crypto operation mbufs */
8982         ut_params->op->sym->m_src = ut_params->ibuf;
8983         ut_params->op->sym->m_dst = NULL;
8984
8985         /* Process crypto operation */
8986         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
8987                         NULL) {
8988                 printf("TestCase %s(%d) line %d: %s\n",
8989                         __func__, i, __LINE__,
8990                         "failed to process security crypto op");
8991                 ret = TEST_FAILED;
8992                 goto on_err;
8993         }
8994
8995         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8996                 printf("TestCase %s(%d) line %d: %s\n",
8997                         __func__, i, __LINE__, "crypto op processing failed");
8998                 ret = TEST_FAILED;
8999                 goto on_err;
9000         }
9001
9002         /* Validate plaintext */
9003         plaintext = ciphertext;
9004
9005         if (memcmp(plaintext, d_td->plaintext.data,
9006                         d_td->plaintext.len - crc_data_len)) {
9007                 printf("TestCase %s(%d) line %d: %s\n",
9008                         __func__, i, __LINE__, "plaintext not as expected\n");
9009                 rte_hexdump(stdout, "expected", d_td->plaintext.data,
9010                                 d_td->plaintext.len);
9011                 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9012                 ret = TEST_FAILED;
9013                 goto on_err;
9014         }
9015
9016 on_err:
9017         rte_crypto_op_free(ut_params->op);
9018         ut_params->op = NULL;
9019
9020         if (ut_params->sec_session)
9021                 rte_security_session_destroy(ctx, ut_params->sec_session);
9022         ut_params->sec_session = NULL;
9023
9024         rte_pktmbuf_free(ut_params->ibuf);
9025         ut_params->ibuf = NULL;
9026
9027         return ret;
9028 }
9029
9030 static int
9031 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9032 {
9033         struct crypto_testsuite_params *ts_params = &testsuite_params;
9034         struct crypto_unittest_params *ut_params = &unittest_params;
9035         uint8_t *plaintext, *ciphertext;
9036         uint8_t *iv_ptr;
9037         int32_t cipher_len, crc_len;
9038         int ret = TEST_SUCCESS;
9039
9040         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9041                                         rte_cryptodev_get_sec_ctx(
9042                                                 ts_params->valid_devs[0]);
9043
9044         /* Verify the capabilities */
9045         struct rte_security_capability_idx sec_cap_idx;
9046         const struct rte_security_capability *sec_cap;
9047         const struct rte_cryptodev_capabilities *crypto_cap;
9048         const struct rte_cryptodev_symmetric_capability *sym_cap;
9049         int j = 0;
9050
9051         sec_cap_idx.action = ut_params->type;
9052         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9053         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9054
9055         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9056         if (sec_cap == NULL)
9057                 return TEST_SKIPPED;
9058
9059         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9060                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9061                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9062                                 crypto_cap->sym.xform_type ==
9063                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9064                                 crypto_cap->sym.cipher.algo ==
9065                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9066                         sym_cap = &crypto_cap->sym;
9067                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9068                                                 d_td->key.len,
9069                                                 d_td->iv.len) == 0)
9070                                 break;
9071                 }
9072         }
9073
9074         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9075                 return TEST_SKIPPED;
9076
9077         /* Setup source mbuf payload */
9078         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9079         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9080                         rte_pktmbuf_tailroom(ut_params->ibuf));
9081
9082         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9083                         d_td->plaintext.len);
9084
9085         memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9086
9087         /* Setup cipher session parameters */
9088         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9089         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9090         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9091         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9092         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9093         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9094         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9095         ut_params->cipher_xform.next = NULL;
9096
9097         /* Setup DOCSIS session parameters */
9098         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9099
9100         struct rte_security_session_conf sess_conf = {
9101                 .action_type = ut_params->type,
9102                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9103                 .docsis = ut_params->docsis_xform,
9104                 .crypto_xform = &ut_params->cipher_xform,
9105         };
9106
9107         /* Create security session */
9108         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9109                                         ts_params->session_mpool,
9110                                         ts_params->session_priv_mpool);
9111
9112         if (!ut_params->sec_session) {
9113                 printf("TestCase %s(%d) line %d: %s\n",
9114                         __func__, i, __LINE__, "failed to allocate session");
9115                 ret = TEST_FAILED;
9116                 goto on_err;
9117         }
9118
9119         /* Generate crypto op data structure */
9120         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9121                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9122         if (!ut_params->op) {
9123                 printf("TestCase %s(%d) line %d: %s\n",
9124                         __func__, i, __LINE__,
9125                         "failed to allocate security crypto operation");
9126                 ret = TEST_FAILED;
9127                 goto on_err;
9128         }
9129
9130         /* Setup CRC operation parameters */
9131         crc_len = d_td->plaintext.no_crc == false ?
9132                         (d_td->plaintext.len -
9133                                 d_td->plaintext.crc_offset -
9134                                 RTE_ETHER_CRC_LEN) :
9135                         0;
9136         crc_len = crc_len > 0 ? crc_len : 0;
9137         ut_params->op->sym->auth.data.length = crc_len;
9138         ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9139
9140         /* Setup cipher operation parameters */
9141         cipher_len = d_td->plaintext.no_cipher == false ?
9142                         (d_td->plaintext.len -
9143                                 d_td->plaintext.cipher_offset) :
9144                         0;
9145         cipher_len = cipher_len > 0 ? cipher_len : 0;
9146         ut_params->op->sym->cipher.data.length = cipher_len;
9147         ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9148
9149         /* Setup cipher IV */
9150         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9151         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9152
9153         /* Attach session to operation */
9154         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9155
9156         /* Set crypto operation mbufs */
9157         ut_params->op->sym->m_src = ut_params->ibuf;
9158         ut_params->op->sym->m_dst = NULL;
9159
9160         /* Process crypto operation */
9161         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9162                         NULL) {
9163                 printf("TestCase %s(%d) line %d: %s\n",
9164                         __func__, i, __LINE__,
9165                         "failed to process security crypto op");
9166                 ret = TEST_FAILED;
9167                 goto on_err;
9168         }
9169
9170         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9171                 printf("TestCase %s(%d) line %d: %s\n",
9172                         __func__, i, __LINE__, "crypto op processing failed");
9173                 ret = TEST_FAILED;
9174                 goto on_err;
9175         }
9176
9177         /* Validate ciphertext */
9178         ciphertext = plaintext;
9179
9180         if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9181                 printf("TestCase %s(%d) line %d: %s\n",
9182                         __func__, i, __LINE__, "ciphertext not as expected\n");
9183                 rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9184                                 d_td->ciphertext.len);
9185                 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9186                 ret = TEST_FAILED;
9187                 goto on_err;
9188         }
9189
9190 on_err:
9191         rte_crypto_op_free(ut_params->op);
9192         ut_params->op = NULL;
9193
9194         if (ut_params->sec_session)
9195                 rte_security_session_destroy(ctx, ut_params->sec_session);
9196         ut_params->sec_session = NULL;
9197
9198         rte_pktmbuf_free(ut_params->ibuf);
9199         ut_params->ibuf = NULL;
9200
9201         return ret;
9202 }
9203
9204 #define TEST_DOCSIS_COUNT(func) do {                    \
9205         int ret = func;                                 \
9206         if (ret == TEST_SUCCESS)  {                     \
9207                 printf("\t%2d)", n++);                  \
9208                 printf("+++++ PASSED:" #func"\n");      \
9209                 p++;                                    \
9210         } else if (ret == TEST_SKIPPED) {               \
9211                 printf("\t%2d)", n++);                  \
9212                 printf("~~~~~ SKIPPED:" #func"\n");     \
9213                 s++;                                    \
9214         } else {                                        \
9215                 printf("\t%2d)", n++);                  \
9216                 printf("----- FAILED:" #func"\n");      \
9217                 f++;                                    \
9218         }                                               \
9219 } while (0)
9220
9221 static int
9222 test_DOCSIS_PROTO_uplink_all(void)
9223 {
9224         int p = 0, s = 0, f = 0, n = 0;
9225
9226         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9227         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9228         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9229         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9230         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9231         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9232         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9233         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9234         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9235         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9236         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9237         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9238         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9239         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9240         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9241         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9242         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9243         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9244         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9245         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9246         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9247         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9248         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9249         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9250         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9251         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9252
9253         if (f)
9254                 printf("## %s: %d passed out of %d (%d skipped)\n",
9255                         __func__, p, n, s);
9256
9257         return f;
9258 };
9259
9260 static int
9261 test_DOCSIS_PROTO_downlink_all(void)
9262 {
9263         int p = 0, s = 0, f = 0, n = 0;
9264
9265         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9266         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9267         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9268         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9269         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9270         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9271         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9272         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9273         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9274         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9275         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9276         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9277         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9278         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9279         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9280         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9281         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9282         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9283         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9284         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9285         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9286         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9287         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9288         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9289         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9290         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9291
9292         if (f)
9293                 printf("## %s: %d passed out of %d (%d skipped)\n",
9294                         __func__, p, n, s);
9295
9296         return f;
9297 };
9298
9299 static int
9300 test_DOCSIS_PROTO_all(void)
9301 {
9302         struct crypto_testsuite_params *ts_params = &testsuite_params;
9303         struct crypto_unittest_params *ut_params = &unittest_params;
9304         struct rte_cryptodev_info dev_info;
9305         int status;
9306
9307         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9308         uint64_t feat_flags = dev_info.feature_flags;
9309
9310         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9311                 return TEST_SKIPPED;
9312
9313         /* Set action type */
9314         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9315                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9316                 gbl_action_type;
9317
9318         if (security_proto_supported(ut_params->type,
9319                         RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9320                 return TEST_SKIPPED;
9321
9322         status = test_DOCSIS_PROTO_uplink_all();
9323         status += test_DOCSIS_PROTO_downlink_all();
9324
9325         if (status)
9326                 return TEST_FAILED;
9327         else
9328                 return TEST_SUCCESS;
9329 }
9330 #endif
9331
9332 static int
9333 test_AES_GCM_authenticated_encryption_test_case_1(void)
9334 {
9335         return test_authenticated_encryption(&gcm_test_case_1);
9336 }
9337
9338 static int
9339 test_AES_GCM_authenticated_encryption_test_case_2(void)
9340 {
9341         return test_authenticated_encryption(&gcm_test_case_2);
9342 }
9343
9344 static int
9345 test_AES_GCM_authenticated_encryption_test_case_3(void)
9346 {
9347         return test_authenticated_encryption(&gcm_test_case_3);
9348 }
9349
9350 static int
9351 test_AES_GCM_authenticated_encryption_test_case_4(void)
9352 {
9353         return test_authenticated_encryption(&gcm_test_case_4);
9354 }
9355
9356 static int
9357 test_AES_GCM_authenticated_encryption_test_case_5(void)
9358 {
9359         return test_authenticated_encryption(&gcm_test_case_5);
9360 }
9361
9362 static int
9363 test_AES_GCM_authenticated_encryption_test_case_6(void)
9364 {
9365         return test_authenticated_encryption(&gcm_test_case_6);
9366 }
9367
9368 static int
9369 test_AES_GCM_authenticated_encryption_test_case_7(void)
9370 {
9371         return test_authenticated_encryption(&gcm_test_case_7);
9372 }
9373
9374 static int
9375 test_AES_GCM_authenticated_encryption_test_case_8(void)
9376 {
9377         return test_authenticated_encryption(&gcm_test_case_8);
9378 }
9379
9380 static int
9381 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9382 {
9383         return test_authenticated_encryption(&gcm_J0_test_case_1);
9384 }
9385
9386 static int
9387 test_AES_GCM_auth_encryption_test_case_192_1(void)
9388 {
9389         return test_authenticated_encryption(&gcm_test_case_192_1);
9390 }
9391
9392 static int
9393 test_AES_GCM_auth_encryption_test_case_192_2(void)
9394 {
9395         return test_authenticated_encryption(&gcm_test_case_192_2);
9396 }
9397
9398 static int
9399 test_AES_GCM_auth_encryption_test_case_192_3(void)
9400 {
9401         return test_authenticated_encryption(&gcm_test_case_192_3);
9402 }
9403
9404 static int
9405 test_AES_GCM_auth_encryption_test_case_192_4(void)
9406 {
9407         return test_authenticated_encryption(&gcm_test_case_192_4);
9408 }
9409
9410 static int
9411 test_AES_GCM_auth_encryption_test_case_192_5(void)
9412 {
9413         return test_authenticated_encryption(&gcm_test_case_192_5);
9414 }
9415
9416 static int
9417 test_AES_GCM_auth_encryption_test_case_192_6(void)
9418 {
9419         return test_authenticated_encryption(&gcm_test_case_192_6);
9420 }
9421
9422 static int
9423 test_AES_GCM_auth_encryption_test_case_192_7(void)
9424 {
9425         return test_authenticated_encryption(&gcm_test_case_192_7);
9426 }
9427
9428 static int
9429 test_AES_GCM_auth_encryption_test_case_256_1(void)
9430 {
9431         return test_authenticated_encryption(&gcm_test_case_256_1);
9432 }
9433
9434 static int
9435 test_AES_GCM_auth_encryption_test_case_256_2(void)
9436 {
9437         return test_authenticated_encryption(&gcm_test_case_256_2);
9438 }
9439
9440 static int
9441 test_AES_GCM_auth_encryption_test_case_256_3(void)
9442 {
9443         return test_authenticated_encryption(&gcm_test_case_256_3);
9444 }
9445
9446 static int
9447 test_AES_GCM_auth_encryption_test_case_256_4(void)
9448 {
9449         return test_authenticated_encryption(&gcm_test_case_256_4);
9450 }
9451
9452 static int
9453 test_AES_GCM_auth_encryption_test_case_256_5(void)
9454 {
9455         return test_authenticated_encryption(&gcm_test_case_256_5);
9456 }
9457
9458 static int
9459 test_AES_GCM_auth_encryption_test_case_256_6(void)
9460 {
9461         return test_authenticated_encryption(&gcm_test_case_256_6);
9462 }
9463
9464 static int
9465 test_AES_GCM_auth_encryption_test_case_256_7(void)
9466 {
9467         return test_authenticated_encryption(&gcm_test_case_256_7);
9468 }
9469
9470 static int
9471 test_AES_GCM_auth_encryption_test_case_aad_1(void)
9472 {
9473         return test_authenticated_encryption(&gcm_test_case_aad_1);
9474 }
9475
9476 static int
9477 test_AES_GCM_auth_encryption_test_case_aad_2(void)
9478 {
9479         return test_authenticated_encryption(&gcm_test_case_aad_2);
9480 }
9481
9482 static int
9483 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
9484 {
9485         struct aead_test_data tdata;
9486         int res;
9487
9488         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9489         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9490         tdata.iv.data[0] += 1;
9491         res = test_authenticated_encryption(&tdata);
9492         if (res == TEST_SKIPPED)
9493                 return res;
9494         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9495         return TEST_SUCCESS;
9496 }
9497
9498 static int
9499 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
9500 {
9501         struct aead_test_data tdata;
9502         int res;
9503
9504         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9505         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9506         tdata.plaintext.data[0] += 1;
9507         res = test_authenticated_encryption(&tdata);
9508         if (res == TEST_SKIPPED)
9509                 return res;
9510         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9511         return TEST_SUCCESS;
9512 }
9513
9514 static int
9515 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
9516 {
9517         struct aead_test_data tdata;
9518         int res;
9519
9520         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9521         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9522         tdata.ciphertext.data[0] += 1;
9523         res = test_authenticated_encryption(&tdata);
9524         if (res == TEST_SKIPPED)
9525                 return res;
9526         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9527         return TEST_SUCCESS;
9528 }
9529
9530 static int
9531 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
9532 {
9533         struct aead_test_data tdata;
9534         int res;
9535
9536         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9537         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9538         tdata.aad.len += 1;
9539         res = test_authenticated_encryption(&tdata);
9540         if (res == TEST_SKIPPED)
9541                 return res;
9542         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9543         return TEST_SUCCESS;
9544 }
9545
9546 static int
9547 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
9548 {
9549         struct aead_test_data tdata;
9550         uint8_t aad[gcm_test_case_7.aad.len];
9551         int res;
9552
9553         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9554         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9555         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9556         aad[0] += 1;
9557         tdata.aad.data = aad;
9558         res = test_authenticated_encryption(&tdata);
9559         if (res == TEST_SKIPPED)
9560                 return res;
9561         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9562         return TEST_SUCCESS;
9563 }
9564
9565 static int
9566 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
9567 {
9568         struct aead_test_data tdata;
9569         int res;
9570
9571         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9572         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9573         tdata.auth_tag.data[0] += 1;
9574         res = test_authenticated_encryption(&tdata);
9575         if (res == TEST_SKIPPED)
9576                 return res;
9577         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9578         return TEST_SUCCESS;
9579 }
9580
9581 static int
9582 test_authenticated_decryption(const struct aead_test_data *tdata)
9583 {
9584         struct crypto_testsuite_params *ts_params = &testsuite_params;
9585         struct crypto_unittest_params *ut_params = &unittest_params;
9586
9587         int retval;
9588         uint8_t *plaintext;
9589         uint32_t i;
9590         struct rte_cryptodev_info dev_info;
9591
9592         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9593         uint64_t feat_flags = dev_info.feature_flags;
9594
9595         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9596                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9597                 printf("Device doesn't support RAW data-path APIs.\n");
9598                 return TEST_SKIPPED;
9599         }
9600
9601         /* Verify the capabilities */
9602         struct rte_cryptodev_sym_capability_idx cap_idx;
9603         const struct rte_cryptodev_symmetric_capability *capability;
9604         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9605         cap_idx.algo.aead = tdata->algo;
9606         capability = rte_cryptodev_sym_capability_get(
9607                         ts_params->valid_devs[0], &cap_idx);
9608         if (capability == NULL)
9609                 return TEST_SKIPPED;
9610         if (rte_cryptodev_sym_capability_check_aead(
9611                         capability, tdata->key.len, tdata->auth_tag.len,
9612                         tdata->aad.len, tdata->iv.len))
9613                 return TEST_SKIPPED;
9614
9615         /* Create AEAD session */
9616         retval = create_aead_session(ts_params->valid_devs[0],
9617                         tdata->algo,
9618                         RTE_CRYPTO_AEAD_OP_DECRYPT,
9619                         tdata->key.data, tdata->key.len,
9620                         tdata->aad.len, tdata->auth_tag.len,
9621                         tdata->iv.len);
9622         if (retval < 0)
9623                 return retval;
9624
9625         /* alloc mbuf and set payload */
9626         if (tdata->aad.len > MBUF_SIZE) {
9627                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9628                 /* Populate full size of add data */
9629                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
9630                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
9631         } else
9632                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9633
9634         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9635                         rte_pktmbuf_tailroom(ut_params->ibuf));
9636
9637         /* Create AEAD operation */
9638         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9639         if (retval < 0)
9640                 return retval;
9641
9642         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9643
9644         ut_params->op->sym->m_src = ut_params->ibuf;
9645
9646         /* Process crypto operation */
9647         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9648                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
9649         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9650                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9651                                 ut_params->op, 0, 0, 0, 0);
9652         else
9653                 TEST_ASSERT_NOT_NULL(
9654                         process_crypto_request(ts_params->valid_devs[0],
9655                         ut_params->op), "failed to process sym crypto op");
9656
9657         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9658                         "crypto op processing failed");
9659
9660         if (ut_params->op->sym->m_dst)
9661                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9662                                 uint8_t *);
9663         else
9664                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
9665                                 uint8_t *,
9666                                 ut_params->op->sym->cipher.data.offset);
9667
9668         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9669
9670         /* Validate obuf */
9671         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9672                         plaintext,
9673                         tdata->plaintext.data,
9674                         tdata->plaintext.len,
9675                         "Plaintext data not as expected");
9676
9677         TEST_ASSERT_EQUAL(ut_params->op->status,
9678                         RTE_CRYPTO_OP_STATUS_SUCCESS,
9679                         "Authentication failed");
9680
9681         return 0;
9682 }
9683
9684 static int
9685 test_AES_GCM_authenticated_decryption_test_case_1(void)
9686 {
9687         return test_authenticated_decryption(&gcm_test_case_1);
9688 }
9689
9690 static int
9691 test_AES_GCM_authenticated_decryption_test_case_2(void)
9692 {
9693         return test_authenticated_decryption(&gcm_test_case_2);
9694 }
9695
9696 static int
9697 test_AES_GCM_authenticated_decryption_test_case_3(void)
9698 {
9699         return test_authenticated_decryption(&gcm_test_case_3);
9700 }
9701
9702 static int
9703 test_AES_GCM_authenticated_decryption_test_case_4(void)
9704 {
9705         return test_authenticated_decryption(&gcm_test_case_4);
9706 }
9707
9708 static int
9709 test_AES_GCM_authenticated_decryption_test_case_5(void)
9710 {
9711         return test_authenticated_decryption(&gcm_test_case_5);
9712 }
9713
9714 static int
9715 test_AES_GCM_authenticated_decryption_test_case_6(void)
9716 {
9717         return test_authenticated_decryption(&gcm_test_case_6);
9718 }
9719
9720 static int
9721 test_AES_GCM_authenticated_decryption_test_case_7(void)
9722 {
9723         return test_authenticated_decryption(&gcm_test_case_7);
9724 }
9725
9726 static int
9727 test_AES_GCM_authenticated_decryption_test_case_8(void)
9728 {
9729         return test_authenticated_decryption(&gcm_test_case_8);
9730 }
9731
9732 static int
9733 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
9734 {
9735         return test_authenticated_decryption(&gcm_J0_test_case_1);
9736 }
9737
9738 static int
9739 test_AES_GCM_auth_decryption_test_case_192_1(void)
9740 {
9741         return test_authenticated_decryption(&gcm_test_case_192_1);
9742 }
9743
9744 static int
9745 test_AES_GCM_auth_decryption_test_case_192_2(void)
9746 {
9747         return test_authenticated_decryption(&gcm_test_case_192_2);
9748 }
9749
9750 static int
9751 test_AES_GCM_auth_decryption_test_case_192_3(void)
9752 {
9753         return test_authenticated_decryption(&gcm_test_case_192_3);
9754 }
9755
9756 static int
9757 test_AES_GCM_auth_decryption_test_case_192_4(void)
9758 {
9759         return test_authenticated_decryption(&gcm_test_case_192_4);
9760 }
9761
9762 static int
9763 test_AES_GCM_auth_decryption_test_case_192_5(void)
9764 {
9765         return test_authenticated_decryption(&gcm_test_case_192_5);
9766 }
9767
9768 static int
9769 test_AES_GCM_auth_decryption_test_case_192_6(void)
9770 {
9771         return test_authenticated_decryption(&gcm_test_case_192_6);
9772 }
9773
9774 static int
9775 test_AES_GCM_auth_decryption_test_case_192_7(void)
9776 {
9777         return test_authenticated_decryption(&gcm_test_case_192_7);
9778 }
9779
9780 static int
9781 test_AES_GCM_auth_decryption_test_case_256_1(void)
9782 {
9783         return test_authenticated_decryption(&gcm_test_case_256_1);
9784 }
9785
9786 static int
9787 test_AES_GCM_auth_decryption_test_case_256_2(void)
9788 {
9789         return test_authenticated_decryption(&gcm_test_case_256_2);
9790 }
9791
9792 static int
9793 test_AES_GCM_auth_decryption_test_case_256_3(void)
9794 {
9795         return test_authenticated_decryption(&gcm_test_case_256_3);
9796 }
9797
9798 static int
9799 test_AES_GCM_auth_decryption_test_case_256_4(void)
9800 {
9801         return test_authenticated_decryption(&gcm_test_case_256_4);
9802 }
9803
9804 static int
9805 test_AES_GCM_auth_decryption_test_case_256_5(void)
9806 {
9807         return test_authenticated_decryption(&gcm_test_case_256_5);
9808 }
9809
9810 static int
9811 test_AES_GCM_auth_decryption_test_case_256_6(void)
9812 {
9813         return test_authenticated_decryption(&gcm_test_case_256_6);
9814 }
9815
9816 static int
9817 test_AES_GCM_auth_decryption_test_case_256_7(void)
9818 {
9819         return test_authenticated_decryption(&gcm_test_case_256_7);
9820 }
9821
9822 static int
9823 test_AES_GCM_auth_decryption_test_case_aad_1(void)
9824 {
9825         return test_authenticated_decryption(&gcm_test_case_aad_1);
9826 }
9827
9828 static int
9829 test_AES_GCM_auth_decryption_test_case_aad_2(void)
9830 {
9831         return test_authenticated_decryption(&gcm_test_case_aad_2);
9832 }
9833
9834 static int
9835 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
9836 {
9837         struct aead_test_data tdata;
9838         int res;
9839
9840         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9841         tdata.iv.data[0] += 1;
9842         res = test_authenticated_decryption(&tdata);
9843         if (res == TEST_SKIPPED)
9844                 return res;
9845         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9846         return TEST_SUCCESS;
9847 }
9848
9849 static int
9850 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
9851 {
9852         struct aead_test_data tdata;
9853         int res;
9854
9855         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9856         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9857         tdata.plaintext.data[0] += 1;
9858         res = test_authenticated_decryption(&tdata);
9859         if (res == TEST_SKIPPED)
9860                 return res;
9861         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9862         return TEST_SUCCESS;
9863 }
9864
9865 static int
9866 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
9867 {
9868         struct aead_test_data tdata;
9869         int res;
9870
9871         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9872         tdata.ciphertext.data[0] += 1;
9873         res = test_authenticated_decryption(&tdata);
9874         if (res == TEST_SKIPPED)
9875                 return res;
9876         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9877         return TEST_SUCCESS;
9878 }
9879
9880 static int
9881 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
9882 {
9883         struct aead_test_data tdata;
9884         int res;
9885
9886         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9887         tdata.aad.len += 1;
9888         res = test_authenticated_decryption(&tdata);
9889         if (res == TEST_SKIPPED)
9890                 return res;
9891         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9892         return TEST_SUCCESS;
9893 }
9894
9895 static int
9896 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
9897 {
9898         struct aead_test_data tdata;
9899         uint8_t aad[gcm_test_case_7.aad.len];
9900         int res;
9901
9902         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9903         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9904         aad[0] += 1;
9905         tdata.aad.data = aad;
9906         res = test_authenticated_decryption(&tdata);
9907         if (res == TEST_SKIPPED)
9908                 return res;
9909         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9910         return TEST_SUCCESS;
9911 }
9912
9913 static int
9914 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
9915 {
9916         struct aead_test_data tdata;
9917         int res;
9918
9919         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9920         tdata.auth_tag.data[0] += 1;
9921         res = test_authenticated_decryption(&tdata);
9922         if (res == TEST_SKIPPED)
9923                 return res;
9924         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
9925         return TEST_SUCCESS;
9926 }
9927
9928 static int
9929 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
9930 {
9931         struct crypto_testsuite_params *ts_params = &testsuite_params;
9932         struct crypto_unittest_params *ut_params = &unittest_params;
9933
9934         int retval;
9935         uint8_t *ciphertext, *auth_tag;
9936         uint16_t plaintext_pad_len;
9937
9938         /* Verify the capabilities */
9939         struct rte_cryptodev_sym_capability_idx cap_idx;
9940         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9941         cap_idx.algo.aead = tdata->algo;
9942         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9943                         &cap_idx) == NULL)
9944                 return TEST_SKIPPED;
9945
9946         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9947                 return TEST_SKIPPED;
9948
9949         /* not supported with CPU crypto */
9950         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9951                 return TEST_SKIPPED;
9952
9953         /* Create AEAD session */
9954         retval = create_aead_session(ts_params->valid_devs[0],
9955                         tdata->algo,
9956                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
9957                         tdata->key.data, tdata->key.len,
9958                         tdata->aad.len, tdata->auth_tag.len,
9959                         tdata->iv.len);
9960         if (retval < 0)
9961                 return retval;
9962
9963         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9964         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9965
9966         /* clear mbuf payload */
9967         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9968                         rte_pktmbuf_tailroom(ut_params->ibuf));
9969         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
9970                         rte_pktmbuf_tailroom(ut_params->obuf));
9971
9972         /* Create AEAD operation */
9973         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
9974         if (retval < 0)
9975                 return retval;
9976
9977         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9978
9979         ut_params->op->sym->m_src = ut_params->ibuf;
9980         ut_params->op->sym->m_dst = ut_params->obuf;
9981
9982         /* Process crypto operation */
9983         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9984                         ut_params->op), "failed to process sym crypto op");
9985
9986         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9987                         "crypto op processing failed");
9988
9989         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9990
9991         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
9992                         ut_params->op->sym->cipher.data.offset);
9993         auth_tag = ciphertext + plaintext_pad_len;
9994
9995         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
9996         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
9997
9998         /* Validate obuf */
9999         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10000                         ciphertext,
10001                         tdata->ciphertext.data,
10002                         tdata->ciphertext.len,
10003                         "Ciphertext data not as expected");
10004
10005         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10006                         auth_tag,
10007                         tdata->auth_tag.data,
10008                         tdata->auth_tag.len,
10009                         "Generated auth tag not as expected");
10010
10011         return 0;
10012
10013 }
10014
10015 static int
10016 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10017 {
10018         return test_authenticated_encryption_oop(&gcm_test_case_5);
10019 }
10020
10021 static int
10022 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10023 {
10024         struct crypto_testsuite_params *ts_params = &testsuite_params;
10025         struct crypto_unittest_params *ut_params = &unittest_params;
10026
10027         int retval;
10028         uint8_t *plaintext;
10029
10030         /* Verify the capabilities */
10031         struct rte_cryptodev_sym_capability_idx cap_idx;
10032         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10033         cap_idx.algo.aead = tdata->algo;
10034         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10035                         &cap_idx) == NULL)
10036                 return TEST_SKIPPED;
10037
10038         /* not supported with CPU crypto and raw data-path APIs*/
10039         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10040                         global_api_test_type == CRYPTODEV_RAW_API_TEST)
10041                 return TEST_SKIPPED;
10042
10043         /* Create AEAD session */
10044         retval = create_aead_session(ts_params->valid_devs[0],
10045                         tdata->algo,
10046                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10047                         tdata->key.data, tdata->key.len,
10048                         tdata->aad.len, tdata->auth_tag.len,
10049                         tdata->iv.len);
10050         if (retval < 0)
10051                 return retval;
10052
10053         /* alloc mbuf and set payload */
10054         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10055         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10056
10057         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10058                         rte_pktmbuf_tailroom(ut_params->ibuf));
10059         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10060                         rte_pktmbuf_tailroom(ut_params->obuf));
10061
10062         /* Create AEAD operation */
10063         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10064         if (retval < 0)
10065                 return retval;
10066
10067         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10068
10069         ut_params->op->sym->m_src = ut_params->ibuf;
10070         ut_params->op->sym->m_dst = ut_params->obuf;
10071
10072         /* Process crypto operation */
10073         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10074                         ut_params->op), "failed to process sym crypto op");
10075
10076         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10077                         "crypto op processing failed");
10078
10079         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10080                         ut_params->op->sym->cipher.data.offset);
10081
10082         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10083
10084         /* Validate obuf */
10085         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10086                         plaintext,
10087                         tdata->plaintext.data,
10088                         tdata->plaintext.len,
10089                         "Plaintext data not as expected");
10090
10091         TEST_ASSERT_EQUAL(ut_params->op->status,
10092                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10093                         "Authentication failed");
10094         return 0;
10095 }
10096
10097 static int
10098 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10099 {
10100         return test_authenticated_decryption_oop(&gcm_test_case_5);
10101 }
10102
10103 static int
10104 test_authenticated_encryption_sessionless(
10105                 const struct aead_test_data *tdata)
10106 {
10107         struct crypto_testsuite_params *ts_params = &testsuite_params;
10108         struct crypto_unittest_params *ut_params = &unittest_params;
10109
10110         int retval;
10111         uint8_t *ciphertext, *auth_tag;
10112         uint16_t plaintext_pad_len;
10113         uint8_t key[tdata->key.len + 1];
10114         struct rte_cryptodev_info dev_info;
10115
10116         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10117         uint64_t feat_flags = dev_info.feature_flags;
10118
10119         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10120                 printf("Device doesn't support Sessionless ops.\n");
10121                 return TEST_SKIPPED;
10122         }
10123
10124         /* not supported with CPU crypto */
10125         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10126                 return TEST_SKIPPED;
10127
10128         /* Verify the capabilities */
10129         struct rte_cryptodev_sym_capability_idx cap_idx;
10130         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10131         cap_idx.algo.aead = tdata->algo;
10132         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10133                         &cap_idx) == NULL)
10134                 return TEST_SKIPPED;
10135
10136         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10137
10138         /* clear mbuf payload */
10139         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10140                         rte_pktmbuf_tailroom(ut_params->ibuf));
10141
10142         /* Create AEAD operation */
10143         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10144         if (retval < 0)
10145                 return retval;
10146
10147         /* Create GCM xform */
10148         memcpy(key, tdata->key.data, tdata->key.len);
10149         retval = create_aead_xform(ut_params->op,
10150                         tdata->algo,
10151                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10152                         key, tdata->key.len,
10153                         tdata->aad.len, tdata->auth_tag.len,
10154                         tdata->iv.len);
10155         if (retval < 0)
10156                 return retval;
10157
10158         ut_params->op->sym->m_src = ut_params->ibuf;
10159
10160         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10161                         RTE_CRYPTO_OP_SESSIONLESS,
10162                         "crypto op session type not sessionless");
10163
10164         /* Process crypto operation */
10165         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10166                         ut_params->op), "failed to process sym crypto op");
10167
10168         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10169
10170         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10171                         "crypto op status not success");
10172
10173         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10174
10175         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10176                         ut_params->op->sym->cipher.data.offset);
10177         auth_tag = ciphertext + plaintext_pad_len;
10178
10179         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10180         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10181
10182         /* Validate obuf */
10183         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10184                         ciphertext,
10185                         tdata->ciphertext.data,
10186                         tdata->ciphertext.len,
10187                         "Ciphertext data not as expected");
10188
10189         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10190                         auth_tag,
10191                         tdata->auth_tag.data,
10192                         tdata->auth_tag.len,
10193                         "Generated auth tag not as expected");
10194
10195         return 0;
10196
10197 }
10198
10199 static int
10200 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10201 {
10202         return test_authenticated_encryption_sessionless(
10203                         &gcm_test_case_5);
10204 }
10205
10206 static int
10207 test_authenticated_decryption_sessionless(
10208                 const struct aead_test_data *tdata)
10209 {
10210         struct crypto_testsuite_params *ts_params = &testsuite_params;
10211         struct crypto_unittest_params *ut_params = &unittest_params;
10212
10213         int retval;
10214         uint8_t *plaintext;
10215         uint8_t key[tdata->key.len + 1];
10216         struct rte_cryptodev_info dev_info;
10217
10218         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10219         uint64_t feat_flags = dev_info.feature_flags;
10220
10221         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10222                 printf("Device doesn't support Sessionless ops.\n");
10223                 return TEST_SKIPPED;
10224         }
10225
10226         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10227                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10228                 printf("Device doesn't support RAW data-path APIs.\n");
10229                 return TEST_SKIPPED;
10230         }
10231
10232         /* not supported with CPU crypto */
10233         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10234                 return TEST_SKIPPED;
10235
10236         /* Verify the capabilities */
10237         struct rte_cryptodev_sym_capability_idx cap_idx;
10238         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10239         cap_idx.algo.aead = tdata->algo;
10240         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10241                         &cap_idx) == NULL)
10242                 return TEST_SKIPPED;
10243
10244         /* alloc mbuf and set payload */
10245         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10246
10247         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10248                         rte_pktmbuf_tailroom(ut_params->ibuf));
10249
10250         /* Create AEAD operation */
10251         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10252         if (retval < 0)
10253                 return retval;
10254
10255         /* Create AEAD xform */
10256         memcpy(key, tdata->key.data, tdata->key.len);
10257         retval = create_aead_xform(ut_params->op,
10258                         tdata->algo,
10259                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10260                         key, tdata->key.len,
10261                         tdata->aad.len, tdata->auth_tag.len,
10262                         tdata->iv.len);
10263         if (retval < 0)
10264                 return retval;
10265
10266         ut_params->op->sym->m_src = ut_params->ibuf;
10267
10268         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10269                         RTE_CRYPTO_OP_SESSIONLESS,
10270                         "crypto op session type not sessionless");
10271
10272         /* Process crypto operation */
10273         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10274                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10275                                 ut_params->op, 0, 0, 0, 0);
10276         else
10277                 TEST_ASSERT_NOT_NULL(process_crypto_request(
10278                         ts_params->valid_devs[0], ut_params->op),
10279                                 "failed to process sym crypto op");
10280
10281         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10282
10283         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10284                         "crypto op status not success");
10285
10286         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10287                         ut_params->op->sym->cipher.data.offset);
10288
10289         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10290
10291         /* Validate obuf */
10292         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10293                         plaintext,
10294                         tdata->plaintext.data,
10295                         tdata->plaintext.len,
10296                         "Plaintext data not as expected");
10297
10298         TEST_ASSERT_EQUAL(ut_params->op->status,
10299                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10300                         "Authentication failed");
10301         return 0;
10302 }
10303
10304 static int
10305 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
10306 {
10307         return test_authenticated_decryption_sessionless(
10308                         &gcm_test_case_5);
10309 }
10310
10311 static int
10312 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
10313 {
10314         return test_authenticated_encryption(&ccm_test_case_128_1);
10315 }
10316
10317 static int
10318 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
10319 {
10320         return test_authenticated_encryption(&ccm_test_case_128_2);
10321 }
10322
10323 static int
10324 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
10325 {
10326         return test_authenticated_encryption(&ccm_test_case_128_3);
10327 }
10328
10329 static int
10330 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
10331 {
10332         return test_authenticated_decryption(&ccm_test_case_128_1);
10333 }
10334
10335 static int
10336 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
10337 {
10338         return test_authenticated_decryption(&ccm_test_case_128_2);
10339 }
10340
10341 static int
10342 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10343 {
10344         return test_authenticated_decryption(&ccm_test_case_128_3);
10345 }
10346
10347 static int
10348 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10349 {
10350         return test_authenticated_encryption(&ccm_test_case_192_1);
10351 }
10352
10353 static int
10354 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10355 {
10356         return test_authenticated_encryption(&ccm_test_case_192_2);
10357 }
10358
10359 static int
10360 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10361 {
10362         return test_authenticated_encryption(&ccm_test_case_192_3);
10363 }
10364
10365 static int
10366 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10367 {
10368         return test_authenticated_decryption(&ccm_test_case_192_1);
10369 }
10370
10371 static int
10372 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10373 {
10374         return test_authenticated_decryption(&ccm_test_case_192_2);
10375 }
10376
10377 static int
10378 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10379 {
10380         return test_authenticated_decryption(&ccm_test_case_192_3);
10381 }
10382
10383 static int
10384 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
10385 {
10386         return test_authenticated_encryption(&ccm_test_case_256_1);
10387 }
10388
10389 static int
10390 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
10391 {
10392         return test_authenticated_encryption(&ccm_test_case_256_2);
10393 }
10394
10395 static int
10396 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
10397 {
10398         return test_authenticated_encryption(&ccm_test_case_256_3);
10399 }
10400
10401 static int
10402 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
10403 {
10404         return test_authenticated_decryption(&ccm_test_case_256_1);
10405 }
10406
10407 static int
10408 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
10409 {
10410         return test_authenticated_decryption(&ccm_test_case_256_2);
10411 }
10412
10413 static int
10414 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
10415 {
10416         return test_authenticated_decryption(&ccm_test_case_256_3);
10417 }
10418
10419 static int
10420 test_stats(void)
10421 {
10422         struct crypto_testsuite_params *ts_params = &testsuite_params;
10423         struct rte_cryptodev_stats stats;
10424
10425         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10426                 return TEST_SKIPPED;
10427
10428         /* Verify the capabilities */
10429         struct rte_cryptodev_sym_capability_idx cap_idx;
10430         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10431         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
10432         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10433                         &cap_idx) == NULL)
10434                 return TEST_SKIPPED;
10435         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10436         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10437         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10438                         &cap_idx) == NULL)
10439                 return TEST_SKIPPED;
10440
10441         if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
10442                         == -ENOTSUP)
10443                 return TEST_SKIPPED;
10444
10445         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10446         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
10447                         &stats) == -ENODEV),
10448                 "rte_cryptodev_stats_get invalid dev failed");
10449         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
10450                 "rte_cryptodev_stats_get invalid Param failed");
10451
10452         /* Test expected values */
10453         test_AES_CBC_HMAC_SHA1_encrypt_digest();
10454         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10455                         &stats),
10456                 "rte_cryptodev_stats_get failed");
10457         TEST_ASSERT((stats.enqueued_count == 1),
10458                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10459         TEST_ASSERT((stats.dequeued_count == 1),
10460                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10461         TEST_ASSERT((stats.enqueue_err_count == 0),
10462                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10463         TEST_ASSERT((stats.dequeue_err_count == 0),
10464                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10465
10466         /* invalid device but should ignore and not reset device stats*/
10467         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
10468         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10469                         &stats),
10470                 "rte_cryptodev_stats_get failed");
10471         TEST_ASSERT((stats.enqueued_count == 1),
10472                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10473
10474         /* check that a valid reset clears stats */
10475         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10476         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10477                         &stats),
10478                                           "rte_cryptodev_stats_get failed");
10479         TEST_ASSERT((stats.enqueued_count == 0),
10480                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10481         TEST_ASSERT((stats.dequeued_count == 0),
10482                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10483
10484         return TEST_SUCCESS;
10485 }
10486
10487 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
10488                                    struct crypto_unittest_params *ut_params,
10489                                    enum rte_crypto_auth_operation op,
10490                                    const struct HMAC_MD5_vector *test_case)
10491 {
10492         uint8_t key[64];
10493
10494         memcpy(key, test_case->key.data, test_case->key.len);
10495
10496         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10497         ut_params->auth_xform.next = NULL;
10498         ut_params->auth_xform.auth.op = op;
10499
10500         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
10501
10502         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
10503         ut_params->auth_xform.auth.key.length = test_case->key.len;
10504         ut_params->auth_xform.auth.key.data = key;
10505
10506         ut_params->sess = rte_cryptodev_sym_session_create(
10507                         ts_params->session_mpool);
10508
10509         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10510                         ut_params->sess, &ut_params->auth_xform,
10511                         ts_params->session_priv_mpool);
10512
10513         if (ut_params->sess == NULL)
10514                 return TEST_FAILED;
10515
10516         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10517
10518         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10519                         rte_pktmbuf_tailroom(ut_params->ibuf));
10520
10521         return 0;
10522 }
10523
10524 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
10525                               const struct HMAC_MD5_vector *test_case,
10526                               uint8_t **plaintext)
10527 {
10528         uint16_t plaintext_pad_len;
10529
10530         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10531
10532         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10533                                 16);
10534
10535         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10536                         plaintext_pad_len);
10537         memcpy(*plaintext, test_case->plaintext.data,
10538                         test_case->plaintext.len);
10539
10540         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10541                         ut_params->ibuf, MD5_DIGEST_LEN);
10542         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10543                         "no room to append digest");
10544         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10545                         ut_params->ibuf, plaintext_pad_len);
10546
10547         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10548                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
10549                            test_case->auth_tag.len);
10550         }
10551
10552         sym_op->auth.data.offset = 0;
10553         sym_op->auth.data.length = test_case->plaintext.len;
10554
10555         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10556         ut_params->op->sym->m_src = ut_params->ibuf;
10557
10558         return 0;
10559 }
10560
10561 static int
10562 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
10563 {
10564         uint16_t plaintext_pad_len;
10565         uint8_t *plaintext, *auth_tag;
10566
10567         struct crypto_testsuite_params *ts_params = &testsuite_params;
10568         struct crypto_unittest_params *ut_params = &unittest_params;
10569         struct rte_cryptodev_info dev_info;
10570
10571         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10572         uint64_t feat_flags = dev_info.feature_flags;
10573
10574         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10575                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10576                 printf("Device doesn't support RAW data-path APIs.\n");
10577                 return TEST_SKIPPED;
10578         }
10579
10580         /* Verify the capabilities */
10581         struct rte_cryptodev_sym_capability_idx cap_idx;
10582         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10583         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10584         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10585                         &cap_idx) == NULL)
10586                 return TEST_SKIPPED;
10587
10588         if (MD5_HMAC_create_session(ts_params, ut_params,
10589                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
10590                 return TEST_FAILED;
10591
10592         /* Generate Crypto op data structure */
10593         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10594                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10595         TEST_ASSERT_NOT_NULL(ut_params->op,
10596                         "Failed to allocate symmetric crypto operation struct");
10597
10598         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10599                                 16);
10600
10601         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10602                 return TEST_FAILED;
10603
10604         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10605                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10606                         ut_params->op);
10607         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10608                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10609                                 ut_params->op, 0, 1, 0, 0);
10610         else
10611                 TEST_ASSERT_NOT_NULL(
10612                         process_crypto_request(ts_params->valid_devs[0],
10613                                 ut_params->op),
10614                                 "failed to process sym crypto op");
10615
10616         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10617                         "crypto op processing failed");
10618
10619         if (ut_params->op->sym->m_dst) {
10620                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10621                                 uint8_t *, plaintext_pad_len);
10622         } else {
10623                 auth_tag = plaintext + plaintext_pad_len;
10624         }
10625
10626         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10627                         auth_tag,
10628                         test_case->auth_tag.data,
10629                         test_case->auth_tag.len,
10630                         "HMAC_MD5 generated tag not as expected");
10631
10632         return TEST_SUCCESS;
10633 }
10634
10635 static int
10636 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
10637 {
10638         uint8_t *plaintext;
10639
10640         struct crypto_testsuite_params *ts_params = &testsuite_params;
10641         struct crypto_unittest_params *ut_params = &unittest_params;
10642         struct rte_cryptodev_info dev_info;
10643
10644         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10645         uint64_t feat_flags = dev_info.feature_flags;
10646
10647         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10648                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10649                 printf("Device doesn't support RAW data-path APIs.\n");
10650                 return TEST_SKIPPED;
10651         }
10652
10653         /* Verify the capabilities */
10654         struct rte_cryptodev_sym_capability_idx cap_idx;
10655         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10656         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10657         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10658                         &cap_idx) == NULL)
10659                 return TEST_SKIPPED;
10660
10661         if (MD5_HMAC_create_session(ts_params, ut_params,
10662                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
10663                 return TEST_FAILED;
10664         }
10665
10666         /* Generate Crypto op data structure */
10667         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10668                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10669         TEST_ASSERT_NOT_NULL(ut_params->op,
10670                         "Failed to allocate symmetric crypto operation struct");
10671
10672         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10673                 return TEST_FAILED;
10674
10675         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10676                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10677                         ut_params->op);
10678         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10679                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10680                                 ut_params->op, 0, 1, 0, 0);
10681         else
10682                 TEST_ASSERT_NOT_NULL(
10683                         process_crypto_request(ts_params->valid_devs[0],
10684                                 ut_params->op),
10685                                 "failed to process sym crypto op");
10686
10687         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10688                         "HMAC_MD5 crypto op processing failed");
10689
10690         return TEST_SUCCESS;
10691 }
10692
10693 static int
10694 test_MD5_HMAC_generate_case_1(void)
10695 {
10696         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
10697 }
10698
10699 static int
10700 test_MD5_HMAC_verify_case_1(void)
10701 {
10702         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
10703 }
10704
10705 static int
10706 test_MD5_HMAC_generate_case_2(void)
10707 {
10708         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
10709 }
10710
10711 static int
10712 test_MD5_HMAC_verify_case_2(void)
10713 {
10714         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
10715 }
10716
10717 static int
10718 test_multi_session(void)
10719 {
10720         struct crypto_testsuite_params *ts_params = &testsuite_params;
10721         struct crypto_unittest_params *ut_params = &unittest_params;
10722
10723         struct rte_cryptodev_info dev_info;
10724         struct rte_cryptodev_sym_session **sessions;
10725
10726         uint16_t i;
10727
10728         /* Verify the capabilities */
10729         struct rte_cryptodev_sym_capability_idx cap_idx;
10730         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10731         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10732         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10733                         &cap_idx) == NULL)
10734                 return TEST_SKIPPED;
10735         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10736         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10737         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10738                         &cap_idx) == NULL)
10739                 return TEST_SKIPPED;
10740
10741         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
10742                         aes_cbc_key, hmac_sha512_key);
10743
10744
10745         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10746
10747         sessions = rte_malloc(NULL,
10748                         sizeof(struct rte_cryptodev_sym_session *) *
10749                         (MAX_NB_SESSIONS + 1), 0);
10750
10751         /* Create multiple crypto sessions*/
10752         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10753
10754                 sessions[i] = rte_cryptodev_sym_session_create(
10755                                 ts_params->session_mpool);
10756
10757                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10758                                 sessions[i], &ut_params->auth_xform,
10759                                 ts_params->session_priv_mpool);
10760                 TEST_ASSERT_NOT_NULL(sessions[i],
10761                                 "Session creation failed at session number %u",
10762                                 i);
10763
10764                 /* Attempt to send a request on each session */
10765                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
10766                         sessions[i],
10767                         ut_params,
10768                         ts_params,
10769                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
10770                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
10771                         aes_cbc_iv),
10772                         "Failed to perform decrypt on request number %u.", i);
10773                 /* free crypto operation structure */
10774                 if (ut_params->op)
10775                         rte_crypto_op_free(ut_params->op);
10776
10777                 /*
10778                  * free mbuf - both obuf and ibuf are usually the same,
10779                  * so check if they point at the same address is necessary,
10780                  * to avoid freeing the mbuf twice.
10781                  */
10782                 if (ut_params->obuf) {
10783                         rte_pktmbuf_free(ut_params->obuf);
10784                         if (ut_params->ibuf == ut_params->obuf)
10785                                 ut_params->ibuf = 0;
10786                         ut_params->obuf = 0;
10787                 }
10788                 if (ut_params->ibuf) {
10789                         rte_pktmbuf_free(ut_params->ibuf);
10790                         ut_params->ibuf = 0;
10791                 }
10792         }
10793
10794         sessions[i] = NULL;
10795         /* Next session create should fail */
10796         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10797                         sessions[i], &ut_params->auth_xform,
10798                         ts_params->session_priv_mpool);
10799         TEST_ASSERT_NULL(sessions[i],
10800                         "Session creation succeeded unexpectedly!");
10801
10802         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10803                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10804                                 sessions[i]);
10805                 rte_cryptodev_sym_session_free(sessions[i]);
10806         }
10807
10808         rte_free(sessions);
10809
10810         return TEST_SUCCESS;
10811 }
10812
10813 struct multi_session_params {
10814         struct crypto_unittest_params ut_params;
10815         uint8_t *cipher_key;
10816         uint8_t *hmac_key;
10817         const uint8_t *cipher;
10818         const uint8_t *digest;
10819         uint8_t *iv;
10820 };
10821
10822 #define MB_SESSION_NUMBER 3
10823
10824 static int
10825 test_multi_session_random_usage(void)
10826 {
10827         struct crypto_testsuite_params *ts_params = &testsuite_params;
10828         struct rte_cryptodev_info dev_info;
10829         struct rte_cryptodev_sym_session **sessions;
10830         uint32_t i, j;
10831         struct multi_session_params ut_paramz[] = {
10832
10833                 {
10834                         .cipher_key = ms_aes_cbc_key0,
10835                         .hmac_key = ms_hmac_key0,
10836                         .cipher = ms_aes_cbc_cipher0,
10837                         .digest = ms_hmac_digest0,
10838                         .iv = ms_aes_cbc_iv0
10839                 },
10840                 {
10841                         .cipher_key = ms_aes_cbc_key1,
10842                         .hmac_key = ms_hmac_key1,
10843                         .cipher = ms_aes_cbc_cipher1,
10844                         .digest = ms_hmac_digest1,
10845                         .iv = ms_aes_cbc_iv1
10846                 },
10847                 {
10848                         .cipher_key = ms_aes_cbc_key2,
10849                         .hmac_key = ms_hmac_key2,
10850                         .cipher = ms_aes_cbc_cipher2,
10851                         .digest = ms_hmac_digest2,
10852                         .iv = ms_aes_cbc_iv2
10853                 },
10854
10855         };
10856
10857         /* Verify the capabilities */
10858         struct rte_cryptodev_sym_capability_idx cap_idx;
10859         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10860         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10861         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10862                         &cap_idx) == NULL)
10863                 return TEST_SKIPPED;
10864         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10865         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10866         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10867                         &cap_idx) == NULL)
10868                 return TEST_SKIPPED;
10869
10870         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10871
10872         sessions = rte_malloc(NULL,
10873                         (sizeof(struct rte_cryptodev_sym_session *)
10874                                         * MAX_NB_SESSIONS) + 1, 0);
10875
10876         for (i = 0; i < MB_SESSION_NUMBER; i++) {
10877                 sessions[i] = rte_cryptodev_sym_session_create(
10878                                 ts_params->session_mpool);
10879
10880                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
10881                                 sizeof(struct crypto_unittest_params));
10882
10883                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
10884                                 &ut_paramz[i].ut_params,
10885                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
10886
10887                 /* Create multiple crypto sessions*/
10888                 rte_cryptodev_sym_session_init(
10889                                 ts_params->valid_devs[0],
10890                                 sessions[i],
10891                                 &ut_paramz[i].ut_params.auth_xform,
10892                                 ts_params->session_priv_mpool);
10893
10894                 TEST_ASSERT_NOT_NULL(sessions[i],
10895                                 "Session creation failed at session number %u",
10896                                 i);
10897
10898         }
10899
10900         srand(time(NULL));
10901         for (i = 0; i < 40000; i++) {
10902
10903                 j = rand() % MB_SESSION_NUMBER;
10904
10905                 TEST_ASSERT_SUCCESS(
10906                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
10907                                         sessions[j],
10908                                         &ut_paramz[j].ut_params,
10909                                         ts_params, ut_paramz[j].cipher,
10910                                         ut_paramz[j].digest,
10911                                         ut_paramz[j].iv),
10912                         "Failed to perform decrypt on request number %u.", i);
10913
10914                 if (ut_paramz[j].ut_params.op)
10915                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
10916
10917                 /*
10918                  * free mbuf - both obuf and ibuf are usually the same,
10919                  * so check if they point at the same address is necessary,
10920                  * to avoid freeing the mbuf twice.
10921                  */
10922                 if (ut_paramz[j].ut_params.obuf) {
10923                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
10924                         if (ut_paramz[j].ut_params.ibuf
10925                                         == ut_paramz[j].ut_params.obuf)
10926                                 ut_paramz[j].ut_params.ibuf = 0;
10927                         ut_paramz[j].ut_params.obuf = 0;
10928                 }
10929                 if (ut_paramz[j].ut_params.ibuf) {
10930                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
10931                         ut_paramz[j].ut_params.ibuf = 0;
10932                 }
10933         }
10934
10935         for (i = 0; i < MB_SESSION_NUMBER; i++) {
10936                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10937                                 sessions[i]);
10938                 rte_cryptodev_sym_session_free(sessions[i]);
10939         }
10940
10941         rte_free(sessions);
10942
10943         return TEST_SUCCESS;
10944 }
10945
10946 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
10947                         0xab, 0xab, 0xab, 0xab,
10948                         0xab, 0xab, 0xab, 0xab,
10949                         0xab, 0xab, 0xab, 0xab};
10950
10951 static int
10952 test_null_invalid_operation(void)
10953 {
10954         struct crypto_testsuite_params *ts_params = &testsuite_params;
10955         struct crypto_unittest_params *ut_params = &unittest_params;
10956         int ret;
10957
10958         /* This test is for NULL PMD only */
10959         if (gbl_driver_id != rte_cryptodev_driver_id_get(
10960                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
10961                 return TEST_SKIPPED;
10962
10963         /* Setup Cipher Parameters */
10964         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10965         ut_params->cipher_xform.next = NULL;
10966
10967         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
10968         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10969
10970         ut_params->sess = rte_cryptodev_sym_session_create(
10971                         ts_params->session_mpool);
10972
10973         /* Create Crypto session*/
10974         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10975                         ut_params->sess, &ut_params->cipher_xform,
10976                         ts_params->session_priv_mpool);
10977         TEST_ASSERT(ret < 0,
10978                         "Session creation succeeded unexpectedly");
10979
10980
10981         /* Setup HMAC Parameters */
10982         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10983         ut_params->auth_xform.next = NULL;
10984
10985         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
10986         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10987
10988         ut_params->sess = rte_cryptodev_sym_session_create(
10989                         ts_params->session_mpool);
10990
10991         /* Create Crypto session*/
10992         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10993                         ut_params->sess, &ut_params->auth_xform,
10994                         ts_params->session_priv_mpool);
10995         TEST_ASSERT(ret < 0,
10996                         "Session creation succeeded unexpectedly");
10997
10998         return TEST_SUCCESS;
10999 }
11000
11001
11002 #define NULL_BURST_LENGTH (32)
11003
11004 static int
11005 test_null_burst_operation(void)
11006 {
11007         struct crypto_testsuite_params *ts_params = &testsuite_params;
11008         struct crypto_unittest_params *ut_params = &unittest_params;
11009
11010         unsigned i, burst_len = NULL_BURST_LENGTH;
11011
11012         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11013         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11014
11015         /* This test is for NULL PMD only */
11016         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11017                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11018                 return TEST_SKIPPED;
11019
11020         /* Setup Cipher Parameters */
11021         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11022         ut_params->cipher_xform.next = &ut_params->auth_xform;
11023
11024         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11025         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11026
11027         /* Setup HMAC Parameters */
11028         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11029         ut_params->auth_xform.next = NULL;
11030
11031         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11032         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11033
11034         ut_params->sess = rte_cryptodev_sym_session_create(
11035                         ts_params->session_mpool);
11036
11037         /* Create Crypto session*/
11038         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11039                         ut_params->sess, &ut_params->cipher_xform,
11040                         ts_params->session_priv_mpool);
11041         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11042
11043         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11044                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11045                         burst_len, "failed to generate burst of crypto ops");
11046
11047         /* Generate an operation for each mbuf in burst */
11048         for (i = 0; i < burst_len; i++) {
11049                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11050
11051                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11052
11053                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11054                                 sizeof(unsigned));
11055                 *data = i;
11056
11057                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11058
11059                 burst[i]->sym->m_src = m;
11060         }
11061
11062         /* Process crypto operation */
11063         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11064                         0, burst, burst_len),
11065                         burst_len,
11066                         "Error enqueuing burst");
11067
11068         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11069                         0, burst_dequeued, burst_len),
11070                         burst_len,
11071                         "Error dequeuing burst");
11072
11073
11074         for (i = 0; i < burst_len; i++) {
11075                 TEST_ASSERT_EQUAL(
11076                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11077                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11078                                         uint32_t *),
11079                         "data not as expected");
11080
11081                 rte_pktmbuf_free(burst[i]->sym->m_src);
11082                 rte_crypto_op_free(burst[i]);
11083         }
11084
11085         return TEST_SUCCESS;
11086 }
11087
11088 static uint16_t
11089 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11090                   uint16_t nb_ops, void *user_param)
11091 {
11092         RTE_SET_USED(dev_id);
11093         RTE_SET_USED(qp_id);
11094         RTE_SET_USED(ops);
11095         RTE_SET_USED(user_param);
11096
11097         printf("crypto enqueue callback called\n");
11098         return nb_ops;
11099 }
11100
11101 static uint16_t
11102 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11103                   uint16_t nb_ops, void *user_param)
11104 {
11105         RTE_SET_USED(dev_id);
11106         RTE_SET_USED(qp_id);
11107         RTE_SET_USED(ops);
11108         RTE_SET_USED(user_param);
11109
11110         printf("crypto dequeue callback called\n");
11111         return nb_ops;
11112 }
11113
11114 /*
11115  * Thread using enqueue/dequeue callback with RCU.
11116  */
11117 static int
11118 test_enqdeq_callback_thread(void *arg)
11119 {
11120         RTE_SET_USED(arg);
11121         /* DP thread calls rte_cryptodev_enqueue_burst()/
11122          * rte_cryptodev_dequeue_burst() and invokes callback.
11123          */
11124         test_null_burst_operation();
11125         return 0;
11126 }
11127
11128 static int
11129 test_enq_callback_setup(void)
11130 {
11131         struct crypto_testsuite_params *ts_params = &testsuite_params;
11132         struct rte_cryptodev_info dev_info;
11133         struct rte_cryptodev_qp_conf qp_conf = {
11134                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11135         };
11136
11137         struct rte_cryptodev_cb *cb;
11138         uint16_t qp_id = 0;
11139
11140         /* Stop the device in case it's started so it can be configured */
11141         rte_cryptodev_stop(ts_params->valid_devs[0]);
11142
11143         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11144
11145         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11146                         &ts_params->conf),
11147                         "Failed to configure cryptodev %u",
11148                         ts_params->valid_devs[0]);
11149
11150         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11151         qp_conf.mp_session = ts_params->session_mpool;
11152         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11153
11154         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11155                         ts_params->valid_devs[0], qp_id, &qp_conf,
11156                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11157                         "Failed test for "
11158                         "rte_cryptodev_queue_pair_setup: num_inflights "
11159                         "%u on qp %u on cryptodev %u",
11160                         qp_conf.nb_descriptors, qp_id,
11161                         ts_params->valid_devs[0]);
11162
11163         /* Test with invalid crypto device */
11164         cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11165                         qp_id, test_enq_callback, NULL);
11166         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11167                         "cryptodev %u did not fail",
11168                         qp_id, RTE_CRYPTO_MAX_DEVS);
11169
11170         /* Test with invalid queue pair */
11171         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11172                         dev_info.max_nb_queue_pairs + 1,
11173                         test_enq_callback, NULL);
11174         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11175                         "cryptodev %u did not fail",
11176                         dev_info.max_nb_queue_pairs + 1,
11177                         ts_params->valid_devs[0]);
11178
11179         /* Test with NULL callback */
11180         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11181                         qp_id, NULL, NULL);
11182         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11183                         "cryptodev %u did not fail",
11184                         qp_id, ts_params->valid_devs[0]);
11185
11186         /* Test with valid configuration */
11187         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11188                         qp_id, test_enq_callback, NULL);
11189         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11190                         "qp %u on cryptodev %u",
11191                         qp_id, ts_params->valid_devs[0]);
11192
11193         rte_cryptodev_start(ts_params->valid_devs[0]);
11194
11195         /* Launch a thread */
11196         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11197                                 rte_get_next_lcore(-1, 1, 0));
11198
11199         /* Wait until reader exited. */
11200         rte_eal_mp_wait_lcore();
11201
11202         /* Test with invalid crypto device */
11203         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11204                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11205                         "Expected call to fail as crypto device is invalid");
11206
11207         /* Test with invalid queue pair */
11208         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11209                         ts_params->valid_devs[0],
11210                         dev_info.max_nb_queue_pairs + 1, cb),
11211                         "Expected call to fail as queue pair is invalid");
11212
11213         /* Test with NULL callback */
11214         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11215                         ts_params->valid_devs[0], qp_id, NULL),
11216                         "Expected call to fail as callback is NULL");
11217
11218         /* Test with valid configuration */
11219         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11220                         ts_params->valid_devs[0], qp_id, cb),
11221                         "Failed test to remove callback on "
11222                         "qp %u on cryptodev %u",
11223                         qp_id, ts_params->valid_devs[0]);
11224
11225         return TEST_SUCCESS;
11226 }
11227
11228 static int
11229 test_deq_callback_setup(void)
11230 {
11231         struct crypto_testsuite_params *ts_params = &testsuite_params;
11232         struct rte_cryptodev_info dev_info;
11233         struct rte_cryptodev_qp_conf qp_conf = {
11234                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11235         };
11236
11237         struct rte_cryptodev_cb *cb;
11238         uint16_t qp_id = 0;
11239
11240         /* Stop the device in case it's started so it can be configured */
11241         rte_cryptodev_stop(ts_params->valid_devs[0]);
11242
11243         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11244
11245         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11246                         &ts_params->conf),
11247                         "Failed to configure cryptodev %u",
11248                         ts_params->valid_devs[0]);
11249
11250         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11251         qp_conf.mp_session = ts_params->session_mpool;
11252         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11253
11254         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11255                         ts_params->valid_devs[0], qp_id, &qp_conf,
11256                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11257                         "Failed test for "
11258                         "rte_cryptodev_queue_pair_setup: num_inflights "
11259                         "%u on qp %u on cryptodev %u",
11260                         qp_conf.nb_descriptors, qp_id,
11261                         ts_params->valid_devs[0]);
11262
11263         /* Test with invalid crypto device */
11264         cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11265                         qp_id, test_deq_callback, NULL);
11266         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11267                         "cryptodev %u did not fail",
11268                         qp_id, RTE_CRYPTO_MAX_DEVS);
11269
11270         /* Test with invalid queue pair */
11271         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11272                         dev_info.max_nb_queue_pairs + 1,
11273                         test_deq_callback, NULL);
11274         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11275                         "cryptodev %u did not fail",
11276                         dev_info.max_nb_queue_pairs + 1,
11277                         ts_params->valid_devs[0]);
11278
11279         /* Test with NULL callback */
11280         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11281                         qp_id, NULL, NULL);
11282         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11283                         "cryptodev %u did not fail",
11284                         qp_id, ts_params->valid_devs[0]);
11285
11286         /* Test with valid configuration */
11287         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11288                         qp_id, test_deq_callback, NULL);
11289         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11290                         "qp %u on cryptodev %u",
11291                         qp_id, ts_params->valid_devs[0]);
11292
11293         rte_cryptodev_start(ts_params->valid_devs[0]);
11294
11295         /* Launch a thread */
11296         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11297                                 rte_get_next_lcore(-1, 1, 0));
11298
11299         /* Wait until reader exited. */
11300         rte_eal_mp_wait_lcore();
11301
11302         /* Test with invalid crypto device */
11303         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11304                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11305                         "Expected call to fail as crypto device is invalid");
11306
11307         /* Test with invalid queue pair */
11308         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11309                         ts_params->valid_devs[0],
11310                         dev_info.max_nb_queue_pairs + 1, cb),
11311                         "Expected call to fail as queue pair is invalid");
11312
11313         /* Test with NULL callback */
11314         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11315                         ts_params->valid_devs[0], qp_id, NULL),
11316                         "Expected call to fail as callback is NULL");
11317
11318         /* Test with valid configuration */
11319         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
11320                         ts_params->valid_devs[0], qp_id, cb),
11321                         "Failed test to remove callback on "
11322                         "qp %u on cryptodev %u",
11323                         qp_id, ts_params->valid_devs[0]);
11324
11325         return TEST_SUCCESS;
11326 }
11327
11328 static void
11329 generate_gmac_large_plaintext(uint8_t *data)
11330 {
11331         uint16_t i;
11332
11333         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
11334                 memcpy(&data[i], &data[0], 32);
11335 }
11336
11337 static int
11338 create_gmac_operation(enum rte_crypto_auth_operation op,
11339                 const struct gmac_test_data *tdata)
11340 {
11341         struct crypto_testsuite_params *ts_params = &testsuite_params;
11342         struct crypto_unittest_params *ut_params = &unittest_params;
11343         struct rte_crypto_sym_op *sym_op;
11344
11345         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11346
11347         /* Generate Crypto op data structure */
11348         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11349                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11350         TEST_ASSERT_NOT_NULL(ut_params->op,
11351                         "Failed to allocate symmetric crypto operation struct");
11352
11353         sym_op = ut_params->op->sym;
11354
11355         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11356                         ut_params->ibuf, tdata->gmac_tag.len);
11357         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11358                         "no room to append digest");
11359
11360         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11361                         ut_params->ibuf, plaintext_pad_len);
11362
11363         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11364                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11365                                 tdata->gmac_tag.len);
11366                 debug_hexdump(stdout, "digest:",
11367                                 sym_op->auth.digest.data,
11368                                 tdata->gmac_tag.len);
11369         }
11370
11371         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11372                         uint8_t *, IV_OFFSET);
11373
11374         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11375
11376         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11377
11378         sym_op->cipher.data.length = 0;
11379         sym_op->cipher.data.offset = 0;
11380
11381         sym_op->auth.data.offset = 0;
11382         sym_op->auth.data.length = tdata->plaintext.len;
11383
11384         return 0;
11385 }
11386
11387 static int
11388 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
11389                 const struct gmac_test_data *tdata,
11390                 void *digest_mem, uint64_t digest_phys)
11391 {
11392         struct crypto_testsuite_params *ts_params = &testsuite_params;
11393         struct crypto_unittest_params *ut_params = &unittest_params;
11394         struct rte_crypto_sym_op *sym_op;
11395
11396         /* Generate Crypto op data structure */
11397         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11398                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11399         TEST_ASSERT_NOT_NULL(ut_params->op,
11400                         "Failed to allocate symmetric crypto operation struct");
11401
11402         sym_op = ut_params->op->sym;
11403
11404         sym_op->auth.digest.data = digest_mem;
11405         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11406                         "no room to append digest");
11407
11408         sym_op->auth.digest.phys_addr = digest_phys;
11409
11410         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11411                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11412                                 tdata->gmac_tag.len);
11413                 debug_hexdump(stdout, "digest:",
11414                                 sym_op->auth.digest.data,
11415                                 tdata->gmac_tag.len);
11416         }
11417
11418         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11419                         uint8_t *, IV_OFFSET);
11420
11421         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11422
11423         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11424
11425         sym_op->cipher.data.length = 0;
11426         sym_op->cipher.data.offset = 0;
11427
11428         sym_op->auth.data.offset = 0;
11429         sym_op->auth.data.length = tdata->plaintext.len;
11430
11431         return 0;
11432 }
11433
11434 static int create_gmac_session(uint8_t dev_id,
11435                 const struct gmac_test_data *tdata,
11436                 enum rte_crypto_auth_operation auth_op)
11437 {
11438         uint8_t auth_key[tdata->key.len];
11439
11440         struct crypto_testsuite_params *ts_params = &testsuite_params;
11441         struct crypto_unittest_params *ut_params = &unittest_params;
11442
11443         memcpy(auth_key, tdata->key.data, tdata->key.len);
11444
11445         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11446         ut_params->auth_xform.next = NULL;
11447
11448         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
11449         ut_params->auth_xform.auth.op = auth_op;
11450         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
11451         ut_params->auth_xform.auth.key.length = tdata->key.len;
11452         ut_params->auth_xform.auth.key.data = auth_key;
11453         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11454         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
11455
11456
11457         ut_params->sess = rte_cryptodev_sym_session_create(
11458                         ts_params->session_mpool);
11459
11460         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11461                         &ut_params->auth_xform,
11462                         ts_params->session_priv_mpool);
11463
11464         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11465
11466         return 0;
11467 }
11468
11469 static int
11470 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
11471 {
11472         struct crypto_testsuite_params *ts_params = &testsuite_params;
11473         struct crypto_unittest_params *ut_params = &unittest_params;
11474         struct rte_cryptodev_info dev_info;
11475
11476         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11477         uint64_t feat_flags = dev_info.feature_flags;
11478
11479         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11480                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11481                 printf("Device doesn't support RAW data-path APIs.\n");
11482                 return TEST_SKIPPED;
11483         }
11484
11485         int retval;
11486
11487         uint8_t *auth_tag, *plaintext;
11488         uint16_t plaintext_pad_len;
11489
11490         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11491                               "No GMAC length in the source data");
11492
11493         /* Verify the capabilities */
11494         struct rte_cryptodev_sym_capability_idx cap_idx;
11495         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11496         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11497         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11498                         &cap_idx) == NULL)
11499                 return TEST_SKIPPED;
11500
11501         retval = create_gmac_session(ts_params->valid_devs[0],
11502                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11503
11504         if (retval < 0)
11505                 return retval;
11506
11507         if (tdata->plaintext.len > MBUF_SIZE)
11508                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11509         else
11510                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11511         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11512                         "Failed to allocate input buffer in mempool");
11513
11514         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11515                         rte_pktmbuf_tailroom(ut_params->ibuf));
11516
11517         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11518         /*
11519          * Runtime generate the large plain text instead of use hard code
11520          * plain text vector. It is done to avoid create huge source file
11521          * with the test vector.
11522          */
11523         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11524                 generate_gmac_large_plaintext(tdata->plaintext.data);
11525
11526         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11527                                 plaintext_pad_len);
11528         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11529
11530         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11531         debug_hexdump(stdout, "plaintext:", plaintext,
11532                         tdata->plaintext.len);
11533
11534         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
11535                         tdata);
11536
11537         if (retval < 0)
11538                 return retval;
11539
11540         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11541
11542         ut_params->op->sym->m_src = ut_params->ibuf;
11543
11544         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11545                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11546                         ut_params->op);
11547         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11548                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11549                                 ut_params->op, 0, 1, 0, 0);
11550         else
11551                 TEST_ASSERT_NOT_NULL(
11552                         process_crypto_request(ts_params->valid_devs[0],
11553                         ut_params->op), "failed to process sym crypto op");
11554
11555         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11556                         "crypto op processing failed");
11557
11558         if (ut_params->op->sym->m_dst) {
11559                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11560                                 uint8_t *, plaintext_pad_len);
11561         } else {
11562                 auth_tag = plaintext + plaintext_pad_len;
11563         }
11564
11565         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11566
11567         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11568                         auth_tag,
11569                         tdata->gmac_tag.data,
11570                         tdata->gmac_tag.len,
11571                         "GMAC Generated auth tag not as expected");
11572
11573         return 0;
11574 }
11575
11576 static int
11577 test_AES_GMAC_authentication_test_case_1(void)
11578 {
11579         return test_AES_GMAC_authentication(&gmac_test_case_1);
11580 }
11581
11582 static int
11583 test_AES_GMAC_authentication_test_case_2(void)
11584 {
11585         return test_AES_GMAC_authentication(&gmac_test_case_2);
11586 }
11587
11588 static int
11589 test_AES_GMAC_authentication_test_case_3(void)
11590 {
11591         return test_AES_GMAC_authentication(&gmac_test_case_3);
11592 }
11593
11594 static int
11595 test_AES_GMAC_authentication_test_case_4(void)
11596 {
11597         return test_AES_GMAC_authentication(&gmac_test_case_4);
11598 }
11599
11600 static int
11601 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
11602 {
11603         struct crypto_testsuite_params *ts_params = &testsuite_params;
11604         struct crypto_unittest_params *ut_params = &unittest_params;
11605         int retval;
11606         uint32_t plaintext_pad_len;
11607         uint8_t *plaintext;
11608         struct rte_cryptodev_info dev_info;
11609
11610         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11611         uint64_t feat_flags = dev_info.feature_flags;
11612
11613         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11614                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11615                 printf("Device doesn't support RAW data-path APIs.\n");
11616                 return TEST_SKIPPED;
11617         }
11618
11619         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11620                               "No GMAC length in the source data");
11621
11622         /* Verify the capabilities */
11623         struct rte_cryptodev_sym_capability_idx cap_idx;
11624         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11625         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11626         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11627                         &cap_idx) == NULL)
11628                 return TEST_SKIPPED;
11629
11630         retval = create_gmac_session(ts_params->valid_devs[0],
11631                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
11632
11633         if (retval < 0)
11634                 return retval;
11635
11636         if (tdata->plaintext.len > MBUF_SIZE)
11637                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11638         else
11639                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11640         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11641                         "Failed to allocate input buffer in mempool");
11642
11643         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11644                         rte_pktmbuf_tailroom(ut_params->ibuf));
11645
11646         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11647
11648         /*
11649          * Runtime generate the large plain text instead of use hard code
11650          * plain text vector. It is done to avoid create huge source file
11651          * with the test vector.
11652          */
11653         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11654                 generate_gmac_large_plaintext(tdata->plaintext.data);
11655
11656         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11657                                 plaintext_pad_len);
11658         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11659
11660         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11661         debug_hexdump(stdout, "plaintext:", plaintext,
11662                         tdata->plaintext.len);
11663
11664         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
11665                         tdata);
11666
11667         if (retval < 0)
11668                 return retval;
11669
11670         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11671
11672         ut_params->op->sym->m_src = ut_params->ibuf;
11673
11674         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11675                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11676                         ut_params->op);
11677         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11678                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11679                                 ut_params->op, 0, 1, 0, 0);
11680         else
11681                 TEST_ASSERT_NOT_NULL(
11682                         process_crypto_request(ts_params->valid_devs[0],
11683                         ut_params->op), "failed to process sym crypto op");
11684
11685         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11686                         "crypto op processing failed");
11687
11688         return 0;
11689
11690 }
11691
11692 static int
11693 test_AES_GMAC_authentication_verify_test_case_1(void)
11694 {
11695         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
11696 }
11697
11698 static int
11699 test_AES_GMAC_authentication_verify_test_case_2(void)
11700 {
11701         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
11702 }
11703
11704 static int
11705 test_AES_GMAC_authentication_verify_test_case_3(void)
11706 {
11707         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
11708 }
11709
11710 static int
11711 test_AES_GMAC_authentication_verify_test_case_4(void)
11712 {
11713         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
11714 }
11715
11716 static int
11717 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
11718                                 uint32_t fragsz)
11719 {
11720         struct crypto_testsuite_params *ts_params = &testsuite_params;
11721         struct crypto_unittest_params *ut_params = &unittest_params;
11722         struct rte_cryptodev_info dev_info;
11723         uint64_t feature_flags;
11724         unsigned int trn_data = 0;
11725         void *digest_mem = NULL;
11726         uint32_t segs = 1;
11727         unsigned int to_trn = 0;
11728         struct rte_mbuf *buf = NULL;
11729         uint8_t *auth_tag, *plaintext;
11730         int retval;
11731
11732         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11733                               "No GMAC length in the source data");
11734
11735         /* Verify the capabilities */
11736         struct rte_cryptodev_sym_capability_idx cap_idx;
11737         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11738         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11739         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11740                         &cap_idx) == NULL)
11741                 return TEST_SKIPPED;
11742
11743         /* Check for any input SGL support */
11744         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11745         feature_flags = dev_info.feature_flags;
11746
11747         if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
11748                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
11749                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
11750                 return TEST_SKIPPED;
11751
11752         if (fragsz > tdata->plaintext.len)
11753                 fragsz = tdata->plaintext.len;
11754
11755         uint16_t plaintext_len = fragsz;
11756
11757         retval = create_gmac_session(ts_params->valid_devs[0],
11758                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11759
11760         if (retval < 0)
11761                 return retval;
11762
11763         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11764         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11765                         "Failed to allocate input buffer in mempool");
11766
11767         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11768                         rte_pktmbuf_tailroom(ut_params->ibuf));
11769
11770         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11771                                 plaintext_len);
11772         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11773
11774         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
11775
11776         trn_data += plaintext_len;
11777
11778         buf = ut_params->ibuf;
11779
11780         /*
11781          * Loop until no more fragments
11782          */
11783
11784         while (trn_data < tdata->plaintext.len) {
11785                 ++segs;
11786                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
11787                                 (tdata->plaintext.len - trn_data) : fragsz;
11788
11789                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11790                 buf = buf->next;
11791
11792                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
11793                                 rte_pktmbuf_tailroom(buf));
11794
11795                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
11796                                 to_trn);
11797
11798                 memcpy(plaintext, tdata->plaintext.data + trn_data,
11799                                 to_trn);
11800                 trn_data += to_trn;
11801                 if (trn_data  == tdata->plaintext.len)
11802                         digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
11803                                         tdata->gmac_tag.len);
11804         }
11805         ut_params->ibuf->nb_segs = segs;
11806
11807         /*
11808          * Place digest at the end of the last buffer
11809          */
11810         uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11811
11812         if (!digest_mem) {
11813                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11814                                 + tdata->gmac_tag.len);
11815                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11816                                 tdata->plaintext.len);
11817         }
11818
11819         retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
11820                         tdata, digest_mem, digest_phys);
11821
11822         if (retval < 0)
11823                 return retval;
11824
11825         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11826
11827         ut_params->op->sym->m_src = ut_params->ibuf;
11828
11829         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11830                 return TEST_SKIPPED;
11831
11832         TEST_ASSERT_NOT_NULL(
11833                 process_crypto_request(ts_params->valid_devs[0],
11834                 ut_params->op), "failed to process sym crypto op");
11835
11836         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11837                         "crypto op processing failed");
11838
11839         auth_tag = digest_mem;
11840         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11841         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11842                         auth_tag,
11843                         tdata->gmac_tag.data,
11844                         tdata->gmac_tag.len,
11845                         "GMAC Generated auth tag not as expected");
11846
11847         return 0;
11848 }
11849
11850 /* Segment size not multiple of block size (16B) */
11851 static int
11852 test_AES_GMAC_authentication_SGL_40B(void)
11853 {
11854         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
11855 }
11856
11857 static int
11858 test_AES_GMAC_authentication_SGL_80B(void)
11859 {
11860         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
11861 }
11862
11863 static int
11864 test_AES_GMAC_authentication_SGL_2048B(void)
11865 {
11866         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
11867 }
11868
11869 /* Segment size not multiple of block size (16B) */
11870 static int
11871 test_AES_GMAC_authentication_SGL_2047B(void)
11872 {
11873         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
11874 }
11875
11876 struct test_crypto_vector {
11877         enum rte_crypto_cipher_algorithm crypto_algo;
11878         unsigned int cipher_offset;
11879         unsigned int cipher_len;
11880
11881         struct {
11882                 uint8_t data[64];
11883                 unsigned int len;
11884         } cipher_key;
11885
11886         struct {
11887                 uint8_t data[64];
11888                 unsigned int len;
11889         } iv;
11890
11891         struct {
11892                 const uint8_t *data;
11893                 unsigned int len;
11894         } plaintext;
11895
11896         struct {
11897                 const uint8_t *data;
11898                 unsigned int len;
11899         } ciphertext;
11900
11901         enum rte_crypto_auth_algorithm auth_algo;
11902         unsigned int auth_offset;
11903
11904         struct {
11905                 uint8_t data[128];
11906                 unsigned int len;
11907         } auth_key;
11908
11909         struct {
11910                 const uint8_t *data;
11911                 unsigned int len;
11912         } aad;
11913
11914         struct {
11915                 uint8_t data[128];
11916                 unsigned int len;
11917         } digest;
11918 };
11919
11920 static const struct test_crypto_vector
11921 hmac_sha1_test_crypto_vector = {
11922         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11923         .plaintext = {
11924                 .data = plaintext_hash,
11925                 .len = 512
11926         },
11927         .auth_key = {
11928                 .data = {
11929                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11930                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11931                         0xDE, 0xF4, 0xDE, 0xAD
11932                 },
11933                 .len = 20
11934         },
11935         .digest = {
11936                 .data = {
11937                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
11938                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
11939                         0x3F, 0x91, 0x64, 0x59
11940                 },
11941                 .len = 20
11942         }
11943 };
11944
11945 static const struct test_crypto_vector
11946 aes128_gmac_test_vector = {
11947         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
11948         .plaintext = {
11949                 .data = plaintext_hash,
11950                 .len = 512
11951         },
11952         .iv = {
11953                 .data = {
11954                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11955                         0x08, 0x09, 0x0A, 0x0B
11956                 },
11957                 .len = 12
11958         },
11959         .auth_key = {
11960                 .data = {
11961                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
11962                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
11963                 },
11964                 .len = 16
11965         },
11966         .digest = {
11967                 .data = {
11968                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
11969                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
11970                 },
11971                 .len = 16
11972         }
11973 };
11974
11975 static const struct test_crypto_vector
11976 aes128cbc_hmac_sha1_test_vector = {
11977         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
11978         .cipher_offset = 0,
11979         .cipher_len = 512,
11980         .cipher_key = {
11981                 .data = {
11982                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
11983                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
11984                 },
11985                 .len = 16
11986         },
11987         .iv = {
11988                 .data = {
11989                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11990                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
11991                 },
11992                 .len = 16
11993         },
11994         .plaintext = {
11995                 .data = plaintext_hash,
11996                 .len = 512
11997         },
11998         .ciphertext = {
11999                 .data = ciphertext512_aes128cbc,
12000                 .len = 512
12001         },
12002         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12003         .auth_offset = 0,
12004         .auth_key = {
12005                 .data = {
12006                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12007                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12008                         0xDE, 0xF4, 0xDE, 0xAD
12009                 },
12010                 .len = 20
12011         },
12012         .digest = {
12013                 .data = {
12014                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12015                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12016                         0x18, 0x8C, 0x1D, 0x32
12017                 },
12018                 .len = 20
12019         }
12020 };
12021
12022 static const struct test_crypto_vector
12023 aes128cbc_hmac_sha1_aad_test_vector = {
12024         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12025         .cipher_offset = 8,
12026         .cipher_len = 496,
12027         .cipher_key = {
12028                 .data = {
12029                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12030                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12031                 },
12032                 .len = 16
12033         },
12034         .iv = {
12035                 .data = {
12036                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12037                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12038                 },
12039                 .len = 16
12040         },
12041         .plaintext = {
12042                 .data = plaintext_hash,
12043                 .len = 512
12044         },
12045         .ciphertext = {
12046                 .data = ciphertext512_aes128cbc_aad,
12047                 .len = 512
12048         },
12049         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12050         .auth_offset = 0,
12051         .auth_key = {
12052                 .data = {
12053                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12054                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12055                         0xDE, 0xF4, 0xDE, 0xAD
12056                 },
12057                 .len = 20
12058         },
12059         .digest = {
12060                 .data = {
12061                         0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12062                         0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12063                         0x62, 0x0F, 0xFB, 0x10
12064                 },
12065                 .len = 20
12066         }
12067 };
12068
12069 static void
12070 data_corruption(uint8_t *data)
12071 {
12072         data[0] += 1;
12073 }
12074
12075 static void
12076 tag_corruption(uint8_t *data, unsigned int tag_offset)
12077 {
12078         data[tag_offset] += 1;
12079 }
12080
12081 static int
12082 create_auth_session(struct crypto_unittest_params *ut_params,
12083                 uint8_t dev_id,
12084                 const struct test_crypto_vector *reference,
12085                 enum rte_crypto_auth_operation auth_op)
12086 {
12087         struct crypto_testsuite_params *ts_params = &testsuite_params;
12088         uint8_t auth_key[reference->auth_key.len + 1];
12089
12090         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12091
12092         /* Setup Authentication Parameters */
12093         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12094         ut_params->auth_xform.auth.op = auth_op;
12095         ut_params->auth_xform.next = NULL;
12096         ut_params->auth_xform.auth.algo = reference->auth_algo;
12097         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12098         ut_params->auth_xform.auth.key.data = auth_key;
12099         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12100
12101         /* Create Crypto session*/
12102         ut_params->sess = rte_cryptodev_sym_session_create(
12103                         ts_params->session_mpool);
12104
12105         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12106                                 &ut_params->auth_xform,
12107                                 ts_params->session_priv_mpool);
12108
12109         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12110
12111         return 0;
12112 }
12113
12114 static int
12115 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12116                 uint8_t dev_id,
12117                 const struct test_crypto_vector *reference,
12118                 enum rte_crypto_auth_operation auth_op,
12119                 enum rte_crypto_cipher_operation cipher_op)
12120 {
12121         struct crypto_testsuite_params *ts_params = &testsuite_params;
12122         uint8_t cipher_key[reference->cipher_key.len + 1];
12123         uint8_t auth_key[reference->auth_key.len + 1];
12124
12125         memcpy(cipher_key, reference->cipher_key.data,
12126                         reference->cipher_key.len);
12127         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12128
12129         /* Setup Authentication Parameters */
12130         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12131         ut_params->auth_xform.auth.op = auth_op;
12132         ut_params->auth_xform.auth.algo = reference->auth_algo;
12133         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12134         ut_params->auth_xform.auth.key.data = auth_key;
12135         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12136
12137         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12138                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12139                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
12140         } else {
12141                 ut_params->auth_xform.next = &ut_params->cipher_xform;
12142
12143                 /* Setup Cipher Parameters */
12144                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12145                 ut_params->cipher_xform.next = NULL;
12146                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12147                 ut_params->cipher_xform.cipher.op = cipher_op;
12148                 ut_params->cipher_xform.cipher.key.data = cipher_key;
12149                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12150                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12151                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12152         }
12153
12154         /* Create Crypto session*/
12155         ut_params->sess = rte_cryptodev_sym_session_create(
12156                         ts_params->session_mpool);
12157
12158         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12159                                 &ut_params->auth_xform,
12160                                 ts_params->session_priv_mpool);
12161
12162         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12163
12164         return 0;
12165 }
12166
12167 static int
12168 create_auth_operation(struct crypto_testsuite_params *ts_params,
12169                 struct crypto_unittest_params *ut_params,
12170                 const struct test_crypto_vector *reference,
12171                 unsigned int auth_generate)
12172 {
12173         /* Generate Crypto op data structure */
12174         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12175                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12176         TEST_ASSERT_NOT_NULL(ut_params->op,
12177                         "Failed to allocate pktmbuf offload");
12178
12179         /* Set crypto operation data parameters */
12180         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12181
12182         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12183
12184         /* set crypto operation source mbuf */
12185         sym_op->m_src = ut_params->ibuf;
12186
12187         /* digest */
12188         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12189                         ut_params->ibuf, reference->digest.len);
12190
12191         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12192                         "no room to append auth tag");
12193
12194         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12195                         ut_params->ibuf, reference->plaintext.len);
12196
12197         if (auth_generate)
12198                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12199         else
12200                 memcpy(sym_op->auth.digest.data,
12201                                 reference->digest.data,
12202                                 reference->digest.len);
12203
12204         debug_hexdump(stdout, "digest:",
12205                         sym_op->auth.digest.data,
12206                         reference->digest.len);
12207
12208         sym_op->auth.data.length = reference->plaintext.len;
12209         sym_op->auth.data.offset = 0;
12210
12211         return 0;
12212 }
12213
12214 static int
12215 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12216                 struct crypto_unittest_params *ut_params,
12217                 const struct test_crypto_vector *reference,
12218                 unsigned int auth_generate)
12219 {
12220         /* Generate Crypto op data structure */
12221         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12222                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12223         TEST_ASSERT_NOT_NULL(ut_params->op,
12224                         "Failed to allocate pktmbuf offload");
12225
12226         /* Set crypto operation data parameters */
12227         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12228
12229         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12230
12231         /* set crypto operation source mbuf */
12232         sym_op->m_src = ut_params->ibuf;
12233
12234         /* digest */
12235         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12236                         ut_params->ibuf, reference->digest.len);
12237
12238         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12239                         "no room to append auth tag");
12240
12241         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12242                         ut_params->ibuf, reference->ciphertext.len);
12243
12244         if (auth_generate)
12245                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12246         else
12247                 memcpy(sym_op->auth.digest.data,
12248                                 reference->digest.data,
12249                                 reference->digest.len);
12250
12251         debug_hexdump(stdout, "digest:",
12252                         sym_op->auth.digest.data,
12253                         reference->digest.len);
12254
12255         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12256                         reference->iv.data, reference->iv.len);
12257
12258         sym_op->cipher.data.length = 0;
12259         sym_op->cipher.data.offset = 0;
12260
12261         sym_op->auth.data.length = reference->plaintext.len;
12262         sym_op->auth.data.offset = 0;
12263
12264         return 0;
12265 }
12266
12267 static int
12268 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12269                 struct crypto_unittest_params *ut_params,
12270                 const struct test_crypto_vector *reference,
12271                 unsigned int auth_generate)
12272 {
12273         /* Generate Crypto op data structure */
12274         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12275                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12276         TEST_ASSERT_NOT_NULL(ut_params->op,
12277                         "Failed to allocate pktmbuf offload");
12278
12279         /* Set crypto operation data parameters */
12280         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12281
12282         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12283
12284         /* set crypto operation source mbuf */
12285         sym_op->m_src = ut_params->ibuf;
12286
12287         /* digest */
12288         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12289                         ut_params->ibuf, reference->digest.len);
12290
12291         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12292                         "no room to append auth tag");
12293
12294         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12295                         ut_params->ibuf, reference->ciphertext.len);
12296
12297         if (auth_generate)
12298                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12299         else
12300                 memcpy(sym_op->auth.digest.data,
12301                                 reference->digest.data,
12302                                 reference->digest.len);
12303
12304         debug_hexdump(stdout, "digest:",
12305                         sym_op->auth.digest.data,
12306                         reference->digest.len);
12307
12308         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12309                         reference->iv.data, reference->iv.len);
12310
12311         sym_op->cipher.data.length = reference->cipher_len;
12312         sym_op->cipher.data.offset = reference->cipher_offset;
12313
12314         sym_op->auth.data.length = reference->plaintext.len;
12315         sym_op->auth.data.offset = reference->auth_offset;
12316
12317         return 0;
12318 }
12319
12320 static int
12321 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12322                 struct crypto_unittest_params *ut_params,
12323                 const struct test_crypto_vector *reference)
12324 {
12325         return create_auth_operation(ts_params, ut_params, reference, 0);
12326 }
12327
12328 static int
12329 create_auth_verify_GMAC_operation(
12330                 struct crypto_testsuite_params *ts_params,
12331                 struct crypto_unittest_params *ut_params,
12332                 const struct test_crypto_vector *reference)
12333 {
12334         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
12335 }
12336
12337 static int
12338 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12339                 struct crypto_unittest_params *ut_params,
12340                 const struct test_crypto_vector *reference)
12341 {
12342         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12343 }
12344
12345 static int
12346 test_authentication_verify_fail_when_data_corruption(
12347                 struct crypto_testsuite_params *ts_params,
12348                 struct crypto_unittest_params *ut_params,
12349                 const struct test_crypto_vector *reference,
12350                 unsigned int data_corrupted)
12351 {
12352         int retval;
12353
12354         uint8_t *plaintext;
12355         struct rte_cryptodev_info dev_info;
12356
12357         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12358         uint64_t feat_flags = dev_info.feature_flags;
12359
12360         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12361                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12362                 printf("Device doesn't support RAW data-path APIs.\n");
12363                 return TEST_SKIPPED;
12364         }
12365
12366         /* Verify the capabilities */
12367         struct rte_cryptodev_sym_capability_idx cap_idx;
12368         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12369         cap_idx.algo.auth = reference->auth_algo;
12370         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12371                         &cap_idx) == NULL)
12372                 return TEST_SKIPPED;
12373
12374
12375         /* Create session */
12376         retval = create_auth_session(ut_params,
12377                         ts_params->valid_devs[0],
12378                         reference,
12379                         RTE_CRYPTO_AUTH_OP_VERIFY);
12380         if (retval < 0)
12381                 return retval;
12382
12383         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12384         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12385                         "Failed to allocate input buffer in mempool");
12386
12387         /* clear mbuf payload */
12388         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12389                         rte_pktmbuf_tailroom(ut_params->ibuf));
12390
12391         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12392                         reference->plaintext.len);
12393         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12394         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12395
12396         debug_hexdump(stdout, "plaintext:", plaintext,
12397                 reference->plaintext.len);
12398
12399         /* Create operation */
12400         retval = create_auth_verify_operation(ts_params, ut_params, reference);
12401
12402         if (retval < 0)
12403                 return retval;
12404
12405         if (data_corrupted)
12406                 data_corruption(plaintext);
12407         else
12408                 tag_corruption(plaintext, reference->plaintext.len);
12409
12410         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12411                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12412                         ut_params->op);
12413                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12414                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12415                         "authentication not failed");
12416         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12417                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12418                                 ut_params->op, 0, 1, 0, 0);
12419         else {
12420                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12421                         ut_params->op);
12422                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12423         }
12424
12425         return 0;
12426 }
12427
12428 static int
12429 test_authentication_verify_GMAC_fail_when_corruption(
12430                 struct crypto_testsuite_params *ts_params,
12431                 struct crypto_unittest_params *ut_params,
12432                 const struct test_crypto_vector *reference,
12433                 unsigned int data_corrupted)
12434 {
12435         int retval;
12436         uint8_t *plaintext;
12437         struct rte_cryptodev_info dev_info;
12438
12439         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12440         uint64_t feat_flags = dev_info.feature_flags;
12441
12442         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12443                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12444                 printf("Device doesn't support RAW data-path APIs.\n");
12445                 return TEST_SKIPPED;
12446         }
12447
12448         /* Verify the capabilities */
12449         struct rte_cryptodev_sym_capability_idx cap_idx;
12450         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12451         cap_idx.algo.auth = reference->auth_algo;
12452         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12453                         &cap_idx) == NULL)
12454                 return TEST_SKIPPED;
12455
12456         /* Create session */
12457         retval = create_auth_cipher_session(ut_params,
12458                         ts_params->valid_devs[0],
12459                         reference,
12460                         RTE_CRYPTO_AUTH_OP_VERIFY,
12461                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12462         if (retval < 0)
12463                 return retval;
12464
12465         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12466         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12467                         "Failed to allocate input buffer in mempool");
12468
12469         /* clear mbuf payload */
12470         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12471                         rte_pktmbuf_tailroom(ut_params->ibuf));
12472
12473         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12474                         reference->plaintext.len);
12475         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12476         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12477
12478         debug_hexdump(stdout, "plaintext:", plaintext,
12479                 reference->plaintext.len);
12480
12481         /* Create operation */
12482         retval = create_auth_verify_GMAC_operation(ts_params,
12483                         ut_params,
12484                         reference);
12485
12486         if (retval < 0)
12487                 return retval;
12488
12489         if (data_corrupted)
12490                 data_corruption(plaintext);
12491         else
12492                 tag_corruption(plaintext, reference->aad.len);
12493
12494         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12495                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12496                         ut_params->op);
12497                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12498                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12499                         "authentication not failed");
12500         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12501                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12502                                 ut_params->op, 0, 1, 0, 0);
12503         else {
12504                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12505                         ut_params->op);
12506                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12507         }
12508
12509         return 0;
12510 }
12511
12512 static int
12513 test_authenticated_decryption_fail_when_corruption(
12514                 struct crypto_testsuite_params *ts_params,
12515                 struct crypto_unittest_params *ut_params,
12516                 const struct test_crypto_vector *reference,
12517                 unsigned int data_corrupted)
12518 {
12519         int retval;
12520
12521         uint8_t *ciphertext;
12522         struct rte_cryptodev_info dev_info;
12523
12524         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12525         uint64_t feat_flags = dev_info.feature_flags;
12526
12527         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12528                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12529                 printf("Device doesn't support RAW data-path APIs.\n");
12530                 return TEST_SKIPPED;
12531         }
12532
12533         /* Verify the capabilities */
12534         struct rte_cryptodev_sym_capability_idx cap_idx;
12535         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12536         cap_idx.algo.auth = reference->auth_algo;
12537         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12538                         &cap_idx) == NULL)
12539                 return TEST_SKIPPED;
12540         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12541         cap_idx.algo.cipher = reference->crypto_algo;
12542         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12543                         &cap_idx) == NULL)
12544                 return TEST_SKIPPED;
12545
12546         /* Create session */
12547         retval = create_auth_cipher_session(ut_params,
12548                         ts_params->valid_devs[0],
12549                         reference,
12550                         RTE_CRYPTO_AUTH_OP_VERIFY,
12551                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12552         if (retval < 0)
12553                 return retval;
12554
12555         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12556         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12557                         "Failed to allocate input buffer in mempool");
12558
12559         /* clear mbuf payload */
12560         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12561                         rte_pktmbuf_tailroom(ut_params->ibuf));
12562
12563         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12564                         reference->ciphertext.len);
12565         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12566         memcpy(ciphertext, reference->ciphertext.data,
12567                         reference->ciphertext.len);
12568
12569         /* Create operation */
12570         retval = create_cipher_auth_verify_operation(ts_params,
12571                         ut_params,
12572                         reference);
12573
12574         if (retval < 0)
12575                 return retval;
12576
12577         if (data_corrupted)
12578                 data_corruption(ciphertext);
12579         else
12580                 tag_corruption(ciphertext, reference->ciphertext.len);
12581
12582         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12583                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12584                         ut_params->op);
12585                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12586                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12587                         "authentication not failed");
12588         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12589                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12590                                 ut_params->op, 1, 1, 0, 0);
12591         else {
12592                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12593                         ut_params->op);
12594                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12595         }
12596
12597         return 0;
12598 }
12599
12600 static int
12601 test_authenticated_encrypt_with_esn(
12602                 struct crypto_testsuite_params *ts_params,
12603                 struct crypto_unittest_params *ut_params,
12604                 const struct test_crypto_vector *reference)
12605 {
12606         int retval;
12607
12608         uint8_t *authciphertext, *plaintext, *auth_tag;
12609         uint16_t plaintext_pad_len;
12610         uint8_t cipher_key[reference->cipher_key.len + 1];
12611         uint8_t auth_key[reference->auth_key.len + 1];
12612         struct rte_cryptodev_info dev_info;
12613
12614         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12615         uint64_t feat_flags = dev_info.feature_flags;
12616
12617         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12618                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12619                 printf("Device doesn't support RAW data-path APIs.\n");
12620                 return TEST_SKIPPED;
12621         }
12622
12623         /* Verify the capabilities */
12624         struct rte_cryptodev_sym_capability_idx cap_idx;
12625         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12626         cap_idx.algo.auth = reference->auth_algo;
12627         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12628                         &cap_idx) == NULL)
12629                 return TEST_SKIPPED;
12630         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12631         cap_idx.algo.cipher = reference->crypto_algo;
12632         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12633                         &cap_idx) == NULL)
12634                 return TEST_SKIPPED;
12635
12636         /* Create session */
12637         memcpy(cipher_key, reference->cipher_key.data,
12638                         reference->cipher_key.len);
12639         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12640
12641         /* Setup Cipher Parameters */
12642         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12643         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12644         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12645         ut_params->cipher_xform.cipher.key.data = cipher_key;
12646         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12647         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12648         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12649
12650         ut_params->cipher_xform.next = &ut_params->auth_xform;
12651
12652         /* Setup Authentication Parameters */
12653         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12654         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12655         ut_params->auth_xform.auth.algo = reference->auth_algo;
12656         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12657         ut_params->auth_xform.auth.key.data = auth_key;
12658         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12659         ut_params->auth_xform.next = NULL;
12660
12661         /* Create Crypto session*/
12662         ut_params->sess = rte_cryptodev_sym_session_create(
12663                         ts_params->session_mpool);
12664
12665         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12666                                 ut_params->sess,
12667                                 &ut_params->cipher_xform,
12668                                 ts_params->session_priv_mpool);
12669
12670         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12671
12672         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12673         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12674                         "Failed to allocate input buffer in mempool");
12675
12676         /* clear mbuf payload */
12677         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12678                         rte_pktmbuf_tailroom(ut_params->ibuf));
12679
12680         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12681                         reference->plaintext.len);
12682         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12683         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12684
12685         /* Create operation */
12686         retval = create_cipher_auth_operation(ts_params,
12687                         ut_params,
12688                         reference, 0);
12689
12690         if (retval < 0)
12691                 return retval;
12692
12693         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12694                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12695                         ut_params->op);
12696         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12697                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12698                                 ut_params->op, 1, 1, 0, 0);
12699         else
12700                 ut_params->op = process_crypto_request(
12701                         ts_params->valid_devs[0], ut_params->op);
12702
12703         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
12704
12705         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12706                         "crypto op processing failed");
12707
12708         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
12709
12710         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
12711                         ut_params->op->sym->auth.data.offset);
12712         auth_tag = authciphertext + plaintext_pad_len;
12713         debug_hexdump(stdout, "ciphertext:", authciphertext,
12714                         reference->ciphertext.len);
12715         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
12716
12717         /* Validate obuf */
12718         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12719                         authciphertext,
12720                         reference->ciphertext.data,
12721                         reference->ciphertext.len,
12722                         "Ciphertext data not as expected");
12723
12724         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12725                         auth_tag,
12726                         reference->digest.data,
12727                         reference->digest.len,
12728                         "Generated digest not as expected");
12729
12730         return TEST_SUCCESS;
12731
12732 }
12733
12734 static int
12735 test_authenticated_decrypt_with_esn(
12736                 struct crypto_testsuite_params *ts_params,
12737                 struct crypto_unittest_params *ut_params,
12738                 const struct test_crypto_vector *reference)
12739 {
12740         int retval;
12741
12742         uint8_t *ciphertext;
12743         uint8_t cipher_key[reference->cipher_key.len + 1];
12744         uint8_t auth_key[reference->auth_key.len + 1];
12745         struct rte_cryptodev_info dev_info;
12746
12747         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12748         uint64_t feat_flags = dev_info.feature_flags;
12749
12750         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12751                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12752                 printf("Device doesn't support RAW data-path APIs.\n");
12753                 return TEST_SKIPPED;
12754         }
12755
12756         /* Verify the capabilities */
12757         struct rte_cryptodev_sym_capability_idx cap_idx;
12758         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12759         cap_idx.algo.auth = reference->auth_algo;
12760         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12761                         &cap_idx) == NULL)
12762                 return TEST_SKIPPED;
12763         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12764         cap_idx.algo.cipher = reference->crypto_algo;
12765         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12766                         &cap_idx) == NULL)
12767                 return TEST_SKIPPED;
12768
12769         /* Create session */
12770         memcpy(cipher_key, reference->cipher_key.data,
12771                         reference->cipher_key.len);
12772         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12773
12774         /* Setup Authentication Parameters */
12775         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12776         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
12777         ut_params->auth_xform.auth.algo = reference->auth_algo;
12778         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12779         ut_params->auth_xform.auth.key.data = auth_key;
12780         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12781         ut_params->auth_xform.next = &ut_params->cipher_xform;
12782
12783         /* Setup Cipher Parameters */
12784         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12785         ut_params->cipher_xform.next = NULL;
12786         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12787         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
12788         ut_params->cipher_xform.cipher.key.data = cipher_key;
12789         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12790         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12791         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12792
12793         /* Create Crypto session*/
12794         ut_params->sess = rte_cryptodev_sym_session_create(
12795                         ts_params->session_mpool);
12796
12797         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12798                                 ut_params->sess,
12799                                 &ut_params->auth_xform,
12800                                 ts_params->session_priv_mpool);
12801
12802         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12803
12804         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12805         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12806                         "Failed to allocate input buffer in mempool");
12807
12808         /* clear mbuf payload */
12809         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12810                         rte_pktmbuf_tailroom(ut_params->ibuf));
12811
12812         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12813                         reference->ciphertext.len);
12814         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12815         memcpy(ciphertext, reference->ciphertext.data,
12816                         reference->ciphertext.len);
12817
12818         /* Create operation */
12819         retval = create_cipher_auth_verify_operation(ts_params,
12820                         ut_params,
12821                         reference);
12822
12823         if (retval < 0)
12824                 return retval;
12825
12826         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12827                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12828                         ut_params->op);
12829         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12830                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12831                                 ut_params->op, 1, 1, 0, 0);
12832         else
12833                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12834                         ut_params->op);
12835
12836         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
12837         TEST_ASSERT_EQUAL(ut_params->op->status,
12838                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12839                         "crypto op processing passed");
12840
12841         ut_params->obuf = ut_params->op->sym->m_src;
12842         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
12843
12844         return 0;
12845 }
12846
12847 static int
12848 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
12849                 const struct aead_test_data *tdata,
12850                 void *digest_mem, uint64_t digest_phys)
12851 {
12852         struct crypto_testsuite_params *ts_params = &testsuite_params;
12853         struct crypto_unittest_params *ut_params = &unittest_params;
12854
12855         const unsigned int auth_tag_len = tdata->auth_tag.len;
12856         const unsigned int iv_len = tdata->iv.len;
12857         unsigned int aad_len = tdata->aad.len;
12858         unsigned int aad_len_pad = 0;
12859
12860         /* Generate Crypto op data structure */
12861         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12862                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12863         TEST_ASSERT_NOT_NULL(ut_params->op,
12864                 "Failed to allocate symmetric crypto operation struct");
12865
12866         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12867
12868         sym_op->aead.digest.data = digest_mem;
12869
12870         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
12871                         "no room to append digest");
12872
12873         sym_op->aead.digest.phys_addr = digest_phys;
12874
12875         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
12876                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
12877                                 auth_tag_len);
12878                 debug_hexdump(stdout, "digest:",
12879                                 sym_op->aead.digest.data,
12880                                 auth_tag_len);
12881         }
12882
12883         /* Append aad data */
12884         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
12885                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12886                                 uint8_t *, IV_OFFSET);
12887
12888                 /* Copy IV 1 byte after the IV pointer, according to the API */
12889                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
12890
12891                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
12892
12893                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12894                                 ut_params->ibuf, aad_len);
12895                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12896                                 "no room to prepend aad");
12897                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12898                                 ut_params->ibuf);
12899
12900                 memset(sym_op->aead.aad.data, 0, aad_len);
12901                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
12902                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12903
12904                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12905                 debug_hexdump(stdout, "aad:",
12906                                 sym_op->aead.aad.data, aad_len);
12907         } else {
12908                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12909                                 uint8_t *, IV_OFFSET);
12910
12911                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
12912
12913                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
12914
12915                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12916                                 ut_params->ibuf, aad_len_pad);
12917                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12918                                 "no room to prepend aad");
12919                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12920                                 ut_params->ibuf);
12921
12922                 memset(sym_op->aead.aad.data, 0, aad_len);
12923                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12924
12925                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12926                 debug_hexdump(stdout, "aad:",
12927                                 sym_op->aead.aad.data, aad_len);
12928         }
12929
12930         sym_op->aead.data.length = tdata->plaintext.len;
12931         sym_op->aead.data.offset = aad_len_pad;
12932
12933         return 0;
12934 }
12935
12936 #define SGL_MAX_NO      16
12937
12938 static int
12939 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
12940                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
12941 {
12942         struct crypto_testsuite_params *ts_params = &testsuite_params;
12943         struct crypto_unittest_params *ut_params = &unittest_params;
12944         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
12945         int retval;
12946         int to_trn = 0;
12947         int to_trn_tbl[SGL_MAX_NO];
12948         int segs = 1;
12949         unsigned int trn_data = 0;
12950         uint8_t *plaintext, *ciphertext, *auth_tag;
12951         struct rte_cryptodev_info dev_info;
12952
12953         /* Verify the capabilities */
12954         struct rte_cryptodev_sym_capability_idx cap_idx;
12955         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
12956         cap_idx.algo.aead = tdata->algo;
12957         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12958                         &cap_idx) == NULL)
12959                 return TEST_SKIPPED;
12960
12961         /* OOP not supported with CPU crypto */
12962         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12963                 return TEST_SKIPPED;
12964
12965         /* Detailed check for the particular SGL support flag */
12966         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12967         if (!oop) {
12968                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
12969                 if (sgl_in && (!(dev_info.feature_flags &
12970                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
12971                         return TEST_SKIPPED;
12972
12973                 uint64_t feat_flags = dev_info.feature_flags;
12974
12975                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12976                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12977                         printf("Device doesn't support RAW data-path APIs.\n");
12978                         return TEST_SKIPPED;
12979                 }
12980         } else {
12981                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
12982                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
12983                                 tdata->plaintext.len;
12984                 /* Raw data path API does not support OOP */
12985                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12986                         return TEST_SKIPPED;
12987                 if (sgl_in && !sgl_out) {
12988                         if (!(dev_info.feature_flags &
12989                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
12990                                 return TEST_SKIPPED;
12991                 } else if (!sgl_in && sgl_out) {
12992                         if (!(dev_info.feature_flags &
12993                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
12994                                 return TEST_SKIPPED;
12995                 } else if (sgl_in && sgl_out) {
12996                         if (!(dev_info.feature_flags &
12997                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
12998                                 return TEST_SKIPPED;
12999                 }
13000         }
13001
13002         if (fragsz > tdata->plaintext.len)
13003                 fragsz = tdata->plaintext.len;
13004
13005         uint16_t plaintext_len = fragsz;
13006         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13007
13008         if (fragsz_oop > tdata->plaintext.len)
13009                 frag_size_oop = tdata->plaintext.len;
13010
13011         int ecx = 0;
13012         void *digest_mem = NULL;
13013
13014         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13015
13016         if (tdata->plaintext.len % fragsz != 0) {
13017                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13018                         return 1;
13019         }       else {
13020                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13021                         return 1;
13022         }
13023
13024         /*
13025          * For out-op-place we need to alloc another mbuf
13026          */
13027         if (oop) {
13028                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13029                 rte_pktmbuf_append(ut_params->obuf,
13030                                 frag_size_oop + prepend_len);
13031                 buf_oop = ut_params->obuf;
13032         }
13033
13034         /* Create AEAD session */
13035         retval = create_aead_session(ts_params->valid_devs[0],
13036                         tdata->algo,
13037                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
13038                         tdata->key.data, tdata->key.len,
13039                         tdata->aad.len, tdata->auth_tag.len,
13040                         tdata->iv.len);
13041         if (retval < 0)
13042                 return retval;
13043
13044         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13045
13046         /* clear mbuf payload */
13047         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13048                         rte_pktmbuf_tailroom(ut_params->ibuf));
13049
13050         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13051                         plaintext_len);
13052
13053         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13054
13055         trn_data += plaintext_len;
13056
13057         buf = ut_params->ibuf;
13058
13059         /*
13060          * Loop until no more fragments
13061          */
13062
13063         while (trn_data < tdata->plaintext.len) {
13064                 ++segs;
13065                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13066                                 (tdata->plaintext.len - trn_data) : fragsz;
13067
13068                 to_trn_tbl[ecx++] = to_trn;
13069
13070                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13071                 buf = buf->next;
13072
13073                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13074                                 rte_pktmbuf_tailroom(buf));
13075
13076                 /* OOP */
13077                 if (oop && !fragsz_oop) {
13078                         buf_last_oop = buf_oop->next =
13079                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13080                         buf_oop = buf_oop->next;
13081                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13082                                         0, rte_pktmbuf_tailroom(buf_oop));
13083                         rte_pktmbuf_append(buf_oop, to_trn);
13084                 }
13085
13086                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13087                                 to_trn);
13088
13089                 memcpy(plaintext, tdata->plaintext.data + trn_data,
13090                                 to_trn);
13091                 trn_data += to_trn;
13092                 if (trn_data  == tdata->plaintext.len) {
13093                         if (oop) {
13094                                 if (!fragsz_oop)
13095                                         digest_mem = rte_pktmbuf_append(buf_oop,
13096                                                 tdata->auth_tag.len);
13097                         } else
13098                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13099                                         tdata->auth_tag.len);
13100                 }
13101         }
13102
13103         uint64_t digest_phys = 0;
13104
13105         ut_params->ibuf->nb_segs = segs;
13106
13107         segs = 1;
13108         if (fragsz_oop && oop) {
13109                 to_trn = 0;
13110                 ecx = 0;
13111
13112                 if (frag_size_oop == tdata->plaintext.len) {
13113                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
13114                                 tdata->auth_tag.len);
13115
13116                         digest_phys = rte_pktmbuf_iova_offset(
13117                                         ut_params->obuf,
13118                                         tdata->plaintext.len + prepend_len);
13119                 }
13120
13121                 trn_data = frag_size_oop;
13122                 while (trn_data < tdata->plaintext.len) {
13123                         ++segs;
13124                         to_trn =
13125                                 (tdata->plaintext.len - trn_data <
13126                                                 frag_size_oop) ?
13127                                 (tdata->plaintext.len - trn_data) :
13128                                                 frag_size_oop;
13129
13130                         to_trn_tbl[ecx++] = to_trn;
13131
13132                         buf_last_oop = buf_oop->next =
13133                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13134                         buf_oop = buf_oop->next;
13135                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13136                                         0, rte_pktmbuf_tailroom(buf_oop));
13137                         rte_pktmbuf_append(buf_oop, to_trn);
13138
13139                         trn_data += to_trn;
13140
13141                         if (trn_data  == tdata->plaintext.len) {
13142                                 digest_mem = rte_pktmbuf_append(buf_oop,
13143                                         tdata->auth_tag.len);
13144                         }
13145                 }
13146
13147                 ut_params->obuf->nb_segs = segs;
13148         }
13149
13150         /*
13151          * Place digest at the end of the last buffer
13152          */
13153         if (!digest_phys)
13154                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13155         if (oop && buf_last_oop)
13156                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13157
13158         if (!digest_mem && !oop) {
13159                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13160                                 + tdata->auth_tag.len);
13161                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13162                                 tdata->plaintext.len);
13163         }
13164
13165         /* Create AEAD operation */
13166         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13167                         tdata, digest_mem, digest_phys);
13168
13169         if (retval < 0)
13170                 return retval;
13171
13172         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13173
13174         ut_params->op->sym->m_src = ut_params->ibuf;
13175         if (oop)
13176                 ut_params->op->sym->m_dst = ut_params->obuf;
13177
13178         /* Process crypto operation */
13179         if (oop == IN_PLACE &&
13180                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13181                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13182         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13183                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13184                                 ut_params->op, 0, 0, 0, 0);
13185         else
13186                 TEST_ASSERT_NOT_NULL(
13187                         process_crypto_request(ts_params->valid_devs[0],
13188                         ut_params->op), "failed to process sym crypto op");
13189
13190         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13191                         "crypto op processing failed");
13192
13193
13194         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13195                         uint8_t *, prepend_len);
13196         if (oop) {
13197                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13198                                 uint8_t *, prepend_len);
13199         }
13200
13201         if (fragsz_oop)
13202                 fragsz = fragsz_oop;
13203
13204         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13205                         ciphertext,
13206                         tdata->ciphertext.data,
13207                         fragsz,
13208                         "Ciphertext data not as expected");
13209
13210         buf = ut_params->op->sym->m_src->next;
13211         if (oop)
13212                 buf = ut_params->op->sym->m_dst->next;
13213
13214         unsigned int off = fragsz;
13215
13216         ecx = 0;
13217         while (buf) {
13218                 ciphertext = rte_pktmbuf_mtod(buf,
13219                                 uint8_t *);
13220
13221                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
13222                                 ciphertext,
13223                                 tdata->ciphertext.data + off,
13224                                 to_trn_tbl[ecx],
13225                                 "Ciphertext data not as expected");
13226
13227                 off += to_trn_tbl[ecx++];
13228                 buf = buf->next;
13229         }
13230
13231         auth_tag = digest_mem;
13232         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13233                         auth_tag,
13234                         tdata->auth_tag.data,
13235                         tdata->auth_tag.len,
13236                         "Generated auth tag not as expected");
13237
13238         return 0;
13239 }
13240
13241 static int
13242 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13243 {
13244         return test_authenticated_encryption_SGL(
13245                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13246 }
13247
13248 static int
13249 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13250 {
13251         return test_authenticated_encryption_SGL(
13252                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13253 }
13254
13255 static int
13256 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13257 {
13258         return test_authenticated_encryption_SGL(
13259                         &gcm_test_case_8, OUT_OF_PLACE, 400,
13260                         gcm_test_case_8.plaintext.len);
13261 }
13262
13263 static int
13264 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13265 {
13266         /* This test is not for OPENSSL PMD */
13267         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13268                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13269                 return TEST_SKIPPED;
13270
13271         return test_authenticated_encryption_SGL(
13272                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13273 }
13274
13275 static int
13276 test_authentication_verify_fail_when_data_corrupted(
13277                 struct crypto_testsuite_params *ts_params,
13278                 struct crypto_unittest_params *ut_params,
13279                 const struct test_crypto_vector *reference)
13280 {
13281         return test_authentication_verify_fail_when_data_corruption(
13282                         ts_params, ut_params, reference, 1);
13283 }
13284
13285 static int
13286 test_authentication_verify_fail_when_tag_corrupted(
13287                 struct crypto_testsuite_params *ts_params,
13288                 struct crypto_unittest_params *ut_params,
13289                 const struct test_crypto_vector *reference)
13290 {
13291         return test_authentication_verify_fail_when_data_corruption(
13292                         ts_params, ut_params, reference, 0);
13293 }
13294
13295 static int
13296 test_authentication_verify_GMAC_fail_when_data_corrupted(
13297                 struct crypto_testsuite_params *ts_params,
13298                 struct crypto_unittest_params *ut_params,
13299                 const struct test_crypto_vector *reference)
13300 {
13301         return test_authentication_verify_GMAC_fail_when_corruption(
13302                         ts_params, ut_params, reference, 1);
13303 }
13304
13305 static int
13306 test_authentication_verify_GMAC_fail_when_tag_corrupted(
13307                 struct crypto_testsuite_params *ts_params,
13308                 struct crypto_unittest_params *ut_params,
13309                 const struct test_crypto_vector *reference)
13310 {
13311         return test_authentication_verify_GMAC_fail_when_corruption(
13312                         ts_params, ut_params, reference, 0);
13313 }
13314
13315 static int
13316 test_authenticated_decryption_fail_when_data_corrupted(
13317                 struct crypto_testsuite_params *ts_params,
13318                 struct crypto_unittest_params *ut_params,
13319                 const struct test_crypto_vector *reference)
13320 {
13321         return test_authenticated_decryption_fail_when_corruption(
13322                         ts_params, ut_params, reference, 1);
13323 }
13324
13325 static int
13326 test_authenticated_decryption_fail_when_tag_corrupted(
13327                 struct crypto_testsuite_params *ts_params,
13328                 struct crypto_unittest_params *ut_params,
13329                 const struct test_crypto_vector *reference)
13330 {
13331         return test_authenticated_decryption_fail_when_corruption(
13332                         ts_params, ut_params, reference, 0);
13333 }
13334
13335 static int
13336 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
13337 {
13338         return test_authentication_verify_fail_when_data_corrupted(
13339                         &testsuite_params, &unittest_params,
13340                         &hmac_sha1_test_crypto_vector);
13341 }
13342
13343 static int
13344 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13345 {
13346         return test_authentication_verify_fail_when_tag_corrupted(
13347                         &testsuite_params, &unittest_params,
13348                         &hmac_sha1_test_crypto_vector);
13349 }
13350
13351 static int
13352 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
13353 {
13354         return test_authentication_verify_GMAC_fail_when_data_corrupted(
13355                         &testsuite_params, &unittest_params,
13356                         &aes128_gmac_test_vector);
13357 }
13358
13359 static int
13360 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
13361 {
13362         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
13363                         &testsuite_params, &unittest_params,
13364                         &aes128_gmac_test_vector);
13365 }
13366
13367 static int
13368 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
13369 {
13370         return test_authenticated_decryption_fail_when_data_corrupted(
13371                         &testsuite_params,
13372                         &unittest_params,
13373                         &aes128cbc_hmac_sha1_test_vector);
13374 }
13375
13376 static int
13377 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
13378 {
13379         return test_authenticated_decryption_fail_when_tag_corrupted(
13380                         &testsuite_params,
13381                         &unittest_params,
13382                         &aes128cbc_hmac_sha1_test_vector);
13383 }
13384
13385 static int
13386 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13387 {
13388         return test_authenticated_encrypt_with_esn(
13389                         &testsuite_params,
13390                         &unittest_params,
13391                         &aes128cbc_hmac_sha1_aad_test_vector);
13392 }
13393
13394 static int
13395 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13396 {
13397         return test_authenticated_decrypt_with_esn(
13398                         &testsuite_params,
13399                         &unittest_params,
13400                         &aes128cbc_hmac_sha1_aad_test_vector);
13401 }
13402
13403 static int
13404 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
13405 {
13406         return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
13407 }
13408
13409 static int
13410 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
13411 {
13412         return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
13413 }
13414
13415 #ifdef RTE_CRYPTO_SCHEDULER
13416
13417 /* global AESNI worker IDs for the scheduler test */
13418 uint8_t aesni_ids[2];
13419
13420 static int
13421 scheduler_testsuite_setup(void)
13422 {
13423         uint32_t i = 0;
13424         int32_t nb_devs, ret;
13425         char vdev_args[VDEV_ARGS_SIZE] = {""};
13426         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
13427                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
13428         uint16_t worker_core_count = 0;
13429         uint16_t socket_id = 0;
13430
13431         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13432                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
13433
13434                 /* Identify the Worker Cores
13435                  * Use 2 worker cores for the device args
13436                  */
13437                 RTE_LCORE_FOREACH_WORKER(i) {
13438                         if (worker_core_count > 1)
13439                                 break;
13440                         snprintf(vdev_args, sizeof(vdev_args),
13441                                         "%s%d", temp_str, i);
13442                         strcpy(temp_str, vdev_args);
13443                         strlcat(temp_str, ";", sizeof(temp_str));
13444                         worker_core_count++;
13445                         socket_id = rte_lcore_to_socket_id(i);
13446                 }
13447                 if (worker_core_count != 2) {
13448                         RTE_LOG(ERR, USER1,
13449                                 "Cryptodev scheduler test require at least "
13450                                 "two worker cores to run. "
13451                                 "Please use the correct coremask.\n");
13452                         return TEST_FAILED;
13453                 }
13454                 strcpy(temp_str, vdev_args);
13455                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
13456                                 temp_str, socket_id);
13457                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
13458                 nb_devs = rte_cryptodev_device_count_by_driver(
13459                                 rte_cryptodev_driver_id_get(
13460                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
13461                 if (nb_devs < 1) {
13462                         ret = rte_vdev_init(
13463                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
13464                                         vdev_args);
13465                         TEST_ASSERT(ret == 0,
13466                                 "Failed to create instance %u of pmd : %s",
13467                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13468                 }
13469         }
13470         return testsuite_setup();
13471 }
13472
13473 static int
13474 test_scheduler_attach_worker_op(void)
13475 {
13476         struct crypto_testsuite_params *ts_params = &testsuite_params;
13477         uint8_t sched_id = ts_params->valid_devs[0];
13478         uint32_t i, nb_devs_attached = 0;
13479         int ret;
13480         char vdev_name[32];
13481         unsigned int count = rte_cryptodev_count();
13482
13483         /* create 2 AESNI_MB vdevs on top of existing devices */
13484         for (i = count; i < count + 2; i++) {
13485                 snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
13486                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
13487                                 i);
13488                 ret = rte_vdev_init(vdev_name, NULL);
13489
13490                 TEST_ASSERT(ret == 0,
13491                         "Failed to create instance %u of"
13492                         " pmd : %s",
13493                         i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13494
13495                 if (ret < 0) {
13496                         RTE_LOG(ERR, USER1,
13497                                 "Failed to create 2 AESNI MB PMDs.\n");
13498                         return TEST_SKIPPED;
13499                 }
13500         }
13501
13502         /* attach 2 AESNI_MB cdevs */
13503         for (i = count; i < count + 2; i++) {
13504                 struct rte_cryptodev_info info;
13505                 unsigned int session_size;
13506
13507                 rte_cryptodev_info_get(i, &info);
13508                 if (info.driver_id != rte_cryptodev_driver_id_get(
13509                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
13510                         continue;
13511
13512                 session_size = rte_cryptodev_sym_get_private_session_size(i);
13513                 /*
13514                  * Create the session mempool again, since now there are new devices
13515                  * to use the mempool.
13516                  */
13517                 if (ts_params->session_mpool) {
13518                         rte_mempool_free(ts_params->session_mpool);
13519                         ts_params->session_mpool = NULL;
13520                 }
13521                 if (ts_params->session_priv_mpool) {
13522                         rte_mempool_free(ts_params->session_priv_mpool);
13523                         ts_params->session_priv_mpool = NULL;
13524                 }
13525
13526                 if (info.sym.max_nb_sessions != 0 &&
13527                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
13528                         RTE_LOG(ERR, USER1,
13529                                         "Device does not support "
13530                                         "at least %u sessions\n",
13531                                         MAX_NB_SESSIONS);
13532                         return TEST_FAILED;
13533                 }
13534                 /*
13535                  * Create mempool with maximum number of sessions,
13536                  * to include the session headers
13537                  */
13538                 if (ts_params->session_mpool == NULL) {
13539                         ts_params->session_mpool =
13540                                 rte_cryptodev_sym_session_pool_create(
13541                                                 "test_sess_mp",
13542                                                 MAX_NB_SESSIONS, 0, 0, 0,
13543                                                 SOCKET_ID_ANY);
13544                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
13545                                         "session mempool allocation failed");
13546                 }
13547
13548                 /*
13549                  * Create mempool with maximum number of sessions,
13550                  * to include device specific session private data
13551                  */
13552                 if (ts_params->session_priv_mpool == NULL) {
13553                         ts_params->session_priv_mpool = rte_mempool_create(
13554                                         "test_sess_mp_priv",
13555                                         MAX_NB_SESSIONS,
13556                                         session_size,
13557                                         0, 0, NULL, NULL, NULL,
13558                                         NULL, SOCKET_ID_ANY,
13559                                         0);
13560
13561                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
13562                                         "session mempool allocation failed");
13563                 }
13564
13565                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
13566                 ts_params->qp_conf.mp_session_private =
13567                                 ts_params->session_priv_mpool;
13568
13569                 ret = rte_cryptodev_scheduler_worker_attach(sched_id,
13570                                 (uint8_t)i);
13571
13572                 TEST_ASSERT(ret == 0,
13573                         "Failed to attach device %u of pmd : %s", i,
13574                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13575
13576                 aesni_ids[nb_devs_attached] = (uint8_t)i;
13577
13578                 nb_devs_attached++;
13579         }
13580
13581         return 0;
13582 }
13583
13584 static int
13585 test_scheduler_detach_worker_op(void)
13586 {
13587         struct crypto_testsuite_params *ts_params = &testsuite_params;
13588         uint8_t sched_id = ts_params->valid_devs[0];
13589         uint32_t i;
13590         int ret;
13591
13592         for (i = 0; i < 2; i++) {
13593                 ret = rte_cryptodev_scheduler_worker_detach(sched_id,
13594                                 aesni_ids[i]);
13595                 TEST_ASSERT(ret == 0,
13596                         "Failed to detach device %u", aesni_ids[i]);
13597         }
13598
13599         return 0;
13600 }
13601
13602 static int
13603 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
13604 {
13605         struct crypto_testsuite_params *ts_params = &testsuite_params;
13606         uint8_t sched_id = ts_params->valid_devs[0];
13607         /* set mode */
13608         return rte_cryptodev_scheduler_mode_set(sched_id,
13609                 scheduler_mode);
13610 }
13611
13612 static int
13613 test_scheduler_mode_roundrobin_op(void)
13614 {
13615         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
13616                         0, "Failed to set roundrobin mode");
13617         return 0;
13618
13619 }
13620
13621 static int
13622 test_scheduler_mode_multicore_op(void)
13623 {
13624         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
13625                         0, "Failed to set multicore mode");
13626
13627         return 0;
13628 }
13629
13630 static int
13631 test_scheduler_mode_failover_op(void)
13632 {
13633         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
13634                         0, "Failed to set failover mode");
13635
13636         return 0;
13637 }
13638
13639 static int
13640 test_scheduler_mode_pkt_size_distr_op(void)
13641 {
13642         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
13643                         0, "Failed to set pktsize mode");
13644
13645         return 0;
13646 }
13647
13648 static int
13649 scheduler_multicore_testsuite_setup(void)
13650 {
13651         if (test_scheduler_attach_worker_op() < 0)
13652                 return TEST_SKIPPED;
13653         if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
13654                 return TEST_SKIPPED;
13655         return 0;
13656 }
13657
13658 static int
13659 scheduler_roundrobin_testsuite_setup(void)
13660 {
13661         if (test_scheduler_attach_worker_op() < 0)
13662                 return TEST_SKIPPED;
13663         if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
13664                 return TEST_SKIPPED;
13665         return 0;
13666 }
13667
13668 static int
13669 scheduler_failover_testsuite_setup(void)
13670 {
13671         if (test_scheduler_attach_worker_op() < 0)
13672                 return TEST_SKIPPED;
13673         if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
13674                 return TEST_SKIPPED;
13675         return 0;
13676 }
13677
13678 static int
13679 scheduler_pkt_size_distr_testsuite_setup(void)
13680 {
13681         if (test_scheduler_attach_worker_op() < 0)
13682                 return TEST_SKIPPED;
13683         if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
13684                 return TEST_SKIPPED;
13685         return 0;
13686 }
13687
13688 static void
13689 scheduler_mode_testsuite_teardown(void)
13690 {
13691         test_scheduler_detach_worker_op();
13692 }
13693
13694 #endif /* RTE_CRYPTO_SCHEDULER */
13695
13696 static struct unit_test_suite end_testsuite = {
13697         .suite_name = NULL,
13698         .setup = NULL,
13699         .teardown = NULL,
13700         .unit_test_suites = NULL
13701 };
13702
13703 #ifdef RTE_LIB_SECURITY
13704 static struct unit_test_suite pdcp_proto_testsuite  = {
13705         .suite_name = "PDCP Proto Unit Test Suite",
13706         .setup = pdcp_proto_testsuite_setup,
13707         .unit_test_cases = {
13708                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13709                         test_PDCP_PROTO_all),
13710                 TEST_CASES_END() /**< NULL terminate unit test array */
13711         }
13712 };
13713
13714 static struct unit_test_suite docsis_proto_testsuite  = {
13715         .suite_name = "Docsis Proto Unit Test Suite",
13716         .setup = docsis_proto_testsuite_setup,
13717         .unit_test_cases = {
13718                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13719                         test_DOCSIS_PROTO_all),
13720                 TEST_CASES_END() /**< NULL terminate unit test array */
13721         }
13722 };
13723 #endif
13724
13725 static struct unit_test_suite cryptodev_gen_testsuite  = {
13726         .suite_name = "Crypto General Unit Test Suite",
13727         .setup = crypto_gen_testsuite_setup,
13728         .unit_test_cases = {
13729                 TEST_CASE_ST(ut_setup, ut_teardown,
13730                                 test_device_configure_invalid_dev_id),
13731                 TEST_CASE_ST(ut_setup, ut_teardown,
13732                                 test_queue_pair_descriptor_setup),
13733                 TEST_CASE_ST(ut_setup, ut_teardown,
13734                                 test_device_configure_invalid_queue_pair_ids),
13735                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
13736                 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
13737                 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
13738                 TEST_CASES_END() /**< NULL terminate unit test array */
13739         }
13740 };
13741
13742 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
13743         .suite_name = "Negative HMAC SHA1 Unit Test Suite",
13744         .setup = negative_hmac_sha1_testsuite_setup,
13745         .unit_test_cases = {
13746                 /** Negative tests */
13747                 TEST_CASE_ST(ut_setup, ut_teardown,
13748                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13749                 TEST_CASE_ST(ut_setup, ut_teardown,
13750                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13751                 TEST_CASE_ST(ut_setup, ut_teardown,
13752                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13753                 TEST_CASE_ST(ut_setup, ut_teardown,
13754                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13755
13756                 TEST_CASES_END() /**< NULL terminate unit test array */
13757         }
13758 };
13759
13760 static struct unit_test_suite cryptodev_multi_session_testsuite = {
13761         .suite_name = "Multi Session Unit Test Suite",
13762         .setup = multi_session_testsuite_setup,
13763         .unit_test_cases = {
13764                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13765                 TEST_CASE_ST(ut_setup, ut_teardown,
13766                                 test_multi_session_random_usage),
13767
13768                 TEST_CASES_END() /**< NULL terminate unit test array */
13769         }
13770 };
13771
13772 static struct unit_test_suite cryptodev_null_testsuite  = {
13773         .suite_name = "NULL Test Suite",
13774         .setup = null_testsuite_setup,
13775         .unit_test_cases = {
13776                 TEST_CASE_ST(ut_setup, ut_teardown,
13777                         test_null_invalid_operation),
13778                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
13779                 TEST_CASES_END()
13780         }
13781 };
13782
13783 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
13784         .suite_name = "AES CCM Authenticated Test Suite",
13785         .setup = aes_ccm_auth_testsuite_setup,
13786         .unit_test_cases = {
13787                 /** AES CCM Authenticated Encryption 128 bits key*/
13788                 TEST_CASE_ST(ut_setup, ut_teardown,
13789                         test_AES_CCM_authenticated_encryption_test_case_128_1),
13790                 TEST_CASE_ST(ut_setup, ut_teardown,
13791                         test_AES_CCM_authenticated_encryption_test_case_128_2),
13792                 TEST_CASE_ST(ut_setup, ut_teardown,
13793                         test_AES_CCM_authenticated_encryption_test_case_128_3),
13794
13795                 /** AES CCM Authenticated Decryption 128 bits key*/
13796                 TEST_CASE_ST(ut_setup, ut_teardown,
13797                         test_AES_CCM_authenticated_decryption_test_case_128_1),
13798                 TEST_CASE_ST(ut_setup, ut_teardown,
13799                         test_AES_CCM_authenticated_decryption_test_case_128_2),
13800                 TEST_CASE_ST(ut_setup, ut_teardown,
13801                         test_AES_CCM_authenticated_decryption_test_case_128_3),
13802
13803                 /** AES CCM Authenticated Encryption 192 bits key */
13804                 TEST_CASE_ST(ut_setup, ut_teardown,
13805                         test_AES_CCM_authenticated_encryption_test_case_192_1),
13806                 TEST_CASE_ST(ut_setup, ut_teardown,
13807                         test_AES_CCM_authenticated_encryption_test_case_192_2),
13808                 TEST_CASE_ST(ut_setup, ut_teardown,
13809                         test_AES_CCM_authenticated_encryption_test_case_192_3),
13810
13811                 /** AES CCM Authenticated Decryption 192 bits key*/
13812                 TEST_CASE_ST(ut_setup, ut_teardown,
13813                         test_AES_CCM_authenticated_decryption_test_case_192_1),
13814                 TEST_CASE_ST(ut_setup, ut_teardown,
13815                         test_AES_CCM_authenticated_decryption_test_case_192_2),
13816                 TEST_CASE_ST(ut_setup, ut_teardown,
13817                         test_AES_CCM_authenticated_decryption_test_case_192_3),
13818
13819                 /** AES CCM Authenticated Encryption 256 bits key */
13820                 TEST_CASE_ST(ut_setup, ut_teardown,
13821                         test_AES_CCM_authenticated_encryption_test_case_256_1),
13822                 TEST_CASE_ST(ut_setup, ut_teardown,
13823                         test_AES_CCM_authenticated_encryption_test_case_256_2),
13824                 TEST_CASE_ST(ut_setup, ut_teardown,
13825                         test_AES_CCM_authenticated_encryption_test_case_256_3),
13826
13827                 /** AES CCM Authenticated Decryption 256 bits key*/
13828                 TEST_CASE_ST(ut_setup, ut_teardown,
13829                         test_AES_CCM_authenticated_decryption_test_case_256_1),
13830                 TEST_CASE_ST(ut_setup, ut_teardown,
13831                         test_AES_CCM_authenticated_decryption_test_case_256_2),
13832                 TEST_CASE_ST(ut_setup, ut_teardown,
13833                         test_AES_CCM_authenticated_decryption_test_case_256_3),
13834                 TEST_CASES_END()
13835         }
13836 };
13837
13838 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
13839         .suite_name = "AES GCM Authenticated Test Suite",
13840         .setup = aes_gcm_auth_testsuite_setup,
13841         .unit_test_cases = {
13842                 /** AES GCM Authenticated Encryption */
13843                 TEST_CASE_ST(ut_setup, ut_teardown,
13844                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
13845                 TEST_CASE_ST(ut_setup, ut_teardown,
13846                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
13847                 TEST_CASE_ST(ut_setup, ut_teardown,
13848                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
13849                 TEST_CASE_ST(ut_setup, ut_teardown,
13850                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
13851                 TEST_CASE_ST(ut_setup, ut_teardown,
13852                         test_AES_GCM_authenticated_encryption_test_case_1),
13853                 TEST_CASE_ST(ut_setup, ut_teardown,
13854                         test_AES_GCM_authenticated_encryption_test_case_2),
13855                 TEST_CASE_ST(ut_setup, ut_teardown,
13856                         test_AES_GCM_authenticated_encryption_test_case_3),
13857                 TEST_CASE_ST(ut_setup, ut_teardown,
13858                         test_AES_GCM_authenticated_encryption_test_case_4),
13859                 TEST_CASE_ST(ut_setup, ut_teardown,
13860                         test_AES_GCM_authenticated_encryption_test_case_5),
13861                 TEST_CASE_ST(ut_setup, ut_teardown,
13862                         test_AES_GCM_authenticated_encryption_test_case_6),
13863                 TEST_CASE_ST(ut_setup, ut_teardown,
13864                         test_AES_GCM_authenticated_encryption_test_case_7),
13865                 TEST_CASE_ST(ut_setup, ut_teardown,
13866                         test_AES_GCM_authenticated_encryption_test_case_8),
13867                 TEST_CASE_ST(ut_setup, ut_teardown,
13868                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
13869
13870                 /** AES GCM Authenticated Decryption */
13871                 TEST_CASE_ST(ut_setup, ut_teardown,
13872                         test_AES_GCM_authenticated_decryption_test_case_1),
13873                 TEST_CASE_ST(ut_setup, ut_teardown,
13874                         test_AES_GCM_authenticated_decryption_test_case_2),
13875                 TEST_CASE_ST(ut_setup, ut_teardown,
13876                         test_AES_GCM_authenticated_decryption_test_case_3),
13877                 TEST_CASE_ST(ut_setup, ut_teardown,
13878                         test_AES_GCM_authenticated_decryption_test_case_4),
13879                 TEST_CASE_ST(ut_setup, ut_teardown,
13880                         test_AES_GCM_authenticated_decryption_test_case_5),
13881                 TEST_CASE_ST(ut_setup, ut_teardown,
13882                         test_AES_GCM_authenticated_decryption_test_case_6),
13883                 TEST_CASE_ST(ut_setup, ut_teardown,
13884                         test_AES_GCM_authenticated_decryption_test_case_7),
13885                 TEST_CASE_ST(ut_setup, ut_teardown,
13886                         test_AES_GCM_authenticated_decryption_test_case_8),
13887                 TEST_CASE_ST(ut_setup, ut_teardown,
13888                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
13889
13890                 /** AES GCM Authenticated Encryption 192 bits key */
13891                 TEST_CASE_ST(ut_setup, ut_teardown,
13892                         test_AES_GCM_auth_encryption_test_case_192_1),
13893                 TEST_CASE_ST(ut_setup, ut_teardown,
13894                         test_AES_GCM_auth_encryption_test_case_192_2),
13895                 TEST_CASE_ST(ut_setup, ut_teardown,
13896                         test_AES_GCM_auth_encryption_test_case_192_3),
13897                 TEST_CASE_ST(ut_setup, ut_teardown,
13898                         test_AES_GCM_auth_encryption_test_case_192_4),
13899                 TEST_CASE_ST(ut_setup, ut_teardown,
13900                         test_AES_GCM_auth_encryption_test_case_192_5),
13901                 TEST_CASE_ST(ut_setup, ut_teardown,
13902                         test_AES_GCM_auth_encryption_test_case_192_6),
13903                 TEST_CASE_ST(ut_setup, ut_teardown,
13904                         test_AES_GCM_auth_encryption_test_case_192_7),
13905
13906                 /** AES GCM Authenticated Decryption 192 bits key */
13907                 TEST_CASE_ST(ut_setup, ut_teardown,
13908                         test_AES_GCM_auth_decryption_test_case_192_1),
13909                 TEST_CASE_ST(ut_setup, ut_teardown,
13910                         test_AES_GCM_auth_decryption_test_case_192_2),
13911                 TEST_CASE_ST(ut_setup, ut_teardown,
13912                         test_AES_GCM_auth_decryption_test_case_192_3),
13913                 TEST_CASE_ST(ut_setup, ut_teardown,
13914                         test_AES_GCM_auth_decryption_test_case_192_4),
13915                 TEST_CASE_ST(ut_setup, ut_teardown,
13916                         test_AES_GCM_auth_decryption_test_case_192_5),
13917                 TEST_CASE_ST(ut_setup, ut_teardown,
13918                         test_AES_GCM_auth_decryption_test_case_192_6),
13919                 TEST_CASE_ST(ut_setup, ut_teardown,
13920                         test_AES_GCM_auth_decryption_test_case_192_7),
13921
13922                 /** AES GCM Authenticated Encryption 256 bits key */
13923                 TEST_CASE_ST(ut_setup, ut_teardown,
13924                         test_AES_GCM_auth_encryption_test_case_256_1),
13925                 TEST_CASE_ST(ut_setup, ut_teardown,
13926                         test_AES_GCM_auth_encryption_test_case_256_2),
13927                 TEST_CASE_ST(ut_setup, ut_teardown,
13928                         test_AES_GCM_auth_encryption_test_case_256_3),
13929                 TEST_CASE_ST(ut_setup, ut_teardown,
13930                         test_AES_GCM_auth_encryption_test_case_256_4),
13931                 TEST_CASE_ST(ut_setup, ut_teardown,
13932                         test_AES_GCM_auth_encryption_test_case_256_5),
13933                 TEST_CASE_ST(ut_setup, ut_teardown,
13934                         test_AES_GCM_auth_encryption_test_case_256_6),
13935                 TEST_CASE_ST(ut_setup, ut_teardown,
13936                         test_AES_GCM_auth_encryption_test_case_256_7),
13937
13938                 /** AES GCM Authenticated Decryption 256 bits key */
13939                 TEST_CASE_ST(ut_setup, ut_teardown,
13940                         test_AES_GCM_auth_decryption_test_case_256_1),
13941                 TEST_CASE_ST(ut_setup, ut_teardown,
13942                         test_AES_GCM_auth_decryption_test_case_256_2),
13943                 TEST_CASE_ST(ut_setup, ut_teardown,
13944                         test_AES_GCM_auth_decryption_test_case_256_3),
13945                 TEST_CASE_ST(ut_setup, ut_teardown,
13946                         test_AES_GCM_auth_decryption_test_case_256_4),
13947                 TEST_CASE_ST(ut_setup, ut_teardown,
13948                         test_AES_GCM_auth_decryption_test_case_256_5),
13949                 TEST_CASE_ST(ut_setup, ut_teardown,
13950                         test_AES_GCM_auth_decryption_test_case_256_6),
13951                 TEST_CASE_ST(ut_setup, ut_teardown,
13952                         test_AES_GCM_auth_decryption_test_case_256_7),
13953
13954                 /** AES GCM Authenticated Encryption big aad size */
13955                 TEST_CASE_ST(ut_setup, ut_teardown,
13956                         test_AES_GCM_auth_encryption_test_case_aad_1),
13957                 TEST_CASE_ST(ut_setup, ut_teardown,
13958                         test_AES_GCM_auth_encryption_test_case_aad_2),
13959
13960                 /** AES GCM Authenticated Decryption big aad size */
13961                 TEST_CASE_ST(ut_setup, ut_teardown,
13962                         test_AES_GCM_auth_decryption_test_case_aad_1),
13963                 TEST_CASE_ST(ut_setup, ut_teardown,
13964                         test_AES_GCM_auth_decryption_test_case_aad_2),
13965
13966                 /** Out of place tests */
13967                 TEST_CASE_ST(ut_setup, ut_teardown,
13968                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
13969                 TEST_CASE_ST(ut_setup, ut_teardown,
13970                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
13971
13972                 /** Session-less tests */
13973                 TEST_CASE_ST(ut_setup, ut_teardown,
13974                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
13975                 TEST_CASE_ST(ut_setup, ut_teardown,
13976                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
13977
13978                 TEST_CASES_END()
13979         }
13980 };
13981
13982 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
13983         .suite_name = "AES GMAC Authentication Test Suite",
13984         .setup = aes_gmac_auth_testsuite_setup,
13985         .unit_test_cases = {
13986                 TEST_CASE_ST(ut_setup, ut_teardown,
13987                         test_AES_GMAC_authentication_test_case_1),
13988                 TEST_CASE_ST(ut_setup, ut_teardown,
13989                         test_AES_GMAC_authentication_verify_test_case_1),
13990                 TEST_CASE_ST(ut_setup, ut_teardown,
13991                         test_AES_GMAC_authentication_test_case_2),
13992                 TEST_CASE_ST(ut_setup, ut_teardown,
13993                         test_AES_GMAC_authentication_verify_test_case_2),
13994                 TEST_CASE_ST(ut_setup, ut_teardown,
13995                         test_AES_GMAC_authentication_test_case_3),
13996                 TEST_CASE_ST(ut_setup, ut_teardown,
13997                         test_AES_GMAC_authentication_verify_test_case_3),
13998                 TEST_CASE_ST(ut_setup, ut_teardown,
13999                         test_AES_GMAC_authentication_test_case_4),
14000                 TEST_CASE_ST(ut_setup, ut_teardown,
14001                         test_AES_GMAC_authentication_verify_test_case_4),
14002                 TEST_CASE_ST(ut_setup, ut_teardown,
14003                         test_AES_GMAC_authentication_SGL_40B),
14004                 TEST_CASE_ST(ut_setup, ut_teardown,
14005                         test_AES_GMAC_authentication_SGL_80B),
14006                 TEST_CASE_ST(ut_setup, ut_teardown,
14007                         test_AES_GMAC_authentication_SGL_2048B),
14008                 TEST_CASE_ST(ut_setup, ut_teardown,
14009                         test_AES_GMAC_authentication_SGL_2047B),
14010
14011                 TEST_CASES_END()
14012         }
14013 };
14014
14015 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14016         .suite_name = "Chacha20-Poly1305 Test Suite",
14017         .setup = chacha20_poly1305_testsuite_setup,
14018         .unit_test_cases = {
14019                 TEST_CASE_ST(ut_setup, ut_teardown,
14020                         test_chacha20_poly1305_encrypt_test_case_rfc8439),
14021                 TEST_CASE_ST(ut_setup, ut_teardown,
14022                         test_chacha20_poly1305_decrypt_test_case_rfc8439),
14023                 TEST_CASES_END()
14024         }
14025 };
14026
14027 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14028         .suite_name = "SNOW 3G Test Suite",
14029         .setup = snow3g_testsuite_setup,
14030         .unit_test_cases = {
14031                 /** SNOW 3G encrypt only (UEA2) */
14032                 TEST_CASE_ST(ut_setup, ut_teardown,
14033                         test_snow3g_encryption_test_case_1),
14034                 TEST_CASE_ST(ut_setup, ut_teardown,
14035                         test_snow3g_encryption_test_case_2),
14036                 TEST_CASE_ST(ut_setup, ut_teardown,
14037                         test_snow3g_encryption_test_case_3),
14038                 TEST_CASE_ST(ut_setup, ut_teardown,
14039                         test_snow3g_encryption_test_case_4),
14040                 TEST_CASE_ST(ut_setup, ut_teardown,
14041                         test_snow3g_encryption_test_case_5),
14042
14043                 TEST_CASE_ST(ut_setup, ut_teardown,
14044                         test_snow3g_encryption_test_case_1_oop),
14045                 TEST_CASE_ST(ut_setup, ut_teardown,
14046                         test_snow3g_encryption_test_case_1_oop_sgl),
14047                 TEST_CASE_ST(ut_setup, ut_teardown,
14048                         test_snow3g_encryption_test_case_1_offset_oop),
14049                 TEST_CASE_ST(ut_setup, ut_teardown,
14050                         test_snow3g_decryption_test_case_1_oop),
14051
14052                 /** SNOW 3G generate auth, then encrypt (UEA2) */
14053                 TEST_CASE_ST(ut_setup, ut_teardown,
14054                         test_snow3g_auth_cipher_test_case_1),
14055                 TEST_CASE_ST(ut_setup, ut_teardown,
14056                         test_snow3g_auth_cipher_test_case_2),
14057                 TEST_CASE_ST(ut_setup, ut_teardown,
14058                         test_snow3g_auth_cipher_test_case_2_oop),
14059                 TEST_CASE_ST(ut_setup, ut_teardown,
14060                         test_snow3g_auth_cipher_part_digest_enc),
14061                 TEST_CASE_ST(ut_setup, ut_teardown,
14062                         test_snow3g_auth_cipher_part_digest_enc_oop),
14063                 TEST_CASE_ST(ut_setup, ut_teardown,
14064                         test_snow3g_auth_cipher_test_case_3_sgl),
14065                 TEST_CASE_ST(ut_setup, ut_teardown,
14066                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
14067                 TEST_CASE_ST(ut_setup, ut_teardown,
14068                         test_snow3g_auth_cipher_part_digest_enc_sgl),
14069                 TEST_CASE_ST(ut_setup, ut_teardown,
14070                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14071
14072                 /** SNOW 3G decrypt (UEA2), then verify auth */
14073                 TEST_CASE_ST(ut_setup, ut_teardown,
14074                         test_snow3g_auth_cipher_verify_test_case_1),
14075                 TEST_CASE_ST(ut_setup, ut_teardown,
14076                         test_snow3g_auth_cipher_verify_test_case_2),
14077                 TEST_CASE_ST(ut_setup, ut_teardown,
14078                         test_snow3g_auth_cipher_verify_test_case_2_oop),
14079                 TEST_CASE_ST(ut_setup, ut_teardown,
14080                         test_snow3g_auth_cipher_verify_part_digest_enc),
14081                 TEST_CASE_ST(ut_setup, ut_teardown,
14082                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14083                 TEST_CASE_ST(ut_setup, ut_teardown,
14084                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
14085                 TEST_CASE_ST(ut_setup, ut_teardown,
14086                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14087                 TEST_CASE_ST(ut_setup, ut_teardown,
14088                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14089                 TEST_CASE_ST(ut_setup, ut_teardown,
14090                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14091
14092                 /** SNOW 3G decrypt only (UEA2) */
14093                 TEST_CASE_ST(ut_setup, ut_teardown,
14094                         test_snow3g_decryption_test_case_1),
14095                 TEST_CASE_ST(ut_setup, ut_teardown,
14096                         test_snow3g_decryption_test_case_2),
14097                 TEST_CASE_ST(ut_setup, ut_teardown,
14098                         test_snow3g_decryption_test_case_3),
14099                 TEST_CASE_ST(ut_setup, ut_teardown,
14100                         test_snow3g_decryption_test_case_4),
14101                 TEST_CASE_ST(ut_setup, ut_teardown,
14102                         test_snow3g_decryption_test_case_5),
14103                 TEST_CASE_ST(ut_setup, ut_teardown,
14104                         test_snow3g_decryption_with_digest_test_case_1),
14105                 TEST_CASE_ST(ut_setup, ut_teardown,
14106                         test_snow3g_hash_generate_test_case_1),
14107                 TEST_CASE_ST(ut_setup, ut_teardown,
14108                         test_snow3g_hash_generate_test_case_2),
14109                 TEST_CASE_ST(ut_setup, ut_teardown,
14110                         test_snow3g_hash_generate_test_case_3),
14111
14112                 /* Tests with buffers which length is not byte-aligned */
14113                 TEST_CASE_ST(ut_setup, ut_teardown,
14114                         test_snow3g_hash_generate_test_case_4),
14115                 TEST_CASE_ST(ut_setup, ut_teardown,
14116                         test_snow3g_hash_generate_test_case_5),
14117                 TEST_CASE_ST(ut_setup, ut_teardown,
14118                         test_snow3g_hash_generate_test_case_6),
14119                 TEST_CASE_ST(ut_setup, ut_teardown,
14120                         test_snow3g_hash_verify_test_case_1),
14121                 TEST_CASE_ST(ut_setup, ut_teardown,
14122                         test_snow3g_hash_verify_test_case_2),
14123                 TEST_CASE_ST(ut_setup, ut_teardown,
14124                         test_snow3g_hash_verify_test_case_3),
14125
14126                 /* Tests with buffers which length is not byte-aligned */
14127                 TEST_CASE_ST(ut_setup, ut_teardown,
14128                         test_snow3g_hash_verify_test_case_4),
14129                 TEST_CASE_ST(ut_setup, ut_teardown,
14130                         test_snow3g_hash_verify_test_case_5),
14131                 TEST_CASE_ST(ut_setup, ut_teardown,
14132                         test_snow3g_hash_verify_test_case_6),
14133                 TEST_CASE_ST(ut_setup, ut_teardown,
14134                         test_snow3g_cipher_auth_test_case_1),
14135                 TEST_CASE_ST(ut_setup, ut_teardown,
14136                         test_snow3g_auth_cipher_with_digest_test_case_1),
14137                 TEST_CASES_END()
14138         }
14139 };
14140
14141 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14142         .suite_name = "ZUC Test Suite",
14143         .setup = zuc_testsuite_setup,
14144         .unit_test_cases = {
14145                 /** ZUC encrypt only (EEA3) */
14146                 TEST_CASE_ST(ut_setup, ut_teardown,
14147                         test_zuc_encryption_test_case_1),
14148                 TEST_CASE_ST(ut_setup, ut_teardown,
14149                         test_zuc_encryption_test_case_2),
14150                 TEST_CASE_ST(ut_setup, ut_teardown,
14151                         test_zuc_encryption_test_case_3),
14152                 TEST_CASE_ST(ut_setup, ut_teardown,
14153                         test_zuc_encryption_test_case_4),
14154                 TEST_CASE_ST(ut_setup, ut_teardown,
14155                         test_zuc_encryption_test_case_5),
14156                 TEST_CASE_ST(ut_setup, ut_teardown,
14157                         test_zuc_encryption_test_case_6_sgl),
14158
14159                 /** ZUC authenticate (EIA3) */
14160                 TEST_CASE_ST(ut_setup, ut_teardown,
14161                         test_zuc_hash_generate_test_case_1),
14162                 TEST_CASE_ST(ut_setup, ut_teardown,
14163                         test_zuc_hash_generate_test_case_2),
14164                 TEST_CASE_ST(ut_setup, ut_teardown,
14165                         test_zuc_hash_generate_test_case_3),
14166                 TEST_CASE_ST(ut_setup, ut_teardown,
14167                         test_zuc_hash_generate_test_case_4),
14168                 TEST_CASE_ST(ut_setup, ut_teardown,
14169                         test_zuc_hash_generate_test_case_5),
14170                 TEST_CASE_ST(ut_setup, ut_teardown,
14171                         test_zuc_hash_generate_test_case_6),
14172                 TEST_CASE_ST(ut_setup, ut_teardown,
14173                         test_zuc_hash_generate_test_case_7),
14174                 TEST_CASE_ST(ut_setup, ut_teardown,
14175                         test_zuc_hash_generate_test_case_8),
14176
14177                 /** ZUC alg-chain (EEA3/EIA3) */
14178                 TEST_CASE_ST(ut_setup, ut_teardown,
14179                         test_zuc_cipher_auth_test_case_1),
14180                 TEST_CASE_ST(ut_setup, ut_teardown,
14181                         test_zuc_cipher_auth_test_case_2),
14182
14183                 /** ZUC generate auth, then encrypt (EEA3) */
14184                 TEST_CASE_ST(ut_setup, ut_teardown,
14185                         test_zuc_auth_cipher_test_case_1),
14186                 TEST_CASE_ST(ut_setup, ut_teardown,
14187                         test_zuc_auth_cipher_test_case_1_oop),
14188                 TEST_CASE_ST(ut_setup, ut_teardown,
14189                         test_zuc_auth_cipher_test_case_1_sgl),
14190                 TEST_CASE_ST(ut_setup, ut_teardown,
14191                         test_zuc_auth_cipher_test_case_1_oop_sgl),
14192
14193                 /** ZUC decrypt (EEA3), then verify auth */
14194                 TEST_CASE_ST(ut_setup, ut_teardown,
14195                         test_zuc_auth_cipher_verify_test_case_1),
14196                 TEST_CASE_ST(ut_setup, ut_teardown,
14197                         test_zuc_auth_cipher_verify_test_case_1_oop),
14198                 TEST_CASE_ST(ut_setup, ut_teardown,
14199                         test_zuc_auth_cipher_verify_test_case_1_sgl),
14200                 TEST_CASE_ST(ut_setup, ut_teardown,
14201                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
14202                 TEST_CASES_END()
14203         }
14204 };
14205
14206 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
14207         .suite_name = "HMAC_MD5 Authentication Test Suite",
14208         .setup = hmac_md5_auth_testsuite_setup,
14209         .unit_test_cases = {
14210                 TEST_CASE_ST(ut_setup, ut_teardown,
14211                         test_MD5_HMAC_generate_case_1),
14212                 TEST_CASE_ST(ut_setup, ut_teardown,
14213                         test_MD5_HMAC_verify_case_1),
14214                 TEST_CASE_ST(ut_setup, ut_teardown,
14215                         test_MD5_HMAC_generate_case_2),
14216                 TEST_CASE_ST(ut_setup, ut_teardown,
14217                         test_MD5_HMAC_verify_case_2),
14218                 TEST_CASES_END()
14219         }
14220 };
14221
14222 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
14223         .suite_name = "Kasumi Test Suite",
14224         .setup = kasumi_testsuite_setup,
14225         .unit_test_cases = {
14226                 /** KASUMI hash only (UIA1) */
14227                 TEST_CASE_ST(ut_setup, ut_teardown,
14228                         test_kasumi_hash_generate_test_case_1),
14229                 TEST_CASE_ST(ut_setup, ut_teardown,
14230                         test_kasumi_hash_generate_test_case_2),
14231                 TEST_CASE_ST(ut_setup, ut_teardown,
14232                         test_kasumi_hash_generate_test_case_3),
14233                 TEST_CASE_ST(ut_setup, ut_teardown,
14234                         test_kasumi_hash_generate_test_case_4),
14235                 TEST_CASE_ST(ut_setup, ut_teardown,
14236                         test_kasumi_hash_generate_test_case_5),
14237                 TEST_CASE_ST(ut_setup, ut_teardown,
14238                         test_kasumi_hash_generate_test_case_6),
14239
14240                 TEST_CASE_ST(ut_setup, ut_teardown,
14241                         test_kasumi_hash_verify_test_case_1),
14242                 TEST_CASE_ST(ut_setup, ut_teardown,
14243                         test_kasumi_hash_verify_test_case_2),
14244                 TEST_CASE_ST(ut_setup, ut_teardown,
14245                         test_kasumi_hash_verify_test_case_3),
14246                 TEST_CASE_ST(ut_setup, ut_teardown,
14247                         test_kasumi_hash_verify_test_case_4),
14248                 TEST_CASE_ST(ut_setup, ut_teardown,
14249                         test_kasumi_hash_verify_test_case_5),
14250
14251                 /** KASUMI encrypt only (UEA1) */
14252                 TEST_CASE_ST(ut_setup, ut_teardown,
14253                         test_kasumi_encryption_test_case_1),
14254                 TEST_CASE_ST(ut_setup, ut_teardown,
14255                         test_kasumi_encryption_test_case_1_sgl),
14256                 TEST_CASE_ST(ut_setup, ut_teardown,
14257                         test_kasumi_encryption_test_case_1_oop),
14258                 TEST_CASE_ST(ut_setup, ut_teardown,
14259                         test_kasumi_encryption_test_case_1_oop_sgl),
14260                 TEST_CASE_ST(ut_setup, ut_teardown,
14261                         test_kasumi_encryption_test_case_2),
14262                 TEST_CASE_ST(ut_setup, ut_teardown,
14263                         test_kasumi_encryption_test_case_3),
14264                 TEST_CASE_ST(ut_setup, ut_teardown,
14265                         test_kasumi_encryption_test_case_4),
14266                 TEST_CASE_ST(ut_setup, ut_teardown,
14267                         test_kasumi_encryption_test_case_5),
14268
14269                 /** KASUMI decrypt only (UEA1) */
14270                 TEST_CASE_ST(ut_setup, ut_teardown,
14271                         test_kasumi_decryption_test_case_1),
14272                 TEST_CASE_ST(ut_setup, ut_teardown,
14273                         test_kasumi_decryption_test_case_2),
14274                 TEST_CASE_ST(ut_setup, ut_teardown,
14275                         test_kasumi_decryption_test_case_3),
14276                 TEST_CASE_ST(ut_setup, ut_teardown,
14277                         test_kasumi_decryption_test_case_4),
14278                 TEST_CASE_ST(ut_setup, ut_teardown,
14279                         test_kasumi_decryption_test_case_5),
14280                 TEST_CASE_ST(ut_setup, ut_teardown,
14281                         test_kasumi_decryption_test_case_1_oop),
14282
14283                 TEST_CASE_ST(ut_setup, ut_teardown,
14284                         test_kasumi_cipher_auth_test_case_1),
14285
14286                 /** KASUMI generate auth, then encrypt (F8) */
14287                 TEST_CASE_ST(ut_setup, ut_teardown,
14288                         test_kasumi_auth_cipher_test_case_1),
14289                 TEST_CASE_ST(ut_setup, ut_teardown,
14290                         test_kasumi_auth_cipher_test_case_2),
14291                 TEST_CASE_ST(ut_setup, ut_teardown,
14292                         test_kasumi_auth_cipher_test_case_2_oop),
14293                 TEST_CASE_ST(ut_setup, ut_teardown,
14294                         test_kasumi_auth_cipher_test_case_2_sgl),
14295                 TEST_CASE_ST(ut_setup, ut_teardown,
14296                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
14297
14298                 /** KASUMI decrypt (F8), then verify auth */
14299                 TEST_CASE_ST(ut_setup, ut_teardown,
14300                         test_kasumi_auth_cipher_verify_test_case_1),
14301                 TEST_CASE_ST(ut_setup, ut_teardown,
14302                         test_kasumi_auth_cipher_verify_test_case_2),
14303                 TEST_CASE_ST(ut_setup, ut_teardown,
14304                         test_kasumi_auth_cipher_verify_test_case_2_oop),
14305                 TEST_CASE_ST(ut_setup, ut_teardown,
14306                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
14307                 TEST_CASE_ST(ut_setup, ut_teardown,
14308                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
14309
14310                 TEST_CASES_END()
14311         }
14312 };
14313
14314 static struct unit_test_suite cryptodev_esn_testsuite  = {
14315         .suite_name = "ESN Test Suite",
14316         .setup = esn_testsuite_setup,
14317         .unit_test_cases = {
14318                 TEST_CASE_ST(ut_setup, ut_teardown,
14319                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
14320                 TEST_CASE_ST(ut_setup, ut_teardown,
14321                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
14322                 TEST_CASES_END()
14323         }
14324 };
14325
14326 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
14327         .suite_name = "Negative AES GCM Test Suite",
14328         .setup = negative_aes_gcm_testsuite_setup,
14329         .unit_test_cases = {
14330                 TEST_CASE_ST(ut_setup, ut_teardown,
14331                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
14332                 TEST_CASE_ST(ut_setup, ut_teardown,
14333                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
14334                 TEST_CASE_ST(ut_setup, ut_teardown,
14335                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
14336                 TEST_CASE_ST(ut_setup, ut_teardown,
14337                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
14338                 TEST_CASE_ST(ut_setup, ut_teardown,
14339                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
14340                 TEST_CASE_ST(ut_setup, ut_teardown,
14341                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
14342                 TEST_CASE_ST(ut_setup, ut_teardown,
14343                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
14344                 TEST_CASE_ST(ut_setup, ut_teardown,
14345                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
14346                 TEST_CASE_ST(ut_setup, ut_teardown,
14347                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
14348                 TEST_CASE_ST(ut_setup, ut_teardown,
14349                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
14350                 TEST_CASE_ST(ut_setup, ut_teardown,
14351                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
14352                 TEST_CASE_ST(ut_setup, ut_teardown,
14353                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
14354
14355                 TEST_CASES_END()
14356         }
14357 };
14358
14359 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
14360         .suite_name = "Negative AES GMAC Test Suite",
14361         .setup = negative_aes_gmac_testsuite_setup,
14362         .unit_test_cases = {
14363                 TEST_CASE_ST(ut_setup, ut_teardown,
14364                         authentication_verify_AES128_GMAC_fail_data_corrupt),
14365                 TEST_CASE_ST(ut_setup, ut_teardown,
14366                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
14367
14368                 TEST_CASES_END()
14369         }
14370 };
14371
14372 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
14373         .suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
14374         .setup = mixed_cipher_hash_testsuite_setup,
14375         .unit_test_cases = {
14376                 /** AUTH AES CMAC + CIPHER AES CTR */
14377                 TEST_CASE_ST(ut_setup, ut_teardown,
14378                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
14379                 TEST_CASE_ST(ut_setup, ut_teardown,
14380                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14381                 TEST_CASE_ST(ut_setup, ut_teardown,
14382                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14383                 TEST_CASE_ST(ut_setup, ut_teardown,
14384                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14385                 TEST_CASE_ST(ut_setup, ut_teardown,
14386                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
14387                 TEST_CASE_ST(ut_setup, ut_teardown,
14388                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14389                 TEST_CASE_ST(ut_setup, ut_teardown,
14390                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14391                 TEST_CASE_ST(ut_setup, ut_teardown,
14392                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14393
14394                 /** AUTH ZUC + CIPHER SNOW3G */
14395                 TEST_CASE_ST(ut_setup, ut_teardown,
14396                         test_auth_zuc_cipher_snow_test_case_1),
14397                 TEST_CASE_ST(ut_setup, ut_teardown,
14398                         test_verify_auth_zuc_cipher_snow_test_case_1),
14399                 /** AUTH AES CMAC + CIPHER SNOW3G */
14400                 TEST_CASE_ST(ut_setup, ut_teardown,
14401                         test_auth_aes_cmac_cipher_snow_test_case_1),
14402                 TEST_CASE_ST(ut_setup, ut_teardown,
14403                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
14404                 /** AUTH ZUC + CIPHER AES CTR */
14405                 TEST_CASE_ST(ut_setup, ut_teardown,
14406                         test_auth_zuc_cipher_aes_ctr_test_case_1),
14407                 TEST_CASE_ST(ut_setup, ut_teardown,
14408                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
14409                 /** AUTH SNOW3G + CIPHER AES CTR */
14410                 TEST_CASE_ST(ut_setup, ut_teardown,
14411                         test_auth_snow_cipher_aes_ctr_test_case_1),
14412                 TEST_CASE_ST(ut_setup, ut_teardown,
14413                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
14414                 /** AUTH SNOW3G + CIPHER ZUC */
14415                 TEST_CASE_ST(ut_setup, ut_teardown,
14416                         test_auth_snow_cipher_zuc_test_case_1),
14417                 TEST_CASE_ST(ut_setup, ut_teardown,
14418                         test_verify_auth_snow_cipher_zuc_test_case_1),
14419                 /** AUTH AES CMAC + CIPHER ZUC */
14420                 TEST_CASE_ST(ut_setup, ut_teardown,
14421                         test_auth_aes_cmac_cipher_zuc_test_case_1),
14422                 TEST_CASE_ST(ut_setup, ut_teardown,
14423                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
14424
14425                 /** AUTH NULL + CIPHER SNOW3G */
14426                 TEST_CASE_ST(ut_setup, ut_teardown,
14427                         test_auth_null_cipher_snow_test_case_1),
14428                 TEST_CASE_ST(ut_setup, ut_teardown,
14429                         test_verify_auth_null_cipher_snow_test_case_1),
14430                 /** AUTH NULL + CIPHER ZUC */
14431                 TEST_CASE_ST(ut_setup, ut_teardown,
14432                         test_auth_null_cipher_zuc_test_case_1),
14433                 TEST_CASE_ST(ut_setup, ut_teardown,
14434                         test_verify_auth_null_cipher_zuc_test_case_1),
14435                 /** AUTH SNOW3G + CIPHER NULL */
14436                 TEST_CASE_ST(ut_setup, ut_teardown,
14437                         test_auth_snow_cipher_null_test_case_1),
14438                 TEST_CASE_ST(ut_setup, ut_teardown,
14439                         test_verify_auth_snow_cipher_null_test_case_1),
14440                 /** AUTH ZUC + CIPHER NULL */
14441                 TEST_CASE_ST(ut_setup, ut_teardown,
14442                         test_auth_zuc_cipher_null_test_case_1),
14443                 TEST_CASE_ST(ut_setup, ut_teardown,
14444                         test_verify_auth_zuc_cipher_null_test_case_1),
14445                 /** AUTH NULL + CIPHER AES CTR */
14446                 TEST_CASE_ST(ut_setup, ut_teardown,
14447                         test_auth_null_cipher_aes_ctr_test_case_1),
14448                 TEST_CASE_ST(ut_setup, ut_teardown,
14449                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
14450                 /** AUTH AES CMAC + CIPHER NULL */
14451                 TEST_CASE_ST(ut_setup, ut_teardown,
14452                         test_auth_aes_cmac_cipher_null_test_case_1),
14453                 TEST_CASE_ST(ut_setup, ut_teardown,
14454                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
14455                 TEST_CASES_END()
14456         }
14457 };
14458
14459 static int
14460 run_cryptodev_testsuite(const char *pmd_name)
14461 {
14462         uint8_t ret, j, i = 0, blk_start_idx = 0;
14463         const enum blockcipher_test_type blk_suites[] = {
14464                 BLKCIPHER_AES_CHAIN_TYPE,
14465                 BLKCIPHER_AES_CIPHERONLY_TYPE,
14466                 BLKCIPHER_AES_DOCSIS_TYPE,
14467                 BLKCIPHER_3DES_CHAIN_TYPE,
14468                 BLKCIPHER_3DES_CIPHERONLY_TYPE,
14469                 BLKCIPHER_DES_CIPHERONLY_TYPE,
14470                 BLKCIPHER_DES_DOCSIS_TYPE,
14471                 BLKCIPHER_AUTHONLY_TYPE};
14472         struct unit_test_suite *static_suites[] = {
14473                 &cryptodev_multi_session_testsuite,
14474                 &cryptodev_null_testsuite,
14475                 &cryptodev_aes_ccm_auth_testsuite,
14476                 &cryptodev_aes_gcm_auth_testsuite,
14477                 &cryptodev_aes_gmac_auth_testsuite,
14478                 &cryptodev_snow3g_testsuite,
14479                 &cryptodev_chacha20_poly1305_testsuite,
14480                 &cryptodev_zuc_testsuite,
14481                 &cryptodev_hmac_md5_auth_testsuite,
14482                 &cryptodev_kasumi_testsuite,
14483                 &cryptodev_esn_testsuite,
14484                 &cryptodev_negative_aes_gcm_testsuite,
14485                 &cryptodev_negative_aes_gmac_testsuite,
14486                 &cryptodev_mixed_cipher_hash_testsuite,
14487                 &cryptodev_negative_hmac_sha1_testsuite,
14488                 &cryptodev_gen_testsuite,
14489 #ifdef RTE_LIB_SECURITY
14490                 &pdcp_proto_testsuite,
14491                 &docsis_proto_testsuite,
14492 #endif
14493                 &end_testsuite
14494         };
14495         static struct unit_test_suite ts = {
14496                 .suite_name = "Cryptodev Unit Test Suite",
14497                 .setup = testsuite_setup,
14498                 .teardown = testsuite_teardown,
14499                 .unit_test_cases = {TEST_CASES_END()}
14500         };
14501
14502         gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
14503
14504         if (gbl_driver_id == -1) {
14505                 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
14506                 return TEST_SKIPPED;
14507         }
14508
14509         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
14510                         (RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
14511
14512         ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
14513         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
14514         ret = unit_test_suite_runner(&ts);
14515
14516         FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
14517         free(ts.unit_test_suites);
14518         return ret;
14519 }
14520
14521 static int
14522 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
14523 {
14524         struct rte_cryptodev_info dev_info;
14525         uint8_t i, nb_devs;
14526         int driver_id;
14527
14528         driver_id = rte_cryptodev_driver_id_get(pmd_name);
14529         if (driver_id == -1) {
14530                 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
14531                 return TEST_SKIPPED;
14532         }
14533
14534         nb_devs = rte_cryptodev_count();
14535         if (nb_devs < 1) {
14536                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
14537                 return TEST_SKIPPED;
14538         }
14539
14540         for (i = 0; i < nb_devs; i++) {
14541                 rte_cryptodev_info_get(i, &dev_info);
14542                 if (dev_info.driver_id == driver_id) {
14543                         if (!(dev_info.feature_flags & flag)) {
14544                                 RTE_LOG(INFO, USER1, "%s not supported\n",
14545                                                 flag_name);
14546                                 return TEST_SKIPPED;
14547                         }
14548                         return 0; /* found */
14549                 }
14550         }
14551
14552         RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
14553         return TEST_SKIPPED;
14554 }
14555
14556 static int
14557 test_cryptodev_qat(void)
14558 {
14559         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14560 }
14561
14562 static int
14563 test_cryptodev_virtio(void)
14564 {
14565         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
14566 }
14567
14568 static int
14569 test_cryptodev_aesni_mb(void)
14570 {
14571         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14572 }
14573
14574 static int
14575 test_cryptodev_cpu_aesni_mb(void)
14576 {
14577         int32_t rc;
14578         enum rte_security_session_action_type at = gbl_action_type;
14579         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14580         rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14581         gbl_action_type = at;
14582         return rc;
14583 }
14584
14585 static int
14586 test_cryptodev_openssl(void)
14587 {
14588         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
14589 }
14590
14591 static int
14592 test_cryptodev_aesni_gcm(void)
14593 {
14594         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14595 }
14596
14597 static int
14598 test_cryptodev_cpu_aesni_gcm(void)
14599 {
14600         int32_t rc;
14601         enum rte_security_session_action_type at = gbl_action_type;
14602         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14603         rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14604         gbl_action_type = at;
14605         return rc;
14606 }
14607
14608 static int
14609 test_cryptodev_mlx5(void)
14610 {
14611         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
14612 }
14613
14614 static int
14615 test_cryptodev_null(void)
14616 {
14617         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
14618 }
14619
14620 static int
14621 test_cryptodev_sw_snow3g(void)
14622 {
14623         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
14624 }
14625
14626 static int
14627 test_cryptodev_sw_kasumi(void)
14628 {
14629         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
14630 }
14631
14632 static int
14633 test_cryptodev_sw_zuc(void)
14634 {
14635         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
14636 }
14637
14638 static int
14639 test_cryptodev_armv8(void)
14640 {
14641         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
14642 }
14643
14644 static int
14645 test_cryptodev_mrvl(void)
14646 {
14647         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
14648 }
14649
14650 #ifdef RTE_CRYPTO_SCHEDULER
14651
14652 static int
14653 test_cryptodev_scheduler(void)
14654 {
14655         uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
14656         const enum blockcipher_test_type blk_suites[] = {
14657                 BLKCIPHER_AES_CHAIN_TYPE,
14658                 BLKCIPHER_AES_CIPHERONLY_TYPE,
14659                 BLKCIPHER_AUTHONLY_TYPE
14660         };
14661         static struct unit_test_suite scheduler_multicore = {
14662                 .suite_name = "Scheduler Multicore Unit Test Suite",
14663                 .setup = scheduler_multicore_testsuite_setup,
14664                 .teardown = scheduler_mode_testsuite_teardown,
14665                 .unit_test_cases = {TEST_CASES_END()}
14666         };
14667         static struct unit_test_suite scheduler_round_robin = {
14668                 .suite_name = "Scheduler Round Robin Unit Test Suite",
14669                 .setup = scheduler_roundrobin_testsuite_setup,
14670                 .teardown = scheduler_mode_testsuite_teardown,
14671                 .unit_test_cases = {TEST_CASES_END()}
14672         };
14673         static struct unit_test_suite scheduler_failover = {
14674                 .suite_name = "Scheduler Failover Unit Test Suite",
14675                 .setup = scheduler_failover_testsuite_setup,
14676                 .teardown = scheduler_mode_testsuite_teardown,
14677                 .unit_test_cases = {TEST_CASES_END()}
14678         };
14679         static struct unit_test_suite scheduler_pkt_size_distr = {
14680                 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
14681                 .setup = scheduler_pkt_size_distr_testsuite_setup,
14682                 .teardown = scheduler_mode_testsuite_teardown,
14683                 .unit_test_cases = {TEST_CASES_END()}
14684         };
14685         struct unit_test_suite *sched_mode_suites[] = {
14686                 &scheduler_multicore,
14687                 &scheduler_round_robin,
14688                 &scheduler_failover,
14689                 &scheduler_pkt_size_distr
14690         };
14691         static struct unit_test_suite scheduler_config = {
14692                 .suite_name = "Crypto Device Scheduler Config Unit Test Suite",
14693                 .unit_test_cases = {
14694                         TEST_CASE(test_scheduler_attach_worker_op),
14695                         TEST_CASE(test_scheduler_mode_multicore_op),
14696                         TEST_CASE(test_scheduler_mode_roundrobin_op),
14697                         TEST_CASE(test_scheduler_mode_failover_op),
14698                         TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
14699                         TEST_CASE(test_scheduler_detach_worker_op),
14700
14701                         TEST_CASES_END() /**< NULL terminate array */
14702                 }
14703         };
14704         struct unit_test_suite *static_suites[] = {
14705                 &scheduler_config,
14706                 &end_testsuite
14707         };
14708         static struct unit_test_suite ts = {
14709                 .suite_name = "Scheduler Unit Test Suite",
14710                 .setup = scheduler_testsuite_setup,
14711                 .teardown = testsuite_teardown,
14712                 .unit_test_cases = {TEST_CASES_END()}
14713         };
14714
14715         gbl_driver_id = rte_cryptodev_driver_id_get(
14716                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14717
14718         if (gbl_driver_id == -1) {
14719                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
14720                 return TEST_SKIPPED;
14721         }
14722
14723         if (rte_cryptodev_driver_id_get(
14724                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
14725                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
14726                 return TEST_SKIPPED;
14727         }
14728
14729         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
14730                 uint8_t blk_i = 0;
14731                 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
14732                                 (struct unit_test_suite *) *
14733                                 (RTE_DIM(blk_suites) + 1));
14734                 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
14735                                 blk_suites, RTE_DIM(blk_suites));
14736                 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
14737         }
14738
14739         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
14740                         (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
14741         ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
14742                         RTE_DIM(sched_mode_suites));
14743         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
14744         ret = unit_test_suite_runner(&ts);
14745
14746         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
14747                 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
14748                                 (*sched_mode_suites[sched_i]),
14749                                 RTE_DIM(blk_suites));
14750                 free(sched_mode_suites[sched_i]->unit_test_suites);
14751         }
14752         free(ts.unit_test_suites);
14753         return ret;
14754 }
14755
14756 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
14757
14758 #endif
14759
14760 static int
14761 test_cryptodev_dpaa2_sec(void)
14762 {
14763         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
14764 }
14765
14766 static int
14767 test_cryptodev_dpaa_sec(void)
14768 {
14769         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
14770 }
14771
14772 static int
14773 test_cryptodev_ccp(void)
14774 {
14775         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
14776 }
14777
14778 static int
14779 test_cryptodev_octeontx(void)
14780 {
14781         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
14782 }
14783
14784 static int
14785 test_cryptodev_octeontx2(void)
14786 {
14787         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
14788 }
14789
14790 static int
14791 test_cryptodev_caam_jr(void)
14792 {
14793         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
14794 }
14795
14796 static int
14797 test_cryptodev_nitrox(void)
14798 {
14799         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
14800 }
14801
14802 static int
14803 test_cryptodev_bcmfs(void)
14804 {
14805         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
14806 }
14807
14808 static int
14809 test_cryptodev_qat_raw_api(void)
14810 {
14811         static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
14812         int ret;
14813
14814         ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
14815                         "RAW API");
14816         if (ret)
14817                 return ret;
14818
14819         global_api_test_type = CRYPTODEV_RAW_API_TEST;
14820         ret = run_cryptodev_testsuite(pmd_name);
14821         global_api_test_type = CRYPTODEV_API_TEST;
14822
14823         return ret;
14824 }
14825
14826 static int
14827 test_cryptodev_cn9k(void)
14828 {
14829         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
14830 }
14831
14832 static int
14833 test_cryptodev_cn10k(void)
14834 {
14835         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
14836 }
14837
14838 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
14839                 test_cryptodev_qat_raw_api);
14840 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
14841 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
14842 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
14843         test_cryptodev_cpu_aesni_mb);
14844 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
14845 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
14846 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
14847         test_cryptodev_cpu_aesni_gcm);
14848 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
14849 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
14850 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
14851 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
14852 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
14853 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
14854 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
14855 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
14856 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
14857 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
14858 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
14859 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
14860 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
14861 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
14862 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
14863 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
14864 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
14865 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);