test/crypto: replace unsupported with skipped
[dpdk.git] / app / test / test_cryptodev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation
3  * Copyright 2020 NXP
4  */
5
6 #include <time.h>
7
8 #include <rte_common.h>
9 #include <rte_hexdump.h>
10 #include <rte_mbuf.h>
11 #include <rte_malloc.h>
12 #include <rte_memcpy.h>
13 #include <rte_pause.h>
14 #include <rte_bus_vdev.h>
15 #include <rte_ether.h>
16
17 #include <rte_crypto.h>
18 #include <rte_cryptodev.h>
19 #include <rte_cryptodev_pmd.h>
20 #include <rte_string_fns.h>
21
22 #ifdef RTE_CRYPTO_SCHEDULER
23 #include <rte_cryptodev_scheduler.h>
24 #include <rte_cryptodev_scheduler_operations.h>
25 #endif
26
27 #include <rte_lcore.h>
28
29 #include "test.h"
30 #include "test_cryptodev.h"
31
32 #include "test_cryptodev_blockcipher.h"
33 #include "test_cryptodev_aes_test_vectors.h"
34 #include "test_cryptodev_des_test_vectors.h"
35 #include "test_cryptodev_hash_test_vectors.h"
36 #include "test_cryptodev_kasumi_test_vectors.h"
37 #include "test_cryptodev_kasumi_hash_test_vectors.h"
38 #include "test_cryptodev_snow3g_test_vectors.h"
39 #include "test_cryptodev_snow3g_hash_test_vectors.h"
40 #include "test_cryptodev_zuc_test_vectors.h"
41 #include "test_cryptodev_aead_test_vectors.h"
42 #include "test_cryptodev_hmac_test_vectors.h"
43 #include "test_cryptodev_mixed_test_vectors.h"
44 #ifdef RTE_LIB_SECURITY
45 #include "test_cryptodev_security_pdcp_test_vectors.h"
46 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
47 #include "test_cryptodev_security_pdcp_test_func.h"
48 #include "test_cryptodev_security_docsis_test_vectors.h"
49
50 #define SDAP_DISABLED   0
51 #define SDAP_ENABLED    1
52 #endif
53
54 #define VDEV_ARGS_SIZE 100
55 #define MAX_NB_SESSIONS 4
56
57 #define MAX_DRV_SERVICE_CTX_SIZE 256
58
59 #define MAX_RAW_DEQUEUE_COUNT   65535
60
61 #define IN_PLACE 0
62 #define OUT_OF_PLACE 1
63
64 #ifndef ARRAY_SIZE
65 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
66 #endif
67
68 static int gbl_driver_id;
69
70 static enum rte_security_session_action_type gbl_action_type =
71         RTE_SECURITY_ACTION_TYPE_NONE;
72
73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
74
75 struct crypto_testsuite_params {
76         struct rte_mempool *mbuf_pool;
77         struct rte_mempool *large_mbuf_pool;
78         struct rte_mempool *op_mpool;
79         struct rte_mempool *session_mpool;
80         struct rte_mempool *session_priv_mpool;
81         struct rte_cryptodev_config conf;
82         struct rte_cryptodev_qp_conf qp_conf;
83
84         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
85         uint8_t valid_dev_count;
86 };
87
88 struct crypto_unittest_params {
89         struct rte_crypto_sym_xform cipher_xform;
90         struct rte_crypto_sym_xform auth_xform;
91         struct rte_crypto_sym_xform aead_xform;
92 #ifdef RTE_LIB_SECURITY
93         struct rte_security_docsis_xform docsis_xform;
94 #endif
95
96         union {
97                 struct rte_cryptodev_sym_session *sess;
98 #ifdef RTE_LIB_SECURITY
99                 struct rte_security_session *sec_session;
100 #endif
101         };
102 #ifdef RTE_LIB_SECURITY
103         enum rte_security_session_action_type type;
104 #endif
105         struct rte_crypto_op *op;
106
107         struct rte_mbuf *obuf, *ibuf;
108
109         uint8_t *digest;
110 };
111
112 #define ALIGN_POW2_ROUNDUP(num, align) \
113         (((num) + (align) - 1) & ~((align) - 1))
114
115 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)  \
116         for (j = 0; j < num_child_ts; index++, j++)                     \
117                 parent_ts.unit_test_suites[index] = child_ts[j]
118
119 /*
120  * Forward declarations.
121  */
122 static int
123 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
124                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
125                 uint8_t *hmac_key);
126
127 static int
128 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
129                 struct crypto_unittest_params *ut_params,
130                 struct crypto_testsuite_params *ts_param,
131                 const uint8_t *cipher,
132                 const uint8_t *digest,
133                 const uint8_t *iv);
134
135 static struct rte_mbuf *
136 setup_test_string(struct rte_mempool *mpool,
137                 const char *string, size_t len, uint8_t blocksize)
138 {
139         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
140         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
141
142         memset(m->buf_addr, 0, m->buf_len);
143         if (m) {
144                 char *dst = rte_pktmbuf_append(m, t_len);
145
146                 if (!dst) {
147                         rte_pktmbuf_free(m);
148                         return NULL;
149                 }
150                 if (string != NULL)
151                         rte_memcpy(dst, string, t_len);
152                 else
153                         memset(dst, 0, t_len);
154         }
155
156         return m;
157 }
158
159 /* Get number of bytes in X bits (rounding up) */
160 static uint32_t
161 ceil_byte_length(uint32_t num_bits)
162 {
163         if (num_bits % 8)
164                 return ((num_bits >> 3) + 1);
165         else
166                 return (num_bits >> 3);
167 }
168
169 static void
170 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused,
171                 uint8_t is_op_success)
172 {
173         struct rte_crypto_op *op = user_data;
174         op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
175                         RTE_CRYPTO_OP_STATUS_ERROR;
176 }
177
178 void
179 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
180                 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
181                 uint8_t len_in_bits, uint8_t cipher_iv_len)
182 {
183         struct rte_crypto_sym_op *sop = op->sym;
184         struct rte_crypto_op *ret_op = NULL;
185         struct rte_crypto_vec data_vec[UINT8_MAX];
186         struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
187         union rte_crypto_sym_ofs ofs;
188         struct rte_crypto_sym_vec vec;
189         struct rte_crypto_sgl sgl;
190         uint32_t max_len;
191         union rte_cryptodev_session_ctx sess;
192         uint32_t count = 0;
193         struct rte_crypto_raw_dp_ctx *ctx;
194         uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
195                         auth_len = 0;
196         int32_t n;
197         uint32_t n_success;
198         int ctx_service_size;
199         int32_t status = 0;
200         int enqueue_status, dequeue_status;
201
202         ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
203         if (ctx_service_size < 0) {
204                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
205                 return;
206         }
207
208         ctx = malloc(ctx_service_size);
209         if (!ctx) {
210                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
211                 return;
212         }
213
214         /* Both are enums, setting crypto_sess will suit any session type */
215         sess.crypto_sess = op->sym->session;
216
217         if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
218                         op->sess_type, sess, 0) < 0) {
219                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
220                 goto exit;
221         }
222
223         cipher_iv.iova = 0;
224         cipher_iv.va = NULL;
225         aad_auth_iv.iova = 0;
226         aad_auth_iv.va = NULL;
227         digest.iova = 0;
228         digest.va = NULL;
229         sgl.vec = data_vec;
230         vec.num = 1;
231         vec.sgl = &sgl;
232         vec.iv = &cipher_iv;
233         vec.digest = &digest;
234         vec.aad = &aad_auth_iv;
235         vec.status = &status;
236
237         ofs.raw = 0;
238
239         if (is_cipher && is_auth) {
240                 cipher_offset = sop->cipher.data.offset;
241                 cipher_len = sop->cipher.data.length;
242                 auth_offset = sop->auth.data.offset;
243                 auth_len = sop->auth.data.length;
244                 max_len = RTE_MAX(cipher_offset + cipher_len,
245                                 auth_offset + auth_len);
246                 if (len_in_bits) {
247                         max_len = max_len >> 3;
248                         cipher_offset = cipher_offset >> 3;
249                         auth_offset = auth_offset >> 3;
250                         cipher_len = cipher_len >> 3;
251                         auth_len = auth_len >> 3;
252                 }
253                 ofs.ofs.cipher.head = cipher_offset;
254                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
255                 ofs.ofs.auth.head = auth_offset;
256                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
257                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
258                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
259                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
260                                 op, void *, IV_OFFSET + cipher_iv_len);
261                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
262                                 cipher_iv_len);
263                 digest.va = (void *)sop->auth.digest.data;
264                 digest.iova = sop->auth.digest.phys_addr;
265
266         } else if (is_cipher) {
267                 cipher_offset = sop->cipher.data.offset;
268                 cipher_len = sop->cipher.data.length;
269                 max_len = cipher_len + cipher_offset;
270                 if (len_in_bits) {
271                         max_len = max_len >> 3;
272                         cipher_offset = cipher_offset >> 3;
273                         cipher_len = cipher_len >> 3;
274                 }
275                 ofs.ofs.cipher.head = cipher_offset;
276                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
277                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
278                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
279
280         } else if (is_auth) {
281                 auth_offset = sop->auth.data.offset;
282                 auth_len = sop->auth.data.length;
283                 max_len = auth_len + auth_offset;
284                 if (len_in_bits) {
285                         max_len = max_len >> 3;
286                         auth_offset = auth_offset >> 3;
287                         auth_len = auth_len >> 3;
288                 }
289                 ofs.ofs.auth.head = auth_offset;
290                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
291                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
292                                 op, void *, IV_OFFSET + cipher_iv_len);
293                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
294                                 cipher_iv_len);
295                 digest.va = (void *)sop->auth.digest.data;
296                 digest.iova = sop->auth.digest.phys_addr;
297
298         } else { /* aead */
299                 cipher_offset = sop->aead.data.offset;
300                 cipher_len = sop->aead.data.length;
301                 max_len = cipher_len + cipher_offset;
302                 if (len_in_bits) {
303                         max_len = max_len >> 3;
304                         cipher_offset = cipher_offset >> 3;
305                         cipher_len = cipher_len >> 3;
306                 }
307                 ofs.ofs.cipher.head = cipher_offset;
308                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
309                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
310                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
311                 aad_auth_iv.va = (void *)sop->aead.aad.data;
312                 aad_auth_iv.iova = sop->aead.aad.phys_addr;
313                 digest.va = (void *)sop->aead.digest.data;
314                 digest.iova = sop->aead.digest.phys_addr;
315         }
316
317         n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
318                         data_vec, RTE_DIM(data_vec));
319         if (n < 0 || n > sop->m_src->nb_segs) {
320                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
321                 goto exit;
322         }
323
324         sgl.num = n;
325
326         if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
327                         &enqueue_status) < 1) {
328                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
329                 goto exit;
330         }
331
332         if (enqueue_status == 0) {
333                 status = rte_cryptodev_raw_enqueue_done(ctx, 1);
334                 if (status < 0) {
335                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
336                         goto exit;
337                 }
338         } else if (enqueue_status < 0) {
339                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
340                 goto exit;
341         }
342
343         n = n_success = 0;
344         while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
345                 n = rte_cryptodev_raw_dequeue_burst(ctx,
346                         NULL, 1, post_process_raw_dp_op,
347                                 (void **)&ret_op, 0, &n_success,
348                                 &dequeue_status);
349                 if (dequeue_status < 0) {
350                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
351                         goto exit;
352                 }
353                 if (n == 0)
354                         rte_pause();
355         }
356
357         if (n == 1 && dequeue_status == 0) {
358                 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
359                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
360                         goto exit;
361                 }
362         }
363
364         op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
365                         n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
366                                         RTE_CRYPTO_OP_STATUS_SUCCESS;
367
368 exit:
369         free(ctx);
370 }
371
372 static void
373 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
374 {
375         int32_t n, st;
376         struct rte_crypto_sym_op *sop;
377         union rte_crypto_sym_ofs ofs;
378         struct rte_crypto_sgl sgl;
379         struct rte_crypto_sym_vec symvec;
380         struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
381         struct rte_crypto_vec vec[UINT8_MAX];
382
383         sop = op->sym;
384
385         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
386                 sop->aead.data.length, vec, RTE_DIM(vec));
387
388         if (n < 0 || n != sop->m_src->nb_segs) {
389                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
390                 return;
391         }
392
393         sgl.vec = vec;
394         sgl.num = n;
395         symvec.sgl = &sgl;
396         symvec.iv = &iv_ptr;
397         symvec.digest = &digest_ptr;
398         symvec.aad = &aad_ptr;
399         symvec.status = &st;
400         symvec.num = 1;
401
402         /* for CPU crypto the IOVA address is not required */
403         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
404         digest_ptr.va = (void *)sop->aead.digest.data;
405         aad_ptr.va = (void *)sop->aead.aad.data;
406
407         ofs.raw = 0;
408
409         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
410                 &symvec);
411
412         if (n != 1)
413                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
414         else
415                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
416 }
417
418 static void
419 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
420 {
421         int32_t n, st;
422         struct rte_crypto_sym_op *sop;
423         union rte_crypto_sym_ofs ofs;
424         struct rte_crypto_sgl sgl;
425         struct rte_crypto_sym_vec symvec;
426         struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
427         struct rte_crypto_vec vec[UINT8_MAX];
428
429         sop = op->sym;
430
431         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
432                 sop->auth.data.length, vec, RTE_DIM(vec));
433
434         if (n < 0 || n != sop->m_src->nb_segs) {
435                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
436                 return;
437         }
438
439         sgl.vec = vec;
440         sgl.num = n;
441         symvec.sgl = &sgl;
442         symvec.iv = &iv_ptr;
443         symvec.digest = &digest_ptr;
444         symvec.status = &st;
445         symvec.num = 1;
446
447         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
448         digest_ptr.va = (void *)sop->auth.digest.data;
449
450         ofs.raw = 0;
451         ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
452         ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
453                 (sop->cipher.data.offset + sop->cipher.data.length);
454
455         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
456                 &symvec);
457
458         if (n != 1)
459                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
460         else
461                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
462 }
463
464 static struct rte_crypto_op *
465 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
466 {
467
468         RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
469
470         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
471                 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
472                 return NULL;
473         }
474
475         op = NULL;
476
477         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
478                 rte_pause();
479
480         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
481                 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
482                 return NULL;
483         }
484
485         return op;
486 }
487
488 static struct crypto_testsuite_params testsuite_params = { NULL };
489 static struct crypto_unittest_params unittest_params;
490
491 static int
492 testsuite_setup(void)
493 {
494         struct crypto_testsuite_params *ts_params = &testsuite_params;
495         struct rte_cryptodev_info info;
496         uint32_t i = 0, nb_devs, dev_id;
497         uint16_t qp_id;
498
499         memset(ts_params, 0, sizeof(*ts_params));
500
501         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
502         if (ts_params->mbuf_pool == NULL) {
503                 /* Not already created so create */
504                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
505                                 "CRYPTO_MBUFPOOL",
506                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
507                                 rte_socket_id());
508                 if (ts_params->mbuf_pool == NULL) {
509                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
510                         return TEST_FAILED;
511                 }
512         }
513
514         ts_params->large_mbuf_pool = rte_mempool_lookup(
515                         "CRYPTO_LARGE_MBUFPOOL");
516         if (ts_params->large_mbuf_pool == NULL) {
517                 /* Not already created so create */
518                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
519                                 "CRYPTO_LARGE_MBUFPOOL",
520                                 1, 0, 0, UINT16_MAX,
521                                 rte_socket_id());
522                 if (ts_params->large_mbuf_pool == NULL) {
523                         RTE_LOG(ERR, USER1,
524                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
525                         return TEST_FAILED;
526                 }
527         }
528
529         ts_params->op_mpool = rte_crypto_op_pool_create(
530                         "MBUF_CRYPTO_SYM_OP_POOL",
531                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
532                         NUM_MBUFS, MBUF_CACHE_SIZE,
533                         DEFAULT_NUM_XFORMS *
534                         sizeof(struct rte_crypto_sym_xform) +
535                         MAXIMUM_IV_LENGTH,
536                         rte_socket_id());
537         if (ts_params->op_mpool == NULL) {
538                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
539                 return TEST_FAILED;
540         }
541
542         nb_devs = rte_cryptodev_count();
543         if (nb_devs < 1) {
544                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
545                 return TEST_SKIPPED;
546         }
547
548         if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
549                 RTE_LOG(WARNING, USER1, "No %s devices found?\n",
550                                 rte_cryptodev_driver_name_get(gbl_driver_id));
551                 return TEST_SKIPPED;
552         }
553
554         /* Create list of valid crypto devs */
555         for (i = 0; i < nb_devs; i++) {
556                 rte_cryptodev_info_get(i, &info);
557                 if (info.driver_id == gbl_driver_id)
558                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
559         }
560
561         if (ts_params->valid_dev_count < 1)
562                 return TEST_FAILED;
563
564         /* Set up all the qps on the first of the valid devices found */
565
566         dev_id = ts_params->valid_devs[0];
567
568         rte_cryptodev_info_get(dev_id, &info);
569
570         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
571         ts_params->conf.socket_id = SOCKET_ID_ANY;
572         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
573
574         unsigned int session_size =
575                 rte_cryptodev_sym_get_private_session_size(dev_id);
576
577 #ifdef RTE_LIB_SECURITY
578         unsigned int security_session_size = rte_security_session_get_size(
579                         rte_cryptodev_get_sec_ctx(dev_id));
580
581         if (session_size < security_session_size)
582                 session_size = security_session_size;
583 #endif
584         /*
585          * Create mempool with maximum number of sessions.
586          */
587         if (info.sym.max_nb_sessions != 0 &&
588                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
589                 RTE_LOG(ERR, USER1, "Device does not support "
590                                 "at least %u sessions\n",
591                                 MAX_NB_SESSIONS);
592                 return TEST_FAILED;
593         }
594
595         ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
596                         "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
597                         SOCKET_ID_ANY);
598         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
599                         "session mempool allocation failed");
600
601         ts_params->session_priv_mpool = rte_mempool_create(
602                         "test_sess_mp_priv",
603                         MAX_NB_SESSIONS,
604                         session_size,
605                         0, 0, NULL, NULL, NULL,
606                         NULL, SOCKET_ID_ANY,
607                         0);
608         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
609                         "session mempool allocation failed");
610
611
612
613         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
614                         &ts_params->conf),
615                         "Failed to configure cryptodev %u with %u qps",
616                         dev_id, ts_params->conf.nb_queue_pairs);
617
618         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
619         ts_params->qp_conf.mp_session = ts_params->session_mpool;
620         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
621
622         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
623                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
624                         dev_id, qp_id, &ts_params->qp_conf,
625                         rte_cryptodev_socket_id(dev_id)),
626                         "Failed to setup queue pair %u on cryptodev %u",
627                         qp_id, dev_id);
628         }
629
630         return TEST_SUCCESS;
631 }
632
633 static void
634 testsuite_teardown(void)
635 {
636         struct crypto_testsuite_params *ts_params = &testsuite_params;
637         int res;
638
639         if (ts_params->mbuf_pool != NULL) {
640                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
641                 rte_mempool_avail_count(ts_params->mbuf_pool));
642         }
643
644         if (ts_params->op_mpool != NULL) {
645                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
646                 rte_mempool_avail_count(ts_params->op_mpool));
647         }
648
649         /* Free session mempools */
650         if (ts_params->session_priv_mpool != NULL) {
651                 rte_mempool_free(ts_params->session_priv_mpool);
652                 ts_params->session_priv_mpool = NULL;
653         }
654
655         if (ts_params->session_mpool != NULL) {
656                 rte_mempool_free(ts_params->session_mpool);
657                 ts_params->session_mpool = NULL;
658         }
659
660         res = rte_cryptodev_close(ts_params->valid_devs[0]);
661         if (res)
662                 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
663 }
664
665 static int
666 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
667                 const int *algs, uint16_t num_algs)
668 {
669         uint8_t dev_id = testsuite_params.valid_devs[0];
670         bool some_alg_supported = FALSE;
671         uint16_t i;
672
673         for (i = 0; i < num_algs && !some_alg_supported; i++) {
674                 struct rte_cryptodev_sym_capability_idx alg = {
675                         type, {algs[i]}
676                 };
677                 if (rte_cryptodev_sym_capability_get(dev_id,
678                                 &alg) != NULL)
679                         some_alg_supported = TRUE;
680         }
681         if (!some_alg_supported)
682                 return TEST_SKIPPED;
683
684         return 0;
685 }
686
687 int
688 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
689                 uint16_t num_ciphers)
690 {
691         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
692                         (const int *) ciphers, num_ciphers);
693 }
694
695 int
696 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
697                 uint16_t num_auths)
698 {
699         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
700                         (const int *) auths, num_auths);
701 }
702
703 int
704 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
705                 uint16_t num_aeads)
706 {
707         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
708                         (const int *) aeads, num_aeads);
709 }
710
711 static int
712 null_testsuite_setup(void)
713 {
714         struct crypto_testsuite_params *ts_params = &testsuite_params;
715         uint8_t dev_id = ts_params->valid_devs[0];
716         struct rte_cryptodev_info dev_info;
717         const enum rte_crypto_cipher_algorithm ciphers[] = {
718                 RTE_CRYPTO_CIPHER_NULL
719         };
720         const enum rte_crypto_auth_algorithm auths[] = {
721                 RTE_CRYPTO_AUTH_NULL
722         };
723
724         rte_cryptodev_info_get(dev_id, &dev_info);
725
726         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
727                 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
728                                 "testsuite not met\n");
729                 return TEST_SKIPPED;
730         }
731
732         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
733                         && check_auth_capabilities_supported(auths,
734                         RTE_DIM(auths)) != 0) {
735                 RTE_LOG(INFO, USER1, "Capability requirements for NULL "
736                                 "testsuite not met\n");
737                 return TEST_SKIPPED;
738         }
739
740         return 0;
741 }
742
743 static int
744 crypto_gen_testsuite_setup(void)
745 {
746         struct crypto_testsuite_params *ts_params = &testsuite_params;
747         uint8_t dev_id = ts_params->valid_devs[0];
748         struct rte_cryptodev_info dev_info;
749
750         rte_cryptodev_info_get(dev_id, &dev_info);
751
752         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
753                 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
754                                 "testsuite not met\n");
755                 return TEST_SKIPPED;
756         }
757
758         return 0;
759 }
760
761 #ifdef RTE_LIB_SECURITY
762 static int
763 pdcp_proto_testsuite_setup(void)
764 {
765         struct crypto_testsuite_params *ts_params = &testsuite_params;
766         uint8_t dev_id = ts_params->valid_devs[0];
767         struct rte_cryptodev_info dev_info;
768         const enum rte_crypto_cipher_algorithm ciphers[] = {
769                 RTE_CRYPTO_CIPHER_NULL,
770                 RTE_CRYPTO_CIPHER_AES_CTR,
771                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
772                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
773         };
774         const enum rte_crypto_auth_algorithm auths[] = {
775                 RTE_CRYPTO_AUTH_NULL,
776                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
777                 RTE_CRYPTO_AUTH_AES_CMAC,
778                 RTE_CRYPTO_AUTH_ZUC_EIA3
779         };
780
781         rte_cryptodev_info_get(dev_id, &dev_info);
782
783         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
784                         !(dev_info.feature_flags &
785                         RTE_CRYPTODEV_FF_SECURITY)) {
786                 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
787                                 "testsuite not met\n");
788                 return TEST_SKIPPED;
789         }
790
791         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
792                         && check_auth_capabilities_supported(auths,
793                         RTE_DIM(auths)) != 0) {
794                 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
795                                 "testsuite not met\n");
796                 return TEST_SKIPPED;
797         }
798
799         return 0;
800 }
801
802 static int
803 docsis_proto_testsuite_setup(void)
804 {
805         struct crypto_testsuite_params *ts_params = &testsuite_params;
806         uint8_t dev_id = ts_params->valid_devs[0];
807         struct rte_cryptodev_info dev_info;
808         const enum rte_crypto_cipher_algorithm ciphers[] = {
809                 RTE_CRYPTO_CIPHER_AES_DOCSISBPI
810         };
811
812         rte_cryptodev_info_get(dev_id, &dev_info);
813
814         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
815                         !(dev_info.feature_flags &
816                         RTE_CRYPTODEV_FF_SECURITY)) {
817                 RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis "
818                                 "Proto testsuite not met\n");
819                 return TEST_SKIPPED;
820         }
821
822         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
823                 RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto "
824                                 "testsuite not met\n");
825                 return TEST_SKIPPED;
826         }
827
828         return 0;
829 }
830 #endif
831
832 static int
833 aes_ccm_auth_testsuite_setup(void)
834 {
835         struct crypto_testsuite_params *ts_params = &testsuite_params;
836         uint8_t dev_id = ts_params->valid_devs[0];
837         struct rte_cryptodev_info dev_info;
838         const enum rte_crypto_aead_algorithm aeads[] = {
839                 RTE_CRYPTO_AEAD_AES_CCM
840         };
841
842         rte_cryptodev_info_get(dev_id, &dev_info);
843
844         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
845                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
846                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
847                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
848                                 "testsuite not met\n");
849                 return TEST_SKIPPED;
850         }
851
852         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
853                 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
854                                 "testsuite not met\n");
855                 return TEST_SKIPPED;
856         }
857
858         return 0;
859 }
860
861 static int
862 aes_gcm_auth_testsuite_setup(void)
863 {
864         struct crypto_testsuite_params *ts_params = &testsuite_params;
865         uint8_t dev_id = ts_params->valid_devs[0];
866         struct rte_cryptodev_info dev_info;
867         const enum rte_crypto_aead_algorithm aeads[] = {
868                 RTE_CRYPTO_AEAD_AES_GCM
869         };
870
871         rte_cryptodev_info_get(dev_id, &dev_info);
872
873         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
874                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
875                                 "testsuite not met\n");
876                 return TEST_SKIPPED;
877         }
878
879         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
880                 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
881                                 "testsuite not met\n");
882                 return TEST_SKIPPED;
883         }
884
885         return 0;
886 }
887
888 static int
889 aes_gmac_auth_testsuite_setup(void)
890 {
891         struct crypto_testsuite_params *ts_params = &testsuite_params;
892         uint8_t dev_id = ts_params->valid_devs[0];
893         struct rte_cryptodev_info dev_info;
894         const enum rte_crypto_auth_algorithm auths[] = {
895                 RTE_CRYPTO_AUTH_AES_GMAC
896         };
897
898         rte_cryptodev_info_get(dev_id, &dev_info);
899
900         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
901                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
902                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
903                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
904                                 "testsuite not met\n");
905                 return TEST_SKIPPED;
906         }
907
908         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
909                 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
910                                 "testsuite not met\n");
911                 return TEST_SKIPPED;
912         }
913
914         return 0;
915 }
916
917 static int
918 chacha20_poly1305_testsuite_setup(void)
919 {
920         struct crypto_testsuite_params *ts_params = &testsuite_params;
921         uint8_t dev_id = ts_params->valid_devs[0];
922         struct rte_cryptodev_info dev_info;
923         const enum rte_crypto_aead_algorithm aeads[] = {
924                 RTE_CRYPTO_AEAD_CHACHA20_POLY1305
925         };
926
927         rte_cryptodev_info_get(dev_id, &dev_info);
928
929         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
930                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
931                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
932                 RTE_LOG(INFO, USER1, "Feature flag requirements for "
933                                 "Chacha20-Poly1305 testsuite not met\n");
934                 return TEST_SKIPPED;
935         }
936
937         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
938                 RTE_LOG(INFO, USER1, "Capability requirements for "
939                                 "Chacha20-Poly1305 testsuite not met\n");
940                 return TEST_SKIPPED;
941         }
942
943         return 0;
944 }
945
946 static int
947 snow3g_testsuite_setup(void)
948 {
949         struct crypto_testsuite_params *ts_params = &testsuite_params;
950         uint8_t dev_id = ts_params->valid_devs[0];
951         struct rte_cryptodev_info dev_info;
952         const enum rte_crypto_cipher_algorithm ciphers[] = {
953                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
954
955         };
956         const enum rte_crypto_auth_algorithm auths[] = {
957                 RTE_CRYPTO_AUTH_SNOW3G_UIA2
958         };
959
960         rte_cryptodev_info_get(dev_id, &dev_info);
961
962         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
963                 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
964                                 "testsuite not met\n");
965                 return TEST_SKIPPED;
966         }
967
968         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
969                         && check_auth_capabilities_supported(auths,
970                         RTE_DIM(auths)) != 0) {
971                 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
972                                 "testsuite not met\n");
973                 return TEST_SKIPPED;
974         }
975
976         return 0;
977 }
978
979 static int
980 zuc_testsuite_setup(void)
981 {
982         struct crypto_testsuite_params *ts_params = &testsuite_params;
983         uint8_t dev_id = ts_params->valid_devs[0];
984         struct rte_cryptodev_info dev_info;
985         const enum rte_crypto_cipher_algorithm ciphers[] = {
986                 RTE_CRYPTO_CIPHER_ZUC_EEA3
987         };
988         const enum rte_crypto_auth_algorithm auths[] = {
989                 RTE_CRYPTO_AUTH_ZUC_EIA3
990         };
991
992         rte_cryptodev_info_get(dev_id, &dev_info);
993
994         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
995                 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
996                                 "testsuite not met\n");
997                 return TEST_SKIPPED;
998         }
999
1000         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1001                         && check_auth_capabilities_supported(auths,
1002                         RTE_DIM(auths)) != 0) {
1003                 RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1004                                 "testsuite not met\n");
1005                 return TEST_SKIPPED;
1006         }
1007
1008         return 0;
1009 }
1010
1011 static int
1012 hmac_md5_auth_testsuite_setup(void)
1013 {
1014         struct crypto_testsuite_params *ts_params = &testsuite_params;
1015         uint8_t dev_id = ts_params->valid_devs[0];
1016         struct rte_cryptodev_info dev_info;
1017         const enum rte_crypto_auth_algorithm auths[] = {
1018                 RTE_CRYPTO_AUTH_MD5_HMAC
1019         };
1020
1021         rte_cryptodev_info_get(dev_id, &dev_info);
1022
1023         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1024                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1025                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1026                 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1027                                 "Auth testsuite not met\n");
1028                 return TEST_SKIPPED;
1029         }
1030
1031         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1032                 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1033                                 "testsuite not met\n");
1034                 return TEST_SKIPPED;
1035         }
1036
1037         return 0;
1038 }
1039
1040 static int
1041 kasumi_testsuite_setup(void)
1042 {
1043         struct crypto_testsuite_params *ts_params = &testsuite_params;
1044         uint8_t dev_id = ts_params->valid_devs[0];
1045         struct rte_cryptodev_info dev_info;
1046         const enum rte_crypto_cipher_algorithm ciphers[] = {
1047                 RTE_CRYPTO_CIPHER_KASUMI_F8
1048         };
1049         const enum rte_crypto_auth_algorithm auths[] = {
1050                 RTE_CRYPTO_AUTH_KASUMI_F9
1051         };
1052
1053         rte_cryptodev_info_get(dev_id, &dev_info);
1054
1055         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1056                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1057                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1058                 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1059                                 "testsuite not met\n");
1060                 return TEST_SKIPPED;
1061         }
1062
1063         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1064                         && check_auth_capabilities_supported(auths,
1065                         RTE_DIM(auths)) != 0) {
1066                 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1067                                 "testsuite not met\n");
1068                 return TEST_SKIPPED;
1069         }
1070
1071         return 0;
1072 }
1073
1074 static int
1075 negative_aes_gcm_testsuite_setup(void)
1076 {
1077         struct crypto_testsuite_params *ts_params = &testsuite_params;
1078         uint8_t dev_id = ts_params->valid_devs[0];
1079         struct rte_cryptodev_info dev_info;
1080         const enum rte_crypto_aead_algorithm aeads[] = {
1081                 RTE_CRYPTO_AEAD_AES_GCM
1082         };
1083
1084         rte_cryptodev_info_get(dev_id, &dev_info);
1085
1086         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1087                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1088                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1089                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1090                                 "AES GCM testsuite not met\n");
1091                 return TEST_SKIPPED;
1092         }
1093
1094         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1095                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1096                                 "AES GCM testsuite not met\n");
1097                 return TEST_SKIPPED;
1098         }
1099
1100         return 0;
1101 }
1102
1103 static int
1104 negative_aes_gmac_testsuite_setup(void)
1105 {
1106         struct crypto_testsuite_params *ts_params = &testsuite_params;
1107         uint8_t dev_id = ts_params->valid_devs[0];
1108         struct rte_cryptodev_info dev_info;
1109         const enum rte_crypto_auth_algorithm auths[] = {
1110                 RTE_CRYPTO_AUTH_AES_GMAC
1111         };
1112
1113         rte_cryptodev_info_get(dev_id, &dev_info);
1114
1115         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1116                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1117                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1118                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1119                                 "AES GMAC testsuite not met\n");
1120                 return TEST_SKIPPED;
1121         }
1122
1123         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1124                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1125                                 "AES GMAC testsuite not met\n");
1126                 return TEST_SKIPPED;
1127         }
1128
1129         return 0;
1130 }
1131
1132 static int
1133 mixed_cipher_hash_testsuite_setup(void)
1134 {
1135         struct crypto_testsuite_params *ts_params = &testsuite_params;
1136         uint8_t dev_id = ts_params->valid_devs[0];
1137         struct rte_cryptodev_info dev_info;
1138         uint64_t feat_flags;
1139         const enum rte_crypto_cipher_algorithm ciphers[] = {
1140                 RTE_CRYPTO_CIPHER_NULL,
1141                 RTE_CRYPTO_CIPHER_AES_CTR,
1142                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
1143                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1144         };
1145         const enum rte_crypto_auth_algorithm auths[] = {
1146                 RTE_CRYPTO_AUTH_NULL,
1147                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1148                 RTE_CRYPTO_AUTH_AES_CMAC,
1149                 RTE_CRYPTO_AUTH_ZUC_EIA3
1150         };
1151
1152         rte_cryptodev_info_get(dev_id, &dev_info);
1153         feat_flags = dev_info.feature_flags;
1154
1155         if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1156                         (global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1157                 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1158                                 "Cipher Hash testsuite not met\n");
1159                 return TEST_SKIPPED;
1160         }
1161
1162         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1163                         && check_auth_capabilities_supported(auths,
1164                         RTE_DIM(auths)) != 0) {
1165                 RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1166                                 "Cipher Hash testsuite not met\n");
1167                 return TEST_SKIPPED;
1168         }
1169
1170         return 0;
1171 }
1172
1173 static int
1174 esn_testsuite_setup(void)
1175 {
1176         struct crypto_testsuite_params *ts_params = &testsuite_params;
1177         uint8_t dev_id = ts_params->valid_devs[0];
1178         struct rte_cryptodev_info dev_info;
1179         const enum rte_crypto_cipher_algorithm ciphers[] = {
1180                 RTE_CRYPTO_CIPHER_AES_CBC
1181         };
1182         const enum rte_crypto_auth_algorithm auths[] = {
1183                 RTE_CRYPTO_AUTH_SHA1_HMAC
1184         };
1185
1186         rte_cryptodev_info_get(dev_id, &dev_info);
1187
1188         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1189                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1190                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1191                 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1192                                 "testsuite not met\n");
1193                 return TEST_SKIPPED;
1194         }
1195
1196         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1197                         && check_auth_capabilities_supported(auths,
1198                         RTE_DIM(auths)) != 0) {
1199                 RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1200                                 "testsuite not met\n");
1201                 return TEST_SKIPPED;
1202         }
1203
1204         return 0;
1205 }
1206
1207 static int
1208 multi_session_testsuite_setup(void)
1209 {
1210         struct crypto_testsuite_params *ts_params = &testsuite_params;
1211         uint8_t dev_id = ts_params->valid_devs[0];
1212         struct rte_cryptodev_info dev_info;
1213         const enum rte_crypto_cipher_algorithm ciphers[] = {
1214                 RTE_CRYPTO_CIPHER_AES_CBC
1215         };
1216         const enum rte_crypto_auth_algorithm auths[] = {
1217                 RTE_CRYPTO_AUTH_SHA512_HMAC
1218         };
1219
1220         rte_cryptodev_info_get(dev_id, &dev_info);
1221
1222         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1223                 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1224                                 "Session testsuite not met\n");
1225                 return TEST_SKIPPED;
1226         }
1227
1228         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1229                         && check_auth_capabilities_supported(auths,
1230                         RTE_DIM(auths)) != 0) {
1231                 RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1232                                 "Session testsuite not met\n");
1233                 return TEST_SKIPPED;
1234         }
1235
1236         return 0;
1237 }
1238
1239 static int
1240 negative_hmac_sha1_testsuite_setup(void)
1241 {
1242         struct crypto_testsuite_params *ts_params = &testsuite_params;
1243         uint8_t dev_id = ts_params->valid_devs[0];
1244         struct rte_cryptodev_info dev_info;
1245         const enum rte_crypto_cipher_algorithm ciphers[] = {
1246                 RTE_CRYPTO_CIPHER_AES_CBC
1247         };
1248         const enum rte_crypto_auth_algorithm auths[] = {
1249                 RTE_CRYPTO_AUTH_SHA1_HMAC
1250         };
1251
1252         rte_cryptodev_info_get(dev_id, &dev_info);
1253
1254         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1255                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1256                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1257                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1258                                 "HMAC SHA1 testsuite not met\n");
1259                 return TEST_SKIPPED;
1260         }
1261
1262         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1263                         && check_auth_capabilities_supported(auths,
1264                         RTE_DIM(auths)) != 0) {
1265                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1266                                 "HMAC SHA1 testsuite not met\n");
1267                 return TEST_SKIPPED;
1268         }
1269
1270         return 0;
1271 }
1272
1273 static int
1274 dev_configure_and_start(uint64_t ff_disable)
1275 {
1276         struct crypto_testsuite_params *ts_params = &testsuite_params;
1277         struct crypto_unittest_params *ut_params = &unittest_params;
1278
1279         uint16_t qp_id;
1280
1281         /* Clear unit test parameters before running test */
1282         memset(ut_params, 0, sizeof(*ut_params));
1283
1284         /* Reconfigure device to default parameters */
1285         ts_params->conf.socket_id = SOCKET_ID_ANY;
1286         ts_params->conf.ff_disable = ff_disable;
1287         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1288         ts_params->qp_conf.mp_session = ts_params->session_mpool;
1289         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1290
1291         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1292                         &ts_params->conf),
1293                         "Failed to configure cryptodev %u",
1294                         ts_params->valid_devs[0]);
1295
1296         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1297                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1298                         ts_params->valid_devs[0], qp_id,
1299                         &ts_params->qp_conf,
1300                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1301                         "Failed to setup queue pair %u on cryptodev %u",
1302                         qp_id, ts_params->valid_devs[0]);
1303         }
1304
1305
1306         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1307
1308         /* Start the device */
1309         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1310                         "Failed to start cryptodev %u",
1311                         ts_params->valid_devs[0]);
1312
1313         return TEST_SUCCESS;
1314 }
1315
1316 static int
1317 ut_setup(void)
1318 {
1319         /* Configure and start the device with security feature disabled */
1320         return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1321 }
1322
1323 static int
1324 ut_setup_security(void)
1325 {
1326         /* Configure and start the device with no features disabled */
1327         return dev_configure_and_start(0);
1328 }
1329
1330 static void
1331 ut_teardown(void)
1332 {
1333         struct crypto_testsuite_params *ts_params = &testsuite_params;
1334         struct crypto_unittest_params *ut_params = &unittest_params;
1335         struct rte_cryptodev_stats stats;
1336
1337         /* free crypto session structure */
1338 #ifdef RTE_LIB_SECURITY
1339         if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1340                 if (ut_params->sec_session) {
1341                         rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1342                                                 (ts_params->valid_devs[0]),
1343                                                 ut_params->sec_session);
1344                         ut_params->sec_session = NULL;
1345                 }
1346         } else
1347 #endif
1348         {
1349                 if (ut_params->sess) {
1350                         rte_cryptodev_sym_session_clear(
1351                                         ts_params->valid_devs[0],
1352                                         ut_params->sess);
1353                         rte_cryptodev_sym_session_free(ut_params->sess);
1354                         ut_params->sess = NULL;
1355                 }
1356         }
1357
1358         /* free crypto operation structure */
1359         if (ut_params->op)
1360                 rte_crypto_op_free(ut_params->op);
1361
1362         /*
1363          * free mbuf - both obuf and ibuf are usually the same,
1364          * so check if they point at the same address is necessary,
1365          * to avoid freeing the mbuf twice.
1366          */
1367         if (ut_params->obuf) {
1368                 rte_pktmbuf_free(ut_params->obuf);
1369                 if (ut_params->ibuf == ut_params->obuf)
1370                         ut_params->ibuf = 0;
1371                 ut_params->obuf = 0;
1372         }
1373         if (ut_params->ibuf) {
1374                 rte_pktmbuf_free(ut_params->ibuf);
1375                 ut_params->ibuf = 0;
1376         }
1377
1378         if (ts_params->mbuf_pool != NULL)
1379                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1380                         rte_mempool_avail_count(ts_params->mbuf_pool));
1381
1382         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1383
1384         /* Stop the device */
1385         rte_cryptodev_stop(ts_params->valid_devs[0]);
1386 }
1387
1388 static int
1389 test_device_configure_invalid_dev_id(void)
1390 {
1391         struct crypto_testsuite_params *ts_params = &testsuite_params;
1392         uint16_t dev_id, num_devs = 0;
1393
1394         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1395                         "Need at least %d devices for test", 1);
1396
1397         /* valid dev_id values */
1398         dev_id = ts_params->valid_devs[0];
1399
1400         /* Stop the device in case it's started so it can be configured */
1401         rte_cryptodev_stop(dev_id);
1402
1403         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1404                         "Failed test for rte_cryptodev_configure: "
1405                         "invalid dev_num %u", dev_id);
1406
1407         /* invalid dev_id values */
1408         dev_id = num_devs;
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         dev_id = 0xff;
1415
1416         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1417                         "Failed test for rte_cryptodev_configure:"
1418                         "invalid dev_num %u", dev_id);
1419
1420         return TEST_SUCCESS;
1421 }
1422
1423 static int
1424 test_device_configure_invalid_queue_pair_ids(void)
1425 {
1426         struct crypto_testsuite_params *ts_params = &testsuite_params;
1427         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1428
1429         /* Stop the device in case it's started so it can be configured */
1430         rte_cryptodev_stop(ts_params->valid_devs[0]);
1431
1432         /* valid - max value queue pairs */
1433         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1434
1435         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1436                         &ts_params->conf),
1437                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1438                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1439
1440         /* valid - one queue pairs */
1441         ts_params->conf.nb_queue_pairs = 1;
1442
1443         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1444                         &ts_params->conf),
1445                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1446                         ts_params->valid_devs[0],
1447                         ts_params->conf.nb_queue_pairs);
1448
1449
1450         /* invalid - zero queue pairs */
1451         ts_params->conf.nb_queue_pairs = 0;
1452
1453         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1454                         &ts_params->conf),
1455                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1456                         " invalid qps: %u",
1457                         ts_params->valid_devs[0],
1458                         ts_params->conf.nb_queue_pairs);
1459
1460
1461         /* invalid - max value supported by field queue pairs */
1462         ts_params->conf.nb_queue_pairs = UINT16_MAX;
1463
1464         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1465                         &ts_params->conf),
1466                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1467                         " invalid qps: %u",
1468                         ts_params->valid_devs[0],
1469                         ts_params->conf.nb_queue_pairs);
1470
1471
1472         /* invalid - max value + 1 queue pairs */
1473         ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1474
1475         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1476                         &ts_params->conf),
1477                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1478                         " invalid qps: %u",
1479                         ts_params->valid_devs[0],
1480                         ts_params->conf.nb_queue_pairs);
1481
1482         /* revert to original testsuite value */
1483         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1484
1485         return TEST_SUCCESS;
1486 }
1487
1488 static int
1489 test_queue_pair_descriptor_setup(void)
1490 {
1491         struct crypto_testsuite_params *ts_params = &testsuite_params;
1492         struct rte_cryptodev_qp_conf qp_conf = {
1493                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
1494         };
1495         uint16_t qp_id;
1496
1497         /* Stop the device in case it's started so it can be configured */
1498         rte_cryptodev_stop(ts_params->valid_devs[0]);
1499
1500         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1501                         &ts_params->conf),
1502                         "Failed to configure cryptodev %u",
1503                         ts_params->valid_devs[0]);
1504
1505         /*
1506          * Test various ring sizes on this device. memzones can't be
1507          * freed so are re-used if ring is released and re-created.
1508          */
1509         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1510         qp_conf.mp_session = ts_params->session_mpool;
1511         qp_conf.mp_session_private = ts_params->session_priv_mpool;
1512
1513         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1514                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1515                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1516                                 rte_cryptodev_socket_id(
1517                                                 ts_params->valid_devs[0])),
1518                                 "Failed test for "
1519                                 "rte_cryptodev_queue_pair_setup: num_inflights "
1520                                 "%u on qp %u on cryptodev %u",
1521                                 qp_conf.nb_descriptors, qp_id,
1522                                 ts_params->valid_devs[0]);
1523         }
1524
1525         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1526
1527         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1528                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1529                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1530                                 rte_cryptodev_socket_id(
1531                                                 ts_params->valid_devs[0])),
1532                                 "Failed test for"
1533                                 " rte_cryptodev_queue_pair_setup: num_inflights"
1534                                 " %u on qp %u on cryptodev %u",
1535                                 qp_conf.nb_descriptors, qp_id,
1536                                 ts_params->valid_devs[0]);
1537         }
1538
1539         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1540
1541         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1542                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1543                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1544                                 rte_cryptodev_socket_id(
1545                                                 ts_params->valid_devs[0])),
1546                                 "Failed test for "
1547                                 "rte_cryptodev_queue_pair_setup: num_inflights"
1548                                 " %u on qp %u on cryptodev %u",
1549                                 qp_conf.nb_descriptors, qp_id,
1550                                 ts_params->valid_devs[0]);
1551         }
1552
1553         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1554
1555         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1556                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1557                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1558                                 rte_cryptodev_socket_id(
1559                                                 ts_params->valid_devs[0])),
1560                                 "Failed test for"
1561                                 " rte_cryptodev_queue_pair_setup:"
1562                                 "num_inflights %u on qp %u on cryptodev %u",
1563                                 qp_conf.nb_descriptors, qp_id,
1564                                 ts_params->valid_devs[0]);
1565         }
1566
1567         /* test invalid queue pair id */
1568         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
1569
1570         qp_id = ts_params->conf.nb_queue_pairs;         /*invalid */
1571
1572         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1573                         ts_params->valid_devs[0],
1574                         qp_id, &qp_conf,
1575                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1576                         "Failed test for rte_cryptodev_queue_pair_setup:"
1577                         "invalid qp %u on cryptodev %u",
1578                         qp_id, ts_params->valid_devs[0]);
1579
1580         qp_id = 0xffff; /*invalid*/
1581
1582         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1583                         ts_params->valid_devs[0],
1584                         qp_id, &qp_conf,
1585                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1586                         "Failed test for rte_cryptodev_queue_pair_setup:"
1587                         "invalid qp %u on cryptodev %u",
1588                         qp_id, ts_params->valid_devs[0]);
1589
1590         return TEST_SUCCESS;
1591 }
1592
1593 /* ***** Plaintext data for tests ***** */
1594
1595 const char catch_22_quote_1[] =
1596                 "There was only one catch and that was Catch-22, which "
1597                 "specified that a concern for one's safety in the face of "
1598                 "dangers that were real and immediate was the process of a "
1599                 "rational mind. Orr was crazy and could be grounded. All he "
1600                 "had to do was ask; and as soon as he did, he would no longer "
1601                 "be crazy and would have to fly more missions. Orr would be "
1602                 "crazy to fly more missions and sane if he didn't, but if he "
1603                 "was sane he had to fly them. If he flew them he was crazy "
1604                 "and didn't have to; but if he didn't want to he was sane and "
1605                 "had to. Yossarian was moved very deeply by the absolute "
1606                 "simplicity of this clause of Catch-22 and let out a "
1607                 "respectful whistle. \"That's some catch, that Catch-22\", he "
1608                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
1609
1610 const char catch_22_quote[] =
1611                 "What a lousy earth! He wondered how many people were "
1612                 "destitute that same night even in his own prosperous country, "
1613                 "how many homes were shanties, how many husbands were drunk "
1614                 "and wives socked, and how many children were bullied, abused, "
1615                 "or abandoned. How many families hungered for food they could "
1616                 "not afford to buy? How many hearts were broken? How many "
1617                 "suicides would take place that same night, how many people "
1618                 "would go insane? How many cockroaches and landlords would "
1619                 "triumph? How many winners were losers, successes failures, "
1620                 "and rich men poor men? How many wise guys were stupid? How "
1621                 "many happy endings were unhappy endings? How many honest men "
1622                 "were liars, brave men cowards, loyal men traitors, how many "
1623                 "sainted men were corrupt, how many people in positions of "
1624                 "trust had sold their souls to bodyguards, how many had never "
1625                 "had souls? How many straight-and-narrow paths were crooked "
1626                 "paths? How many best families were worst families and how "
1627                 "many good people were bad people? When you added them all up "
1628                 "and then subtracted, you might be left with only the children, "
1629                 "and perhaps with Albert Einstein and an old violinist or "
1630                 "sculptor somewhere.";
1631
1632 #define QUOTE_480_BYTES         (480)
1633 #define QUOTE_512_BYTES         (512)
1634 #define QUOTE_768_BYTES         (768)
1635 #define QUOTE_1024_BYTES        (1024)
1636
1637
1638
1639 /* ***** SHA1 Hash Tests ***** */
1640
1641 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
1642
1643 static uint8_t hmac_sha1_key[] = {
1644         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1645         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1646         0xDE, 0xF4, 0xDE, 0xAD };
1647
1648 /* ***** SHA224 Hash Tests ***** */
1649
1650 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
1651
1652
1653 /* ***** AES-CBC Cipher Tests ***** */
1654
1655 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
1656 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
1657
1658 static uint8_t aes_cbc_key[] = {
1659         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1660         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1661
1662 static uint8_t aes_cbc_iv[] = {
1663         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1664         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1665
1666
1667 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1668
1669 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1670         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1671         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1672         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1673         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1674         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1675         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1676         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1677         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1678         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1679         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1680         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1681         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1682         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1683         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1684         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1685         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1686         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1687         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1688         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1689         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1690         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1691         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1692         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1693         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1694         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1695         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1696         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1697         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1698         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1699         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1700         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1701         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1702         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1703         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1704         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1705         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1706         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1707         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1708         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1709         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1710         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1711         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1712         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1713         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1714         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1715         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1716         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1717         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1718         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1719         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1720         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1721         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1722         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1723         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1724         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1725         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1726         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1727         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1728         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1729         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1730         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1731         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1732         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1733         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1734 };
1735
1736 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1737         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1738         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1739         0x18, 0x8c, 0x1d, 0x32
1740 };
1741
1742
1743 /* Multisession Vector context Test */
1744 /*Begin Session 0 */
1745 static uint8_t ms_aes_cbc_key0[] = {
1746         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1747         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1748 };
1749
1750 static uint8_t ms_aes_cbc_iv0[] = {
1751         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1752         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1753 };
1754
1755 static const uint8_t ms_aes_cbc_cipher0[] = {
1756                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1757                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1758                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1759                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1760                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1761                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1762                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1763                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1764                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1765                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1766                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1767                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1768                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1769                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1770                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1771                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1772                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1773                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1774                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1775                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1776                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1777                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1778                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1779                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1780                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1781                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1782                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1783                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1784                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1785                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1786                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1787                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1788                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1789                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1790                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1791                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1792                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1793                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1794                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1795                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1796                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1797                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1798                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1799                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1800                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1801                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1802                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1803                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1804                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1805                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1806                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1807                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1808                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1809                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1810                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1811                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1812                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1813                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1814                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1815                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1816                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1817                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1818                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1819                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1820 };
1821
1822
1823 static  uint8_t ms_hmac_key0[] = {
1824                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1825                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1826                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1827                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1828                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1829                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1830                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1831                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1832 };
1833
1834 static const uint8_t ms_hmac_digest0[] = {
1835                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1836                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1837                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1838                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1839                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1840                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1841                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1842                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1843                 };
1844
1845 /* End Session 0 */
1846 /* Begin session 1 */
1847
1848 static  uint8_t ms_aes_cbc_key1[] = {
1849                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1850                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1851 };
1852
1853 static  uint8_t ms_aes_cbc_iv1[] = {
1854         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1855         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1856 };
1857
1858 static const uint8_t ms_aes_cbc_cipher1[] = {
1859                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1860                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1861                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1862                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1863                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1864                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1865                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1866                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1867                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1868                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1869                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1870                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1871                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1872                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1873                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1874                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1875                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1876                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1877                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1878                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1879                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1880                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1881                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1882                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1883                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1884                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1885                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1886                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1887                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1888                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1889                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1890                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1891                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1892                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1893                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1894                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1895                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1896                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1897                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1898                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1899                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1900                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1901                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1902                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1903                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1904                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1905                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1906                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1907                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1908                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1909                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1910                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1911                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1912                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1913                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1914                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1915                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1916                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1917                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1918                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1919                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1920                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1921                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1922                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1923
1924 };
1925
1926 static uint8_t ms_hmac_key1[] = {
1927                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1928                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1929                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1930                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1931                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1932                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1933                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1934                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1935 };
1936
1937 static const uint8_t ms_hmac_digest1[] = {
1938                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1939                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1940                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1941                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1942                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1943                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1944                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1945                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1946 };
1947 /* End Session 1  */
1948 /* Begin Session 2 */
1949 static  uint8_t ms_aes_cbc_key2[] = {
1950                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1951                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1952 };
1953
1954 static  uint8_t ms_aes_cbc_iv2[] = {
1955                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1956                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1957 };
1958
1959 static const uint8_t ms_aes_cbc_cipher2[] = {
1960                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1961                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1962                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1963                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1964                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1965                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1966                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1967                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1968                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1969                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1970                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1971                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1972                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1973                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1974                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1975                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1976                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1977                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1978                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1979                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1980                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1981                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1982                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1983                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1984                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1985                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1986                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1987                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1988                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1989                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1990                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1991                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1992                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1993                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1994                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1995                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1996                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1997                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1998                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1999                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2000                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2001                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2002                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2003                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2004                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2005                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2006                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2007                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2008                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2009                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2010                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2011                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2012                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2013                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2014                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2015                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2016                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2017                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2018                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2019                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2020                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2021                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2022                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2023                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2024 };
2025
2026 static  uint8_t ms_hmac_key2[] = {
2027                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2028                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2029                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2030                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2031                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2032                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2033                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2034                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2035 };
2036
2037 static const uint8_t ms_hmac_digest2[] = {
2038                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2039                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2040                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2041                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2042                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2043                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2044                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2045                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2046 };
2047
2048 /* End Session 2 */
2049
2050
2051 static int
2052 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2053 {
2054         struct crypto_testsuite_params *ts_params = &testsuite_params;
2055         struct crypto_unittest_params *ut_params = &unittest_params;
2056
2057         /* Verify the capabilities */
2058         struct rte_cryptodev_sym_capability_idx cap_idx;
2059         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2060         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2061         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2062                         &cap_idx) == NULL)
2063                 return TEST_SKIPPED;
2064         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2065         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2066         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2067                         &cap_idx) == NULL)
2068                 return TEST_SKIPPED;
2069
2070         /* Generate test mbuf data and space for digest */
2071         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2072                         catch_22_quote, QUOTE_512_BYTES, 0);
2073
2074         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2075                         DIGEST_BYTE_LENGTH_SHA1);
2076         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2077
2078         /* Setup Cipher Parameters */
2079         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2080         ut_params->cipher_xform.next = &ut_params->auth_xform;
2081
2082         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2083         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2084         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2085         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2086         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2087         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2088
2089         /* Setup HMAC Parameters */
2090         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2091
2092         ut_params->auth_xform.next = NULL;
2093
2094         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2095         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2096         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2097         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2098         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2099
2100         ut_params->sess = rte_cryptodev_sym_session_create(
2101                         ts_params->session_mpool);
2102
2103         /* Create crypto session*/
2104         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2105                         ut_params->sess, &ut_params->cipher_xform,
2106                         ts_params->session_priv_mpool);
2107         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2108
2109         /* Generate crypto op data structure */
2110         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2111                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2112         TEST_ASSERT_NOT_NULL(ut_params->op,
2113                         "Failed to allocate symmetric crypto operation struct");
2114
2115         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2116
2117         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2118
2119         /* set crypto operation source mbuf */
2120         sym_op->m_src = ut_params->ibuf;
2121
2122         /* Set crypto operation authentication parameters */
2123         sym_op->auth.digest.data = ut_params->digest;
2124         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2125                         ut_params->ibuf, QUOTE_512_BYTES);
2126
2127         sym_op->auth.data.offset = 0;
2128         sym_op->auth.data.length = QUOTE_512_BYTES;
2129
2130         /* Copy IV at the end of the crypto operation */
2131         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2132                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2133
2134         /* Set crypto operation cipher parameters */
2135         sym_op->cipher.data.offset = 0;
2136         sym_op->cipher.data.length = QUOTE_512_BYTES;
2137
2138         /* Process crypto operation */
2139         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2140                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2141                         ut_params->op);
2142         else
2143                 TEST_ASSERT_NOT_NULL(
2144                         process_crypto_request(ts_params->valid_devs[0],
2145                                 ut_params->op),
2146                                 "failed to process sym crypto op");
2147
2148         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2149                         "crypto op processing failed");
2150
2151         /* Validate obuf */
2152         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2153                         uint8_t *);
2154
2155         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2156                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2157                         QUOTE_512_BYTES,
2158                         "ciphertext data not as expected");
2159
2160         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2161
2162         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2163                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2164                         gbl_driver_id == rte_cryptodev_driver_id_get(
2165                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2166                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2167                                         DIGEST_BYTE_LENGTH_SHA1,
2168                         "Generated digest data not as expected");
2169
2170         return TEST_SUCCESS;
2171 }
2172
2173 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2174
2175 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2176
2177 static uint8_t hmac_sha512_key[] = {
2178         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2179         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2180         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2181         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2182         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2183         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2184         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2185         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2186
2187 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2188         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2189         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2190         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2191         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2192         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2193         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2194         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2195         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2196
2197
2198
2199 static int
2200 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2201                 struct crypto_unittest_params *ut_params,
2202                 uint8_t *cipher_key,
2203                 uint8_t *hmac_key);
2204
2205 static int
2206 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2207                 struct crypto_unittest_params *ut_params,
2208                 struct crypto_testsuite_params *ts_params,
2209                 const uint8_t *cipher,
2210                 const uint8_t *digest,
2211                 const uint8_t *iv);
2212
2213
2214 static int
2215 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2216                 struct crypto_unittest_params *ut_params,
2217                 uint8_t *cipher_key,
2218                 uint8_t *hmac_key)
2219 {
2220
2221         /* Setup Cipher Parameters */
2222         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2223         ut_params->cipher_xform.next = NULL;
2224
2225         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2226         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2227         ut_params->cipher_xform.cipher.key.data = cipher_key;
2228         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2229         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2230         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2231
2232         /* Setup HMAC Parameters */
2233         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2234         ut_params->auth_xform.next = &ut_params->cipher_xform;
2235
2236         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2237         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2238         ut_params->auth_xform.auth.key.data = hmac_key;
2239         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2240         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2241
2242         return TEST_SUCCESS;
2243 }
2244
2245
2246 static int
2247 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2248                 struct crypto_unittest_params *ut_params,
2249                 struct crypto_testsuite_params *ts_params,
2250                 const uint8_t *cipher,
2251                 const uint8_t *digest,
2252                 const uint8_t *iv)
2253 {
2254         /* Generate test mbuf data and digest */
2255         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2256                         (const char *)
2257                         cipher,
2258                         QUOTE_512_BYTES, 0);
2259
2260         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2261                         DIGEST_BYTE_LENGTH_SHA512);
2262         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2263
2264         rte_memcpy(ut_params->digest,
2265                         digest,
2266                         DIGEST_BYTE_LENGTH_SHA512);
2267
2268         /* Generate Crypto op data structure */
2269         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2270                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2271         TEST_ASSERT_NOT_NULL(ut_params->op,
2272                         "Failed to allocate symmetric crypto operation struct");
2273
2274         rte_crypto_op_attach_sym_session(ut_params->op, sess);
2275
2276         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2277
2278         /* set crypto operation source mbuf */
2279         sym_op->m_src = ut_params->ibuf;
2280
2281         sym_op->auth.digest.data = ut_params->digest;
2282         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2283                         ut_params->ibuf, QUOTE_512_BYTES);
2284
2285         sym_op->auth.data.offset = 0;
2286         sym_op->auth.data.length = QUOTE_512_BYTES;
2287
2288         /* Copy IV at the end of the crypto operation */
2289         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2290                         iv, CIPHER_IV_LENGTH_AES_CBC);
2291
2292         sym_op->cipher.data.offset = 0;
2293         sym_op->cipher.data.length = QUOTE_512_BYTES;
2294
2295         /* Process crypto operation */
2296         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2297                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2298                         ut_params->op);
2299         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2300                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2301                                 ut_params->op, 1, 1, 0, 0);
2302         else
2303                 TEST_ASSERT_NOT_NULL(
2304                                 process_crypto_request(ts_params->valid_devs[0],
2305                                         ut_params->op),
2306                                         "failed to process sym crypto op");
2307
2308         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2309                         "crypto op processing failed");
2310
2311         ut_params->obuf = ut_params->op->sym->m_src;
2312
2313         /* Validate obuf */
2314         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2315                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2316                         catch_22_quote,
2317                         QUOTE_512_BYTES,
2318                         "Plaintext data not as expected");
2319
2320         /* Validate obuf */
2321         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2322                         "Digest verification failed");
2323
2324         return TEST_SUCCESS;
2325 }
2326
2327 static int
2328 test_blockcipher(enum blockcipher_test_type test_type)
2329 {
2330         struct crypto_testsuite_params *ts_params = &testsuite_params;
2331         int status;
2332
2333         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2334                 ts_params->op_mpool,
2335                 ts_params->session_mpool, ts_params->session_priv_mpool,
2336                 ts_params->valid_devs[0],
2337                 test_type);
2338
2339         if (status == -ENOTSUP)
2340                 return status;
2341
2342         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2343
2344         return TEST_SUCCESS;
2345 }
2346
2347 static int
2348 test_AES_cipheronly_all(void)
2349 {
2350         return test_blockcipher(BLKCIPHER_AES_CIPHERONLY_TYPE);
2351 }
2352
2353 static int
2354 test_AES_docsis_all(void)
2355 {
2356         /* Data-path service does not support DOCSIS yet */
2357         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2358                 return TEST_SKIPPED;
2359         return test_blockcipher(BLKCIPHER_AES_DOCSIS_TYPE);
2360 }
2361
2362 static int
2363 test_DES_docsis_all(void)
2364 {
2365         /* Data-path service does not support DOCSIS yet */
2366         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2367                 return TEST_SKIPPED;
2368         return test_blockcipher(BLKCIPHER_DES_DOCSIS_TYPE);
2369 }
2370
2371 static int
2372 test_DES_cipheronly_all(void)
2373 {
2374         return test_blockcipher(BLKCIPHER_DES_CIPHERONLY_TYPE);
2375 }
2376
2377 static int
2378 test_authonly_all(void)
2379 {
2380         return test_blockcipher(BLKCIPHER_AUTHONLY_TYPE);
2381 }
2382
2383 static int
2384 test_AES_chain_all(void)
2385 {
2386         return test_blockcipher(BLKCIPHER_AES_CHAIN_TYPE);
2387 }
2388
2389 static int
2390 test_3DES_chain_all(void)
2391 {
2392         return test_blockcipher(BLKCIPHER_3DES_CHAIN_TYPE);
2393 }
2394
2395 static int
2396 test_3DES_cipheronly_all(void)
2397 {
2398         return test_blockcipher(BLKCIPHER_3DES_CIPHERONLY_TYPE);
2399 }
2400
2401 /* ***** SNOW 3G Tests ***** */
2402 static int
2403 create_wireless_algo_hash_session(uint8_t dev_id,
2404         const uint8_t *key, const uint8_t key_len,
2405         const uint8_t iv_len, const uint8_t auth_len,
2406         enum rte_crypto_auth_operation op,
2407         enum rte_crypto_auth_algorithm algo)
2408 {
2409         uint8_t hash_key[key_len];
2410         int status;
2411
2412         struct crypto_testsuite_params *ts_params = &testsuite_params;
2413         struct crypto_unittest_params *ut_params = &unittest_params;
2414
2415         memcpy(hash_key, key, key_len);
2416
2417         debug_hexdump(stdout, "key:", key, key_len);
2418
2419         /* Setup Authentication Parameters */
2420         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2421         ut_params->auth_xform.next = NULL;
2422
2423         ut_params->auth_xform.auth.op = op;
2424         ut_params->auth_xform.auth.algo = algo;
2425         ut_params->auth_xform.auth.key.length = key_len;
2426         ut_params->auth_xform.auth.key.data = hash_key;
2427         ut_params->auth_xform.auth.digest_length = auth_len;
2428         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2429         ut_params->auth_xform.auth.iv.length = iv_len;
2430         ut_params->sess = rte_cryptodev_sym_session_create(
2431                         ts_params->session_mpool);
2432
2433         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2434                         &ut_params->auth_xform,
2435                         ts_params->session_priv_mpool);
2436         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2437         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2438         return 0;
2439 }
2440
2441 static int
2442 create_wireless_algo_cipher_session(uint8_t dev_id,
2443                         enum rte_crypto_cipher_operation op,
2444                         enum rte_crypto_cipher_algorithm algo,
2445                         const uint8_t *key, const uint8_t key_len,
2446                         uint8_t iv_len)
2447 {
2448         uint8_t cipher_key[key_len];
2449         int status;
2450         struct crypto_testsuite_params *ts_params = &testsuite_params;
2451         struct crypto_unittest_params *ut_params = &unittest_params;
2452
2453         memcpy(cipher_key, key, key_len);
2454
2455         /* Setup Cipher Parameters */
2456         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2457         ut_params->cipher_xform.next = NULL;
2458
2459         ut_params->cipher_xform.cipher.algo = algo;
2460         ut_params->cipher_xform.cipher.op = op;
2461         ut_params->cipher_xform.cipher.key.data = cipher_key;
2462         ut_params->cipher_xform.cipher.key.length = key_len;
2463         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2464         ut_params->cipher_xform.cipher.iv.length = iv_len;
2465
2466         debug_hexdump(stdout, "key:", key, key_len);
2467
2468         /* Create Crypto session */
2469         ut_params->sess = rte_cryptodev_sym_session_create(
2470                         ts_params->session_mpool);
2471
2472         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2473                         &ut_params->cipher_xform,
2474                         ts_params->session_priv_mpool);
2475         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2476         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2477         return 0;
2478 }
2479
2480 static int
2481 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2482                         unsigned int cipher_len,
2483                         unsigned int cipher_offset)
2484 {
2485         struct crypto_testsuite_params *ts_params = &testsuite_params;
2486         struct crypto_unittest_params *ut_params = &unittest_params;
2487
2488         /* Generate Crypto op data structure */
2489         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2490                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2491         TEST_ASSERT_NOT_NULL(ut_params->op,
2492                                 "Failed to allocate pktmbuf offload");
2493
2494         /* Set crypto operation data parameters */
2495         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2496
2497         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2498
2499         /* set crypto operation source mbuf */
2500         sym_op->m_src = ut_params->ibuf;
2501
2502         /* iv */
2503         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2504                         iv, iv_len);
2505         sym_op->cipher.data.length = cipher_len;
2506         sym_op->cipher.data.offset = cipher_offset;
2507         return 0;
2508 }
2509
2510 static int
2511 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2512                         unsigned int cipher_len,
2513                         unsigned int cipher_offset)
2514 {
2515         struct crypto_testsuite_params *ts_params = &testsuite_params;
2516         struct crypto_unittest_params *ut_params = &unittest_params;
2517
2518         /* Generate Crypto op data structure */
2519         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2520                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2521         TEST_ASSERT_NOT_NULL(ut_params->op,
2522                                 "Failed to allocate pktmbuf offload");
2523
2524         /* Set crypto operation data parameters */
2525         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2526
2527         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2528
2529         /* set crypto operation source mbuf */
2530         sym_op->m_src = ut_params->ibuf;
2531         sym_op->m_dst = ut_params->obuf;
2532
2533         /* iv */
2534         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2535                         iv, iv_len);
2536         sym_op->cipher.data.length = cipher_len;
2537         sym_op->cipher.data.offset = cipher_offset;
2538         return 0;
2539 }
2540
2541 static int
2542 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2543                 enum rte_crypto_cipher_operation cipher_op,
2544                 enum rte_crypto_auth_operation auth_op,
2545                 enum rte_crypto_auth_algorithm auth_algo,
2546                 enum rte_crypto_cipher_algorithm cipher_algo,
2547                 const uint8_t *key, uint8_t key_len,
2548                 uint8_t auth_iv_len, uint8_t auth_len,
2549                 uint8_t cipher_iv_len)
2550
2551 {
2552         uint8_t cipher_auth_key[key_len];
2553         int status;
2554
2555         struct crypto_testsuite_params *ts_params = &testsuite_params;
2556         struct crypto_unittest_params *ut_params = &unittest_params;
2557
2558         memcpy(cipher_auth_key, key, key_len);
2559
2560         /* Setup Authentication Parameters */
2561         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2562         ut_params->auth_xform.next = NULL;
2563
2564         ut_params->auth_xform.auth.op = auth_op;
2565         ut_params->auth_xform.auth.algo = auth_algo;
2566         ut_params->auth_xform.auth.key.length = key_len;
2567         /* Hash key = cipher key */
2568         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2569         ut_params->auth_xform.auth.digest_length = auth_len;
2570         /* Auth IV will be after cipher IV */
2571         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2572         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2573
2574         /* Setup Cipher Parameters */
2575         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2576         ut_params->cipher_xform.next = &ut_params->auth_xform;
2577
2578         ut_params->cipher_xform.cipher.algo = cipher_algo;
2579         ut_params->cipher_xform.cipher.op = cipher_op;
2580         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2581         ut_params->cipher_xform.cipher.key.length = key_len;
2582         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2583         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2584
2585         debug_hexdump(stdout, "key:", key, key_len);
2586
2587         /* Create Crypto session*/
2588         ut_params->sess = rte_cryptodev_sym_session_create(
2589                         ts_params->session_mpool);
2590         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2591
2592         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2593                         &ut_params->cipher_xform,
2594                         ts_params->session_priv_mpool);
2595         if (status == -ENOTSUP)
2596                 return TEST_SKIPPED;
2597
2598         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2599         return 0;
2600 }
2601
2602 static int
2603 create_wireless_cipher_auth_session(uint8_t dev_id,
2604                 enum rte_crypto_cipher_operation cipher_op,
2605                 enum rte_crypto_auth_operation auth_op,
2606                 enum rte_crypto_auth_algorithm auth_algo,
2607                 enum rte_crypto_cipher_algorithm cipher_algo,
2608                 const struct wireless_test_data *tdata)
2609 {
2610         const uint8_t key_len = tdata->key.len;
2611         uint8_t cipher_auth_key[key_len];
2612         int status;
2613
2614         struct crypto_testsuite_params *ts_params = &testsuite_params;
2615         struct crypto_unittest_params *ut_params = &unittest_params;
2616         const uint8_t *key = tdata->key.data;
2617         const uint8_t auth_len = tdata->digest.len;
2618         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2619         uint8_t auth_iv_len = tdata->auth_iv.len;
2620
2621         memcpy(cipher_auth_key, key, key_len);
2622
2623         /* Setup Authentication Parameters */
2624         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2625         ut_params->auth_xform.next = NULL;
2626
2627         ut_params->auth_xform.auth.op = auth_op;
2628         ut_params->auth_xform.auth.algo = auth_algo;
2629         ut_params->auth_xform.auth.key.length = key_len;
2630         /* Hash key = cipher key */
2631         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2632         ut_params->auth_xform.auth.digest_length = auth_len;
2633         /* Auth IV will be after cipher IV */
2634         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2635         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2636
2637         /* Setup Cipher Parameters */
2638         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2639         ut_params->cipher_xform.next = &ut_params->auth_xform;
2640
2641         ut_params->cipher_xform.cipher.algo = cipher_algo;
2642         ut_params->cipher_xform.cipher.op = cipher_op;
2643         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2644         ut_params->cipher_xform.cipher.key.length = key_len;
2645         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2646         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2647
2648
2649         debug_hexdump(stdout, "key:", key, key_len);
2650
2651         /* Create Crypto session*/
2652         ut_params->sess = rte_cryptodev_sym_session_create(
2653                         ts_params->session_mpool);
2654
2655         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2656                         &ut_params->cipher_xform,
2657                         ts_params->session_priv_mpool);
2658         if (status == -ENOTSUP)
2659                 return TEST_SKIPPED;
2660
2661         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2662         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2663         return 0;
2664 }
2665
2666 static int
2667 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2668                 const struct wireless_test_data *tdata)
2669 {
2670         return create_wireless_cipher_auth_session(dev_id,
2671                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2672                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2673                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2674 }
2675
2676 static int
2677 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2678                 enum rte_crypto_cipher_operation cipher_op,
2679                 enum rte_crypto_auth_operation auth_op,
2680                 enum rte_crypto_auth_algorithm auth_algo,
2681                 enum rte_crypto_cipher_algorithm cipher_algo,
2682                 const uint8_t *key, const uint8_t key_len,
2683                 uint8_t auth_iv_len, uint8_t auth_len,
2684                 uint8_t cipher_iv_len)
2685 {
2686         uint8_t auth_cipher_key[key_len];
2687         int status;
2688         struct crypto_testsuite_params *ts_params = &testsuite_params;
2689         struct crypto_unittest_params *ut_params = &unittest_params;
2690
2691         memcpy(auth_cipher_key, key, key_len);
2692
2693         /* Setup Authentication Parameters */
2694         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2695         ut_params->auth_xform.auth.op = auth_op;
2696         ut_params->auth_xform.next = &ut_params->cipher_xform;
2697         ut_params->auth_xform.auth.algo = auth_algo;
2698         ut_params->auth_xform.auth.key.length = key_len;
2699         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2700         ut_params->auth_xform.auth.digest_length = auth_len;
2701         /* Auth IV will be after cipher IV */
2702         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2703         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2704
2705         /* Setup Cipher Parameters */
2706         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2707         ut_params->cipher_xform.next = NULL;
2708         ut_params->cipher_xform.cipher.algo = cipher_algo;
2709         ut_params->cipher_xform.cipher.op = cipher_op;
2710         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2711         ut_params->cipher_xform.cipher.key.length = key_len;
2712         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2713         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2714
2715         debug_hexdump(stdout, "key:", key, key_len);
2716
2717         /* Create Crypto session*/
2718         ut_params->sess = rte_cryptodev_sym_session_create(
2719                         ts_params->session_mpool);
2720         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2721
2722         if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2723                 ut_params->auth_xform.next = NULL;
2724                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2725                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2726                                 &ut_params->cipher_xform,
2727                                 ts_params->session_priv_mpool);
2728
2729         } else
2730                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2731                                 &ut_params->auth_xform,
2732                                 ts_params->session_priv_mpool);
2733
2734         if (status == -ENOTSUP)
2735                 return TEST_SKIPPED;
2736
2737         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2738
2739         return 0;
2740 }
2741
2742 static int
2743 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2744                 unsigned int auth_tag_len,
2745                 const uint8_t *iv, unsigned int iv_len,
2746                 unsigned int data_pad_len,
2747                 enum rte_crypto_auth_operation op,
2748                 unsigned int auth_len, unsigned int auth_offset)
2749 {
2750         struct crypto_testsuite_params *ts_params = &testsuite_params;
2751
2752         struct crypto_unittest_params *ut_params = &unittest_params;
2753
2754         /* Generate Crypto op data structure */
2755         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2756                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2757         TEST_ASSERT_NOT_NULL(ut_params->op,
2758                 "Failed to allocate pktmbuf offload");
2759
2760         /* Set crypto operation data parameters */
2761         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2762
2763         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2764
2765         /* set crypto operation source mbuf */
2766         sym_op->m_src = ut_params->ibuf;
2767
2768         /* iv */
2769         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2770                         iv, iv_len);
2771         /* digest */
2772         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2773                                         ut_params->ibuf, auth_tag_len);
2774
2775         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2776                                 "no room to append auth tag");
2777         ut_params->digest = sym_op->auth.digest.data;
2778         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2779                         ut_params->ibuf, data_pad_len);
2780         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2781                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2782         else
2783                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2784
2785         debug_hexdump(stdout, "digest:",
2786                 sym_op->auth.digest.data,
2787                 auth_tag_len);
2788
2789         sym_op->auth.data.length = auth_len;
2790         sym_op->auth.data.offset = auth_offset;
2791
2792         return 0;
2793 }
2794
2795 static int
2796 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2797         enum rte_crypto_auth_operation op)
2798 {
2799         struct crypto_testsuite_params *ts_params = &testsuite_params;
2800         struct crypto_unittest_params *ut_params = &unittest_params;
2801
2802         const uint8_t *auth_tag = tdata->digest.data;
2803         const unsigned int auth_tag_len = tdata->digest.len;
2804         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2805         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2806
2807         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2808         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2809         const uint8_t *auth_iv = tdata->auth_iv.data;
2810         const uint8_t auth_iv_len = tdata->auth_iv.len;
2811         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2812         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2813
2814         /* Generate Crypto op data structure */
2815         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2816                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2817         TEST_ASSERT_NOT_NULL(ut_params->op,
2818                         "Failed to allocate pktmbuf offload");
2819         /* Set crypto operation data parameters */
2820         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2821
2822         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2823
2824         /* set crypto operation source mbuf */
2825         sym_op->m_src = ut_params->ibuf;
2826
2827         /* digest */
2828         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2829                         ut_params->ibuf, auth_tag_len);
2830
2831         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2832                         "no room to append auth tag");
2833         ut_params->digest = sym_op->auth.digest.data;
2834         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2835                         ut_params->ibuf, data_pad_len);
2836         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2837                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2838         else
2839                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2840
2841         debug_hexdump(stdout, "digest:",
2842                 sym_op->auth.digest.data,
2843                 auth_tag_len);
2844
2845         /* Copy cipher and auth IVs at the end of the crypto operation */
2846         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2847                                                 IV_OFFSET);
2848         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2849         iv_ptr += cipher_iv_len;
2850         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2851
2852         sym_op->cipher.data.length = cipher_len;
2853         sym_op->cipher.data.offset = 0;
2854         sym_op->auth.data.length = auth_len;
2855         sym_op->auth.data.offset = 0;
2856
2857         return 0;
2858 }
2859
2860 static int
2861 create_zuc_cipher_hash_generate_operation(
2862                 const struct wireless_test_data *tdata)
2863 {
2864         return create_wireless_cipher_hash_operation(tdata,
2865                 RTE_CRYPTO_AUTH_OP_GENERATE);
2866 }
2867
2868 static int
2869 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2870                 const unsigned auth_tag_len,
2871                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2872                 unsigned data_pad_len,
2873                 enum rte_crypto_auth_operation op,
2874                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2875                 const unsigned cipher_len, const unsigned cipher_offset,
2876                 const unsigned auth_len, const unsigned auth_offset)
2877 {
2878         struct crypto_testsuite_params *ts_params = &testsuite_params;
2879         struct crypto_unittest_params *ut_params = &unittest_params;
2880
2881         enum rte_crypto_cipher_algorithm cipher_algo =
2882                         ut_params->cipher_xform.cipher.algo;
2883         enum rte_crypto_auth_algorithm auth_algo =
2884                         ut_params->auth_xform.auth.algo;
2885
2886         /* Generate Crypto op data structure */
2887         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2888                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2889         TEST_ASSERT_NOT_NULL(ut_params->op,
2890                         "Failed to allocate pktmbuf offload");
2891         /* Set crypto operation data parameters */
2892         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2893
2894         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2895
2896         /* set crypto operation source mbuf */
2897         sym_op->m_src = ut_params->ibuf;
2898
2899         /* digest */
2900         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2901                         ut_params->ibuf, auth_tag_len);
2902
2903         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2904                         "no room to append auth tag");
2905         ut_params->digest = sym_op->auth.digest.data;
2906
2907         if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2908                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2909                                 ut_params->ibuf, data_pad_len);
2910         } else {
2911                 struct rte_mbuf *m = ut_params->ibuf;
2912                 unsigned int offset = data_pad_len;
2913
2914                 while (offset > m->data_len && m->next != NULL) {
2915                         offset -= m->data_len;
2916                         m = m->next;
2917                 }
2918                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2919                         m, offset);
2920         }
2921
2922         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2923                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2924         else
2925                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2926
2927         debug_hexdump(stdout, "digest:",
2928                 sym_op->auth.digest.data,
2929                 auth_tag_len);
2930
2931         /* Copy cipher and auth IVs at the end of the crypto operation */
2932         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2933                                                 IV_OFFSET);
2934         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2935         iv_ptr += cipher_iv_len;
2936         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2937
2938         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2939                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2940                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2941                 sym_op->cipher.data.length = cipher_len;
2942                 sym_op->cipher.data.offset = cipher_offset;
2943         } else {
2944                 sym_op->cipher.data.length = cipher_len >> 3;
2945                 sym_op->cipher.data.offset = cipher_offset >> 3;
2946         }
2947
2948         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2949                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2950                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2951                 sym_op->auth.data.length = auth_len;
2952                 sym_op->auth.data.offset = auth_offset;
2953         } else {
2954                 sym_op->auth.data.length = auth_len >> 3;
2955                 sym_op->auth.data.offset = auth_offset >> 3;
2956         }
2957
2958         return 0;
2959 }
2960
2961 static int
2962 create_wireless_algo_auth_cipher_operation(
2963                 const uint8_t *auth_tag, unsigned int auth_tag_len,
2964                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2965                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2966                 unsigned int data_pad_len,
2967                 unsigned int cipher_len, unsigned int cipher_offset,
2968                 unsigned int auth_len, unsigned int auth_offset,
2969                 uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2970 {
2971         struct crypto_testsuite_params *ts_params = &testsuite_params;
2972         struct crypto_unittest_params *ut_params = &unittest_params;
2973
2974         enum rte_crypto_cipher_algorithm cipher_algo =
2975                         ut_params->cipher_xform.cipher.algo;
2976         enum rte_crypto_auth_algorithm auth_algo =
2977                         ut_params->auth_xform.auth.algo;
2978
2979         /* Generate Crypto op data structure */
2980         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2981                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2982         TEST_ASSERT_NOT_NULL(ut_params->op,
2983                         "Failed to allocate pktmbuf offload");
2984
2985         /* Set crypto operation data parameters */
2986         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2987
2988         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2989
2990         /* set crypto operation mbufs */
2991         sym_op->m_src = ut_params->ibuf;
2992         if (op_mode == OUT_OF_PLACE)
2993                 sym_op->m_dst = ut_params->obuf;
2994
2995         /* digest */
2996         if (!do_sgl) {
2997                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2998                         (op_mode == IN_PLACE ?
2999                                 ut_params->ibuf : ut_params->obuf),
3000                         uint8_t *, data_pad_len);
3001                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
3002                         (op_mode == IN_PLACE ?
3003                                 ut_params->ibuf : ut_params->obuf),
3004                         data_pad_len);
3005                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
3006         } else {
3007                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
3008                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
3009                                 sym_op->m_src : sym_op->m_dst);
3010                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
3011                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
3012                         sgl_buf = sgl_buf->next;
3013                 }
3014                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
3015                                 uint8_t *, remaining_off);
3016                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
3017                                 remaining_off);
3018                 memset(sym_op->auth.digest.data, 0, remaining_off);
3019                 while (sgl_buf->next != NULL) {
3020                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
3021                                 0, rte_pktmbuf_data_len(sgl_buf));
3022                         sgl_buf = sgl_buf->next;
3023                 }
3024         }
3025
3026         /* Copy digest for the verification */
3027         if (verify)
3028                 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3029
3030         /* Copy cipher and auth IVs at the end of the crypto operation */
3031         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3032                         ut_params->op, uint8_t *, IV_OFFSET);
3033
3034         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3035         iv_ptr += cipher_iv_len;
3036         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3037
3038         /* Only copy over the offset data needed from src to dst in OOP,
3039          * if the auth and cipher offsets are not aligned
3040          */
3041         if (op_mode == OUT_OF_PLACE) {
3042                 if (cipher_offset > auth_offset)
3043                         rte_memcpy(
3044                                 rte_pktmbuf_mtod_offset(
3045                                         sym_op->m_dst,
3046                                         uint8_t *, auth_offset >> 3),
3047                                 rte_pktmbuf_mtod_offset(
3048                                         sym_op->m_src,
3049                                         uint8_t *, auth_offset >> 3),
3050                                 ((cipher_offset >> 3) - (auth_offset >> 3)));
3051         }
3052
3053         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3054                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3055                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3056                 sym_op->cipher.data.length = cipher_len;
3057                 sym_op->cipher.data.offset = cipher_offset;
3058         } else {
3059                 sym_op->cipher.data.length = cipher_len >> 3;
3060                 sym_op->cipher.data.offset = cipher_offset >> 3;
3061         }
3062
3063         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3064                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3065                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3066                 sym_op->auth.data.length = auth_len;
3067                 sym_op->auth.data.offset = auth_offset;
3068         } else {
3069                 sym_op->auth.data.length = auth_len >> 3;
3070                 sym_op->auth.data.offset = auth_offset >> 3;
3071         }
3072
3073         return 0;
3074 }
3075
3076 static int
3077 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3078 {
3079         struct crypto_testsuite_params *ts_params = &testsuite_params;
3080         struct crypto_unittest_params *ut_params = &unittest_params;
3081
3082         int retval;
3083         unsigned plaintext_pad_len;
3084         unsigned plaintext_len;
3085         uint8_t *plaintext;
3086         struct rte_cryptodev_info dev_info;
3087
3088         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3089         uint64_t feat_flags = dev_info.feature_flags;
3090
3091         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3092                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3093                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3094                 return TEST_SKIPPED;
3095         }
3096
3097         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3098                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3099                 printf("Device doesn't support RAW data-path APIs.\n");
3100                 return TEST_SKIPPED;
3101         }
3102
3103         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3104                 return TEST_SKIPPED;
3105
3106         /* Verify the capabilities */
3107         struct rte_cryptodev_sym_capability_idx cap_idx;
3108         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3109         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3110         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3111                         &cap_idx) == NULL)
3112                 return TEST_SKIPPED;
3113
3114         /* Create SNOW 3G session */
3115         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3116                         tdata->key.data, tdata->key.len,
3117                         tdata->auth_iv.len, tdata->digest.len,
3118                         RTE_CRYPTO_AUTH_OP_GENERATE,
3119                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3120         if (retval < 0)
3121                 return retval;
3122
3123         /* alloc mbuf and set payload */
3124         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3125
3126         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3127         rte_pktmbuf_tailroom(ut_params->ibuf));
3128
3129         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3130         /* Append data which is padded to a multiple of */
3131         /* the algorithms block size */
3132         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3133         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3134                                 plaintext_pad_len);
3135         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3136
3137         /* Create SNOW 3G operation */
3138         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3139                         tdata->auth_iv.data, tdata->auth_iv.len,
3140                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3141                         tdata->validAuthLenInBits.len,
3142                         0);
3143         if (retval < 0)
3144                 return retval;
3145
3146         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3147                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3148                                 ut_params->op, 0, 1, 1, 0);
3149         else
3150                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3151                                 ut_params->op);
3152         ut_params->obuf = ut_params->op->sym->m_src;
3153         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3154         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3155                         + plaintext_pad_len;
3156
3157         /* Validate obuf */
3158         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3159         ut_params->digest,
3160         tdata->digest.data,
3161         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3162         "SNOW 3G Generated auth tag not as expected");
3163
3164         return 0;
3165 }
3166
3167 static int
3168 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3169 {
3170         struct crypto_testsuite_params *ts_params = &testsuite_params;
3171         struct crypto_unittest_params *ut_params = &unittest_params;
3172
3173         int retval;
3174         unsigned plaintext_pad_len;
3175         unsigned plaintext_len;
3176         uint8_t *plaintext;
3177         struct rte_cryptodev_info dev_info;
3178
3179         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3180         uint64_t feat_flags = dev_info.feature_flags;
3181
3182         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3183                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3184                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3185                 return TEST_SKIPPED;
3186         }
3187
3188         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3189                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3190                 printf("Device doesn't support RAW data-path APIs.\n");
3191                 return TEST_SKIPPED;
3192         }
3193
3194         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3195                 return TEST_SKIPPED;
3196
3197         /* Verify the capabilities */
3198         struct rte_cryptodev_sym_capability_idx cap_idx;
3199         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3200         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3201         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3202                         &cap_idx) == NULL)
3203                 return TEST_SKIPPED;
3204
3205         /* Create SNOW 3G session */
3206         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3207                                 tdata->key.data, tdata->key.len,
3208                                 tdata->auth_iv.len, tdata->digest.len,
3209                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3210                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3211         if (retval < 0)
3212                 return retval;
3213         /* alloc mbuf and set payload */
3214         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3215
3216         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3217         rte_pktmbuf_tailroom(ut_params->ibuf));
3218
3219         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3220         /* Append data which is padded to a multiple of */
3221         /* the algorithms block size */
3222         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3223         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3224                                 plaintext_pad_len);
3225         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3226
3227         /* Create SNOW 3G operation */
3228         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3229                         tdata->digest.len,
3230                         tdata->auth_iv.data, tdata->auth_iv.len,
3231                         plaintext_pad_len,
3232                         RTE_CRYPTO_AUTH_OP_VERIFY,
3233                         tdata->validAuthLenInBits.len,
3234                         0);
3235         if (retval < 0)
3236                 return retval;
3237
3238         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3239                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3240                                 ut_params->op, 0, 1, 1, 0);
3241         else
3242                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3243                                 ut_params->op);
3244         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3245         ut_params->obuf = ut_params->op->sym->m_src;
3246         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3247                                 + plaintext_pad_len;
3248
3249         /* Validate obuf */
3250         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3251                 return 0;
3252         else
3253                 return -1;
3254
3255         return 0;
3256 }
3257
3258 static int
3259 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3260 {
3261         struct crypto_testsuite_params *ts_params = &testsuite_params;
3262         struct crypto_unittest_params *ut_params = &unittest_params;
3263
3264         int retval;
3265         unsigned plaintext_pad_len;
3266         unsigned plaintext_len;
3267         uint8_t *plaintext;
3268         struct rte_cryptodev_info dev_info;
3269
3270         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3271         uint64_t feat_flags = dev_info.feature_flags;
3272
3273         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3274                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3275                 printf("Device doesn't support RAW data-path APIs.\n");
3276                 return TEST_SKIPPED;
3277         }
3278
3279         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3280                 return TEST_SKIPPED;
3281
3282         /* Verify the capabilities */
3283         struct rte_cryptodev_sym_capability_idx cap_idx;
3284         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3285         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3286         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3287                         &cap_idx) == NULL)
3288                 return TEST_SKIPPED;
3289
3290         /* Create KASUMI session */
3291         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3292                         tdata->key.data, tdata->key.len,
3293                         0, tdata->digest.len,
3294                         RTE_CRYPTO_AUTH_OP_GENERATE,
3295                         RTE_CRYPTO_AUTH_KASUMI_F9);
3296         if (retval < 0)
3297                 return retval;
3298
3299         /* alloc mbuf and set payload */
3300         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3301
3302         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3303         rte_pktmbuf_tailroom(ut_params->ibuf));
3304
3305         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3306         /* Append data which is padded to a multiple of */
3307         /* the algorithms block size */
3308         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3309         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3310                                 plaintext_pad_len);
3311         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3312
3313         /* Create KASUMI operation */
3314         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3315                         NULL, 0,
3316                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3317                         tdata->plaintext.len,
3318                         0);
3319         if (retval < 0)
3320                 return retval;
3321
3322         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3323                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3324                         ut_params->op);
3325         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3326                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3327                                 ut_params->op, 0, 1, 1, 0);
3328         else
3329                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3330                         ut_params->op);
3331
3332         ut_params->obuf = ut_params->op->sym->m_src;
3333         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3334         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3335                         + plaintext_pad_len;
3336
3337         /* Validate obuf */
3338         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3339         ut_params->digest,
3340         tdata->digest.data,
3341         DIGEST_BYTE_LENGTH_KASUMI_F9,
3342         "KASUMI Generated auth tag not as expected");
3343
3344         return 0;
3345 }
3346
3347 static int
3348 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3349 {
3350         struct crypto_testsuite_params *ts_params = &testsuite_params;
3351         struct crypto_unittest_params *ut_params = &unittest_params;
3352
3353         int retval;
3354         unsigned plaintext_pad_len;
3355         unsigned plaintext_len;
3356         uint8_t *plaintext;
3357         struct rte_cryptodev_info dev_info;
3358
3359         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3360         uint64_t feat_flags = dev_info.feature_flags;
3361
3362         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3363                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3364                 printf("Device doesn't support RAW data-path APIs.\n");
3365                 return TEST_SKIPPED;
3366         }
3367
3368         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3369                 return TEST_SKIPPED;
3370
3371         /* Verify the capabilities */
3372         struct rte_cryptodev_sym_capability_idx cap_idx;
3373         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3374         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3375         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3376                         &cap_idx) == NULL)
3377                 return TEST_SKIPPED;
3378
3379         /* Create KASUMI session */
3380         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3381                                 tdata->key.data, tdata->key.len,
3382                                 0, tdata->digest.len,
3383                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3384                                 RTE_CRYPTO_AUTH_KASUMI_F9);
3385         if (retval < 0)
3386                 return retval;
3387         /* alloc mbuf and set payload */
3388         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3389
3390         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3391         rte_pktmbuf_tailroom(ut_params->ibuf));
3392
3393         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3394         /* Append data which is padded to a multiple */
3395         /* of the algorithms block size */
3396         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3397         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3398                                 plaintext_pad_len);
3399         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3400
3401         /* Create KASUMI operation */
3402         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3403                         tdata->digest.len,
3404                         NULL, 0,
3405                         plaintext_pad_len,
3406                         RTE_CRYPTO_AUTH_OP_VERIFY,
3407                         tdata->plaintext.len,
3408                         0);
3409         if (retval < 0)
3410                 return retval;
3411
3412         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3413                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3414                                 ut_params->op, 0, 1, 1, 0);
3415         else
3416                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3417                                 ut_params->op);
3418         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3419         ut_params->obuf = ut_params->op->sym->m_src;
3420         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3421                                 + plaintext_pad_len;
3422
3423         /* Validate obuf */
3424         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3425                 return 0;
3426         else
3427                 return -1;
3428
3429         return 0;
3430 }
3431
3432 static int
3433 test_snow3g_hash_generate_test_case_1(void)
3434 {
3435         return test_snow3g_authentication(&snow3g_hash_test_case_1);
3436 }
3437
3438 static int
3439 test_snow3g_hash_generate_test_case_2(void)
3440 {
3441         return test_snow3g_authentication(&snow3g_hash_test_case_2);
3442 }
3443
3444 static int
3445 test_snow3g_hash_generate_test_case_3(void)
3446 {
3447         return test_snow3g_authentication(&snow3g_hash_test_case_3);
3448 }
3449
3450 static int
3451 test_snow3g_hash_generate_test_case_4(void)
3452 {
3453         return test_snow3g_authentication(&snow3g_hash_test_case_4);
3454 }
3455
3456 static int
3457 test_snow3g_hash_generate_test_case_5(void)
3458 {
3459         return test_snow3g_authentication(&snow3g_hash_test_case_5);
3460 }
3461
3462 static int
3463 test_snow3g_hash_generate_test_case_6(void)
3464 {
3465         return test_snow3g_authentication(&snow3g_hash_test_case_6);
3466 }
3467
3468 static int
3469 test_snow3g_hash_verify_test_case_1(void)
3470 {
3471         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3472
3473 }
3474
3475 static int
3476 test_snow3g_hash_verify_test_case_2(void)
3477 {
3478         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3479 }
3480
3481 static int
3482 test_snow3g_hash_verify_test_case_3(void)
3483 {
3484         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3485 }
3486
3487 static int
3488 test_snow3g_hash_verify_test_case_4(void)
3489 {
3490         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3491 }
3492
3493 static int
3494 test_snow3g_hash_verify_test_case_5(void)
3495 {
3496         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3497 }
3498
3499 static int
3500 test_snow3g_hash_verify_test_case_6(void)
3501 {
3502         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3503 }
3504
3505 static int
3506 test_kasumi_hash_generate_test_case_1(void)
3507 {
3508         return test_kasumi_authentication(&kasumi_hash_test_case_1);
3509 }
3510
3511 static int
3512 test_kasumi_hash_generate_test_case_2(void)
3513 {
3514         return test_kasumi_authentication(&kasumi_hash_test_case_2);
3515 }
3516
3517 static int
3518 test_kasumi_hash_generate_test_case_3(void)
3519 {
3520         return test_kasumi_authentication(&kasumi_hash_test_case_3);
3521 }
3522
3523 static int
3524 test_kasumi_hash_generate_test_case_4(void)
3525 {
3526         return test_kasumi_authentication(&kasumi_hash_test_case_4);
3527 }
3528
3529 static int
3530 test_kasumi_hash_generate_test_case_5(void)
3531 {
3532         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3533 }
3534
3535 static int
3536 test_kasumi_hash_generate_test_case_6(void)
3537 {
3538         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3539 }
3540
3541 static int
3542 test_kasumi_hash_verify_test_case_1(void)
3543 {
3544         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3545 }
3546
3547 static int
3548 test_kasumi_hash_verify_test_case_2(void)
3549 {
3550         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3551 }
3552
3553 static int
3554 test_kasumi_hash_verify_test_case_3(void)
3555 {
3556         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3557 }
3558
3559 static int
3560 test_kasumi_hash_verify_test_case_4(void)
3561 {
3562         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3563 }
3564
3565 static int
3566 test_kasumi_hash_verify_test_case_5(void)
3567 {
3568         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3569 }
3570
3571 static int
3572 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3573 {
3574         struct crypto_testsuite_params *ts_params = &testsuite_params;
3575         struct crypto_unittest_params *ut_params = &unittest_params;
3576
3577         int retval;
3578         uint8_t *plaintext, *ciphertext;
3579         unsigned plaintext_pad_len;
3580         unsigned plaintext_len;
3581         struct rte_cryptodev_info dev_info;
3582
3583         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3584         uint64_t feat_flags = dev_info.feature_flags;
3585
3586         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3587                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3588                 printf("Device doesn't support RAW data-path APIs.\n");
3589                 return TEST_SKIPPED;
3590         }
3591
3592         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3593                 return TEST_SKIPPED;
3594
3595         /* Verify the capabilities */
3596         struct rte_cryptodev_sym_capability_idx cap_idx;
3597         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3598         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3599         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3600                         &cap_idx) == NULL)
3601                 return TEST_SKIPPED;
3602
3603         /* Create KASUMI session */
3604         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3605                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3606                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3607                                         tdata->key.data, tdata->key.len,
3608                                         tdata->cipher_iv.len);
3609         if (retval < 0)
3610                 return retval;
3611
3612         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3613
3614         /* Clear mbuf payload */
3615         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3616                rte_pktmbuf_tailroom(ut_params->ibuf));
3617
3618         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3619         /* Append data which is padded to a multiple */
3620         /* of the algorithms block size */
3621         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3622         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3623                                 plaintext_pad_len);
3624         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3625
3626         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3627
3628         /* Create KASUMI operation */
3629         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3630                                 tdata->cipher_iv.len,
3631                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3632                                 tdata->validCipherOffsetInBits.len);
3633         if (retval < 0)
3634                 return retval;
3635
3636         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3637                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3638                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3639         else
3640                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3641                                 ut_params->op);
3642         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3643
3644         ut_params->obuf = ut_params->op->sym->m_dst;
3645         if (ut_params->obuf)
3646                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3647         else
3648                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3649
3650         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3651
3652         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3653                                 (tdata->validCipherOffsetInBits.len >> 3);
3654         /* Validate obuf */
3655         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3656                 ciphertext,
3657                 reference_ciphertext,
3658                 tdata->validCipherLenInBits.len,
3659                 "KASUMI Ciphertext data not as expected");
3660         return 0;
3661 }
3662
3663 static int
3664 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3665 {
3666         struct crypto_testsuite_params *ts_params = &testsuite_params;
3667         struct crypto_unittest_params *ut_params = &unittest_params;
3668
3669         int retval;
3670
3671         unsigned int plaintext_pad_len;
3672         unsigned int plaintext_len;
3673
3674         uint8_t buffer[10000];
3675         const uint8_t *ciphertext;
3676
3677         struct rte_cryptodev_info dev_info;
3678
3679         /* Verify the capabilities */
3680         struct rte_cryptodev_sym_capability_idx cap_idx;
3681         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3682         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3683         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3684                         &cap_idx) == NULL)
3685                 return TEST_SKIPPED;
3686
3687         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3688
3689         uint64_t feat_flags = dev_info.feature_flags;
3690
3691         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3692                 printf("Device doesn't support in-place scatter-gather. "
3693                                 "Test Skipped.\n");
3694                 return TEST_SKIPPED;
3695         }
3696
3697         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3698                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3699                 printf("Device doesn't support RAW data-path APIs.\n");
3700                 return TEST_SKIPPED;
3701         }
3702
3703         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3704                 return TEST_SKIPPED;
3705
3706         /* Create KASUMI session */
3707         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3708                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3709                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3710                                         tdata->key.data, tdata->key.len,
3711                                         tdata->cipher_iv.len);
3712         if (retval < 0)
3713                 return retval;
3714
3715         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3716
3717
3718         /* Append data which is padded to a multiple */
3719         /* of the algorithms block size */
3720         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3721
3722         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3723                         plaintext_pad_len, 10, 0);
3724
3725         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3726
3727         /* Create KASUMI operation */
3728         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3729                                 tdata->cipher_iv.len,
3730                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3731                                 tdata->validCipherOffsetInBits.len);
3732         if (retval < 0)
3733                 return retval;
3734
3735         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3736                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3737                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3738         else
3739                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3740                                                 ut_params->op);
3741         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3742
3743         ut_params->obuf = ut_params->op->sym->m_dst;
3744
3745         if (ut_params->obuf)
3746                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3747                                 plaintext_len, buffer);
3748         else
3749                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3750                                 tdata->validCipherOffsetInBits.len >> 3,
3751                                 plaintext_len, buffer);
3752
3753         /* Validate obuf */
3754         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3755
3756         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3757                                 (tdata->validCipherOffsetInBits.len >> 3);
3758         /* Validate obuf */
3759         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3760                 ciphertext,
3761                 reference_ciphertext,
3762                 tdata->validCipherLenInBits.len,
3763                 "KASUMI Ciphertext data not as expected");
3764         return 0;
3765 }
3766
3767 static int
3768 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3769 {
3770         struct crypto_testsuite_params *ts_params = &testsuite_params;
3771         struct crypto_unittest_params *ut_params = &unittest_params;
3772
3773         int retval;
3774         uint8_t *plaintext, *ciphertext;
3775         unsigned plaintext_pad_len;
3776         unsigned plaintext_len;
3777
3778         /* Verify the capabilities */
3779         struct rte_cryptodev_sym_capability_idx cap_idx;
3780         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3781         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3782         /* Data-path service does not support OOP */
3783         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3784                         &cap_idx) == NULL)
3785                 return TEST_SKIPPED;
3786
3787         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3788                 return TEST_SKIPPED;
3789
3790         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3791                 return TEST_SKIPPED;
3792
3793         /* Create KASUMI session */
3794         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3795                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3796                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3797                                         tdata->key.data, tdata->key.len,
3798                                         tdata->cipher_iv.len);
3799         if (retval < 0)
3800                 return retval;
3801
3802         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3803         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3804
3805         /* Clear mbuf payload */
3806         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3807                rte_pktmbuf_tailroom(ut_params->ibuf));
3808
3809         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3810         /* Append data which is padded to a multiple */
3811         /* of the algorithms block size */
3812         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3813         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3814                                 plaintext_pad_len);
3815         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3816         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3817
3818         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3819
3820         /* Create KASUMI operation */
3821         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3822                                 tdata->cipher_iv.len,
3823                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3824                                 tdata->validCipherOffsetInBits.len);
3825         if (retval < 0)
3826                 return retval;
3827
3828         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3829                                                 ut_params->op);
3830         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3831
3832         ut_params->obuf = ut_params->op->sym->m_dst;
3833         if (ut_params->obuf)
3834                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3835         else
3836                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3837
3838         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3839
3840         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3841                                 (tdata->validCipherOffsetInBits.len >> 3);
3842         /* Validate obuf */
3843         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3844                 ciphertext,
3845                 reference_ciphertext,
3846                 tdata->validCipherLenInBits.len,
3847                 "KASUMI Ciphertext data not as expected");
3848         return 0;
3849 }
3850
3851 static int
3852 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3853 {
3854         struct crypto_testsuite_params *ts_params = &testsuite_params;
3855         struct crypto_unittest_params *ut_params = &unittest_params;
3856
3857         int retval;
3858         unsigned int plaintext_pad_len;
3859         unsigned int plaintext_len;
3860
3861         const uint8_t *ciphertext;
3862         uint8_t buffer[2048];
3863
3864         struct rte_cryptodev_info dev_info;
3865
3866         /* Verify the capabilities */
3867         struct rte_cryptodev_sym_capability_idx cap_idx;
3868         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3869         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3870         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3871                         &cap_idx) == NULL)
3872                 return TEST_SKIPPED;
3873
3874         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3875                 return TEST_SKIPPED;
3876
3877         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3878                 return TEST_SKIPPED;
3879
3880         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3881
3882         uint64_t feat_flags = dev_info.feature_flags;
3883         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3884                 printf("Device doesn't support out-of-place scatter-gather "
3885                                 "in both input and output mbufs. "
3886                                 "Test Skipped.\n");
3887                 return TEST_SKIPPED;
3888         }
3889
3890         /* Create KASUMI session */
3891         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3892                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3893                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3894                                         tdata->key.data, tdata->key.len,
3895                                         tdata->cipher_iv.len);
3896         if (retval < 0)
3897                 return retval;
3898
3899         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3900         /* Append data which is padded to a multiple */
3901         /* of the algorithms block size */
3902         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3903
3904         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3905                         plaintext_pad_len, 10, 0);
3906         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3907                         plaintext_pad_len, 3, 0);
3908
3909         /* Append data which is padded to a multiple */
3910         /* of the algorithms block size */
3911         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3912
3913         /* Create KASUMI operation */
3914         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3915                                 tdata->cipher_iv.len,
3916                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3917                                 tdata->validCipherOffsetInBits.len);
3918         if (retval < 0)
3919                 return retval;
3920
3921         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3922                                                 ut_params->op);
3923         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3924
3925         ut_params->obuf = ut_params->op->sym->m_dst;
3926         if (ut_params->obuf)
3927                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3928                                 plaintext_pad_len, buffer);
3929         else
3930                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3931                                 tdata->validCipherOffsetInBits.len >> 3,
3932                                 plaintext_pad_len, buffer);
3933
3934         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3935                                 (tdata->validCipherOffsetInBits.len >> 3);
3936         /* Validate obuf */
3937         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3938                 ciphertext,
3939                 reference_ciphertext,
3940                 tdata->validCipherLenInBits.len,
3941                 "KASUMI Ciphertext data not as expected");
3942         return 0;
3943 }
3944
3945
3946 static int
3947 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3948 {
3949         struct crypto_testsuite_params *ts_params = &testsuite_params;
3950         struct crypto_unittest_params *ut_params = &unittest_params;
3951
3952         int retval;
3953         uint8_t *ciphertext, *plaintext;
3954         unsigned ciphertext_pad_len;
3955         unsigned ciphertext_len;
3956
3957         /* Verify the capabilities */
3958         struct rte_cryptodev_sym_capability_idx cap_idx;
3959         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3960         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3961         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3962                         &cap_idx) == NULL)
3963                 return TEST_SKIPPED;
3964
3965         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3966                 return TEST_SKIPPED;
3967
3968         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3969                 return TEST_SKIPPED;
3970
3971         /* Create KASUMI session */
3972         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3973                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3974                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3975                                         tdata->key.data, tdata->key.len,
3976                                         tdata->cipher_iv.len);
3977         if (retval < 0)
3978                 return retval;
3979
3980         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3981         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3982
3983         /* Clear mbuf payload */
3984         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3985                rte_pktmbuf_tailroom(ut_params->ibuf));
3986
3987         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3988         /* Append data which is padded to a multiple */
3989         /* of the algorithms block size */
3990         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3991         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3992                                 ciphertext_pad_len);
3993         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3994         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3995
3996         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3997
3998         /* Create KASUMI operation */
3999         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4000                                 tdata->cipher_iv.len,
4001                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4002                                 tdata->validCipherOffsetInBits.len);
4003         if (retval < 0)
4004                 return retval;
4005
4006         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4007                                                 ut_params->op);
4008         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4009
4010         ut_params->obuf = ut_params->op->sym->m_dst;
4011         if (ut_params->obuf)
4012                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4013         else
4014                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4015
4016         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4017
4018         const uint8_t *reference_plaintext = tdata->plaintext.data +
4019                                 (tdata->validCipherOffsetInBits.len >> 3);
4020         /* Validate obuf */
4021         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4022                 plaintext,
4023                 reference_plaintext,
4024                 tdata->validCipherLenInBits.len,
4025                 "KASUMI Plaintext data not as expected");
4026         return 0;
4027 }
4028
4029 static int
4030 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4031 {
4032         struct crypto_testsuite_params *ts_params = &testsuite_params;
4033         struct crypto_unittest_params *ut_params = &unittest_params;
4034
4035         int retval;
4036         uint8_t *ciphertext, *plaintext;
4037         unsigned ciphertext_pad_len;
4038         unsigned ciphertext_len;
4039         struct rte_cryptodev_info dev_info;
4040
4041         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4042         uint64_t feat_flags = dev_info.feature_flags;
4043
4044         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4045                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4046                 printf("Device doesn't support RAW data-path APIs.\n");
4047                 return TEST_SKIPPED;
4048         }
4049
4050         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4051                 return TEST_SKIPPED;
4052
4053         /* Verify the capabilities */
4054         struct rte_cryptodev_sym_capability_idx cap_idx;
4055         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4056         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4057         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4058                         &cap_idx) == NULL)
4059                 return TEST_SKIPPED;
4060
4061         /* Create KASUMI session */
4062         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4063                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4064                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4065                                         tdata->key.data, tdata->key.len,
4066                                         tdata->cipher_iv.len);
4067         if (retval < 0)
4068                 return retval;
4069
4070         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4071
4072         /* Clear mbuf payload */
4073         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4074                rte_pktmbuf_tailroom(ut_params->ibuf));
4075
4076         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4077         /* Append data which is padded to a multiple */
4078         /* of the algorithms block size */
4079         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4080         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4081                                 ciphertext_pad_len);
4082         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4083
4084         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4085
4086         /* Create KASUMI operation */
4087         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4088                                         tdata->cipher_iv.len,
4089                                         tdata->ciphertext.len,
4090                                         tdata->validCipherOffsetInBits.len);
4091         if (retval < 0)
4092                 return retval;
4093
4094         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4095                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4096                                 ut_params->op, 1, 0, 1, 0);
4097         else
4098                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4099                                                 ut_params->op);
4100         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4101
4102         ut_params->obuf = ut_params->op->sym->m_dst;
4103         if (ut_params->obuf)
4104                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4105         else
4106                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4107
4108         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4109
4110         const uint8_t *reference_plaintext = tdata->plaintext.data +
4111                                 (tdata->validCipherOffsetInBits.len >> 3);
4112         /* Validate obuf */
4113         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4114                 plaintext,
4115                 reference_plaintext,
4116                 tdata->validCipherLenInBits.len,
4117                 "KASUMI Plaintext data not as expected");
4118         return 0;
4119 }
4120
4121 static int
4122 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4123 {
4124         struct crypto_testsuite_params *ts_params = &testsuite_params;
4125         struct crypto_unittest_params *ut_params = &unittest_params;
4126
4127         int retval;
4128         uint8_t *plaintext, *ciphertext;
4129         unsigned plaintext_pad_len;
4130         unsigned plaintext_len;
4131         struct rte_cryptodev_info dev_info;
4132
4133         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4134         uint64_t feat_flags = dev_info.feature_flags;
4135
4136         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4137                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4138                 printf("Device doesn't support RAW data-path APIs.\n");
4139                 return TEST_SKIPPED;
4140         }
4141
4142         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4143                 return TEST_SKIPPED;
4144
4145         /* Verify the capabilities */
4146         struct rte_cryptodev_sym_capability_idx cap_idx;
4147         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4148         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4149         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4150                         &cap_idx) == NULL)
4151                 return TEST_SKIPPED;
4152
4153         /* Create SNOW 3G session */
4154         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4155                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4156                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4157                                         tdata->key.data, tdata->key.len,
4158                                         tdata->cipher_iv.len);
4159         if (retval < 0)
4160                 return retval;
4161
4162         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4163
4164         /* Clear mbuf payload */
4165         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4166                rte_pktmbuf_tailroom(ut_params->ibuf));
4167
4168         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4169         /* Append data which is padded to a multiple of */
4170         /* the algorithms block size */
4171         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4172         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4173                                 plaintext_pad_len);
4174         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4175
4176         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4177
4178         /* Create SNOW 3G operation */
4179         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4180                                         tdata->cipher_iv.len,
4181                                         tdata->validCipherLenInBits.len,
4182                                         0);
4183         if (retval < 0)
4184                 return retval;
4185
4186         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4187                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4188                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4189         else
4190                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4191                                                 ut_params->op);
4192         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4193
4194         ut_params->obuf = ut_params->op->sym->m_dst;
4195         if (ut_params->obuf)
4196                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4197         else
4198                 ciphertext = plaintext;
4199
4200         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4201
4202         /* Validate obuf */
4203         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4204                 ciphertext,
4205                 tdata->ciphertext.data,
4206                 tdata->validDataLenInBits.len,
4207                 "SNOW 3G Ciphertext data not as expected");
4208         return 0;
4209 }
4210
4211
4212 static int
4213 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4214 {
4215         struct crypto_testsuite_params *ts_params = &testsuite_params;
4216         struct crypto_unittest_params *ut_params = &unittest_params;
4217         uint8_t *plaintext, *ciphertext;
4218
4219         int retval;
4220         unsigned plaintext_pad_len;
4221         unsigned plaintext_len;
4222
4223         /* Verify the capabilities */
4224         struct rte_cryptodev_sym_capability_idx cap_idx;
4225         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4226         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4227         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4228                         &cap_idx) == NULL)
4229                 return TEST_SKIPPED;
4230
4231         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4232                 return TEST_SKIPPED;
4233
4234         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4235                 return TEST_SKIPPED;
4236
4237         /* Create SNOW 3G session */
4238         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4239                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4240                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4241                                         tdata->key.data, tdata->key.len,
4242                                         tdata->cipher_iv.len);
4243         if (retval < 0)
4244                 return retval;
4245
4246         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4247         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4248
4249         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4250                         "Failed to allocate input buffer in mempool");
4251         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4252                         "Failed to allocate output buffer in mempool");
4253
4254         /* Clear mbuf payload */
4255         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4256                rte_pktmbuf_tailroom(ut_params->ibuf));
4257
4258         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4259         /* Append data which is padded to a multiple of */
4260         /* the algorithms block size */
4261         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4262         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4263                                 plaintext_pad_len);
4264         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4265         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4266
4267         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4268
4269         /* Create SNOW 3G operation */
4270         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4271                                         tdata->cipher_iv.len,
4272                                         tdata->validCipherLenInBits.len,
4273                                         0);
4274         if (retval < 0)
4275                 return retval;
4276
4277         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4278                                                 ut_params->op);
4279         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4280
4281         ut_params->obuf = ut_params->op->sym->m_dst;
4282         if (ut_params->obuf)
4283                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4284         else
4285                 ciphertext = plaintext;
4286
4287         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4288
4289         /* Validate obuf */
4290         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4291                 ciphertext,
4292                 tdata->ciphertext.data,
4293                 tdata->validDataLenInBits.len,
4294                 "SNOW 3G Ciphertext data not as expected");
4295         return 0;
4296 }
4297
4298 static int
4299 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4300 {
4301         struct crypto_testsuite_params *ts_params = &testsuite_params;
4302         struct crypto_unittest_params *ut_params = &unittest_params;
4303
4304         int retval;
4305         unsigned int plaintext_pad_len;
4306         unsigned int plaintext_len;
4307         uint8_t buffer[10000];
4308         const uint8_t *ciphertext;
4309
4310         struct rte_cryptodev_info dev_info;
4311
4312         /* Verify the capabilities */
4313         struct rte_cryptodev_sym_capability_idx cap_idx;
4314         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4315         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4316         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4317                         &cap_idx) == NULL)
4318                 return TEST_SKIPPED;
4319
4320         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4321                 return TEST_SKIPPED;
4322
4323         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4324                 return TEST_SKIPPED;
4325
4326         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4327
4328         uint64_t feat_flags = dev_info.feature_flags;
4329
4330         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4331                 printf("Device doesn't support out-of-place scatter-gather "
4332                                 "in both input and output mbufs. "
4333                                 "Test Skipped.\n");
4334                 return TEST_SKIPPED;
4335         }
4336
4337         /* Create SNOW 3G session */
4338         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4339                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4340                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4341                                         tdata->key.data, tdata->key.len,
4342                                         tdata->cipher_iv.len);
4343         if (retval < 0)
4344                 return retval;
4345
4346         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4347         /* Append data which is padded to a multiple of */
4348         /* the algorithms block size */
4349         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4350
4351         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4352                         plaintext_pad_len, 10, 0);
4353         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4354                         plaintext_pad_len, 3, 0);
4355
4356         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4357                         "Failed to allocate input buffer in mempool");
4358         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4359                         "Failed to allocate output buffer in mempool");
4360
4361         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4362
4363         /* Create SNOW 3G operation */
4364         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4365                                         tdata->cipher_iv.len,
4366                                         tdata->validCipherLenInBits.len,
4367                                         0);
4368         if (retval < 0)
4369                 return retval;
4370
4371         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4372                                                 ut_params->op);
4373         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4374
4375         ut_params->obuf = ut_params->op->sym->m_dst;
4376         if (ut_params->obuf)
4377                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4378                                 plaintext_len, buffer);
4379         else
4380                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4381                                 plaintext_len, buffer);
4382
4383         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4384
4385         /* Validate obuf */
4386         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4387                 ciphertext,
4388                 tdata->ciphertext.data,
4389                 tdata->validDataLenInBits.len,
4390                 "SNOW 3G Ciphertext data not as expected");
4391
4392         return 0;
4393 }
4394
4395 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4396 static void
4397 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4398 {
4399         uint8_t curr_byte, prev_byte;
4400         uint32_t length_in_bytes = ceil_byte_length(length + offset);
4401         uint8_t lower_byte_mask = (1 << offset) - 1;
4402         unsigned i;
4403
4404         prev_byte = buffer[0];
4405         buffer[0] >>= offset;
4406
4407         for (i = 1; i < length_in_bytes; i++) {
4408                 curr_byte = buffer[i];
4409                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4410                                 (curr_byte >> offset);
4411                 prev_byte = curr_byte;
4412         }
4413 }
4414
4415 static int
4416 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4417 {
4418         struct crypto_testsuite_params *ts_params = &testsuite_params;
4419         struct crypto_unittest_params *ut_params = &unittest_params;
4420         uint8_t *plaintext, *ciphertext;
4421         int retval;
4422         uint32_t plaintext_len;
4423         uint32_t plaintext_pad_len;
4424         uint8_t extra_offset = 4;
4425         uint8_t *expected_ciphertext_shifted;
4426         struct rte_cryptodev_info dev_info;
4427
4428         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4429         uint64_t feat_flags = dev_info.feature_flags;
4430
4431         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4432                         ((tdata->validDataLenInBits.len % 8) != 0)) {
4433                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4434                 return TEST_SKIPPED;
4435         }
4436
4437         /* Verify the capabilities */
4438         struct rte_cryptodev_sym_capability_idx cap_idx;
4439         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4440         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4441         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4442                         &cap_idx) == NULL)
4443                 return TEST_SKIPPED;
4444
4445         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4446                 return TEST_SKIPPED;
4447
4448         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4449                 return TEST_SKIPPED;
4450
4451         /* Create SNOW 3G session */
4452         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4453                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4454                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4455                                         tdata->key.data, tdata->key.len,
4456                                         tdata->cipher_iv.len);
4457         if (retval < 0)
4458                 return retval;
4459
4460         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4461         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4462
4463         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4464                         "Failed to allocate input buffer in mempool");
4465         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4466                         "Failed to allocate output buffer in mempool");
4467
4468         /* Clear mbuf payload */
4469         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4470                rte_pktmbuf_tailroom(ut_params->ibuf));
4471
4472         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4473         /*
4474          * Append data which is padded to a
4475          * multiple of the algorithms block size
4476          */
4477         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4478
4479         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4480                                                 plaintext_pad_len);
4481
4482         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4483
4484         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4485         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4486
4487 #ifdef RTE_APP_TEST_DEBUG
4488         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4489 #endif
4490         /* Create SNOW 3G operation */
4491         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4492                                         tdata->cipher_iv.len,
4493                                         tdata->validCipherLenInBits.len,
4494                                         extra_offset);
4495         if (retval < 0)
4496                 return retval;
4497
4498         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4499                                                 ut_params->op);
4500         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4501
4502         ut_params->obuf = ut_params->op->sym->m_dst;
4503         if (ut_params->obuf)
4504                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4505         else
4506                 ciphertext = plaintext;
4507
4508 #ifdef RTE_APP_TEST_DEBUG
4509         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4510 #endif
4511
4512         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4513
4514         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4515                         "failed to reserve memory for ciphertext shifted\n");
4516
4517         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4518                         ceil_byte_length(tdata->ciphertext.len));
4519         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4520                         extra_offset);
4521         /* Validate obuf */
4522         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4523                 ciphertext,
4524                 expected_ciphertext_shifted,
4525                 tdata->validDataLenInBits.len,
4526                 extra_offset,
4527                 "SNOW 3G Ciphertext data not as expected");
4528         return 0;
4529 }
4530
4531 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4532 {
4533         struct crypto_testsuite_params *ts_params = &testsuite_params;
4534         struct crypto_unittest_params *ut_params = &unittest_params;
4535
4536         int retval;
4537
4538         uint8_t *plaintext, *ciphertext;
4539         unsigned ciphertext_pad_len;
4540         unsigned ciphertext_len;
4541         struct rte_cryptodev_info dev_info;
4542
4543         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4544         uint64_t feat_flags = dev_info.feature_flags;
4545
4546         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4547                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4548                 printf("Device doesn't support RAW data-path APIs.\n");
4549                 return TEST_SKIPPED;
4550         }
4551
4552         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4553                 return TEST_SKIPPED;
4554
4555         /* Verify the capabilities */
4556         struct rte_cryptodev_sym_capability_idx cap_idx;
4557         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4558         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4559         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4560                         &cap_idx) == NULL)
4561                 return TEST_SKIPPED;
4562
4563         /* Create SNOW 3G session */
4564         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4565                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4566                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4567                                         tdata->key.data, tdata->key.len,
4568                                         tdata->cipher_iv.len);
4569         if (retval < 0)
4570                 return retval;
4571
4572         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4573
4574         /* Clear mbuf payload */
4575         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4576                rte_pktmbuf_tailroom(ut_params->ibuf));
4577
4578         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4579         /* Append data which is padded to a multiple of */
4580         /* the algorithms block size */
4581         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4582         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4583                                 ciphertext_pad_len);
4584         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4585
4586         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4587
4588         /* Create SNOW 3G operation */
4589         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4590                                         tdata->cipher_iv.len,
4591                                         tdata->validCipherLenInBits.len,
4592                                         tdata->cipher.offset_bits);
4593         if (retval < 0)
4594                 return retval;
4595
4596         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4597                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4598                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4599         else
4600                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4601                                                 ut_params->op);
4602         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4603         ut_params->obuf = ut_params->op->sym->m_dst;
4604         if (ut_params->obuf)
4605                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4606         else
4607                 plaintext = ciphertext;
4608
4609         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4610
4611         /* Validate obuf */
4612         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4613                                 tdata->plaintext.data,
4614                                 tdata->validDataLenInBits.len,
4615                                 "SNOW 3G Plaintext data not as expected");
4616         return 0;
4617 }
4618
4619 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4620 {
4621         struct crypto_testsuite_params *ts_params = &testsuite_params;
4622         struct crypto_unittest_params *ut_params = &unittest_params;
4623
4624         int retval;
4625
4626         uint8_t *plaintext, *ciphertext;
4627         unsigned ciphertext_pad_len;
4628         unsigned ciphertext_len;
4629
4630         /* Verify the capabilities */
4631         struct rte_cryptodev_sym_capability_idx cap_idx;
4632         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4633         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4634         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4635                         &cap_idx) == NULL)
4636                 return TEST_SKIPPED;
4637
4638         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4639                 return TEST_SKIPPED;
4640
4641         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4642                 return TEST_SKIPPED;
4643
4644         /* Create SNOW 3G session */
4645         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4646                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4647                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4648                                         tdata->key.data, tdata->key.len,
4649                                         tdata->cipher_iv.len);
4650         if (retval < 0)
4651                 return retval;
4652
4653         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4654         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4655
4656         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4657                         "Failed to allocate input buffer");
4658         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4659                         "Failed to allocate output buffer");
4660
4661         /* Clear mbuf payload */
4662         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4663                rte_pktmbuf_tailroom(ut_params->ibuf));
4664
4665         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4666                        rte_pktmbuf_tailroom(ut_params->obuf));
4667
4668         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4669         /* Append data which is padded to a multiple of */
4670         /* the algorithms block size */
4671         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4672         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4673                                 ciphertext_pad_len);
4674         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4675         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4676
4677         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4678
4679         /* Create SNOW 3G operation */
4680         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4681                                         tdata->cipher_iv.len,
4682                                         tdata->validCipherLenInBits.len,
4683                                         0);
4684         if (retval < 0)
4685                 return retval;
4686
4687         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4688                                                 ut_params->op);
4689         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4690         ut_params->obuf = ut_params->op->sym->m_dst;
4691         if (ut_params->obuf)
4692                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4693         else
4694                 plaintext = ciphertext;
4695
4696         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4697
4698         /* Validate obuf */
4699         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4700                                 tdata->plaintext.data,
4701                                 tdata->validDataLenInBits.len,
4702                                 "SNOW 3G Plaintext data not as expected");
4703         return 0;
4704 }
4705
4706 static int
4707 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4708 {
4709         struct crypto_testsuite_params *ts_params = &testsuite_params;
4710         struct crypto_unittest_params *ut_params = &unittest_params;
4711
4712         int retval;
4713
4714         uint8_t *plaintext, *ciphertext;
4715         unsigned int plaintext_pad_len;
4716         unsigned int plaintext_len;
4717
4718         struct rte_cryptodev_info dev_info;
4719         struct rte_cryptodev_sym_capability_idx cap_idx;
4720
4721         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4722         uint64_t feat_flags = dev_info.feature_flags;
4723
4724         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4725                         ((tdata->validAuthLenInBits.len % 8 != 0) ||
4726                         (tdata->validDataLenInBits.len % 8 != 0))) {
4727                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4728                 return TEST_SKIPPED;
4729         }
4730
4731         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4732                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4733                 printf("Device doesn't support RAW data-path APIs.\n");
4734                 return TEST_SKIPPED;
4735         }
4736
4737         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4738                 return TEST_SKIPPED;
4739
4740         /* Check if device supports ZUC EEA3 */
4741         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4742         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4743
4744         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4745                         &cap_idx) == NULL)
4746                 return TEST_SKIPPED;
4747
4748         /* Check if device supports ZUC EIA3 */
4749         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4750         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4751
4752         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4753                         &cap_idx) == NULL)
4754                 return TEST_SKIPPED;
4755
4756         /* Create ZUC session */
4757         retval = create_zuc_cipher_auth_encrypt_generate_session(
4758                         ts_params->valid_devs[0],
4759                         tdata);
4760         if (retval != 0)
4761                 return retval;
4762         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4763
4764         /* clear mbuf payload */
4765         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4766                         rte_pktmbuf_tailroom(ut_params->ibuf));
4767
4768         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4769         /* Append data which is padded to a multiple of */
4770         /* the algorithms block size */
4771         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4772         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4773                                 plaintext_pad_len);
4774         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4775
4776         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4777
4778         /* Create ZUC operation */
4779         retval = create_zuc_cipher_hash_generate_operation(tdata);
4780         if (retval < 0)
4781                 return retval;
4782
4783         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4784                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4785                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4786         else
4787                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4788                         ut_params->op);
4789         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4790         ut_params->obuf = ut_params->op->sym->m_src;
4791         if (ut_params->obuf)
4792                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4793         else
4794                 ciphertext = plaintext;
4795
4796         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4797         /* Validate obuf */
4798         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4799                         ciphertext,
4800                         tdata->ciphertext.data,
4801                         tdata->validDataLenInBits.len,
4802                         "ZUC Ciphertext data not as expected");
4803
4804         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4805             + plaintext_pad_len;
4806
4807         /* Validate obuf */
4808         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4809                         ut_params->digest,
4810                         tdata->digest.data,
4811                         4,
4812                         "ZUC Generated auth tag not as expected");
4813         return 0;
4814 }
4815
4816 static int
4817 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4818 {
4819         struct crypto_testsuite_params *ts_params = &testsuite_params;
4820         struct crypto_unittest_params *ut_params = &unittest_params;
4821
4822         int retval;
4823
4824         uint8_t *plaintext, *ciphertext;
4825         unsigned plaintext_pad_len;
4826         unsigned plaintext_len;
4827         struct rte_cryptodev_info dev_info;
4828
4829         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4830         uint64_t feat_flags = dev_info.feature_flags;
4831
4832         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4833                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4834                 printf("Device doesn't support RAW data-path APIs.\n");
4835                 return TEST_SKIPPED;
4836         }
4837
4838         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4839                 return TEST_SKIPPED;
4840
4841         /* Verify the capabilities */
4842         struct rte_cryptodev_sym_capability_idx cap_idx;
4843         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4844         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4845         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4846                         &cap_idx) == NULL)
4847                 return TEST_SKIPPED;
4848         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4849         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4850         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4851                         &cap_idx) == NULL)
4852                 return TEST_SKIPPED;
4853
4854         /* Create SNOW 3G session */
4855         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4856                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4857                         RTE_CRYPTO_AUTH_OP_GENERATE,
4858                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4859                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4860                         tdata->key.data, tdata->key.len,
4861                         tdata->auth_iv.len, tdata->digest.len,
4862                         tdata->cipher_iv.len);
4863         if (retval != 0)
4864                 return retval;
4865         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4866
4867         /* clear mbuf payload */
4868         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4869                         rte_pktmbuf_tailroom(ut_params->ibuf));
4870
4871         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4872         /* Append data which is padded to a multiple of */
4873         /* the algorithms block size */
4874         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4875         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4876                                 plaintext_pad_len);
4877         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4878
4879         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4880
4881         /* Create SNOW 3G operation */
4882         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4883                         tdata->digest.len, tdata->auth_iv.data,
4884                         tdata->auth_iv.len,
4885                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4886                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4887                         tdata->validCipherLenInBits.len,
4888                         0,
4889                         tdata->validAuthLenInBits.len,
4890                         0
4891                         );
4892         if (retval < 0)
4893                 return retval;
4894
4895         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4896                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4897                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4898         else
4899                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4900                         ut_params->op);
4901         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4902         ut_params->obuf = ut_params->op->sym->m_src;
4903         if (ut_params->obuf)
4904                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4905         else
4906                 ciphertext = plaintext;
4907
4908         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4909         /* Validate obuf */
4910         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4911                         ciphertext,
4912                         tdata->ciphertext.data,
4913                         tdata->validDataLenInBits.len,
4914                         "SNOW 3G Ciphertext data not as expected");
4915
4916         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4917             + plaintext_pad_len;
4918
4919         /* Validate obuf */
4920         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4921                         ut_params->digest,
4922                         tdata->digest.data,
4923                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4924                         "SNOW 3G Generated auth tag not as expected");
4925         return 0;
4926 }
4927
4928 static int
4929 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4930         uint8_t op_mode, uint8_t verify)
4931 {
4932         struct crypto_testsuite_params *ts_params = &testsuite_params;
4933         struct crypto_unittest_params *ut_params = &unittest_params;
4934
4935         int retval;
4936
4937         uint8_t *plaintext = NULL, *ciphertext = NULL;
4938         unsigned int plaintext_pad_len;
4939         unsigned int plaintext_len;
4940         unsigned int ciphertext_pad_len;
4941         unsigned int ciphertext_len;
4942
4943         struct rte_cryptodev_info dev_info;
4944
4945         /* Verify the capabilities */
4946         struct rte_cryptodev_sym_capability_idx cap_idx;
4947         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4948         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4949         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4950                         &cap_idx) == NULL)
4951                 return TEST_SKIPPED;
4952         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4953         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4954         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4955                         &cap_idx) == NULL)
4956                 return TEST_SKIPPED;
4957
4958         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4959                 return TEST_SKIPPED;
4960
4961         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4962
4963         uint64_t feat_flags = dev_info.feature_flags;
4964
4965         if (op_mode == OUT_OF_PLACE) {
4966                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4967                         printf("Device doesn't support digest encrypted.\n");
4968                         return TEST_SKIPPED;
4969                 }
4970                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4971                         return TEST_SKIPPED;
4972         }
4973
4974         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4975                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4976                 printf("Device doesn't support RAW data-path APIs.\n");
4977                 return TEST_SKIPPED;
4978         }
4979
4980         /* Create SNOW 3G session */
4981         retval = create_wireless_algo_auth_cipher_session(
4982                         ts_params->valid_devs[0],
4983                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4984                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4985                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4986                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4987                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4988                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4989                         tdata->key.data, tdata->key.len,
4990                         tdata->auth_iv.len, tdata->digest.len,
4991                         tdata->cipher_iv.len);
4992         if (retval != 0)
4993                 return retval;
4994
4995         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4996         if (op_mode == OUT_OF_PLACE)
4997                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4998
4999         /* clear mbuf payload */
5000         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5001                 rte_pktmbuf_tailroom(ut_params->ibuf));
5002         if (op_mode == OUT_OF_PLACE)
5003                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5004                         rte_pktmbuf_tailroom(ut_params->obuf));
5005
5006         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5007         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5008         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5009         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5010
5011         if (verify) {
5012                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5013                                         ciphertext_pad_len);
5014                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5015                 if (op_mode == OUT_OF_PLACE)
5016                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5017                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5018                         ciphertext_len);
5019         } else {
5020                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5021                                         plaintext_pad_len);
5022                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5023                 if (op_mode == OUT_OF_PLACE)
5024                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5025                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5026         }
5027
5028         /* Create SNOW 3G operation */
5029         retval = create_wireless_algo_auth_cipher_operation(
5030                 tdata->digest.data, tdata->digest.len,
5031                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5032                 tdata->auth_iv.data, tdata->auth_iv.len,
5033                 (tdata->digest.offset_bytes == 0 ?
5034                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5035                         : tdata->digest.offset_bytes),
5036                 tdata->validCipherLenInBits.len,
5037                 tdata->cipher.offset_bits,
5038                 tdata->validAuthLenInBits.len,
5039                 tdata->auth.offset_bits,
5040                 op_mode, 0, verify);
5041
5042         if (retval < 0)
5043                 return retval;
5044
5045         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5046                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5047                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5048         else
5049                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5050                         ut_params->op);
5051
5052         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5053
5054         ut_params->obuf = (op_mode == IN_PLACE ?
5055                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5056
5057         if (verify) {
5058                 if (ut_params->obuf)
5059                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5060                                                         uint8_t *);
5061                 else
5062                         plaintext = ciphertext +
5063                                 (tdata->cipher.offset_bits >> 3);
5064
5065                 debug_hexdump(stdout, "plaintext:", plaintext,
5066                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5067                 debug_hexdump(stdout, "plaintext expected:",
5068                         tdata->plaintext.data,
5069                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5070         } else {
5071                 if (ut_params->obuf)
5072                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5073                                                         uint8_t *);
5074                 else
5075                         ciphertext = plaintext;
5076
5077                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5078                         ciphertext_len);
5079                 debug_hexdump(stdout, "ciphertext expected:",
5080                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5081
5082                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5083                         + (tdata->digest.offset_bytes == 0 ?
5084                 plaintext_pad_len : tdata->digest.offset_bytes);
5085
5086                 debug_hexdump(stdout, "digest:", ut_params->digest,
5087                         tdata->digest.len);
5088                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5089                                 tdata->digest.len);
5090         }
5091
5092         /* Validate obuf */
5093         if (verify) {
5094                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5095                         plaintext,
5096                         tdata->plaintext.data,
5097                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5098                          (tdata->digest.len << 3)),
5099                         tdata->cipher.offset_bits,
5100                         "SNOW 3G Plaintext data not as expected");
5101         } else {
5102                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5103                         ciphertext,
5104                         tdata->ciphertext.data,
5105                         (tdata->validDataLenInBits.len -
5106                          tdata->cipher.offset_bits),
5107                         tdata->cipher.offset_bits,
5108                         "SNOW 3G Ciphertext data not as expected");
5109
5110                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5111                         ut_params->digest,
5112                         tdata->digest.data,
5113                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5114                         "SNOW 3G Generated auth tag not as expected");
5115         }
5116         return 0;
5117 }
5118
5119 static int
5120 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5121         uint8_t op_mode, uint8_t verify)
5122 {
5123         struct crypto_testsuite_params *ts_params = &testsuite_params;
5124         struct crypto_unittest_params *ut_params = &unittest_params;
5125
5126         int retval;
5127
5128         const uint8_t *plaintext = NULL;
5129         const uint8_t *ciphertext = NULL;
5130         const uint8_t *digest = NULL;
5131         unsigned int plaintext_pad_len;
5132         unsigned int plaintext_len;
5133         unsigned int ciphertext_pad_len;
5134         unsigned int ciphertext_len;
5135         uint8_t buffer[10000];
5136         uint8_t digest_buffer[10000];
5137
5138         struct rte_cryptodev_info dev_info;
5139
5140         /* Verify the capabilities */
5141         struct rte_cryptodev_sym_capability_idx cap_idx;
5142         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5143         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5144         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5145                         &cap_idx) == NULL)
5146                 return TEST_SKIPPED;
5147         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5148         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5149         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5150                         &cap_idx) == NULL)
5151                 return TEST_SKIPPED;
5152
5153         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5154                 return TEST_SKIPPED;
5155
5156         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5157
5158         uint64_t feat_flags = dev_info.feature_flags;
5159
5160         if (op_mode == IN_PLACE) {
5161                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5162                         printf("Device doesn't support in-place scatter-gather "
5163                                         "in both input and output mbufs.\n");
5164                         return TEST_SKIPPED;
5165                 }
5166                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5167                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5168                         printf("Device doesn't support RAW data-path APIs.\n");
5169                         return TEST_SKIPPED;
5170                 }
5171         } else {
5172                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5173                         return TEST_SKIPPED;
5174                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5175                         printf("Device doesn't support out-of-place scatter-gather "
5176                                         "in both input and output mbufs.\n");
5177                         return TEST_SKIPPED;
5178                 }
5179                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5180                         printf("Device doesn't support digest encrypted.\n");
5181                         return TEST_SKIPPED;
5182                 }
5183         }
5184
5185         /* Create SNOW 3G session */
5186         retval = create_wireless_algo_auth_cipher_session(
5187                         ts_params->valid_devs[0],
5188                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5189                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5190                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5191                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5192                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5193                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5194                         tdata->key.data, tdata->key.len,
5195                         tdata->auth_iv.len, tdata->digest.len,
5196                         tdata->cipher_iv.len);
5197
5198         if (retval != 0)
5199                 return retval;
5200
5201         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5202         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5203         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5204         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5205
5206         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5207                         plaintext_pad_len, 15, 0);
5208         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5209                         "Failed to allocate input buffer in mempool");
5210
5211         if (op_mode == OUT_OF_PLACE) {
5212                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5213                                 plaintext_pad_len, 15, 0);
5214                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5215                                 "Failed to allocate output buffer in mempool");
5216         }
5217
5218         if (verify) {
5219                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5220                         tdata->ciphertext.data);
5221                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5222                                         ciphertext_len, buffer);
5223                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5224                         ciphertext_len);
5225         } else {
5226                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5227                         tdata->plaintext.data);
5228                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5229                                         plaintext_len, buffer);
5230                 debug_hexdump(stdout, "plaintext:", plaintext,
5231                         plaintext_len);
5232         }
5233         memset(buffer, 0, sizeof(buffer));
5234
5235         /* Create SNOW 3G operation */
5236         retval = create_wireless_algo_auth_cipher_operation(
5237                 tdata->digest.data, tdata->digest.len,
5238                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5239                 tdata->auth_iv.data, tdata->auth_iv.len,
5240                 (tdata->digest.offset_bytes == 0 ?
5241                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5242                         : tdata->digest.offset_bytes),
5243                 tdata->validCipherLenInBits.len,
5244                 tdata->cipher.offset_bits,
5245                 tdata->validAuthLenInBits.len,
5246                 tdata->auth.offset_bits,
5247                 op_mode, 1, verify);
5248
5249         if (retval < 0)
5250                 return retval;
5251
5252         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5253                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5254                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5255         else
5256                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5257                         ut_params->op);
5258
5259         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5260
5261         ut_params->obuf = (op_mode == IN_PLACE ?
5262                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5263
5264         if (verify) {
5265                 if (ut_params->obuf)
5266                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5267                                         plaintext_len, buffer);
5268                 else
5269                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5270                                         plaintext_len, buffer);
5271
5272                 debug_hexdump(stdout, "plaintext:", plaintext,
5273                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5274                 debug_hexdump(stdout, "plaintext expected:",
5275                         tdata->plaintext.data,
5276                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5277         } else {
5278                 if (ut_params->obuf)
5279                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5280                                         ciphertext_len, buffer);
5281                 else
5282                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5283                                         ciphertext_len, buffer);
5284
5285                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5286                         ciphertext_len);
5287                 debug_hexdump(stdout, "ciphertext expected:",
5288                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5289
5290                 if (ut_params->obuf)
5291                         digest = rte_pktmbuf_read(ut_params->obuf,
5292                                 (tdata->digest.offset_bytes == 0 ?
5293                                 plaintext_pad_len : tdata->digest.offset_bytes),
5294                                 tdata->digest.len, digest_buffer);
5295                 else
5296                         digest = rte_pktmbuf_read(ut_params->ibuf,
5297                                 (tdata->digest.offset_bytes == 0 ?
5298                                 plaintext_pad_len : tdata->digest.offset_bytes),
5299                                 tdata->digest.len, digest_buffer);
5300
5301                 debug_hexdump(stdout, "digest:", digest,
5302                         tdata->digest.len);
5303                 debug_hexdump(stdout, "digest expected:",
5304                         tdata->digest.data, tdata->digest.len);
5305         }
5306
5307         /* Validate obuf */
5308         if (verify) {
5309                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5310                         plaintext,
5311                         tdata->plaintext.data,
5312                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5313                          (tdata->digest.len << 3)),
5314                         tdata->cipher.offset_bits,
5315                         "SNOW 3G Plaintext data not as expected");
5316         } else {
5317                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5318                         ciphertext,
5319                         tdata->ciphertext.data,
5320                         (tdata->validDataLenInBits.len -
5321                          tdata->cipher.offset_bits),
5322                         tdata->cipher.offset_bits,
5323                         "SNOW 3G Ciphertext data not as expected");
5324
5325                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5326                         digest,
5327                         tdata->digest.data,
5328                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5329                         "SNOW 3G Generated auth tag not as expected");
5330         }
5331         return 0;
5332 }
5333
5334 static int
5335 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5336         uint8_t op_mode, uint8_t verify)
5337 {
5338         struct crypto_testsuite_params *ts_params = &testsuite_params;
5339         struct crypto_unittest_params *ut_params = &unittest_params;
5340
5341         int retval;
5342
5343         uint8_t *plaintext = NULL, *ciphertext = NULL;
5344         unsigned int plaintext_pad_len;
5345         unsigned int plaintext_len;
5346         unsigned int ciphertext_pad_len;
5347         unsigned int ciphertext_len;
5348
5349         struct rte_cryptodev_info dev_info;
5350
5351         /* Verify the capabilities */
5352         struct rte_cryptodev_sym_capability_idx cap_idx;
5353         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5354         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5355         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5356                         &cap_idx) == NULL)
5357                 return TEST_SKIPPED;
5358         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5359         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5360         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5361                         &cap_idx) == NULL)
5362                 return TEST_SKIPPED;
5363
5364         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5365
5366         uint64_t feat_flags = dev_info.feature_flags;
5367
5368         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5369                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5370                 printf("Device doesn't support RAW data-path APIs.\n");
5371                 return TEST_SKIPPED;
5372         }
5373
5374         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5375                 return TEST_SKIPPED;
5376
5377         if (op_mode == OUT_OF_PLACE) {
5378                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5379                         return TEST_SKIPPED;
5380                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5381                         printf("Device doesn't support digest encrypted.\n");
5382                         return TEST_SKIPPED;
5383                 }
5384         }
5385
5386         /* Create KASUMI session */
5387         retval = create_wireless_algo_auth_cipher_session(
5388                         ts_params->valid_devs[0],
5389                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5390                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5391                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5392                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5393                         RTE_CRYPTO_AUTH_KASUMI_F9,
5394                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5395                         tdata->key.data, tdata->key.len,
5396                         0, tdata->digest.len,
5397                         tdata->cipher_iv.len);
5398
5399         if (retval != 0)
5400                 return retval;
5401
5402         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5403         if (op_mode == OUT_OF_PLACE)
5404                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5405
5406         /* clear mbuf payload */
5407         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5408                 rte_pktmbuf_tailroom(ut_params->ibuf));
5409         if (op_mode == OUT_OF_PLACE)
5410                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5411                         rte_pktmbuf_tailroom(ut_params->obuf));
5412
5413         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5414         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5415         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5416         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5417
5418         if (verify) {
5419                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5420                                         ciphertext_pad_len);
5421                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5422                 if (op_mode == OUT_OF_PLACE)
5423                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5424                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5425                         ciphertext_len);
5426         } else {
5427                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5428                                         plaintext_pad_len);
5429                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5430                 if (op_mode == OUT_OF_PLACE)
5431                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5432                 debug_hexdump(stdout, "plaintext:", plaintext,
5433                         plaintext_len);
5434         }
5435
5436         /* Create KASUMI operation */
5437         retval = create_wireless_algo_auth_cipher_operation(
5438                 tdata->digest.data, tdata->digest.len,
5439                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5440                 NULL, 0,
5441                 (tdata->digest.offset_bytes == 0 ?
5442                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5443                         : tdata->digest.offset_bytes),
5444                 tdata->validCipherLenInBits.len,
5445                 tdata->validCipherOffsetInBits.len,
5446                 tdata->validAuthLenInBits.len,
5447                 0,
5448                 op_mode, 0, verify);
5449
5450         if (retval < 0)
5451                 return retval;
5452
5453         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5454                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5455                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5456         else
5457                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5458                         ut_params->op);
5459
5460         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5461
5462         ut_params->obuf = (op_mode == IN_PLACE ?
5463                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5464
5465
5466         if (verify) {
5467                 if (ut_params->obuf)
5468                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5469                                                         uint8_t *);
5470                 else
5471                         plaintext = ciphertext;
5472
5473                 debug_hexdump(stdout, "plaintext:", plaintext,
5474                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5475                 debug_hexdump(stdout, "plaintext expected:",
5476                         tdata->plaintext.data,
5477                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5478         } else {
5479                 if (ut_params->obuf)
5480                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5481                                                         uint8_t *);
5482                 else
5483                         ciphertext = plaintext;
5484
5485                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5486                         ciphertext_len);
5487                 debug_hexdump(stdout, "ciphertext expected:",
5488                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5489
5490                 ut_params->digest = rte_pktmbuf_mtod(
5491                         ut_params->obuf, uint8_t *) +
5492                         (tdata->digest.offset_bytes == 0 ?
5493                         plaintext_pad_len : tdata->digest.offset_bytes);
5494
5495                 debug_hexdump(stdout, "digest:", ut_params->digest,
5496                         tdata->digest.len);
5497                 debug_hexdump(stdout, "digest expected:",
5498                         tdata->digest.data, tdata->digest.len);
5499         }
5500
5501         /* Validate obuf */
5502         if (verify) {
5503                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5504                         plaintext,
5505                         tdata->plaintext.data,
5506                         tdata->plaintext.len >> 3,
5507                         "KASUMI Plaintext data not as expected");
5508         } else {
5509                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5510                         ciphertext,
5511                         tdata->ciphertext.data,
5512                         tdata->ciphertext.len >> 3,
5513                         "KASUMI Ciphertext data not as expected");
5514
5515                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5516                         ut_params->digest,
5517                         tdata->digest.data,
5518                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5519                         "KASUMI Generated auth tag not as expected");
5520         }
5521         return 0;
5522 }
5523
5524 static int
5525 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5526         uint8_t op_mode, uint8_t verify)
5527 {
5528         struct crypto_testsuite_params *ts_params = &testsuite_params;
5529         struct crypto_unittest_params *ut_params = &unittest_params;
5530
5531         int retval;
5532
5533         const uint8_t *plaintext = NULL;
5534         const uint8_t *ciphertext = NULL;
5535         const uint8_t *digest = NULL;
5536         unsigned int plaintext_pad_len;
5537         unsigned int plaintext_len;
5538         unsigned int ciphertext_pad_len;
5539         unsigned int ciphertext_len;
5540         uint8_t buffer[10000];
5541         uint8_t digest_buffer[10000];
5542
5543         struct rte_cryptodev_info dev_info;
5544
5545         /* Verify the capabilities */
5546         struct rte_cryptodev_sym_capability_idx cap_idx;
5547         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5548         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5549         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5550                         &cap_idx) == NULL)
5551                 return TEST_SKIPPED;
5552         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5553         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5554         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5555                         &cap_idx) == NULL)
5556                 return TEST_SKIPPED;
5557
5558         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5559                 return TEST_SKIPPED;
5560
5561         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5562
5563         uint64_t feat_flags = dev_info.feature_flags;
5564
5565         if (op_mode == IN_PLACE) {
5566                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5567                         printf("Device doesn't support in-place scatter-gather "
5568                                         "in both input and output mbufs.\n");
5569                         return TEST_SKIPPED;
5570                 }
5571                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5572                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5573                         printf("Device doesn't support RAW data-path APIs.\n");
5574                         return TEST_SKIPPED;
5575                 }
5576         } else {
5577                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5578                         return TEST_SKIPPED;
5579                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5580                         printf("Device doesn't support out-of-place scatter-gather "
5581                                         "in both input and output mbufs.\n");
5582                         return TEST_SKIPPED;
5583                 }
5584                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5585                         printf("Device doesn't support digest encrypted.\n");
5586                         return TEST_SKIPPED;
5587                 }
5588         }
5589
5590         /* Create KASUMI session */
5591         retval = create_wireless_algo_auth_cipher_session(
5592                         ts_params->valid_devs[0],
5593                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5594                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5595                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5596                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5597                         RTE_CRYPTO_AUTH_KASUMI_F9,
5598                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5599                         tdata->key.data, tdata->key.len,
5600                         0, tdata->digest.len,
5601                         tdata->cipher_iv.len);
5602
5603         if (retval != 0)
5604                 return retval;
5605
5606         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5607         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5608         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5609         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5610
5611         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5612                         plaintext_pad_len, 15, 0);
5613         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5614                         "Failed to allocate input buffer in mempool");
5615
5616         if (op_mode == OUT_OF_PLACE) {
5617                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5618                                 plaintext_pad_len, 15, 0);
5619                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5620                                 "Failed to allocate output buffer in mempool");
5621         }
5622
5623         if (verify) {
5624                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5625                         tdata->ciphertext.data);
5626                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5627                                         ciphertext_len, buffer);
5628                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5629                         ciphertext_len);
5630         } else {
5631                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5632                         tdata->plaintext.data);
5633                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5634                                         plaintext_len, buffer);
5635                 debug_hexdump(stdout, "plaintext:", plaintext,
5636                         plaintext_len);
5637         }
5638         memset(buffer, 0, sizeof(buffer));
5639
5640         /* Create KASUMI operation */
5641         retval = create_wireless_algo_auth_cipher_operation(
5642                 tdata->digest.data, tdata->digest.len,
5643                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5644                 NULL, 0,
5645                 (tdata->digest.offset_bytes == 0 ?
5646                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5647                         : tdata->digest.offset_bytes),
5648                 tdata->validCipherLenInBits.len,
5649                 tdata->validCipherOffsetInBits.len,
5650                 tdata->validAuthLenInBits.len,
5651                 0,
5652                 op_mode, 1, verify);
5653
5654         if (retval < 0)
5655                 return retval;
5656
5657         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5658                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5659                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5660         else
5661                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5662                         ut_params->op);
5663
5664         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5665
5666         ut_params->obuf = (op_mode == IN_PLACE ?
5667                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5668
5669         if (verify) {
5670                 if (ut_params->obuf)
5671                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5672                                         plaintext_len, buffer);
5673                 else
5674                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5675                                         plaintext_len, buffer);
5676
5677                 debug_hexdump(stdout, "plaintext:", plaintext,
5678                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5679                 debug_hexdump(stdout, "plaintext expected:",
5680                         tdata->plaintext.data,
5681                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5682         } else {
5683                 if (ut_params->obuf)
5684                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5685                                         ciphertext_len, buffer);
5686                 else
5687                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5688                                         ciphertext_len, buffer);
5689
5690                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5691                         ciphertext_len);
5692                 debug_hexdump(stdout, "ciphertext expected:",
5693                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5694
5695                 if (ut_params->obuf)
5696                         digest = rte_pktmbuf_read(ut_params->obuf,
5697                                 (tdata->digest.offset_bytes == 0 ?
5698                                 plaintext_pad_len : tdata->digest.offset_bytes),
5699                                 tdata->digest.len, digest_buffer);
5700                 else
5701                         digest = rte_pktmbuf_read(ut_params->ibuf,
5702                                 (tdata->digest.offset_bytes == 0 ?
5703                                 plaintext_pad_len : tdata->digest.offset_bytes),
5704                                 tdata->digest.len, digest_buffer);
5705
5706                 debug_hexdump(stdout, "digest:", digest,
5707                         tdata->digest.len);
5708                 debug_hexdump(stdout, "digest expected:",
5709                         tdata->digest.data, tdata->digest.len);
5710         }
5711
5712         /* Validate obuf */
5713         if (verify) {
5714                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5715                         plaintext,
5716                         tdata->plaintext.data,
5717                         tdata->plaintext.len >> 3,
5718                         "KASUMI Plaintext data not as expected");
5719         } else {
5720                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5721                         ciphertext,
5722                         tdata->ciphertext.data,
5723                         tdata->validDataLenInBits.len,
5724                         "KASUMI Ciphertext data not as expected");
5725
5726                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5727                         digest,
5728                         tdata->digest.data,
5729                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5730                         "KASUMI Generated auth tag not as expected");
5731         }
5732         return 0;
5733 }
5734
5735 static int
5736 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5737 {
5738         struct crypto_testsuite_params *ts_params = &testsuite_params;
5739         struct crypto_unittest_params *ut_params = &unittest_params;
5740
5741         int retval;
5742
5743         uint8_t *plaintext, *ciphertext;
5744         unsigned plaintext_pad_len;
5745         unsigned plaintext_len;
5746         struct rte_cryptodev_info dev_info;
5747
5748         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5749         uint64_t feat_flags = dev_info.feature_flags;
5750
5751         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5752                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5753                 printf("Device doesn't support RAW data-path APIs.\n");
5754                 return TEST_SKIPPED;
5755         }
5756
5757         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5758                 return TEST_SKIPPED;
5759
5760         /* Verify the capabilities */
5761         struct rte_cryptodev_sym_capability_idx cap_idx;
5762         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5763         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5764         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5765                         &cap_idx) == NULL)
5766                 return TEST_SKIPPED;
5767         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5768         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5769         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5770                         &cap_idx) == NULL)
5771                 return TEST_SKIPPED;
5772
5773         /* Create KASUMI session */
5774         retval = create_wireless_algo_cipher_auth_session(
5775                         ts_params->valid_devs[0],
5776                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5777                         RTE_CRYPTO_AUTH_OP_GENERATE,
5778                         RTE_CRYPTO_AUTH_KASUMI_F9,
5779                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5780                         tdata->key.data, tdata->key.len,
5781                         0, tdata->digest.len,
5782                         tdata->cipher_iv.len);
5783         if (retval != 0)
5784                 return retval;
5785
5786         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5787
5788         /* clear mbuf payload */
5789         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5790                         rte_pktmbuf_tailroom(ut_params->ibuf));
5791
5792         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5793         /* Append data which is padded to a multiple of */
5794         /* the algorithms block size */
5795         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5796         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5797                                 plaintext_pad_len);
5798         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5799
5800         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5801
5802         /* Create KASUMI operation */
5803         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5804                                 tdata->digest.len, NULL, 0,
5805                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5806                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5807                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5808                                 tdata->validCipherOffsetInBits.len,
5809                                 tdata->validAuthLenInBits.len,
5810                                 0
5811                                 );
5812         if (retval < 0)
5813                 return retval;
5814
5815         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5816                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5817                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5818         else
5819                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5820                         ut_params->op);
5821         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5822
5823         if (ut_params->op->sym->m_dst)
5824                 ut_params->obuf = ut_params->op->sym->m_dst;
5825         else
5826                 ut_params->obuf = ut_params->op->sym->m_src;
5827
5828         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5829                                 tdata->validCipherOffsetInBits.len >> 3);
5830
5831         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5832                         + plaintext_pad_len;
5833
5834         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5835                                 (tdata->validCipherOffsetInBits.len >> 3);
5836         /* Validate obuf */
5837         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5838                 ciphertext,
5839                 reference_ciphertext,
5840                 tdata->validCipherLenInBits.len,
5841                 "KASUMI Ciphertext data not as expected");
5842
5843         /* Validate obuf */
5844         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5845                 ut_params->digest,
5846                 tdata->digest.data,
5847                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5848                 "KASUMI Generated auth tag not as expected");
5849         return 0;
5850 }
5851
5852 static int
5853 test_zuc_encryption(const struct wireless_test_data *tdata)
5854 {
5855         struct crypto_testsuite_params *ts_params = &testsuite_params;
5856         struct crypto_unittest_params *ut_params = &unittest_params;
5857
5858         int retval;
5859         uint8_t *plaintext, *ciphertext;
5860         unsigned plaintext_pad_len;
5861         unsigned plaintext_len;
5862         struct rte_cryptodev_info dev_info;
5863
5864         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5865         uint64_t feat_flags = dev_info.feature_flags;
5866
5867         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5868                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5869                 printf("Device doesn't support RAW data-path APIs.\n");
5870                 return TEST_SKIPPED;
5871         }
5872
5873         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5874                 return TEST_SKIPPED;
5875
5876         struct rte_cryptodev_sym_capability_idx cap_idx;
5877
5878         /* Check if device supports ZUC EEA3 */
5879         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5880         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5881
5882         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5883                         &cap_idx) == NULL)
5884                 return TEST_SKIPPED;
5885
5886         /* Create ZUC session */
5887         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5888                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5889                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5890                                         tdata->key.data, tdata->key.len,
5891                                         tdata->cipher_iv.len);
5892         if (retval < 0)
5893                 return retval;
5894
5895         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5896
5897         /* Clear mbuf payload */
5898         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5899                rte_pktmbuf_tailroom(ut_params->ibuf));
5900
5901         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5902         /* Append data which is padded to a multiple */
5903         /* of the algorithms block size */
5904         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5905         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5906                                 plaintext_pad_len);
5907         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5908
5909         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5910
5911         /* Create ZUC operation */
5912         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5913                                         tdata->cipher_iv.len,
5914                                         tdata->plaintext.len,
5915                                         0);
5916         if (retval < 0)
5917                 return retval;
5918
5919         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5920                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5921                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5922         else
5923                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5924                                                 ut_params->op);
5925         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5926
5927         ut_params->obuf = ut_params->op->sym->m_dst;
5928         if (ut_params->obuf)
5929                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5930         else
5931                 ciphertext = plaintext;
5932
5933         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5934
5935         /* Validate obuf */
5936         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5937                 ciphertext,
5938                 tdata->ciphertext.data,
5939                 tdata->validCipherLenInBits.len,
5940                 "ZUC Ciphertext data not as expected");
5941         return 0;
5942 }
5943
5944 static int
5945 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5946 {
5947         struct crypto_testsuite_params *ts_params = &testsuite_params;
5948         struct crypto_unittest_params *ut_params = &unittest_params;
5949
5950         int retval;
5951
5952         unsigned int plaintext_pad_len;
5953         unsigned int plaintext_len;
5954         const uint8_t *ciphertext;
5955         uint8_t ciphertext_buffer[2048];
5956         struct rte_cryptodev_info dev_info;
5957
5958         struct rte_cryptodev_sym_capability_idx cap_idx;
5959
5960         /* Check if device supports ZUC EEA3 */
5961         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5962         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5963
5964         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5965                         &cap_idx) == NULL)
5966                 return TEST_SKIPPED;
5967
5968         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5969                 return TEST_SKIPPED;
5970
5971         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5972
5973         uint64_t feat_flags = dev_info.feature_flags;
5974
5975         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5976                 printf("Device doesn't support in-place scatter-gather. "
5977                                 "Test Skipped.\n");
5978                 return TEST_SKIPPED;
5979         }
5980
5981         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5982                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5983                 printf("Device doesn't support RAW data-path APIs.\n");
5984                 return TEST_SKIPPED;
5985         }
5986
5987         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5988
5989         /* Append data which is padded to a multiple */
5990         /* of the algorithms block size */
5991         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5992
5993         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5994                         plaintext_pad_len, 10, 0);
5995
5996         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5997                         tdata->plaintext.data);
5998
5999         /* Create ZUC session */
6000         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6001                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6002                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6003                         tdata->key.data, tdata->key.len,
6004                         tdata->cipher_iv.len);
6005         if (retval < 0)
6006                 return retval;
6007
6008         /* Clear mbuf payload */
6009
6010         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
6011
6012         /* Create ZUC operation */
6013         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6014                         tdata->cipher_iv.len, tdata->plaintext.len,
6015                         0);
6016         if (retval < 0)
6017                 return retval;
6018
6019         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6020                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6021                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6022         else
6023                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6024                                                 ut_params->op);
6025         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6026
6027         ut_params->obuf = ut_params->op->sym->m_dst;
6028         if (ut_params->obuf)
6029                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
6030                         0, plaintext_len, ciphertext_buffer);
6031         else
6032                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6033                         0, plaintext_len, ciphertext_buffer);
6034
6035         /* Validate obuf */
6036         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6037
6038         /* Validate obuf */
6039         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6040                 ciphertext,
6041                 tdata->ciphertext.data,
6042                 tdata->validCipherLenInBits.len,
6043                 "ZUC Ciphertext data not as expected");
6044
6045         return 0;
6046 }
6047
6048 static int
6049 test_zuc_authentication(const struct wireless_test_data *tdata)
6050 {
6051         struct crypto_testsuite_params *ts_params = &testsuite_params;
6052         struct crypto_unittest_params *ut_params = &unittest_params;
6053
6054         int retval;
6055         unsigned plaintext_pad_len;
6056         unsigned plaintext_len;
6057         uint8_t *plaintext;
6058
6059         struct rte_cryptodev_sym_capability_idx cap_idx;
6060         struct rte_cryptodev_info dev_info;
6061
6062         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6063         uint64_t feat_flags = dev_info.feature_flags;
6064
6065         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6066                         (tdata->validAuthLenInBits.len % 8 != 0)) {
6067                 printf("Device doesn't support NON-Byte Aligned Data.\n");
6068                 return TEST_SKIPPED;
6069         }
6070
6071         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6072                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6073                 printf("Device doesn't support RAW data-path APIs.\n");
6074                 return TEST_SKIPPED;
6075         }
6076
6077         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6078                 return TEST_SKIPPED;
6079
6080         /* Check if device supports ZUC EIA3 */
6081         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6082         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6083
6084         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6085                         &cap_idx) == NULL)
6086                 return TEST_SKIPPED;
6087
6088         /* Create ZUC session */
6089         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6090                         tdata->key.data, tdata->key.len,
6091                         tdata->auth_iv.len, tdata->digest.len,
6092                         RTE_CRYPTO_AUTH_OP_GENERATE,
6093                         RTE_CRYPTO_AUTH_ZUC_EIA3);
6094         if (retval < 0)
6095                 return retval;
6096
6097         /* alloc mbuf and set payload */
6098         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6099
6100         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6101         rte_pktmbuf_tailroom(ut_params->ibuf));
6102
6103         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6104         /* Append data which is padded to a multiple of */
6105         /* the algorithms block size */
6106         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6107         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6108                                 plaintext_pad_len);
6109         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6110
6111         /* Create ZUC operation */
6112         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6113                         tdata->auth_iv.data, tdata->auth_iv.len,
6114                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6115                         tdata->validAuthLenInBits.len,
6116                         0);
6117         if (retval < 0)
6118                 return retval;
6119
6120         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6121                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6122                                 ut_params->op, 0, 1, 1, 0);
6123         else
6124                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6125                                 ut_params->op);
6126         ut_params->obuf = ut_params->op->sym->m_src;
6127         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6128         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6129                         + plaintext_pad_len;
6130
6131         /* Validate obuf */
6132         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6133         ut_params->digest,
6134         tdata->digest.data,
6135         tdata->digest.len,
6136         "ZUC Generated auth tag not as expected");
6137
6138         return 0;
6139 }
6140
6141 static int
6142 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6143         uint8_t op_mode, uint8_t verify)
6144 {
6145         struct crypto_testsuite_params *ts_params = &testsuite_params;
6146         struct crypto_unittest_params *ut_params = &unittest_params;
6147
6148         int retval;
6149
6150         uint8_t *plaintext = NULL, *ciphertext = NULL;
6151         unsigned int plaintext_pad_len;
6152         unsigned int plaintext_len;
6153         unsigned int ciphertext_pad_len;
6154         unsigned int ciphertext_len;
6155
6156         struct rte_cryptodev_info dev_info;
6157         struct rte_cryptodev_sym_capability_idx cap_idx;
6158
6159         /* Check if device supports ZUC EIA3 */
6160         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6161         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6162
6163         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6164                         &cap_idx) == NULL)
6165                 return TEST_SKIPPED;
6166
6167         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6168
6169         uint64_t feat_flags = dev_info.feature_flags;
6170
6171         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6172                 printf("Device doesn't support digest encrypted.\n");
6173                 return TEST_SKIPPED;
6174         }
6175         if (op_mode == IN_PLACE) {
6176                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6177                         printf("Device doesn't support in-place scatter-gather "
6178                                         "in both input and output mbufs.\n");
6179                         return TEST_SKIPPED;
6180                 }
6181
6182                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6183                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6184                         printf("Device doesn't support RAW data-path APIs.\n");
6185                         return TEST_SKIPPED;
6186                 }
6187         } else {
6188                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6189                         return TEST_SKIPPED;
6190                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6191                         printf("Device doesn't support out-of-place scatter-gather "
6192                                         "in both input and output mbufs.\n");
6193                         return TEST_SKIPPED;
6194                 }
6195         }
6196
6197         /* Create ZUC session */
6198         retval = create_wireless_algo_auth_cipher_session(
6199                         ts_params->valid_devs[0],
6200                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6201                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6202                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6203                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6204                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6205                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6206                         tdata->key.data, tdata->key.len,
6207                         tdata->auth_iv.len, tdata->digest.len,
6208                         tdata->cipher_iv.len);
6209
6210         if (retval != 0)
6211                 return retval;
6212
6213         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6214         if (op_mode == OUT_OF_PLACE)
6215                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6216
6217         /* clear mbuf payload */
6218         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6219                 rte_pktmbuf_tailroom(ut_params->ibuf));
6220         if (op_mode == OUT_OF_PLACE)
6221                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6222                         rte_pktmbuf_tailroom(ut_params->obuf));
6223
6224         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6225         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6226         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6227         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6228
6229         if (verify) {
6230                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6231                                         ciphertext_pad_len);
6232                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6233                 if (op_mode == OUT_OF_PLACE)
6234                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6235                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6236                         ciphertext_len);
6237         } else {
6238                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6239                                         plaintext_pad_len);
6240                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6241                 if (op_mode == OUT_OF_PLACE)
6242                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6243                 debug_hexdump(stdout, "plaintext:", plaintext,
6244                         plaintext_len);
6245         }
6246
6247         /* Create ZUC operation */
6248         retval = create_wireless_algo_auth_cipher_operation(
6249                 tdata->digest.data, tdata->digest.len,
6250                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6251                 tdata->auth_iv.data, tdata->auth_iv.len,
6252                 (tdata->digest.offset_bytes == 0 ?
6253                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6254                         : tdata->digest.offset_bytes),
6255                 tdata->validCipherLenInBits.len,
6256                 tdata->validCipherOffsetInBits.len,
6257                 tdata->validAuthLenInBits.len,
6258                 0,
6259                 op_mode, 0, verify);
6260
6261         if (retval < 0)
6262                 return retval;
6263
6264         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6265                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6266                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6267         else
6268                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6269                         ut_params->op);
6270
6271         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6272
6273         ut_params->obuf = (op_mode == IN_PLACE ?
6274                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6275
6276
6277         if (verify) {
6278                 if (ut_params->obuf)
6279                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6280                                                         uint8_t *);
6281                 else
6282                         plaintext = ciphertext;
6283
6284                 debug_hexdump(stdout, "plaintext:", plaintext,
6285                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6286                 debug_hexdump(stdout, "plaintext expected:",
6287                         tdata->plaintext.data,
6288                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6289         } else {
6290                 if (ut_params->obuf)
6291                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6292                                                         uint8_t *);
6293                 else
6294                         ciphertext = plaintext;
6295
6296                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6297                         ciphertext_len);
6298                 debug_hexdump(stdout, "ciphertext expected:",
6299                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6300
6301                 ut_params->digest = rte_pktmbuf_mtod(
6302                         ut_params->obuf, uint8_t *) +
6303                         (tdata->digest.offset_bytes == 0 ?
6304                         plaintext_pad_len : tdata->digest.offset_bytes);
6305
6306                 debug_hexdump(stdout, "digest:", ut_params->digest,
6307                         tdata->digest.len);
6308                 debug_hexdump(stdout, "digest expected:",
6309                         tdata->digest.data, tdata->digest.len);
6310         }
6311
6312         /* Validate obuf */
6313         if (verify) {
6314                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6315                         plaintext,
6316                         tdata->plaintext.data,
6317                         tdata->plaintext.len >> 3,
6318                         "ZUC Plaintext data not as expected");
6319         } else {
6320                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6321                         ciphertext,
6322                         tdata->ciphertext.data,
6323                         tdata->ciphertext.len >> 3,
6324                         "ZUC Ciphertext data not as expected");
6325
6326                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6327                         ut_params->digest,
6328                         tdata->digest.data,
6329                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6330                         "ZUC Generated auth tag not as expected");
6331         }
6332         return 0;
6333 }
6334
6335 static int
6336 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6337         uint8_t op_mode, uint8_t verify)
6338 {
6339         struct crypto_testsuite_params *ts_params = &testsuite_params;
6340         struct crypto_unittest_params *ut_params = &unittest_params;
6341
6342         int retval;
6343
6344         const uint8_t *plaintext = NULL;
6345         const uint8_t *ciphertext = NULL;
6346         const uint8_t *digest = NULL;
6347         unsigned int plaintext_pad_len;
6348         unsigned int plaintext_len;
6349         unsigned int ciphertext_pad_len;
6350         unsigned int ciphertext_len;
6351         uint8_t buffer[10000];
6352         uint8_t digest_buffer[10000];
6353
6354         struct rte_cryptodev_info dev_info;
6355         struct rte_cryptodev_sym_capability_idx cap_idx;
6356
6357         /* Check if device supports ZUC EIA3 */
6358         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6359         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6360
6361         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6362                         &cap_idx) == NULL)
6363                 return TEST_SKIPPED;
6364
6365         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6366
6367         uint64_t feat_flags = dev_info.feature_flags;
6368
6369         if (op_mode == IN_PLACE) {
6370                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6371                         printf("Device doesn't support in-place scatter-gather "
6372                                         "in both input and output mbufs.\n");
6373                         return TEST_SKIPPED;
6374                 }
6375
6376                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6377                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6378                         printf("Device doesn't support RAW data-path APIs.\n");
6379                         return TEST_SKIPPED;
6380                 }
6381         } else {
6382                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6383                         return TEST_SKIPPED;
6384                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6385                         printf("Device doesn't support out-of-place scatter-gather "
6386                                         "in both input and output mbufs.\n");
6387                         return TEST_SKIPPED;
6388                 }
6389                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6390                         printf("Device doesn't support digest encrypted.\n");
6391                         return TEST_SKIPPED;
6392                 }
6393         }
6394
6395         /* Create ZUC session */
6396         retval = create_wireless_algo_auth_cipher_session(
6397                         ts_params->valid_devs[0],
6398                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6399                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6400                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6401                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6402                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6403                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6404                         tdata->key.data, tdata->key.len,
6405                         tdata->auth_iv.len, tdata->digest.len,
6406                         tdata->cipher_iv.len);
6407
6408         if (retval != 0)
6409                 return retval;
6410
6411         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6412         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6413         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6414         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6415
6416         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6417                         plaintext_pad_len, 15, 0);
6418         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6419                         "Failed to allocate input buffer in mempool");
6420
6421         if (op_mode == OUT_OF_PLACE) {
6422                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6423                                 plaintext_pad_len, 15, 0);
6424                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6425                                 "Failed to allocate output buffer in mempool");
6426         }
6427
6428         if (verify) {
6429                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6430                         tdata->ciphertext.data);
6431                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6432                                         ciphertext_len, buffer);
6433                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6434                         ciphertext_len);
6435         } else {
6436                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6437                         tdata->plaintext.data);
6438                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6439                                         plaintext_len, buffer);
6440                 debug_hexdump(stdout, "plaintext:", plaintext,
6441                         plaintext_len);
6442         }
6443         memset(buffer, 0, sizeof(buffer));
6444
6445         /* Create ZUC operation */
6446         retval = create_wireless_algo_auth_cipher_operation(
6447                 tdata->digest.data, tdata->digest.len,
6448                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6449                 NULL, 0,
6450                 (tdata->digest.offset_bytes == 0 ?
6451                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6452                         : tdata->digest.offset_bytes),
6453                 tdata->validCipherLenInBits.len,
6454                 tdata->validCipherOffsetInBits.len,
6455                 tdata->validAuthLenInBits.len,
6456                 0,
6457                 op_mode, 1, verify);
6458
6459         if (retval < 0)
6460                 return retval;
6461
6462         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6463                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6464                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6465         else
6466                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6467                         ut_params->op);
6468
6469         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6470
6471         ut_params->obuf = (op_mode == IN_PLACE ?
6472                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6473
6474         if (verify) {
6475                 if (ut_params->obuf)
6476                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6477                                         plaintext_len, buffer);
6478                 else
6479                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6480                                         plaintext_len, buffer);
6481
6482                 debug_hexdump(stdout, "plaintext:", plaintext,
6483                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6484                 debug_hexdump(stdout, "plaintext expected:",
6485                         tdata->plaintext.data,
6486                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6487         } else {
6488                 if (ut_params->obuf)
6489                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6490                                         ciphertext_len, buffer);
6491                 else
6492                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6493                                         ciphertext_len, buffer);
6494
6495                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6496                         ciphertext_len);
6497                 debug_hexdump(stdout, "ciphertext expected:",
6498                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6499
6500                 if (ut_params->obuf)
6501                         digest = rte_pktmbuf_read(ut_params->obuf,
6502                                 (tdata->digest.offset_bytes == 0 ?
6503                                 plaintext_pad_len : tdata->digest.offset_bytes),
6504                                 tdata->digest.len, digest_buffer);
6505                 else
6506                         digest = rte_pktmbuf_read(ut_params->ibuf,
6507                                 (tdata->digest.offset_bytes == 0 ?
6508                                 plaintext_pad_len : tdata->digest.offset_bytes),
6509                                 tdata->digest.len, digest_buffer);
6510
6511                 debug_hexdump(stdout, "digest:", digest,
6512                         tdata->digest.len);
6513                 debug_hexdump(stdout, "digest expected:",
6514                         tdata->digest.data, tdata->digest.len);
6515         }
6516
6517         /* Validate obuf */
6518         if (verify) {
6519                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6520                         plaintext,
6521                         tdata->plaintext.data,
6522                         tdata->plaintext.len >> 3,
6523                         "ZUC Plaintext data not as expected");
6524         } else {
6525                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6526                         ciphertext,
6527                         tdata->ciphertext.data,
6528                         tdata->validDataLenInBits.len,
6529                         "ZUC Ciphertext data not as expected");
6530
6531                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6532                         digest,
6533                         tdata->digest.data,
6534                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6535                         "ZUC Generated auth tag not as expected");
6536         }
6537         return 0;
6538 }
6539
6540 static int
6541 test_kasumi_encryption_test_case_1(void)
6542 {
6543         return test_kasumi_encryption(&kasumi_test_case_1);
6544 }
6545
6546 static int
6547 test_kasumi_encryption_test_case_1_sgl(void)
6548 {
6549         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6550 }
6551
6552 static int
6553 test_kasumi_encryption_test_case_1_oop(void)
6554 {
6555         return test_kasumi_encryption_oop(&kasumi_test_case_1);
6556 }
6557
6558 static int
6559 test_kasumi_encryption_test_case_1_oop_sgl(void)
6560 {
6561         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6562 }
6563
6564 static int
6565 test_kasumi_encryption_test_case_2(void)
6566 {
6567         return test_kasumi_encryption(&kasumi_test_case_2);
6568 }
6569
6570 static int
6571 test_kasumi_encryption_test_case_3(void)
6572 {
6573         return test_kasumi_encryption(&kasumi_test_case_3);
6574 }
6575
6576 static int
6577 test_kasumi_encryption_test_case_4(void)
6578 {
6579         return test_kasumi_encryption(&kasumi_test_case_4);
6580 }
6581
6582 static int
6583 test_kasumi_encryption_test_case_5(void)
6584 {
6585         return test_kasumi_encryption(&kasumi_test_case_5);
6586 }
6587
6588 static int
6589 test_kasumi_decryption_test_case_1(void)
6590 {
6591         return test_kasumi_decryption(&kasumi_test_case_1);
6592 }
6593
6594 static int
6595 test_kasumi_decryption_test_case_1_oop(void)
6596 {
6597         return test_kasumi_decryption_oop(&kasumi_test_case_1);
6598 }
6599
6600 static int
6601 test_kasumi_decryption_test_case_2(void)
6602 {
6603         return test_kasumi_decryption(&kasumi_test_case_2);
6604 }
6605
6606 static int
6607 test_kasumi_decryption_test_case_3(void)
6608 {
6609         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6610         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6611                 return TEST_SKIPPED;
6612         return test_kasumi_decryption(&kasumi_test_case_3);
6613 }
6614
6615 static int
6616 test_kasumi_decryption_test_case_4(void)
6617 {
6618         return test_kasumi_decryption(&kasumi_test_case_4);
6619 }
6620
6621 static int
6622 test_kasumi_decryption_test_case_5(void)
6623 {
6624         return test_kasumi_decryption(&kasumi_test_case_5);
6625 }
6626 static int
6627 test_snow3g_encryption_test_case_1(void)
6628 {
6629         return test_snow3g_encryption(&snow3g_test_case_1);
6630 }
6631
6632 static int
6633 test_snow3g_encryption_test_case_1_oop(void)
6634 {
6635         return test_snow3g_encryption_oop(&snow3g_test_case_1);
6636 }
6637
6638 static int
6639 test_snow3g_encryption_test_case_1_oop_sgl(void)
6640 {
6641         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6642 }
6643
6644
6645 static int
6646 test_snow3g_encryption_test_case_1_offset_oop(void)
6647 {
6648         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6649 }
6650
6651 static int
6652 test_snow3g_encryption_test_case_2(void)
6653 {
6654         return test_snow3g_encryption(&snow3g_test_case_2);
6655 }
6656
6657 static int
6658 test_snow3g_encryption_test_case_3(void)
6659 {
6660         return test_snow3g_encryption(&snow3g_test_case_3);
6661 }
6662
6663 static int
6664 test_snow3g_encryption_test_case_4(void)
6665 {
6666         return test_snow3g_encryption(&snow3g_test_case_4);
6667 }
6668
6669 static int
6670 test_snow3g_encryption_test_case_5(void)
6671 {
6672         return test_snow3g_encryption(&snow3g_test_case_5);
6673 }
6674
6675 static int
6676 test_snow3g_decryption_test_case_1(void)
6677 {
6678         return test_snow3g_decryption(&snow3g_test_case_1);
6679 }
6680
6681 static int
6682 test_snow3g_decryption_test_case_1_oop(void)
6683 {
6684         return test_snow3g_decryption_oop(&snow3g_test_case_1);
6685 }
6686
6687 static int
6688 test_snow3g_decryption_test_case_2(void)
6689 {
6690         return test_snow3g_decryption(&snow3g_test_case_2);
6691 }
6692
6693 static int
6694 test_snow3g_decryption_test_case_3(void)
6695 {
6696         return test_snow3g_decryption(&snow3g_test_case_3);
6697 }
6698
6699 static int
6700 test_snow3g_decryption_test_case_4(void)
6701 {
6702         return test_snow3g_decryption(&snow3g_test_case_4);
6703 }
6704
6705 static int
6706 test_snow3g_decryption_test_case_5(void)
6707 {
6708         return test_snow3g_decryption(&snow3g_test_case_5);
6709 }
6710
6711 /*
6712  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6713  * Pattern digest from snow3g_test_data must be allocated as
6714  * 4 last bytes in plaintext.
6715  */
6716 static void
6717 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6718                 struct snow3g_hash_test_data *output)
6719 {
6720         if ((pattern != NULL) && (output != NULL)) {
6721                 output->key.len = pattern->key.len;
6722
6723                 memcpy(output->key.data,
6724                 pattern->key.data, pattern->key.len);
6725
6726                 output->auth_iv.len = pattern->auth_iv.len;
6727
6728                 memcpy(output->auth_iv.data,
6729                 pattern->auth_iv.data, pattern->auth_iv.len);
6730
6731                 output->plaintext.len = pattern->plaintext.len;
6732
6733                 memcpy(output->plaintext.data,
6734                 pattern->plaintext.data, pattern->plaintext.len >> 3);
6735
6736                 output->digest.len = pattern->digest.len;
6737
6738                 memcpy(output->digest.data,
6739                 &pattern->plaintext.data[pattern->digest.offset_bytes],
6740                 pattern->digest.len);
6741
6742                 output->validAuthLenInBits.len =
6743                 pattern->validAuthLenInBits.len;
6744         }
6745 }
6746
6747 /*
6748  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6749  */
6750 static int
6751 test_snow3g_decryption_with_digest_test_case_1(void)
6752 {
6753         struct snow3g_hash_test_data snow3g_hash_data;
6754         struct rte_cryptodev_info dev_info;
6755         struct crypto_testsuite_params *ts_params = &testsuite_params;
6756
6757         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6758         uint64_t feat_flags = dev_info.feature_flags;
6759
6760         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6761                 printf("Device doesn't support encrypted digest operations.\n");
6762                 return TEST_SKIPPED;
6763         }
6764
6765         /*
6766          * Function prepare data for hash veryfication test case.
6767          * Digest is allocated in 4 last bytes in plaintext, pattern.
6768          */
6769         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6770
6771         return test_snow3g_decryption(&snow3g_test_case_7) &
6772                         test_snow3g_authentication_verify(&snow3g_hash_data);
6773 }
6774
6775 static int
6776 test_snow3g_cipher_auth_test_case_1(void)
6777 {
6778         return test_snow3g_cipher_auth(&snow3g_test_case_3);
6779 }
6780
6781 static int
6782 test_snow3g_auth_cipher_test_case_1(void)
6783 {
6784         return test_snow3g_auth_cipher(
6785                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6786 }
6787
6788 static int
6789 test_snow3g_auth_cipher_test_case_2(void)
6790 {
6791         return test_snow3g_auth_cipher(
6792                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6793 }
6794
6795 static int
6796 test_snow3g_auth_cipher_test_case_2_oop(void)
6797 {
6798         return test_snow3g_auth_cipher(
6799                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6800 }
6801
6802 static int
6803 test_snow3g_auth_cipher_part_digest_enc(void)
6804 {
6805         return test_snow3g_auth_cipher(
6806                 &snow3g_auth_cipher_partial_digest_encryption,
6807                         IN_PLACE, 0);
6808 }
6809
6810 static int
6811 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6812 {
6813         return test_snow3g_auth_cipher(
6814                 &snow3g_auth_cipher_partial_digest_encryption,
6815                         OUT_OF_PLACE, 0);
6816 }
6817
6818 static int
6819 test_snow3g_auth_cipher_test_case_3_sgl(void)
6820 {
6821         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6822         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6823                 return TEST_SKIPPED;
6824         return test_snow3g_auth_cipher_sgl(
6825                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6826 }
6827
6828 static int
6829 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6830 {
6831         return test_snow3g_auth_cipher_sgl(
6832                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6833 }
6834
6835 static int
6836 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6837 {
6838         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6839         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6840                 return TEST_SKIPPED;
6841         return test_snow3g_auth_cipher_sgl(
6842                 &snow3g_auth_cipher_partial_digest_encryption,
6843                         IN_PLACE, 0);
6844 }
6845
6846 static int
6847 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6848 {
6849         return test_snow3g_auth_cipher_sgl(
6850                 &snow3g_auth_cipher_partial_digest_encryption,
6851                         OUT_OF_PLACE, 0);
6852 }
6853
6854 static int
6855 test_snow3g_auth_cipher_verify_test_case_1(void)
6856 {
6857         return test_snow3g_auth_cipher(
6858                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6859 }
6860
6861 static int
6862 test_snow3g_auth_cipher_verify_test_case_2(void)
6863 {
6864         return test_snow3g_auth_cipher(
6865                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6866 }
6867
6868 static int
6869 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6870 {
6871         return test_snow3g_auth_cipher(
6872                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6873 }
6874
6875 static int
6876 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6877 {
6878         return test_snow3g_auth_cipher(
6879                 &snow3g_auth_cipher_partial_digest_encryption,
6880                         IN_PLACE, 1);
6881 }
6882
6883 static int
6884 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6885 {
6886         return test_snow3g_auth_cipher(
6887                 &snow3g_auth_cipher_partial_digest_encryption,
6888                         OUT_OF_PLACE, 1);
6889 }
6890
6891 static int
6892 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6893 {
6894         return test_snow3g_auth_cipher_sgl(
6895                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6896 }
6897
6898 static int
6899 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6900 {
6901         return test_snow3g_auth_cipher_sgl(
6902                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6903 }
6904
6905 static int
6906 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6907 {
6908         return test_snow3g_auth_cipher_sgl(
6909                 &snow3g_auth_cipher_partial_digest_encryption,
6910                         IN_PLACE, 1);
6911 }
6912
6913 static int
6914 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6915 {
6916         return test_snow3g_auth_cipher_sgl(
6917                 &snow3g_auth_cipher_partial_digest_encryption,
6918                         OUT_OF_PLACE, 1);
6919 }
6920
6921 static int
6922 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6923 {
6924         return test_snow3g_auth_cipher(
6925                 &snow3g_test_case_7, IN_PLACE, 0);
6926 }
6927
6928 static int
6929 test_kasumi_auth_cipher_test_case_1(void)
6930 {
6931         return test_kasumi_auth_cipher(
6932                 &kasumi_test_case_3, IN_PLACE, 0);
6933 }
6934
6935 static int
6936 test_kasumi_auth_cipher_test_case_2(void)
6937 {
6938         return test_kasumi_auth_cipher(
6939                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6940 }
6941
6942 static int
6943 test_kasumi_auth_cipher_test_case_2_oop(void)
6944 {
6945         return test_kasumi_auth_cipher(
6946                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6947 }
6948
6949 static int
6950 test_kasumi_auth_cipher_test_case_2_sgl(void)
6951 {
6952         return test_kasumi_auth_cipher_sgl(
6953                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6954 }
6955
6956 static int
6957 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6958 {
6959         return test_kasumi_auth_cipher_sgl(
6960                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6961 }
6962
6963 static int
6964 test_kasumi_auth_cipher_verify_test_case_1(void)
6965 {
6966         return test_kasumi_auth_cipher(
6967                 &kasumi_test_case_3, IN_PLACE, 1);
6968 }
6969
6970 static int
6971 test_kasumi_auth_cipher_verify_test_case_2(void)
6972 {
6973         return test_kasumi_auth_cipher(
6974                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6975 }
6976
6977 static int
6978 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6979 {
6980         return test_kasumi_auth_cipher(
6981                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6982 }
6983
6984 static int
6985 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6986 {
6987         return test_kasumi_auth_cipher_sgl(
6988                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6989 }
6990
6991 static int
6992 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6993 {
6994         return test_kasumi_auth_cipher_sgl(
6995                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6996 }
6997
6998 static int
6999 test_kasumi_cipher_auth_test_case_1(void)
7000 {
7001         return test_kasumi_cipher_auth(&kasumi_test_case_6);
7002 }
7003
7004 static int
7005 test_zuc_encryption_test_case_1(void)
7006 {
7007         return test_zuc_encryption(&zuc_test_case_cipher_193b);
7008 }
7009
7010 static int
7011 test_zuc_encryption_test_case_2(void)
7012 {
7013         return test_zuc_encryption(&zuc_test_case_cipher_800b);
7014 }
7015
7016 static int
7017 test_zuc_encryption_test_case_3(void)
7018 {
7019         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
7020 }
7021
7022 static int
7023 test_zuc_encryption_test_case_4(void)
7024 {
7025         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
7026 }
7027
7028 static int
7029 test_zuc_encryption_test_case_5(void)
7030 {
7031         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7032 }
7033
7034 static int
7035 test_zuc_encryption_test_case_6_sgl(void)
7036 {
7037         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7038 }
7039
7040 static int
7041 test_zuc_hash_generate_test_case_1(void)
7042 {
7043         return test_zuc_authentication(&zuc_test_case_auth_1b);
7044 }
7045
7046 static int
7047 test_zuc_hash_generate_test_case_2(void)
7048 {
7049         return test_zuc_authentication(&zuc_test_case_auth_90b);
7050 }
7051
7052 static int
7053 test_zuc_hash_generate_test_case_3(void)
7054 {
7055         return test_zuc_authentication(&zuc_test_case_auth_577b);
7056 }
7057
7058 static int
7059 test_zuc_hash_generate_test_case_4(void)
7060 {
7061         return test_zuc_authentication(&zuc_test_case_auth_2079b);
7062 }
7063
7064 static int
7065 test_zuc_hash_generate_test_case_5(void)
7066 {
7067         return test_zuc_authentication(&zuc_test_auth_5670b);
7068 }
7069
7070 static int
7071 test_zuc_hash_generate_test_case_6(void)
7072 {
7073         return test_zuc_authentication(&zuc_test_case_auth_128b);
7074 }
7075
7076 static int
7077 test_zuc_hash_generate_test_case_7(void)
7078 {
7079         return test_zuc_authentication(&zuc_test_case_auth_2080b);
7080 }
7081
7082 static int
7083 test_zuc_hash_generate_test_case_8(void)
7084 {
7085         return test_zuc_authentication(&zuc_test_case_auth_584b);
7086 }
7087
7088 static int
7089 test_zuc_cipher_auth_test_case_1(void)
7090 {
7091         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7092 }
7093
7094 static int
7095 test_zuc_cipher_auth_test_case_2(void)
7096 {
7097         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7098 }
7099
7100 static int
7101 test_zuc_auth_cipher_test_case_1(void)
7102 {
7103         return test_zuc_auth_cipher(
7104                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7105 }
7106
7107 static int
7108 test_zuc_auth_cipher_test_case_1_oop(void)
7109 {
7110         return test_zuc_auth_cipher(
7111                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7112 }
7113
7114 static int
7115 test_zuc_auth_cipher_test_case_1_sgl(void)
7116 {
7117         return test_zuc_auth_cipher_sgl(
7118                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7119 }
7120
7121 static int
7122 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7123 {
7124         return test_zuc_auth_cipher_sgl(
7125                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7126 }
7127
7128 static int
7129 test_zuc_auth_cipher_verify_test_case_1(void)
7130 {
7131         return test_zuc_auth_cipher(
7132                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7133 }
7134
7135 static int
7136 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7137 {
7138         return test_zuc_auth_cipher(
7139                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7140 }
7141
7142 static int
7143 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7144 {
7145         return test_zuc_auth_cipher_sgl(
7146                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7147 }
7148
7149 static int
7150 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7151 {
7152         return test_zuc_auth_cipher_sgl(
7153                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7154 }
7155
7156 static int
7157 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7158 {
7159         uint8_t dev_id = testsuite_params.valid_devs[0];
7160
7161         struct rte_cryptodev_sym_capability_idx cap_idx;
7162
7163         /* Check if device supports particular cipher algorithm */
7164         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7165         cap_idx.algo.cipher = tdata->cipher_algo;
7166         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7167                 return TEST_SKIPPED;
7168
7169         /* Check if device supports particular hash algorithm */
7170         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7171         cap_idx.algo.auth = tdata->auth_algo;
7172         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7173                 return TEST_SKIPPED;
7174
7175         return 0;
7176 }
7177
7178 static int
7179 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7180         uint8_t op_mode, uint8_t verify)
7181 {
7182         struct crypto_testsuite_params *ts_params = &testsuite_params;
7183         struct crypto_unittest_params *ut_params = &unittest_params;
7184
7185         int retval;
7186
7187         uint8_t *plaintext = NULL, *ciphertext = NULL;
7188         unsigned int plaintext_pad_len;
7189         unsigned int plaintext_len;
7190         unsigned int ciphertext_pad_len;
7191         unsigned int ciphertext_len;
7192
7193         struct rte_cryptodev_info dev_info;
7194         struct rte_crypto_op *op;
7195
7196         /* Check if device supports particular algorithms separately */
7197         if (test_mixed_check_if_unsupported(tdata))
7198                 return TEST_SKIPPED;
7199         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7200                 return TEST_SKIPPED;
7201
7202         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7203
7204         uint64_t feat_flags = dev_info.feature_flags;
7205
7206         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7207                 printf("Device doesn't support digest encrypted.\n");
7208                 return TEST_SKIPPED;
7209         }
7210
7211         /* Create the session */
7212         if (verify)
7213                 retval = create_wireless_algo_cipher_auth_session(
7214                                 ts_params->valid_devs[0],
7215                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7216                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7217                                 tdata->auth_algo,
7218                                 tdata->cipher_algo,
7219                                 tdata->auth_key.data, tdata->auth_key.len,
7220                                 tdata->auth_iv.len, tdata->digest_enc.len,
7221                                 tdata->cipher_iv.len);
7222         else
7223                 retval = create_wireless_algo_auth_cipher_session(
7224                                 ts_params->valid_devs[0],
7225                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7226                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7227                                 tdata->auth_algo,
7228                                 tdata->cipher_algo,
7229                                 tdata->auth_key.data, tdata->auth_key.len,
7230                                 tdata->auth_iv.len, tdata->digest_enc.len,
7231                                 tdata->cipher_iv.len);
7232         if (retval != 0)
7233                 return retval;
7234
7235         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7236         if (op_mode == OUT_OF_PLACE)
7237                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7238
7239         /* clear mbuf payload */
7240         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7241                 rte_pktmbuf_tailroom(ut_params->ibuf));
7242         if (op_mode == OUT_OF_PLACE) {
7243
7244                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7245                                 rte_pktmbuf_tailroom(ut_params->obuf));
7246         }
7247
7248         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7249         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7250         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7251         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7252
7253         if (verify) {
7254                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7255                                 ciphertext_pad_len);
7256                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7257                 if (op_mode == OUT_OF_PLACE)
7258                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7259                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7260                                 ciphertext_len);
7261         } else {
7262                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7263                                 plaintext_pad_len);
7264                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7265                 if (op_mode == OUT_OF_PLACE)
7266                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7267                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7268         }
7269
7270         /* Create the operation */
7271         retval = create_wireless_algo_auth_cipher_operation(
7272                         tdata->digest_enc.data, tdata->digest_enc.len,
7273                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7274                         tdata->auth_iv.data, tdata->auth_iv.len,
7275                         (tdata->digest_enc.offset == 0 ?
7276                                 plaintext_pad_len
7277                                 : tdata->digest_enc.offset),
7278                         tdata->validCipherLen.len_bits,
7279                         tdata->cipher.offset_bits,
7280                         tdata->validAuthLen.len_bits,
7281                         tdata->auth.offset_bits,
7282                         op_mode, 0, verify);
7283
7284         if (retval < 0)
7285                 return retval;
7286
7287         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7288
7289         /* Check if the op failed because the device doesn't */
7290         /* support this particular combination of algorithms */
7291         if (op == NULL && ut_params->op->status ==
7292                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7293                 printf("Device doesn't support this mixed combination. "
7294                                 "Test Skipped.\n");
7295                 return TEST_SKIPPED;
7296         }
7297         ut_params->op = op;
7298
7299         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7300
7301         ut_params->obuf = (op_mode == IN_PLACE ?
7302                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7303
7304         if (verify) {
7305                 if (ut_params->obuf)
7306                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7307                                                         uint8_t *);
7308                 else
7309                         plaintext = ciphertext +
7310                                         (tdata->cipher.offset_bits >> 3);
7311
7312                 debug_hexdump(stdout, "plaintext:", plaintext,
7313                                 tdata->plaintext.len_bits >> 3);
7314                 debug_hexdump(stdout, "plaintext expected:",
7315                                 tdata->plaintext.data,
7316                                 tdata->plaintext.len_bits >> 3);
7317         } else {
7318                 if (ut_params->obuf)
7319                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7320                                         uint8_t *);
7321                 else
7322                         ciphertext = plaintext;
7323
7324                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7325                                 ciphertext_len);
7326                 debug_hexdump(stdout, "ciphertext expected:",
7327                                 tdata->ciphertext.data,
7328                                 tdata->ciphertext.len_bits >> 3);
7329
7330                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7331                                 + (tdata->digest_enc.offset == 0 ?
7332                 plaintext_pad_len : tdata->digest_enc.offset);
7333
7334                 debug_hexdump(stdout, "digest:", ut_params->digest,
7335                                 tdata->digest_enc.len);
7336                 debug_hexdump(stdout, "digest expected:",
7337                                 tdata->digest_enc.data,
7338                                 tdata->digest_enc.len);
7339         }
7340
7341         /* Validate obuf */
7342         if (verify) {
7343                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7344                                 plaintext,
7345                                 tdata->plaintext.data,
7346                                 tdata->plaintext.len_bits >> 3,
7347                                 "Plaintext data not as expected");
7348         } else {
7349                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7350                                 ciphertext,
7351                                 tdata->ciphertext.data,
7352                                 tdata->validDataLen.len_bits,
7353                                 "Ciphertext data not as expected");
7354
7355                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7356                                 ut_params->digest,
7357                                 tdata->digest_enc.data,
7358                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7359                                 "Generated auth tag not as expected");
7360         }
7361
7362         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7363                         "crypto op processing failed");
7364
7365         return 0;
7366 }
7367
7368 static int
7369 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7370         uint8_t op_mode, uint8_t verify)
7371 {
7372         struct crypto_testsuite_params *ts_params = &testsuite_params;
7373         struct crypto_unittest_params *ut_params = &unittest_params;
7374
7375         int retval;
7376
7377         const uint8_t *plaintext = NULL;
7378         const uint8_t *ciphertext = NULL;
7379         const uint8_t *digest = NULL;
7380         unsigned int plaintext_pad_len;
7381         unsigned int plaintext_len;
7382         unsigned int ciphertext_pad_len;
7383         unsigned int ciphertext_len;
7384         uint8_t buffer[10000];
7385         uint8_t digest_buffer[10000];
7386
7387         struct rte_cryptodev_info dev_info;
7388         struct rte_crypto_op *op;
7389
7390         /* Check if device supports particular algorithms */
7391         if (test_mixed_check_if_unsupported(tdata))
7392                 return TEST_SKIPPED;
7393         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7394                 return TEST_SKIPPED;
7395
7396         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7397
7398         uint64_t feat_flags = dev_info.feature_flags;
7399
7400         if (op_mode == IN_PLACE) {
7401                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7402                         printf("Device doesn't support in-place scatter-gather "
7403                                         "in both input and output mbufs.\n");
7404                         return TEST_SKIPPED;
7405                 }
7406         } else {
7407                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7408                         printf("Device doesn't support out-of-place scatter-gather "
7409                                         "in both input and output mbufs.\n");
7410                         return TEST_SKIPPED;
7411                 }
7412                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7413                         printf("Device doesn't support digest encrypted.\n");
7414                         return TEST_SKIPPED;
7415                 }
7416         }
7417
7418         /* Create the session */
7419         if (verify)
7420                 retval = create_wireless_algo_cipher_auth_session(
7421                                 ts_params->valid_devs[0],
7422                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7423                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7424                                 tdata->auth_algo,
7425                                 tdata->cipher_algo,
7426                                 tdata->auth_key.data, tdata->auth_key.len,
7427                                 tdata->auth_iv.len, tdata->digest_enc.len,
7428                                 tdata->cipher_iv.len);
7429         else
7430                 retval = create_wireless_algo_auth_cipher_session(
7431                                 ts_params->valid_devs[0],
7432                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7433                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7434                                 tdata->auth_algo,
7435                                 tdata->cipher_algo,
7436                                 tdata->auth_key.data, tdata->auth_key.len,
7437                                 tdata->auth_iv.len, tdata->digest_enc.len,
7438                                 tdata->cipher_iv.len);
7439         if (retval != 0)
7440                 return retval;
7441
7442         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7443         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7444         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7445         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7446
7447         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7448                         ciphertext_pad_len, 15, 0);
7449         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7450                         "Failed to allocate input buffer in mempool");
7451
7452         if (op_mode == OUT_OF_PLACE) {
7453                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7454                                 plaintext_pad_len, 15, 0);
7455                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
7456                                 "Failed to allocate output buffer in mempool");
7457         }
7458
7459         if (verify) {
7460                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7461                         tdata->ciphertext.data);
7462                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7463                                         ciphertext_len, buffer);
7464                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7465                         ciphertext_len);
7466         } else {
7467                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7468                         tdata->plaintext.data);
7469                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7470                                         plaintext_len, buffer);
7471                 debug_hexdump(stdout, "plaintext:", plaintext,
7472                         plaintext_len);
7473         }
7474         memset(buffer, 0, sizeof(buffer));
7475
7476         /* Create the operation */
7477         retval = create_wireless_algo_auth_cipher_operation(
7478                         tdata->digest_enc.data, tdata->digest_enc.len,
7479                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7480                         tdata->auth_iv.data, tdata->auth_iv.len,
7481                         (tdata->digest_enc.offset == 0 ?
7482                                 plaintext_pad_len
7483                                 : tdata->digest_enc.offset),
7484                         tdata->validCipherLen.len_bits,
7485                         tdata->cipher.offset_bits,
7486                         tdata->validAuthLen.len_bits,
7487                         tdata->auth.offset_bits,
7488                         op_mode, 1, verify);
7489
7490         if (retval < 0)
7491                 return retval;
7492
7493         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7494
7495         /* Check if the op failed because the device doesn't */
7496         /* support this particular combination of algorithms */
7497         if (op == NULL && ut_params->op->status ==
7498                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7499                 printf("Device doesn't support this mixed combination. "
7500                                 "Test Skipped.\n");
7501                 return TEST_SKIPPED;
7502         }
7503         ut_params->op = op;
7504
7505         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7506
7507         ut_params->obuf = (op_mode == IN_PLACE ?
7508                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7509
7510         if (verify) {
7511                 if (ut_params->obuf)
7512                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7513                                         plaintext_len, buffer);
7514                 else
7515                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7516                                         plaintext_len, buffer);
7517
7518                 debug_hexdump(stdout, "plaintext:", plaintext,
7519                                 (tdata->plaintext.len_bits >> 3) -
7520                                 tdata->digest_enc.len);
7521                 debug_hexdump(stdout, "plaintext expected:",
7522                                 tdata->plaintext.data,
7523                                 (tdata->plaintext.len_bits >> 3) -
7524                                 tdata->digest_enc.len);
7525         } else {
7526                 if (ut_params->obuf)
7527                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7528                                         ciphertext_len, buffer);
7529                 else
7530                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7531                                         ciphertext_len, buffer);
7532
7533                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7534                         ciphertext_len);
7535                 debug_hexdump(stdout, "ciphertext expected:",
7536                         tdata->ciphertext.data,
7537                         tdata->ciphertext.len_bits >> 3);
7538
7539                 if (ut_params->obuf)
7540                         digest = rte_pktmbuf_read(ut_params->obuf,
7541                                         (tdata->digest_enc.offset == 0 ?
7542                                                 plaintext_pad_len :
7543                                                 tdata->digest_enc.offset),
7544                                         tdata->digest_enc.len, digest_buffer);
7545                 else
7546                         digest = rte_pktmbuf_read(ut_params->ibuf,
7547                                         (tdata->digest_enc.offset == 0 ?
7548                                                 plaintext_pad_len :
7549                                                 tdata->digest_enc.offset),
7550                                         tdata->digest_enc.len, digest_buffer);
7551
7552                 debug_hexdump(stdout, "digest:", digest,
7553                                 tdata->digest_enc.len);
7554                 debug_hexdump(stdout, "digest expected:",
7555                                 tdata->digest_enc.data, tdata->digest_enc.len);
7556         }
7557
7558         /* Validate obuf */
7559         if (verify) {
7560                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7561                                 plaintext,
7562                                 tdata->plaintext.data,
7563                                 tdata->plaintext.len_bits >> 3,
7564                                 "Plaintext data not as expected");
7565         } else {
7566                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7567                                 ciphertext,
7568                                 tdata->ciphertext.data,
7569                                 tdata->validDataLen.len_bits,
7570                                 "Ciphertext data not as expected");
7571                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7572                                 digest,
7573                                 tdata->digest_enc.data,
7574                                 tdata->digest_enc.len,
7575                                 "Generated auth tag not as expected");
7576         }
7577
7578         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7579                         "crypto op processing failed");
7580
7581         return 0;
7582 }
7583
7584 /** AUTH AES CMAC + CIPHER AES CTR */
7585
7586 static int
7587 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7588 {
7589         return test_mixed_auth_cipher(
7590                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7591 }
7592
7593 static int
7594 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7595 {
7596         return test_mixed_auth_cipher(
7597                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7598 }
7599
7600 static int
7601 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7602 {
7603         return test_mixed_auth_cipher_sgl(
7604                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7605 }
7606
7607 static int
7608 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7609 {
7610         return test_mixed_auth_cipher_sgl(
7611                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7612 }
7613
7614 static int
7615 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7616 {
7617         return test_mixed_auth_cipher(
7618                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7619 }
7620
7621 static int
7622 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7623 {
7624         return test_mixed_auth_cipher(
7625                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7626 }
7627
7628 static int
7629 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7630 {
7631         return test_mixed_auth_cipher_sgl(
7632                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7633 }
7634
7635 static int
7636 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7637 {
7638         return test_mixed_auth_cipher_sgl(
7639                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7640 }
7641
7642 /** MIXED AUTH + CIPHER */
7643
7644 static int
7645 test_auth_zuc_cipher_snow_test_case_1(void)
7646 {
7647         return test_mixed_auth_cipher(
7648                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7649 }
7650
7651 static int
7652 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7653 {
7654         return test_mixed_auth_cipher(
7655                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7656 }
7657
7658 static int
7659 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7660 {
7661         return test_mixed_auth_cipher(
7662                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7663 }
7664
7665 static int
7666 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7667 {
7668         return test_mixed_auth_cipher(
7669                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7670 }
7671
7672 static int
7673 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7674 {
7675         return test_mixed_auth_cipher(
7676                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7677 }
7678
7679 static int
7680 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7681 {
7682         return test_mixed_auth_cipher(
7683                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7684 }
7685
7686 static int
7687 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7688 {
7689         return test_mixed_auth_cipher(
7690                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7691 }
7692
7693 static int
7694 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7695 {
7696         return test_mixed_auth_cipher(
7697                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7698 }
7699
7700 static int
7701 test_auth_snow_cipher_zuc_test_case_1(void)
7702 {
7703         return test_mixed_auth_cipher(
7704                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7705 }
7706
7707 static int
7708 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7709 {
7710         return test_mixed_auth_cipher(
7711                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7712 }
7713
7714 static int
7715 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7716 {
7717         return test_mixed_auth_cipher(
7718                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7719 }
7720
7721 static int
7722 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7723 {
7724         return test_mixed_auth_cipher(
7725                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7726 }
7727
7728 static int
7729 test_auth_null_cipher_snow_test_case_1(void)
7730 {
7731         return test_mixed_auth_cipher(
7732                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7733 }
7734
7735 static int
7736 test_verify_auth_null_cipher_snow_test_case_1(void)
7737 {
7738         return test_mixed_auth_cipher(
7739                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7740 }
7741
7742 static int
7743 test_auth_null_cipher_zuc_test_case_1(void)
7744 {
7745         return test_mixed_auth_cipher(
7746                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7747 }
7748
7749 static int
7750 test_verify_auth_null_cipher_zuc_test_case_1(void)
7751 {
7752         return test_mixed_auth_cipher(
7753                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7754 }
7755
7756 static int
7757 test_auth_snow_cipher_null_test_case_1(void)
7758 {
7759         return test_mixed_auth_cipher(
7760                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7761 }
7762
7763 static int
7764 test_verify_auth_snow_cipher_null_test_case_1(void)
7765 {
7766         return test_mixed_auth_cipher(
7767                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7768 }
7769
7770 static int
7771 test_auth_zuc_cipher_null_test_case_1(void)
7772 {
7773         return test_mixed_auth_cipher(
7774                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7775 }
7776
7777 static int
7778 test_verify_auth_zuc_cipher_null_test_case_1(void)
7779 {
7780         return test_mixed_auth_cipher(
7781                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7782 }
7783
7784 static int
7785 test_auth_null_cipher_aes_ctr_test_case_1(void)
7786 {
7787         return test_mixed_auth_cipher(
7788                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7789 }
7790
7791 static int
7792 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7793 {
7794         return test_mixed_auth_cipher(
7795                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7796 }
7797
7798 static int
7799 test_auth_aes_cmac_cipher_null_test_case_1(void)
7800 {
7801         return test_mixed_auth_cipher(
7802                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7803 }
7804
7805 static int
7806 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7807 {
7808         return test_mixed_auth_cipher(
7809                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7810 }
7811
7812 /* ***** AEAD algorithm Tests ***** */
7813
7814 static int
7815 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7816                 enum rte_crypto_aead_operation op,
7817                 const uint8_t *key, const uint8_t key_len,
7818                 const uint16_t aad_len, const uint8_t auth_len,
7819                 uint8_t iv_len)
7820 {
7821         uint8_t aead_key[key_len];
7822
7823         struct crypto_testsuite_params *ts_params = &testsuite_params;
7824         struct crypto_unittest_params *ut_params = &unittest_params;
7825
7826         memcpy(aead_key, key, key_len);
7827
7828         /* Setup AEAD Parameters */
7829         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7830         ut_params->aead_xform.next = NULL;
7831         ut_params->aead_xform.aead.algo = algo;
7832         ut_params->aead_xform.aead.op = op;
7833         ut_params->aead_xform.aead.key.data = aead_key;
7834         ut_params->aead_xform.aead.key.length = key_len;
7835         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7836         ut_params->aead_xform.aead.iv.length = iv_len;
7837         ut_params->aead_xform.aead.digest_length = auth_len;
7838         ut_params->aead_xform.aead.aad_length = aad_len;
7839
7840         debug_hexdump(stdout, "key:", key, key_len);
7841
7842         /* Create Crypto session*/
7843         ut_params->sess = rte_cryptodev_sym_session_create(
7844                         ts_params->session_mpool);
7845
7846         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7847                         &ut_params->aead_xform,
7848                         ts_params->session_priv_mpool);
7849
7850         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7851
7852         return 0;
7853 }
7854
7855 static int
7856 create_aead_xform(struct rte_crypto_op *op,
7857                 enum rte_crypto_aead_algorithm algo,
7858                 enum rte_crypto_aead_operation aead_op,
7859                 uint8_t *key, const uint8_t key_len,
7860                 const uint8_t aad_len, const uint8_t auth_len,
7861                 uint8_t iv_len)
7862 {
7863         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7864                         "failed to allocate space for crypto transform");
7865
7866         struct rte_crypto_sym_op *sym_op = op->sym;
7867
7868         /* Setup AEAD Parameters */
7869         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7870         sym_op->xform->next = NULL;
7871         sym_op->xform->aead.algo = algo;
7872         sym_op->xform->aead.op = aead_op;
7873         sym_op->xform->aead.key.data = key;
7874         sym_op->xform->aead.key.length = key_len;
7875         sym_op->xform->aead.iv.offset = IV_OFFSET;
7876         sym_op->xform->aead.iv.length = iv_len;
7877         sym_op->xform->aead.digest_length = auth_len;
7878         sym_op->xform->aead.aad_length = aad_len;
7879
7880         debug_hexdump(stdout, "key:", key, key_len);
7881
7882         return 0;
7883 }
7884
7885 static int
7886 create_aead_operation(enum rte_crypto_aead_operation op,
7887                 const struct aead_test_data *tdata)
7888 {
7889         struct crypto_testsuite_params *ts_params = &testsuite_params;
7890         struct crypto_unittest_params *ut_params = &unittest_params;
7891
7892         uint8_t *plaintext, *ciphertext;
7893         unsigned int aad_pad_len, plaintext_pad_len;
7894
7895         /* Generate Crypto op data structure */
7896         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7897                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7898         TEST_ASSERT_NOT_NULL(ut_params->op,
7899                         "Failed to allocate symmetric crypto operation struct");
7900
7901         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7902
7903         /* Append aad data */
7904         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7905                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7906                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7907                                 aad_pad_len);
7908                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7909                                 "no room to append aad");
7910
7911                 sym_op->aead.aad.phys_addr =
7912                                 rte_pktmbuf_iova(ut_params->ibuf);
7913                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
7914                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7915                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7916                         tdata->aad.len);
7917
7918                 /* Append IV at the end of the crypto operation*/
7919                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7920                                 uint8_t *, IV_OFFSET);
7921
7922                 /* Copy IV 1 byte after the IV pointer, according to the API */
7923                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7924                 debug_hexdump(stdout, "iv:", iv_ptr,
7925                         tdata->iv.len);
7926         } else {
7927                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7928                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7929                                 aad_pad_len);
7930                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7931                                 "no room to append aad");
7932
7933                 sym_op->aead.aad.phys_addr =
7934                                 rte_pktmbuf_iova(ut_params->ibuf);
7935                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7936                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7937                         tdata->aad.len);
7938
7939                 /* Append IV at the end of the crypto operation*/
7940                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7941                                 uint8_t *, IV_OFFSET);
7942
7943                 if (tdata->iv.len == 0) {
7944                         rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7945                         debug_hexdump(stdout, "iv:", iv_ptr,
7946                                 AES_GCM_J0_LENGTH);
7947                 } else {
7948                         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7949                         debug_hexdump(stdout, "iv:", iv_ptr,
7950                                 tdata->iv.len);
7951                 }
7952         }
7953
7954         /* Append plaintext/ciphertext */
7955         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7956                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7957                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7958                                 plaintext_pad_len);
7959                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7960
7961                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7962                 debug_hexdump(stdout, "plaintext:", plaintext,
7963                                 tdata->plaintext.len);
7964
7965                 if (ut_params->obuf) {
7966                         ciphertext = (uint8_t *)rte_pktmbuf_append(
7967                                         ut_params->obuf,
7968                                         plaintext_pad_len + aad_pad_len);
7969                         TEST_ASSERT_NOT_NULL(ciphertext,
7970                                         "no room to append ciphertext");
7971
7972                         memset(ciphertext + aad_pad_len, 0,
7973                                         tdata->ciphertext.len);
7974                 }
7975         } else {
7976                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7977                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7978                                 plaintext_pad_len);
7979                 TEST_ASSERT_NOT_NULL(ciphertext,
7980                                 "no room to append ciphertext");
7981
7982                 memcpy(ciphertext, tdata->ciphertext.data,
7983                                 tdata->ciphertext.len);
7984                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7985                                 tdata->ciphertext.len);
7986
7987                 if (ut_params->obuf) {
7988                         plaintext = (uint8_t *)rte_pktmbuf_append(
7989                                         ut_params->obuf,
7990                                         plaintext_pad_len + aad_pad_len);
7991                         TEST_ASSERT_NOT_NULL(plaintext,
7992                                         "no room to append plaintext");
7993
7994                         memset(plaintext + aad_pad_len, 0,
7995                                         tdata->plaintext.len);
7996                 }
7997         }
7998
7999         /* Append digest data */
8000         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8001                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8002                                 ut_params->obuf ? ut_params->obuf :
8003                                                 ut_params->ibuf,
8004                                                 tdata->auth_tag.len);
8005                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8006                                 "no room to append digest");
8007                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
8008                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8009                                 ut_params->obuf ? ut_params->obuf :
8010                                                 ut_params->ibuf,
8011                                                 plaintext_pad_len +
8012                                                 aad_pad_len);
8013         } else {
8014                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8015                                 ut_params->ibuf, tdata->auth_tag.len);
8016                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8017                                 "no room to append digest");
8018                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8019                                 ut_params->ibuf,
8020                                 plaintext_pad_len + aad_pad_len);
8021
8022                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8023                         tdata->auth_tag.len);
8024                 debug_hexdump(stdout, "digest:",
8025                         sym_op->aead.digest.data,
8026                         tdata->auth_tag.len);
8027         }
8028
8029         sym_op->aead.data.length = tdata->plaintext.len;
8030         sym_op->aead.data.offset = aad_pad_len;
8031
8032         return 0;
8033 }
8034
8035 static int
8036 test_authenticated_encryption(const struct aead_test_data *tdata)
8037 {
8038         struct crypto_testsuite_params *ts_params = &testsuite_params;
8039         struct crypto_unittest_params *ut_params = &unittest_params;
8040
8041         int retval;
8042         uint8_t *ciphertext, *auth_tag;
8043         uint16_t plaintext_pad_len;
8044         uint32_t i;
8045         struct rte_cryptodev_info dev_info;
8046
8047         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8048         uint64_t feat_flags = dev_info.feature_flags;
8049
8050         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8051                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8052                 printf("Device doesn't support RAW data-path APIs.\n");
8053                 return TEST_SKIPPED;
8054         }
8055
8056         /* Verify the capabilities */
8057         struct rte_cryptodev_sym_capability_idx cap_idx;
8058         const struct rte_cryptodev_symmetric_capability *capability;
8059         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8060         cap_idx.algo.aead = tdata->algo;
8061         capability = rte_cryptodev_sym_capability_get(
8062                         ts_params->valid_devs[0], &cap_idx);
8063         if (capability == NULL)
8064                 return TEST_SKIPPED;
8065         if (rte_cryptodev_sym_capability_check_aead(
8066                         capability, tdata->key.len, tdata->auth_tag.len,
8067                         tdata->aad.len, tdata->iv.len))
8068                 return TEST_SKIPPED;
8069
8070         /* Create AEAD session */
8071         retval = create_aead_session(ts_params->valid_devs[0],
8072                         tdata->algo,
8073                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8074                         tdata->key.data, tdata->key.len,
8075                         tdata->aad.len, tdata->auth_tag.len,
8076                         tdata->iv.len);
8077         if (retval < 0)
8078                 return retval;
8079
8080         if (tdata->aad.len > MBUF_SIZE) {
8081                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8082                 /* Populate full size of add data */
8083                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8084                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8085         } else
8086                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8087
8088         /* clear mbuf payload */
8089         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8090                         rte_pktmbuf_tailroom(ut_params->ibuf));
8091
8092         /* Create AEAD operation */
8093         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8094         if (retval < 0)
8095                 return retval;
8096
8097         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8098
8099         ut_params->op->sym->m_src = ut_params->ibuf;
8100
8101         /* Process crypto operation */
8102         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8103                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8104         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8105                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8106                                 ut_params->op, 0, 0, 0, 0);
8107         else
8108                 TEST_ASSERT_NOT_NULL(
8109                         process_crypto_request(ts_params->valid_devs[0],
8110                         ut_params->op), "failed to process sym crypto op");
8111
8112         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8113                         "crypto op processing failed");
8114
8115         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8116
8117         if (ut_params->op->sym->m_dst) {
8118                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8119                                 uint8_t *);
8120                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8121                                 uint8_t *, plaintext_pad_len);
8122         } else {
8123                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8124                                 uint8_t *,
8125                                 ut_params->op->sym->cipher.data.offset);
8126                 auth_tag = ciphertext + plaintext_pad_len;
8127         }
8128
8129         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8130         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8131
8132         /* Validate obuf */
8133         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8134                         ciphertext,
8135                         tdata->ciphertext.data,
8136                         tdata->ciphertext.len,
8137                         "Ciphertext data not as expected");
8138
8139         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8140                         auth_tag,
8141                         tdata->auth_tag.data,
8142                         tdata->auth_tag.len,
8143                         "Generated auth tag not as expected");
8144
8145         return 0;
8146
8147 }
8148
8149 #ifdef RTE_LIB_SECURITY
8150 static int
8151 security_proto_supported(enum rte_security_session_action_type action,
8152         enum rte_security_session_protocol proto)
8153 {
8154         struct crypto_testsuite_params *ts_params = &testsuite_params;
8155
8156         const struct rte_security_capability *capabilities;
8157         const struct rte_security_capability *capability;
8158         uint16_t i = 0;
8159
8160         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8161                                 rte_cryptodev_get_sec_ctx(
8162                                 ts_params->valid_devs[0]);
8163
8164
8165         capabilities = rte_security_capabilities_get(ctx);
8166
8167         if (capabilities == NULL)
8168                 return -ENOTSUP;
8169
8170         while ((capability = &capabilities[i++])->action !=
8171                         RTE_SECURITY_ACTION_TYPE_NONE) {
8172                 if (capability->action == action &&
8173                                 capability->protocol == proto)
8174                         return 0;
8175         }
8176
8177         return -ENOTSUP;
8178 }
8179
8180 /* Basic algorithm run function for async inplace mode.
8181  * Creates a session from input parameters and runs one operation
8182  * on input_vec. Checks the output of the crypto operation against
8183  * output_vec.
8184  */
8185 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8186                            enum rte_crypto_auth_operation opa,
8187                            const uint8_t *input_vec, unsigned int input_vec_len,
8188                            const uint8_t *output_vec,
8189                            unsigned int output_vec_len,
8190                            enum rte_crypto_cipher_algorithm cipher_alg,
8191                            const uint8_t *cipher_key, uint32_t cipher_key_len,
8192                            enum rte_crypto_auth_algorithm auth_alg,
8193                            const uint8_t *auth_key, uint32_t auth_key_len,
8194                            uint8_t bearer, enum rte_security_pdcp_domain domain,
8195                            uint8_t packet_direction, uint8_t sn_size,
8196                            uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8197 {
8198         struct crypto_testsuite_params *ts_params = &testsuite_params;
8199         struct crypto_unittest_params *ut_params = &unittest_params;
8200         uint8_t *plaintext;
8201         int ret = TEST_SUCCESS;
8202         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8203                                 rte_cryptodev_get_sec_ctx(
8204                                 ts_params->valid_devs[0]);
8205
8206         /* Verify the capabilities */
8207         struct rte_security_capability_idx sec_cap_idx;
8208
8209         sec_cap_idx.action = ut_params->type;
8210         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8211         sec_cap_idx.pdcp.domain = domain;
8212         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8213                 return TEST_SKIPPED;
8214
8215         /* Generate test mbuf data */
8216         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8217
8218         /* clear mbuf payload */
8219         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8220                         rte_pktmbuf_tailroom(ut_params->ibuf));
8221
8222         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8223                                                   input_vec_len);
8224         memcpy(plaintext, input_vec, input_vec_len);
8225
8226         /* Out of place support */
8227         if (oop) {
8228                 /*
8229                  * For out-op-place we need to alloc another mbuf
8230                  */
8231                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8232                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8233         }
8234
8235         /* Setup Cipher Parameters */
8236         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8237         ut_params->cipher_xform.cipher.algo = cipher_alg;
8238         ut_params->cipher_xform.cipher.op = opc;
8239         ut_params->cipher_xform.cipher.key.data = cipher_key;
8240         ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8241         ut_params->cipher_xform.cipher.iv.length =
8242                                 packet_direction ? 4 : 0;
8243         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8244
8245         /* Setup HMAC Parameters if ICV header is required */
8246         if (auth_alg != 0) {
8247                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8248                 ut_params->auth_xform.next = NULL;
8249                 ut_params->auth_xform.auth.algo = auth_alg;
8250                 ut_params->auth_xform.auth.op = opa;
8251                 ut_params->auth_xform.auth.key.data = auth_key;
8252                 ut_params->auth_xform.auth.key.length = auth_key_len;
8253
8254                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8255         } else {
8256                 ut_params->cipher_xform.next = NULL;
8257         }
8258
8259         struct rte_security_session_conf sess_conf = {
8260                 .action_type = ut_params->type,
8261                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8262                 {.pdcp = {
8263                         .bearer = bearer,
8264                         .domain = domain,
8265                         .pkt_dir = packet_direction,
8266                         .sn_size = sn_size,
8267                         .hfn = packet_direction ? 0 : hfn,
8268                         /**
8269                          * hfn can be set as pdcp_test_hfn[i]
8270                          * if hfn_ovrd is not set. Here, PDCP
8271                          * packet direction is just used to
8272                          * run half of the cases with session
8273                          * HFN and other half with per packet
8274                          * HFN.
8275                          */
8276                         .hfn_threshold = hfn_threshold,
8277                         .hfn_ovrd = packet_direction ? 1 : 0,
8278                         .sdap_enabled = sdap,
8279                 } },
8280                 .crypto_xform = &ut_params->cipher_xform
8281         };
8282
8283         /* Create security session */
8284         ut_params->sec_session = rte_security_session_create(ctx,
8285                                 &sess_conf, ts_params->session_mpool,
8286                                 ts_params->session_priv_mpool);
8287
8288         if (!ut_params->sec_session) {
8289                 printf("TestCase %s()-%d line %d failed %s: ",
8290                         __func__, i, __LINE__, "Failed to allocate session");
8291                 ret = TEST_FAILED;
8292                 goto on_err;
8293         }
8294
8295         /* Generate crypto op data structure */
8296         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8297                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8298         if (!ut_params->op) {
8299                 printf("TestCase %s()-%d line %d failed %s: ",
8300                         __func__, i, __LINE__,
8301                         "Failed to allocate symmetric crypto operation struct");
8302                 ret = TEST_FAILED;
8303                 goto on_err;
8304         }
8305
8306         uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8307                                         uint32_t *, IV_OFFSET);
8308         *per_pkt_hfn = packet_direction ? hfn : 0;
8309
8310         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8311
8312         /* set crypto operation source mbuf */
8313         ut_params->op->sym->m_src = ut_params->ibuf;
8314         if (oop)
8315                 ut_params->op->sym->m_dst = ut_params->obuf;
8316
8317         /* Process crypto operation */
8318         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8319                 == NULL) {
8320                 printf("TestCase %s()-%d line %d failed %s: ",
8321                         __func__, i, __LINE__,
8322                         "failed to process sym crypto op");
8323                 ret = TEST_FAILED;
8324                 goto on_err;
8325         }
8326
8327         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8328                 printf("TestCase %s()-%d line %d failed %s: ",
8329                         __func__, i, __LINE__, "crypto op processing failed");
8330                 ret = TEST_FAILED;
8331                 goto on_err;
8332         }
8333
8334         /* Validate obuf */
8335         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8336                         uint8_t *);
8337         if (oop) {
8338                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8339                                 uint8_t *);
8340         }
8341
8342         if (memcmp(ciphertext, output_vec, output_vec_len)) {
8343                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8344                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8345                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8346                 ret = TEST_FAILED;
8347                 goto on_err;
8348         }
8349
8350 on_err:
8351         rte_crypto_op_free(ut_params->op);
8352         ut_params->op = NULL;
8353
8354         if (ut_params->sec_session)
8355                 rte_security_session_destroy(ctx, ut_params->sec_session);
8356         ut_params->sec_session = NULL;
8357
8358         rte_pktmbuf_free(ut_params->ibuf);
8359         ut_params->ibuf = NULL;
8360         if (oop) {
8361                 rte_pktmbuf_free(ut_params->obuf);
8362                 ut_params->obuf = NULL;
8363         }
8364
8365         return ret;
8366 }
8367
8368 static int
8369 test_pdcp_proto_SGL(int i, int oop,
8370         enum rte_crypto_cipher_operation opc,
8371         enum rte_crypto_auth_operation opa,
8372         uint8_t *input_vec,
8373         unsigned int input_vec_len,
8374         uint8_t *output_vec,
8375         unsigned int output_vec_len,
8376         uint32_t fragsz,
8377         uint32_t fragsz_oop)
8378 {
8379         struct crypto_testsuite_params *ts_params = &testsuite_params;
8380         struct crypto_unittest_params *ut_params = &unittest_params;
8381         uint8_t *plaintext;
8382         struct rte_mbuf *buf, *buf_oop = NULL;
8383         int ret = TEST_SUCCESS;
8384         int to_trn = 0;
8385         int to_trn_tbl[16];
8386         int segs = 1;
8387         unsigned int trn_data = 0;
8388         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8389                                 rte_cryptodev_get_sec_ctx(
8390                                 ts_params->valid_devs[0]);
8391
8392         /* Verify the capabilities */
8393         struct rte_security_capability_idx sec_cap_idx;
8394
8395         sec_cap_idx.action = ut_params->type;
8396         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8397         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8398         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8399                 return TEST_SKIPPED;
8400
8401         if (fragsz > input_vec_len)
8402                 fragsz = input_vec_len;
8403
8404         uint16_t plaintext_len = fragsz;
8405         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8406
8407         if (fragsz_oop > output_vec_len)
8408                 frag_size_oop = output_vec_len;
8409
8410         int ecx = 0;
8411         if (input_vec_len % fragsz != 0) {
8412                 if (input_vec_len / fragsz + 1 > 16)
8413                         return 1;
8414         } else if (input_vec_len / fragsz > 16)
8415                 return 1;
8416
8417         /* Out of place support */
8418         if (oop) {
8419                 /*
8420                  * For out-op-place we need to alloc another mbuf
8421                  */
8422                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8423                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8424                 buf_oop = ut_params->obuf;
8425         }
8426
8427         /* Generate test mbuf data */
8428         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8429
8430         /* clear mbuf payload */
8431         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8432                         rte_pktmbuf_tailroom(ut_params->ibuf));
8433
8434         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8435                                                   plaintext_len);
8436         memcpy(plaintext, input_vec, plaintext_len);
8437         trn_data += plaintext_len;
8438
8439         buf = ut_params->ibuf;
8440
8441         /*
8442          * Loop until no more fragments
8443          */
8444
8445         while (trn_data < input_vec_len) {
8446                 ++segs;
8447                 to_trn = (input_vec_len - trn_data < fragsz) ?
8448                                 (input_vec_len - trn_data) : fragsz;
8449
8450                 to_trn_tbl[ecx++] = to_trn;
8451
8452                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8453                 buf = buf->next;
8454
8455                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8456                                 rte_pktmbuf_tailroom(buf));
8457
8458                 /* OOP */
8459                 if (oop && !fragsz_oop) {
8460                         buf_oop->next =
8461                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8462                         buf_oop = buf_oop->next;
8463                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8464                                         0, rte_pktmbuf_tailroom(buf_oop));
8465                         rte_pktmbuf_append(buf_oop, to_trn);
8466                 }
8467
8468                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8469                                 to_trn);
8470
8471                 memcpy(plaintext, input_vec + trn_data, to_trn);
8472                 trn_data += to_trn;
8473         }
8474
8475         ut_params->ibuf->nb_segs = segs;
8476
8477         segs = 1;
8478         if (fragsz_oop && oop) {
8479                 to_trn = 0;
8480                 ecx = 0;
8481
8482                 trn_data = frag_size_oop;
8483                 while (trn_data < output_vec_len) {
8484                         ++segs;
8485                         to_trn =
8486                                 (output_vec_len - trn_data <
8487                                                 frag_size_oop) ?
8488                                 (output_vec_len - trn_data) :
8489                                                 frag_size_oop;
8490
8491                         to_trn_tbl[ecx++] = to_trn;
8492
8493                         buf_oop->next =
8494                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
8495                         buf_oop = buf_oop->next;
8496                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8497                                         0, rte_pktmbuf_tailroom(buf_oop));
8498                         rte_pktmbuf_append(buf_oop, to_trn);
8499
8500                         trn_data += to_trn;
8501                 }
8502                 ut_params->obuf->nb_segs = segs;
8503         }
8504
8505         /* Setup Cipher Parameters */
8506         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8507         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8508         ut_params->cipher_xform.cipher.op = opc;
8509         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8510         ut_params->cipher_xform.cipher.key.length =
8511                                         pdcp_test_params[i].cipher_key_len;
8512         ut_params->cipher_xform.cipher.iv.length = 0;
8513
8514         /* Setup HMAC Parameters if ICV header is required */
8515         if (pdcp_test_params[i].auth_alg != 0) {
8516                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8517                 ut_params->auth_xform.next = NULL;
8518                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8519                 ut_params->auth_xform.auth.op = opa;
8520                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8521                 ut_params->auth_xform.auth.key.length =
8522                                         pdcp_test_params[i].auth_key_len;
8523
8524                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8525         } else {
8526                 ut_params->cipher_xform.next = NULL;
8527         }
8528
8529         struct rte_security_session_conf sess_conf = {
8530                 .action_type = ut_params->type,
8531                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8532                 {.pdcp = {
8533                         .bearer = pdcp_test_bearer[i],
8534                         .domain = pdcp_test_params[i].domain,
8535                         .pkt_dir = pdcp_test_packet_direction[i],
8536                         .sn_size = pdcp_test_data_sn_size[i],
8537                         .hfn = pdcp_test_hfn[i],
8538                         .hfn_threshold = pdcp_test_hfn_threshold[i],
8539                         .hfn_ovrd = 0,
8540                 } },
8541                 .crypto_xform = &ut_params->cipher_xform
8542         };
8543
8544         /* Create security session */
8545         ut_params->sec_session = rte_security_session_create(ctx,
8546                                 &sess_conf, ts_params->session_mpool,
8547                                 ts_params->session_priv_mpool);
8548
8549         if (!ut_params->sec_session) {
8550                 printf("TestCase %s()-%d line %d failed %s: ",
8551                         __func__, i, __LINE__, "Failed to allocate session");
8552                 ret = TEST_FAILED;
8553                 goto on_err;
8554         }
8555
8556         /* Generate crypto op data structure */
8557         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8558                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8559         if (!ut_params->op) {
8560                 printf("TestCase %s()-%d line %d failed %s: ",
8561                         __func__, i, __LINE__,
8562                         "Failed to allocate symmetric crypto operation struct");
8563                 ret = TEST_FAILED;
8564                 goto on_err;
8565         }
8566
8567         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8568
8569         /* set crypto operation source mbuf */
8570         ut_params->op->sym->m_src = ut_params->ibuf;
8571         if (oop)
8572                 ut_params->op->sym->m_dst = ut_params->obuf;
8573
8574         /* Process crypto operation */
8575         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8576                 == NULL) {
8577                 printf("TestCase %s()-%d line %d failed %s: ",
8578                         __func__, i, __LINE__,
8579                         "failed to process sym crypto op");
8580                 ret = TEST_FAILED;
8581                 goto on_err;
8582         }
8583
8584         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8585                 printf("TestCase %s()-%d line %d failed %s: ",
8586                         __func__, i, __LINE__, "crypto op processing failed");
8587                 ret = TEST_FAILED;
8588                 goto on_err;
8589         }
8590
8591         /* Validate obuf */
8592         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8593                         uint8_t *);
8594         if (oop) {
8595                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8596                                 uint8_t *);
8597         }
8598         if (fragsz_oop)
8599                 fragsz = frag_size_oop;
8600         if (memcmp(ciphertext, output_vec, fragsz)) {
8601                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8602                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8603                 rte_hexdump(stdout, "reference", output_vec, fragsz);
8604                 ret = TEST_FAILED;
8605                 goto on_err;
8606         }
8607
8608         buf = ut_params->op->sym->m_src->next;
8609         if (oop)
8610                 buf = ut_params->op->sym->m_dst->next;
8611
8612         unsigned int off = fragsz;
8613
8614         ecx = 0;
8615         while (buf) {
8616                 ciphertext = rte_pktmbuf_mtod(buf,
8617                                 uint8_t *);
8618                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8619                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8620                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8621                         rte_hexdump(stdout, "reference", output_vec + off,
8622                                         to_trn_tbl[ecx]);
8623                         ret = TEST_FAILED;
8624                         goto on_err;
8625                 }
8626                 off += to_trn_tbl[ecx++];
8627                 buf = buf->next;
8628         }
8629 on_err:
8630         rte_crypto_op_free(ut_params->op);
8631         ut_params->op = NULL;
8632
8633         if (ut_params->sec_session)
8634                 rte_security_session_destroy(ctx, ut_params->sec_session);
8635         ut_params->sec_session = NULL;
8636
8637         rte_pktmbuf_free(ut_params->ibuf);
8638         ut_params->ibuf = NULL;
8639         if (oop) {
8640                 rte_pktmbuf_free(ut_params->obuf);
8641                 ut_params->obuf = NULL;
8642         }
8643
8644         return ret;
8645 }
8646
8647 int
8648 test_pdcp_proto_cplane_encap(int i)
8649 {
8650         return test_pdcp_proto(
8651                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8652                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8653                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
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 int
8664 test_pdcp_proto_uplane_encap(int i)
8665 {
8666         return test_pdcp_proto(
8667                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8668                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8669                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8670                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8671                 pdcp_test_params[i].cipher_key_len,
8672                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8673                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8674                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8675                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8676                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8677 }
8678
8679 int
8680 test_pdcp_proto_uplane_encap_with_int(int i)
8681 {
8682         return test_pdcp_proto(
8683                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8684                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8685                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8686                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8687                 pdcp_test_params[i].cipher_key_len,
8688                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8689                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8690                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8691                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8692                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8693 }
8694
8695 int
8696 test_pdcp_proto_cplane_decap(int i)
8697 {
8698         return test_pdcp_proto(
8699                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8700                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8701                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8702                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8703                 pdcp_test_params[i].cipher_key_len,
8704                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8705                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8706                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8707                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8708                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8709 }
8710
8711 int
8712 test_pdcp_proto_uplane_decap(int i)
8713 {
8714         return test_pdcp_proto(
8715                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8716                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8717                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8718                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8719                 pdcp_test_params[i].cipher_key_len,
8720                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8721                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8722                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8723                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8724                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8725 }
8726
8727 int
8728 test_pdcp_proto_uplane_decap_with_int(int i)
8729 {
8730         return test_pdcp_proto(
8731                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8732                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8733                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8734                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8735                 pdcp_test_params[i].cipher_key_len,
8736                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8737                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8738                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8739                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8740                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8741 }
8742
8743 static int
8744 test_PDCP_PROTO_SGL_in_place_32B(void)
8745 {
8746         /* i can be used for running any PDCP case
8747          * In this case it is uplane 12-bit AES-SNOW DL encap
8748          */
8749         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8750         return test_pdcp_proto_SGL(i, IN_PLACE,
8751                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8752                         RTE_CRYPTO_AUTH_OP_GENERATE,
8753                         pdcp_test_data_in[i],
8754                         pdcp_test_data_in_len[i],
8755                         pdcp_test_data_out[i],
8756                         pdcp_test_data_in_len[i]+4,
8757                         32, 0);
8758 }
8759 static int
8760 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8761 {
8762         /* i can be used for running any PDCP case
8763          * In this case it is uplane 18-bit NULL-NULL DL encap
8764          */
8765         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8766         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8767                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8768                         RTE_CRYPTO_AUTH_OP_GENERATE,
8769                         pdcp_test_data_in[i],
8770                         pdcp_test_data_in_len[i],
8771                         pdcp_test_data_out[i],
8772                         pdcp_test_data_in_len[i]+4,
8773                         32, 128);
8774 }
8775 static int
8776 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8777 {
8778         /* i can be used for running any PDCP case
8779          * In this case it is uplane 18-bit AES DL encap
8780          */
8781         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8782                         + DOWNLINK;
8783         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8784                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8785                         RTE_CRYPTO_AUTH_OP_GENERATE,
8786                         pdcp_test_data_in[i],
8787                         pdcp_test_data_in_len[i],
8788                         pdcp_test_data_out[i],
8789                         pdcp_test_data_in_len[i],
8790                         32, 40);
8791 }
8792 static int
8793 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8794 {
8795         /* i can be used for running any PDCP case
8796          * In this case it is cplane 12-bit AES-ZUC DL encap
8797          */
8798         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8799         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8800                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8801                         RTE_CRYPTO_AUTH_OP_GENERATE,
8802                         pdcp_test_data_in[i],
8803                         pdcp_test_data_in_len[i],
8804                         pdcp_test_data_out[i],
8805                         pdcp_test_data_in_len[i]+4,
8806                         128, 32);
8807 }
8808
8809 static int
8810 test_PDCP_SDAP_PROTO_encap_all(void)
8811 {
8812         int i = 0, size = 0;
8813         int err, all_err = TEST_SUCCESS;
8814         const struct pdcp_sdap_test *cur_test;
8815
8816         size = ARRAY_SIZE(list_pdcp_sdap_tests);
8817
8818         for (i = 0; i < size; i++) {
8819                 cur_test = &list_pdcp_sdap_tests[i];
8820                 err = test_pdcp_proto(
8821                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8822                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8823                         cur_test->in_len, cur_test->data_out,
8824                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8825                         cur_test->param.cipher_alg, cur_test->cipher_key,
8826                         cur_test->param.cipher_key_len,
8827                         cur_test->param.auth_alg,
8828                         cur_test->auth_key, cur_test->param.auth_key_len,
8829                         cur_test->bearer, cur_test->param.domain,
8830                         cur_test->packet_direction, cur_test->sn_size,
8831                         cur_test->hfn,
8832                         cur_test->hfn_threshold, SDAP_ENABLED);
8833                 if (err) {
8834                         printf("\t%d) %s: Encapsulation failed\n",
8835                                         cur_test->test_idx,
8836                                         cur_test->param.name);
8837                         err = TEST_FAILED;
8838                 } else {
8839                         printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8840                                         cur_test->param.name);
8841                         err = TEST_SUCCESS;
8842                 }
8843                 all_err += err;
8844         }
8845
8846         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8847
8848         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8849 }
8850
8851 static int
8852 test_PDCP_SDAP_PROTO_decap_all(void)
8853 {
8854         int i = 0, size = 0;
8855         int err, all_err = TEST_SUCCESS;
8856         const struct pdcp_sdap_test *cur_test;
8857
8858         size = ARRAY_SIZE(list_pdcp_sdap_tests);
8859
8860         for (i = 0; i < size; i++) {
8861                 cur_test = &list_pdcp_sdap_tests[i];
8862                 err = test_pdcp_proto(
8863                         i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8864                         RTE_CRYPTO_AUTH_OP_VERIFY,
8865                         cur_test->data_out,
8866                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8867                         cur_test->data_in, cur_test->in_len,
8868                         cur_test->param.cipher_alg,
8869                         cur_test->cipher_key, cur_test->param.cipher_key_len,
8870                         cur_test->param.auth_alg, cur_test->auth_key,
8871                         cur_test->param.auth_key_len, cur_test->bearer,
8872                         cur_test->param.domain, cur_test->packet_direction,
8873                         cur_test->sn_size, cur_test->hfn,
8874                         cur_test->hfn_threshold, SDAP_ENABLED);
8875                 if (err) {
8876                         printf("\t%d) %s: Decapsulation failed\n",
8877                                         cur_test->test_idx,
8878                                         cur_test->param.name);
8879                         err = TEST_FAILED;
8880                 } else {
8881                         printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8882                                         cur_test->param.name);
8883                         err = TEST_SUCCESS;
8884                 }
8885                 all_err += err;
8886         }
8887
8888         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8889
8890         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8891 }
8892
8893 static int
8894 test_PDCP_PROTO_all(void)
8895 {
8896         struct crypto_testsuite_params *ts_params = &testsuite_params;
8897         struct crypto_unittest_params *ut_params = &unittest_params;
8898         struct rte_cryptodev_info dev_info;
8899         int status;
8900
8901         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8902         uint64_t feat_flags = dev_info.feature_flags;
8903
8904         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8905                 return TEST_SKIPPED;
8906
8907         /* Set action type */
8908         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8909                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8910                 gbl_action_type;
8911
8912         if (security_proto_supported(ut_params->type,
8913                         RTE_SECURITY_PROTOCOL_PDCP) < 0)
8914                 return TEST_SKIPPED;
8915
8916         status = test_PDCP_PROTO_cplane_encap_all();
8917         status += test_PDCP_PROTO_cplane_decap_all();
8918         status += test_PDCP_PROTO_uplane_encap_all();
8919         status += test_PDCP_PROTO_uplane_decap_all();
8920         status += test_PDCP_PROTO_SGL_in_place_32B();
8921         status += test_PDCP_PROTO_SGL_oop_32B_128B();
8922         status += test_PDCP_PROTO_SGL_oop_32B_40B();
8923         status += test_PDCP_PROTO_SGL_oop_128B_32B();
8924         status += test_PDCP_SDAP_PROTO_encap_all();
8925         status += test_PDCP_SDAP_PROTO_decap_all();
8926
8927         if (status)
8928                 return TEST_FAILED;
8929         else
8930                 return TEST_SUCCESS;
8931 }
8932
8933 static int
8934 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
8935 {
8936         struct crypto_testsuite_params *ts_params = &testsuite_params;
8937         struct crypto_unittest_params *ut_params = &unittest_params;
8938         uint8_t *plaintext, *ciphertext;
8939         uint8_t *iv_ptr;
8940         int32_t cipher_len, crc_len;
8941         uint32_t crc_data_len;
8942         int ret = TEST_SUCCESS;
8943
8944         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8945                                         rte_cryptodev_get_sec_ctx(
8946                                                 ts_params->valid_devs[0]);
8947
8948         /* Verify the capabilities */
8949         struct rte_security_capability_idx sec_cap_idx;
8950         const struct rte_security_capability *sec_cap;
8951         const struct rte_cryptodev_capabilities *crypto_cap;
8952         const struct rte_cryptodev_symmetric_capability *sym_cap;
8953         int j = 0;
8954
8955         sec_cap_idx.action = ut_params->type;
8956         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8957         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
8958
8959         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8960         if (sec_cap == NULL)
8961                 return TEST_SKIPPED;
8962
8963         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8964                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8965                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8966                                 crypto_cap->sym.xform_type ==
8967                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
8968                                 crypto_cap->sym.cipher.algo ==
8969                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8970                         sym_cap = &crypto_cap->sym;
8971                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8972                                                 d_td->key.len,
8973                                                 d_td->iv.len) == 0)
8974                                 break;
8975                 }
8976         }
8977
8978         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8979                 return TEST_SKIPPED;
8980
8981         /* Setup source mbuf payload */
8982         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8983         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8984                         rte_pktmbuf_tailroom(ut_params->ibuf));
8985
8986         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8987                         d_td->ciphertext.len);
8988
8989         memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
8990
8991         /* Setup cipher session parameters */
8992         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8993         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8994         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
8995         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8996         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8997         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8998         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8999         ut_params->cipher_xform.next = NULL;
9000
9001         /* Setup DOCSIS session parameters */
9002         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
9003
9004         struct rte_security_session_conf sess_conf = {
9005                 .action_type = ut_params->type,
9006                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9007                 .docsis = ut_params->docsis_xform,
9008                 .crypto_xform = &ut_params->cipher_xform,
9009         };
9010
9011         /* Create security session */
9012         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9013                                         ts_params->session_mpool,
9014                                         ts_params->session_priv_mpool);
9015
9016         if (!ut_params->sec_session) {
9017                 printf("TestCase %s(%d) line %d: %s\n",
9018                         __func__, i, __LINE__, "failed to allocate session");
9019                 ret = TEST_FAILED;
9020                 goto on_err;
9021         }
9022
9023         /* Generate crypto op data structure */
9024         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9025                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9026         if (!ut_params->op) {
9027                 printf("TestCase %s(%d) line %d: %s\n",
9028                         __func__, i, __LINE__,
9029                         "failed to allocate symmetric crypto operation");
9030                 ret = TEST_FAILED;
9031                 goto on_err;
9032         }
9033
9034         /* Setup CRC operation parameters */
9035         crc_len = d_td->ciphertext.no_crc == false ?
9036                         (d_td->ciphertext.len -
9037                                 d_td->ciphertext.crc_offset -
9038                                 RTE_ETHER_CRC_LEN) :
9039                         0;
9040         crc_len = crc_len > 0 ? crc_len : 0;
9041         crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
9042         ut_params->op->sym->auth.data.length = crc_len;
9043         ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
9044
9045         /* Setup cipher operation parameters */
9046         cipher_len = d_td->ciphertext.no_cipher == false ?
9047                         (d_td->ciphertext.len -
9048                                 d_td->ciphertext.cipher_offset) :
9049                         0;
9050         cipher_len = cipher_len > 0 ? cipher_len : 0;
9051         ut_params->op->sym->cipher.data.length = cipher_len;
9052         ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
9053
9054         /* Setup cipher IV */
9055         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9056         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9057
9058         /* Attach session to operation */
9059         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9060
9061         /* Set crypto operation mbufs */
9062         ut_params->op->sym->m_src = ut_params->ibuf;
9063         ut_params->op->sym->m_dst = NULL;
9064
9065         /* Process crypto operation */
9066         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9067                         NULL) {
9068                 printf("TestCase %s(%d) line %d: %s\n",
9069                         __func__, i, __LINE__,
9070                         "failed to process security crypto op");
9071                 ret = TEST_FAILED;
9072                 goto on_err;
9073         }
9074
9075         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9076                 printf("TestCase %s(%d) line %d: %s\n",
9077                         __func__, i, __LINE__, "crypto op processing failed");
9078                 ret = TEST_FAILED;
9079                 goto on_err;
9080         }
9081
9082         /* Validate plaintext */
9083         plaintext = ciphertext;
9084
9085         if (memcmp(plaintext, d_td->plaintext.data,
9086                         d_td->plaintext.len - crc_data_len)) {
9087                 printf("TestCase %s(%d) line %d: %s\n",
9088                         __func__, i, __LINE__, "plaintext not as expected\n");
9089                 rte_hexdump(stdout, "expected", d_td->plaintext.data,
9090                                 d_td->plaintext.len);
9091                 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9092                 ret = TEST_FAILED;
9093                 goto on_err;
9094         }
9095
9096 on_err:
9097         rte_crypto_op_free(ut_params->op);
9098         ut_params->op = NULL;
9099
9100         if (ut_params->sec_session)
9101                 rte_security_session_destroy(ctx, ut_params->sec_session);
9102         ut_params->sec_session = NULL;
9103
9104         rte_pktmbuf_free(ut_params->ibuf);
9105         ut_params->ibuf = NULL;
9106
9107         return ret;
9108 }
9109
9110 static int
9111 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9112 {
9113         struct crypto_testsuite_params *ts_params = &testsuite_params;
9114         struct crypto_unittest_params *ut_params = &unittest_params;
9115         uint8_t *plaintext, *ciphertext;
9116         uint8_t *iv_ptr;
9117         int32_t cipher_len, crc_len;
9118         int ret = TEST_SUCCESS;
9119
9120         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9121                                         rte_cryptodev_get_sec_ctx(
9122                                                 ts_params->valid_devs[0]);
9123
9124         /* Verify the capabilities */
9125         struct rte_security_capability_idx sec_cap_idx;
9126         const struct rte_security_capability *sec_cap;
9127         const struct rte_cryptodev_capabilities *crypto_cap;
9128         const struct rte_cryptodev_symmetric_capability *sym_cap;
9129         int j = 0;
9130
9131         sec_cap_idx.action = ut_params->type;
9132         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9133         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9134
9135         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9136         if (sec_cap == NULL)
9137                 return TEST_SKIPPED;
9138
9139         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9140                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9141                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9142                                 crypto_cap->sym.xform_type ==
9143                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9144                                 crypto_cap->sym.cipher.algo ==
9145                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9146                         sym_cap = &crypto_cap->sym;
9147                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9148                                                 d_td->key.len,
9149                                                 d_td->iv.len) == 0)
9150                                 break;
9151                 }
9152         }
9153
9154         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9155                 return TEST_SKIPPED;
9156
9157         /* Setup source mbuf payload */
9158         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9159         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9160                         rte_pktmbuf_tailroom(ut_params->ibuf));
9161
9162         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9163                         d_td->plaintext.len);
9164
9165         memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9166
9167         /* Setup cipher session parameters */
9168         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9169         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9170         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9171         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9172         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9173         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9174         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9175         ut_params->cipher_xform.next = NULL;
9176
9177         /* Setup DOCSIS session parameters */
9178         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9179
9180         struct rte_security_session_conf sess_conf = {
9181                 .action_type = ut_params->type,
9182                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9183                 .docsis = ut_params->docsis_xform,
9184                 .crypto_xform = &ut_params->cipher_xform,
9185         };
9186
9187         /* Create security session */
9188         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9189                                         ts_params->session_mpool,
9190                                         ts_params->session_priv_mpool);
9191
9192         if (!ut_params->sec_session) {
9193                 printf("TestCase %s(%d) line %d: %s\n",
9194                         __func__, i, __LINE__, "failed to allocate session");
9195                 ret = TEST_FAILED;
9196                 goto on_err;
9197         }
9198
9199         /* Generate crypto op data structure */
9200         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9201                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9202         if (!ut_params->op) {
9203                 printf("TestCase %s(%d) line %d: %s\n",
9204                         __func__, i, __LINE__,
9205                         "failed to allocate security crypto operation");
9206                 ret = TEST_FAILED;
9207                 goto on_err;
9208         }
9209
9210         /* Setup CRC operation parameters */
9211         crc_len = d_td->plaintext.no_crc == false ?
9212                         (d_td->plaintext.len -
9213                                 d_td->plaintext.crc_offset -
9214                                 RTE_ETHER_CRC_LEN) :
9215                         0;
9216         crc_len = crc_len > 0 ? crc_len : 0;
9217         ut_params->op->sym->auth.data.length = crc_len;
9218         ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9219
9220         /* Setup cipher operation parameters */
9221         cipher_len = d_td->plaintext.no_cipher == false ?
9222                         (d_td->plaintext.len -
9223                                 d_td->plaintext.cipher_offset) :
9224                         0;
9225         cipher_len = cipher_len > 0 ? cipher_len : 0;
9226         ut_params->op->sym->cipher.data.length = cipher_len;
9227         ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9228
9229         /* Setup cipher IV */
9230         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9231         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9232
9233         /* Attach session to operation */
9234         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9235
9236         /* Set crypto operation mbufs */
9237         ut_params->op->sym->m_src = ut_params->ibuf;
9238         ut_params->op->sym->m_dst = NULL;
9239
9240         /* Process crypto operation */
9241         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9242                         NULL) {
9243                 printf("TestCase %s(%d) line %d: %s\n",
9244                         __func__, i, __LINE__,
9245                         "failed to process security crypto op");
9246                 ret = TEST_FAILED;
9247                 goto on_err;
9248         }
9249
9250         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9251                 printf("TestCase %s(%d) line %d: %s\n",
9252                         __func__, i, __LINE__, "crypto op processing failed");
9253                 ret = TEST_FAILED;
9254                 goto on_err;
9255         }
9256
9257         /* Validate ciphertext */
9258         ciphertext = plaintext;
9259
9260         if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9261                 printf("TestCase %s(%d) line %d: %s\n",
9262                         __func__, i, __LINE__, "ciphertext not as expected\n");
9263                 rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9264                                 d_td->ciphertext.len);
9265                 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9266                 ret = TEST_FAILED;
9267                 goto on_err;
9268         }
9269
9270 on_err:
9271         rte_crypto_op_free(ut_params->op);
9272         ut_params->op = NULL;
9273
9274         if (ut_params->sec_session)
9275                 rte_security_session_destroy(ctx, ut_params->sec_session);
9276         ut_params->sec_session = NULL;
9277
9278         rte_pktmbuf_free(ut_params->ibuf);
9279         ut_params->ibuf = NULL;
9280
9281         return ret;
9282 }
9283
9284 #define TEST_DOCSIS_COUNT(func) do {                    \
9285         int ret = func;                                 \
9286         if (ret == TEST_SUCCESS)  {                     \
9287                 printf("\t%2d)", n++);                  \
9288                 printf("+++++ PASSED:" #func"\n");      \
9289                 p++;                                    \
9290         } else if (ret == TEST_SKIPPED) {               \
9291                 printf("\t%2d)", n++);                  \
9292                 printf("~~~~~ SKIPPED:" #func"\n");     \
9293                 s++;                                    \
9294         } else {                                        \
9295                 printf("\t%2d)", n++);                  \
9296                 printf("----- FAILED:" #func"\n");      \
9297                 f++;                                    \
9298         }                                               \
9299 } while (0)
9300
9301 static int
9302 test_DOCSIS_PROTO_uplink_all(void)
9303 {
9304         int p = 0, s = 0, f = 0, n = 0;
9305
9306         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9307         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9308         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9309         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9310         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9311         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9312         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9313         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9314         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9315         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9316         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9317         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9318         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9319         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9320         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9321         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9322         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9323         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9324         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9325         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9326         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9327         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9328         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9329         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9330         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9331         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9332
9333         if (f)
9334                 printf("## %s: %d passed out of %d (%d skipped)\n",
9335                         __func__, p, n, s);
9336
9337         return f;
9338 };
9339
9340 static int
9341 test_DOCSIS_PROTO_downlink_all(void)
9342 {
9343         int p = 0, s = 0, f = 0, n = 0;
9344
9345         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9346         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9347         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9348         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9349         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9350         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9351         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9352         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9353         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9354         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9355         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9356         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9357         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9358         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9359         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9360         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9361         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9362         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9363         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9364         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9365         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9366         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9367         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9368         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9369         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9370         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9371
9372         if (f)
9373                 printf("## %s: %d passed out of %d (%d skipped)\n",
9374                         __func__, p, n, s);
9375
9376         return f;
9377 };
9378
9379 static int
9380 test_DOCSIS_PROTO_all(void)
9381 {
9382         struct crypto_testsuite_params *ts_params = &testsuite_params;
9383         struct crypto_unittest_params *ut_params = &unittest_params;
9384         struct rte_cryptodev_info dev_info;
9385         int status;
9386
9387         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9388         uint64_t feat_flags = dev_info.feature_flags;
9389
9390         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9391                 return TEST_SKIPPED;
9392
9393         /* Set action type */
9394         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9395                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9396                 gbl_action_type;
9397
9398         if (security_proto_supported(ut_params->type,
9399                         RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9400                 return TEST_SKIPPED;
9401
9402         status = test_DOCSIS_PROTO_uplink_all();
9403         status += test_DOCSIS_PROTO_downlink_all();
9404
9405         if (status)
9406                 return TEST_FAILED;
9407         else
9408                 return TEST_SUCCESS;
9409 }
9410 #endif
9411
9412 static int
9413 test_AES_GCM_authenticated_encryption_test_case_1(void)
9414 {
9415         return test_authenticated_encryption(&gcm_test_case_1);
9416 }
9417
9418 static int
9419 test_AES_GCM_authenticated_encryption_test_case_2(void)
9420 {
9421         return test_authenticated_encryption(&gcm_test_case_2);
9422 }
9423
9424 static int
9425 test_AES_GCM_authenticated_encryption_test_case_3(void)
9426 {
9427         return test_authenticated_encryption(&gcm_test_case_3);
9428 }
9429
9430 static int
9431 test_AES_GCM_authenticated_encryption_test_case_4(void)
9432 {
9433         return test_authenticated_encryption(&gcm_test_case_4);
9434 }
9435
9436 static int
9437 test_AES_GCM_authenticated_encryption_test_case_5(void)
9438 {
9439         return test_authenticated_encryption(&gcm_test_case_5);
9440 }
9441
9442 static int
9443 test_AES_GCM_authenticated_encryption_test_case_6(void)
9444 {
9445         return test_authenticated_encryption(&gcm_test_case_6);
9446 }
9447
9448 static int
9449 test_AES_GCM_authenticated_encryption_test_case_7(void)
9450 {
9451         return test_authenticated_encryption(&gcm_test_case_7);
9452 }
9453
9454 static int
9455 test_AES_GCM_authenticated_encryption_test_case_8(void)
9456 {
9457         return test_authenticated_encryption(&gcm_test_case_8);
9458 }
9459
9460 static int
9461 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9462 {
9463         return test_authenticated_encryption(&gcm_J0_test_case_1);
9464 }
9465
9466 static int
9467 test_AES_GCM_auth_encryption_test_case_192_1(void)
9468 {
9469         return test_authenticated_encryption(&gcm_test_case_192_1);
9470 }
9471
9472 static int
9473 test_AES_GCM_auth_encryption_test_case_192_2(void)
9474 {
9475         return test_authenticated_encryption(&gcm_test_case_192_2);
9476 }
9477
9478 static int
9479 test_AES_GCM_auth_encryption_test_case_192_3(void)
9480 {
9481         return test_authenticated_encryption(&gcm_test_case_192_3);
9482 }
9483
9484 static int
9485 test_AES_GCM_auth_encryption_test_case_192_4(void)
9486 {
9487         return test_authenticated_encryption(&gcm_test_case_192_4);
9488 }
9489
9490 static int
9491 test_AES_GCM_auth_encryption_test_case_192_5(void)
9492 {
9493         return test_authenticated_encryption(&gcm_test_case_192_5);
9494 }
9495
9496 static int
9497 test_AES_GCM_auth_encryption_test_case_192_6(void)
9498 {
9499         return test_authenticated_encryption(&gcm_test_case_192_6);
9500 }
9501
9502 static int
9503 test_AES_GCM_auth_encryption_test_case_192_7(void)
9504 {
9505         return test_authenticated_encryption(&gcm_test_case_192_7);
9506 }
9507
9508 static int
9509 test_AES_GCM_auth_encryption_test_case_256_1(void)
9510 {
9511         return test_authenticated_encryption(&gcm_test_case_256_1);
9512 }
9513
9514 static int
9515 test_AES_GCM_auth_encryption_test_case_256_2(void)
9516 {
9517         return test_authenticated_encryption(&gcm_test_case_256_2);
9518 }
9519
9520 static int
9521 test_AES_GCM_auth_encryption_test_case_256_3(void)
9522 {
9523         return test_authenticated_encryption(&gcm_test_case_256_3);
9524 }
9525
9526 static int
9527 test_AES_GCM_auth_encryption_test_case_256_4(void)
9528 {
9529         return test_authenticated_encryption(&gcm_test_case_256_4);
9530 }
9531
9532 static int
9533 test_AES_GCM_auth_encryption_test_case_256_5(void)
9534 {
9535         return test_authenticated_encryption(&gcm_test_case_256_5);
9536 }
9537
9538 static int
9539 test_AES_GCM_auth_encryption_test_case_256_6(void)
9540 {
9541         return test_authenticated_encryption(&gcm_test_case_256_6);
9542 }
9543
9544 static int
9545 test_AES_GCM_auth_encryption_test_case_256_7(void)
9546 {
9547         return test_authenticated_encryption(&gcm_test_case_256_7);
9548 }
9549
9550 static int
9551 test_AES_GCM_auth_encryption_test_case_aad_1(void)
9552 {
9553         return test_authenticated_encryption(&gcm_test_case_aad_1);
9554 }
9555
9556 static int
9557 test_AES_GCM_auth_encryption_test_case_aad_2(void)
9558 {
9559         return test_authenticated_encryption(&gcm_test_case_aad_2);
9560 }
9561
9562 static int
9563 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
9564 {
9565         struct aead_test_data tdata;
9566         int res;
9567
9568         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9569         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9570         tdata.iv.data[0] += 1;
9571         res = test_authenticated_encryption(&tdata);
9572         if (res == TEST_SKIPPED)
9573                 return res;
9574         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9575         return TEST_SUCCESS;
9576 }
9577
9578 static int
9579 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
9580 {
9581         struct aead_test_data tdata;
9582         int res;
9583
9584         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9585         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9586         tdata.plaintext.data[0] += 1;
9587         res = test_authenticated_encryption(&tdata);
9588         if (res == TEST_SKIPPED)
9589                 return res;
9590         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9591         return TEST_SUCCESS;
9592 }
9593
9594 static int
9595 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
9596 {
9597         struct aead_test_data tdata;
9598         int res;
9599
9600         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9601         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9602         tdata.ciphertext.data[0] += 1;
9603         res = test_authenticated_encryption(&tdata);
9604         if (res == TEST_SKIPPED)
9605                 return res;
9606         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9607         return TEST_SUCCESS;
9608 }
9609
9610 static int
9611 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
9612 {
9613         struct aead_test_data tdata;
9614         int res;
9615
9616         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9617         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9618         tdata.aad.len += 1;
9619         res = test_authenticated_encryption(&tdata);
9620         if (res == TEST_SKIPPED)
9621                 return res;
9622         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9623         return TEST_SUCCESS;
9624 }
9625
9626 static int
9627 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
9628 {
9629         struct aead_test_data tdata;
9630         uint8_t aad[gcm_test_case_7.aad.len];
9631         int res;
9632
9633         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9634         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9635         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9636         aad[0] += 1;
9637         tdata.aad.data = aad;
9638         res = test_authenticated_encryption(&tdata);
9639         if (res == TEST_SKIPPED)
9640                 return res;
9641         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9642         return TEST_SUCCESS;
9643 }
9644
9645 static int
9646 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
9647 {
9648         struct aead_test_data tdata;
9649         int res;
9650
9651         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9652         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9653         tdata.auth_tag.data[0] += 1;
9654         res = test_authenticated_encryption(&tdata);
9655         if (res == TEST_SKIPPED)
9656                 return res;
9657         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9658         return TEST_SUCCESS;
9659 }
9660
9661 static int
9662 test_authenticated_decryption(const struct aead_test_data *tdata)
9663 {
9664         struct crypto_testsuite_params *ts_params = &testsuite_params;
9665         struct crypto_unittest_params *ut_params = &unittest_params;
9666
9667         int retval;
9668         uint8_t *plaintext;
9669         uint32_t i;
9670         struct rte_cryptodev_info dev_info;
9671
9672         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9673         uint64_t feat_flags = dev_info.feature_flags;
9674
9675         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9676                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9677                 printf("Device doesn't support RAW data-path APIs.\n");
9678                 return TEST_SKIPPED;
9679         }
9680
9681         /* Verify the capabilities */
9682         struct rte_cryptodev_sym_capability_idx cap_idx;
9683         const struct rte_cryptodev_symmetric_capability *capability;
9684         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9685         cap_idx.algo.aead = tdata->algo;
9686         capability = rte_cryptodev_sym_capability_get(
9687                         ts_params->valid_devs[0], &cap_idx);
9688         if (capability == NULL)
9689                 return TEST_SKIPPED;
9690         if (rte_cryptodev_sym_capability_check_aead(
9691                         capability, tdata->key.len, tdata->auth_tag.len,
9692                         tdata->aad.len, tdata->iv.len))
9693                 return TEST_SKIPPED;
9694
9695         /* Create AEAD session */
9696         retval = create_aead_session(ts_params->valid_devs[0],
9697                         tdata->algo,
9698                         RTE_CRYPTO_AEAD_OP_DECRYPT,
9699                         tdata->key.data, tdata->key.len,
9700                         tdata->aad.len, tdata->auth_tag.len,
9701                         tdata->iv.len);
9702         if (retval < 0)
9703                 return retval;
9704
9705         /* alloc mbuf and set payload */
9706         if (tdata->aad.len > MBUF_SIZE) {
9707                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9708                 /* Populate full size of add data */
9709                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
9710                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
9711         } else
9712                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9713
9714         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9715                         rte_pktmbuf_tailroom(ut_params->ibuf));
9716
9717         /* Create AEAD operation */
9718         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9719         if (retval < 0)
9720                 return retval;
9721
9722         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9723
9724         ut_params->op->sym->m_src = ut_params->ibuf;
9725
9726         /* Process crypto operation */
9727         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9728                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
9729         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9730                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9731                                 ut_params->op, 0, 0, 0, 0);
9732         else
9733                 TEST_ASSERT_NOT_NULL(
9734                         process_crypto_request(ts_params->valid_devs[0],
9735                         ut_params->op), "failed to process sym crypto op");
9736
9737         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9738                         "crypto op processing failed");
9739
9740         if (ut_params->op->sym->m_dst)
9741                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9742                                 uint8_t *);
9743         else
9744                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
9745                                 uint8_t *,
9746                                 ut_params->op->sym->cipher.data.offset);
9747
9748         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9749
9750         /* Validate obuf */
9751         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9752                         plaintext,
9753                         tdata->plaintext.data,
9754                         tdata->plaintext.len,
9755                         "Plaintext data not as expected");
9756
9757         TEST_ASSERT_EQUAL(ut_params->op->status,
9758                         RTE_CRYPTO_OP_STATUS_SUCCESS,
9759                         "Authentication failed");
9760
9761         return 0;
9762 }
9763
9764 static int
9765 test_AES_GCM_authenticated_decryption_test_case_1(void)
9766 {
9767         return test_authenticated_decryption(&gcm_test_case_1);
9768 }
9769
9770 static int
9771 test_AES_GCM_authenticated_decryption_test_case_2(void)
9772 {
9773         return test_authenticated_decryption(&gcm_test_case_2);
9774 }
9775
9776 static int
9777 test_AES_GCM_authenticated_decryption_test_case_3(void)
9778 {
9779         return test_authenticated_decryption(&gcm_test_case_3);
9780 }
9781
9782 static int
9783 test_AES_GCM_authenticated_decryption_test_case_4(void)
9784 {
9785         return test_authenticated_decryption(&gcm_test_case_4);
9786 }
9787
9788 static int
9789 test_AES_GCM_authenticated_decryption_test_case_5(void)
9790 {
9791         return test_authenticated_decryption(&gcm_test_case_5);
9792 }
9793
9794 static int
9795 test_AES_GCM_authenticated_decryption_test_case_6(void)
9796 {
9797         return test_authenticated_decryption(&gcm_test_case_6);
9798 }
9799
9800 static int
9801 test_AES_GCM_authenticated_decryption_test_case_7(void)
9802 {
9803         return test_authenticated_decryption(&gcm_test_case_7);
9804 }
9805
9806 static int
9807 test_AES_GCM_authenticated_decryption_test_case_8(void)
9808 {
9809         return test_authenticated_decryption(&gcm_test_case_8);
9810 }
9811
9812 static int
9813 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
9814 {
9815         return test_authenticated_decryption(&gcm_J0_test_case_1);
9816 }
9817
9818 static int
9819 test_AES_GCM_auth_decryption_test_case_192_1(void)
9820 {
9821         return test_authenticated_decryption(&gcm_test_case_192_1);
9822 }
9823
9824 static int
9825 test_AES_GCM_auth_decryption_test_case_192_2(void)
9826 {
9827         return test_authenticated_decryption(&gcm_test_case_192_2);
9828 }
9829
9830 static int
9831 test_AES_GCM_auth_decryption_test_case_192_3(void)
9832 {
9833         return test_authenticated_decryption(&gcm_test_case_192_3);
9834 }
9835
9836 static int
9837 test_AES_GCM_auth_decryption_test_case_192_4(void)
9838 {
9839         return test_authenticated_decryption(&gcm_test_case_192_4);
9840 }
9841
9842 static int
9843 test_AES_GCM_auth_decryption_test_case_192_5(void)
9844 {
9845         return test_authenticated_decryption(&gcm_test_case_192_5);
9846 }
9847
9848 static int
9849 test_AES_GCM_auth_decryption_test_case_192_6(void)
9850 {
9851         return test_authenticated_decryption(&gcm_test_case_192_6);
9852 }
9853
9854 static int
9855 test_AES_GCM_auth_decryption_test_case_192_7(void)
9856 {
9857         return test_authenticated_decryption(&gcm_test_case_192_7);
9858 }
9859
9860 static int
9861 test_AES_GCM_auth_decryption_test_case_256_1(void)
9862 {
9863         return test_authenticated_decryption(&gcm_test_case_256_1);
9864 }
9865
9866 static int
9867 test_AES_GCM_auth_decryption_test_case_256_2(void)
9868 {
9869         return test_authenticated_decryption(&gcm_test_case_256_2);
9870 }
9871
9872 static int
9873 test_AES_GCM_auth_decryption_test_case_256_3(void)
9874 {
9875         return test_authenticated_decryption(&gcm_test_case_256_3);
9876 }
9877
9878 static int
9879 test_AES_GCM_auth_decryption_test_case_256_4(void)
9880 {
9881         return test_authenticated_decryption(&gcm_test_case_256_4);
9882 }
9883
9884 static int
9885 test_AES_GCM_auth_decryption_test_case_256_5(void)
9886 {
9887         return test_authenticated_decryption(&gcm_test_case_256_5);
9888 }
9889
9890 static int
9891 test_AES_GCM_auth_decryption_test_case_256_6(void)
9892 {
9893         return test_authenticated_decryption(&gcm_test_case_256_6);
9894 }
9895
9896 static int
9897 test_AES_GCM_auth_decryption_test_case_256_7(void)
9898 {
9899         return test_authenticated_decryption(&gcm_test_case_256_7);
9900 }
9901
9902 static int
9903 test_AES_GCM_auth_decryption_test_case_aad_1(void)
9904 {
9905         return test_authenticated_decryption(&gcm_test_case_aad_1);
9906 }
9907
9908 static int
9909 test_AES_GCM_auth_decryption_test_case_aad_2(void)
9910 {
9911         return test_authenticated_decryption(&gcm_test_case_aad_2);
9912 }
9913
9914 static int
9915 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
9916 {
9917         struct aead_test_data tdata;
9918         int res;
9919
9920         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9921         tdata.iv.data[0] += 1;
9922         res = test_authenticated_decryption(&tdata);
9923         if (res == TEST_SKIPPED)
9924                 return res;
9925         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9926         return TEST_SUCCESS;
9927 }
9928
9929 static int
9930 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
9931 {
9932         struct aead_test_data tdata;
9933         int res;
9934
9935         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9936         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9937         tdata.plaintext.data[0] += 1;
9938         res = test_authenticated_decryption(&tdata);
9939         if (res == TEST_SKIPPED)
9940                 return res;
9941         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9942         return TEST_SUCCESS;
9943 }
9944
9945 static int
9946 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
9947 {
9948         struct aead_test_data tdata;
9949         int res;
9950
9951         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9952         tdata.ciphertext.data[0] += 1;
9953         res = test_authenticated_decryption(&tdata);
9954         if (res == TEST_SKIPPED)
9955                 return res;
9956         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9957         return TEST_SUCCESS;
9958 }
9959
9960 static int
9961 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
9962 {
9963         struct aead_test_data tdata;
9964         int res;
9965
9966         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9967         tdata.aad.len += 1;
9968         res = test_authenticated_decryption(&tdata);
9969         if (res == TEST_SKIPPED)
9970                 return res;
9971         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9972         return TEST_SUCCESS;
9973 }
9974
9975 static int
9976 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
9977 {
9978         struct aead_test_data tdata;
9979         uint8_t aad[gcm_test_case_7.aad.len];
9980         int res;
9981
9982         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9983         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9984         aad[0] += 1;
9985         tdata.aad.data = aad;
9986         res = test_authenticated_decryption(&tdata);
9987         if (res == TEST_SKIPPED)
9988                 return res;
9989         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9990         return TEST_SUCCESS;
9991 }
9992
9993 static int
9994 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
9995 {
9996         struct aead_test_data tdata;
9997         int res;
9998
9999         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10000         tdata.auth_tag.data[0] += 1;
10001         res = test_authenticated_decryption(&tdata);
10002         if (res == TEST_SKIPPED)
10003                 return res;
10004         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
10005         return TEST_SUCCESS;
10006 }
10007
10008 static int
10009 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
10010 {
10011         struct crypto_testsuite_params *ts_params = &testsuite_params;
10012         struct crypto_unittest_params *ut_params = &unittest_params;
10013
10014         int retval;
10015         uint8_t *ciphertext, *auth_tag;
10016         uint16_t plaintext_pad_len;
10017
10018         /* Verify the capabilities */
10019         struct rte_cryptodev_sym_capability_idx cap_idx;
10020         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10021         cap_idx.algo.aead = tdata->algo;
10022         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10023                         &cap_idx) == NULL)
10024                 return TEST_SKIPPED;
10025
10026         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10027                 return TEST_SKIPPED;
10028
10029         /* not supported with CPU crypto */
10030         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10031                 return TEST_SKIPPED;
10032
10033         /* Create AEAD session */
10034         retval = create_aead_session(ts_params->valid_devs[0],
10035                         tdata->algo,
10036                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10037                         tdata->key.data, tdata->key.len,
10038                         tdata->aad.len, tdata->auth_tag.len,
10039                         tdata->iv.len);
10040         if (retval < 0)
10041                 return retval;
10042
10043         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10044         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10045
10046         /* clear mbuf payload */
10047         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10048                         rte_pktmbuf_tailroom(ut_params->ibuf));
10049         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10050                         rte_pktmbuf_tailroom(ut_params->obuf));
10051
10052         /* Create AEAD operation */
10053         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10054         if (retval < 0)
10055                 return retval;
10056
10057         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10058
10059         ut_params->op->sym->m_src = ut_params->ibuf;
10060         ut_params->op->sym->m_dst = ut_params->obuf;
10061
10062         /* Process crypto operation */
10063         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10064                         ut_params->op), "failed to process sym crypto op");
10065
10066         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10067                         "crypto op processing failed");
10068
10069         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10070
10071         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10072                         ut_params->op->sym->cipher.data.offset);
10073         auth_tag = ciphertext + plaintext_pad_len;
10074
10075         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10076         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10077
10078         /* Validate obuf */
10079         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10080                         ciphertext,
10081                         tdata->ciphertext.data,
10082                         tdata->ciphertext.len,
10083                         "Ciphertext data not as expected");
10084
10085         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10086                         auth_tag,
10087                         tdata->auth_tag.data,
10088                         tdata->auth_tag.len,
10089                         "Generated auth tag not as expected");
10090
10091         return 0;
10092
10093 }
10094
10095 static int
10096 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10097 {
10098         return test_authenticated_encryption_oop(&gcm_test_case_5);
10099 }
10100
10101 static int
10102 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10103 {
10104         struct crypto_testsuite_params *ts_params = &testsuite_params;
10105         struct crypto_unittest_params *ut_params = &unittest_params;
10106
10107         int retval;
10108         uint8_t *plaintext;
10109
10110         /* Verify the capabilities */
10111         struct rte_cryptodev_sym_capability_idx cap_idx;
10112         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10113         cap_idx.algo.aead = tdata->algo;
10114         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10115                         &cap_idx) == NULL)
10116                 return TEST_SKIPPED;
10117
10118         /* not supported with CPU crypto and raw data-path APIs*/
10119         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10120                         global_api_test_type == CRYPTODEV_RAW_API_TEST)
10121                 return TEST_SKIPPED;
10122
10123         /* Create AEAD session */
10124         retval = create_aead_session(ts_params->valid_devs[0],
10125                         tdata->algo,
10126                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10127                         tdata->key.data, tdata->key.len,
10128                         tdata->aad.len, tdata->auth_tag.len,
10129                         tdata->iv.len);
10130         if (retval < 0)
10131                 return retval;
10132
10133         /* alloc mbuf and set payload */
10134         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10135         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10136
10137         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10138                         rte_pktmbuf_tailroom(ut_params->ibuf));
10139         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10140                         rte_pktmbuf_tailroom(ut_params->obuf));
10141
10142         /* Create AEAD operation */
10143         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10144         if (retval < 0)
10145                 return retval;
10146
10147         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10148
10149         ut_params->op->sym->m_src = ut_params->ibuf;
10150         ut_params->op->sym->m_dst = ut_params->obuf;
10151
10152         /* Process crypto operation */
10153         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10154                         ut_params->op), "failed to process sym crypto op");
10155
10156         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10157                         "crypto op processing failed");
10158
10159         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10160                         ut_params->op->sym->cipher.data.offset);
10161
10162         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10163
10164         /* Validate obuf */
10165         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10166                         plaintext,
10167                         tdata->plaintext.data,
10168                         tdata->plaintext.len,
10169                         "Plaintext data not as expected");
10170
10171         TEST_ASSERT_EQUAL(ut_params->op->status,
10172                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10173                         "Authentication failed");
10174         return 0;
10175 }
10176
10177 static int
10178 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10179 {
10180         return test_authenticated_decryption_oop(&gcm_test_case_5);
10181 }
10182
10183 static int
10184 test_authenticated_encryption_sessionless(
10185                 const struct aead_test_data *tdata)
10186 {
10187         struct crypto_testsuite_params *ts_params = &testsuite_params;
10188         struct crypto_unittest_params *ut_params = &unittest_params;
10189
10190         int retval;
10191         uint8_t *ciphertext, *auth_tag;
10192         uint16_t plaintext_pad_len;
10193         uint8_t key[tdata->key.len + 1];
10194         struct rte_cryptodev_info dev_info;
10195
10196         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10197         uint64_t feat_flags = dev_info.feature_flags;
10198
10199         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10200                 printf("Device doesn't support Sessionless ops.\n");
10201                 return TEST_SKIPPED;
10202         }
10203
10204         /* not supported with CPU crypto */
10205         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10206                 return TEST_SKIPPED;
10207
10208         /* Verify the capabilities */
10209         struct rte_cryptodev_sym_capability_idx cap_idx;
10210         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10211         cap_idx.algo.aead = tdata->algo;
10212         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10213                         &cap_idx) == NULL)
10214                 return TEST_SKIPPED;
10215
10216         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10217
10218         /* clear mbuf payload */
10219         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10220                         rte_pktmbuf_tailroom(ut_params->ibuf));
10221
10222         /* Create AEAD operation */
10223         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10224         if (retval < 0)
10225                 return retval;
10226
10227         /* Create GCM xform */
10228         memcpy(key, tdata->key.data, tdata->key.len);
10229         retval = create_aead_xform(ut_params->op,
10230                         tdata->algo,
10231                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10232                         key, tdata->key.len,
10233                         tdata->aad.len, tdata->auth_tag.len,
10234                         tdata->iv.len);
10235         if (retval < 0)
10236                 return retval;
10237
10238         ut_params->op->sym->m_src = ut_params->ibuf;
10239
10240         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10241                         RTE_CRYPTO_OP_SESSIONLESS,
10242                         "crypto op session type not sessionless");
10243
10244         /* Process crypto operation */
10245         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10246                         ut_params->op), "failed to process sym crypto op");
10247
10248         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10249
10250         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10251                         "crypto op status not success");
10252
10253         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10254
10255         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10256                         ut_params->op->sym->cipher.data.offset);
10257         auth_tag = ciphertext + plaintext_pad_len;
10258
10259         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10260         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10261
10262         /* Validate obuf */
10263         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10264                         ciphertext,
10265                         tdata->ciphertext.data,
10266                         tdata->ciphertext.len,
10267                         "Ciphertext data not as expected");
10268
10269         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10270                         auth_tag,
10271                         tdata->auth_tag.data,
10272                         tdata->auth_tag.len,
10273                         "Generated auth tag not as expected");
10274
10275         return 0;
10276
10277 }
10278
10279 static int
10280 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10281 {
10282         return test_authenticated_encryption_sessionless(
10283                         &gcm_test_case_5);
10284 }
10285
10286 static int
10287 test_authenticated_decryption_sessionless(
10288                 const struct aead_test_data *tdata)
10289 {
10290         struct crypto_testsuite_params *ts_params = &testsuite_params;
10291         struct crypto_unittest_params *ut_params = &unittest_params;
10292
10293         int retval;
10294         uint8_t *plaintext;
10295         uint8_t key[tdata->key.len + 1];
10296         struct rte_cryptodev_info dev_info;
10297
10298         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10299         uint64_t feat_flags = dev_info.feature_flags;
10300
10301         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10302                 printf("Device doesn't support Sessionless ops.\n");
10303                 return TEST_SKIPPED;
10304         }
10305
10306         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10307                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10308                 printf("Device doesn't support RAW data-path APIs.\n");
10309                 return TEST_SKIPPED;
10310         }
10311
10312         /* not supported with CPU crypto */
10313         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10314                 return TEST_SKIPPED;
10315
10316         /* Verify the capabilities */
10317         struct rte_cryptodev_sym_capability_idx cap_idx;
10318         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10319         cap_idx.algo.aead = tdata->algo;
10320         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10321                         &cap_idx) == NULL)
10322                 return TEST_SKIPPED;
10323
10324         /* alloc mbuf and set payload */
10325         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10326
10327         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10328                         rte_pktmbuf_tailroom(ut_params->ibuf));
10329
10330         /* Create AEAD operation */
10331         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10332         if (retval < 0)
10333                 return retval;
10334
10335         /* Create AEAD xform */
10336         memcpy(key, tdata->key.data, tdata->key.len);
10337         retval = create_aead_xform(ut_params->op,
10338                         tdata->algo,
10339                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10340                         key, tdata->key.len,
10341                         tdata->aad.len, tdata->auth_tag.len,
10342                         tdata->iv.len);
10343         if (retval < 0)
10344                 return retval;
10345
10346         ut_params->op->sym->m_src = ut_params->ibuf;
10347
10348         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10349                         RTE_CRYPTO_OP_SESSIONLESS,
10350                         "crypto op session type not sessionless");
10351
10352         /* Process crypto operation */
10353         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10354                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10355                                 ut_params->op, 0, 0, 0, 0);
10356         else
10357                 TEST_ASSERT_NOT_NULL(process_crypto_request(
10358                         ts_params->valid_devs[0], ut_params->op),
10359                                 "failed to process sym crypto op");
10360
10361         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10362
10363         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10364                         "crypto op status not success");
10365
10366         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10367                         ut_params->op->sym->cipher.data.offset);
10368
10369         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10370
10371         /* Validate obuf */
10372         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10373                         plaintext,
10374                         tdata->plaintext.data,
10375                         tdata->plaintext.len,
10376                         "Plaintext data not as expected");
10377
10378         TEST_ASSERT_EQUAL(ut_params->op->status,
10379                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10380                         "Authentication failed");
10381         return 0;
10382 }
10383
10384 static int
10385 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
10386 {
10387         return test_authenticated_decryption_sessionless(
10388                         &gcm_test_case_5);
10389 }
10390
10391 static int
10392 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
10393 {
10394         return test_authenticated_encryption(&ccm_test_case_128_1);
10395 }
10396
10397 static int
10398 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
10399 {
10400         return test_authenticated_encryption(&ccm_test_case_128_2);
10401 }
10402
10403 static int
10404 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
10405 {
10406         return test_authenticated_encryption(&ccm_test_case_128_3);
10407 }
10408
10409 static int
10410 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
10411 {
10412         return test_authenticated_decryption(&ccm_test_case_128_1);
10413 }
10414
10415 static int
10416 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
10417 {
10418         return test_authenticated_decryption(&ccm_test_case_128_2);
10419 }
10420
10421 static int
10422 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10423 {
10424         return test_authenticated_decryption(&ccm_test_case_128_3);
10425 }
10426
10427 static int
10428 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10429 {
10430         return test_authenticated_encryption(&ccm_test_case_192_1);
10431 }
10432
10433 static int
10434 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10435 {
10436         return test_authenticated_encryption(&ccm_test_case_192_2);
10437 }
10438
10439 static int
10440 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10441 {
10442         return test_authenticated_encryption(&ccm_test_case_192_3);
10443 }
10444
10445 static int
10446 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10447 {
10448         return test_authenticated_decryption(&ccm_test_case_192_1);
10449 }
10450
10451 static int
10452 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10453 {
10454         return test_authenticated_decryption(&ccm_test_case_192_2);
10455 }
10456
10457 static int
10458 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10459 {
10460         return test_authenticated_decryption(&ccm_test_case_192_3);
10461 }
10462
10463 static int
10464 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
10465 {
10466         return test_authenticated_encryption(&ccm_test_case_256_1);
10467 }
10468
10469 static int
10470 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
10471 {
10472         return test_authenticated_encryption(&ccm_test_case_256_2);
10473 }
10474
10475 static int
10476 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
10477 {
10478         return test_authenticated_encryption(&ccm_test_case_256_3);
10479 }
10480
10481 static int
10482 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
10483 {
10484         return test_authenticated_decryption(&ccm_test_case_256_1);
10485 }
10486
10487 static int
10488 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
10489 {
10490         return test_authenticated_decryption(&ccm_test_case_256_2);
10491 }
10492
10493 static int
10494 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
10495 {
10496         return test_authenticated_decryption(&ccm_test_case_256_3);
10497 }
10498
10499 static int
10500 test_stats(void)
10501 {
10502         struct crypto_testsuite_params *ts_params = &testsuite_params;
10503         struct rte_cryptodev_stats stats;
10504
10505         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10506                 return TEST_SKIPPED;
10507
10508         /* Verify the capabilities */
10509         struct rte_cryptodev_sym_capability_idx cap_idx;
10510         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10511         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
10512         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10513                         &cap_idx) == NULL)
10514                 return TEST_SKIPPED;
10515         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10516         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10517         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10518                         &cap_idx) == NULL)
10519                 return TEST_SKIPPED;
10520
10521         if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
10522                         == -ENOTSUP)
10523                 return TEST_SKIPPED;
10524
10525         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10526         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
10527                         &stats) == -ENODEV),
10528                 "rte_cryptodev_stats_get invalid dev failed");
10529         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
10530                 "rte_cryptodev_stats_get invalid Param failed");
10531
10532         /* Test expected values */
10533         test_AES_CBC_HMAC_SHA1_encrypt_digest();
10534         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10535                         &stats),
10536                 "rte_cryptodev_stats_get failed");
10537         TEST_ASSERT((stats.enqueued_count == 1),
10538                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10539         TEST_ASSERT((stats.dequeued_count == 1),
10540                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10541         TEST_ASSERT((stats.enqueue_err_count == 0),
10542                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10543         TEST_ASSERT((stats.dequeue_err_count == 0),
10544                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10545
10546         /* invalid device but should ignore and not reset device stats*/
10547         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
10548         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10549                         &stats),
10550                 "rte_cryptodev_stats_get failed");
10551         TEST_ASSERT((stats.enqueued_count == 1),
10552                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10553
10554         /* check that a valid reset clears stats */
10555         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10556         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10557                         &stats),
10558                                           "rte_cryptodev_stats_get failed");
10559         TEST_ASSERT((stats.enqueued_count == 0),
10560                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10561         TEST_ASSERT((stats.dequeued_count == 0),
10562                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10563
10564         return TEST_SUCCESS;
10565 }
10566
10567 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
10568                                    struct crypto_unittest_params *ut_params,
10569                                    enum rte_crypto_auth_operation op,
10570                                    const struct HMAC_MD5_vector *test_case)
10571 {
10572         uint8_t key[64];
10573
10574         memcpy(key, test_case->key.data, test_case->key.len);
10575
10576         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10577         ut_params->auth_xform.next = NULL;
10578         ut_params->auth_xform.auth.op = op;
10579
10580         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
10581
10582         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
10583         ut_params->auth_xform.auth.key.length = test_case->key.len;
10584         ut_params->auth_xform.auth.key.data = key;
10585
10586         ut_params->sess = rte_cryptodev_sym_session_create(
10587                         ts_params->session_mpool);
10588
10589         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10590                         ut_params->sess, &ut_params->auth_xform,
10591                         ts_params->session_priv_mpool);
10592
10593         if (ut_params->sess == NULL)
10594                 return TEST_FAILED;
10595
10596         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10597
10598         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10599                         rte_pktmbuf_tailroom(ut_params->ibuf));
10600
10601         return 0;
10602 }
10603
10604 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
10605                               const struct HMAC_MD5_vector *test_case,
10606                               uint8_t **plaintext)
10607 {
10608         uint16_t plaintext_pad_len;
10609
10610         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10611
10612         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10613                                 16);
10614
10615         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10616                         plaintext_pad_len);
10617         memcpy(*plaintext, test_case->plaintext.data,
10618                         test_case->plaintext.len);
10619
10620         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10621                         ut_params->ibuf, MD5_DIGEST_LEN);
10622         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10623                         "no room to append digest");
10624         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10625                         ut_params->ibuf, plaintext_pad_len);
10626
10627         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10628                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
10629                            test_case->auth_tag.len);
10630         }
10631
10632         sym_op->auth.data.offset = 0;
10633         sym_op->auth.data.length = test_case->plaintext.len;
10634
10635         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10636         ut_params->op->sym->m_src = ut_params->ibuf;
10637
10638         return 0;
10639 }
10640
10641 static int
10642 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
10643 {
10644         uint16_t plaintext_pad_len;
10645         uint8_t *plaintext, *auth_tag;
10646
10647         struct crypto_testsuite_params *ts_params = &testsuite_params;
10648         struct crypto_unittest_params *ut_params = &unittest_params;
10649         struct rte_cryptodev_info dev_info;
10650
10651         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10652         uint64_t feat_flags = dev_info.feature_flags;
10653
10654         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10655                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10656                 printf("Device doesn't support RAW data-path APIs.\n");
10657                 return TEST_SKIPPED;
10658         }
10659
10660         /* Verify the capabilities */
10661         struct rte_cryptodev_sym_capability_idx cap_idx;
10662         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10663         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10664         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10665                         &cap_idx) == NULL)
10666                 return TEST_SKIPPED;
10667
10668         if (MD5_HMAC_create_session(ts_params, ut_params,
10669                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
10670                 return TEST_FAILED;
10671
10672         /* Generate Crypto op data structure */
10673         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10674                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10675         TEST_ASSERT_NOT_NULL(ut_params->op,
10676                         "Failed to allocate symmetric crypto operation struct");
10677
10678         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10679                                 16);
10680
10681         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10682                 return TEST_FAILED;
10683
10684         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10685                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10686                         ut_params->op);
10687         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10688                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10689                                 ut_params->op, 0, 1, 0, 0);
10690         else
10691                 TEST_ASSERT_NOT_NULL(
10692                         process_crypto_request(ts_params->valid_devs[0],
10693                                 ut_params->op),
10694                                 "failed to process sym crypto op");
10695
10696         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10697                         "crypto op processing failed");
10698
10699         if (ut_params->op->sym->m_dst) {
10700                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10701                                 uint8_t *, plaintext_pad_len);
10702         } else {
10703                 auth_tag = plaintext + plaintext_pad_len;
10704         }
10705
10706         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10707                         auth_tag,
10708                         test_case->auth_tag.data,
10709                         test_case->auth_tag.len,
10710                         "HMAC_MD5 generated tag not as expected");
10711
10712         return TEST_SUCCESS;
10713 }
10714
10715 static int
10716 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
10717 {
10718         uint8_t *plaintext;
10719
10720         struct crypto_testsuite_params *ts_params = &testsuite_params;
10721         struct crypto_unittest_params *ut_params = &unittest_params;
10722         struct rte_cryptodev_info dev_info;
10723
10724         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10725         uint64_t feat_flags = dev_info.feature_flags;
10726
10727         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10728                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10729                 printf("Device doesn't support RAW data-path APIs.\n");
10730                 return TEST_SKIPPED;
10731         }
10732
10733         /* Verify the capabilities */
10734         struct rte_cryptodev_sym_capability_idx cap_idx;
10735         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10736         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10737         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10738                         &cap_idx) == NULL)
10739                 return TEST_SKIPPED;
10740
10741         if (MD5_HMAC_create_session(ts_params, ut_params,
10742                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
10743                 return TEST_FAILED;
10744         }
10745
10746         /* Generate Crypto op data structure */
10747         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10748                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10749         TEST_ASSERT_NOT_NULL(ut_params->op,
10750                         "Failed to allocate symmetric crypto operation struct");
10751
10752         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10753                 return TEST_FAILED;
10754
10755         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10756                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10757                         ut_params->op);
10758         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10759                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10760                                 ut_params->op, 0, 1, 0, 0);
10761         else
10762                 TEST_ASSERT_NOT_NULL(
10763                         process_crypto_request(ts_params->valid_devs[0],
10764                                 ut_params->op),
10765                                 "failed to process sym crypto op");
10766
10767         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10768                         "HMAC_MD5 crypto op processing failed");
10769
10770         return TEST_SUCCESS;
10771 }
10772
10773 static int
10774 test_MD5_HMAC_generate_case_1(void)
10775 {
10776         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
10777 }
10778
10779 static int
10780 test_MD5_HMAC_verify_case_1(void)
10781 {
10782         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
10783 }
10784
10785 static int
10786 test_MD5_HMAC_generate_case_2(void)
10787 {
10788         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
10789 }
10790
10791 static int
10792 test_MD5_HMAC_verify_case_2(void)
10793 {
10794         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
10795 }
10796
10797 static int
10798 test_multi_session(void)
10799 {
10800         struct crypto_testsuite_params *ts_params = &testsuite_params;
10801         struct crypto_unittest_params *ut_params = &unittest_params;
10802
10803         struct rte_cryptodev_info dev_info;
10804         struct rte_cryptodev_sym_session **sessions;
10805
10806         uint16_t i;
10807
10808         /* Verify the capabilities */
10809         struct rte_cryptodev_sym_capability_idx cap_idx;
10810         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10811         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10812         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10813                         &cap_idx) == NULL)
10814                 return TEST_SKIPPED;
10815         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10816         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10817         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10818                         &cap_idx) == NULL)
10819                 return TEST_SKIPPED;
10820
10821         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
10822                         aes_cbc_key, hmac_sha512_key);
10823
10824
10825         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10826
10827         sessions = rte_malloc(NULL,
10828                         (sizeof(struct rte_cryptodev_sym_session *) *
10829                         MAX_NB_SESSIONS) + 1, 0);
10830
10831         /* Create multiple crypto sessions*/
10832         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10833
10834                 sessions[i] = rte_cryptodev_sym_session_create(
10835                                 ts_params->session_mpool);
10836
10837                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10838                                 sessions[i], &ut_params->auth_xform,
10839                                 ts_params->session_priv_mpool);
10840                 TEST_ASSERT_NOT_NULL(sessions[i],
10841                                 "Session creation failed at session number %u",
10842                                 i);
10843
10844                 /* Attempt to send a request on each session */
10845                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
10846                         sessions[i],
10847                         ut_params,
10848                         ts_params,
10849                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
10850                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
10851                         aes_cbc_iv),
10852                         "Failed to perform decrypt on request number %u.", i);
10853                 /* free crypto operation structure */
10854                 if (ut_params->op)
10855                         rte_crypto_op_free(ut_params->op);
10856
10857                 /*
10858                  * free mbuf - both obuf and ibuf are usually the same,
10859                  * so check if they point at the same address is necessary,
10860                  * to avoid freeing the mbuf twice.
10861                  */
10862                 if (ut_params->obuf) {
10863                         rte_pktmbuf_free(ut_params->obuf);
10864                         if (ut_params->ibuf == ut_params->obuf)
10865                                 ut_params->ibuf = 0;
10866                         ut_params->obuf = 0;
10867                 }
10868                 if (ut_params->ibuf) {
10869                         rte_pktmbuf_free(ut_params->ibuf);
10870                         ut_params->ibuf = 0;
10871                 }
10872         }
10873
10874         /* Next session create should fail */
10875         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10876                         sessions[i], &ut_params->auth_xform,
10877                         ts_params->session_priv_mpool);
10878         TEST_ASSERT_NULL(sessions[i],
10879                         "Session creation succeeded unexpectedly!");
10880
10881         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10882                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10883                                 sessions[i]);
10884                 rte_cryptodev_sym_session_free(sessions[i]);
10885         }
10886
10887         rte_free(sessions);
10888
10889         return TEST_SUCCESS;
10890 }
10891
10892 struct multi_session_params {
10893         struct crypto_unittest_params ut_params;
10894         uint8_t *cipher_key;
10895         uint8_t *hmac_key;
10896         const uint8_t *cipher;
10897         const uint8_t *digest;
10898         uint8_t *iv;
10899 };
10900
10901 #define MB_SESSION_NUMBER 3
10902
10903 static int
10904 test_multi_session_random_usage(void)
10905 {
10906         struct crypto_testsuite_params *ts_params = &testsuite_params;
10907         struct rte_cryptodev_info dev_info;
10908         struct rte_cryptodev_sym_session **sessions;
10909         uint32_t i, j;
10910         struct multi_session_params ut_paramz[] = {
10911
10912                 {
10913                         .cipher_key = ms_aes_cbc_key0,
10914                         .hmac_key = ms_hmac_key0,
10915                         .cipher = ms_aes_cbc_cipher0,
10916                         .digest = ms_hmac_digest0,
10917                         .iv = ms_aes_cbc_iv0
10918                 },
10919                 {
10920                         .cipher_key = ms_aes_cbc_key1,
10921                         .hmac_key = ms_hmac_key1,
10922                         .cipher = ms_aes_cbc_cipher1,
10923                         .digest = ms_hmac_digest1,
10924                         .iv = ms_aes_cbc_iv1
10925                 },
10926                 {
10927                         .cipher_key = ms_aes_cbc_key2,
10928                         .hmac_key = ms_hmac_key2,
10929                         .cipher = ms_aes_cbc_cipher2,
10930                         .digest = ms_hmac_digest2,
10931                         .iv = ms_aes_cbc_iv2
10932                 },
10933
10934         };
10935
10936         /* Verify the capabilities */
10937         struct rte_cryptodev_sym_capability_idx cap_idx;
10938         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10939         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10940         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10941                         &cap_idx) == NULL)
10942                 return TEST_SKIPPED;
10943         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10944         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10945         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10946                         &cap_idx) == NULL)
10947                 return TEST_SKIPPED;
10948
10949         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10950
10951         sessions = rte_malloc(NULL,
10952                         (sizeof(struct rte_cryptodev_sym_session *)
10953                                         * MAX_NB_SESSIONS) + 1, 0);
10954
10955         for (i = 0; i < MB_SESSION_NUMBER; i++) {
10956                 sessions[i] = rte_cryptodev_sym_session_create(
10957                                 ts_params->session_mpool);
10958
10959                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
10960                                 sizeof(struct crypto_unittest_params));
10961
10962                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
10963                                 &ut_paramz[i].ut_params,
10964                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
10965
10966                 /* Create multiple crypto sessions*/
10967                 rte_cryptodev_sym_session_init(
10968                                 ts_params->valid_devs[0],
10969                                 sessions[i],
10970                                 &ut_paramz[i].ut_params.auth_xform,
10971                                 ts_params->session_priv_mpool);
10972
10973                 TEST_ASSERT_NOT_NULL(sessions[i],
10974                                 "Session creation failed at session number %u",
10975                                 i);
10976
10977         }
10978
10979         srand(time(NULL));
10980         for (i = 0; i < 40000; i++) {
10981
10982                 j = rand() % MB_SESSION_NUMBER;
10983
10984                 TEST_ASSERT_SUCCESS(
10985                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
10986                                         sessions[j],
10987                                         &ut_paramz[j].ut_params,
10988                                         ts_params, ut_paramz[j].cipher,
10989                                         ut_paramz[j].digest,
10990                                         ut_paramz[j].iv),
10991                         "Failed to perform decrypt on request number %u.", i);
10992
10993                 if (ut_paramz[j].ut_params.op)
10994                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
10995
10996                 /*
10997                  * free mbuf - both obuf and ibuf are usually the same,
10998                  * so check if they point at the same address is necessary,
10999                  * to avoid freeing the mbuf twice.
11000                  */
11001                 if (ut_paramz[j].ut_params.obuf) {
11002                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
11003                         if (ut_paramz[j].ut_params.ibuf
11004                                         == ut_paramz[j].ut_params.obuf)
11005                                 ut_paramz[j].ut_params.ibuf = 0;
11006                         ut_paramz[j].ut_params.obuf = 0;
11007                 }
11008                 if (ut_paramz[j].ut_params.ibuf) {
11009                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
11010                         ut_paramz[j].ut_params.ibuf = 0;
11011                 }
11012         }
11013
11014         for (i = 0; i < MB_SESSION_NUMBER; i++) {
11015                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11016                                 sessions[i]);
11017                 rte_cryptodev_sym_session_free(sessions[i]);
11018         }
11019
11020         rte_free(sessions);
11021
11022         return TEST_SUCCESS;
11023 }
11024
11025 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
11026                         0xab, 0xab, 0xab, 0xab,
11027                         0xab, 0xab, 0xab, 0xab,
11028                         0xab, 0xab, 0xab, 0xab};
11029
11030 static int
11031 test_null_invalid_operation(void)
11032 {
11033         struct crypto_testsuite_params *ts_params = &testsuite_params;
11034         struct crypto_unittest_params *ut_params = &unittest_params;
11035         int ret;
11036
11037         /* This test is for NULL PMD only */
11038         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11039                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11040                 return TEST_SKIPPED;
11041
11042         /* Setup Cipher Parameters */
11043         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11044         ut_params->cipher_xform.next = NULL;
11045
11046         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
11047         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11048
11049         ut_params->sess = rte_cryptodev_sym_session_create(
11050                         ts_params->session_mpool);
11051
11052         /* Create Crypto session*/
11053         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11054                         ut_params->sess, &ut_params->cipher_xform,
11055                         ts_params->session_priv_mpool);
11056         TEST_ASSERT(ret < 0,
11057                         "Session creation succeeded unexpectedly");
11058
11059
11060         /* Setup HMAC Parameters */
11061         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11062         ut_params->auth_xform.next = NULL;
11063
11064         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
11065         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11066
11067         ut_params->sess = rte_cryptodev_sym_session_create(
11068                         ts_params->session_mpool);
11069
11070         /* Create Crypto session*/
11071         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11072                         ut_params->sess, &ut_params->auth_xform,
11073                         ts_params->session_priv_mpool);
11074         TEST_ASSERT(ret < 0,
11075                         "Session creation succeeded unexpectedly");
11076
11077         return TEST_SUCCESS;
11078 }
11079
11080
11081 #define NULL_BURST_LENGTH (32)
11082
11083 static int
11084 test_null_burst_operation(void)
11085 {
11086         struct crypto_testsuite_params *ts_params = &testsuite_params;
11087         struct crypto_unittest_params *ut_params = &unittest_params;
11088
11089         unsigned i, burst_len = NULL_BURST_LENGTH;
11090
11091         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11092         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11093
11094         /* This test is for NULL PMD only */
11095         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11096                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11097                 return TEST_SKIPPED;
11098
11099         /* Setup Cipher Parameters */
11100         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11101         ut_params->cipher_xform.next = &ut_params->auth_xform;
11102
11103         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11104         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11105
11106         /* Setup HMAC Parameters */
11107         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11108         ut_params->auth_xform.next = NULL;
11109
11110         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11111         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11112
11113         ut_params->sess = rte_cryptodev_sym_session_create(
11114                         ts_params->session_mpool);
11115
11116         /* Create Crypto session*/
11117         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11118                         ut_params->sess, &ut_params->cipher_xform,
11119                         ts_params->session_priv_mpool);
11120         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11121
11122         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11123                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11124                         burst_len, "failed to generate burst of crypto ops");
11125
11126         /* Generate an operation for each mbuf in burst */
11127         for (i = 0; i < burst_len; i++) {
11128                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11129
11130                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11131
11132                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11133                                 sizeof(unsigned));
11134                 *data = i;
11135
11136                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11137
11138                 burst[i]->sym->m_src = m;
11139         }
11140
11141         /* Process crypto operation */
11142         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11143                         0, burst, burst_len),
11144                         burst_len,
11145                         "Error enqueuing burst");
11146
11147         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11148                         0, burst_dequeued, burst_len),
11149                         burst_len,
11150                         "Error dequeuing burst");
11151
11152
11153         for (i = 0; i < burst_len; i++) {
11154                 TEST_ASSERT_EQUAL(
11155                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11156                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11157                                         uint32_t *),
11158                         "data not as expected");
11159
11160                 rte_pktmbuf_free(burst[i]->sym->m_src);
11161                 rte_crypto_op_free(burst[i]);
11162         }
11163
11164         return TEST_SUCCESS;
11165 }
11166
11167 static uint16_t
11168 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11169                   uint16_t nb_ops, void *user_param)
11170 {
11171         RTE_SET_USED(dev_id);
11172         RTE_SET_USED(qp_id);
11173         RTE_SET_USED(ops);
11174         RTE_SET_USED(user_param);
11175
11176         printf("crypto enqueue callback called\n");
11177         return nb_ops;
11178 }
11179
11180 static uint16_t
11181 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11182                   uint16_t nb_ops, void *user_param)
11183 {
11184         RTE_SET_USED(dev_id);
11185         RTE_SET_USED(qp_id);
11186         RTE_SET_USED(ops);
11187         RTE_SET_USED(user_param);
11188
11189         printf("crypto dequeue callback called\n");
11190         return nb_ops;
11191 }
11192
11193 /*
11194  * Thread using enqueue/dequeue callback with RCU.
11195  */
11196 static int
11197 test_enqdeq_callback_thread(void *arg)
11198 {
11199         RTE_SET_USED(arg);
11200         /* DP thread calls rte_cryptodev_enqueue_burst()/
11201          * rte_cryptodev_dequeue_burst() and invokes callback.
11202          */
11203         test_null_burst_operation();
11204         return 0;
11205 }
11206
11207 static int
11208 test_enq_callback_setup(void)
11209 {
11210         struct crypto_testsuite_params *ts_params = &testsuite_params;
11211         struct rte_cryptodev_info dev_info;
11212         struct rte_cryptodev_qp_conf qp_conf = {
11213                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11214         };
11215
11216         struct rte_cryptodev_cb *cb;
11217         uint16_t qp_id = 0;
11218
11219         /* Stop the device in case it's started so it can be configured */
11220         rte_cryptodev_stop(ts_params->valid_devs[0]);
11221
11222         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11223
11224         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11225                         &ts_params->conf),
11226                         "Failed to configure cryptodev %u",
11227                         ts_params->valid_devs[0]);
11228
11229         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11230         qp_conf.mp_session = ts_params->session_mpool;
11231         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11232
11233         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11234                         ts_params->valid_devs[0], qp_id, &qp_conf,
11235                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11236                         "Failed test for "
11237                         "rte_cryptodev_queue_pair_setup: num_inflights "
11238                         "%u on qp %u on cryptodev %u",
11239                         qp_conf.nb_descriptors, qp_id,
11240                         ts_params->valid_devs[0]);
11241
11242         /* Test with invalid crypto device */
11243         cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11244                         qp_id, test_enq_callback, NULL);
11245         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11246                         "cryptodev %u did not fail",
11247                         qp_id, RTE_CRYPTO_MAX_DEVS);
11248
11249         /* Test with invalid queue pair */
11250         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11251                         dev_info.max_nb_queue_pairs + 1,
11252                         test_enq_callback, NULL);
11253         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11254                         "cryptodev %u did not fail",
11255                         dev_info.max_nb_queue_pairs + 1,
11256                         ts_params->valid_devs[0]);
11257
11258         /* Test with NULL callback */
11259         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11260                         qp_id, NULL, NULL);
11261         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11262                         "cryptodev %u did not fail",
11263                         qp_id, ts_params->valid_devs[0]);
11264
11265         /* Test with valid configuration */
11266         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11267                         qp_id, test_enq_callback, NULL);
11268         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11269                         "qp %u on cryptodev %u",
11270                         qp_id, ts_params->valid_devs[0]);
11271
11272         rte_cryptodev_start(ts_params->valid_devs[0]);
11273
11274         /* Launch a thread */
11275         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11276                                 rte_get_next_lcore(-1, 1, 0));
11277
11278         /* Wait until reader exited. */
11279         rte_eal_mp_wait_lcore();
11280
11281         /* Test with invalid crypto device */
11282         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11283                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11284                         "Expected call to fail as crypto device is invalid");
11285
11286         /* Test with invalid queue pair */
11287         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11288                         ts_params->valid_devs[0],
11289                         dev_info.max_nb_queue_pairs + 1, cb),
11290                         "Expected call to fail as queue pair is invalid");
11291
11292         /* Test with NULL callback */
11293         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11294                         ts_params->valid_devs[0], qp_id, NULL),
11295                         "Expected call to fail as callback is NULL");
11296
11297         /* Test with valid configuration */
11298         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11299                         ts_params->valid_devs[0], qp_id, cb),
11300                         "Failed test to remove callback on "
11301                         "qp %u on cryptodev %u",
11302                         qp_id, ts_params->valid_devs[0]);
11303
11304         return TEST_SUCCESS;
11305 }
11306
11307 static int
11308 test_deq_callback_setup(void)
11309 {
11310         struct crypto_testsuite_params *ts_params = &testsuite_params;
11311         struct rte_cryptodev_info dev_info;
11312         struct rte_cryptodev_qp_conf qp_conf = {
11313                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11314         };
11315
11316         struct rte_cryptodev_cb *cb;
11317         uint16_t qp_id = 0;
11318
11319         /* Stop the device in case it's started so it can be configured */
11320         rte_cryptodev_stop(ts_params->valid_devs[0]);
11321
11322         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11323
11324         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11325                         &ts_params->conf),
11326                         "Failed to configure cryptodev %u",
11327                         ts_params->valid_devs[0]);
11328
11329         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11330         qp_conf.mp_session = ts_params->session_mpool;
11331         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11332
11333         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11334                         ts_params->valid_devs[0], qp_id, &qp_conf,
11335                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11336                         "Failed test for "
11337                         "rte_cryptodev_queue_pair_setup: num_inflights "
11338                         "%u on qp %u on cryptodev %u",
11339                         qp_conf.nb_descriptors, qp_id,
11340                         ts_params->valid_devs[0]);
11341
11342         /* Test with invalid crypto device */
11343         cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11344                         qp_id, test_deq_callback, NULL);
11345         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11346                         "cryptodev %u did not fail",
11347                         qp_id, RTE_CRYPTO_MAX_DEVS);
11348
11349         /* Test with invalid queue pair */
11350         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11351                         dev_info.max_nb_queue_pairs + 1,
11352                         test_deq_callback, NULL);
11353         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11354                         "cryptodev %u did not fail",
11355                         dev_info.max_nb_queue_pairs + 1,
11356                         ts_params->valid_devs[0]);
11357
11358         /* Test with NULL callback */
11359         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11360                         qp_id, NULL, NULL);
11361         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11362                         "cryptodev %u did not fail",
11363                         qp_id, ts_params->valid_devs[0]);
11364
11365         /* Test with valid configuration */
11366         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11367                         qp_id, test_deq_callback, NULL);
11368         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11369                         "qp %u on cryptodev %u",
11370                         qp_id, ts_params->valid_devs[0]);
11371
11372         rte_cryptodev_start(ts_params->valid_devs[0]);
11373
11374         /* Launch a thread */
11375         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11376                                 rte_get_next_lcore(-1, 1, 0));
11377
11378         /* Wait until reader exited. */
11379         rte_eal_mp_wait_lcore();
11380
11381         /* Test with invalid crypto device */
11382         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11383                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11384                         "Expected call to fail as crypto device is invalid");
11385
11386         /* Test with invalid queue pair */
11387         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11388                         ts_params->valid_devs[0],
11389                         dev_info.max_nb_queue_pairs + 1, cb),
11390                         "Expected call to fail as queue pair is invalid");
11391
11392         /* Test with NULL callback */
11393         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11394                         ts_params->valid_devs[0], qp_id, NULL),
11395                         "Expected call to fail as callback is NULL");
11396
11397         /* Test with valid configuration */
11398         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
11399                         ts_params->valid_devs[0], qp_id, cb),
11400                         "Failed test to remove callback on "
11401                         "qp %u on cryptodev %u",
11402                         qp_id, ts_params->valid_devs[0]);
11403
11404         return TEST_SUCCESS;
11405 }
11406
11407 static void
11408 generate_gmac_large_plaintext(uint8_t *data)
11409 {
11410         uint16_t i;
11411
11412         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
11413                 memcpy(&data[i], &data[0], 32);
11414 }
11415
11416 static int
11417 create_gmac_operation(enum rte_crypto_auth_operation op,
11418                 const struct gmac_test_data *tdata)
11419 {
11420         struct crypto_testsuite_params *ts_params = &testsuite_params;
11421         struct crypto_unittest_params *ut_params = &unittest_params;
11422         struct rte_crypto_sym_op *sym_op;
11423
11424         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11425
11426         /* Generate Crypto op data structure */
11427         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11428                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11429         TEST_ASSERT_NOT_NULL(ut_params->op,
11430                         "Failed to allocate symmetric crypto operation struct");
11431
11432         sym_op = ut_params->op->sym;
11433
11434         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11435                         ut_params->ibuf, tdata->gmac_tag.len);
11436         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11437                         "no room to append digest");
11438
11439         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11440                         ut_params->ibuf, plaintext_pad_len);
11441
11442         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11443                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11444                                 tdata->gmac_tag.len);
11445                 debug_hexdump(stdout, "digest:",
11446                                 sym_op->auth.digest.data,
11447                                 tdata->gmac_tag.len);
11448         }
11449
11450         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11451                         uint8_t *, IV_OFFSET);
11452
11453         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11454
11455         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11456
11457         sym_op->cipher.data.length = 0;
11458         sym_op->cipher.data.offset = 0;
11459
11460         sym_op->auth.data.offset = 0;
11461         sym_op->auth.data.length = tdata->plaintext.len;
11462
11463         return 0;
11464 }
11465
11466 static int
11467 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
11468                 const struct gmac_test_data *tdata,
11469                 void *digest_mem, uint64_t digest_phys)
11470 {
11471         struct crypto_testsuite_params *ts_params = &testsuite_params;
11472         struct crypto_unittest_params *ut_params = &unittest_params;
11473         struct rte_crypto_sym_op *sym_op;
11474
11475         /* Generate Crypto op data structure */
11476         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11477                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11478         TEST_ASSERT_NOT_NULL(ut_params->op,
11479                         "Failed to allocate symmetric crypto operation struct");
11480
11481         sym_op = ut_params->op->sym;
11482
11483         sym_op->auth.digest.data = digest_mem;
11484         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11485                         "no room to append digest");
11486
11487         sym_op->auth.digest.phys_addr = digest_phys;
11488
11489         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11490                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11491                                 tdata->gmac_tag.len);
11492                 debug_hexdump(stdout, "digest:",
11493                                 sym_op->auth.digest.data,
11494                                 tdata->gmac_tag.len);
11495         }
11496
11497         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11498                         uint8_t *, IV_OFFSET);
11499
11500         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11501
11502         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11503
11504         sym_op->cipher.data.length = 0;
11505         sym_op->cipher.data.offset = 0;
11506
11507         sym_op->auth.data.offset = 0;
11508         sym_op->auth.data.length = tdata->plaintext.len;
11509
11510         return 0;
11511 }
11512
11513 static int create_gmac_session(uint8_t dev_id,
11514                 const struct gmac_test_data *tdata,
11515                 enum rte_crypto_auth_operation auth_op)
11516 {
11517         uint8_t auth_key[tdata->key.len];
11518
11519         struct crypto_testsuite_params *ts_params = &testsuite_params;
11520         struct crypto_unittest_params *ut_params = &unittest_params;
11521
11522         memcpy(auth_key, tdata->key.data, tdata->key.len);
11523
11524         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11525         ut_params->auth_xform.next = NULL;
11526
11527         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
11528         ut_params->auth_xform.auth.op = auth_op;
11529         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
11530         ut_params->auth_xform.auth.key.length = tdata->key.len;
11531         ut_params->auth_xform.auth.key.data = auth_key;
11532         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11533         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
11534
11535
11536         ut_params->sess = rte_cryptodev_sym_session_create(
11537                         ts_params->session_mpool);
11538
11539         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11540                         &ut_params->auth_xform,
11541                         ts_params->session_priv_mpool);
11542
11543         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11544
11545         return 0;
11546 }
11547
11548 static int
11549 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
11550 {
11551         struct crypto_testsuite_params *ts_params = &testsuite_params;
11552         struct crypto_unittest_params *ut_params = &unittest_params;
11553         struct rte_cryptodev_info dev_info;
11554
11555         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11556         uint64_t feat_flags = dev_info.feature_flags;
11557
11558         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11559                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11560                 printf("Device doesn't support RAW data-path APIs.\n");
11561                 return TEST_SKIPPED;
11562         }
11563
11564         int retval;
11565
11566         uint8_t *auth_tag, *plaintext;
11567         uint16_t plaintext_pad_len;
11568
11569         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11570                               "No GMAC length in the source data");
11571
11572         /* Verify the capabilities */
11573         struct rte_cryptodev_sym_capability_idx cap_idx;
11574         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11575         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11576         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11577                         &cap_idx) == NULL)
11578                 return TEST_SKIPPED;
11579
11580         retval = create_gmac_session(ts_params->valid_devs[0],
11581                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11582
11583         if (retval < 0)
11584                 return retval;
11585
11586         if (tdata->plaintext.len > MBUF_SIZE)
11587                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11588         else
11589                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11590         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11591                         "Failed to allocate input buffer in mempool");
11592
11593         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11594                         rte_pktmbuf_tailroom(ut_params->ibuf));
11595
11596         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11597         /*
11598          * Runtime generate the large plain text instead of use hard code
11599          * plain text vector. It is done to avoid create huge source file
11600          * with the test vector.
11601          */
11602         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11603                 generate_gmac_large_plaintext(tdata->plaintext.data);
11604
11605         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11606                                 plaintext_pad_len);
11607         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11608
11609         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11610         debug_hexdump(stdout, "plaintext:", plaintext,
11611                         tdata->plaintext.len);
11612
11613         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
11614                         tdata);
11615
11616         if (retval < 0)
11617                 return retval;
11618
11619         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11620
11621         ut_params->op->sym->m_src = ut_params->ibuf;
11622
11623         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11624                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11625                         ut_params->op);
11626         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11627                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11628                                 ut_params->op, 0, 1, 0, 0);
11629         else
11630                 TEST_ASSERT_NOT_NULL(
11631                         process_crypto_request(ts_params->valid_devs[0],
11632                         ut_params->op), "failed to process sym crypto op");
11633
11634         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11635                         "crypto op processing failed");
11636
11637         if (ut_params->op->sym->m_dst) {
11638                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11639                                 uint8_t *, plaintext_pad_len);
11640         } else {
11641                 auth_tag = plaintext + plaintext_pad_len;
11642         }
11643
11644         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11645
11646         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11647                         auth_tag,
11648                         tdata->gmac_tag.data,
11649                         tdata->gmac_tag.len,
11650                         "GMAC Generated auth tag not as expected");
11651
11652         return 0;
11653 }
11654
11655 static int
11656 test_AES_GMAC_authentication_test_case_1(void)
11657 {
11658         return test_AES_GMAC_authentication(&gmac_test_case_1);
11659 }
11660
11661 static int
11662 test_AES_GMAC_authentication_test_case_2(void)
11663 {
11664         return test_AES_GMAC_authentication(&gmac_test_case_2);
11665 }
11666
11667 static int
11668 test_AES_GMAC_authentication_test_case_3(void)
11669 {
11670         return test_AES_GMAC_authentication(&gmac_test_case_3);
11671 }
11672
11673 static int
11674 test_AES_GMAC_authentication_test_case_4(void)
11675 {
11676         return test_AES_GMAC_authentication(&gmac_test_case_4);
11677 }
11678
11679 static int
11680 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
11681 {
11682         struct crypto_testsuite_params *ts_params = &testsuite_params;
11683         struct crypto_unittest_params *ut_params = &unittest_params;
11684         int retval;
11685         uint32_t plaintext_pad_len;
11686         uint8_t *plaintext;
11687         struct rte_cryptodev_info dev_info;
11688
11689         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11690         uint64_t feat_flags = dev_info.feature_flags;
11691
11692         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11693                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11694                 printf("Device doesn't support RAW data-path APIs.\n");
11695                 return TEST_SKIPPED;
11696         }
11697
11698         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11699                               "No GMAC length in the source data");
11700
11701         /* Verify the capabilities */
11702         struct rte_cryptodev_sym_capability_idx cap_idx;
11703         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11704         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11705         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11706                         &cap_idx) == NULL)
11707                 return TEST_SKIPPED;
11708
11709         retval = create_gmac_session(ts_params->valid_devs[0],
11710                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
11711
11712         if (retval < 0)
11713                 return retval;
11714
11715         if (tdata->plaintext.len > MBUF_SIZE)
11716                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11717         else
11718                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11719         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11720                         "Failed to allocate input buffer in mempool");
11721
11722         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11723                         rte_pktmbuf_tailroom(ut_params->ibuf));
11724
11725         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11726
11727         /*
11728          * Runtime generate the large plain text instead of use hard code
11729          * plain text vector. It is done to avoid create huge source file
11730          * with the test vector.
11731          */
11732         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11733                 generate_gmac_large_plaintext(tdata->plaintext.data);
11734
11735         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11736                                 plaintext_pad_len);
11737         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11738
11739         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11740         debug_hexdump(stdout, "plaintext:", plaintext,
11741                         tdata->plaintext.len);
11742
11743         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
11744                         tdata);
11745
11746         if (retval < 0)
11747                 return retval;
11748
11749         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11750
11751         ut_params->op->sym->m_src = ut_params->ibuf;
11752
11753         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11754                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11755                         ut_params->op);
11756         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11757                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11758                                 ut_params->op, 0, 1, 0, 0);
11759         else
11760                 TEST_ASSERT_NOT_NULL(
11761                         process_crypto_request(ts_params->valid_devs[0],
11762                         ut_params->op), "failed to process sym crypto op");
11763
11764         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11765                         "crypto op processing failed");
11766
11767         return 0;
11768
11769 }
11770
11771 static int
11772 test_AES_GMAC_authentication_verify_test_case_1(void)
11773 {
11774         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
11775 }
11776
11777 static int
11778 test_AES_GMAC_authentication_verify_test_case_2(void)
11779 {
11780         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
11781 }
11782
11783 static int
11784 test_AES_GMAC_authentication_verify_test_case_3(void)
11785 {
11786         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
11787 }
11788
11789 static int
11790 test_AES_GMAC_authentication_verify_test_case_4(void)
11791 {
11792         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
11793 }
11794
11795 static int
11796 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
11797                                 uint32_t fragsz)
11798 {
11799         struct crypto_testsuite_params *ts_params = &testsuite_params;
11800         struct crypto_unittest_params *ut_params = &unittest_params;
11801         struct rte_cryptodev_info dev_info;
11802         uint64_t feature_flags;
11803         unsigned int trn_data = 0;
11804         void *digest_mem = NULL;
11805         uint32_t segs = 1;
11806         unsigned int to_trn = 0;
11807         struct rte_mbuf *buf = NULL;
11808         uint8_t *auth_tag, *plaintext;
11809         int retval;
11810
11811         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11812                               "No GMAC length in the source data");
11813
11814         /* Verify the capabilities */
11815         struct rte_cryptodev_sym_capability_idx cap_idx;
11816         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11817         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11818         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11819                         &cap_idx) == NULL)
11820                 return TEST_SKIPPED;
11821
11822         /* Check for any input SGL support */
11823         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11824         feature_flags = dev_info.feature_flags;
11825
11826         if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
11827                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
11828                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
11829                 return TEST_SKIPPED;
11830
11831         if (fragsz > tdata->plaintext.len)
11832                 fragsz = tdata->plaintext.len;
11833
11834         uint16_t plaintext_len = fragsz;
11835
11836         retval = create_gmac_session(ts_params->valid_devs[0],
11837                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11838
11839         if (retval < 0)
11840                 return retval;
11841
11842         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11843         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11844                         "Failed to allocate input buffer in mempool");
11845
11846         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11847                         rte_pktmbuf_tailroom(ut_params->ibuf));
11848
11849         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11850                                 plaintext_len);
11851         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11852
11853         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
11854
11855         trn_data += plaintext_len;
11856
11857         buf = ut_params->ibuf;
11858
11859         /*
11860          * Loop until no more fragments
11861          */
11862
11863         while (trn_data < tdata->plaintext.len) {
11864                 ++segs;
11865                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
11866                                 (tdata->plaintext.len - trn_data) : fragsz;
11867
11868                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11869                 buf = buf->next;
11870
11871                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
11872                                 rte_pktmbuf_tailroom(buf));
11873
11874                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
11875                                 to_trn);
11876
11877                 memcpy(plaintext, tdata->plaintext.data + trn_data,
11878                                 to_trn);
11879                 trn_data += to_trn;
11880                 if (trn_data  == tdata->plaintext.len)
11881                         digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
11882                                         tdata->gmac_tag.len);
11883         }
11884         ut_params->ibuf->nb_segs = segs;
11885
11886         /*
11887          * Place digest at the end of the last buffer
11888          */
11889         uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11890
11891         if (!digest_mem) {
11892                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11893                                 + tdata->gmac_tag.len);
11894                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11895                                 tdata->plaintext.len);
11896         }
11897
11898         retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
11899                         tdata, digest_mem, digest_phys);
11900
11901         if (retval < 0)
11902                 return retval;
11903
11904         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11905
11906         ut_params->op->sym->m_src = ut_params->ibuf;
11907
11908         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11909                 return TEST_SKIPPED;
11910
11911         TEST_ASSERT_NOT_NULL(
11912                 process_crypto_request(ts_params->valid_devs[0],
11913                 ut_params->op), "failed to process sym crypto op");
11914
11915         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11916                         "crypto op processing failed");
11917
11918         auth_tag = digest_mem;
11919         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11920         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11921                         auth_tag,
11922                         tdata->gmac_tag.data,
11923                         tdata->gmac_tag.len,
11924                         "GMAC Generated auth tag not as expected");
11925
11926         return 0;
11927 }
11928
11929 /* Segment size not multiple of block size (16B) */
11930 static int
11931 test_AES_GMAC_authentication_SGL_40B(void)
11932 {
11933         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
11934 }
11935
11936 static int
11937 test_AES_GMAC_authentication_SGL_80B(void)
11938 {
11939         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
11940 }
11941
11942 static int
11943 test_AES_GMAC_authentication_SGL_2048B(void)
11944 {
11945         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
11946 }
11947
11948 /* Segment size not multiple of block size (16B) */
11949 static int
11950 test_AES_GMAC_authentication_SGL_2047B(void)
11951 {
11952         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
11953 }
11954
11955 struct test_crypto_vector {
11956         enum rte_crypto_cipher_algorithm crypto_algo;
11957         unsigned int cipher_offset;
11958         unsigned int cipher_len;
11959
11960         struct {
11961                 uint8_t data[64];
11962                 unsigned int len;
11963         } cipher_key;
11964
11965         struct {
11966                 uint8_t data[64];
11967                 unsigned int len;
11968         } iv;
11969
11970         struct {
11971                 const uint8_t *data;
11972                 unsigned int len;
11973         } plaintext;
11974
11975         struct {
11976                 const uint8_t *data;
11977                 unsigned int len;
11978         } ciphertext;
11979
11980         enum rte_crypto_auth_algorithm auth_algo;
11981         unsigned int auth_offset;
11982
11983         struct {
11984                 uint8_t data[128];
11985                 unsigned int len;
11986         } auth_key;
11987
11988         struct {
11989                 const uint8_t *data;
11990                 unsigned int len;
11991         } aad;
11992
11993         struct {
11994                 uint8_t data[128];
11995                 unsigned int len;
11996         } digest;
11997 };
11998
11999 static const struct test_crypto_vector
12000 hmac_sha1_test_crypto_vector = {
12001         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12002         .plaintext = {
12003                 .data = plaintext_hash,
12004                 .len = 512
12005         },
12006         .auth_key = {
12007                 .data = {
12008                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12009                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12010                         0xDE, 0xF4, 0xDE, 0xAD
12011                 },
12012                 .len = 20
12013         },
12014         .digest = {
12015                 .data = {
12016                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
12017                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
12018                         0x3F, 0x91, 0x64, 0x59
12019                 },
12020                 .len = 20
12021         }
12022 };
12023
12024 static const struct test_crypto_vector
12025 aes128_gmac_test_vector = {
12026         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
12027         .plaintext = {
12028                 .data = plaintext_hash,
12029                 .len = 512
12030         },
12031         .iv = {
12032                 .data = {
12033                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12034                         0x08, 0x09, 0x0A, 0x0B
12035                 },
12036                 .len = 12
12037         },
12038         .auth_key = {
12039                 .data = {
12040                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12041                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
12042                 },
12043                 .len = 16
12044         },
12045         .digest = {
12046                 .data = {
12047                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
12048                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
12049                 },
12050                 .len = 16
12051         }
12052 };
12053
12054 static const struct test_crypto_vector
12055 aes128cbc_hmac_sha1_test_vector = {
12056         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12057         .cipher_offset = 0,
12058         .cipher_len = 512,
12059         .cipher_key = {
12060                 .data = {
12061                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12062                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12063                 },
12064                 .len = 16
12065         },
12066         .iv = {
12067                 .data = {
12068                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12069                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12070                 },
12071                 .len = 16
12072         },
12073         .plaintext = {
12074                 .data = plaintext_hash,
12075                 .len = 512
12076         },
12077         .ciphertext = {
12078                 .data = ciphertext512_aes128cbc,
12079                 .len = 512
12080         },
12081         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12082         .auth_offset = 0,
12083         .auth_key = {
12084                 .data = {
12085                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12086                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12087                         0xDE, 0xF4, 0xDE, 0xAD
12088                 },
12089                 .len = 20
12090         },
12091         .digest = {
12092                 .data = {
12093                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12094                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12095                         0x18, 0x8C, 0x1D, 0x32
12096                 },
12097                 .len = 20
12098         }
12099 };
12100
12101 static const struct test_crypto_vector
12102 aes128cbc_hmac_sha1_aad_test_vector = {
12103         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12104         .cipher_offset = 8,
12105         .cipher_len = 496,
12106         .cipher_key = {
12107                 .data = {
12108                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12109                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12110                 },
12111                 .len = 16
12112         },
12113         .iv = {
12114                 .data = {
12115                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12116                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12117                 },
12118                 .len = 16
12119         },
12120         .plaintext = {
12121                 .data = plaintext_hash,
12122                 .len = 512
12123         },
12124         .ciphertext = {
12125                 .data = ciphertext512_aes128cbc_aad,
12126                 .len = 512
12127         },
12128         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12129         .auth_offset = 0,
12130         .auth_key = {
12131                 .data = {
12132                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12133                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12134                         0xDE, 0xF4, 0xDE, 0xAD
12135                 },
12136                 .len = 20
12137         },
12138         .digest = {
12139                 .data = {
12140                         0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12141                         0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12142                         0x62, 0x0F, 0xFB, 0x10
12143                 },
12144                 .len = 20
12145         }
12146 };
12147
12148 static void
12149 data_corruption(uint8_t *data)
12150 {
12151         data[0] += 1;
12152 }
12153
12154 static void
12155 tag_corruption(uint8_t *data, unsigned int tag_offset)
12156 {
12157         data[tag_offset] += 1;
12158 }
12159
12160 static int
12161 create_auth_session(struct crypto_unittest_params *ut_params,
12162                 uint8_t dev_id,
12163                 const struct test_crypto_vector *reference,
12164                 enum rte_crypto_auth_operation auth_op)
12165 {
12166         struct crypto_testsuite_params *ts_params = &testsuite_params;
12167         uint8_t auth_key[reference->auth_key.len + 1];
12168
12169         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12170
12171         /* Setup Authentication Parameters */
12172         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12173         ut_params->auth_xform.auth.op = auth_op;
12174         ut_params->auth_xform.next = NULL;
12175         ut_params->auth_xform.auth.algo = reference->auth_algo;
12176         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12177         ut_params->auth_xform.auth.key.data = auth_key;
12178         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12179
12180         /* Create Crypto session*/
12181         ut_params->sess = rte_cryptodev_sym_session_create(
12182                         ts_params->session_mpool);
12183
12184         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12185                                 &ut_params->auth_xform,
12186                                 ts_params->session_priv_mpool);
12187
12188         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12189
12190         return 0;
12191 }
12192
12193 static int
12194 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12195                 uint8_t dev_id,
12196                 const struct test_crypto_vector *reference,
12197                 enum rte_crypto_auth_operation auth_op,
12198                 enum rte_crypto_cipher_operation cipher_op)
12199 {
12200         struct crypto_testsuite_params *ts_params = &testsuite_params;
12201         uint8_t cipher_key[reference->cipher_key.len + 1];
12202         uint8_t auth_key[reference->auth_key.len + 1];
12203
12204         memcpy(cipher_key, reference->cipher_key.data,
12205                         reference->cipher_key.len);
12206         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12207
12208         /* Setup Authentication Parameters */
12209         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12210         ut_params->auth_xform.auth.op = auth_op;
12211         ut_params->auth_xform.auth.algo = reference->auth_algo;
12212         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12213         ut_params->auth_xform.auth.key.data = auth_key;
12214         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12215
12216         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12217                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12218                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
12219         } else {
12220                 ut_params->auth_xform.next = &ut_params->cipher_xform;
12221
12222                 /* Setup Cipher Parameters */
12223                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12224                 ut_params->cipher_xform.next = NULL;
12225                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12226                 ut_params->cipher_xform.cipher.op = cipher_op;
12227                 ut_params->cipher_xform.cipher.key.data = cipher_key;
12228                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12229                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12230                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12231         }
12232
12233         /* Create Crypto session*/
12234         ut_params->sess = rte_cryptodev_sym_session_create(
12235                         ts_params->session_mpool);
12236
12237         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12238                                 &ut_params->auth_xform,
12239                                 ts_params->session_priv_mpool);
12240
12241         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12242
12243         return 0;
12244 }
12245
12246 static int
12247 create_auth_operation(struct crypto_testsuite_params *ts_params,
12248                 struct crypto_unittest_params *ut_params,
12249                 const struct test_crypto_vector *reference,
12250                 unsigned int auth_generate)
12251 {
12252         /* Generate Crypto op data structure */
12253         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12254                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12255         TEST_ASSERT_NOT_NULL(ut_params->op,
12256                         "Failed to allocate pktmbuf offload");
12257
12258         /* Set crypto operation data parameters */
12259         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12260
12261         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12262
12263         /* set crypto operation source mbuf */
12264         sym_op->m_src = ut_params->ibuf;
12265
12266         /* digest */
12267         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12268                         ut_params->ibuf, reference->digest.len);
12269
12270         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12271                         "no room to append auth tag");
12272
12273         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12274                         ut_params->ibuf, reference->plaintext.len);
12275
12276         if (auth_generate)
12277                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12278         else
12279                 memcpy(sym_op->auth.digest.data,
12280                                 reference->digest.data,
12281                                 reference->digest.len);
12282
12283         debug_hexdump(stdout, "digest:",
12284                         sym_op->auth.digest.data,
12285                         reference->digest.len);
12286
12287         sym_op->auth.data.length = reference->plaintext.len;
12288         sym_op->auth.data.offset = 0;
12289
12290         return 0;
12291 }
12292
12293 static int
12294 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12295                 struct crypto_unittest_params *ut_params,
12296                 const struct test_crypto_vector *reference,
12297                 unsigned int auth_generate)
12298 {
12299         /* Generate Crypto op data structure */
12300         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12301                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12302         TEST_ASSERT_NOT_NULL(ut_params->op,
12303                         "Failed to allocate pktmbuf offload");
12304
12305         /* Set crypto operation data parameters */
12306         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12307
12308         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12309
12310         /* set crypto operation source mbuf */
12311         sym_op->m_src = ut_params->ibuf;
12312
12313         /* digest */
12314         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12315                         ut_params->ibuf, reference->digest.len);
12316
12317         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12318                         "no room to append auth tag");
12319
12320         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12321                         ut_params->ibuf, reference->ciphertext.len);
12322
12323         if (auth_generate)
12324                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12325         else
12326                 memcpy(sym_op->auth.digest.data,
12327                                 reference->digest.data,
12328                                 reference->digest.len);
12329
12330         debug_hexdump(stdout, "digest:",
12331                         sym_op->auth.digest.data,
12332                         reference->digest.len);
12333
12334         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12335                         reference->iv.data, reference->iv.len);
12336
12337         sym_op->cipher.data.length = 0;
12338         sym_op->cipher.data.offset = 0;
12339
12340         sym_op->auth.data.length = reference->plaintext.len;
12341         sym_op->auth.data.offset = 0;
12342
12343         return 0;
12344 }
12345
12346 static int
12347 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12348                 struct crypto_unittest_params *ut_params,
12349                 const struct test_crypto_vector *reference,
12350                 unsigned int auth_generate)
12351 {
12352         /* Generate Crypto op data structure */
12353         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12354                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12355         TEST_ASSERT_NOT_NULL(ut_params->op,
12356                         "Failed to allocate pktmbuf offload");
12357
12358         /* Set crypto operation data parameters */
12359         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12360
12361         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12362
12363         /* set crypto operation source mbuf */
12364         sym_op->m_src = ut_params->ibuf;
12365
12366         /* digest */
12367         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12368                         ut_params->ibuf, reference->digest.len);
12369
12370         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12371                         "no room to append auth tag");
12372
12373         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12374                         ut_params->ibuf, reference->ciphertext.len);
12375
12376         if (auth_generate)
12377                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12378         else
12379                 memcpy(sym_op->auth.digest.data,
12380                                 reference->digest.data,
12381                                 reference->digest.len);
12382
12383         debug_hexdump(stdout, "digest:",
12384                         sym_op->auth.digest.data,
12385                         reference->digest.len);
12386
12387         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12388                         reference->iv.data, reference->iv.len);
12389
12390         sym_op->cipher.data.length = reference->cipher_len;
12391         sym_op->cipher.data.offset = reference->cipher_offset;
12392
12393         sym_op->auth.data.length = reference->plaintext.len;
12394         sym_op->auth.data.offset = reference->auth_offset;
12395
12396         return 0;
12397 }
12398
12399 static int
12400 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12401                 struct crypto_unittest_params *ut_params,
12402                 const struct test_crypto_vector *reference)
12403 {
12404         return create_auth_operation(ts_params, ut_params, reference, 0);
12405 }
12406
12407 static int
12408 create_auth_verify_GMAC_operation(
12409                 struct crypto_testsuite_params *ts_params,
12410                 struct crypto_unittest_params *ut_params,
12411                 const struct test_crypto_vector *reference)
12412 {
12413         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
12414 }
12415
12416 static int
12417 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12418                 struct crypto_unittest_params *ut_params,
12419                 const struct test_crypto_vector *reference)
12420 {
12421         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12422 }
12423
12424 static int
12425 test_authentication_verify_fail_when_data_corruption(
12426                 struct crypto_testsuite_params *ts_params,
12427                 struct crypto_unittest_params *ut_params,
12428                 const struct test_crypto_vector *reference,
12429                 unsigned int data_corrupted)
12430 {
12431         int retval;
12432
12433         uint8_t *plaintext;
12434         struct rte_cryptodev_info dev_info;
12435
12436         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12437         uint64_t feat_flags = dev_info.feature_flags;
12438
12439         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12440                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12441                 printf("Device doesn't support RAW data-path APIs.\n");
12442                 return TEST_SKIPPED;
12443         }
12444
12445         /* Verify the capabilities */
12446         struct rte_cryptodev_sym_capability_idx cap_idx;
12447         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12448         cap_idx.algo.auth = reference->auth_algo;
12449         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12450                         &cap_idx) == NULL)
12451                 return TEST_SKIPPED;
12452
12453
12454         /* Create session */
12455         retval = create_auth_session(ut_params,
12456                         ts_params->valid_devs[0],
12457                         reference,
12458                         RTE_CRYPTO_AUTH_OP_VERIFY);
12459         if (retval < 0)
12460                 return retval;
12461
12462         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12463         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12464                         "Failed to allocate input buffer in mempool");
12465
12466         /* clear mbuf payload */
12467         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12468                         rte_pktmbuf_tailroom(ut_params->ibuf));
12469
12470         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12471                         reference->plaintext.len);
12472         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12473         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12474
12475         debug_hexdump(stdout, "plaintext:", plaintext,
12476                 reference->plaintext.len);
12477
12478         /* Create operation */
12479         retval = create_auth_verify_operation(ts_params, ut_params, reference);
12480
12481         if (retval < 0)
12482                 return retval;
12483
12484         if (data_corrupted)
12485                 data_corruption(plaintext);
12486         else
12487                 tag_corruption(plaintext, reference->plaintext.len);
12488
12489         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12490                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12491                         ut_params->op);
12492                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12493                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12494                         "authentication not failed");
12495         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12496                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12497                                 ut_params->op, 0, 1, 0, 0);
12498         else {
12499                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12500                         ut_params->op);
12501                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12502         }
12503
12504         return 0;
12505 }
12506
12507 static int
12508 test_authentication_verify_GMAC_fail_when_corruption(
12509                 struct crypto_testsuite_params *ts_params,
12510                 struct crypto_unittest_params *ut_params,
12511                 const struct test_crypto_vector *reference,
12512                 unsigned int data_corrupted)
12513 {
12514         int retval;
12515         uint8_t *plaintext;
12516         struct rte_cryptodev_info dev_info;
12517
12518         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12519         uint64_t feat_flags = dev_info.feature_flags;
12520
12521         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12522                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12523                 printf("Device doesn't support RAW data-path APIs.\n");
12524                 return TEST_SKIPPED;
12525         }
12526
12527         /* Verify the capabilities */
12528         struct rte_cryptodev_sym_capability_idx cap_idx;
12529         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12530         cap_idx.algo.auth = reference->auth_algo;
12531         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12532                         &cap_idx) == NULL)
12533                 return TEST_SKIPPED;
12534
12535         /* Create session */
12536         retval = create_auth_cipher_session(ut_params,
12537                         ts_params->valid_devs[0],
12538                         reference,
12539                         RTE_CRYPTO_AUTH_OP_VERIFY,
12540                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12541         if (retval < 0)
12542                 return retval;
12543
12544         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12545         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12546                         "Failed to allocate input buffer in mempool");
12547
12548         /* clear mbuf payload */
12549         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12550                         rte_pktmbuf_tailroom(ut_params->ibuf));
12551
12552         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12553                         reference->plaintext.len);
12554         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12555         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12556
12557         debug_hexdump(stdout, "plaintext:", plaintext,
12558                 reference->plaintext.len);
12559
12560         /* Create operation */
12561         retval = create_auth_verify_GMAC_operation(ts_params,
12562                         ut_params,
12563                         reference);
12564
12565         if (retval < 0)
12566                 return retval;
12567
12568         if (data_corrupted)
12569                 data_corruption(plaintext);
12570         else
12571                 tag_corruption(plaintext, reference->aad.len);
12572
12573         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12574                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12575                         ut_params->op);
12576                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12577                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12578                         "authentication not failed");
12579         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12580                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12581                                 ut_params->op, 0, 1, 0, 0);
12582         else {
12583                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12584                         ut_params->op);
12585                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12586         }
12587
12588         return 0;
12589 }
12590
12591 static int
12592 test_authenticated_decryption_fail_when_corruption(
12593                 struct crypto_testsuite_params *ts_params,
12594                 struct crypto_unittest_params *ut_params,
12595                 const struct test_crypto_vector *reference,
12596                 unsigned int data_corrupted)
12597 {
12598         int retval;
12599
12600         uint8_t *ciphertext;
12601         struct rte_cryptodev_info dev_info;
12602
12603         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12604         uint64_t feat_flags = dev_info.feature_flags;
12605
12606         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12607                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12608                 printf("Device doesn't support RAW data-path APIs.\n");
12609                 return TEST_SKIPPED;
12610         }
12611
12612         /* Verify the capabilities */
12613         struct rte_cryptodev_sym_capability_idx cap_idx;
12614         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12615         cap_idx.algo.auth = reference->auth_algo;
12616         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12617                         &cap_idx) == NULL)
12618                 return TEST_SKIPPED;
12619         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12620         cap_idx.algo.cipher = reference->crypto_algo;
12621         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12622                         &cap_idx) == NULL)
12623                 return TEST_SKIPPED;
12624
12625         /* Create session */
12626         retval = create_auth_cipher_session(ut_params,
12627                         ts_params->valid_devs[0],
12628                         reference,
12629                         RTE_CRYPTO_AUTH_OP_VERIFY,
12630                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12631         if (retval < 0)
12632                 return retval;
12633
12634         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12635         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12636                         "Failed to allocate input buffer in mempool");
12637
12638         /* clear mbuf payload */
12639         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12640                         rte_pktmbuf_tailroom(ut_params->ibuf));
12641
12642         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12643                         reference->ciphertext.len);
12644         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12645         memcpy(ciphertext, reference->ciphertext.data,
12646                         reference->ciphertext.len);
12647
12648         /* Create operation */
12649         retval = create_cipher_auth_verify_operation(ts_params,
12650                         ut_params,
12651                         reference);
12652
12653         if (retval < 0)
12654                 return retval;
12655
12656         if (data_corrupted)
12657                 data_corruption(ciphertext);
12658         else
12659                 tag_corruption(ciphertext, reference->ciphertext.len);
12660
12661         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12662                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12663                         ut_params->op);
12664                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12665                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12666                         "authentication not failed");
12667         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12668                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12669                                 ut_params->op, 1, 1, 0, 0);
12670         else {
12671                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12672                         ut_params->op);
12673                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12674         }
12675
12676         return 0;
12677 }
12678
12679 static int
12680 test_authenticated_encryt_with_esn(
12681                 struct crypto_testsuite_params *ts_params,
12682                 struct crypto_unittest_params *ut_params,
12683                 const struct test_crypto_vector *reference)
12684 {
12685         int retval;
12686
12687         uint8_t *authciphertext, *plaintext, *auth_tag;
12688         uint16_t plaintext_pad_len;
12689         uint8_t cipher_key[reference->cipher_key.len + 1];
12690         uint8_t auth_key[reference->auth_key.len + 1];
12691         struct rte_cryptodev_info dev_info;
12692
12693         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12694         uint64_t feat_flags = dev_info.feature_flags;
12695
12696         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12697                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12698                 printf("Device doesn't support RAW data-path APIs.\n");
12699                 return TEST_SKIPPED;
12700         }
12701
12702         /* Verify the capabilities */
12703         struct rte_cryptodev_sym_capability_idx cap_idx;
12704         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12705         cap_idx.algo.auth = reference->auth_algo;
12706         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12707                         &cap_idx) == NULL)
12708                 return TEST_SKIPPED;
12709         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12710         cap_idx.algo.cipher = reference->crypto_algo;
12711         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12712                         &cap_idx) == NULL)
12713                 return TEST_SKIPPED;
12714
12715         /* Create session */
12716         memcpy(cipher_key, reference->cipher_key.data,
12717                         reference->cipher_key.len);
12718         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12719
12720         /* Setup Cipher Parameters */
12721         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12722         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12723         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12724         ut_params->cipher_xform.cipher.key.data = cipher_key;
12725         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12726         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12727         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12728
12729         ut_params->cipher_xform.next = &ut_params->auth_xform;
12730
12731         /* Setup Authentication Parameters */
12732         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12733         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12734         ut_params->auth_xform.auth.algo = reference->auth_algo;
12735         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12736         ut_params->auth_xform.auth.key.data = auth_key;
12737         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12738         ut_params->auth_xform.next = NULL;
12739
12740         /* Create Crypto session*/
12741         ut_params->sess = rte_cryptodev_sym_session_create(
12742                         ts_params->session_mpool);
12743
12744         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12745                                 ut_params->sess,
12746                                 &ut_params->cipher_xform,
12747                                 ts_params->session_priv_mpool);
12748
12749         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12750
12751         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12752         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12753                         "Failed to allocate input buffer in mempool");
12754
12755         /* clear mbuf payload */
12756         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12757                         rte_pktmbuf_tailroom(ut_params->ibuf));
12758
12759         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12760                         reference->plaintext.len);
12761         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12762         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12763
12764         /* Create operation */
12765         retval = create_cipher_auth_operation(ts_params,
12766                         ut_params,
12767                         reference, 0);
12768
12769         if (retval < 0)
12770                 return retval;
12771
12772         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12773                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12774                         ut_params->op);
12775         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12776                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12777                                 ut_params->op, 1, 1, 0, 0);
12778         else
12779                 ut_params->op = process_crypto_request(
12780                         ts_params->valid_devs[0], ut_params->op);
12781
12782         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
12783
12784         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12785                         "crypto op processing failed");
12786
12787         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
12788
12789         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
12790                         ut_params->op->sym->auth.data.offset);
12791         auth_tag = authciphertext + plaintext_pad_len;
12792         debug_hexdump(stdout, "ciphertext:", authciphertext,
12793                         reference->ciphertext.len);
12794         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
12795
12796         /* Validate obuf */
12797         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12798                         authciphertext,
12799                         reference->ciphertext.data,
12800                         reference->ciphertext.len,
12801                         "Ciphertext data not as expected");
12802
12803         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12804                         auth_tag,
12805                         reference->digest.data,
12806                         reference->digest.len,
12807                         "Generated digest not as expected");
12808
12809         return TEST_SUCCESS;
12810
12811 }
12812
12813 static int
12814 test_authenticated_decrypt_with_esn(
12815                 struct crypto_testsuite_params *ts_params,
12816                 struct crypto_unittest_params *ut_params,
12817                 const struct test_crypto_vector *reference)
12818 {
12819         int retval;
12820
12821         uint8_t *ciphertext;
12822         uint8_t cipher_key[reference->cipher_key.len + 1];
12823         uint8_t auth_key[reference->auth_key.len + 1];
12824         struct rte_cryptodev_info dev_info;
12825
12826         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12827         uint64_t feat_flags = dev_info.feature_flags;
12828
12829         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12830                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12831                 printf("Device doesn't support RAW data-path APIs.\n");
12832                 return TEST_SKIPPED;
12833         }
12834
12835         /* Verify the capabilities */
12836         struct rte_cryptodev_sym_capability_idx cap_idx;
12837         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12838         cap_idx.algo.auth = reference->auth_algo;
12839         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12840                         &cap_idx) == NULL)
12841                 return TEST_SKIPPED;
12842         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12843         cap_idx.algo.cipher = reference->crypto_algo;
12844         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12845                         &cap_idx) == NULL)
12846                 return TEST_SKIPPED;
12847
12848         /* Create session */
12849         memcpy(cipher_key, reference->cipher_key.data,
12850                         reference->cipher_key.len);
12851         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12852
12853         /* Setup Authentication Parameters */
12854         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12855         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
12856         ut_params->auth_xform.auth.algo = reference->auth_algo;
12857         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12858         ut_params->auth_xform.auth.key.data = auth_key;
12859         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12860         ut_params->auth_xform.next = &ut_params->cipher_xform;
12861
12862         /* Setup Cipher Parameters */
12863         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12864         ut_params->cipher_xform.next = NULL;
12865         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12866         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
12867         ut_params->cipher_xform.cipher.key.data = cipher_key;
12868         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12869         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12870         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12871
12872         /* Create Crypto session*/
12873         ut_params->sess = rte_cryptodev_sym_session_create(
12874                         ts_params->session_mpool);
12875
12876         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12877                                 ut_params->sess,
12878                                 &ut_params->auth_xform,
12879                                 ts_params->session_priv_mpool);
12880
12881         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12882
12883         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12884         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12885                         "Failed to allocate input buffer in mempool");
12886
12887         /* clear mbuf payload */
12888         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12889                         rte_pktmbuf_tailroom(ut_params->ibuf));
12890
12891         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12892                         reference->ciphertext.len);
12893         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12894         memcpy(ciphertext, reference->ciphertext.data,
12895                         reference->ciphertext.len);
12896
12897         /* Create operation */
12898         retval = create_cipher_auth_verify_operation(ts_params,
12899                         ut_params,
12900                         reference);
12901
12902         if (retval < 0)
12903                 return retval;
12904
12905         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12906                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12907                         ut_params->op);
12908         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12909                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12910                                 ut_params->op, 1, 1, 0, 0);
12911         else
12912                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12913                         ut_params->op);
12914
12915         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
12916         TEST_ASSERT_EQUAL(ut_params->op->status,
12917                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12918                         "crypto op processing passed");
12919
12920         ut_params->obuf = ut_params->op->sym->m_src;
12921         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
12922
12923         return 0;
12924 }
12925
12926 static int
12927 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
12928                 const struct aead_test_data *tdata,
12929                 void *digest_mem, uint64_t digest_phys)
12930 {
12931         struct crypto_testsuite_params *ts_params = &testsuite_params;
12932         struct crypto_unittest_params *ut_params = &unittest_params;
12933
12934         const unsigned int auth_tag_len = tdata->auth_tag.len;
12935         const unsigned int iv_len = tdata->iv.len;
12936         unsigned int aad_len = tdata->aad.len;
12937         unsigned int aad_len_pad = 0;
12938
12939         /* Generate Crypto op data structure */
12940         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12941                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12942         TEST_ASSERT_NOT_NULL(ut_params->op,
12943                 "Failed to allocate symmetric crypto operation struct");
12944
12945         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12946
12947         sym_op->aead.digest.data = digest_mem;
12948
12949         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
12950                         "no room to append digest");
12951
12952         sym_op->aead.digest.phys_addr = digest_phys;
12953
12954         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
12955                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
12956                                 auth_tag_len);
12957                 debug_hexdump(stdout, "digest:",
12958                                 sym_op->aead.digest.data,
12959                                 auth_tag_len);
12960         }
12961
12962         /* Append aad data */
12963         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
12964                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12965                                 uint8_t *, IV_OFFSET);
12966
12967                 /* Copy IV 1 byte after the IV pointer, according to the API */
12968                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
12969
12970                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
12971
12972                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12973                                 ut_params->ibuf, aad_len);
12974                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12975                                 "no room to prepend aad");
12976                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12977                                 ut_params->ibuf);
12978
12979                 memset(sym_op->aead.aad.data, 0, aad_len);
12980                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
12981                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12982
12983                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12984                 debug_hexdump(stdout, "aad:",
12985                                 sym_op->aead.aad.data, aad_len);
12986         } else {
12987                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12988                                 uint8_t *, IV_OFFSET);
12989
12990                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
12991
12992                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
12993
12994                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12995                                 ut_params->ibuf, aad_len_pad);
12996                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12997                                 "no room to prepend aad");
12998                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12999                                 ut_params->ibuf);
13000
13001                 memset(sym_op->aead.aad.data, 0, aad_len);
13002                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13003
13004                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13005                 debug_hexdump(stdout, "aad:",
13006                                 sym_op->aead.aad.data, aad_len);
13007         }
13008
13009         sym_op->aead.data.length = tdata->plaintext.len;
13010         sym_op->aead.data.offset = aad_len_pad;
13011
13012         return 0;
13013 }
13014
13015 #define SGL_MAX_NO      16
13016
13017 static int
13018 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
13019                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
13020 {
13021         struct crypto_testsuite_params *ts_params = &testsuite_params;
13022         struct crypto_unittest_params *ut_params = &unittest_params;
13023         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
13024         int retval;
13025         int to_trn = 0;
13026         int to_trn_tbl[SGL_MAX_NO];
13027         int segs = 1;
13028         unsigned int trn_data = 0;
13029         uint8_t *plaintext, *ciphertext, *auth_tag;
13030         struct rte_cryptodev_info dev_info;
13031
13032         /* Verify the capabilities */
13033         struct rte_cryptodev_sym_capability_idx cap_idx;
13034         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13035         cap_idx.algo.aead = tdata->algo;
13036         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13037                         &cap_idx) == NULL)
13038                 return TEST_SKIPPED;
13039
13040         /* OOP not supported with CPU crypto */
13041         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13042                 return TEST_SKIPPED;
13043
13044         /* Detailed check for the particular SGL support flag */
13045         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13046         if (!oop) {
13047                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
13048                 if (sgl_in && (!(dev_info.feature_flags &
13049                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
13050                         return TEST_SKIPPED;
13051
13052                 uint64_t feat_flags = dev_info.feature_flags;
13053
13054                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13055                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13056                         printf("Device doesn't support RAW data-path APIs.\n");
13057                         return TEST_SKIPPED;
13058                 }
13059         } else {
13060                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
13061                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
13062                                 tdata->plaintext.len;
13063                 /* Raw data path API does not support OOP */
13064                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13065                         return TEST_SKIPPED;
13066                 if (sgl_in && !sgl_out) {
13067                         if (!(dev_info.feature_flags &
13068                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
13069                                 return TEST_SKIPPED;
13070                 } else if (!sgl_in && sgl_out) {
13071                         if (!(dev_info.feature_flags &
13072                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
13073                                 return TEST_SKIPPED;
13074                 } else if (sgl_in && sgl_out) {
13075                         if (!(dev_info.feature_flags &
13076                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13077                                 return TEST_SKIPPED;
13078                 }
13079         }
13080
13081         if (fragsz > tdata->plaintext.len)
13082                 fragsz = tdata->plaintext.len;
13083
13084         uint16_t plaintext_len = fragsz;
13085         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13086
13087         if (fragsz_oop > tdata->plaintext.len)
13088                 frag_size_oop = tdata->plaintext.len;
13089
13090         int ecx = 0;
13091         void *digest_mem = NULL;
13092
13093         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13094
13095         if (tdata->plaintext.len % fragsz != 0) {
13096                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13097                         return 1;
13098         }       else {
13099                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13100                         return 1;
13101         }
13102
13103         /*
13104          * For out-op-place we need to alloc another mbuf
13105          */
13106         if (oop) {
13107                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13108                 rte_pktmbuf_append(ut_params->obuf,
13109                                 frag_size_oop + prepend_len);
13110                 buf_oop = ut_params->obuf;
13111         }
13112
13113         /* Create AEAD session */
13114         retval = create_aead_session(ts_params->valid_devs[0],
13115                         tdata->algo,
13116                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
13117                         tdata->key.data, tdata->key.len,
13118                         tdata->aad.len, tdata->auth_tag.len,
13119                         tdata->iv.len);
13120         if (retval < 0)
13121                 return retval;
13122
13123         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13124
13125         /* clear mbuf payload */
13126         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13127                         rte_pktmbuf_tailroom(ut_params->ibuf));
13128
13129         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13130                         plaintext_len);
13131
13132         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13133
13134         trn_data += plaintext_len;
13135
13136         buf = ut_params->ibuf;
13137
13138         /*
13139          * Loop until no more fragments
13140          */
13141
13142         while (trn_data < tdata->plaintext.len) {
13143                 ++segs;
13144                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13145                                 (tdata->plaintext.len - trn_data) : fragsz;
13146
13147                 to_trn_tbl[ecx++] = to_trn;
13148
13149                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13150                 buf = buf->next;
13151
13152                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13153                                 rte_pktmbuf_tailroom(buf));
13154
13155                 /* OOP */
13156                 if (oop && !fragsz_oop) {
13157                         buf_last_oop = buf_oop->next =
13158                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13159                         buf_oop = buf_oop->next;
13160                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13161                                         0, rte_pktmbuf_tailroom(buf_oop));
13162                         rte_pktmbuf_append(buf_oop, to_trn);
13163                 }
13164
13165                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13166                                 to_trn);
13167
13168                 memcpy(plaintext, tdata->plaintext.data + trn_data,
13169                                 to_trn);
13170                 trn_data += to_trn;
13171                 if (trn_data  == tdata->plaintext.len) {
13172                         if (oop) {
13173                                 if (!fragsz_oop)
13174                                         digest_mem = rte_pktmbuf_append(buf_oop,
13175                                                 tdata->auth_tag.len);
13176                         } else
13177                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13178                                         tdata->auth_tag.len);
13179                 }
13180         }
13181
13182         uint64_t digest_phys = 0;
13183
13184         ut_params->ibuf->nb_segs = segs;
13185
13186         segs = 1;
13187         if (fragsz_oop && oop) {
13188                 to_trn = 0;
13189                 ecx = 0;
13190
13191                 if (frag_size_oop == tdata->plaintext.len) {
13192                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
13193                                 tdata->auth_tag.len);
13194
13195                         digest_phys = rte_pktmbuf_iova_offset(
13196                                         ut_params->obuf,
13197                                         tdata->plaintext.len + prepend_len);
13198                 }
13199
13200                 trn_data = frag_size_oop;
13201                 while (trn_data < tdata->plaintext.len) {
13202                         ++segs;
13203                         to_trn =
13204                                 (tdata->plaintext.len - trn_data <
13205                                                 frag_size_oop) ?
13206                                 (tdata->plaintext.len - trn_data) :
13207                                                 frag_size_oop;
13208
13209                         to_trn_tbl[ecx++] = to_trn;
13210
13211                         buf_last_oop = buf_oop->next =
13212                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13213                         buf_oop = buf_oop->next;
13214                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13215                                         0, rte_pktmbuf_tailroom(buf_oop));
13216                         rte_pktmbuf_append(buf_oop, to_trn);
13217
13218                         trn_data += to_trn;
13219
13220                         if (trn_data  == tdata->plaintext.len) {
13221                                 digest_mem = rte_pktmbuf_append(buf_oop,
13222                                         tdata->auth_tag.len);
13223                         }
13224                 }
13225
13226                 ut_params->obuf->nb_segs = segs;
13227         }
13228
13229         /*
13230          * Place digest at the end of the last buffer
13231          */
13232         if (!digest_phys)
13233                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13234         if (oop && buf_last_oop)
13235                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13236
13237         if (!digest_mem && !oop) {
13238                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13239                                 + tdata->auth_tag.len);
13240                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13241                                 tdata->plaintext.len);
13242         }
13243
13244         /* Create AEAD operation */
13245         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13246                         tdata, digest_mem, digest_phys);
13247
13248         if (retval < 0)
13249                 return retval;
13250
13251         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13252
13253         ut_params->op->sym->m_src = ut_params->ibuf;
13254         if (oop)
13255                 ut_params->op->sym->m_dst = ut_params->obuf;
13256
13257         /* Process crypto operation */
13258         if (oop == IN_PLACE &&
13259                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13260                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13261         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13262                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13263                                 ut_params->op, 0, 0, 0, 0);
13264         else
13265                 TEST_ASSERT_NOT_NULL(
13266                         process_crypto_request(ts_params->valid_devs[0],
13267                         ut_params->op), "failed to process sym crypto op");
13268
13269         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13270                         "crypto op processing failed");
13271
13272
13273         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13274                         uint8_t *, prepend_len);
13275         if (oop) {
13276                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13277                                 uint8_t *, prepend_len);
13278         }
13279
13280         if (fragsz_oop)
13281                 fragsz = fragsz_oop;
13282
13283         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13284                         ciphertext,
13285                         tdata->ciphertext.data,
13286                         fragsz,
13287                         "Ciphertext data not as expected");
13288
13289         buf = ut_params->op->sym->m_src->next;
13290         if (oop)
13291                 buf = ut_params->op->sym->m_dst->next;
13292
13293         unsigned int off = fragsz;
13294
13295         ecx = 0;
13296         while (buf) {
13297                 ciphertext = rte_pktmbuf_mtod(buf,
13298                                 uint8_t *);
13299
13300                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
13301                                 ciphertext,
13302                                 tdata->ciphertext.data + off,
13303                                 to_trn_tbl[ecx],
13304                                 "Ciphertext data not as expected");
13305
13306                 off += to_trn_tbl[ecx++];
13307                 buf = buf->next;
13308         }
13309
13310         auth_tag = digest_mem;
13311         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13312                         auth_tag,
13313                         tdata->auth_tag.data,
13314                         tdata->auth_tag.len,
13315                         "Generated auth tag not as expected");
13316
13317         return 0;
13318 }
13319
13320 static int
13321 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13322 {
13323         return test_authenticated_encryption_SGL(
13324                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13325 }
13326
13327 static int
13328 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13329 {
13330         return test_authenticated_encryption_SGL(
13331                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13332 }
13333
13334 static int
13335 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13336 {
13337         return test_authenticated_encryption_SGL(
13338                         &gcm_test_case_8, OUT_OF_PLACE, 400,
13339                         gcm_test_case_8.plaintext.len);
13340 }
13341
13342 static int
13343 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13344 {
13345         /* This test is not for OPENSSL PMD */
13346         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13347                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13348                 return TEST_SKIPPED;
13349
13350         return test_authenticated_encryption_SGL(
13351                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13352 }
13353
13354 static int
13355 test_authentication_verify_fail_when_data_corrupted(
13356                 struct crypto_testsuite_params *ts_params,
13357                 struct crypto_unittest_params *ut_params,
13358                 const struct test_crypto_vector *reference)
13359 {
13360         return test_authentication_verify_fail_when_data_corruption(
13361                         ts_params, ut_params, reference, 1);
13362 }
13363
13364 static int
13365 test_authentication_verify_fail_when_tag_corrupted(
13366                 struct crypto_testsuite_params *ts_params,
13367                 struct crypto_unittest_params *ut_params,
13368                 const struct test_crypto_vector *reference)
13369 {
13370         return test_authentication_verify_fail_when_data_corruption(
13371                         ts_params, ut_params, reference, 0);
13372 }
13373
13374 static int
13375 test_authentication_verify_GMAC_fail_when_data_corrupted(
13376                 struct crypto_testsuite_params *ts_params,
13377                 struct crypto_unittest_params *ut_params,
13378                 const struct test_crypto_vector *reference)
13379 {
13380         return test_authentication_verify_GMAC_fail_when_corruption(
13381                         ts_params, ut_params, reference, 1);
13382 }
13383
13384 static int
13385 test_authentication_verify_GMAC_fail_when_tag_corrupted(
13386                 struct crypto_testsuite_params *ts_params,
13387                 struct crypto_unittest_params *ut_params,
13388                 const struct test_crypto_vector *reference)
13389 {
13390         return test_authentication_verify_GMAC_fail_when_corruption(
13391                         ts_params, ut_params, reference, 0);
13392 }
13393
13394 static int
13395 test_authenticated_decryption_fail_when_data_corrupted(
13396                 struct crypto_testsuite_params *ts_params,
13397                 struct crypto_unittest_params *ut_params,
13398                 const struct test_crypto_vector *reference)
13399 {
13400         return test_authenticated_decryption_fail_when_corruption(
13401                         ts_params, ut_params, reference, 1);
13402 }
13403
13404 static int
13405 test_authenticated_decryption_fail_when_tag_corrupted(
13406                 struct crypto_testsuite_params *ts_params,
13407                 struct crypto_unittest_params *ut_params,
13408                 const struct test_crypto_vector *reference)
13409 {
13410         return test_authenticated_decryption_fail_when_corruption(
13411                         ts_params, ut_params, reference, 0);
13412 }
13413
13414 static int
13415 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
13416 {
13417         return test_authentication_verify_fail_when_data_corrupted(
13418                         &testsuite_params, &unittest_params,
13419                         &hmac_sha1_test_crypto_vector);
13420 }
13421
13422 static int
13423 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13424 {
13425         return test_authentication_verify_fail_when_tag_corrupted(
13426                         &testsuite_params, &unittest_params,
13427                         &hmac_sha1_test_crypto_vector);
13428 }
13429
13430 static int
13431 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
13432 {
13433         return test_authentication_verify_GMAC_fail_when_data_corrupted(
13434                         &testsuite_params, &unittest_params,
13435                         &aes128_gmac_test_vector);
13436 }
13437
13438 static int
13439 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
13440 {
13441         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
13442                         &testsuite_params, &unittest_params,
13443                         &aes128_gmac_test_vector);
13444 }
13445
13446 static int
13447 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
13448 {
13449         return test_authenticated_decryption_fail_when_data_corrupted(
13450                         &testsuite_params,
13451                         &unittest_params,
13452                         &aes128cbc_hmac_sha1_test_vector);
13453 }
13454
13455 static int
13456 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
13457 {
13458         return test_authenticated_decryption_fail_when_tag_corrupted(
13459                         &testsuite_params,
13460                         &unittest_params,
13461                         &aes128cbc_hmac_sha1_test_vector);
13462 }
13463
13464 static int
13465 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13466 {
13467         return test_authenticated_encryt_with_esn(
13468                         &testsuite_params,
13469                         &unittest_params,
13470                         &aes128cbc_hmac_sha1_aad_test_vector);
13471 }
13472
13473 static int
13474 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13475 {
13476         return test_authenticated_decrypt_with_esn(
13477                         &testsuite_params,
13478                         &unittest_params,
13479                         &aes128cbc_hmac_sha1_aad_test_vector);
13480 }
13481
13482 static int
13483 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
13484 {
13485         return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
13486 }
13487
13488 static int
13489 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
13490 {
13491         return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
13492 }
13493
13494 #ifdef RTE_CRYPTO_SCHEDULER
13495
13496 /* global AESNI worker IDs for the scheduler test */
13497 uint8_t aesni_ids[2];
13498
13499 static int
13500 scheduler_testsuite_setup(void)
13501 {
13502         uint32_t i = 0;
13503         int32_t nb_devs, ret;
13504         char vdev_args[VDEV_ARGS_SIZE] = {""};
13505         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
13506                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
13507         uint16_t worker_core_count = 0;
13508         uint16_t socket_id = 0;
13509
13510         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13511                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
13512
13513                 /* Identify the Worker Cores
13514                  * Use 2 worker cores for the device args
13515                  */
13516                 RTE_LCORE_FOREACH_WORKER(i) {
13517                         if (worker_core_count > 1)
13518                                 break;
13519                         snprintf(vdev_args, sizeof(vdev_args),
13520                                         "%s%d", temp_str, i);
13521                         strcpy(temp_str, vdev_args);
13522                         strlcat(temp_str, ";", sizeof(temp_str));
13523                         worker_core_count++;
13524                         socket_id = rte_lcore_to_socket_id(i);
13525                 }
13526                 if (worker_core_count != 2) {
13527                         RTE_LOG(ERR, USER1,
13528                                 "Cryptodev scheduler test require at least "
13529                                 "two worker cores to run. "
13530                                 "Please use the correct coremask.\n");
13531                         return TEST_FAILED;
13532                 }
13533                 strcpy(temp_str, vdev_args);
13534                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
13535                                 temp_str, socket_id);
13536                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
13537                 nb_devs = rte_cryptodev_device_count_by_driver(
13538                                 rte_cryptodev_driver_id_get(
13539                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
13540                 if (nb_devs < 1) {
13541                         ret = rte_vdev_init(
13542                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
13543                                         vdev_args);
13544                         TEST_ASSERT(ret == 0,
13545                                 "Failed to create instance %u of pmd : %s",
13546                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13547                 }
13548         }
13549         return testsuite_setup();
13550 }
13551
13552 static int
13553 test_scheduler_attach_slave_op(void)
13554 {
13555         struct crypto_testsuite_params *ts_params = &testsuite_params;
13556         uint8_t sched_id = ts_params->valid_devs[0];
13557         uint32_t nb_devs, i, nb_devs_attached = 0;
13558         int ret;
13559         char vdev_name[32];
13560
13561         /* create 2 AESNI_MB if necessary */
13562         nb_devs = rte_cryptodev_device_count_by_driver(
13563                         rte_cryptodev_driver_id_get(
13564                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
13565         if (nb_devs < 2) {
13566                 for (i = nb_devs; i < 2; i++) {
13567                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
13568                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
13569                                         i);
13570                         ret = rte_vdev_init(vdev_name, NULL);
13571
13572                         TEST_ASSERT(ret == 0,
13573                                 "Failed to create instance %u of"
13574                                 " pmd : %s",
13575                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13576                 }
13577         }
13578
13579         /* attach 2 AESNI_MB cdevs */
13580         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
13581                         i++) {
13582                 struct rte_cryptodev_info info;
13583                 unsigned int session_size;
13584
13585                 rte_cryptodev_info_get(i, &info);
13586                 if (info.driver_id != rte_cryptodev_driver_id_get(
13587                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
13588                         continue;
13589
13590                 session_size = rte_cryptodev_sym_get_private_session_size(i);
13591                 /*
13592                  * Create the session mempool again, since now there are new devices
13593                  * to use the mempool.
13594                  */
13595                 if (ts_params->session_mpool) {
13596                         rte_mempool_free(ts_params->session_mpool);
13597                         ts_params->session_mpool = NULL;
13598                 }
13599                 if (ts_params->session_priv_mpool) {
13600                         rte_mempool_free(ts_params->session_priv_mpool);
13601                         ts_params->session_priv_mpool = NULL;
13602                 }
13603
13604                 if (info.sym.max_nb_sessions != 0 &&
13605                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
13606                         RTE_LOG(ERR, USER1,
13607                                         "Device does not support "
13608                                         "at least %u sessions\n",
13609                                         MAX_NB_SESSIONS);
13610                         return TEST_FAILED;
13611                 }
13612                 /*
13613                  * Create mempool with maximum number of sessions,
13614                  * to include the session headers
13615                  */
13616                 if (ts_params->session_mpool == NULL) {
13617                         ts_params->session_mpool =
13618                                 rte_cryptodev_sym_session_pool_create(
13619                                                 "test_sess_mp",
13620                                                 MAX_NB_SESSIONS, 0, 0, 0,
13621                                                 SOCKET_ID_ANY);
13622                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
13623                                         "session mempool allocation failed");
13624                 }
13625
13626                 /*
13627                  * Create mempool with maximum number of sessions,
13628                  * to include device specific session private data
13629                  */
13630                 if (ts_params->session_priv_mpool == NULL) {
13631                         ts_params->session_priv_mpool = rte_mempool_create(
13632                                         "test_sess_mp_priv",
13633                                         MAX_NB_SESSIONS,
13634                                         session_size,
13635                                         0, 0, NULL, NULL, NULL,
13636                                         NULL, SOCKET_ID_ANY,
13637                                         0);
13638
13639                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
13640                                         "session mempool allocation failed");
13641                 }
13642
13643                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
13644                 ts_params->qp_conf.mp_session_private =
13645                                 ts_params->session_priv_mpool;
13646
13647                 ret = rte_cryptodev_scheduler_worker_attach(sched_id,
13648                                 (uint8_t)i);
13649
13650                 TEST_ASSERT(ret == 0,
13651                         "Failed to attach device %u of pmd : %s", i,
13652                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13653
13654                 aesni_ids[nb_devs_attached] = (uint8_t)i;
13655
13656                 nb_devs_attached++;
13657         }
13658
13659         return 0;
13660 }
13661
13662 static int
13663 test_scheduler_detach_slave_op(void)
13664 {
13665         struct crypto_testsuite_params *ts_params = &testsuite_params;
13666         uint8_t sched_id = ts_params->valid_devs[0];
13667         uint32_t i;
13668         int ret;
13669
13670         for (i = 0; i < 2; i++) {
13671                 ret = rte_cryptodev_scheduler_worker_detach(sched_id,
13672                                 aesni_ids[i]);
13673                 TEST_ASSERT(ret == 0,
13674                         "Failed to detach device %u", aesni_ids[i]);
13675         }
13676
13677         return 0;
13678 }
13679
13680 static int
13681 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
13682 {
13683         struct crypto_testsuite_params *ts_params = &testsuite_params;
13684         uint8_t sched_id = ts_params->valid_devs[0];
13685         /* set mode */
13686         return rte_cryptodev_scheduler_mode_set(sched_id,
13687                 scheduler_mode);
13688 }
13689
13690 static int
13691 test_scheduler_mode_roundrobin_op(void)
13692 {
13693         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
13694                         0, "Failed to set roundrobin mode");
13695         return 0;
13696
13697 }
13698
13699 static int
13700 test_scheduler_mode_multicore_op(void)
13701 {
13702         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
13703                         0, "Failed to set multicore mode");
13704
13705         return 0;
13706 }
13707
13708 static int
13709 test_scheduler_mode_failover_op(void)
13710 {
13711         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
13712                         0, "Failed to set failover mode");
13713
13714         return 0;
13715 }
13716
13717 static int
13718 test_scheduler_mode_pkt_size_distr_op(void)
13719 {
13720         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
13721                         0, "Failed to set pktsize mode");
13722
13723         return 0;
13724 }
13725
13726 static int
13727 scheduler_multicore_testsuite_setup(void)
13728 {
13729         if (test_scheduler_attach_slave_op() < 0)
13730                 return TEST_SKIPPED;
13731         if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
13732                 return TEST_SKIPPED;
13733         return 0;
13734 }
13735
13736 static int
13737 scheduler_roundrobin_testsuite_setup(void)
13738 {
13739         if (test_scheduler_attach_slave_op() < 0)
13740                 return TEST_SKIPPED;
13741         if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
13742                 return TEST_SKIPPED;
13743         return 0;
13744 }
13745
13746 static int
13747 scheduler_failover_testsuite_setup(void)
13748 {
13749         if (test_scheduler_attach_slave_op() < 0)
13750                 return TEST_SKIPPED;
13751         if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
13752                 return TEST_SKIPPED;
13753         return 0;
13754 }
13755
13756 static int
13757 scheduler_pkt_size_distr_testsuite_setup(void)
13758 {
13759         if (test_scheduler_attach_slave_op() < 0)
13760                 return TEST_SKIPPED;
13761         if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
13762                 return TEST_SKIPPED;
13763         return 0;
13764 }
13765
13766 static void
13767 scheduler_mode_testsuite_teardown(void)
13768 {
13769         test_scheduler_detach_slave_op();
13770 }
13771
13772 #endif /* RTE_CRYPTO_SCHEDULER */
13773
13774 static struct unit_test_suite end_testsuite = {
13775         .suite_name = NULL,
13776         .setup = NULL,
13777         .teardown = NULL,
13778         .unit_test_suites = NULL
13779 };
13780
13781 #ifdef RTE_LIB_SECURITY
13782 static struct unit_test_suite pdcp_proto_testsuite  = {
13783         .suite_name = "PDCP Proto Unit Test Suite",
13784         .setup = pdcp_proto_testsuite_setup,
13785         .unit_test_cases = {
13786                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13787                         test_PDCP_PROTO_all),
13788                 TEST_CASES_END() /**< NULL terminate unit test array */
13789         }
13790 };
13791
13792 static struct unit_test_suite docsis_proto_testsuite  = {
13793         .suite_name = "Docsis Proto Unit Test Suite",
13794         .setup = docsis_proto_testsuite_setup,
13795         .unit_test_cases = {
13796                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13797                         test_DOCSIS_PROTO_all),
13798                 TEST_CASES_END() /**< NULL terminate unit test array */
13799         }
13800 };
13801 #endif
13802
13803 static struct unit_test_suite cryptodev_gen_testsuite  = {
13804         .suite_name = "Crypto General Unit Test Suite",
13805         .setup = crypto_gen_testsuite_setup,
13806         .unit_test_cases = {
13807                 TEST_CASE_ST(ut_setup, ut_teardown,
13808                                 test_device_configure_invalid_dev_id),
13809                 TEST_CASE_ST(ut_setup, ut_teardown,
13810                                 test_queue_pair_descriptor_setup),
13811                 TEST_CASE_ST(ut_setup, ut_teardown,
13812                                 test_device_configure_invalid_queue_pair_ids),
13813                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13814                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13815                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13816                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13817                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all),
13818                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all),
13819                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all),
13820                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13821                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
13822                 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
13823                 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
13824                 TEST_CASES_END() /**< NULL terminate unit test array */
13825         }
13826 };
13827
13828 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
13829         .suite_name = "Negative HMAC SHA1 Unit Test Suite",
13830         .setup = negative_hmac_sha1_testsuite_setup,
13831         .unit_test_cases = {
13832                 /** Negative tests */
13833                 TEST_CASE_ST(ut_setup, ut_teardown,
13834                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13835                 TEST_CASE_ST(ut_setup, ut_teardown,
13836                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13837                 TEST_CASE_ST(ut_setup, ut_teardown,
13838                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13839                 TEST_CASE_ST(ut_setup, ut_teardown,
13840                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13841
13842                 TEST_CASES_END() /**< NULL terminate unit test array */
13843         }
13844 };
13845
13846 static struct unit_test_suite cryptodev_multi_session_testsuite = {
13847         .suite_name = "Multi Session Unit Test Suite",
13848         .setup = multi_session_testsuite_setup,
13849         .unit_test_cases = {
13850                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13851                 TEST_CASE_ST(ut_setup, ut_teardown,
13852                                 test_multi_session_random_usage),
13853
13854                 TEST_CASES_END() /**< NULL terminate unit test array */
13855         }
13856 };
13857
13858 static struct unit_test_suite cryptodev_null_testsuite  = {
13859         .suite_name = "NULL Test Suite",
13860         .setup = null_testsuite_setup,
13861         .unit_test_cases = {
13862                 TEST_CASE_ST(ut_setup, ut_teardown,
13863                         test_null_invalid_operation),
13864                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
13865                 TEST_CASES_END()
13866         }
13867 };
13868
13869 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
13870         .suite_name = "AES CCM Authenticated Test Suite",
13871         .setup = aes_ccm_auth_testsuite_setup,
13872         .unit_test_cases = {
13873                 /** AES CCM Authenticated Encryption 128 bits key*/
13874                 TEST_CASE_ST(ut_setup, ut_teardown,
13875                         test_AES_CCM_authenticated_encryption_test_case_128_1),
13876                 TEST_CASE_ST(ut_setup, ut_teardown,
13877                         test_AES_CCM_authenticated_encryption_test_case_128_2),
13878                 TEST_CASE_ST(ut_setup, ut_teardown,
13879                         test_AES_CCM_authenticated_encryption_test_case_128_3),
13880
13881                 /** AES CCM Authenticated Decryption 128 bits key*/
13882                 TEST_CASE_ST(ut_setup, ut_teardown,
13883                         test_AES_CCM_authenticated_decryption_test_case_128_1),
13884                 TEST_CASE_ST(ut_setup, ut_teardown,
13885                         test_AES_CCM_authenticated_decryption_test_case_128_2),
13886                 TEST_CASE_ST(ut_setup, ut_teardown,
13887                         test_AES_CCM_authenticated_decryption_test_case_128_3),
13888
13889                 /** AES CCM Authenticated Encryption 192 bits key */
13890                 TEST_CASE_ST(ut_setup, ut_teardown,
13891                         test_AES_CCM_authenticated_encryption_test_case_192_1),
13892                 TEST_CASE_ST(ut_setup, ut_teardown,
13893                         test_AES_CCM_authenticated_encryption_test_case_192_2),
13894                 TEST_CASE_ST(ut_setup, ut_teardown,
13895                         test_AES_CCM_authenticated_encryption_test_case_192_3),
13896
13897                 /** AES CCM Authenticated Decryption 192 bits key*/
13898                 TEST_CASE_ST(ut_setup, ut_teardown,
13899                         test_AES_CCM_authenticated_decryption_test_case_192_1),
13900                 TEST_CASE_ST(ut_setup, ut_teardown,
13901                         test_AES_CCM_authenticated_decryption_test_case_192_2),
13902                 TEST_CASE_ST(ut_setup, ut_teardown,
13903                         test_AES_CCM_authenticated_decryption_test_case_192_3),
13904
13905                 /** AES CCM Authenticated Encryption 256 bits key */
13906                 TEST_CASE_ST(ut_setup, ut_teardown,
13907                         test_AES_CCM_authenticated_encryption_test_case_256_1),
13908                 TEST_CASE_ST(ut_setup, ut_teardown,
13909                         test_AES_CCM_authenticated_encryption_test_case_256_2),
13910                 TEST_CASE_ST(ut_setup, ut_teardown,
13911                         test_AES_CCM_authenticated_encryption_test_case_256_3),
13912
13913                 /** AES CCM Authenticated Decryption 256 bits key*/
13914                 TEST_CASE_ST(ut_setup, ut_teardown,
13915                         test_AES_CCM_authenticated_decryption_test_case_256_1),
13916                 TEST_CASE_ST(ut_setup, ut_teardown,
13917                         test_AES_CCM_authenticated_decryption_test_case_256_2),
13918                 TEST_CASE_ST(ut_setup, ut_teardown,
13919                         test_AES_CCM_authenticated_decryption_test_case_256_3),
13920                 TEST_CASES_END()
13921         }
13922 };
13923
13924 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
13925         .suite_name = "AES GCM Authenticated Test Suite",
13926         .setup = aes_gcm_auth_testsuite_setup,
13927         .unit_test_cases = {
13928                 /** AES GCM Authenticated Encryption */
13929                 TEST_CASE_ST(ut_setup, ut_teardown,
13930                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
13931                 TEST_CASE_ST(ut_setup, ut_teardown,
13932                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
13933                 TEST_CASE_ST(ut_setup, ut_teardown,
13934                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
13935                 TEST_CASE_ST(ut_setup, ut_teardown,
13936                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
13937                 TEST_CASE_ST(ut_setup, ut_teardown,
13938                         test_AES_GCM_authenticated_encryption_test_case_1),
13939                 TEST_CASE_ST(ut_setup, ut_teardown,
13940                         test_AES_GCM_authenticated_encryption_test_case_2),
13941                 TEST_CASE_ST(ut_setup, ut_teardown,
13942                         test_AES_GCM_authenticated_encryption_test_case_3),
13943                 TEST_CASE_ST(ut_setup, ut_teardown,
13944                         test_AES_GCM_authenticated_encryption_test_case_4),
13945                 TEST_CASE_ST(ut_setup, ut_teardown,
13946                         test_AES_GCM_authenticated_encryption_test_case_5),
13947                 TEST_CASE_ST(ut_setup, ut_teardown,
13948                         test_AES_GCM_authenticated_encryption_test_case_6),
13949                 TEST_CASE_ST(ut_setup, ut_teardown,
13950                         test_AES_GCM_authenticated_encryption_test_case_7),
13951                 TEST_CASE_ST(ut_setup, ut_teardown,
13952                         test_AES_GCM_authenticated_encryption_test_case_8),
13953                 TEST_CASE_ST(ut_setup, ut_teardown,
13954                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
13955
13956                 /** AES GCM Authenticated Decryption */
13957                 TEST_CASE_ST(ut_setup, ut_teardown,
13958                         test_AES_GCM_authenticated_decryption_test_case_1),
13959                 TEST_CASE_ST(ut_setup, ut_teardown,
13960                         test_AES_GCM_authenticated_decryption_test_case_2),
13961                 TEST_CASE_ST(ut_setup, ut_teardown,
13962                         test_AES_GCM_authenticated_decryption_test_case_3),
13963                 TEST_CASE_ST(ut_setup, ut_teardown,
13964                         test_AES_GCM_authenticated_decryption_test_case_4),
13965                 TEST_CASE_ST(ut_setup, ut_teardown,
13966                         test_AES_GCM_authenticated_decryption_test_case_5),
13967                 TEST_CASE_ST(ut_setup, ut_teardown,
13968                         test_AES_GCM_authenticated_decryption_test_case_6),
13969                 TEST_CASE_ST(ut_setup, ut_teardown,
13970                         test_AES_GCM_authenticated_decryption_test_case_7),
13971                 TEST_CASE_ST(ut_setup, ut_teardown,
13972                         test_AES_GCM_authenticated_decryption_test_case_8),
13973                 TEST_CASE_ST(ut_setup, ut_teardown,
13974                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
13975
13976                 /** AES GCM Authenticated Encryption 192 bits key */
13977                 TEST_CASE_ST(ut_setup, ut_teardown,
13978                         test_AES_GCM_auth_encryption_test_case_192_1),
13979                 TEST_CASE_ST(ut_setup, ut_teardown,
13980                         test_AES_GCM_auth_encryption_test_case_192_2),
13981                 TEST_CASE_ST(ut_setup, ut_teardown,
13982                         test_AES_GCM_auth_encryption_test_case_192_3),
13983                 TEST_CASE_ST(ut_setup, ut_teardown,
13984                         test_AES_GCM_auth_encryption_test_case_192_4),
13985                 TEST_CASE_ST(ut_setup, ut_teardown,
13986                         test_AES_GCM_auth_encryption_test_case_192_5),
13987                 TEST_CASE_ST(ut_setup, ut_teardown,
13988                         test_AES_GCM_auth_encryption_test_case_192_6),
13989                 TEST_CASE_ST(ut_setup, ut_teardown,
13990                         test_AES_GCM_auth_encryption_test_case_192_7),
13991
13992                 /** AES GCM Authenticated Decryption 192 bits key */
13993                 TEST_CASE_ST(ut_setup, ut_teardown,
13994                         test_AES_GCM_auth_decryption_test_case_192_1),
13995                 TEST_CASE_ST(ut_setup, ut_teardown,
13996                         test_AES_GCM_auth_decryption_test_case_192_2),
13997                 TEST_CASE_ST(ut_setup, ut_teardown,
13998                         test_AES_GCM_auth_decryption_test_case_192_3),
13999                 TEST_CASE_ST(ut_setup, ut_teardown,
14000                         test_AES_GCM_auth_decryption_test_case_192_4),
14001                 TEST_CASE_ST(ut_setup, ut_teardown,
14002                         test_AES_GCM_auth_decryption_test_case_192_5),
14003                 TEST_CASE_ST(ut_setup, ut_teardown,
14004                         test_AES_GCM_auth_decryption_test_case_192_6),
14005                 TEST_CASE_ST(ut_setup, ut_teardown,
14006                         test_AES_GCM_auth_decryption_test_case_192_7),
14007
14008                 /** AES GCM Authenticated Encryption 256 bits key */
14009                 TEST_CASE_ST(ut_setup, ut_teardown,
14010                         test_AES_GCM_auth_encryption_test_case_256_1),
14011                 TEST_CASE_ST(ut_setup, ut_teardown,
14012                         test_AES_GCM_auth_encryption_test_case_256_2),
14013                 TEST_CASE_ST(ut_setup, ut_teardown,
14014                         test_AES_GCM_auth_encryption_test_case_256_3),
14015                 TEST_CASE_ST(ut_setup, ut_teardown,
14016                         test_AES_GCM_auth_encryption_test_case_256_4),
14017                 TEST_CASE_ST(ut_setup, ut_teardown,
14018                         test_AES_GCM_auth_encryption_test_case_256_5),
14019                 TEST_CASE_ST(ut_setup, ut_teardown,
14020                         test_AES_GCM_auth_encryption_test_case_256_6),
14021                 TEST_CASE_ST(ut_setup, ut_teardown,
14022                         test_AES_GCM_auth_encryption_test_case_256_7),
14023
14024                 /** AES GCM Authenticated Decryption 256 bits key */
14025                 TEST_CASE_ST(ut_setup, ut_teardown,
14026                         test_AES_GCM_auth_decryption_test_case_256_1),
14027                 TEST_CASE_ST(ut_setup, ut_teardown,
14028                         test_AES_GCM_auth_decryption_test_case_256_2),
14029                 TEST_CASE_ST(ut_setup, ut_teardown,
14030                         test_AES_GCM_auth_decryption_test_case_256_3),
14031                 TEST_CASE_ST(ut_setup, ut_teardown,
14032                         test_AES_GCM_auth_decryption_test_case_256_4),
14033                 TEST_CASE_ST(ut_setup, ut_teardown,
14034                         test_AES_GCM_auth_decryption_test_case_256_5),
14035                 TEST_CASE_ST(ut_setup, ut_teardown,
14036                         test_AES_GCM_auth_decryption_test_case_256_6),
14037                 TEST_CASE_ST(ut_setup, ut_teardown,
14038                         test_AES_GCM_auth_decryption_test_case_256_7),
14039
14040                 /** AES GCM Authenticated Encryption big aad size */
14041                 TEST_CASE_ST(ut_setup, ut_teardown,
14042                         test_AES_GCM_auth_encryption_test_case_aad_1),
14043                 TEST_CASE_ST(ut_setup, ut_teardown,
14044                         test_AES_GCM_auth_encryption_test_case_aad_2),
14045
14046                 /** AES GCM Authenticated Decryption big aad size */
14047                 TEST_CASE_ST(ut_setup, ut_teardown,
14048                         test_AES_GCM_auth_decryption_test_case_aad_1),
14049                 TEST_CASE_ST(ut_setup, ut_teardown,
14050                         test_AES_GCM_auth_decryption_test_case_aad_2),
14051
14052                 /** Out of place tests */
14053                 TEST_CASE_ST(ut_setup, ut_teardown,
14054                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
14055                 TEST_CASE_ST(ut_setup, ut_teardown,
14056                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
14057
14058                 /** Session-less tests */
14059                 TEST_CASE_ST(ut_setup, ut_teardown,
14060                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
14061                 TEST_CASE_ST(ut_setup, ut_teardown,
14062                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
14063
14064                 TEST_CASES_END()
14065         }
14066 };
14067
14068 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
14069         .suite_name = "AES GMAC Authentication Test Suite",
14070         .setup = aes_gmac_auth_testsuite_setup,
14071         .unit_test_cases = {
14072                 TEST_CASE_ST(ut_setup, ut_teardown,
14073                         test_AES_GMAC_authentication_test_case_1),
14074                 TEST_CASE_ST(ut_setup, ut_teardown,
14075                         test_AES_GMAC_authentication_verify_test_case_1),
14076                 TEST_CASE_ST(ut_setup, ut_teardown,
14077                         test_AES_GMAC_authentication_test_case_2),
14078                 TEST_CASE_ST(ut_setup, ut_teardown,
14079                         test_AES_GMAC_authentication_verify_test_case_2),
14080                 TEST_CASE_ST(ut_setup, ut_teardown,
14081                         test_AES_GMAC_authentication_test_case_3),
14082                 TEST_CASE_ST(ut_setup, ut_teardown,
14083                         test_AES_GMAC_authentication_verify_test_case_3),
14084                 TEST_CASE_ST(ut_setup, ut_teardown,
14085                         test_AES_GMAC_authentication_test_case_4),
14086                 TEST_CASE_ST(ut_setup, ut_teardown,
14087                         test_AES_GMAC_authentication_verify_test_case_4),
14088                 TEST_CASE_ST(ut_setup, ut_teardown,
14089                         test_AES_GMAC_authentication_SGL_40B),
14090                 TEST_CASE_ST(ut_setup, ut_teardown,
14091                         test_AES_GMAC_authentication_SGL_80B),
14092                 TEST_CASE_ST(ut_setup, ut_teardown,
14093                         test_AES_GMAC_authentication_SGL_2048B),
14094                 TEST_CASE_ST(ut_setup, ut_teardown,
14095                         test_AES_GMAC_authentication_SGL_2047B),
14096
14097                 TEST_CASES_END()
14098         }
14099 };
14100
14101 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14102         .suite_name = "Chacha20-Poly1305 Test Suite",
14103         .setup = chacha20_poly1305_testsuite_setup,
14104         .unit_test_cases = {
14105                 TEST_CASE_ST(ut_setup, ut_teardown,
14106                         test_chacha20_poly1305_encrypt_test_case_rfc8439),
14107                 TEST_CASE_ST(ut_setup, ut_teardown,
14108                         test_chacha20_poly1305_decrypt_test_case_rfc8439),
14109                 TEST_CASES_END()
14110         }
14111 };
14112
14113 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14114         .suite_name = "SNOW 3G Test Suite",
14115         .setup = snow3g_testsuite_setup,
14116         .unit_test_cases = {
14117                 /** SNOW 3G encrypt only (UEA2) */
14118                 TEST_CASE_ST(ut_setup, ut_teardown,
14119                         test_snow3g_encryption_test_case_1),
14120                 TEST_CASE_ST(ut_setup, ut_teardown,
14121                         test_snow3g_encryption_test_case_2),
14122                 TEST_CASE_ST(ut_setup, ut_teardown,
14123                         test_snow3g_encryption_test_case_3),
14124                 TEST_CASE_ST(ut_setup, ut_teardown,
14125                         test_snow3g_encryption_test_case_4),
14126                 TEST_CASE_ST(ut_setup, ut_teardown,
14127                         test_snow3g_encryption_test_case_5),
14128
14129                 TEST_CASE_ST(ut_setup, ut_teardown,
14130                         test_snow3g_encryption_test_case_1_oop),
14131                 TEST_CASE_ST(ut_setup, ut_teardown,
14132                         test_snow3g_encryption_test_case_1_oop_sgl),
14133                 TEST_CASE_ST(ut_setup, ut_teardown,
14134                         test_snow3g_encryption_test_case_1_offset_oop),
14135                 TEST_CASE_ST(ut_setup, ut_teardown,
14136                         test_snow3g_decryption_test_case_1_oop),
14137
14138                 /** SNOW 3G generate auth, then encrypt (UEA2) */
14139                 TEST_CASE_ST(ut_setup, ut_teardown,
14140                         test_snow3g_auth_cipher_test_case_1),
14141                 TEST_CASE_ST(ut_setup, ut_teardown,
14142                         test_snow3g_auth_cipher_test_case_2),
14143                 TEST_CASE_ST(ut_setup, ut_teardown,
14144                         test_snow3g_auth_cipher_test_case_2_oop),
14145                 TEST_CASE_ST(ut_setup, ut_teardown,
14146                         test_snow3g_auth_cipher_part_digest_enc),
14147                 TEST_CASE_ST(ut_setup, ut_teardown,
14148                         test_snow3g_auth_cipher_part_digest_enc_oop),
14149                 TEST_CASE_ST(ut_setup, ut_teardown,
14150                         test_snow3g_auth_cipher_test_case_3_sgl),
14151                 TEST_CASE_ST(ut_setup, ut_teardown,
14152                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
14153                 TEST_CASE_ST(ut_setup, ut_teardown,
14154                         test_snow3g_auth_cipher_part_digest_enc_sgl),
14155                 TEST_CASE_ST(ut_setup, ut_teardown,
14156                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14157
14158                 /** SNOW 3G decrypt (UEA2), then verify auth */
14159                 TEST_CASE_ST(ut_setup, ut_teardown,
14160                         test_snow3g_auth_cipher_verify_test_case_1),
14161                 TEST_CASE_ST(ut_setup, ut_teardown,
14162                         test_snow3g_auth_cipher_verify_test_case_2),
14163                 TEST_CASE_ST(ut_setup, ut_teardown,
14164                         test_snow3g_auth_cipher_verify_test_case_2_oop),
14165                 TEST_CASE_ST(ut_setup, ut_teardown,
14166                         test_snow3g_auth_cipher_verify_part_digest_enc),
14167                 TEST_CASE_ST(ut_setup, ut_teardown,
14168                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14169                 TEST_CASE_ST(ut_setup, ut_teardown,
14170                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
14171                 TEST_CASE_ST(ut_setup, ut_teardown,
14172                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14173                 TEST_CASE_ST(ut_setup, ut_teardown,
14174                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14175                 TEST_CASE_ST(ut_setup, ut_teardown,
14176                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14177
14178                 /** SNOW 3G decrypt only (UEA2) */
14179                 TEST_CASE_ST(ut_setup, ut_teardown,
14180                         test_snow3g_decryption_test_case_1),
14181                 TEST_CASE_ST(ut_setup, ut_teardown,
14182                         test_snow3g_decryption_test_case_2),
14183                 TEST_CASE_ST(ut_setup, ut_teardown,
14184                         test_snow3g_decryption_test_case_3),
14185                 TEST_CASE_ST(ut_setup, ut_teardown,
14186                         test_snow3g_decryption_test_case_4),
14187                 TEST_CASE_ST(ut_setup, ut_teardown,
14188                         test_snow3g_decryption_test_case_5),
14189                 TEST_CASE_ST(ut_setup, ut_teardown,
14190                         test_snow3g_decryption_with_digest_test_case_1),
14191                 TEST_CASE_ST(ut_setup, ut_teardown,
14192                         test_snow3g_hash_generate_test_case_1),
14193                 TEST_CASE_ST(ut_setup, ut_teardown,
14194                         test_snow3g_hash_generate_test_case_2),
14195                 TEST_CASE_ST(ut_setup, ut_teardown,
14196                         test_snow3g_hash_generate_test_case_3),
14197
14198                 /* Tests with buffers which length is not byte-aligned */
14199                 TEST_CASE_ST(ut_setup, ut_teardown,
14200                         test_snow3g_hash_generate_test_case_4),
14201                 TEST_CASE_ST(ut_setup, ut_teardown,
14202                         test_snow3g_hash_generate_test_case_5),
14203                 TEST_CASE_ST(ut_setup, ut_teardown,
14204                         test_snow3g_hash_generate_test_case_6),
14205                 TEST_CASE_ST(ut_setup, ut_teardown,
14206                         test_snow3g_hash_verify_test_case_1),
14207                 TEST_CASE_ST(ut_setup, ut_teardown,
14208                         test_snow3g_hash_verify_test_case_2),
14209                 TEST_CASE_ST(ut_setup, ut_teardown,
14210                         test_snow3g_hash_verify_test_case_3),
14211
14212                 /* Tests with buffers which length is not byte-aligned */
14213                 TEST_CASE_ST(ut_setup, ut_teardown,
14214                         test_snow3g_hash_verify_test_case_4),
14215                 TEST_CASE_ST(ut_setup, ut_teardown,
14216                         test_snow3g_hash_verify_test_case_5),
14217                 TEST_CASE_ST(ut_setup, ut_teardown,
14218                         test_snow3g_hash_verify_test_case_6),
14219                 TEST_CASE_ST(ut_setup, ut_teardown,
14220                         test_snow3g_cipher_auth_test_case_1),
14221                 TEST_CASE_ST(ut_setup, ut_teardown,
14222                         test_snow3g_auth_cipher_with_digest_test_case_1),
14223                 TEST_CASES_END()
14224         }
14225 };
14226
14227 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14228         .suite_name = "ZUC Test Suite",
14229         .setup = zuc_testsuite_setup,
14230         .unit_test_cases = {
14231                 /** ZUC encrypt only (EEA3) */
14232                 TEST_CASE_ST(ut_setup, ut_teardown,
14233                         test_zuc_encryption_test_case_1),
14234                 TEST_CASE_ST(ut_setup, ut_teardown,
14235                         test_zuc_encryption_test_case_2),
14236                 TEST_CASE_ST(ut_setup, ut_teardown,
14237                         test_zuc_encryption_test_case_3),
14238                 TEST_CASE_ST(ut_setup, ut_teardown,
14239                         test_zuc_encryption_test_case_4),
14240                 TEST_CASE_ST(ut_setup, ut_teardown,
14241                         test_zuc_encryption_test_case_5),
14242                 TEST_CASE_ST(ut_setup, ut_teardown,
14243                         test_zuc_encryption_test_case_6_sgl),
14244
14245                 /** ZUC authenticate (EIA3) */
14246                 TEST_CASE_ST(ut_setup, ut_teardown,
14247                         test_zuc_hash_generate_test_case_1),
14248                 TEST_CASE_ST(ut_setup, ut_teardown,
14249                         test_zuc_hash_generate_test_case_2),
14250                 TEST_CASE_ST(ut_setup, ut_teardown,
14251                         test_zuc_hash_generate_test_case_3),
14252                 TEST_CASE_ST(ut_setup, ut_teardown,
14253                         test_zuc_hash_generate_test_case_4),
14254                 TEST_CASE_ST(ut_setup, ut_teardown,
14255                         test_zuc_hash_generate_test_case_5),
14256                 TEST_CASE_ST(ut_setup, ut_teardown,
14257                         test_zuc_hash_generate_test_case_6),
14258                 TEST_CASE_ST(ut_setup, ut_teardown,
14259                         test_zuc_hash_generate_test_case_7),
14260                 TEST_CASE_ST(ut_setup, ut_teardown,
14261                         test_zuc_hash_generate_test_case_8),
14262
14263                 /** ZUC alg-chain (EEA3/EIA3) */
14264                 TEST_CASE_ST(ut_setup, ut_teardown,
14265                         test_zuc_cipher_auth_test_case_1),
14266                 TEST_CASE_ST(ut_setup, ut_teardown,
14267                         test_zuc_cipher_auth_test_case_2),
14268
14269                 /** ZUC generate auth, then encrypt (EEA3) */
14270                 TEST_CASE_ST(ut_setup, ut_teardown,
14271                         test_zuc_auth_cipher_test_case_1),
14272                 TEST_CASE_ST(ut_setup, ut_teardown,
14273                         test_zuc_auth_cipher_test_case_1_oop),
14274                 TEST_CASE_ST(ut_setup, ut_teardown,
14275                         test_zuc_auth_cipher_test_case_1_sgl),
14276                 TEST_CASE_ST(ut_setup, ut_teardown,
14277                         test_zuc_auth_cipher_test_case_1_oop_sgl),
14278
14279                 /** ZUC decrypt (EEA3), then verify auth */
14280                 TEST_CASE_ST(ut_setup, ut_teardown,
14281                         test_zuc_auth_cipher_verify_test_case_1),
14282                 TEST_CASE_ST(ut_setup, ut_teardown,
14283                         test_zuc_auth_cipher_verify_test_case_1_oop),
14284                 TEST_CASE_ST(ut_setup, ut_teardown,
14285                         test_zuc_auth_cipher_verify_test_case_1_sgl),
14286                 TEST_CASE_ST(ut_setup, ut_teardown,
14287                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
14288                 TEST_CASES_END()
14289         }
14290 };
14291
14292 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
14293         .suite_name = "HMAC_MD5 Authentication Test Suite",
14294         .setup = hmac_md5_auth_testsuite_setup,
14295         .unit_test_cases = {
14296                 TEST_CASE_ST(ut_setup, ut_teardown,
14297                         test_MD5_HMAC_generate_case_1),
14298                 TEST_CASE_ST(ut_setup, ut_teardown,
14299                         test_MD5_HMAC_verify_case_1),
14300                 TEST_CASE_ST(ut_setup, ut_teardown,
14301                         test_MD5_HMAC_generate_case_2),
14302                 TEST_CASE_ST(ut_setup, ut_teardown,
14303                         test_MD5_HMAC_verify_case_2),
14304                 TEST_CASES_END()
14305         }
14306 };
14307
14308 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
14309         .suite_name = "Kasumi Test Suite",
14310         .setup = kasumi_testsuite_setup,
14311         .unit_test_cases = {
14312                 /** KASUMI hash only (UIA1) */
14313                 TEST_CASE_ST(ut_setup, ut_teardown,
14314                         test_kasumi_hash_generate_test_case_1),
14315                 TEST_CASE_ST(ut_setup, ut_teardown,
14316                         test_kasumi_hash_generate_test_case_2),
14317                 TEST_CASE_ST(ut_setup, ut_teardown,
14318                         test_kasumi_hash_generate_test_case_3),
14319                 TEST_CASE_ST(ut_setup, ut_teardown,
14320                         test_kasumi_hash_generate_test_case_4),
14321                 TEST_CASE_ST(ut_setup, ut_teardown,
14322                         test_kasumi_hash_generate_test_case_5),
14323                 TEST_CASE_ST(ut_setup, ut_teardown,
14324                         test_kasumi_hash_generate_test_case_6),
14325
14326                 TEST_CASE_ST(ut_setup, ut_teardown,
14327                         test_kasumi_hash_verify_test_case_1),
14328                 TEST_CASE_ST(ut_setup, ut_teardown,
14329                         test_kasumi_hash_verify_test_case_2),
14330                 TEST_CASE_ST(ut_setup, ut_teardown,
14331                         test_kasumi_hash_verify_test_case_3),
14332                 TEST_CASE_ST(ut_setup, ut_teardown,
14333                         test_kasumi_hash_verify_test_case_4),
14334                 TEST_CASE_ST(ut_setup, ut_teardown,
14335                         test_kasumi_hash_verify_test_case_5),
14336
14337                 /** KASUMI encrypt only (UEA1) */
14338                 TEST_CASE_ST(ut_setup, ut_teardown,
14339                         test_kasumi_encryption_test_case_1),
14340                 TEST_CASE_ST(ut_setup, ut_teardown,
14341                         test_kasumi_encryption_test_case_1_sgl),
14342                 TEST_CASE_ST(ut_setup, ut_teardown,
14343                         test_kasumi_encryption_test_case_1_oop),
14344                 TEST_CASE_ST(ut_setup, ut_teardown,
14345                         test_kasumi_encryption_test_case_1_oop_sgl),
14346                 TEST_CASE_ST(ut_setup, ut_teardown,
14347                         test_kasumi_encryption_test_case_2),
14348                 TEST_CASE_ST(ut_setup, ut_teardown,
14349                         test_kasumi_encryption_test_case_3),
14350                 TEST_CASE_ST(ut_setup, ut_teardown,
14351                         test_kasumi_encryption_test_case_4),
14352                 TEST_CASE_ST(ut_setup, ut_teardown,
14353                         test_kasumi_encryption_test_case_5),
14354
14355                 /** KASUMI decrypt only (UEA1) */
14356                 TEST_CASE_ST(ut_setup, ut_teardown,
14357                         test_kasumi_decryption_test_case_1),
14358                 TEST_CASE_ST(ut_setup, ut_teardown,
14359                         test_kasumi_decryption_test_case_2),
14360                 TEST_CASE_ST(ut_setup, ut_teardown,
14361                         test_kasumi_decryption_test_case_3),
14362                 TEST_CASE_ST(ut_setup, ut_teardown,
14363                         test_kasumi_decryption_test_case_4),
14364                 TEST_CASE_ST(ut_setup, ut_teardown,
14365                         test_kasumi_decryption_test_case_5),
14366                 TEST_CASE_ST(ut_setup, ut_teardown,
14367                         test_kasumi_decryption_test_case_1_oop),
14368
14369                 TEST_CASE_ST(ut_setup, ut_teardown,
14370                         test_kasumi_cipher_auth_test_case_1),
14371
14372                 /** KASUMI generate auth, then encrypt (F8) */
14373                 TEST_CASE_ST(ut_setup, ut_teardown,
14374                         test_kasumi_auth_cipher_test_case_1),
14375                 TEST_CASE_ST(ut_setup, ut_teardown,
14376                         test_kasumi_auth_cipher_test_case_2),
14377                 TEST_CASE_ST(ut_setup, ut_teardown,
14378                         test_kasumi_auth_cipher_test_case_2_oop),
14379                 TEST_CASE_ST(ut_setup, ut_teardown,
14380                         test_kasumi_auth_cipher_test_case_2_sgl),
14381                 TEST_CASE_ST(ut_setup, ut_teardown,
14382                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
14383
14384                 /** KASUMI decrypt (F8), then verify auth */
14385                 TEST_CASE_ST(ut_setup, ut_teardown,
14386                         test_kasumi_auth_cipher_verify_test_case_1),
14387                 TEST_CASE_ST(ut_setup, ut_teardown,
14388                         test_kasumi_auth_cipher_verify_test_case_2),
14389                 TEST_CASE_ST(ut_setup, ut_teardown,
14390                         test_kasumi_auth_cipher_verify_test_case_2_oop),
14391                 TEST_CASE_ST(ut_setup, ut_teardown,
14392                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
14393                 TEST_CASE_ST(ut_setup, ut_teardown,
14394                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
14395
14396                 TEST_CASES_END()
14397         }
14398 };
14399
14400 static struct unit_test_suite cryptodev_esn_testsuite  = {
14401         .suite_name = "ESN Test Suite",
14402         .setup = esn_testsuite_setup,
14403         .unit_test_cases = {
14404                 TEST_CASE_ST(ut_setup, ut_teardown,
14405                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
14406                 TEST_CASE_ST(ut_setup, ut_teardown,
14407                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
14408                 TEST_CASES_END()
14409         }
14410 };
14411
14412 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
14413         .suite_name = "Negative AES GCM Test Suite",
14414         .setup = negative_aes_gcm_testsuite_setup,
14415         .unit_test_cases = {
14416                 TEST_CASE_ST(ut_setup, ut_teardown,
14417                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
14418                 TEST_CASE_ST(ut_setup, ut_teardown,
14419                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
14420                 TEST_CASE_ST(ut_setup, ut_teardown,
14421                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
14422                 TEST_CASE_ST(ut_setup, ut_teardown,
14423                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
14424                 TEST_CASE_ST(ut_setup, ut_teardown,
14425                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
14426                 TEST_CASE_ST(ut_setup, ut_teardown,
14427                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
14428                 TEST_CASE_ST(ut_setup, ut_teardown,
14429                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
14430                 TEST_CASE_ST(ut_setup, ut_teardown,
14431                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
14432                 TEST_CASE_ST(ut_setup, ut_teardown,
14433                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
14434                 TEST_CASE_ST(ut_setup, ut_teardown,
14435                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
14436                 TEST_CASE_ST(ut_setup, ut_teardown,
14437                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
14438                 TEST_CASE_ST(ut_setup, ut_teardown,
14439                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
14440
14441                 TEST_CASES_END()
14442         }
14443 };
14444
14445 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
14446         .suite_name = "Negative AES GMAC Test Suite",
14447         .setup = negative_aes_gmac_testsuite_setup,
14448         .unit_test_cases = {
14449                 TEST_CASE_ST(ut_setup, ut_teardown,
14450                         authentication_verify_AES128_GMAC_fail_data_corrupt),
14451                 TEST_CASE_ST(ut_setup, ut_teardown,
14452                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
14453
14454                 TEST_CASES_END()
14455         }
14456 };
14457
14458 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
14459         .suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
14460         .setup = mixed_cipher_hash_testsuite_setup,
14461         .unit_test_cases = {
14462                 /** AUTH AES CMAC + CIPHER AES CTR */
14463                 TEST_CASE_ST(ut_setup, ut_teardown,
14464                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
14465                 TEST_CASE_ST(ut_setup, ut_teardown,
14466                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14467                 TEST_CASE_ST(ut_setup, ut_teardown,
14468                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14469                 TEST_CASE_ST(ut_setup, ut_teardown,
14470                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14471                 TEST_CASE_ST(ut_setup, ut_teardown,
14472                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
14473                 TEST_CASE_ST(ut_setup, ut_teardown,
14474                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14475                 TEST_CASE_ST(ut_setup, ut_teardown,
14476                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14477                 TEST_CASE_ST(ut_setup, ut_teardown,
14478                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14479
14480                 /** AUTH ZUC + CIPHER SNOW3G */
14481                 TEST_CASE_ST(ut_setup, ut_teardown,
14482                         test_auth_zuc_cipher_snow_test_case_1),
14483                 TEST_CASE_ST(ut_setup, ut_teardown,
14484                         test_verify_auth_zuc_cipher_snow_test_case_1),
14485                 /** AUTH AES CMAC + CIPHER SNOW3G */
14486                 TEST_CASE_ST(ut_setup, ut_teardown,
14487                         test_auth_aes_cmac_cipher_snow_test_case_1),
14488                 TEST_CASE_ST(ut_setup, ut_teardown,
14489                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
14490                 /** AUTH ZUC + CIPHER AES CTR */
14491                 TEST_CASE_ST(ut_setup, ut_teardown,
14492                         test_auth_zuc_cipher_aes_ctr_test_case_1),
14493                 TEST_CASE_ST(ut_setup, ut_teardown,
14494                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
14495                 /** AUTH SNOW3G + CIPHER AES CTR */
14496                 TEST_CASE_ST(ut_setup, ut_teardown,
14497                         test_auth_snow_cipher_aes_ctr_test_case_1),
14498                 TEST_CASE_ST(ut_setup, ut_teardown,
14499                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
14500                 /** AUTH SNOW3G + CIPHER ZUC */
14501                 TEST_CASE_ST(ut_setup, ut_teardown,
14502                         test_auth_snow_cipher_zuc_test_case_1),
14503                 TEST_CASE_ST(ut_setup, ut_teardown,
14504                         test_verify_auth_snow_cipher_zuc_test_case_1),
14505                 /** AUTH AES CMAC + CIPHER ZUC */
14506                 TEST_CASE_ST(ut_setup, ut_teardown,
14507                         test_auth_aes_cmac_cipher_zuc_test_case_1),
14508                 TEST_CASE_ST(ut_setup, ut_teardown,
14509                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
14510
14511                 /** AUTH NULL + CIPHER SNOW3G */
14512                 TEST_CASE_ST(ut_setup, ut_teardown,
14513                         test_auth_null_cipher_snow_test_case_1),
14514                 TEST_CASE_ST(ut_setup, ut_teardown,
14515                         test_verify_auth_null_cipher_snow_test_case_1),
14516                 /** AUTH NULL + CIPHER ZUC */
14517                 TEST_CASE_ST(ut_setup, ut_teardown,
14518                         test_auth_null_cipher_zuc_test_case_1),
14519                 TEST_CASE_ST(ut_setup, ut_teardown,
14520                         test_verify_auth_null_cipher_zuc_test_case_1),
14521                 /** AUTH SNOW3G + CIPHER NULL */
14522                 TEST_CASE_ST(ut_setup, ut_teardown,
14523                         test_auth_snow_cipher_null_test_case_1),
14524                 TEST_CASE_ST(ut_setup, ut_teardown,
14525                         test_verify_auth_snow_cipher_null_test_case_1),
14526                 /** AUTH ZUC + CIPHER NULL */
14527                 TEST_CASE_ST(ut_setup, ut_teardown,
14528                         test_auth_zuc_cipher_null_test_case_1),
14529                 TEST_CASE_ST(ut_setup, ut_teardown,
14530                         test_verify_auth_zuc_cipher_null_test_case_1),
14531                 /** AUTH NULL + CIPHER AES CTR */
14532                 TEST_CASE_ST(ut_setup, ut_teardown,
14533                         test_auth_null_cipher_aes_ctr_test_case_1),
14534                 TEST_CASE_ST(ut_setup, ut_teardown,
14535                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
14536                 /** AUTH AES CMAC + CIPHER NULL */
14537                 TEST_CASE_ST(ut_setup, ut_teardown,
14538                         test_auth_aes_cmac_cipher_null_test_case_1),
14539                 TEST_CASE_ST(ut_setup, ut_teardown,
14540                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
14541                 TEST_CASES_END()
14542         }
14543 };
14544
14545 static int
14546 run_cryptodev_testsuite(const char *pmd_name)
14547 {
14548         uint8_t ret, j, i = 0;
14549         struct unit_test_suite *static_suites[] = {
14550                 &cryptodev_multi_session_testsuite,
14551                 &cryptodev_null_testsuite,
14552                 &cryptodev_aes_ccm_auth_testsuite,
14553                 &cryptodev_aes_gcm_auth_testsuite,
14554                 &cryptodev_aes_gmac_auth_testsuite,
14555                 &cryptodev_snow3g_testsuite,
14556                 &cryptodev_chacha20_poly1305_testsuite,
14557                 &cryptodev_zuc_testsuite,
14558                 &cryptodev_hmac_md5_auth_testsuite,
14559                 &cryptodev_kasumi_testsuite,
14560                 &cryptodev_esn_testsuite,
14561                 &cryptodev_negative_aes_gcm_testsuite,
14562                 &cryptodev_negative_aes_gmac_testsuite,
14563                 &cryptodev_mixed_cipher_hash_testsuite,
14564                 &cryptodev_negative_hmac_sha1_testsuite,
14565                 &cryptodev_gen_testsuite,
14566 #ifdef RTE_LIB_SECURITY
14567                 &pdcp_proto_testsuite,
14568                 &docsis_proto_testsuite,
14569 #endif
14570                 &end_testsuite
14571         };
14572         static struct unit_test_suite ts = {
14573                 .suite_name = "Cryptodev Unit Test Suite",
14574                 .setup = testsuite_setup,
14575                 .teardown = testsuite_teardown,
14576                 .unit_test_cases = {TEST_CASES_END()}
14577         };
14578
14579         gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
14580
14581         if (gbl_driver_id == -1) {
14582                 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
14583                 return TEST_FAILED;
14584         }
14585
14586         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
14587                         RTE_DIM(static_suites));
14588
14589         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
14590         ret = unit_test_suite_runner(&ts);
14591
14592         free(ts.unit_test_suites);
14593         return ret;
14594 }
14595
14596 static int
14597 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
14598 {
14599         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14600 }
14601
14602 static int
14603 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
14604 {
14605         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
14606 }
14607
14608 static int
14609 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
14610 {
14611         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14612 }
14613
14614 static int
14615 test_cryptodev_cpu_aesni_mb(void)
14616 {
14617         int32_t rc;
14618         enum rte_security_session_action_type at = gbl_action_type;
14619         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14620         rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14621         gbl_action_type = at;
14622         return rc;
14623 }
14624
14625 static int
14626 test_cryptodev_openssl(void)
14627 {
14628         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
14629 }
14630
14631 static int
14632 test_cryptodev_aesni_gcm(void)
14633 {
14634         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14635 }
14636
14637 static int
14638 test_cryptodev_cpu_aesni_gcm(void)
14639 {
14640         int32_t rc;
14641         enum rte_security_session_action_type at = gbl_action_type;
14642         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14643         rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14644         gbl_action_type = at;
14645         return rc;
14646 }
14647
14648 static int
14649 test_cryptodev_null(void)
14650 {
14651         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
14652 }
14653
14654 static int
14655 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
14656 {
14657         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
14658 }
14659
14660 static int
14661 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
14662 {
14663         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
14664 }
14665
14666 static int
14667 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
14668 {
14669         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
14670 }
14671
14672 static int
14673 test_cryptodev_armv8(void)
14674 {
14675         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
14676 }
14677
14678 static int
14679 test_cryptodev_mrvl(void)
14680 {
14681         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
14682 }
14683
14684 #ifdef RTE_CRYPTO_SCHEDULER
14685
14686 static int
14687 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
14688 {
14689         uint8_t ret, j, i = 0;
14690         static struct unit_test_suite scheduler_multicore = {
14691                 .suite_name = "Scheduler Multicore Unit Test Suite",
14692                 .setup = scheduler_multicore_testsuite_setup,
14693                 .teardown = scheduler_mode_testsuite_teardown,
14694                 .unit_test_cases = {
14695                         TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
14696                         TEST_CASE_ST(ut_setup, ut_teardown,
14697                                         test_AES_cipheronly_all),
14698                         TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
14699                         TEST_CASES_END()
14700                 }
14701         };
14702         static struct unit_test_suite scheduler_round_robin = {
14703                 .suite_name = "Scheduler Round Robin Unit Test Suite",
14704                 .setup = scheduler_roundrobin_testsuite_setup,
14705                 .teardown = scheduler_mode_testsuite_teardown,
14706                 .unit_test_cases = {
14707                         TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
14708                         TEST_CASE_ST(ut_setup, ut_teardown,
14709                                         test_AES_cipheronly_all),
14710                         TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
14711                         TEST_CASES_END()
14712                 }
14713         };
14714         static struct unit_test_suite scheduler_failover = {
14715                 .suite_name = "Scheduler Failover Unit Test Suite",
14716                 .setup = scheduler_failover_testsuite_setup,
14717                 .teardown = scheduler_mode_testsuite_teardown,
14718                 .unit_test_cases = {
14719                         TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
14720                         TEST_CASE_ST(ut_setup, ut_teardown,
14721                                         test_AES_cipheronly_all),
14722                         TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
14723                         TEST_CASES_END()
14724                 }
14725         };
14726         static struct unit_test_suite scheduler_pkt_size_distr = {
14727                 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
14728                 .setup = scheduler_pkt_size_distr_testsuite_setup,
14729                 .teardown = scheduler_mode_testsuite_teardown,
14730                 .unit_test_cases = {
14731                         TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
14732                         TEST_CASE_ST(ut_setup, ut_teardown,
14733                                         test_AES_cipheronly_all),
14734                         TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
14735                         TEST_CASES_END()
14736                 }
14737         };
14738         struct unit_test_suite *sched_mode_suites[] = {
14739                 &scheduler_multicore,
14740                 &scheduler_round_robin,
14741                 &scheduler_failover,
14742                 &scheduler_pkt_size_distr
14743         };
14744         static struct unit_test_suite scheduler_config = {
14745                 .suite_name = "Crypto Device Scheduler Config Unit Test Suite",
14746                 .unit_test_cases = {
14747                         TEST_CASE(test_scheduler_attach_slave_op),
14748                         TEST_CASE(test_scheduler_mode_multicore_op),
14749                         TEST_CASE(test_scheduler_mode_roundrobin_op),
14750                         TEST_CASE(test_scheduler_mode_failover_op),
14751                         TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
14752                         TEST_CASE(test_scheduler_detach_slave_op),
14753
14754                         TEST_CASES_END() /**< NULL terminate array */
14755                 }
14756         };
14757         struct unit_test_suite *static_suites[] = {
14758                 &scheduler_config,
14759                 &end_testsuite
14760         };
14761         static struct unit_test_suite ts = {
14762                 .suite_name = "Scheduler Unit Test Suite",
14763                 .setup = scheduler_testsuite_setup,
14764                 .teardown = testsuite_teardown,
14765                 .unit_test_cases = {TEST_CASES_END()}
14766         };
14767
14768         gbl_driver_id = rte_cryptodev_driver_id_get(
14769                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14770
14771         if (gbl_driver_id == -1) {
14772                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
14773                 return TEST_SKIPPED;
14774         }
14775
14776         if (rte_cryptodev_driver_id_get(
14777                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
14778                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
14779                 return TEST_SKIPPED;
14780         }
14781
14782         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
14783                         (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
14784         ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
14785                         RTE_DIM(sched_mode_suites));
14786         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
14787         ret = unit_test_suite_runner(&ts);
14788
14789         free(ts.unit_test_suites);
14790         return ret;
14791 }
14792
14793 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
14794
14795 #endif
14796
14797 static int
14798 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
14799 {
14800         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
14801 }
14802
14803 static int
14804 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
14805 {
14806         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
14807 }
14808
14809 static int
14810 test_cryptodev_ccp(void)
14811 {
14812         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
14813 }
14814
14815 static int
14816 test_cryptodev_octeontx(void)
14817 {
14818         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
14819 }
14820
14821 static int
14822 test_cryptodev_octeontx2(void)
14823 {
14824         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
14825 }
14826
14827 static int
14828 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/)
14829 {
14830         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
14831 }
14832
14833 static int
14834 test_cryptodev_nitrox(void)
14835 {
14836         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
14837 }
14838
14839 static int
14840 test_cryptodev_bcmfs(void)
14841 {
14842         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
14843 }
14844
14845 static int
14846 test_cryptodev_qat_raw_api(void /*argv __rte_unused, int argc __rte_unused*/)
14847 {
14848         int ret;
14849
14850         global_api_test_type = CRYPTODEV_RAW_API_TEST;
14851         ret = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14852         global_api_test_type = CRYPTODEV_API_TEST;
14853
14854         return ret;
14855 }
14856
14857 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
14858                 test_cryptodev_qat_raw_api);
14859 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
14860 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
14861 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
14862         test_cryptodev_cpu_aesni_mb);
14863 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
14864 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
14865 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
14866         test_cryptodev_cpu_aesni_gcm);
14867 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
14868 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
14869 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
14870 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
14871 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
14872 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
14873 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
14874 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
14875 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
14876 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
14877 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
14878 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
14879 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
14880 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
14881 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);