5f0d02345132dad9aa6663c0d05845abcacb1e30
[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_ip.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_ipsec.h"
46 #include "test_cryptodev_security_ipsec_test_vectors.h"
47 #include "test_cryptodev_security_pdcp_test_vectors.h"
48 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
49 #include "test_cryptodev_security_pdcp_test_func.h"
50 #include "test_cryptodev_security_docsis_test_vectors.h"
51
52 #define SDAP_DISABLED   0
53 #define SDAP_ENABLED    1
54 #endif
55
56 #define VDEV_ARGS_SIZE 100
57 #define MAX_NB_SESSIONS 4
58
59 #define MAX_DRV_SERVICE_CTX_SIZE 256
60
61 #define MAX_RAW_DEQUEUE_COUNT   65535
62
63 #define IN_PLACE 0
64 #define OUT_OF_PLACE 1
65
66 static int gbl_driver_id;
67
68 static enum rte_security_session_action_type gbl_action_type =
69         RTE_SECURITY_ACTION_TYPE_NONE;
70
71 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
72
73 struct crypto_unittest_params {
74         struct rte_crypto_sym_xform cipher_xform;
75         struct rte_crypto_sym_xform auth_xform;
76         struct rte_crypto_sym_xform aead_xform;
77 #ifdef RTE_LIB_SECURITY
78         struct rte_security_docsis_xform docsis_xform;
79 #endif
80
81         union {
82                 struct rte_cryptodev_sym_session *sess;
83 #ifdef RTE_LIB_SECURITY
84                 struct rte_security_session *sec_session;
85 #endif
86         };
87 #ifdef RTE_LIB_SECURITY
88         enum rte_security_session_action_type type;
89 #endif
90         struct rte_crypto_op *op;
91
92         struct rte_mbuf *obuf, *ibuf;
93
94         uint8_t *digest;
95 };
96
97 #define ALIGN_POW2_ROUNDUP(num, align) \
98         (((num) + (align) - 1) & ~((align) - 1))
99
100 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)  \
101         for (j = 0; j < num_child_ts; index++, j++)                     \
102                 parent_ts.unit_test_suites[index] = child_ts[j]
103
104 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)   \
105         for (j = 0; j < num_blk_types; index++, j++)                            \
106                 parent_ts.unit_test_suites[index] =                             \
107                                 build_blockcipher_test_suite(blk_types[j])
108
109 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)             \
110         for (j = index; j < index + num_blk_types; j++)                         \
111                 free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
112
113 /*
114  * Forward declarations.
115  */
116 static int
117 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
118                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
119                 uint8_t *hmac_key);
120
121 static int
122 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
123                 struct crypto_unittest_params *ut_params,
124                 struct crypto_testsuite_params *ts_param,
125                 const uint8_t *cipher,
126                 const uint8_t *digest,
127                 const uint8_t *iv);
128
129 static int
130 security_proto_supported(enum rte_security_session_action_type action,
131         enum rte_security_session_protocol proto);
132
133 static int
134 dev_configure_and_start(uint64_t ff_disable);
135
136 static struct rte_mbuf *
137 setup_test_string(struct rte_mempool *mpool,
138                 const char *string, size_t len, uint8_t blocksize)
139 {
140         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
141         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
142
143         if (m) {
144                 char *dst;
145
146                 memset(m->buf_addr, 0, m->buf_len);
147                 dst = rte_pktmbuf_append(m, t_len);
148                 if (!dst) {
149                         rte_pktmbuf_free(m);
150                         return NULL;
151                 }
152                 if (string != NULL)
153                         rte_memcpy(dst, string, t_len);
154                 else
155                         memset(dst, 0, t_len);
156         }
157
158         return m;
159 }
160
161 /* Get number of bytes in X bits (rounding up) */
162 static uint32_t
163 ceil_byte_length(uint32_t num_bits)
164 {
165         if (num_bits % 8)
166                 return ((num_bits >> 3) + 1);
167         else
168                 return (num_bits >> 3);
169 }
170
171 static void
172 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused,
173                 uint8_t is_op_success)
174 {
175         struct rte_crypto_op *op = user_data;
176         op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
177                         RTE_CRYPTO_OP_STATUS_ERROR;
178 }
179
180 void
181 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
182                 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
183                 uint8_t len_in_bits, uint8_t cipher_iv_len)
184 {
185         struct rte_crypto_sym_op *sop = op->sym;
186         struct rte_crypto_op *ret_op = NULL;
187         struct rte_crypto_vec data_vec[UINT8_MAX];
188         struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
189         union rte_crypto_sym_ofs ofs;
190         struct rte_crypto_sym_vec vec;
191         struct rte_crypto_sgl sgl;
192         uint32_t max_len;
193         union rte_cryptodev_session_ctx sess;
194         uint32_t count = 0;
195         struct rte_crypto_raw_dp_ctx *ctx;
196         uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
197                         auth_len = 0;
198         int32_t n;
199         uint32_t n_success;
200         int ctx_service_size;
201         int32_t status = 0;
202         int enqueue_status, dequeue_status;
203
204         ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
205         if (ctx_service_size < 0) {
206                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
207                 return;
208         }
209
210         ctx = malloc(ctx_service_size);
211         if (!ctx) {
212                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
213                 return;
214         }
215
216         /* Both are enums, setting crypto_sess will suit any session type */
217         sess.crypto_sess = op->sym->session;
218
219         if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
220                         op->sess_type, sess, 0) < 0) {
221                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
222                 goto exit;
223         }
224
225         cipher_iv.iova = 0;
226         cipher_iv.va = NULL;
227         aad_auth_iv.iova = 0;
228         aad_auth_iv.va = NULL;
229         digest.iova = 0;
230         digest.va = NULL;
231         sgl.vec = data_vec;
232         vec.num = 1;
233         vec.sgl = &sgl;
234         vec.iv = &cipher_iv;
235         vec.digest = &digest;
236         vec.aad = &aad_auth_iv;
237         vec.status = &status;
238
239         ofs.raw = 0;
240
241         if (is_cipher && is_auth) {
242                 cipher_offset = sop->cipher.data.offset;
243                 cipher_len = sop->cipher.data.length;
244                 auth_offset = sop->auth.data.offset;
245                 auth_len = sop->auth.data.length;
246                 max_len = RTE_MAX(cipher_offset + cipher_len,
247                                 auth_offset + auth_len);
248                 if (len_in_bits) {
249                         max_len = max_len >> 3;
250                         cipher_offset = cipher_offset >> 3;
251                         auth_offset = auth_offset >> 3;
252                         cipher_len = cipher_len >> 3;
253                         auth_len = auth_len >> 3;
254                 }
255                 ofs.ofs.cipher.head = cipher_offset;
256                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
257                 ofs.ofs.auth.head = auth_offset;
258                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
259                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
260                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
261                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
262                                 op, void *, IV_OFFSET + cipher_iv_len);
263                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
264                                 cipher_iv_len);
265                 digest.va = (void *)sop->auth.digest.data;
266                 digest.iova = sop->auth.digest.phys_addr;
267
268         } else if (is_cipher) {
269                 cipher_offset = sop->cipher.data.offset;
270                 cipher_len = sop->cipher.data.length;
271                 max_len = cipher_len + cipher_offset;
272                 if (len_in_bits) {
273                         max_len = max_len >> 3;
274                         cipher_offset = cipher_offset >> 3;
275                         cipher_len = cipher_len >> 3;
276                 }
277                 ofs.ofs.cipher.head = cipher_offset;
278                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
279                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
280                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
281
282         } else if (is_auth) {
283                 auth_offset = sop->auth.data.offset;
284                 auth_len = sop->auth.data.length;
285                 max_len = auth_len + auth_offset;
286                 if (len_in_bits) {
287                         max_len = max_len >> 3;
288                         auth_offset = auth_offset >> 3;
289                         auth_len = auth_len >> 3;
290                 }
291                 ofs.ofs.auth.head = auth_offset;
292                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
293                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
294                                 op, void *, IV_OFFSET + cipher_iv_len);
295                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
296                                 cipher_iv_len);
297                 digest.va = (void *)sop->auth.digest.data;
298                 digest.iova = sop->auth.digest.phys_addr;
299
300         } else { /* aead */
301                 cipher_offset = sop->aead.data.offset;
302                 cipher_len = sop->aead.data.length;
303                 max_len = cipher_len + cipher_offset;
304                 if (len_in_bits) {
305                         max_len = max_len >> 3;
306                         cipher_offset = cipher_offset >> 3;
307                         cipher_len = cipher_len >> 3;
308                 }
309                 ofs.ofs.cipher.head = cipher_offset;
310                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
311                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
312                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
313                 aad_auth_iv.va = (void *)sop->aead.aad.data;
314                 aad_auth_iv.iova = sop->aead.aad.phys_addr;
315                 digest.va = (void *)sop->aead.digest.data;
316                 digest.iova = sop->aead.digest.phys_addr;
317         }
318
319         n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
320                         data_vec, RTE_DIM(data_vec));
321         if (n < 0 || n > sop->m_src->nb_segs) {
322                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
323                 goto exit;
324         }
325
326         sgl.num = n;
327
328         if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
329                         &enqueue_status) < 1) {
330                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
331                 goto exit;
332         }
333
334         if (enqueue_status == 0) {
335                 status = rte_cryptodev_raw_enqueue_done(ctx, 1);
336                 if (status < 0) {
337                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
338                         goto exit;
339                 }
340         } else if (enqueue_status < 0) {
341                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
342                 goto exit;
343         }
344
345         n = n_success = 0;
346         while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
347                 n = rte_cryptodev_raw_dequeue_burst(ctx,
348                         NULL, 1, post_process_raw_dp_op,
349                                 (void **)&ret_op, 0, &n_success,
350                                 &dequeue_status);
351                 if (dequeue_status < 0) {
352                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
353                         goto exit;
354                 }
355                 if (n == 0)
356                         rte_pause();
357         }
358
359         if (n == 1 && dequeue_status == 0) {
360                 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
361                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
362                         goto exit;
363                 }
364         }
365
366         op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
367                         n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
368                                         RTE_CRYPTO_OP_STATUS_SUCCESS;
369
370 exit:
371         free(ctx);
372 }
373
374 static void
375 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
376 {
377         int32_t n, st;
378         struct rte_crypto_sym_op *sop;
379         union rte_crypto_sym_ofs ofs;
380         struct rte_crypto_sgl sgl;
381         struct rte_crypto_sym_vec symvec;
382         struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
383         struct rte_crypto_vec vec[UINT8_MAX];
384
385         sop = op->sym;
386
387         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
388                 sop->aead.data.length, vec, RTE_DIM(vec));
389
390         if (n < 0 || n != sop->m_src->nb_segs) {
391                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
392                 return;
393         }
394
395         sgl.vec = vec;
396         sgl.num = n;
397         symvec.sgl = &sgl;
398         symvec.iv = &iv_ptr;
399         symvec.digest = &digest_ptr;
400         symvec.aad = &aad_ptr;
401         symvec.status = &st;
402         symvec.num = 1;
403
404         /* for CPU crypto the IOVA address is not required */
405         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
406         digest_ptr.va = (void *)sop->aead.digest.data;
407         aad_ptr.va = (void *)sop->aead.aad.data;
408
409         ofs.raw = 0;
410
411         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
412                 &symvec);
413
414         if (n != 1)
415                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
416         else
417                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
418 }
419
420 static void
421 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
422 {
423         int32_t n, st;
424         struct rte_crypto_sym_op *sop;
425         union rte_crypto_sym_ofs ofs;
426         struct rte_crypto_sgl sgl;
427         struct rte_crypto_sym_vec symvec;
428         struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
429         struct rte_crypto_vec vec[UINT8_MAX];
430
431         sop = op->sym;
432
433         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
434                 sop->auth.data.length, vec, RTE_DIM(vec));
435
436         if (n < 0 || n != sop->m_src->nb_segs) {
437                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
438                 return;
439         }
440
441         sgl.vec = vec;
442         sgl.num = n;
443         symvec.sgl = &sgl;
444         symvec.iv = &iv_ptr;
445         symvec.digest = &digest_ptr;
446         symvec.status = &st;
447         symvec.num = 1;
448
449         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
450         digest_ptr.va = (void *)sop->auth.digest.data;
451
452         ofs.raw = 0;
453         ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
454         ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
455                 (sop->cipher.data.offset + sop->cipher.data.length);
456
457         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
458                 &symvec);
459
460         if (n != 1)
461                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
462         else
463                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
464 }
465
466 static struct rte_crypto_op *
467 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
468 {
469
470         RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
471
472         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
473                 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
474                 return NULL;
475         }
476
477         op = NULL;
478
479         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
480                 rte_pause();
481
482         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
483                 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
484                 return NULL;
485         }
486
487         return op;
488 }
489
490 static struct crypto_testsuite_params testsuite_params = { NULL };
491 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
492 static struct crypto_unittest_params unittest_params;
493
494 static int
495 testsuite_setup(void)
496 {
497         struct crypto_testsuite_params *ts_params = &testsuite_params;
498         struct rte_cryptodev_info info;
499         uint32_t i = 0, nb_devs, dev_id;
500         uint16_t qp_id;
501
502         memset(ts_params, 0, sizeof(*ts_params));
503
504         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
505         if (ts_params->mbuf_pool == NULL) {
506                 /* Not already created so create */
507                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
508                                 "CRYPTO_MBUFPOOL",
509                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
510                                 rte_socket_id());
511                 if (ts_params->mbuf_pool == NULL) {
512                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
513                         return TEST_FAILED;
514                 }
515         }
516
517         ts_params->large_mbuf_pool = rte_mempool_lookup(
518                         "CRYPTO_LARGE_MBUFPOOL");
519         if (ts_params->large_mbuf_pool == NULL) {
520                 /* Not already created so create */
521                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
522                                 "CRYPTO_LARGE_MBUFPOOL",
523                                 1, 0, 0, UINT16_MAX,
524                                 rte_socket_id());
525                 if (ts_params->large_mbuf_pool == NULL) {
526                         RTE_LOG(ERR, USER1,
527                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
528                         return TEST_FAILED;
529                 }
530         }
531
532         ts_params->op_mpool = rte_crypto_op_pool_create(
533                         "MBUF_CRYPTO_SYM_OP_POOL",
534                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
535                         NUM_MBUFS, MBUF_CACHE_SIZE,
536                         DEFAULT_NUM_XFORMS *
537                         sizeof(struct rte_crypto_sym_xform) +
538                         MAXIMUM_IV_LENGTH,
539                         rte_socket_id());
540         if (ts_params->op_mpool == NULL) {
541                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
542                 return TEST_FAILED;
543         }
544
545         nb_devs = rte_cryptodev_count();
546         if (nb_devs < 1) {
547                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
548                 return TEST_SKIPPED;
549         }
550
551         if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
552                 RTE_LOG(WARNING, USER1, "No %s devices found?\n",
553                                 rte_cryptodev_driver_name_get(gbl_driver_id));
554                 return TEST_SKIPPED;
555         }
556
557         /* Create list of valid crypto devs */
558         for (i = 0; i < nb_devs; i++) {
559                 rte_cryptodev_info_get(i, &info);
560                 if (info.driver_id == gbl_driver_id)
561                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
562         }
563
564         if (ts_params->valid_dev_count < 1)
565                 return TEST_FAILED;
566
567         /* Set up all the qps on the first of the valid devices found */
568
569         dev_id = ts_params->valid_devs[0];
570
571         rte_cryptodev_info_get(dev_id, &info);
572
573         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
574         ts_params->conf.socket_id = SOCKET_ID_ANY;
575         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
576
577         unsigned int session_size =
578                 rte_cryptodev_sym_get_private_session_size(dev_id);
579
580 #ifdef RTE_LIB_SECURITY
581         unsigned int security_session_size = rte_security_session_get_size(
582                         rte_cryptodev_get_sec_ctx(dev_id));
583
584         if (session_size < security_session_size)
585                 session_size = security_session_size;
586 #endif
587         /*
588          * Create mempool with maximum number of sessions.
589          */
590         if (info.sym.max_nb_sessions != 0 &&
591                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
592                 RTE_LOG(ERR, USER1, "Device does not support "
593                                 "at least %u sessions\n",
594                                 MAX_NB_SESSIONS);
595                 return TEST_FAILED;
596         }
597
598         ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
599                         "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
600                         SOCKET_ID_ANY);
601         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
602                         "session mempool allocation failed");
603
604         ts_params->session_priv_mpool = rte_mempool_create(
605                         "test_sess_mp_priv",
606                         MAX_NB_SESSIONS,
607                         session_size,
608                         0, 0, NULL, NULL, NULL,
609                         NULL, SOCKET_ID_ANY,
610                         0);
611         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
612                         "session mempool allocation failed");
613
614
615
616         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
617                         &ts_params->conf),
618                         "Failed to configure cryptodev %u with %u qps",
619                         dev_id, ts_params->conf.nb_queue_pairs);
620
621         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
622         ts_params->qp_conf.mp_session = ts_params->session_mpool;
623         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
624
625         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
626                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
627                         dev_id, qp_id, &ts_params->qp_conf,
628                         rte_cryptodev_socket_id(dev_id)),
629                         "Failed to setup queue pair %u on cryptodev %u",
630                         qp_id, dev_id);
631         }
632
633         return TEST_SUCCESS;
634 }
635
636 static void
637 testsuite_teardown(void)
638 {
639         struct crypto_testsuite_params *ts_params = &testsuite_params;
640         int res;
641
642         if (ts_params->mbuf_pool != NULL) {
643                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
644                 rte_mempool_avail_count(ts_params->mbuf_pool));
645         }
646
647         if (ts_params->op_mpool != NULL) {
648                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
649                 rte_mempool_avail_count(ts_params->op_mpool));
650         }
651
652         /* Free session mempools */
653         if (ts_params->session_priv_mpool != NULL) {
654                 rte_mempool_free(ts_params->session_priv_mpool);
655                 ts_params->session_priv_mpool = NULL;
656         }
657
658         if (ts_params->session_mpool != NULL) {
659                 rte_mempool_free(ts_params->session_mpool);
660                 ts_params->session_mpool = NULL;
661         }
662
663         res = rte_cryptodev_close(ts_params->valid_devs[0]);
664         if (res)
665                 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
666 }
667
668 static int
669 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
670                 const int *algs, uint16_t num_algs)
671 {
672         uint8_t dev_id = testsuite_params.valid_devs[0];
673         bool some_alg_supported = FALSE;
674         uint16_t i;
675
676         for (i = 0; i < num_algs && !some_alg_supported; i++) {
677                 struct rte_cryptodev_sym_capability_idx alg = {
678                         type, {algs[i]}
679                 };
680                 if (rte_cryptodev_sym_capability_get(dev_id,
681                                 &alg) != NULL)
682                         some_alg_supported = TRUE;
683         }
684         if (!some_alg_supported)
685                 return TEST_SKIPPED;
686
687         return 0;
688 }
689
690 int
691 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
692                 uint16_t num_ciphers)
693 {
694         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
695                         (const int *) ciphers, num_ciphers);
696 }
697
698 int
699 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
700                 uint16_t num_auths)
701 {
702         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
703                         (const int *) auths, num_auths);
704 }
705
706 int
707 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
708                 uint16_t num_aeads)
709 {
710         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
711                         (const int *) aeads, num_aeads);
712 }
713
714 static int
715 null_testsuite_setup(void)
716 {
717         struct crypto_testsuite_params *ts_params = &testsuite_params;
718         uint8_t dev_id = ts_params->valid_devs[0];
719         struct rte_cryptodev_info dev_info;
720         const enum rte_crypto_cipher_algorithm ciphers[] = {
721                 RTE_CRYPTO_CIPHER_NULL
722         };
723         const enum rte_crypto_auth_algorithm auths[] = {
724                 RTE_CRYPTO_AUTH_NULL
725         };
726
727         rte_cryptodev_info_get(dev_id, &dev_info);
728
729         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
730                 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
731                                 "testsuite not met\n");
732                 return TEST_SKIPPED;
733         }
734
735         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
736                         && check_auth_capabilities_supported(auths,
737                         RTE_DIM(auths)) != 0) {
738                 RTE_LOG(INFO, USER1, "Capability requirements for NULL "
739                                 "testsuite not met\n");
740                 return TEST_SKIPPED;
741         }
742
743         return 0;
744 }
745
746 static int
747 crypto_gen_testsuite_setup(void)
748 {
749         struct crypto_testsuite_params *ts_params = &testsuite_params;
750         uint8_t dev_id = ts_params->valid_devs[0];
751         struct rte_cryptodev_info dev_info;
752
753         rte_cryptodev_info_get(dev_id, &dev_info);
754
755         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
756                 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
757                                 "testsuite not met\n");
758                 return TEST_SKIPPED;
759         }
760
761         return 0;
762 }
763
764 #ifdef RTE_LIB_SECURITY
765 static int
766 ipsec_proto_testsuite_setup(void)
767 {
768         struct crypto_testsuite_params *ts_params = &testsuite_params;
769         struct crypto_unittest_params *ut_params = &unittest_params;
770         struct rte_cryptodev_info dev_info;
771         int ret = 0;
772
773         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
774
775         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
776                 RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto "
777                                 "testsuite not met\n");
778                 return TEST_SKIPPED;
779         }
780
781         /* Reconfigure to enable security */
782         ret = dev_configure_and_start(0);
783         if (ret != TEST_SUCCESS)
784                 return ret;
785
786         /* Set action type */
787         ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
788
789         if (security_proto_supported(
790                         RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
791                         RTE_SECURITY_PROTOCOL_IPSEC) < 0) {
792                 RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto "
793                                 "test not met\n");
794                 ret = TEST_SKIPPED;
795         }
796
797         /*
798          * Stop the device. Device would be started again by individual test
799          * case setup routine.
800          */
801         rte_cryptodev_stop(ts_params->valid_devs[0]);
802
803         return ret;
804 }
805
806 static int
807 pdcp_proto_testsuite_setup(void)
808 {
809         struct crypto_testsuite_params *ts_params = &testsuite_params;
810         uint8_t dev_id = ts_params->valid_devs[0];
811         struct rte_cryptodev_info dev_info;
812         const enum rte_crypto_cipher_algorithm ciphers[] = {
813                 RTE_CRYPTO_CIPHER_NULL,
814                 RTE_CRYPTO_CIPHER_AES_CTR,
815                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
816                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
817         };
818         const enum rte_crypto_auth_algorithm auths[] = {
819                 RTE_CRYPTO_AUTH_NULL,
820                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
821                 RTE_CRYPTO_AUTH_AES_CMAC,
822                 RTE_CRYPTO_AUTH_ZUC_EIA3
823         };
824
825         rte_cryptodev_info_get(dev_id, &dev_info);
826
827         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
828                         !(dev_info.feature_flags &
829                         RTE_CRYPTODEV_FF_SECURITY)) {
830                 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
831                                 "testsuite not met\n");
832                 return TEST_SKIPPED;
833         }
834
835         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
836                         && check_auth_capabilities_supported(auths,
837                         RTE_DIM(auths)) != 0) {
838                 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
839                                 "testsuite not met\n");
840                 return TEST_SKIPPED;
841         }
842
843         return 0;
844 }
845
846 static int
847 docsis_proto_testsuite_setup(void)
848 {
849         struct crypto_testsuite_params *ts_params = &testsuite_params;
850         uint8_t dev_id = ts_params->valid_devs[0];
851         struct rte_cryptodev_info dev_info;
852         const enum rte_crypto_cipher_algorithm ciphers[] = {
853                 RTE_CRYPTO_CIPHER_AES_DOCSISBPI
854         };
855
856         rte_cryptodev_info_get(dev_id, &dev_info);
857
858         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
859                         !(dev_info.feature_flags &
860                         RTE_CRYPTODEV_FF_SECURITY)) {
861                 RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis "
862                                 "Proto testsuite not met\n");
863                 return TEST_SKIPPED;
864         }
865
866         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
867                 RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto "
868                                 "testsuite not met\n");
869                 return TEST_SKIPPED;
870         }
871
872         return 0;
873 }
874 #endif
875
876 static int
877 aes_ccm_auth_testsuite_setup(void)
878 {
879         struct crypto_testsuite_params *ts_params = &testsuite_params;
880         uint8_t dev_id = ts_params->valid_devs[0];
881         struct rte_cryptodev_info dev_info;
882         const enum rte_crypto_aead_algorithm aeads[] = {
883                 RTE_CRYPTO_AEAD_AES_CCM
884         };
885
886         rte_cryptodev_info_get(dev_id, &dev_info);
887
888         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
889                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
890                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
891                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
892                                 "testsuite not met\n");
893                 return TEST_SKIPPED;
894         }
895
896         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
897                 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
898                                 "testsuite not met\n");
899                 return TEST_SKIPPED;
900         }
901
902         return 0;
903 }
904
905 static int
906 aes_gcm_auth_testsuite_setup(void)
907 {
908         struct crypto_testsuite_params *ts_params = &testsuite_params;
909         uint8_t dev_id = ts_params->valid_devs[0];
910         struct rte_cryptodev_info dev_info;
911         const enum rte_crypto_aead_algorithm aeads[] = {
912                 RTE_CRYPTO_AEAD_AES_GCM
913         };
914
915         rte_cryptodev_info_get(dev_id, &dev_info);
916
917         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
918                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
919                                 "testsuite not met\n");
920                 return TEST_SKIPPED;
921         }
922
923         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
924                 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
925                                 "testsuite not met\n");
926                 return TEST_SKIPPED;
927         }
928
929         return 0;
930 }
931
932 static int
933 aes_gmac_auth_testsuite_setup(void)
934 {
935         struct crypto_testsuite_params *ts_params = &testsuite_params;
936         uint8_t dev_id = ts_params->valid_devs[0];
937         struct rte_cryptodev_info dev_info;
938         const enum rte_crypto_auth_algorithm auths[] = {
939                 RTE_CRYPTO_AUTH_AES_GMAC
940         };
941
942         rte_cryptodev_info_get(dev_id, &dev_info);
943
944         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
945                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
946                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
947                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
948                                 "testsuite not met\n");
949                 return TEST_SKIPPED;
950         }
951
952         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
953                 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
954                                 "testsuite not met\n");
955                 return TEST_SKIPPED;
956         }
957
958         return 0;
959 }
960
961 static int
962 chacha20_poly1305_testsuite_setup(void)
963 {
964         struct crypto_testsuite_params *ts_params = &testsuite_params;
965         uint8_t dev_id = ts_params->valid_devs[0];
966         struct rte_cryptodev_info dev_info;
967         const enum rte_crypto_aead_algorithm aeads[] = {
968                 RTE_CRYPTO_AEAD_CHACHA20_POLY1305
969         };
970
971         rte_cryptodev_info_get(dev_id, &dev_info);
972
973         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
974                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
975                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
976                 RTE_LOG(INFO, USER1, "Feature flag requirements for "
977                                 "Chacha20-Poly1305 testsuite not met\n");
978                 return TEST_SKIPPED;
979         }
980
981         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
982                 RTE_LOG(INFO, USER1, "Capability requirements for "
983                                 "Chacha20-Poly1305 testsuite not met\n");
984                 return TEST_SKIPPED;
985         }
986
987         return 0;
988 }
989
990 static int
991 snow3g_testsuite_setup(void)
992 {
993         struct crypto_testsuite_params *ts_params = &testsuite_params;
994         uint8_t dev_id = ts_params->valid_devs[0];
995         struct rte_cryptodev_info dev_info;
996         const enum rte_crypto_cipher_algorithm ciphers[] = {
997                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
998
999         };
1000         const enum rte_crypto_auth_algorithm auths[] = {
1001                 RTE_CRYPTO_AUTH_SNOW3G_UIA2
1002         };
1003
1004         rte_cryptodev_info_get(dev_id, &dev_info);
1005
1006         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1007                 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
1008                                 "testsuite not met\n");
1009                 return TEST_SKIPPED;
1010         }
1011
1012         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1013                         && check_auth_capabilities_supported(auths,
1014                         RTE_DIM(auths)) != 0) {
1015                 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
1016                                 "testsuite not met\n");
1017                 return TEST_SKIPPED;
1018         }
1019
1020         return 0;
1021 }
1022
1023 static int
1024 zuc_testsuite_setup(void)
1025 {
1026         struct crypto_testsuite_params *ts_params = &testsuite_params;
1027         uint8_t dev_id = ts_params->valid_devs[0];
1028         struct rte_cryptodev_info dev_info;
1029         const enum rte_crypto_cipher_algorithm ciphers[] = {
1030                 RTE_CRYPTO_CIPHER_ZUC_EEA3
1031         };
1032         const enum rte_crypto_auth_algorithm auths[] = {
1033                 RTE_CRYPTO_AUTH_ZUC_EIA3
1034         };
1035
1036         rte_cryptodev_info_get(dev_id, &dev_info);
1037
1038         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1039                 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
1040                                 "testsuite not met\n");
1041                 return TEST_SKIPPED;
1042         }
1043
1044         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1045                         && check_auth_capabilities_supported(auths,
1046                         RTE_DIM(auths)) != 0) {
1047                 RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1048                                 "testsuite not met\n");
1049                 return TEST_SKIPPED;
1050         }
1051
1052         return 0;
1053 }
1054
1055 static int
1056 hmac_md5_auth_testsuite_setup(void)
1057 {
1058         struct crypto_testsuite_params *ts_params = &testsuite_params;
1059         uint8_t dev_id = ts_params->valid_devs[0];
1060         struct rte_cryptodev_info dev_info;
1061         const enum rte_crypto_auth_algorithm auths[] = {
1062                 RTE_CRYPTO_AUTH_MD5_HMAC
1063         };
1064
1065         rte_cryptodev_info_get(dev_id, &dev_info);
1066
1067         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1068                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1069                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1070                 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1071                                 "Auth testsuite not met\n");
1072                 return TEST_SKIPPED;
1073         }
1074
1075         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1076                 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1077                                 "testsuite not met\n");
1078                 return TEST_SKIPPED;
1079         }
1080
1081         return 0;
1082 }
1083
1084 static int
1085 kasumi_testsuite_setup(void)
1086 {
1087         struct crypto_testsuite_params *ts_params = &testsuite_params;
1088         uint8_t dev_id = ts_params->valid_devs[0];
1089         struct rte_cryptodev_info dev_info;
1090         const enum rte_crypto_cipher_algorithm ciphers[] = {
1091                 RTE_CRYPTO_CIPHER_KASUMI_F8
1092         };
1093         const enum rte_crypto_auth_algorithm auths[] = {
1094                 RTE_CRYPTO_AUTH_KASUMI_F9
1095         };
1096
1097         rte_cryptodev_info_get(dev_id, &dev_info);
1098
1099         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1100                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1101                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1102                 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1103                                 "testsuite not met\n");
1104                 return TEST_SKIPPED;
1105         }
1106
1107         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1108                         && check_auth_capabilities_supported(auths,
1109                         RTE_DIM(auths)) != 0) {
1110                 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1111                                 "testsuite not met\n");
1112                 return TEST_SKIPPED;
1113         }
1114
1115         return 0;
1116 }
1117
1118 static int
1119 negative_aes_gcm_testsuite_setup(void)
1120 {
1121         struct crypto_testsuite_params *ts_params = &testsuite_params;
1122         uint8_t dev_id = ts_params->valid_devs[0];
1123         struct rte_cryptodev_info dev_info;
1124         const enum rte_crypto_aead_algorithm aeads[] = {
1125                 RTE_CRYPTO_AEAD_AES_GCM
1126         };
1127
1128         rte_cryptodev_info_get(dev_id, &dev_info);
1129
1130         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1131                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1132                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1133                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1134                                 "AES GCM testsuite not met\n");
1135                 return TEST_SKIPPED;
1136         }
1137
1138         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1139                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1140                                 "AES GCM testsuite not met\n");
1141                 return TEST_SKIPPED;
1142         }
1143
1144         return 0;
1145 }
1146
1147 static int
1148 negative_aes_gmac_testsuite_setup(void)
1149 {
1150         struct crypto_testsuite_params *ts_params = &testsuite_params;
1151         uint8_t dev_id = ts_params->valid_devs[0];
1152         struct rte_cryptodev_info dev_info;
1153         const enum rte_crypto_auth_algorithm auths[] = {
1154                 RTE_CRYPTO_AUTH_AES_GMAC
1155         };
1156
1157         rte_cryptodev_info_get(dev_id, &dev_info);
1158
1159         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1160                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1161                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1162                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1163                                 "AES GMAC testsuite not met\n");
1164                 return TEST_SKIPPED;
1165         }
1166
1167         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1168                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1169                                 "AES GMAC testsuite not met\n");
1170                 return TEST_SKIPPED;
1171         }
1172
1173         return 0;
1174 }
1175
1176 static int
1177 mixed_cipher_hash_testsuite_setup(void)
1178 {
1179         struct crypto_testsuite_params *ts_params = &testsuite_params;
1180         uint8_t dev_id = ts_params->valid_devs[0];
1181         struct rte_cryptodev_info dev_info;
1182         uint64_t feat_flags;
1183         const enum rte_crypto_cipher_algorithm ciphers[] = {
1184                 RTE_CRYPTO_CIPHER_NULL,
1185                 RTE_CRYPTO_CIPHER_AES_CTR,
1186                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
1187                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1188         };
1189         const enum rte_crypto_auth_algorithm auths[] = {
1190                 RTE_CRYPTO_AUTH_NULL,
1191                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1192                 RTE_CRYPTO_AUTH_AES_CMAC,
1193                 RTE_CRYPTO_AUTH_ZUC_EIA3
1194         };
1195
1196         rte_cryptodev_info_get(dev_id, &dev_info);
1197         feat_flags = dev_info.feature_flags;
1198
1199         if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1200                         (global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1201                 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1202                                 "Cipher Hash testsuite not met\n");
1203                 return TEST_SKIPPED;
1204         }
1205
1206         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1207                         && check_auth_capabilities_supported(auths,
1208                         RTE_DIM(auths)) != 0) {
1209                 RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1210                                 "Cipher Hash testsuite not met\n");
1211                 return TEST_SKIPPED;
1212         }
1213
1214         return 0;
1215 }
1216
1217 static int
1218 esn_testsuite_setup(void)
1219 {
1220         struct crypto_testsuite_params *ts_params = &testsuite_params;
1221         uint8_t dev_id = ts_params->valid_devs[0];
1222         struct rte_cryptodev_info dev_info;
1223         const enum rte_crypto_cipher_algorithm ciphers[] = {
1224                 RTE_CRYPTO_CIPHER_AES_CBC
1225         };
1226         const enum rte_crypto_auth_algorithm auths[] = {
1227                 RTE_CRYPTO_AUTH_SHA1_HMAC
1228         };
1229
1230         rte_cryptodev_info_get(dev_id, &dev_info);
1231
1232         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1233                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1234                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1235                 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1236                                 "testsuite not met\n");
1237                 return TEST_SKIPPED;
1238         }
1239
1240         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1241                         && check_auth_capabilities_supported(auths,
1242                         RTE_DIM(auths)) != 0) {
1243                 RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1244                                 "testsuite not met\n");
1245                 return TEST_SKIPPED;
1246         }
1247
1248         return 0;
1249 }
1250
1251 static int
1252 multi_session_testsuite_setup(void)
1253 {
1254         struct crypto_testsuite_params *ts_params = &testsuite_params;
1255         uint8_t dev_id = ts_params->valid_devs[0];
1256         struct rte_cryptodev_info dev_info;
1257         const enum rte_crypto_cipher_algorithm ciphers[] = {
1258                 RTE_CRYPTO_CIPHER_AES_CBC
1259         };
1260         const enum rte_crypto_auth_algorithm auths[] = {
1261                 RTE_CRYPTO_AUTH_SHA512_HMAC
1262         };
1263
1264         rte_cryptodev_info_get(dev_id, &dev_info);
1265
1266         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1267                 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1268                                 "Session testsuite not met\n");
1269                 return TEST_SKIPPED;
1270         }
1271
1272         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1273                         && check_auth_capabilities_supported(auths,
1274                         RTE_DIM(auths)) != 0) {
1275                 RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1276                                 "Session testsuite not met\n");
1277                 return TEST_SKIPPED;
1278         }
1279
1280         return 0;
1281 }
1282
1283 static int
1284 negative_hmac_sha1_testsuite_setup(void)
1285 {
1286         struct crypto_testsuite_params *ts_params = &testsuite_params;
1287         uint8_t dev_id = ts_params->valid_devs[0];
1288         struct rte_cryptodev_info dev_info;
1289         const enum rte_crypto_cipher_algorithm ciphers[] = {
1290                 RTE_CRYPTO_CIPHER_AES_CBC
1291         };
1292         const enum rte_crypto_auth_algorithm auths[] = {
1293                 RTE_CRYPTO_AUTH_SHA1_HMAC
1294         };
1295
1296         rte_cryptodev_info_get(dev_id, &dev_info);
1297
1298         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1299                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1300                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1301                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1302                                 "HMAC SHA1 testsuite not met\n");
1303                 return TEST_SKIPPED;
1304         }
1305
1306         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1307                         && check_auth_capabilities_supported(auths,
1308                         RTE_DIM(auths)) != 0) {
1309                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1310                                 "HMAC SHA1 testsuite not met\n");
1311                 return TEST_SKIPPED;
1312         }
1313
1314         return 0;
1315 }
1316
1317 static int
1318 dev_configure_and_start(uint64_t ff_disable)
1319 {
1320         struct crypto_testsuite_params *ts_params = &testsuite_params;
1321         struct crypto_unittest_params *ut_params = &unittest_params;
1322
1323         uint16_t qp_id;
1324
1325         /* Clear unit test parameters before running test */
1326         memset(ut_params, 0, sizeof(*ut_params));
1327
1328         /* Reconfigure device to default parameters */
1329         ts_params->conf.socket_id = SOCKET_ID_ANY;
1330         ts_params->conf.ff_disable = ff_disable;
1331         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1332         ts_params->qp_conf.mp_session = ts_params->session_mpool;
1333         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1334
1335         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1336                         &ts_params->conf),
1337                         "Failed to configure cryptodev %u",
1338                         ts_params->valid_devs[0]);
1339
1340         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1341                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1342                         ts_params->valid_devs[0], qp_id,
1343                         &ts_params->qp_conf,
1344                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1345                         "Failed to setup queue pair %u on cryptodev %u",
1346                         qp_id, ts_params->valid_devs[0]);
1347         }
1348
1349
1350         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1351
1352         /* Start the device */
1353         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1354                         "Failed to start cryptodev %u",
1355                         ts_params->valid_devs[0]);
1356
1357         return TEST_SUCCESS;
1358 }
1359
1360 int
1361 ut_setup(void)
1362 {
1363         /* Configure and start the device with security feature disabled */
1364         return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1365 }
1366
1367 static int
1368 ut_setup_security(void)
1369 {
1370         /* Configure and start the device with no features disabled */
1371         return dev_configure_and_start(0);
1372 }
1373
1374 void
1375 ut_teardown(void)
1376 {
1377         struct crypto_testsuite_params *ts_params = &testsuite_params;
1378         struct crypto_unittest_params *ut_params = &unittest_params;
1379         struct rte_cryptodev_stats stats;
1380
1381         /* free crypto session structure */
1382 #ifdef RTE_LIB_SECURITY
1383         if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1384                 if (ut_params->sec_session) {
1385                         rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1386                                                 (ts_params->valid_devs[0]),
1387                                                 ut_params->sec_session);
1388                         ut_params->sec_session = NULL;
1389                 }
1390         } else
1391 #endif
1392         {
1393                 if (ut_params->sess) {
1394                         rte_cryptodev_sym_session_clear(
1395                                         ts_params->valid_devs[0],
1396                                         ut_params->sess);
1397                         rte_cryptodev_sym_session_free(ut_params->sess);
1398                         ut_params->sess = NULL;
1399                 }
1400         }
1401
1402         /* free crypto operation structure */
1403         if (ut_params->op)
1404                 rte_crypto_op_free(ut_params->op);
1405
1406         /*
1407          * free mbuf - both obuf and ibuf are usually the same,
1408          * so check if they point at the same address is necessary,
1409          * to avoid freeing the mbuf twice.
1410          */
1411         if (ut_params->obuf) {
1412                 rte_pktmbuf_free(ut_params->obuf);
1413                 if (ut_params->ibuf == ut_params->obuf)
1414                         ut_params->ibuf = 0;
1415                 ut_params->obuf = 0;
1416         }
1417         if (ut_params->ibuf) {
1418                 rte_pktmbuf_free(ut_params->ibuf);
1419                 ut_params->ibuf = 0;
1420         }
1421
1422         if (ts_params->mbuf_pool != NULL)
1423                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1424                         rte_mempool_avail_count(ts_params->mbuf_pool));
1425
1426         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1427
1428         /* Stop the device */
1429         rte_cryptodev_stop(ts_params->valid_devs[0]);
1430 }
1431
1432 static int
1433 test_device_configure_invalid_dev_id(void)
1434 {
1435         struct crypto_testsuite_params *ts_params = &testsuite_params;
1436         uint16_t dev_id, num_devs = 0;
1437
1438         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1439                         "Need at least %d devices for test", 1);
1440
1441         /* valid dev_id values */
1442         dev_id = ts_params->valid_devs[0];
1443
1444         /* Stop the device in case it's started so it can be configured */
1445         rte_cryptodev_stop(dev_id);
1446
1447         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1448                         "Failed test for rte_cryptodev_configure: "
1449                         "invalid dev_num %u", dev_id);
1450
1451         /* invalid dev_id values */
1452         dev_id = num_devs;
1453
1454         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1455                         "Failed test for rte_cryptodev_configure: "
1456                         "invalid dev_num %u", dev_id);
1457
1458         dev_id = 0xff;
1459
1460         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1461                         "Failed test for rte_cryptodev_configure:"
1462                         "invalid dev_num %u", dev_id);
1463
1464         return TEST_SUCCESS;
1465 }
1466
1467 static int
1468 test_device_configure_invalid_queue_pair_ids(void)
1469 {
1470         struct crypto_testsuite_params *ts_params = &testsuite_params;
1471         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1472
1473         /* Stop the device in case it's started so it can be configured */
1474         rte_cryptodev_stop(ts_params->valid_devs[0]);
1475
1476         /* valid - max value queue pairs */
1477         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1478
1479         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1480                         &ts_params->conf),
1481                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1482                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1483
1484         /* valid - one queue pairs */
1485         ts_params->conf.nb_queue_pairs = 1;
1486
1487         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1488                         &ts_params->conf),
1489                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1490                         ts_params->valid_devs[0],
1491                         ts_params->conf.nb_queue_pairs);
1492
1493
1494         /* invalid - zero queue pairs */
1495         ts_params->conf.nb_queue_pairs = 0;
1496
1497         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1498                         &ts_params->conf),
1499                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1500                         " invalid qps: %u",
1501                         ts_params->valid_devs[0],
1502                         ts_params->conf.nb_queue_pairs);
1503
1504
1505         /* invalid - max value supported by field queue pairs */
1506         ts_params->conf.nb_queue_pairs = UINT16_MAX;
1507
1508         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1509                         &ts_params->conf),
1510                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1511                         " invalid qps: %u",
1512                         ts_params->valid_devs[0],
1513                         ts_params->conf.nb_queue_pairs);
1514
1515
1516         /* invalid - max value + 1 queue pairs */
1517         ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1518
1519         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1520                         &ts_params->conf),
1521                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1522                         " invalid qps: %u",
1523                         ts_params->valid_devs[0],
1524                         ts_params->conf.nb_queue_pairs);
1525
1526         /* revert to original testsuite value */
1527         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1528
1529         return TEST_SUCCESS;
1530 }
1531
1532 static int
1533 test_queue_pair_descriptor_setup(void)
1534 {
1535         struct crypto_testsuite_params *ts_params = &testsuite_params;
1536         struct rte_cryptodev_qp_conf qp_conf = {
1537                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
1538         };
1539         uint16_t qp_id;
1540
1541         /* Stop the device in case it's started so it can be configured */
1542         rte_cryptodev_stop(ts_params->valid_devs[0]);
1543
1544         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1545                         &ts_params->conf),
1546                         "Failed to configure cryptodev %u",
1547                         ts_params->valid_devs[0]);
1548
1549         /*
1550          * Test various ring sizes on this device. memzones can't be
1551          * freed so are re-used if ring is released and re-created.
1552          */
1553         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1554         qp_conf.mp_session = ts_params->session_mpool;
1555         qp_conf.mp_session_private = ts_params->session_priv_mpool;
1556
1557         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1558                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1559                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1560                                 rte_cryptodev_socket_id(
1561                                                 ts_params->valid_devs[0])),
1562                                 "Failed test for "
1563                                 "rte_cryptodev_queue_pair_setup: num_inflights "
1564                                 "%u on qp %u on cryptodev %u",
1565                                 qp_conf.nb_descriptors, qp_id,
1566                                 ts_params->valid_devs[0]);
1567         }
1568
1569         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1570
1571         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1572                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1573                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1574                                 rte_cryptodev_socket_id(
1575                                                 ts_params->valid_devs[0])),
1576                                 "Failed test for"
1577                                 " rte_cryptodev_queue_pair_setup: num_inflights"
1578                                 " %u on qp %u on cryptodev %u",
1579                                 qp_conf.nb_descriptors, qp_id,
1580                                 ts_params->valid_devs[0]);
1581         }
1582
1583         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1584
1585         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1586                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1587                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1588                                 rte_cryptodev_socket_id(
1589                                                 ts_params->valid_devs[0])),
1590                                 "Failed test for "
1591                                 "rte_cryptodev_queue_pair_setup: num_inflights"
1592                                 " %u on qp %u on cryptodev %u",
1593                                 qp_conf.nb_descriptors, qp_id,
1594                                 ts_params->valid_devs[0]);
1595         }
1596
1597         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1598
1599         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1600                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1601                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1602                                 rte_cryptodev_socket_id(
1603                                                 ts_params->valid_devs[0])),
1604                                 "Failed test for"
1605                                 " rte_cryptodev_queue_pair_setup:"
1606                                 "num_inflights %u on qp %u on cryptodev %u",
1607                                 qp_conf.nb_descriptors, qp_id,
1608                                 ts_params->valid_devs[0]);
1609         }
1610
1611         /* test invalid queue pair id */
1612         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
1613
1614         qp_id = ts_params->conf.nb_queue_pairs;         /*invalid */
1615
1616         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1617                         ts_params->valid_devs[0],
1618                         qp_id, &qp_conf,
1619                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1620                         "Failed test for rte_cryptodev_queue_pair_setup:"
1621                         "invalid qp %u on cryptodev %u",
1622                         qp_id, ts_params->valid_devs[0]);
1623
1624         qp_id = 0xffff; /*invalid*/
1625
1626         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1627                         ts_params->valid_devs[0],
1628                         qp_id, &qp_conf,
1629                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1630                         "Failed test for rte_cryptodev_queue_pair_setup:"
1631                         "invalid qp %u on cryptodev %u",
1632                         qp_id, ts_params->valid_devs[0]);
1633
1634         return TEST_SUCCESS;
1635 }
1636
1637 /* ***** Plaintext data for tests ***** */
1638
1639 const char catch_22_quote_1[] =
1640                 "There was only one catch and that was Catch-22, which "
1641                 "specified that a concern for one's safety in the face of "
1642                 "dangers that were real and immediate was the process of a "
1643                 "rational mind. Orr was crazy and could be grounded. All he "
1644                 "had to do was ask; and as soon as he did, he would no longer "
1645                 "be crazy and would have to fly more missions. Orr would be "
1646                 "crazy to fly more missions and sane if he didn't, but if he "
1647                 "was sane he had to fly them. If he flew them he was crazy "
1648                 "and didn't have to; but if he didn't want to he was sane and "
1649                 "had to. Yossarian was moved very deeply by the absolute "
1650                 "simplicity of this clause of Catch-22 and let out a "
1651                 "respectful whistle. \"That's some catch, that Catch-22\", he "
1652                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
1653
1654 const char catch_22_quote[] =
1655                 "What a lousy earth! He wondered how many people were "
1656                 "destitute that same night even in his own prosperous country, "
1657                 "how many homes were shanties, how many husbands were drunk "
1658                 "and wives socked, and how many children were bullied, abused, "
1659                 "or abandoned. How many families hungered for food they could "
1660                 "not afford to buy? How many hearts were broken? How many "
1661                 "suicides would take place that same night, how many people "
1662                 "would go insane? How many cockroaches and landlords would "
1663                 "triumph? How many winners were losers, successes failures, "
1664                 "and rich men poor men? How many wise guys were stupid? How "
1665                 "many happy endings were unhappy endings? How many honest men "
1666                 "were liars, brave men cowards, loyal men traitors, how many "
1667                 "sainted men were corrupt, how many people in positions of "
1668                 "trust had sold their souls to bodyguards, how many had never "
1669                 "had souls? How many straight-and-narrow paths were crooked "
1670                 "paths? How many best families were worst families and how "
1671                 "many good people were bad people? When you added them all up "
1672                 "and then subtracted, you might be left with only the children, "
1673                 "and perhaps with Albert Einstein and an old violinist or "
1674                 "sculptor somewhere.";
1675
1676 #define QUOTE_480_BYTES         (480)
1677 #define QUOTE_512_BYTES         (512)
1678 #define QUOTE_768_BYTES         (768)
1679 #define QUOTE_1024_BYTES        (1024)
1680
1681
1682
1683 /* ***** SHA1 Hash Tests ***** */
1684
1685 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
1686
1687 static uint8_t hmac_sha1_key[] = {
1688         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1689         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1690         0xDE, 0xF4, 0xDE, 0xAD };
1691
1692 /* ***** SHA224 Hash Tests ***** */
1693
1694 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
1695
1696
1697 /* ***** AES-CBC Cipher Tests ***** */
1698
1699 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
1700 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
1701
1702 static uint8_t aes_cbc_key[] = {
1703         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1704         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1705
1706 static uint8_t aes_cbc_iv[] = {
1707         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1708         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1709
1710
1711 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1712
1713 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1714         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1715         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1716         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1717         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1718         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1719         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1720         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1721         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1722         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1723         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1724         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1725         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1726         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1727         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1728         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1729         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1730         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1731         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1732         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1733         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1734         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1735         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1736         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1737         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1738         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1739         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1740         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1741         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1742         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1743         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1744         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1745         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1746         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1747         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1748         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1749         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1750         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1751         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1752         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1753         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1754         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1755         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1756         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1757         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1758         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1759         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1760         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1761         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1762         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1763         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1764         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1765         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1766         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1767         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1768         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1769         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1770         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1771         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1772         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1773         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1774         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1775         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1776         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1777         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1778 };
1779
1780 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1781         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1782         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1783         0x18, 0x8c, 0x1d, 0x32
1784 };
1785
1786
1787 /* Multisession Vector context Test */
1788 /*Begin Session 0 */
1789 static uint8_t ms_aes_cbc_key0[] = {
1790         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1791         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1792 };
1793
1794 static uint8_t ms_aes_cbc_iv0[] = {
1795         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1796         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1797 };
1798
1799 static const uint8_t ms_aes_cbc_cipher0[] = {
1800                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1801                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1802                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1803                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1804                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1805                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1806                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1807                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1808                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1809                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1810                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1811                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1812                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1813                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1814                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1815                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1816                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1817                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1818                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1819                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1820                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1821                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1822                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1823                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1824                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1825                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1826                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1827                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1828                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1829                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1830                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1831                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1832                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1833                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1834                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1835                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1836                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1837                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1838                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1839                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1840                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1841                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1842                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1843                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1844                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1845                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1846                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1847                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1848                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1849                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1850                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1851                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1852                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1853                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1854                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1855                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1856                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1857                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1858                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1859                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1860                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1861                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1862                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1863                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1864 };
1865
1866
1867 static  uint8_t ms_hmac_key0[] = {
1868                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1869                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1870                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1871                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1872                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1873                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1874                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1875                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1876 };
1877
1878 static const uint8_t ms_hmac_digest0[] = {
1879                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1880                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1881                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1882                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1883                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1884                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1885                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1886                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1887                 };
1888
1889 /* End Session 0 */
1890 /* Begin session 1 */
1891
1892 static  uint8_t ms_aes_cbc_key1[] = {
1893                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1894                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1895 };
1896
1897 static  uint8_t ms_aes_cbc_iv1[] = {
1898         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1899         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1900 };
1901
1902 static const uint8_t ms_aes_cbc_cipher1[] = {
1903                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1904                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1905                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1906                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1907                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1908                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1909                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1910                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1911                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1912                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1913                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1914                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1915                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1916                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1917                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1918                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1919                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1920                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1921                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1922                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1923                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1924                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1925                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1926                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1927                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1928                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1929                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1930                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1931                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1932                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1933                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1934                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1935                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1936                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1937                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1938                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1939                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1940                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1941                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1942                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1943                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1944                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1945                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1946                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1947                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1948                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1949                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1950                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1951                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1952                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1953                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1954                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1955                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1956                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1957                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1958                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1959                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1960                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1961                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1962                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1963                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1964                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1965                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1966                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1967
1968 };
1969
1970 static uint8_t ms_hmac_key1[] = {
1971                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1972                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1973                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1974                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1975                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1976                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1977                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1978                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1979 };
1980
1981 static const uint8_t ms_hmac_digest1[] = {
1982                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1983                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1984                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1985                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1986                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1987                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1988                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1989                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1990 };
1991 /* End Session 1  */
1992 /* Begin Session 2 */
1993 static  uint8_t ms_aes_cbc_key2[] = {
1994                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1995                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1996 };
1997
1998 static  uint8_t ms_aes_cbc_iv2[] = {
1999                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2000                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2001 };
2002
2003 static const uint8_t ms_aes_cbc_cipher2[] = {
2004                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
2005                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
2006                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
2007                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
2008                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
2009                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
2010                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
2011                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
2012                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
2013                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
2014                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
2015                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
2016                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
2017                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
2018                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
2019                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
2020                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
2021                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
2022                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
2023                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
2024                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
2025                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
2026                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
2027                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
2028                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
2029                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
2030                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
2031                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
2032                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
2033                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
2034                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
2035                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
2036                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
2037                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
2038                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
2039                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
2040                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
2041                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
2042                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
2043                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2044                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2045                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2046                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2047                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2048                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2049                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2050                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2051                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2052                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2053                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2054                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2055                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2056                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2057                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2058                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2059                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2060                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2061                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2062                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2063                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2064                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2065                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2066                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2067                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2068 };
2069
2070 static  uint8_t ms_hmac_key2[] = {
2071                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2072                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2073                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2074                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2075                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2076                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2077                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2078                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2079 };
2080
2081 static const uint8_t ms_hmac_digest2[] = {
2082                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2083                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2084                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2085                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2086                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2087                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2088                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2089                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2090 };
2091
2092 /* End Session 2 */
2093
2094
2095 static int
2096 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2097 {
2098         struct crypto_testsuite_params *ts_params = &testsuite_params;
2099         struct crypto_unittest_params *ut_params = &unittest_params;
2100
2101         /* Verify the capabilities */
2102         struct rte_cryptodev_sym_capability_idx cap_idx;
2103         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2104         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2105         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2106                         &cap_idx) == NULL)
2107                 return TEST_SKIPPED;
2108         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2109         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2110         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2111                         &cap_idx) == NULL)
2112                 return TEST_SKIPPED;
2113
2114         /* Generate test mbuf data and space for digest */
2115         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2116                         catch_22_quote, QUOTE_512_BYTES, 0);
2117
2118         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2119                         DIGEST_BYTE_LENGTH_SHA1);
2120         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2121
2122         /* Setup Cipher Parameters */
2123         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2124         ut_params->cipher_xform.next = &ut_params->auth_xform;
2125
2126         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2127         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2128         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2129         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2130         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2131         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2132
2133         /* Setup HMAC Parameters */
2134         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2135
2136         ut_params->auth_xform.next = NULL;
2137
2138         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2139         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2140         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2141         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2142         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2143
2144         ut_params->sess = rte_cryptodev_sym_session_create(
2145                         ts_params->session_mpool);
2146
2147         /* Create crypto session*/
2148         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2149                         ut_params->sess, &ut_params->cipher_xform,
2150                         ts_params->session_priv_mpool);
2151         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2152
2153         /* Generate crypto op data structure */
2154         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2155                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2156         TEST_ASSERT_NOT_NULL(ut_params->op,
2157                         "Failed to allocate symmetric crypto operation struct");
2158
2159         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2160
2161         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2162
2163         /* set crypto operation source mbuf */
2164         sym_op->m_src = ut_params->ibuf;
2165
2166         /* Set crypto operation authentication parameters */
2167         sym_op->auth.digest.data = ut_params->digest;
2168         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2169                         ut_params->ibuf, QUOTE_512_BYTES);
2170
2171         sym_op->auth.data.offset = 0;
2172         sym_op->auth.data.length = QUOTE_512_BYTES;
2173
2174         /* Copy IV at the end of the crypto operation */
2175         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2176                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2177
2178         /* Set crypto operation cipher parameters */
2179         sym_op->cipher.data.offset = 0;
2180         sym_op->cipher.data.length = QUOTE_512_BYTES;
2181
2182         /* Process crypto operation */
2183         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2184                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2185                         ut_params->op);
2186         else
2187                 TEST_ASSERT_NOT_NULL(
2188                         process_crypto_request(ts_params->valid_devs[0],
2189                                 ut_params->op),
2190                                 "failed to process sym crypto op");
2191
2192         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2193                         "crypto op processing failed");
2194
2195         /* Validate obuf */
2196         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2197                         uint8_t *);
2198
2199         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2200                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2201                         QUOTE_512_BYTES,
2202                         "ciphertext data not as expected");
2203
2204         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2205
2206         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2207                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2208                         gbl_driver_id == rte_cryptodev_driver_id_get(
2209                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2210                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2211                                         DIGEST_BYTE_LENGTH_SHA1,
2212                         "Generated digest data not as expected");
2213
2214         return TEST_SUCCESS;
2215 }
2216
2217 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2218
2219 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2220
2221 static uint8_t hmac_sha512_key[] = {
2222         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2223         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2224         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2225         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2226         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2227         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2228         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2229         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2230
2231 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2232         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2233         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2234         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2235         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2236         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2237         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2238         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2239         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2240
2241
2242
2243 static int
2244 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2245                 struct crypto_unittest_params *ut_params,
2246                 uint8_t *cipher_key,
2247                 uint8_t *hmac_key);
2248
2249 static int
2250 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2251                 struct crypto_unittest_params *ut_params,
2252                 struct crypto_testsuite_params *ts_params,
2253                 const uint8_t *cipher,
2254                 const uint8_t *digest,
2255                 const uint8_t *iv);
2256
2257
2258 static int
2259 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2260                 struct crypto_unittest_params *ut_params,
2261                 uint8_t *cipher_key,
2262                 uint8_t *hmac_key)
2263 {
2264
2265         /* Setup Cipher Parameters */
2266         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2267         ut_params->cipher_xform.next = NULL;
2268
2269         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2270         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2271         ut_params->cipher_xform.cipher.key.data = cipher_key;
2272         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2273         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2274         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2275
2276         /* Setup HMAC Parameters */
2277         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2278         ut_params->auth_xform.next = &ut_params->cipher_xform;
2279
2280         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2281         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2282         ut_params->auth_xform.auth.key.data = hmac_key;
2283         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2284         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2285
2286         return TEST_SUCCESS;
2287 }
2288
2289
2290 static int
2291 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2292                 struct crypto_unittest_params *ut_params,
2293                 struct crypto_testsuite_params *ts_params,
2294                 const uint8_t *cipher,
2295                 const uint8_t *digest,
2296                 const uint8_t *iv)
2297 {
2298         /* Generate test mbuf data and digest */
2299         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2300                         (const char *)
2301                         cipher,
2302                         QUOTE_512_BYTES, 0);
2303
2304         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2305                         DIGEST_BYTE_LENGTH_SHA512);
2306         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2307
2308         rte_memcpy(ut_params->digest,
2309                         digest,
2310                         DIGEST_BYTE_LENGTH_SHA512);
2311
2312         /* Generate Crypto op data structure */
2313         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2314                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2315         TEST_ASSERT_NOT_NULL(ut_params->op,
2316                         "Failed to allocate symmetric crypto operation struct");
2317
2318         rte_crypto_op_attach_sym_session(ut_params->op, sess);
2319
2320         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2321
2322         /* set crypto operation source mbuf */
2323         sym_op->m_src = ut_params->ibuf;
2324
2325         sym_op->auth.digest.data = ut_params->digest;
2326         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2327                         ut_params->ibuf, QUOTE_512_BYTES);
2328
2329         sym_op->auth.data.offset = 0;
2330         sym_op->auth.data.length = QUOTE_512_BYTES;
2331
2332         /* Copy IV at the end of the crypto operation */
2333         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2334                         iv, CIPHER_IV_LENGTH_AES_CBC);
2335
2336         sym_op->cipher.data.offset = 0;
2337         sym_op->cipher.data.length = QUOTE_512_BYTES;
2338
2339         /* Process crypto operation */
2340         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2341                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2342                         ut_params->op);
2343         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2344                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2345                                 ut_params->op, 1, 1, 0, 0);
2346         else
2347                 TEST_ASSERT_NOT_NULL(
2348                                 process_crypto_request(ts_params->valid_devs[0],
2349                                         ut_params->op),
2350                                         "failed to process sym crypto op");
2351
2352         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2353                         "crypto op processing failed");
2354
2355         ut_params->obuf = ut_params->op->sym->m_src;
2356
2357         /* Validate obuf */
2358         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2359                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2360                         catch_22_quote,
2361                         QUOTE_512_BYTES,
2362                         "Plaintext data not as expected");
2363
2364         /* Validate obuf */
2365         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2366                         "Digest verification failed");
2367
2368         return TEST_SUCCESS;
2369 }
2370
2371 /* ***** SNOW 3G Tests ***** */
2372 static int
2373 create_wireless_algo_hash_session(uint8_t dev_id,
2374         const uint8_t *key, const uint8_t key_len,
2375         const uint8_t iv_len, const uint8_t auth_len,
2376         enum rte_crypto_auth_operation op,
2377         enum rte_crypto_auth_algorithm algo)
2378 {
2379         uint8_t hash_key[key_len];
2380         int status;
2381
2382         struct crypto_testsuite_params *ts_params = &testsuite_params;
2383         struct crypto_unittest_params *ut_params = &unittest_params;
2384
2385         memcpy(hash_key, key, key_len);
2386
2387         debug_hexdump(stdout, "key:", key, key_len);
2388
2389         /* Setup Authentication Parameters */
2390         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2391         ut_params->auth_xform.next = NULL;
2392
2393         ut_params->auth_xform.auth.op = op;
2394         ut_params->auth_xform.auth.algo = algo;
2395         ut_params->auth_xform.auth.key.length = key_len;
2396         ut_params->auth_xform.auth.key.data = hash_key;
2397         ut_params->auth_xform.auth.digest_length = auth_len;
2398         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2399         ut_params->auth_xform.auth.iv.length = iv_len;
2400         ut_params->sess = rte_cryptodev_sym_session_create(
2401                         ts_params->session_mpool);
2402
2403         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2404                         &ut_params->auth_xform,
2405                         ts_params->session_priv_mpool);
2406         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2407         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2408         return 0;
2409 }
2410
2411 static int
2412 create_wireless_algo_cipher_session(uint8_t dev_id,
2413                         enum rte_crypto_cipher_operation op,
2414                         enum rte_crypto_cipher_algorithm algo,
2415                         const uint8_t *key, const uint8_t key_len,
2416                         uint8_t iv_len)
2417 {
2418         uint8_t cipher_key[key_len];
2419         int status;
2420         struct crypto_testsuite_params *ts_params = &testsuite_params;
2421         struct crypto_unittest_params *ut_params = &unittest_params;
2422
2423         memcpy(cipher_key, key, key_len);
2424
2425         /* Setup Cipher Parameters */
2426         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2427         ut_params->cipher_xform.next = NULL;
2428
2429         ut_params->cipher_xform.cipher.algo = algo;
2430         ut_params->cipher_xform.cipher.op = op;
2431         ut_params->cipher_xform.cipher.key.data = cipher_key;
2432         ut_params->cipher_xform.cipher.key.length = key_len;
2433         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2434         ut_params->cipher_xform.cipher.iv.length = iv_len;
2435
2436         debug_hexdump(stdout, "key:", key, key_len);
2437
2438         /* Create Crypto session */
2439         ut_params->sess = rte_cryptodev_sym_session_create(
2440                         ts_params->session_mpool);
2441
2442         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2443                         &ut_params->cipher_xform,
2444                         ts_params->session_priv_mpool);
2445         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2446         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2447         return 0;
2448 }
2449
2450 static int
2451 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2452                         unsigned int cipher_len,
2453                         unsigned int cipher_offset)
2454 {
2455         struct crypto_testsuite_params *ts_params = &testsuite_params;
2456         struct crypto_unittest_params *ut_params = &unittest_params;
2457
2458         /* Generate Crypto op data structure */
2459         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2460                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2461         TEST_ASSERT_NOT_NULL(ut_params->op,
2462                                 "Failed to allocate pktmbuf offload");
2463
2464         /* Set crypto operation data parameters */
2465         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2466
2467         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2468
2469         /* set crypto operation source mbuf */
2470         sym_op->m_src = ut_params->ibuf;
2471
2472         /* iv */
2473         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2474                         iv, iv_len);
2475         sym_op->cipher.data.length = cipher_len;
2476         sym_op->cipher.data.offset = cipher_offset;
2477         return 0;
2478 }
2479
2480 static int
2481 create_wireless_algo_cipher_operation_oop(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         sym_op->m_dst = ut_params->obuf;
2502
2503         /* iv */
2504         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2505                         iv, iv_len);
2506         sym_op->cipher.data.length = cipher_len;
2507         sym_op->cipher.data.offset = cipher_offset;
2508         return 0;
2509 }
2510
2511 static int
2512 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2513                 enum rte_crypto_cipher_operation cipher_op,
2514                 enum rte_crypto_auth_operation auth_op,
2515                 enum rte_crypto_auth_algorithm auth_algo,
2516                 enum rte_crypto_cipher_algorithm cipher_algo,
2517                 const uint8_t *key, uint8_t key_len,
2518                 uint8_t auth_iv_len, uint8_t auth_len,
2519                 uint8_t cipher_iv_len)
2520
2521 {
2522         uint8_t cipher_auth_key[key_len];
2523         int status;
2524
2525         struct crypto_testsuite_params *ts_params = &testsuite_params;
2526         struct crypto_unittest_params *ut_params = &unittest_params;
2527
2528         memcpy(cipher_auth_key, key, key_len);
2529
2530         /* Setup Authentication Parameters */
2531         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2532         ut_params->auth_xform.next = NULL;
2533
2534         ut_params->auth_xform.auth.op = auth_op;
2535         ut_params->auth_xform.auth.algo = auth_algo;
2536         ut_params->auth_xform.auth.key.length = key_len;
2537         /* Hash key = cipher key */
2538         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2539         ut_params->auth_xform.auth.digest_length = auth_len;
2540         /* Auth IV will be after cipher IV */
2541         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2542         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2543
2544         /* Setup Cipher Parameters */
2545         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2546         ut_params->cipher_xform.next = &ut_params->auth_xform;
2547
2548         ut_params->cipher_xform.cipher.algo = cipher_algo;
2549         ut_params->cipher_xform.cipher.op = cipher_op;
2550         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2551         ut_params->cipher_xform.cipher.key.length = key_len;
2552         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2553         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2554
2555         debug_hexdump(stdout, "key:", key, key_len);
2556
2557         /* Create Crypto session*/
2558         ut_params->sess = rte_cryptodev_sym_session_create(
2559                         ts_params->session_mpool);
2560         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2561
2562         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2563                         &ut_params->cipher_xform,
2564                         ts_params->session_priv_mpool);
2565         if (status == -ENOTSUP)
2566                 return TEST_SKIPPED;
2567
2568         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2569         return 0;
2570 }
2571
2572 static int
2573 create_wireless_cipher_auth_session(uint8_t dev_id,
2574                 enum rte_crypto_cipher_operation cipher_op,
2575                 enum rte_crypto_auth_operation auth_op,
2576                 enum rte_crypto_auth_algorithm auth_algo,
2577                 enum rte_crypto_cipher_algorithm cipher_algo,
2578                 const struct wireless_test_data *tdata)
2579 {
2580         const uint8_t key_len = tdata->key.len;
2581         uint8_t cipher_auth_key[key_len];
2582         int status;
2583
2584         struct crypto_testsuite_params *ts_params = &testsuite_params;
2585         struct crypto_unittest_params *ut_params = &unittest_params;
2586         const uint8_t *key = tdata->key.data;
2587         const uint8_t auth_len = tdata->digest.len;
2588         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2589         uint8_t auth_iv_len = tdata->auth_iv.len;
2590
2591         memcpy(cipher_auth_key, key, key_len);
2592
2593         /* Setup Authentication Parameters */
2594         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2595         ut_params->auth_xform.next = NULL;
2596
2597         ut_params->auth_xform.auth.op = auth_op;
2598         ut_params->auth_xform.auth.algo = auth_algo;
2599         ut_params->auth_xform.auth.key.length = key_len;
2600         /* Hash key = cipher key */
2601         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2602         ut_params->auth_xform.auth.digest_length = auth_len;
2603         /* Auth IV will be after cipher IV */
2604         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2605         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2606
2607         /* Setup Cipher Parameters */
2608         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2609         ut_params->cipher_xform.next = &ut_params->auth_xform;
2610
2611         ut_params->cipher_xform.cipher.algo = cipher_algo;
2612         ut_params->cipher_xform.cipher.op = cipher_op;
2613         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2614         ut_params->cipher_xform.cipher.key.length = key_len;
2615         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2616         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2617
2618
2619         debug_hexdump(stdout, "key:", key, key_len);
2620
2621         /* Create Crypto session*/
2622         ut_params->sess = rte_cryptodev_sym_session_create(
2623                         ts_params->session_mpool);
2624
2625         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2626                         &ut_params->cipher_xform,
2627                         ts_params->session_priv_mpool);
2628         if (status == -ENOTSUP)
2629                 return TEST_SKIPPED;
2630
2631         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2632         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2633         return 0;
2634 }
2635
2636 static int
2637 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2638                 const struct wireless_test_data *tdata)
2639 {
2640         return create_wireless_cipher_auth_session(dev_id,
2641                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2642                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2643                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2644 }
2645
2646 static int
2647 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2648                 enum rte_crypto_cipher_operation cipher_op,
2649                 enum rte_crypto_auth_operation auth_op,
2650                 enum rte_crypto_auth_algorithm auth_algo,
2651                 enum rte_crypto_cipher_algorithm cipher_algo,
2652                 const uint8_t *key, const uint8_t key_len,
2653                 uint8_t auth_iv_len, uint8_t auth_len,
2654                 uint8_t cipher_iv_len)
2655 {
2656         uint8_t auth_cipher_key[key_len];
2657         int status;
2658         struct crypto_testsuite_params *ts_params = &testsuite_params;
2659         struct crypto_unittest_params *ut_params = &unittest_params;
2660
2661         memcpy(auth_cipher_key, key, key_len);
2662
2663         /* Setup Authentication Parameters */
2664         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2665         ut_params->auth_xform.auth.op = auth_op;
2666         ut_params->auth_xform.next = &ut_params->cipher_xform;
2667         ut_params->auth_xform.auth.algo = auth_algo;
2668         ut_params->auth_xform.auth.key.length = key_len;
2669         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2670         ut_params->auth_xform.auth.digest_length = auth_len;
2671         /* Auth IV will be after cipher IV */
2672         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2673         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2674
2675         /* Setup Cipher Parameters */
2676         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2677         ut_params->cipher_xform.next = NULL;
2678         ut_params->cipher_xform.cipher.algo = cipher_algo;
2679         ut_params->cipher_xform.cipher.op = cipher_op;
2680         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2681         ut_params->cipher_xform.cipher.key.length = key_len;
2682         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2683         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2684
2685         debug_hexdump(stdout, "key:", key, key_len);
2686
2687         /* Create Crypto session*/
2688         ut_params->sess = rte_cryptodev_sym_session_create(
2689                         ts_params->session_mpool);
2690         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2691
2692         if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2693                 ut_params->auth_xform.next = NULL;
2694                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2695                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2696                                 &ut_params->cipher_xform,
2697                                 ts_params->session_priv_mpool);
2698
2699         } else
2700                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2701                                 &ut_params->auth_xform,
2702                                 ts_params->session_priv_mpool);
2703
2704         if (status == -ENOTSUP)
2705                 return TEST_SKIPPED;
2706
2707         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2708
2709         return 0;
2710 }
2711
2712 static int
2713 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2714                 unsigned int auth_tag_len,
2715                 const uint8_t *iv, unsigned int iv_len,
2716                 unsigned int data_pad_len,
2717                 enum rte_crypto_auth_operation op,
2718                 unsigned int auth_len, unsigned int auth_offset)
2719 {
2720         struct crypto_testsuite_params *ts_params = &testsuite_params;
2721
2722         struct crypto_unittest_params *ut_params = &unittest_params;
2723
2724         /* Generate Crypto op data structure */
2725         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2726                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2727         TEST_ASSERT_NOT_NULL(ut_params->op,
2728                 "Failed to allocate pktmbuf offload");
2729
2730         /* Set crypto operation data parameters */
2731         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2732
2733         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2734
2735         /* set crypto operation source mbuf */
2736         sym_op->m_src = ut_params->ibuf;
2737
2738         /* iv */
2739         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2740                         iv, iv_len);
2741         /* digest */
2742         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2743                                         ut_params->ibuf, auth_tag_len);
2744
2745         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2746                                 "no room to append auth tag");
2747         ut_params->digest = sym_op->auth.digest.data;
2748         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2749                         ut_params->ibuf, data_pad_len);
2750         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2751                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2752         else
2753                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2754
2755         debug_hexdump(stdout, "digest:",
2756                 sym_op->auth.digest.data,
2757                 auth_tag_len);
2758
2759         sym_op->auth.data.length = auth_len;
2760         sym_op->auth.data.offset = auth_offset;
2761
2762         return 0;
2763 }
2764
2765 static int
2766 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2767         enum rte_crypto_auth_operation op)
2768 {
2769         struct crypto_testsuite_params *ts_params = &testsuite_params;
2770         struct crypto_unittest_params *ut_params = &unittest_params;
2771
2772         const uint8_t *auth_tag = tdata->digest.data;
2773         const unsigned int auth_tag_len = tdata->digest.len;
2774         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2775         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2776
2777         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2778         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2779         const uint8_t *auth_iv = tdata->auth_iv.data;
2780         const uint8_t auth_iv_len = tdata->auth_iv.len;
2781         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2782         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2783
2784         /* Generate Crypto op data structure */
2785         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2786                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2787         TEST_ASSERT_NOT_NULL(ut_params->op,
2788                         "Failed to allocate pktmbuf offload");
2789         /* Set crypto operation data parameters */
2790         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2791
2792         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2793
2794         /* set crypto operation source mbuf */
2795         sym_op->m_src = ut_params->ibuf;
2796
2797         /* digest */
2798         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2799                         ut_params->ibuf, auth_tag_len);
2800
2801         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2802                         "no room to append auth tag");
2803         ut_params->digest = sym_op->auth.digest.data;
2804         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2805                         ut_params->ibuf, data_pad_len);
2806         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2807                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2808         else
2809                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2810
2811         debug_hexdump(stdout, "digest:",
2812                 sym_op->auth.digest.data,
2813                 auth_tag_len);
2814
2815         /* Copy cipher and auth IVs at the end of the crypto operation */
2816         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2817                                                 IV_OFFSET);
2818         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2819         iv_ptr += cipher_iv_len;
2820         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2821
2822         sym_op->cipher.data.length = cipher_len;
2823         sym_op->cipher.data.offset = 0;
2824         sym_op->auth.data.length = auth_len;
2825         sym_op->auth.data.offset = 0;
2826
2827         return 0;
2828 }
2829
2830 static int
2831 create_zuc_cipher_hash_generate_operation(
2832                 const struct wireless_test_data *tdata)
2833 {
2834         return create_wireless_cipher_hash_operation(tdata,
2835                 RTE_CRYPTO_AUTH_OP_GENERATE);
2836 }
2837
2838 static int
2839 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2840                 const unsigned auth_tag_len,
2841                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2842                 unsigned data_pad_len,
2843                 enum rte_crypto_auth_operation op,
2844                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2845                 const unsigned cipher_len, const unsigned cipher_offset,
2846                 const unsigned auth_len, const unsigned auth_offset)
2847 {
2848         struct crypto_testsuite_params *ts_params = &testsuite_params;
2849         struct crypto_unittest_params *ut_params = &unittest_params;
2850
2851         enum rte_crypto_cipher_algorithm cipher_algo =
2852                         ut_params->cipher_xform.cipher.algo;
2853         enum rte_crypto_auth_algorithm auth_algo =
2854                         ut_params->auth_xform.auth.algo;
2855
2856         /* Generate Crypto op data structure */
2857         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2858                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2859         TEST_ASSERT_NOT_NULL(ut_params->op,
2860                         "Failed to allocate pktmbuf offload");
2861         /* Set crypto operation data parameters */
2862         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2863
2864         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2865
2866         /* set crypto operation source mbuf */
2867         sym_op->m_src = ut_params->ibuf;
2868
2869         /* digest */
2870         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2871                         ut_params->ibuf, auth_tag_len);
2872
2873         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2874                         "no room to append auth tag");
2875         ut_params->digest = sym_op->auth.digest.data;
2876
2877         if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2878                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2879                                 ut_params->ibuf, data_pad_len);
2880         } else {
2881                 struct rte_mbuf *m = ut_params->ibuf;
2882                 unsigned int offset = data_pad_len;
2883
2884                 while (offset > m->data_len && m->next != NULL) {
2885                         offset -= m->data_len;
2886                         m = m->next;
2887                 }
2888                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2889                         m, offset);
2890         }
2891
2892         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2893                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2894         else
2895                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2896
2897         debug_hexdump(stdout, "digest:",
2898                 sym_op->auth.digest.data,
2899                 auth_tag_len);
2900
2901         /* Copy cipher and auth IVs at the end of the crypto operation */
2902         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2903                                                 IV_OFFSET);
2904         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2905         iv_ptr += cipher_iv_len;
2906         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2907
2908         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2909                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2910                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2911                 sym_op->cipher.data.length = cipher_len;
2912                 sym_op->cipher.data.offset = cipher_offset;
2913         } else {
2914                 sym_op->cipher.data.length = cipher_len >> 3;
2915                 sym_op->cipher.data.offset = cipher_offset >> 3;
2916         }
2917
2918         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2919                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2920                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2921                 sym_op->auth.data.length = auth_len;
2922                 sym_op->auth.data.offset = auth_offset;
2923         } else {
2924                 sym_op->auth.data.length = auth_len >> 3;
2925                 sym_op->auth.data.offset = auth_offset >> 3;
2926         }
2927
2928         return 0;
2929 }
2930
2931 static int
2932 create_wireless_algo_auth_cipher_operation(
2933                 const uint8_t *auth_tag, unsigned int auth_tag_len,
2934                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2935                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2936                 unsigned int data_pad_len,
2937                 unsigned int cipher_len, unsigned int cipher_offset,
2938                 unsigned int auth_len, unsigned int auth_offset,
2939                 uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2940 {
2941         struct crypto_testsuite_params *ts_params = &testsuite_params;
2942         struct crypto_unittest_params *ut_params = &unittest_params;
2943
2944         enum rte_crypto_cipher_algorithm cipher_algo =
2945                         ut_params->cipher_xform.cipher.algo;
2946         enum rte_crypto_auth_algorithm auth_algo =
2947                         ut_params->auth_xform.auth.algo;
2948
2949         /* Generate Crypto op data structure */
2950         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2951                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2952         TEST_ASSERT_NOT_NULL(ut_params->op,
2953                         "Failed to allocate pktmbuf offload");
2954
2955         /* Set crypto operation data parameters */
2956         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2957
2958         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2959
2960         /* set crypto operation mbufs */
2961         sym_op->m_src = ut_params->ibuf;
2962         if (op_mode == OUT_OF_PLACE)
2963                 sym_op->m_dst = ut_params->obuf;
2964
2965         /* digest */
2966         if (!do_sgl) {
2967                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2968                         (op_mode == IN_PLACE ?
2969                                 ut_params->ibuf : ut_params->obuf),
2970                         uint8_t *, data_pad_len);
2971                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2972                         (op_mode == IN_PLACE ?
2973                                 ut_params->ibuf : ut_params->obuf),
2974                         data_pad_len);
2975                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2976         } else {
2977                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2978                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2979                                 sym_op->m_src : sym_op->m_dst);
2980                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2981                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2982                         sgl_buf = sgl_buf->next;
2983                 }
2984                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2985                                 uint8_t *, remaining_off);
2986                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2987                                 remaining_off);
2988                 memset(sym_op->auth.digest.data, 0, remaining_off);
2989                 while (sgl_buf->next != NULL) {
2990                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2991                                 0, rte_pktmbuf_data_len(sgl_buf));
2992                         sgl_buf = sgl_buf->next;
2993                 }
2994         }
2995
2996         /* Copy digest for the verification */
2997         if (verify)
2998                 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2999
3000         /* Copy cipher and auth IVs at the end of the crypto operation */
3001         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3002                         ut_params->op, uint8_t *, IV_OFFSET);
3003
3004         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3005         iv_ptr += cipher_iv_len;
3006         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3007
3008         /* Only copy over the offset data needed from src to dst in OOP,
3009          * if the auth and cipher offsets are not aligned
3010          */
3011         if (op_mode == OUT_OF_PLACE) {
3012                 if (cipher_offset > auth_offset)
3013                         rte_memcpy(
3014                                 rte_pktmbuf_mtod_offset(
3015                                         sym_op->m_dst,
3016                                         uint8_t *, auth_offset >> 3),
3017                                 rte_pktmbuf_mtod_offset(
3018                                         sym_op->m_src,
3019                                         uint8_t *, auth_offset >> 3),
3020                                 ((cipher_offset >> 3) - (auth_offset >> 3)));
3021         }
3022
3023         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3024                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3025                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3026                 sym_op->cipher.data.length = cipher_len;
3027                 sym_op->cipher.data.offset = cipher_offset;
3028         } else {
3029                 sym_op->cipher.data.length = cipher_len >> 3;
3030                 sym_op->cipher.data.offset = cipher_offset >> 3;
3031         }
3032
3033         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3034                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3035                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3036                 sym_op->auth.data.length = auth_len;
3037                 sym_op->auth.data.offset = auth_offset;
3038         } else {
3039                 sym_op->auth.data.length = auth_len >> 3;
3040                 sym_op->auth.data.offset = auth_offset >> 3;
3041         }
3042
3043         return 0;
3044 }
3045
3046 static int
3047 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3048 {
3049         struct crypto_testsuite_params *ts_params = &testsuite_params;
3050         struct crypto_unittest_params *ut_params = &unittest_params;
3051
3052         int retval;
3053         unsigned plaintext_pad_len;
3054         unsigned plaintext_len;
3055         uint8_t *plaintext;
3056         struct rte_cryptodev_info dev_info;
3057
3058         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3059         uint64_t feat_flags = dev_info.feature_flags;
3060
3061         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3062                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3063                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3064                 return TEST_SKIPPED;
3065         }
3066
3067         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3068                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3069                 printf("Device doesn't support RAW data-path APIs.\n");
3070                 return TEST_SKIPPED;
3071         }
3072
3073         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3074                 return TEST_SKIPPED;
3075
3076         /* Verify the capabilities */
3077         struct rte_cryptodev_sym_capability_idx cap_idx;
3078         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3079         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3080         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3081                         &cap_idx) == NULL)
3082                 return TEST_SKIPPED;
3083
3084         /* Create SNOW 3G session */
3085         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3086                         tdata->key.data, tdata->key.len,
3087                         tdata->auth_iv.len, tdata->digest.len,
3088                         RTE_CRYPTO_AUTH_OP_GENERATE,
3089                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3090         if (retval < 0)
3091                 return retval;
3092
3093         /* alloc mbuf and set payload */
3094         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3095
3096         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3097         rte_pktmbuf_tailroom(ut_params->ibuf));
3098
3099         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3100         /* Append data which is padded to a multiple of */
3101         /* the algorithms block size */
3102         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3103         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3104                                 plaintext_pad_len);
3105         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3106
3107         /* Create SNOW 3G operation */
3108         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3109                         tdata->auth_iv.data, tdata->auth_iv.len,
3110                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3111                         tdata->validAuthLenInBits.len,
3112                         0);
3113         if (retval < 0)
3114                 return retval;
3115
3116         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3117                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3118                                 ut_params->op, 0, 1, 1, 0);
3119         else
3120                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3121                                 ut_params->op);
3122         ut_params->obuf = ut_params->op->sym->m_src;
3123         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3124         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3125                         + plaintext_pad_len;
3126
3127         /* Validate obuf */
3128         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3129         ut_params->digest,
3130         tdata->digest.data,
3131         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3132         "SNOW 3G Generated auth tag not as expected");
3133
3134         return 0;
3135 }
3136
3137 static int
3138 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3139 {
3140         struct crypto_testsuite_params *ts_params = &testsuite_params;
3141         struct crypto_unittest_params *ut_params = &unittest_params;
3142
3143         int retval;
3144         unsigned plaintext_pad_len;
3145         unsigned plaintext_len;
3146         uint8_t *plaintext;
3147         struct rte_cryptodev_info dev_info;
3148
3149         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3150         uint64_t feat_flags = dev_info.feature_flags;
3151
3152         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3153                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3154                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3155                 return TEST_SKIPPED;
3156         }
3157
3158         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3159                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3160                 printf("Device doesn't support RAW data-path APIs.\n");
3161                 return TEST_SKIPPED;
3162         }
3163
3164         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3165                 return TEST_SKIPPED;
3166
3167         /* Verify the capabilities */
3168         struct rte_cryptodev_sym_capability_idx cap_idx;
3169         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3170         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3171         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3172                         &cap_idx) == NULL)
3173                 return TEST_SKIPPED;
3174
3175         /* Create SNOW 3G session */
3176         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3177                                 tdata->key.data, tdata->key.len,
3178                                 tdata->auth_iv.len, tdata->digest.len,
3179                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3180                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3181         if (retval < 0)
3182                 return retval;
3183         /* alloc mbuf and set payload */
3184         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3185
3186         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3187         rte_pktmbuf_tailroom(ut_params->ibuf));
3188
3189         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3190         /* Append data which is padded to a multiple of */
3191         /* the algorithms block size */
3192         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3193         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3194                                 plaintext_pad_len);
3195         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3196
3197         /* Create SNOW 3G operation */
3198         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3199                         tdata->digest.len,
3200                         tdata->auth_iv.data, tdata->auth_iv.len,
3201                         plaintext_pad_len,
3202                         RTE_CRYPTO_AUTH_OP_VERIFY,
3203                         tdata->validAuthLenInBits.len,
3204                         0);
3205         if (retval < 0)
3206                 return retval;
3207
3208         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3209                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3210                                 ut_params->op, 0, 1, 1, 0);
3211         else
3212                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3213                                 ut_params->op);
3214         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3215         ut_params->obuf = ut_params->op->sym->m_src;
3216         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3217                                 + plaintext_pad_len;
3218
3219         /* Validate obuf */
3220         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3221                 return 0;
3222         else
3223                 return -1;
3224
3225         return 0;
3226 }
3227
3228 static int
3229 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3230 {
3231         struct crypto_testsuite_params *ts_params = &testsuite_params;
3232         struct crypto_unittest_params *ut_params = &unittest_params;
3233
3234         int retval;
3235         unsigned plaintext_pad_len;
3236         unsigned plaintext_len;
3237         uint8_t *plaintext;
3238         struct rte_cryptodev_info dev_info;
3239
3240         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3241         uint64_t feat_flags = dev_info.feature_flags;
3242
3243         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3244                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3245                 printf("Device doesn't support RAW data-path APIs.\n");
3246                 return TEST_SKIPPED;
3247         }
3248
3249         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3250                 return TEST_SKIPPED;
3251
3252         /* Verify the capabilities */
3253         struct rte_cryptodev_sym_capability_idx cap_idx;
3254         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3255         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3256         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3257                         &cap_idx) == NULL)
3258                 return TEST_SKIPPED;
3259
3260         /* Create KASUMI session */
3261         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3262                         tdata->key.data, tdata->key.len,
3263                         0, tdata->digest.len,
3264                         RTE_CRYPTO_AUTH_OP_GENERATE,
3265                         RTE_CRYPTO_AUTH_KASUMI_F9);
3266         if (retval < 0)
3267                 return retval;
3268
3269         /* alloc mbuf and set payload */
3270         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3271
3272         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3273         rte_pktmbuf_tailroom(ut_params->ibuf));
3274
3275         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3276         /* Append data which is padded to a multiple of */
3277         /* the algorithms block size */
3278         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3279         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3280                                 plaintext_pad_len);
3281         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3282
3283         /* Create KASUMI operation */
3284         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3285                         NULL, 0,
3286                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3287                         tdata->plaintext.len,
3288                         0);
3289         if (retval < 0)
3290                 return retval;
3291
3292         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3293                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3294                         ut_params->op);
3295         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3296                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3297                                 ut_params->op, 0, 1, 1, 0);
3298         else
3299                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3300                         ut_params->op);
3301
3302         ut_params->obuf = ut_params->op->sym->m_src;
3303         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3304         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3305                         + plaintext_pad_len;
3306
3307         /* Validate obuf */
3308         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3309         ut_params->digest,
3310         tdata->digest.data,
3311         DIGEST_BYTE_LENGTH_KASUMI_F9,
3312         "KASUMI Generated auth tag not as expected");
3313
3314         return 0;
3315 }
3316
3317 static int
3318 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3319 {
3320         struct crypto_testsuite_params *ts_params = &testsuite_params;
3321         struct crypto_unittest_params *ut_params = &unittest_params;
3322
3323         int retval;
3324         unsigned plaintext_pad_len;
3325         unsigned plaintext_len;
3326         uint8_t *plaintext;
3327         struct rte_cryptodev_info dev_info;
3328
3329         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3330         uint64_t feat_flags = dev_info.feature_flags;
3331
3332         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3333                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3334                 printf("Device doesn't support RAW data-path APIs.\n");
3335                 return TEST_SKIPPED;
3336         }
3337
3338         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3339                 return TEST_SKIPPED;
3340
3341         /* Verify the capabilities */
3342         struct rte_cryptodev_sym_capability_idx cap_idx;
3343         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3344         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3345         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3346                         &cap_idx) == NULL)
3347                 return TEST_SKIPPED;
3348
3349         /* Create KASUMI session */
3350         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3351                                 tdata->key.data, tdata->key.len,
3352                                 0, tdata->digest.len,
3353                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3354                                 RTE_CRYPTO_AUTH_KASUMI_F9);
3355         if (retval < 0)
3356                 return retval;
3357         /* alloc mbuf and set payload */
3358         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3359
3360         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3361         rte_pktmbuf_tailroom(ut_params->ibuf));
3362
3363         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3364         /* Append data which is padded to a multiple */
3365         /* of the algorithms block size */
3366         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3367         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3368                                 plaintext_pad_len);
3369         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3370
3371         /* Create KASUMI operation */
3372         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3373                         tdata->digest.len,
3374                         NULL, 0,
3375                         plaintext_pad_len,
3376                         RTE_CRYPTO_AUTH_OP_VERIFY,
3377                         tdata->plaintext.len,
3378                         0);
3379         if (retval < 0)
3380                 return retval;
3381
3382         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3383                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3384                                 ut_params->op, 0, 1, 1, 0);
3385         else
3386                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3387                                 ut_params->op);
3388         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3389         ut_params->obuf = ut_params->op->sym->m_src;
3390         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3391                                 + plaintext_pad_len;
3392
3393         /* Validate obuf */
3394         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3395                 return 0;
3396         else
3397                 return -1;
3398
3399         return 0;
3400 }
3401
3402 static int
3403 test_snow3g_hash_generate_test_case_1(void)
3404 {
3405         return test_snow3g_authentication(&snow3g_hash_test_case_1);
3406 }
3407
3408 static int
3409 test_snow3g_hash_generate_test_case_2(void)
3410 {
3411         return test_snow3g_authentication(&snow3g_hash_test_case_2);
3412 }
3413
3414 static int
3415 test_snow3g_hash_generate_test_case_3(void)
3416 {
3417         return test_snow3g_authentication(&snow3g_hash_test_case_3);
3418 }
3419
3420 static int
3421 test_snow3g_hash_generate_test_case_4(void)
3422 {
3423         return test_snow3g_authentication(&snow3g_hash_test_case_4);
3424 }
3425
3426 static int
3427 test_snow3g_hash_generate_test_case_5(void)
3428 {
3429         return test_snow3g_authentication(&snow3g_hash_test_case_5);
3430 }
3431
3432 static int
3433 test_snow3g_hash_generate_test_case_6(void)
3434 {
3435         return test_snow3g_authentication(&snow3g_hash_test_case_6);
3436 }
3437
3438 static int
3439 test_snow3g_hash_verify_test_case_1(void)
3440 {
3441         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3442
3443 }
3444
3445 static int
3446 test_snow3g_hash_verify_test_case_2(void)
3447 {
3448         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3449 }
3450
3451 static int
3452 test_snow3g_hash_verify_test_case_3(void)
3453 {
3454         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3455 }
3456
3457 static int
3458 test_snow3g_hash_verify_test_case_4(void)
3459 {
3460         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3461 }
3462
3463 static int
3464 test_snow3g_hash_verify_test_case_5(void)
3465 {
3466         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3467 }
3468
3469 static int
3470 test_snow3g_hash_verify_test_case_6(void)
3471 {
3472         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3473 }
3474
3475 static int
3476 test_kasumi_hash_generate_test_case_1(void)
3477 {
3478         return test_kasumi_authentication(&kasumi_hash_test_case_1);
3479 }
3480
3481 static int
3482 test_kasumi_hash_generate_test_case_2(void)
3483 {
3484         return test_kasumi_authentication(&kasumi_hash_test_case_2);
3485 }
3486
3487 static int
3488 test_kasumi_hash_generate_test_case_3(void)
3489 {
3490         return test_kasumi_authentication(&kasumi_hash_test_case_3);
3491 }
3492
3493 static int
3494 test_kasumi_hash_generate_test_case_4(void)
3495 {
3496         return test_kasumi_authentication(&kasumi_hash_test_case_4);
3497 }
3498
3499 static int
3500 test_kasumi_hash_generate_test_case_5(void)
3501 {
3502         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3503 }
3504
3505 static int
3506 test_kasumi_hash_generate_test_case_6(void)
3507 {
3508         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3509 }
3510
3511 static int
3512 test_kasumi_hash_verify_test_case_1(void)
3513 {
3514         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3515 }
3516
3517 static int
3518 test_kasumi_hash_verify_test_case_2(void)
3519 {
3520         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3521 }
3522
3523 static int
3524 test_kasumi_hash_verify_test_case_3(void)
3525 {
3526         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3527 }
3528
3529 static int
3530 test_kasumi_hash_verify_test_case_4(void)
3531 {
3532         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3533 }
3534
3535 static int
3536 test_kasumi_hash_verify_test_case_5(void)
3537 {
3538         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3539 }
3540
3541 static int
3542 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3543 {
3544         struct crypto_testsuite_params *ts_params = &testsuite_params;
3545         struct crypto_unittest_params *ut_params = &unittest_params;
3546
3547         int retval;
3548         uint8_t *plaintext, *ciphertext;
3549         unsigned plaintext_pad_len;
3550         unsigned plaintext_len;
3551         struct rte_cryptodev_info dev_info;
3552
3553         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3554         uint64_t feat_flags = dev_info.feature_flags;
3555
3556         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3557                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3558                 printf("Device doesn't support RAW data-path APIs.\n");
3559                 return TEST_SKIPPED;
3560         }
3561
3562         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3563                 return TEST_SKIPPED;
3564
3565         /* Verify the capabilities */
3566         struct rte_cryptodev_sym_capability_idx cap_idx;
3567         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3568         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3569         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3570                         &cap_idx) == NULL)
3571                 return TEST_SKIPPED;
3572
3573         /* Create KASUMI session */
3574         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3575                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3576                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3577                                         tdata->key.data, tdata->key.len,
3578                                         tdata->cipher_iv.len);
3579         if (retval < 0)
3580                 return retval;
3581
3582         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3583
3584         /* Clear mbuf payload */
3585         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3586                rte_pktmbuf_tailroom(ut_params->ibuf));
3587
3588         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3589         /* Append data which is padded to a multiple */
3590         /* of the algorithms block size */
3591         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3592         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3593                                 plaintext_pad_len);
3594         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3595
3596         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3597
3598         /* Create KASUMI operation */
3599         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3600                                 tdata->cipher_iv.len,
3601                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3602                                 tdata->validCipherOffsetInBits.len);
3603         if (retval < 0)
3604                 return retval;
3605
3606         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3607                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3608                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3609         else
3610                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3611                                 ut_params->op);
3612         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3613
3614         ut_params->obuf = ut_params->op->sym->m_dst;
3615         if (ut_params->obuf)
3616                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3617         else
3618                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3619
3620         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3621
3622         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3623                                 (tdata->validCipherOffsetInBits.len >> 3);
3624         /* Validate obuf */
3625         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3626                 ciphertext,
3627                 reference_ciphertext,
3628                 tdata->validCipherLenInBits.len,
3629                 "KASUMI Ciphertext data not as expected");
3630         return 0;
3631 }
3632
3633 static int
3634 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3635 {
3636         struct crypto_testsuite_params *ts_params = &testsuite_params;
3637         struct crypto_unittest_params *ut_params = &unittest_params;
3638
3639         int retval;
3640
3641         unsigned int plaintext_pad_len;
3642         unsigned int plaintext_len;
3643
3644         uint8_t buffer[10000];
3645         const uint8_t *ciphertext;
3646
3647         struct rte_cryptodev_info dev_info;
3648
3649         /* Verify the capabilities */
3650         struct rte_cryptodev_sym_capability_idx cap_idx;
3651         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3652         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3653         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3654                         &cap_idx) == NULL)
3655                 return TEST_SKIPPED;
3656
3657         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3658
3659         uint64_t feat_flags = dev_info.feature_flags;
3660
3661         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3662                 printf("Device doesn't support in-place scatter-gather. "
3663                                 "Test Skipped.\n");
3664                 return TEST_SKIPPED;
3665         }
3666
3667         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3668                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3669                 printf("Device doesn't support RAW data-path APIs.\n");
3670                 return TEST_SKIPPED;
3671         }
3672
3673         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3674                 return TEST_SKIPPED;
3675
3676         /* Create KASUMI session */
3677         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3678                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3679                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3680                                         tdata->key.data, tdata->key.len,
3681                                         tdata->cipher_iv.len);
3682         if (retval < 0)
3683                 return retval;
3684
3685         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3686
3687
3688         /* Append data which is padded to a multiple */
3689         /* of the algorithms block size */
3690         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3691
3692         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3693                         plaintext_pad_len, 10, 0);
3694
3695         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3696
3697         /* Create KASUMI operation */
3698         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3699                                 tdata->cipher_iv.len,
3700                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3701                                 tdata->validCipherOffsetInBits.len);
3702         if (retval < 0)
3703                 return retval;
3704
3705         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3706                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3707                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3708         else
3709                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3710                                                 ut_params->op);
3711         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3712
3713         ut_params->obuf = ut_params->op->sym->m_dst;
3714
3715         if (ut_params->obuf)
3716                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3717                                 plaintext_len, buffer);
3718         else
3719                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3720                                 tdata->validCipherOffsetInBits.len >> 3,
3721                                 plaintext_len, buffer);
3722
3723         /* Validate obuf */
3724         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3725
3726         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3727                                 (tdata->validCipherOffsetInBits.len >> 3);
3728         /* Validate obuf */
3729         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3730                 ciphertext,
3731                 reference_ciphertext,
3732                 tdata->validCipherLenInBits.len,
3733                 "KASUMI Ciphertext data not as expected");
3734         return 0;
3735 }
3736
3737 static int
3738 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3739 {
3740         struct crypto_testsuite_params *ts_params = &testsuite_params;
3741         struct crypto_unittest_params *ut_params = &unittest_params;
3742
3743         int retval;
3744         uint8_t *plaintext, *ciphertext;
3745         unsigned plaintext_pad_len;
3746         unsigned plaintext_len;
3747
3748         /* Verify the capabilities */
3749         struct rte_cryptodev_sym_capability_idx cap_idx;
3750         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3751         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3752         /* Data-path service does not support OOP */
3753         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3754                         &cap_idx) == NULL)
3755                 return TEST_SKIPPED;
3756
3757         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3758                 return TEST_SKIPPED;
3759
3760         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3761                 return TEST_SKIPPED;
3762
3763         /* Create KASUMI session */
3764         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3765                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3766                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3767                                         tdata->key.data, tdata->key.len,
3768                                         tdata->cipher_iv.len);
3769         if (retval < 0)
3770                 return retval;
3771
3772         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3773         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3774
3775         /* Clear mbuf payload */
3776         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3777                rte_pktmbuf_tailroom(ut_params->ibuf));
3778
3779         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3780         /* Append data which is padded to a multiple */
3781         /* of the algorithms block size */
3782         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3783         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3784                                 plaintext_pad_len);
3785         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3786         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3787
3788         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3789
3790         /* Create KASUMI operation */
3791         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3792                                 tdata->cipher_iv.len,
3793                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3794                                 tdata->validCipherOffsetInBits.len);
3795         if (retval < 0)
3796                 return retval;
3797
3798         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3799                                                 ut_params->op);
3800         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3801
3802         ut_params->obuf = ut_params->op->sym->m_dst;
3803         if (ut_params->obuf)
3804                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3805         else
3806                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3807
3808         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3809
3810         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3811                                 (tdata->validCipherOffsetInBits.len >> 3);
3812         /* Validate obuf */
3813         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3814                 ciphertext,
3815                 reference_ciphertext,
3816                 tdata->validCipherLenInBits.len,
3817                 "KASUMI Ciphertext data not as expected");
3818         return 0;
3819 }
3820
3821 static int
3822 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3823 {
3824         struct crypto_testsuite_params *ts_params = &testsuite_params;
3825         struct crypto_unittest_params *ut_params = &unittest_params;
3826
3827         int retval;
3828         unsigned int plaintext_pad_len;
3829         unsigned int plaintext_len;
3830
3831         const uint8_t *ciphertext;
3832         uint8_t buffer[2048];
3833
3834         struct rte_cryptodev_info dev_info;
3835
3836         /* Verify the capabilities */
3837         struct rte_cryptodev_sym_capability_idx cap_idx;
3838         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3839         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3840         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3841                         &cap_idx) == NULL)
3842                 return TEST_SKIPPED;
3843
3844         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3845                 return TEST_SKIPPED;
3846
3847         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3848                 return TEST_SKIPPED;
3849
3850         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3851
3852         uint64_t feat_flags = dev_info.feature_flags;
3853         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3854                 printf("Device doesn't support out-of-place scatter-gather "
3855                                 "in both input and output mbufs. "
3856                                 "Test Skipped.\n");
3857                 return TEST_SKIPPED;
3858         }
3859
3860         /* Create KASUMI session */
3861         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3862                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3863                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3864                                         tdata->key.data, tdata->key.len,
3865                                         tdata->cipher_iv.len);
3866         if (retval < 0)
3867                 return retval;
3868
3869         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3870         /* Append data which is padded to a multiple */
3871         /* of the algorithms block size */
3872         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3873
3874         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3875                         plaintext_pad_len, 10, 0);
3876         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3877                         plaintext_pad_len, 3, 0);
3878
3879         /* Append data which is padded to a multiple */
3880         /* of the algorithms block size */
3881         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3882
3883         /* Create KASUMI operation */
3884         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3885                                 tdata->cipher_iv.len,
3886                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3887                                 tdata->validCipherOffsetInBits.len);
3888         if (retval < 0)
3889                 return retval;
3890
3891         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3892                                                 ut_params->op);
3893         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3894
3895         ut_params->obuf = ut_params->op->sym->m_dst;
3896         if (ut_params->obuf)
3897                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3898                                 plaintext_pad_len, buffer);
3899         else
3900                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3901                                 tdata->validCipherOffsetInBits.len >> 3,
3902                                 plaintext_pad_len, buffer);
3903
3904         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3905                                 (tdata->validCipherOffsetInBits.len >> 3);
3906         /* Validate obuf */
3907         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3908                 ciphertext,
3909                 reference_ciphertext,
3910                 tdata->validCipherLenInBits.len,
3911                 "KASUMI Ciphertext data not as expected");
3912         return 0;
3913 }
3914
3915
3916 static int
3917 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3918 {
3919         struct crypto_testsuite_params *ts_params = &testsuite_params;
3920         struct crypto_unittest_params *ut_params = &unittest_params;
3921
3922         int retval;
3923         uint8_t *ciphertext, *plaintext;
3924         unsigned ciphertext_pad_len;
3925         unsigned ciphertext_len;
3926
3927         /* Verify the capabilities */
3928         struct rte_cryptodev_sym_capability_idx cap_idx;
3929         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3930         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3931         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3932                         &cap_idx) == NULL)
3933                 return TEST_SKIPPED;
3934
3935         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3936                 return TEST_SKIPPED;
3937
3938         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3939                 return TEST_SKIPPED;
3940
3941         /* Create KASUMI session */
3942         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3943                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3944                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3945                                         tdata->key.data, tdata->key.len,
3946                                         tdata->cipher_iv.len);
3947         if (retval < 0)
3948                 return retval;
3949
3950         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3951         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3952
3953         /* Clear mbuf payload */
3954         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3955                rte_pktmbuf_tailroom(ut_params->ibuf));
3956
3957         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3958         /* Append data which is padded to a multiple */
3959         /* of the algorithms block size */
3960         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3961         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3962                                 ciphertext_pad_len);
3963         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3964         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3965
3966         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3967
3968         /* Create KASUMI operation */
3969         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3970                                 tdata->cipher_iv.len,
3971                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3972                                 tdata->validCipherOffsetInBits.len);
3973         if (retval < 0)
3974                 return retval;
3975
3976         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3977                                                 ut_params->op);
3978         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3979
3980         ut_params->obuf = ut_params->op->sym->m_dst;
3981         if (ut_params->obuf)
3982                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3983         else
3984                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3985
3986         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3987
3988         const uint8_t *reference_plaintext = tdata->plaintext.data +
3989                                 (tdata->validCipherOffsetInBits.len >> 3);
3990         /* Validate obuf */
3991         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3992                 plaintext,
3993                 reference_plaintext,
3994                 tdata->validCipherLenInBits.len,
3995                 "KASUMI Plaintext data not as expected");
3996         return 0;
3997 }
3998
3999 static int
4000 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4001 {
4002         struct crypto_testsuite_params *ts_params = &testsuite_params;
4003         struct crypto_unittest_params *ut_params = &unittest_params;
4004
4005         int retval;
4006         uint8_t *ciphertext, *plaintext;
4007         unsigned ciphertext_pad_len;
4008         unsigned ciphertext_len;
4009         struct rte_cryptodev_info dev_info;
4010
4011         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4012         uint64_t feat_flags = dev_info.feature_flags;
4013
4014         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4015                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4016                 printf("Device doesn't support RAW data-path APIs.\n");
4017                 return TEST_SKIPPED;
4018         }
4019
4020         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4021                 return TEST_SKIPPED;
4022
4023         /* Verify the capabilities */
4024         struct rte_cryptodev_sym_capability_idx cap_idx;
4025         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4026         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4027         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4028                         &cap_idx) == NULL)
4029                 return TEST_SKIPPED;
4030
4031         /* Create KASUMI session */
4032         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4033                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4034                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4035                                         tdata->key.data, tdata->key.len,
4036                                         tdata->cipher_iv.len);
4037         if (retval < 0)
4038                 return retval;
4039
4040         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4041
4042         /* Clear mbuf payload */
4043         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4044                rte_pktmbuf_tailroom(ut_params->ibuf));
4045
4046         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4047         /* Append data which is padded to a multiple */
4048         /* of the algorithms block size */
4049         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4050         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4051                                 ciphertext_pad_len);
4052         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4053
4054         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4055
4056         /* Create KASUMI operation */
4057         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4058                                         tdata->cipher_iv.len,
4059                                         tdata->ciphertext.len,
4060                                         tdata->validCipherOffsetInBits.len);
4061         if (retval < 0)
4062                 return retval;
4063
4064         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4065                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4066                                 ut_params->op, 1, 0, 1, 0);
4067         else
4068                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4069                                                 ut_params->op);
4070         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4071
4072         ut_params->obuf = ut_params->op->sym->m_dst;
4073         if (ut_params->obuf)
4074                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4075         else
4076                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4077
4078         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4079
4080         const uint8_t *reference_plaintext = tdata->plaintext.data +
4081                                 (tdata->validCipherOffsetInBits.len >> 3);
4082         /* Validate obuf */
4083         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4084                 plaintext,
4085                 reference_plaintext,
4086                 tdata->validCipherLenInBits.len,
4087                 "KASUMI Plaintext data not as expected");
4088         return 0;
4089 }
4090
4091 static int
4092 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4093 {
4094         struct crypto_testsuite_params *ts_params = &testsuite_params;
4095         struct crypto_unittest_params *ut_params = &unittest_params;
4096
4097         int retval;
4098         uint8_t *plaintext, *ciphertext;
4099         unsigned plaintext_pad_len;
4100         unsigned plaintext_len;
4101         struct rte_cryptodev_info dev_info;
4102
4103         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4104         uint64_t feat_flags = dev_info.feature_flags;
4105
4106         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4107                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4108                 printf("Device doesn't support RAW data-path APIs.\n");
4109                 return TEST_SKIPPED;
4110         }
4111
4112         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4113                 return TEST_SKIPPED;
4114
4115         /* Verify the capabilities */
4116         struct rte_cryptodev_sym_capability_idx cap_idx;
4117         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4118         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4119         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4120                         &cap_idx) == NULL)
4121                 return TEST_SKIPPED;
4122
4123         /* Create SNOW 3G session */
4124         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4125                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4126                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4127                                         tdata->key.data, tdata->key.len,
4128                                         tdata->cipher_iv.len);
4129         if (retval < 0)
4130                 return retval;
4131
4132         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4133
4134         /* Clear mbuf payload */
4135         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4136                rte_pktmbuf_tailroom(ut_params->ibuf));
4137
4138         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4139         /* Append data which is padded to a multiple of */
4140         /* the algorithms block size */
4141         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4142         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4143                                 plaintext_pad_len);
4144         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4145
4146         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4147
4148         /* Create SNOW 3G operation */
4149         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4150                                         tdata->cipher_iv.len,
4151                                         tdata->validCipherLenInBits.len,
4152                                         0);
4153         if (retval < 0)
4154                 return retval;
4155
4156         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4157                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4158                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4159         else
4160                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4161                                                 ut_params->op);
4162         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4163
4164         ut_params->obuf = ut_params->op->sym->m_dst;
4165         if (ut_params->obuf)
4166                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4167         else
4168                 ciphertext = plaintext;
4169
4170         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4171
4172         /* Validate obuf */
4173         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4174                 ciphertext,
4175                 tdata->ciphertext.data,
4176                 tdata->validDataLenInBits.len,
4177                 "SNOW 3G Ciphertext data not as expected");
4178         return 0;
4179 }
4180
4181
4182 static int
4183 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4184 {
4185         struct crypto_testsuite_params *ts_params = &testsuite_params;
4186         struct crypto_unittest_params *ut_params = &unittest_params;
4187         uint8_t *plaintext, *ciphertext;
4188
4189         int retval;
4190         unsigned plaintext_pad_len;
4191         unsigned plaintext_len;
4192
4193         /* Verify the capabilities */
4194         struct rte_cryptodev_sym_capability_idx cap_idx;
4195         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4196         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4197         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4198                         &cap_idx) == NULL)
4199                 return TEST_SKIPPED;
4200
4201         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4202                 return TEST_SKIPPED;
4203
4204         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4205                 return TEST_SKIPPED;
4206
4207         /* Create SNOW 3G session */
4208         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4209                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4210                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4211                                         tdata->key.data, tdata->key.len,
4212                                         tdata->cipher_iv.len);
4213         if (retval < 0)
4214                 return retval;
4215
4216         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4217         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4218
4219         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4220                         "Failed to allocate input buffer in mempool");
4221         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4222                         "Failed to allocate output buffer in mempool");
4223
4224         /* Clear mbuf payload */
4225         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4226                rte_pktmbuf_tailroom(ut_params->ibuf));
4227
4228         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4229         /* Append data which is padded to a multiple of */
4230         /* the algorithms block size */
4231         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4232         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4233                                 plaintext_pad_len);
4234         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4235         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4236
4237         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4238
4239         /* Create SNOW 3G operation */
4240         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4241                                         tdata->cipher_iv.len,
4242                                         tdata->validCipherLenInBits.len,
4243                                         0);
4244         if (retval < 0)
4245                 return retval;
4246
4247         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4248                                                 ut_params->op);
4249         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4250
4251         ut_params->obuf = ut_params->op->sym->m_dst;
4252         if (ut_params->obuf)
4253                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4254         else
4255                 ciphertext = plaintext;
4256
4257         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4258
4259         /* Validate obuf */
4260         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4261                 ciphertext,
4262                 tdata->ciphertext.data,
4263                 tdata->validDataLenInBits.len,
4264                 "SNOW 3G Ciphertext data not as expected");
4265         return 0;
4266 }
4267
4268 static int
4269 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4270 {
4271         struct crypto_testsuite_params *ts_params = &testsuite_params;
4272         struct crypto_unittest_params *ut_params = &unittest_params;
4273
4274         int retval;
4275         unsigned int plaintext_pad_len;
4276         unsigned int plaintext_len;
4277         uint8_t buffer[10000];
4278         const uint8_t *ciphertext;
4279
4280         struct rte_cryptodev_info dev_info;
4281
4282         /* Verify the capabilities */
4283         struct rte_cryptodev_sym_capability_idx cap_idx;
4284         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4285         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4286         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4287                         &cap_idx) == NULL)
4288                 return TEST_SKIPPED;
4289
4290         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4291                 return TEST_SKIPPED;
4292
4293         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4294                 return TEST_SKIPPED;
4295
4296         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4297
4298         uint64_t feat_flags = dev_info.feature_flags;
4299
4300         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4301                 printf("Device doesn't support out-of-place scatter-gather "
4302                                 "in both input and output mbufs. "
4303                                 "Test Skipped.\n");
4304                 return TEST_SKIPPED;
4305         }
4306
4307         /* Create SNOW 3G session */
4308         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4309                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4310                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4311                                         tdata->key.data, tdata->key.len,
4312                                         tdata->cipher_iv.len);
4313         if (retval < 0)
4314                 return retval;
4315
4316         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4317         /* Append data which is padded to a multiple of */
4318         /* the algorithms block size */
4319         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4320
4321         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4322                         plaintext_pad_len, 10, 0);
4323         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4324                         plaintext_pad_len, 3, 0);
4325
4326         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4327                         "Failed to allocate input buffer in mempool");
4328         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4329                         "Failed to allocate output buffer in mempool");
4330
4331         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4332
4333         /* Create SNOW 3G operation */
4334         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4335                                         tdata->cipher_iv.len,
4336                                         tdata->validCipherLenInBits.len,
4337                                         0);
4338         if (retval < 0)
4339                 return retval;
4340
4341         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4342                                                 ut_params->op);
4343         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4344
4345         ut_params->obuf = ut_params->op->sym->m_dst;
4346         if (ut_params->obuf)
4347                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4348                                 plaintext_len, buffer);
4349         else
4350                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4351                                 plaintext_len, buffer);
4352
4353         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4354
4355         /* Validate obuf */
4356         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4357                 ciphertext,
4358                 tdata->ciphertext.data,
4359                 tdata->validDataLenInBits.len,
4360                 "SNOW 3G Ciphertext data not as expected");
4361
4362         return 0;
4363 }
4364
4365 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4366 static void
4367 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4368 {
4369         uint8_t curr_byte, prev_byte;
4370         uint32_t length_in_bytes = ceil_byte_length(length + offset);
4371         uint8_t lower_byte_mask = (1 << offset) - 1;
4372         unsigned i;
4373
4374         prev_byte = buffer[0];
4375         buffer[0] >>= offset;
4376
4377         for (i = 1; i < length_in_bytes; i++) {
4378                 curr_byte = buffer[i];
4379                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4380                                 (curr_byte >> offset);
4381                 prev_byte = curr_byte;
4382         }
4383 }
4384
4385 static int
4386 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4387 {
4388         struct crypto_testsuite_params *ts_params = &testsuite_params;
4389         struct crypto_unittest_params *ut_params = &unittest_params;
4390         uint8_t *plaintext, *ciphertext;
4391         int retval;
4392         uint32_t plaintext_len;
4393         uint32_t plaintext_pad_len;
4394         uint8_t extra_offset = 4;
4395         uint8_t *expected_ciphertext_shifted;
4396         struct rte_cryptodev_info dev_info;
4397
4398         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4399         uint64_t feat_flags = dev_info.feature_flags;
4400
4401         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4402                         ((tdata->validDataLenInBits.len % 8) != 0)) {
4403                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4404                 return TEST_SKIPPED;
4405         }
4406
4407         /* Verify the capabilities */
4408         struct rte_cryptodev_sym_capability_idx cap_idx;
4409         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4410         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4411         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4412                         &cap_idx) == NULL)
4413                 return TEST_SKIPPED;
4414
4415         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4416                 return TEST_SKIPPED;
4417
4418         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4419                 return TEST_SKIPPED;
4420
4421         /* Create SNOW 3G session */
4422         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4423                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4424                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4425                                         tdata->key.data, tdata->key.len,
4426                                         tdata->cipher_iv.len);
4427         if (retval < 0)
4428                 return retval;
4429
4430         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4431         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4432
4433         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4434                         "Failed to allocate input buffer in mempool");
4435         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4436                         "Failed to allocate output buffer in mempool");
4437
4438         /* Clear mbuf payload */
4439         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4440                rte_pktmbuf_tailroom(ut_params->ibuf));
4441
4442         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4443         /*
4444          * Append data which is padded to a
4445          * multiple of the algorithms block size
4446          */
4447         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4448
4449         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4450                                                 plaintext_pad_len);
4451
4452         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4453
4454         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4455         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4456
4457 #ifdef RTE_APP_TEST_DEBUG
4458         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4459 #endif
4460         /* Create SNOW 3G operation */
4461         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4462                                         tdata->cipher_iv.len,
4463                                         tdata->validCipherLenInBits.len,
4464                                         extra_offset);
4465         if (retval < 0)
4466                 return retval;
4467
4468         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4469                                                 ut_params->op);
4470         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4471
4472         ut_params->obuf = ut_params->op->sym->m_dst;
4473         if (ut_params->obuf)
4474                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4475         else
4476                 ciphertext = plaintext;
4477
4478 #ifdef RTE_APP_TEST_DEBUG
4479         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4480 #endif
4481
4482         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4483
4484         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4485                         "failed to reserve memory for ciphertext shifted\n");
4486
4487         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4488                         ceil_byte_length(tdata->ciphertext.len));
4489         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4490                         extra_offset);
4491         /* Validate obuf */
4492         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4493                 ciphertext,
4494                 expected_ciphertext_shifted,
4495                 tdata->validDataLenInBits.len,
4496                 extra_offset,
4497                 "SNOW 3G Ciphertext data not as expected");
4498         return 0;
4499 }
4500
4501 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4502 {
4503         struct crypto_testsuite_params *ts_params = &testsuite_params;
4504         struct crypto_unittest_params *ut_params = &unittest_params;
4505
4506         int retval;
4507
4508         uint8_t *plaintext, *ciphertext;
4509         unsigned ciphertext_pad_len;
4510         unsigned ciphertext_len;
4511         struct rte_cryptodev_info dev_info;
4512
4513         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4514         uint64_t feat_flags = dev_info.feature_flags;
4515
4516         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4517                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4518                 printf("Device doesn't support RAW data-path APIs.\n");
4519                 return TEST_SKIPPED;
4520         }
4521
4522         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4523                 return TEST_SKIPPED;
4524
4525         /* Verify the capabilities */
4526         struct rte_cryptodev_sym_capability_idx cap_idx;
4527         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4528         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4529         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4530                         &cap_idx) == NULL)
4531                 return TEST_SKIPPED;
4532
4533         /* Create SNOW 3G session */
4534         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4535                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4536                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4537                                         tdata->key.data, tdata->key.len,
4538                                         tdata->cipher_iv.len);
4539         if (retval < 0)
4540                 return retval;
4541
4542         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4543
4544         /* Clear mbuf payload */
4545         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4546                rte_pktmbuf_tailroom(ut_params->ibuf));
4547
4548         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4549         /* Append data which is padded to a multiple of */
4550         /* the algorithms block size */
4551         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4552         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4553                                 ciphertext_pad_len);
4554         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4555
4556         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4557
4558         /* Create SNOW 3G operation */
4559         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4560                                         tdata->cipher_iv.len,
4561                                         tdata->validCipherLenInBits.len,
4562                                         tdata->cipher.offset_bits);
4563         if (retval < 0)
4564                 return retval;
4565
4566         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4567                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4568                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4569         else
4570                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4571                                                 ut_params->op);
4572         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4573         ut_params->obuf = ut_params->op->sym->m_dst;
4574         if (ut_params->obuf)
4575                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4576         else
4577                 plaintext = ciphertext;
4578
4579         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4580
4581         /* Validate obuf */
4582         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4583                                 tdata->plaintext.data,
4584                                 tdata->validDataLenInBits.len,
4585                                 "SNOW 3G Plaintext data not as expected");
4586         return 0;
4587 }
4588
4589 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4590 {
4591         struct crypto_testsuite_params *ts_params = &testsuite_params;
4592         struct crypto_unittest_params *ut_params = &unittest_params;
4593
4594         int retval;
4595
4596         uint8_t *plaintext, *ciphertext;
4597         unsigned ciphertext_pad_len;
4598         unsigned ciphertext_len;
4599
4600         /* Verify the capabilities */
4601         struct rte_cryptodev_sym_capability_idx cap_idx;
4602         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4603         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4604         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4605                         &cap_idx) == NULL)
4606                 return TEST_SKIPPED;
4607
4608         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4609                 return TEST_SKIPPED;
4610
4611         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4612                 return TEST_SKIPPED;
4613
4614         /* Create SNOW 3G session */
4615         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4616                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4617                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4618                                         tdata->key.data, tdata->key.len,
4619                                         tdata->cipher_iv.len);
4620         if (retval < 0)
4621                 return retval;
4622
4623         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4624         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4625
4626         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4627                         "Failed to allocate input buffer");
4628         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4629                         "Failed to allocate output buffer");
4630
4631         /* Clear mbuf payload */
4632         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4633                rte_pktmbuf_tailroom(ut_params->ibuf));
4634
4635         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4636                        rte_pktmbuf_tailroom(ut_params->obuf));
4637
4638         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4639         /* Append data which is padded to a multiple of */
4640         /* the algorithms block size */
4641         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4642         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4643                                 ciphertext_pad_len);
4644         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4645         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4646
4647         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4648
4649         /* Create SNOW 3G operation */
4650         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4651                                         tdata->cipher_iv.len,
4652                                         tdata->validCipherLenInBits.len,
4653                                         0);
4654         if (retval < 0)
4655                 return retval;
4656
4657         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4658                                                 ut_params->op);
4659         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4660         ut_params->obuf = ut_params->op->sym->m_dst;
4661         if (ut_params->obuf)
4662                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4663         else
4664                 plaintext = ciphertext;
4665
4666         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4667
4668         /* Validate obuf */
4669         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4670                                 tdata->plaintext.data,
4671                                 tdata->validDataLenInBits.len,
4672                                 "SNOW 3G Plaintext data not as expected");
4673         return 0;
4674 }
4675
4676 static int
4677 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4678 {
4679         struct crypto_testsuite_params *ts_params = &testsuite_params;
4680         struct crypto_unittest_params *ut_params = &unittest_params;
4681
4682         int retval;
4683
4684         uint8_t *plaintext, *ciphertext;
4685         unsigned int plaintext_pad_len;
4686         unsigned int plaintext_len;
4687
4688         struct rte_cryptodev_info dev_info;
4689         struct rte_cryptodev_sym_capability_idx cap_idx;
4690
4691         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4692         uint64_t feat_flags = dev_info.feature_flags;
4693
4694         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4695                         ((tdata->validAuthLenInBits.len % 8 != 0) ||
4696                         (tdata->validDataLenInBits.len % 8 != 0))) {
4697                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4698                 return TEST_SKIPPED;
4699         }
4700
4701         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4702                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4703                 printf("Device doesn't support RAW data-path APIs.\n");
4704                 return TEST_SKIPPED;
4705         }
4706
4707         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4708                 return TEST_SKIPPED;
4709
4710         /* Check if device supports ZUC EEA3 */
4711         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4712         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4713
4714         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4715                         &cap_idx) == NULL)
4716                 return TEST_SKIPPED;
4717
4718         /* Check if device supports ZUC EIA3 */
4719         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4720         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4721
4722         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4723                         &cap_idx) == NULL)
4724                 return TEST_SKIPPED;
4725
4726         /* Create ZUC session */
4727         retval = create_zuc_cipher_auth_encrypt_generate_session(
4728                         ts_params->valid_devs[0],
4729                         tdata);
4730         if (retval != 0)
4731                 return retval;
4732         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4733
4734         /* clear mbuf payload */
4735         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4736                         rte_pktmbuf_tailroom(ut_params->ibuf));
4737
4738         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4739         /* Append data which is padded to a multiple of */
4740         /* the algorithms block size */
4741         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4742         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4743                                 plaintext_pad_len);
4744         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4745
4746         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4747
4748         /* Create ZUC operation */
4749         retval = create_zuc_cipher_hash_generate_operation(tdata);
4750         if (retval < 0)
4751                 return retval;
4752
4753         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4754                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4755                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4756         else
4757                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4758                         ut_params->op);
4759         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4760         ut_params->obuf = ut_params->op->sym->m_src;
4761         if (ut_params->obuf)
4762                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4763         else
4764                 ciphertext = plaintext;
4765
4766         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4767         /* Validate obuf */
4768         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4769                         ciphertext,
4770                         tdata->ciphertext.data,
4771                         tdata->validDataLenInBits.len,
4772                         "ZUC Ciphertext data not as expected");
4773
4774         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4775             + plaintext_pad_len;
4776
4777         /* Validate obuf */
4778         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4779                         ut_params->digest,
4780                         tdata->digest.data,
4781                         4,
4782                         "ZUC Generated auth tag not as expected");
4783         return 0;
4784 }
4785
4786 static int
4787 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4788 {
4789         struct crypto_testsuite_params *ts_params = &testsuite_params;
4790         struct crypto_unittest_params *ut_params = &unittest_params;
4791
4792         int retval;
4793
4794         uint8_t *plaintext, *ciphertext;
4795         unsigned plaintext_pad_len;
4796         unsigned plaintext_len;
4797         struct rte_cryptodev_info dev_info;
4798
4799         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4800         uint64_t feat_flags = dev_info.feature_flags;
4801
4802         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4803                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4804                 printf("Device doesn't support RAW data-path APIs.\n");
4805                 return TEST_SKIPPED;
4806         }
4807
4808         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4809                 return TEST_SKIPPED;
4810
4811         /* Verify the capabilities */
4812         struct rte_cryptodev_sym_capability_idx cap_idx;
4813         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4814         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4815         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4816                         &cap_idx) == NULL)
4817                 return TEST_SKIPPED;
4818         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4819         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4820         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4821                         &cap_idx) == NULL)
4822                 return TEST_SKIPPED;
4823
4824         /* Create SNOW 3G session */
4825         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4826                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4827                         RTE_CRYPTO_AUTH_OP_GENERATE,
4828                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4829                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4830                         tdata->key.data, tdata->key.len,
4831                         tdata->auth_iv.len, tdata->digest.len,
4832                         tdata->cipher_iv.len);
4833         if (retval != 0)
4834                 return retval;
4835         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4836
4837         /* clear mbuf payload */
4838         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4839                         rte_pktmbuf_tailroom(ut_params->ibuf));
4840
4841         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4842         /* Append data which is padded to a multiple of */
4843         /* the algorithms block size */
4844         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4845         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4846                                 plaintext_pad_len);
4847         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4848
4849         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4850
4851         /* Create SNOW 3G operation */
4852         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4853                         tdata->digest.len, tdata->auth_iv.data,
4854                         tdata->auth_iv.len,
4855                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4856                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4857                         tdata->validCipherLenInBits.len,
4858                         0,
4859                         tdata->validAuthLenInBits.len,
4860                         0
4861                         );
4862         if (retval < 0)
4863                 return retval;
4864
4865         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4866                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4867                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4868         else
4869                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4870                         ut_params->op);
4871         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4872         ut_params->obuf = ut_params->op->sym->m_src;
4873         if (ut_params->obuf)
4874                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4875         else
4876                 ciphertext = plaintext;
4877
4878         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4879         /* Validate obuf */
4880         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4881                         ciphertext,
4882                         tdata->ciphertext.data,
4883                         tdata->validDataLenInBits.len,
4884                         "SNOW 3G Ciphertext data not as expected");
4885
4886         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4887             + plaintext_pad_len;
4888
4889         /* Validate obuf */
4890         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4891                         ut_params->digest,
4892                         tdata->digest.data,
4893                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4894                         "SNOW 3G Generated auth tag not as expected");
4895         return 0;
4896 }
4897
4898 static int
4899 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4900         uint8_t op_mode, uint8_t verify)
4901 {
4902         struct crypto_testsuite_params *ts_params = &testsuite_params;
4903         struct crypto_unittest_params *ut_params = &unittest_params;
4904
4905         int retval;
4906
4907         uint8_t *plaintext = NULL, *ciphertext = NULL;
4908         unsigned int plaintext_pad_len;
4909         unsigned int plaintext_len;
4910         unsigned int ciphertext_pad_len;
4911         unsigned int ciphertext_len;
4912
4913         struct rte_cryptodev_info dev_info;
4914
4915         /* Verify the capabilities */
4916         struct rte_cryptodev_sym_capability_idx cap_idx;
4917         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4918         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4919         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4920                         &cap_idx) == NULL)
4921                 return TEST_SKIPPED;
4922         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4923         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4924         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4925                         &cap_idx) == NULL)
4926                 return TEST_SKIPPED;
4927
4928         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4929                 return TEST_SKIPPED;
4930
4931         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4932
4933         uint64_t feat_flags = dev_info.feature_flags;
4934
4935         if (op_mode == OUT_OF_PLACE) {
4936                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4937                         printf("Device doesn't support digest encrypted.\n");
4938                         return TEST_SKIPPED;
4939                 }
4940                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4941                         return TEST_SKIPPED;
4942         }
4943
4944         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4945                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4946                 printf("Device doesn't support RAW data-path APIs.\n");
4947                 return TEST_SKIPPED;
4948         }
4949
4950         /* Create SNOW 3G session */
4951         retval = create_wireless_algo_auth_cipher_session(
4952                         ts_params->valid_devs[0],
4953                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4954                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4955                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4956                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4957                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4958                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4959                         tdata->key.data, tdata->key.len,
4960                         tdata->auth_iv.len, tdata->digest.len,
4961                         tdata->cipher_iv.len);
4962         if (retval != 0)
4963                 return retval;
4964
4965         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4966         if (op_mode == OUT_OF_PLACE)
4967                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4968
4969         /* clear mbuf payload */
4970         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4971                 rte_pktmbuf_tailroom(ut_params->ibuf));
4972         if (op_mode == OUT_OF_PLACE)
4973                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4974                         rte_pktmbuf_tailroom(ut_params->obuf));
4975
4976         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4977         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4978         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4979         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4980
4981         if (verify) {
4982                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4983                                         ciphertext_pad_len);
4984                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4985                 if (op_mode == OUT_OF_PLACE)
4986                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4987                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4988                         ciphertext_len);
4989         } else {
4990                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4991                                         plaintext_pad_len);
4992                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4993                 if (op_mode == OUT_OF_PLACE)
4994                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4995                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4996         }
4997
4998         /* Create SNOW 3G operation */
4999         retval = create_wireless_algo_auth_cipher_operation(
5000                 tdata->digest.data, tdata->digest.len,
5001                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5002                 tdata->auth_iv.data, tdata->auth_iv.len,
5003                 (tdata->digest.offset_bytes == 0 ?
5004                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5005                         : tdata->digest.offset_bytes),
5006                 tdata->validCipherLenInBits.len,
5007                 tdata->cipher.offset_bits,
5008                 tdata->validAuthLenInBits.len,
5009                 tdata->auth.offset_bits,
5010                 op_mode, 0, verify);
5011
5012         if (retval < 0)
5013                 return retval;
5014
5015         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5016                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5017                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5018         else
5019                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5020                         ut_params->op);
5021
5022         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5023
5024         ut_params->obuf = (op_mode == IN_PLACE ?
5025                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5026
5027         if (verify) {
5028                 if (ut_params->obuf)
5029                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5030                                                         uint8_t *);
5031                 else
5032                         plaintext = ciphertext +
5033                                 (tdata->cipher.offset_bits >> 3);
5034
5035                 debug_hexdump(stdout, "plaintext:", plaintext,
5036                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5037                 debug_hexdump(stdout, "plaintext expected:",
5038                         tdata->plaintext.data,
5039                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5040         } else {
5041                 if (ut_params->obuf)
5042                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5043                                                         uint8_t *);
5044                 else
5045                         ciphertext = plaintext;
5046
5047                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5048                         ciphertext_len);
5049                 debug_hexdump(stdout, "ciphertext expected:",
5050                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5051
5052                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5053                         + (tdata->digest.offset_bytes == 0 ?
5054                 plaintext_pad_len : tdata->digest.offset_bytes);
5055
5056                 debug_hexdump(stdout, "digest:", ut_params->digest,
5057                         tdata->digest.len);
5058                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5059                                 tdata->digest.len);
5060         }
5061
5062         /* Validate obuf */
5063         if (verify) {
5064                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5065                         plaintext,
5066                         tdata->plaintext.data,
5067                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5068                          (tdata->digest.len << 3)),
5069                         tdata->cipher.offset_bits,
5070                         "SNOW 3G Plaintext data not as expected");
5071         } else {
5072                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5073                         ciphertext,
5074                         tdata->ciphertext.data,
5075                         (tdata->validDataLenInBits.len -
5076                          tdata->cipher.offset_bits),
5077                         tdata->cipher.offset_bits,
5078                         "SNOW 3G Ciphertext data not as expected");
5079
5080                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5081                         ut_params->digest,
5082                         tdata->digest.data,
5083                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5084                         "SNOW 3G Generated auth tag not as expected");
5085         }
5086         return 0;
5087 }
5088
5089 static int
5090 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5091         uint8_t op_mode, uint8_t verify)
5092 {
5093         struct crypto_testsuite_params *ts_params = &testsuite_params;
5094         struct crypto_unittest_params *ut_params = &unittest_params;
5095
5096         int retval;
5097
5098         const uint8_t *plaintext = NULL;
5099         const uint8_t *ciphertext = NULL;
5100         const uint8_t *digest = NULL;
5101         unsigned int plaintext_pad_len;
5102         unsigned int plaintext_len;
5103         unsigned int ciphertext_pad_len;
5104         unsigned int ciphertext_len;
5105         uint8_t buffer[10000];
5106         uint8_t digest_buffer[10000];
5107
5108         struct rte_cryptodev_info dev_info;
5109
5110         /* Verify the capabilities */
5111         struct rte_cryptodev_sym_capability_idx cap_idx;
5112         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5113         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5114         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5115                         &cap_idx) == NULL)
5116                 return TEST_SKIPPED;
5117         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5118         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5119         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5120                         &cap_idx) == NULL)
5121                 return TEST_SKIPPED;
5122
5123         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5124                 return TEST_SKIPPED;
5125
5126         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5127
5128         uint64_t feat_flags = dev_info.feature_flags;
5129
5130         if (op_mode == IN_PLACE) {
5131                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5132                         printf("Device doesn't support in-place scatter-gather "
5133                                         "in both input and output mbufs.\n");
5134                         return TEST_SKIPPED;
5135                 }
5136                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5137                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5138                         printf("Device doesn't support RAW data-path APIs.\n");
5139                         return TEST_SKIPPED;
5140                 }
5141         } else {
5142                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5143                         return TEST_SKIPPED;
5144                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5145                         printf("Device doesn't support out-of-place scatter-gather "
5146                                         "in both input and output mbufs.\n");
5147                         return TEST_SKIPPED;
5148                 }
5149                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5150                         printf("Device doesn't support digest encrypted.\n");
5151                         return TEST_SKIPPED;
5152                 }
5153         }
5154
5155         /* Create SNOW 3G session */
5156         retval = create_wireless_algo_auth_cipher_session(
5157                         ts_params->valid_devs[0],
5158                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5159                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5160                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5161                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5162                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5163                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5164                         tdata->key.data, tdata->key.len,
5165                         tdata->auth_iv.len, tdata->digest.len,
5166                         tdata->cipher_iv.len);
5167
5168         if (retval != 0)
5169                 return retval;
5170
5171         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5172         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5173         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5174         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5175
5176         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5177                         plaintext_pad_len, 15, 0);
5178         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5179                         "Failed to allocate input buffer in mempool");
5180
5181         if (op_mode == OUT_OF_PLACE) {
5182                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5183                                 plaintext_pad_len, 15, 0);
5184                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5185                                 "Failed to allocate output buffer in mempool");
5186         }
5187
5188         if (verify) {
5189                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5190                         tdata->ciphertext.data);
5191                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5192                                         ciphertext_len, buffer);
5193                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5194                         ciphertext_len);
5195         } else {
5196                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5197                         tdata->plaintext.data);
5198                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5199                                         plaintext_len, buffer);
5200                 debug_hexdump(stdout, "plaintext:", plaintext,
5201                         plaintext_len);
5202         }
5203         memset(buffer, 0, sizeof(buffer));
5204
5205         /* Create SNOW 3G operation */
5206         retval = create_wireless_algo_auth_cipher_operation(
5207                 tdata->digest.data, tdata->digest.len,
5208                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5209                 tdata->auth_iv.data, tdata->auth_iv.len,
5210                 (tdata->digest.offset_bytes == 0 ?
5211                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5212                         : tdata->digest.offset_bytes),
5213                 tdata->validCipherLenInBits.len,
5214                 tdata->cipher.offset_bits,
5215                 tdata->validAuthLenInBits.len,
5216                 tdata->auth.offset_bits,
5217                 op_mode, 1, verify);
5218
5219         if (retval < 0)
5220                 return retval;
5221
5222         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5223                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5224                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5225         else
5226                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5227                         ut_params->op);
5228
5229         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5230
5231         ut_params->obuf = (op_mode == IN_PLACE ?
5232                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5233
5234         if (verify) {
5235                 if (ut_params->obuf)
5236                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5237                                         plaintext_len, buffer);
5238                 else
5239                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5240                                         plaintext_len, buffer);
5241
5242                 debug_hexdump(stdout, "plaintext:", plaintext,
5243                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5244                 debug_hexdump(stdout, "plaintext expected:",
5245                         tdata->plaintext.data,
5246                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5247         } else {
5248                 if (ut_params->obuf)
5249                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5250                                         ciphertext_len, buffer);
5251                 else
5252                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5253                                         ciphertext_len, buffer);
5254
5255                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5256                         ciphertext_len);
5257                 debug_hexdump(stdout, "ciphertext expected:",
5258                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5259
5260                 if (ut_params->obuf)
5261                         digest = rte_pktmbuf_read(ut_params->obuf,
5262                                 (tdata->digest.offset_bytes == 0 ?
5263                                 plaintext_pad_len : tdata->digest.offset_bytes),
5264                                 tdata->digest.len, digest_buffer);
5265                 else
5266                         digest = rte_pktmbuf_read(ut_params->ibuf,
5267                                 (tdata->digest.offset_bytes == 0 ?
5268                                 plaintext_pad_len : tdata->digest.offset_bytes),
5269                                 tdata->digest.len, digest_buffer);
5270
5271                 debug_hexdump(stdout, "digest:", digest,
5272                         tdata->digest.len);
5273                 debug_hexdump(stdout, "digest expected:",
5274                         tdata->digest.data, tdata->digest.len);
5275         }
5276
5277         /* Validate obuf */
5278         if (verify) {
5279                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5280                         plaintext,
5281                         tdata->plaintext.data,
5282                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5283                          (tdata->digest.len << 3)),
5284                         tdata->cipher.offset_bits,
5285                         "SNOW 3G Plaintext data not as expected");
5286         } else {
5287                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5288                         ciphertext,
5289                         tdata->ciphertext.data,
5290                         (tdata->validDataLenInBits.len -
5291                          tdata->cipher.offset_bits),
5292                         tdata->cipher.offset_bits,
5293                         "SNOW 3G Ciphertext data not as expected");
5294
5295                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5296                         digest,
5297                         tdata->digest.data,
5298                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5299                         "SNOW 3G Generated auth tag not as expected");
5300         }
5301         return 0;
5302 }
5303
5304 static int
5305 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5306         uint8_t op_mode, uint8_t verify)
5307 {
5308         struct crypto_testsuite_params *ts_params = &testsuite_params;
5309         struct crypto_unittest_params *ut_params = &unittest_params;
5310
5311         int retval;
5312
5313         uint8_t *plaintext = NULL, *ciphertext = NULL;
5314         unsigned int plaintext_pad_len;
5315         unsigned int plaintext_len;
5316         unsigned int ciphertext_pad_len;
5317         unsigned int ciphertext_len;
5318
5319         struct rte_cryptodev_info dev_info;
5320
5321         /* Verify the capabilities */
5322         struct rte_cryptodev_sym_capability_idx cap_idx;
5323         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5324         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5325         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5326                         &cap_idx) == NULL)
5327                 return TEST_SKIPPED;
5328         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5329         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5330         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5331                         &cap_idx) == NULL)
5332                 return TEST_SKIPPED;
5333
5334         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5335
5336         uint64_t feat_flags = dev_info.feature_flags;
5337
5338         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5339                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5340                 printf("Device doesn't support RAW data-path APIs.\n");
5341                 return TEST_SKIPPED;
5342         }
5343
5344         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5345                 return TEST_SKIPPED;
5346
5347         if (op_mode == OUT_OF_PLACE) {
5348                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5349                         return TEST_SKIPPED;
5350                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5351                         printf("Device doesn't support digest encrypted.\n");
5352                         return TEST_SKIPPED;
5353                 }
5354         }
5355
5356         /* Create KASUMI session */
5357         retval = create_wireless_algo_auth_cipher_session(
5358                         ts_params->valid_devs[0],
5359                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5360                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5361                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5362                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5363                         RTE_CRYPTO_AUTH_KASUMI_F9,
5364                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5365                         tdata->key.data, tdata->key.len,
5366                         0, tdata->digest.len,
5367                         tdata->cipher_iv.len);
5368
5369         if (retval != 0)
5370                 return retval;
5371
5372         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5373         if (op_mode == OUT_OF_PLACE)
5374                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5375
5376         /* clear mbuf payload */
5377         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5378                 rte_pktmbuf_tailroom(ut_params->ibuf));
5379         if (op_mode == OUT_OF_PLACE)
5380                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5381                         rte_pktmbuf_tailroom(ut_params->obuf));
5382
5383         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5384         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5385         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5386         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5387
5388         if (verify) {
5389                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5390                                         ciphertext_pad_len);
5391                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5392                 if (op_mode == OUT_OF_PLACE)
5393                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5394                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5395                         ciphertext_len);
5396         } else {
5397                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5398                                         plaintext_pad_len);
5399                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5400                 if (op_mode == OUT_OF_PLACE)
5401                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5402                 debug_hexdump(stdout, "plaintext:", plaintext,
5403                         plaintext_len);
5404         }
5405
5406         /* Create KASUMI operation */
5407         retval = create_wireless_algo_auth_cipher_operation(
5408                 tdata->digest.data, tdata->digest.len,
5409                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5410                 NULL, 0,
5411                 (tdata->digest.offset_bytes == 0 ?
5412                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5413                         : tdata->digest.offset_bytes),
5414                 tdata->validCipherLenInBits.len,
5415                 tdata->validCipherOffsetInBits.len,
5416                 tdata->validAuthLenInBits.len,
5417                 0,
5418                 op_mode, 0, verify);
5419
5420         if (retval < 0)
5421                 return retval;
5422
5423         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5424                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5425                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5426         else
5427                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5428                         ut_params->op);
5429
5430         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5431
5432         ut_params->obuf = (op_mode == IN_PLACE ?
5433                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5434
5435
5436         if (verify) {
5437                 if (ut_params->obuf)
5438                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5439                                                         uint8_t *);
5440                 else
5441                         plaintext = ciphertext;
5442
5443                 debug_hexdump(stdout, "plaintext:", plaintext,
5444                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5445                 debug_hexdump(stdout, "plaintext expected:",
5446                         tdata->plaintext.data,
5447                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5448         } else {
5449                 if (ut_params->obuf)
5450                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5451                                                         uint8_t *);
5452                 else
5453                         ciphertext = plaintext;
5454
5455                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5456                         ciphertext_len);
5457                 debug_hexdump(stdout, "ciphertext expected:",
5458                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5459
5460                 ut_params->digest = rte_pktmbuf_mtod(
5461                         ut_params->obuf, uint8_t *) +
5462                         (tdata->digest.offset_bytes == 0 ?
5463                         plaintext_pad_len : tdata->digest.offset_bytes);
5464
5465                 debug_hexdump(stdout, "digest:", ut_params->digest,
5466                         tdata->digest.len);
5467                 debug_hexdump(stdout, "digest expected:",
5468                         tdata->digest.data, tdata->digest.len);
5469         }
5470
5471         /* Validate obuf */
5472         if (verify) {
5473                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5474                         plaintext,
5475                         tdata->plaintext.data,
5476                         tdata->plaintext.len >> 3,
5477                         "KASUMI Plaintext data not as expected");
5478         } else {
5479                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5480                         ciphertext,
5481                         tdata->ciphertext.data,
5482                         tdata->ciphertext.len >> 3,
5483                         "KASUMI Ciphertext data not as expected");
5484
5485                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5486                         ut_params->digest,
5487                         tdata->digest.data,
5488                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5489                         "KASUMI Generated auth tag not as expected");
5490         }
5491         return 0;
5492 }
5493
5494 static int
5495 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5496         uint8_t op_mode, uint8_t verify)
5497 {
5498         struct crypto_testsuite_params *ts_params = &testsuite_params;
5499         struct crypto_unittest_params *ut_params = &unittest_params;
5500
5501         int retval;
5502
5503         const uint8_t *plaintext = NULL;
5504         const uint8_t *ciphertext = NULL;
5505         const uint8_t *digest = NULL;
5506         unsigned int plaintext_pad_len;
5507         unsigned int plaintext_len;
5508         unsigned int ciphertext_pad_len;
5509         unsigned int ciphertext_len;
5510         uint8_t buffer[10000];
5511         uint8_t digest_buffer[10000];
5512
5513         struct rte_cryptodev_info dev_info;
5514
5515         /* Verify the capabilities */
5516         struct rte_cryptodev_sym_capability_idx cap_idx;
5517         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5518         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5519         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5520                         &cap_idx) == NULL)
5521                 return TEST_SKIPPED;
5522         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5523         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5524         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5525                         &cap_idx) == NULL)
5526                 return TEST_SKIPPED;
5527
5528         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5529                 return TEST_SKIPPED;
5530
5531         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5532
5533         uint64_t feat_flags = dev_info.feature_flags;
5534
5535         if (op_mode == IN_PLACE) {
5536                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5537                         printf("Device doesn't support in-place scatter-gather "
5538                                         "in both input and output mbufs.\n");
5539                         return TEST_SKIPPED;
5540                 }
5541                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5542                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5543                         printf("Device doesn't support RAW data-path APIs.\n");
5544                         return TEST_SKIPPED;
5545                 }
5546         } else {
5547                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5548                         return TEST_SKIPPED;
5549                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5550                         printf("Device doesn't support out-of-place scatter-gather "
5551                                         "in both input and output mbufs.\n");
5552                         return TEST_SKIPPED;
5553                 }
5554                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5555                         printf("Device doesn't support digest encrypted.\n");
5556                         return TEST_SKIPPED;
5557                 }
5558         }
5559
5560         /* Create KASUMI session */
5561         retval = create_wireless_algo_auth_cipher_session(
5562                         ts_params->valid_devs[0],
5563                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5564                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5565                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5566                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5567                         RTE_CRYPTO_AUTH_KASUMI_F9,
5568                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5569                         tdata->key.data, tdata->key.len,
5570                         0, tdata->digest.len,
5571                         tdata->cipher_iv.len);
5572
5573         if (retval != 0)
5574                 return retval;
5575
5576         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5577         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5578         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5579         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5580
5581         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5582                         plaintext_pad_len, 15, 0);
5583         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5584                         "Failed to allocate input buffer in mempool");
5585
5586         if (op_mode == OUT_OF_PLACE) {
5587                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5588                                 plaintext_pad_len, 15, 0);
5589                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5590                                 "Failed to allocate output buffer in mempool");
5591         }
5592
5593         if (verify) {
5594                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5595                         tdata->ciphertext.data);
5596                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5597                                         ciphertext_len, buffer);
5598                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5599                         ciphertext_len);
5600         } else {
5601                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5602                         tdata->plaintext.data);
5603                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5604                                         plaintext_len, buffer);
5605                 debug_hexdump(stdout, "plaintext:", plaintext,
5606                         plaintext_len);
5607         }
5608         memset(buffer, 0, sizeof(buffer));
5609
5610         /* Create KASUMI operation */
5611         retval = create_wireless_algo_auth_cipher_operation(
5612                 tdata->digest.data, tdata->digest.len,
5613                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5614                 NULL, 0,
5615                 (tdata->digest.offset_bytes == 0 ?
5616                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5617                         : tdata->digest.offset_bytes),
5618                 tdata->validCipherLenInBits.len,
5619                 tdata->validCipherOffsetInBits.len,
5620                 tdata->validAuthLenInBits.len,
5621                 0,
5622                 op_mode, 1, verify);
5623
5624         if (retval < 0)
5625                 return retval;
5626
5627         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5628                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5629                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5630         else
5631                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5632                         ut_params->op);
5633
5634         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5635
5636         ut_params->obuf = (op_mode == IN_PLACE ?
5637                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5638
5639         if (verify) {
5640                 if (ut_params->obuf)
5641                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5642                                         plaintext_len, buffer);
5643                 else
5644                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5645                                         plaintext_len, buffer);
5646
5647                 debug_hexdump(stdout, "plaintext:", plaintext,
5648                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5649                 debug_hexdump(stdout, "plaintext expected:",
5650                         tdata->plaintext.data,
5651                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5652         } else {
5653                 if (ut_params->obuf)
5654                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5655                                         ciphertext_len, buffer);
5656                 else
5657                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5658                                         ciphertext_len, buffer);
5659
5660                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5661                         ciphertext_len);
5662                 debug_hexdump(stdout, "ciphertext expected:",
5663                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5664
5665                 if (ut_params->obuf)
5666                         digest = rte_pktmbuf_read(ut_params->obuf,
5667                                 (tdata->digest.offset_bytes == 0 ?
5668                                 plaintext_pad_len : tdata->digest.offset_bytes),
5669                                 tdata->digest.len, digest_buffer);
5670                 else
5671                         digest = rte_pktmbuf_read(ut_params->ibuf,
5672                                 (tdata->digest.offset_bytes == 0 ?
5673                                 plaintext_pad_len : tdata->digest.offset_bytes),
5674                                 tdata->digest.len, digest_buffer);
5675
5676                 debug_hexdump(stdout, "digest:", digest,
5677                         tdata->digest.len);
5678                 debug_hexdump(stdout, "digest expected:",
5679                         tdata->digest.data, tdata->digest.len);
5680         }
5681
5682         /* Validate obuf */
5683         if (verify) {
5684                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5685                         plaintext,
5686                         tdata->plaintext.data,
5687                         tdata->plaintext.len >> 3,
5688                         "KASUMI Plaintext data not as expected");
5689         } else {
5690                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5691                         ciphertext,
5692                         tdata->ciphertext.data,
5693                         tdata->validDataLenInBits.len,
5694                         "KASUMI Ciphertext data not as expected");
5695
5696                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5697                         digest,
5698                         tdata->digest.data,
5699                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5700                         "KASUMI Generated auth tag not as expected");
5701         }
5702         return 0;
5703 }
5704
5705 static int
5706 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5707 {
5708         struct crypto_testsuite_params *ts_params = &testsuite_params;
5709         struct crypto_unittest_params *ut_params = &unittest_params;
5710
5711         int retval;
5712
5713         uint8_t *plaintext, *ciphertext;
5714         unsigned plaintext_pad_len;
5715         unsigned plaintext_len;
5716         struct rte_cryptodev_info dev_info;
5717
5718         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5719         uint64_t feat_flags = dev_info.feature_flags;
5720
5721         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5722                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5723                 printf("Device doesn't support RAW data-path APIs.\n");
5724                 return TEST_SKIPPED;
5725         }
5726
5727         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5728                 return TEST_SKIPPED;
5729
5730         /* Verify the capabilities */
5731         struct rte_cryptodev_sym_capability_idx cap_idx;
5732         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5733         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5734         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5735                         &cap_idx) == NULL)
5736                 return TEST_SKIPPED;
5737         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5738         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5739         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5740                         &cap_idx) == NULL)
5741                 return TEST_SKIPPED;
5742
5743         /* Create KASUMI session */
5744         retval = create_wireless_algo_cipher_auth_session(
5745                         ts_params->valid_devs[0],
5746                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5747                         RTE_CRYPTO_AUTH_OP_GENERATE,
5748                         RTE_CRYPTO_AUTH_KASUMI_F9,
5749                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5750                         tdata->key.data, tdata->key.len,
5751                         0, tdata->digest.len,
5752                         tdata->cipher_iv.len);
5753         if (retval != 0)
5754                 return retval;
5755
5756         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5757
5758         /* clear mbuf payload */
5759         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5760                         rte_pktmbuf_tailroom(ut_params->ibuf));
5761
5762         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5763         /* Append data which is padded to a multiple of */
5764         /* the algorithms block size */
5765         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5766         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5767                                 plaintext_pad_len);
5768         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5769
5770         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5771
5772         /* Create KASUMI operation */
5773         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5774                                 tdata->digest.len, NULL, 0,
5775                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5776                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5777                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5778                                 tdata->validCipherOffsetInBits.len,
5779                                 tdata->validAuthLenInBits.len,
5780                                 0
5781                                 );
5782         if (retval < 0)
5783                 return retval;
5784
5785         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5786                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5787                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5788         else
5789                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5790                         ut_params->op);
5791         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5792
5793         if (ut_params->op->sym->m_dst)
5794                 ut_params->obuf = ut_params->op->sym->m_dst;
5795         else
5796                 ut_params->obuf = ut_params->op->sym->m_src;
5797
5798         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5799                                 tdata->validCipherOffsetInBits.len >> 3);
5800
5801         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5802                         + plaintext_pad_len;
5803
5804         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5805                                 (tdata->validCipherOffsetInBits.len >> 3);
5806         /* Validate obuf */
5807         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5808                 ciphertext,
5809                 reference_ciphertext,
5810                 tdata->validCipherLenInBits.len,
5811                 "KASUMI Ciphertext data not as expected");
5812
5813         /* Validate obuf */
5814         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5815                 ut_params->digest,
5816                 tdata->digest.data,
5817                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5818                 "KASUMI Generated auth tag not as expected");
5819         return 0;
5820 }
5821
5822 static int
5823 test_zuc_encryption(const struct wireless_test_data *tdata)
5824 {
5825         struct crypto_testsuite_params *ts_params = &testsuite_params;
5826         struct crypto_unittest_params *ut_params = &unittest_params;
5827
5828         int retval;
5829         uint8_t *plaintext, *ciphertext;
5830         unsigned plaintext_pad_len;
5831         unsigned plaintext_len;
5832         struct rte_cryptodev_info dev_info;
5833
5834         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5835         uint64_t feat_flags = dev_info.feature_flags;
5836
5837         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5838                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5839                 printf("Device doesn't support RAW data-path APIs.\n");
5840                 return TEST_SKIPPED;
5841         }
5842
5843         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5844                 return TEST_SKIPPED;
5845
5846         struct rte_cryptodev_sym_capability_idx cap_idx;
5847
5848         /* Check if device supports ZUC EEA3 */
5849         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5850         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5851
5852         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5853                         &cap_idx) == NULL)
5854                 return TEST_SKIPPED;
5855
5856         /* Create ZUC session */
5857         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5858                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5859                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5860                                         tdata->key.data, tdata->key.len,
5861                                         tdata->cipher_iv.len);
5862         if (retval < 0)
5863                 return retval;
5864
5865         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5866
5867         /* Clear mbuf payload */
5868         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5869                rte_pktmbuf_tailroom(ut_params->ibuf));
5870
5871         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5872         /* Append data which is padded to a multiple */
5873         /* of the algorithms block size */
5874         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5875         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5876                                 plaintext_pad_len);
5877         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5878
5879         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5880
5881         /* Create ZUC operation */
5882         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5883                                         tdata->cipher_iv.len,
5884                                         tdata->plaintext.len,
5885                                         0);
5886         if (retval < 0)
5887                 return retval;
5888
5889         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5890                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5891                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5892         else
5893                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5894                                                 ut_params->op);
5895         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5896
5897         ut_params->obuf = ut_params->op->sym->m_dst;
5898         if (ut_params->obuf)
5899                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5900         else
5901                 ciphertext = plaintext;
5902
5903         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5904
5905         /* Validate obuf */
5906         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5907                 ciphertext,
5908                 tdata->ciphertext.data,
5909                 tdata->validCipherLenInBits.len,
5910                 "ZUC Ciphertext data not as expected");
5911         return 0;
5912 }
5913
5914 static int
5915 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5916 {
5917         struct crypto_testsuite_params *ts_params = &testsuite_params;
5918         struct crypto_unittest_params *ut_params = &unittest_params;
5919
5920         int retval;
5921
5922         unsigned int plaintext_pad_len;
5923         unsigned int plaintext_len;
5924         const uint8_t *ciphertext;
5925         uint8_t ciphertext_buffer[2048];
5926         struct rte_cryptodev_info dev_info;
5927
5928         struct rte_cryptodev_sym_capability_idx cap_idx;
5929
5930         /* Check if device supports ZUC EEA3 */
5931         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5932         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5933
5934         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5935                         &cap_idx) == NULL)
5936                 return TEST_SKIPPED;
5937
5938         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5939                 return TEST_SKIPPED;
5940
5941         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5942
5943         uint64_t feat_flags = dev_info.feature_flags;
5944
5945         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5946                 printf("Device doesn't support in-place scatter-gather. "
5947                                 "Test Skipped.\n");
5948                 return TEST_SKIPPED;
5949         }
5950
5951         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5952                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5953                 printf("Device doesn't support RAW data-path APIs.\n");
5954                 return TEST_SKIPPED;
5955         }
5956
5957         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5958
5959         /* Append data which is padded to a multiple */
5960         /* of the algorithms block size */
5961         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5962
5963         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5964                         plaintext_pad_len, 10, 0);
5965
5966         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5967                         tdata->plaintext.data);
5968
5969         /* Create ZUC session */
5970         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5971                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5972                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5973                         tdata->key.data, tdata->key.len,
5974                         tdata->cipher_iv.len);
5975         if (retval < 0)
5976                 return retval;
5977
5978         /* Clear mbuf payload */
5979
5980         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5981
5982         /* Create ZUC operation */
5983         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5984                         tdata->cipher_iv.len, tdata->plaintext.len,
5985                         0);
5986         if (retval < 0)
5987                 return retval;
5988
5989         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5990                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5991                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5992         else
5993                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5994                                                 ut_params->op);
5995         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5996
5997         ut_params->obuf = ut_params->op->sym->m_dst;
5998         if (ut_params->obuf)
5999                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
6000                         0, plaintext_len, ciphertext_buffer);
6001         else
6002                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6003                         0, plaintext_len, ciphertext_buffer);
6004
6005         /* Validate obuf */
6006         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6007
6008         /* Validate obuf */
6009         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6010                 ciphertext,
6011                 tdata->ciphertext.data,
6012                 tdata->validCipherLenInBits.len,
6013                 "ZUC Ciphertext data not as expected");
6014
6015         return 0;
6016 }
6017
6018 static int
6019 test_zuc_authentication(const struct wireless_test_data *tdata)
6020 {
6021         struct crypto_testsuite_params *ts_params = &testsuite_params;
6022         struct crypto_unittest_params *ut_params = &unittest_params;
6023
6024         int retval;
6025         unsigned plaintext_pad_len;
6026         unsigned plaintext_len;
6027         uint8_t *plaintext;
6028
6029         struct rte_cryptodev_sym_capability_idx cap_idx;
6030         struct rte_cryptodev_info dev_info;
6031
6032         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6033         uint64_t feat_flags = dev_info.feature_flags;
6034
6035         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6036                         (tdata->validAuthLenInBits.len % 8 != 0)) {
6037                 printf("Device doesn't support NON-Byte Aligned Data.\n");
6038                 return TEST_SKIPPED;
6039         }
6040
6041         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6042                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6043                 printf("Device doesn't support RAW data-path APIs.\n");
6044                 return TEST_SKIPPED;
6045         }
6046
6047         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6048                 return TEST_SKIPPED;
6049
6050         /* Check if device supports ZUC EIA3 */
6051         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6052         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6053
6054         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6055                         &cap_idx) == NULL)
6056                 return TEST_SKIPPED;
6057
6058         /* Create ZUC session */
6059         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6060                         tdata->key.data, tdata->key.len,
6061                         tdata->auth_iv.len, tdata->digest.len,
6062                         RTE_CRYPTO_AUTH_OP_GENERATE,
6063                         RTE_CRYPTO_AUTH_ZUC_EIA3);
6064         if (retval < 0)
6065                 return retval;
6066
6067         /* alloc mbuf and set payload */
6068         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6069
6070         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6071         rte_pktmbuf_tailroom(ut_params->ibuf));
6072
6073         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6074         /* Append data which is padded to a multiple of */
6075         /* the algorithms block size */
6076         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6077         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6078                                 plaintext_pad_len);
6079         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6080
6081         /* Create ZUC operation */
6082         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6083                         tdata->auth_iv.data, tdata->auth_iv.len,
6084                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6085                         tdata->validAuthLenInBits.len,
6086                         0);
6087         if (retval < 0)
6088                 return retval;
6089
6090         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6091                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6092                                 ut_params->op, 0, 1, 1, 0);
6093         else
6094                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6095                                 ut_params->op);
6096         ut_params->obuf = ut_params->op->sym->m_src;
6097         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6098         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6099                         + plaintext_pad_len;
6100
6101         /* Validate obuf */
6102         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6103         ut_params->digest,
6104         tdata->digest.data,
6105         tdata->digest.len,
6106         "ZUC Generated auth tag not as expected");
6107
6108         return 0;
6109 }
6110
6111 static int
6112 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6113         uint8_t op_mode, uint8_t verify)
6114 {
6115         struct crypto_testsuite_params *ts_params = &testsuite_params;
6116         struct crypto_unittest_params *ut_params = &unittest_params;
6117
6118         int retval;
6119
6120         uint8_t *plaintext = NULL, *ciphertext = NULL;
6121         unsigned int plaintext_pad_len;
6122         unsigned int plaintext_len;
6123         unsigned int ciphertext_pad_len;
6124         unsigned int ciphertext_len;
6125
6126         struct rte_cryptodev_info dev_info;
6127         struct rte_cryptodev_sym_capability_idx cap_idx;
6128
6129         /* Check if device supports ZUC EIA3 */
6130         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6131         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6132
6133         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6134                         &cap_idx) == NULL)
6135                 return TEST_SKIPPED;
6136
6137         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6138
6139         uint64_t feat_flags = dev_info.feature_flags;
6140
6141         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6142                 printf("Device doesn't support digest encrypted.\n");
6143                 return TEST_SKIPPED;
6144         }
6145         if (op_mode == IN_PLACE) {
6146                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6147                         printf("Device doesn't support in-place scatter-gather "
6148                                         "in both input and output mbufs.\n");
6149                         return TEST_SKIPPED;
6150                 }
6151
6152                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6153                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6154                         printf("Device doesn't support RAW data-path APIs.\n");
6155                         return TEST_SKIPPED;
6156                 }
6157         } else {
6158                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6159                         return TEST_SKIPPED;
6160                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6161                         printf("Device doesn't support out-of-place scatter-gather "
6162                                         "in both input and output mbufs.\n");
6163                         return TEST_SKIPPED;
6164                 }
6165         }
6166
6167         /* Create ZUC session */
6168         retval = create_wireless_algo_auth_cipher_session(
6169                         ts_params->valid_devs[0],
6170                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6171                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6172                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6173                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6174                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6175                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6176                         tdata->key.data, tdata->key.len,
6177                         tdata->auth_iv.len, tdata->digest.len,
6178                         tdata->cipher_iv.len);
6179
6180         if (retval != 0)
6181                 return retval;
6182
6183         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6184         if (op_mode == OUT_OF_PLACE)
6185                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6186
6187         /* clear mbuf payload */
6188         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6189                 rte_pktmbuf_tailroom(ut_params->ibuf));
6190         if (op_mode == OUT_OF_PLACE)
6191                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6192                         rte_pktmbuf_tailroom(ut_params->obuf));
6193
6194         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6195         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6196         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6197         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6198
6199         if (verify) {
6200                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6201                                         ciphertext_pad_len);
6202                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6203                 if (op_mode == OUT_OF_PLACE)
6204                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6205                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6206                         ciphertext_len);
6207         } else {
6208                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6209                                         plaintext_pad_len);
6210                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6211                 if (op_mode == OUT_OF_PLACE)
6212                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6213                 debug_hexdump(stdout, "plaintext:", plaintext,
6214                         plaintext_len);
6215         }
6216
6217         /* Create ZUC operation */
6218         retval = create_wireless_algo_auth_cipher_operation(
6219                 tdata->digest.data, tdata->digest.len,
6220                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6221                 tdata->auth_iv.data, tdata->auth_iv.len,
6222                 (tdata->digest.offset_bytes == 0 ?
6223                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6224                         : tdata->digest.offset_bytes),
6225                 tdata->validCipherLenInBits.len,
6226                 tdata->validCipherOffsetInBits.len,
6227                 tdata->validAuthLenInBits.len,
6228                 0,
6229                 op_mode, 0, verify);
6230
6231         if (retval < 0)
6232                 return retval;
6233
6234         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6235                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6236                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6237         else
6238                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6239                         ut_params->op);
6240
6241         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6242
6243         ut_params->obuf = (op_mode == IN_PLACE ?
6244                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6245
6246
6247         if (verify) {
6248                 if (ut_params->obuf)
6249                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6250                                                         uint8_t *);
6251                 else
6252                         plaintext = ciphertext;
6253
6254                 debug_hexdump(stdout, "plaintext:", plaintext,
6255                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6256                 debug_hexdump(stdout, "plaintext expected:",
6257                         tdata->plaintext.data,
6258                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6259         } else {
6260                 if (ut_params->obuf)
6261                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6262                                                         uint8_t *);
6263                 else
6264                         ciphertext = plaintext;
6265
6266                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6267                         ciphertext_len);
6268                 debug_hexdump(stdout, "ciphertext expected:",
6269                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6270
6271                 ut_params->digest = rte_pktmbuf_mtod(
6272                         ut_params->obuf, uint8_t *) +
6273                         (tdata->digest.offset_bytes == 0 ?
6274                         plaintext_pad_len : tdata->digest.offset_bytes);
6275
6276                 debug_hexdump(stdout, "digest:", ut_params->digest,
6277                         tdata->digest.len);
6278                 debug_hexdump(stdout, "digest expected:",
6279                         tdata->digest.data, tdata->digest.len);
6280         }
6281
6282         /* Validate obuf */
6283         if (verify) {
6284                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6285                         plaintext,
6286                         tdata->plaintext.data,
6287                         tdata->plaintext.len >> 3,
6288                         "ZUC Plaintext data not as expected");
6289         } else {
6290                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6291                         ciphertext,
6292                         tdata->ciphertext.data,
6293                         tdata->ciphertext.len >> 3,
6294                         "ZUC Ciphertext data not as expected");
6295
6296                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6297                         ut_params->digest,
6298                         tdata->digest.data,
6299                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6300                         "ZUC Generated auth tag not as expected");
6301         }
6302         return 0;
6303 }
6304
6305 static int
6306 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6307         uint8_t op_mode, uint8_t verify)
6308 {
6309         struct crypto_testsuite_params *ts_params = &testsuite_params;
6310         struct crypto_unittest_params *ut_params = &unittest_params;
6311
6312         int retval;
6313
6314         const uint8_t *plaintext = NULL;
6315         const uint8_t *ciphertext = NULL;
6316         const uint8_t *digest = NULL;
6317         unsigned int plaintext_pad_len;
6318         unsigned int plaintext_len;
6319         unsigned int ciphertext_pad_len;
6320         unsigned int ciphertext_len;
6321         uint8_t buffer[10000];
6322         uint8_t digest_buffer[10000];
6323
6324         struct rte_cryptodev_info dev_info;
6325         struct rte_cryptodev_sym_capability_idx cap_idx;
6326
6327         /* Check if device supports ZUC EIA3 */
6328         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6329         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6330
6331         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6332                         &cap_idx) == NULL)
6333                 return TEST_SKIPPED;
6334
6335         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6336
6337         uint64_t feat_flags = dev_info.feature_flags;
6338
6339         if (op_mode == IN_PLACE) {
6340                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6341                         printf("Device doesn't support in-place scatter-gather "
6342                                         "in both input and output mbufs.\n");
6343                         return TEST_SKIPPED;
6344                 }
6345
6346                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6347                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6348                         printf("Device doesn't support RAW data-path APIs.\n");
6349                         return TEST_SKIPPED;
6350                 }
6351         } else {
6352                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6353                         return TEST_SKIPPED;
6354                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6355                         printf("Device doesn't support out-of-place scatter-gather "
6356                                         "in both input and output mbufs.\n");
6357                         return TEST_SKIPPED;
6358                 }
6359                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6360                         printf("Device doesn't support digest encrypted.\n");
6361                         return TEST_SKIPPED;
6362                 }
6363         }
6364
6365         /* Create ZUC session */
6366         retval = create_wireless_algo_auth_cipher_session(
6367                         ts_params->valid_devs[0],
6368                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6369                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6370                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6371                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6372                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6373                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6374                         tdata->key.data, tdata->key.len,
6375                         tdata->auth_iv.len, tdata->digest.len,
6376                         tdata->cipher_iv.len);
6377
6378         if (retval != 0)
6379                 return retval;
6380
6381         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6382         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6383         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6384         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6385
6386         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6387                         plaintext_pad_len, 15, 0);
6388         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6389                         "Failed to allocate input buffer in mempool");
6390
6391         if (op_mode == OUT_OF_PLACE) {
6392                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6393                                 plaintext_pad_len, 15, 0);
6394                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6395                                 "Failed to allocate output buffer in mempool");
6396         }
6397
6398         if (verify) {
6399                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6400                         tdata->ciphertext.data);
6401                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6402                                         ciphertext_len, buffer);
6403                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6404                         ciphertext_len);
6405         } else {
6406                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6407                         tdata->plaintext.data);
6408                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6409                                         plaintext_len, buffer);
6410                 debug_hexdump(stdout, "plaintext:", plaintext,
6411                         plaintext_len);
6412         }
6413         memset(buffer, 0, sizeof(buffer));
6414
6415         /* Create ZUC operation */
6416         retval = create_wireless_algo_auth_cipher_operation(
6417                 tdata->digest.data, tdata->digest.len,
6418                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6419                 NULL, 0,
6420                 (tdata->digest.offset_bytes == 0 ?
6421                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6422                         : tdata->digest.offset_bytes),
6423                 tdata->validCipherLenInBits.len,
6424                 tdata->validCipherOffsetInBits.len,
6425                 tdata->validAuthLenInBits.len,
6426                 0,
6427                 op_mode, 1, verify);
6428
6429         if (retval < 0)
6430                 return retval;
6431
6432         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6433                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6434                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6435         else
6436                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6437                         ut_params->op);
6438
6439         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6440
6441         ut_params->obuf = (op_mode == IN_PLACE ?
6442                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6443
6444         if (verify) {
6445                 if (ut_params->obuf)
6446                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6447                                         plaintext_len, buffer);
6448                 else
6449                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6450                                         plaintext_len, buffer);
6451
6452                 debug_hexdump(stdout, "plaintext:", plaintext,
6453                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6454                 debug_hexdump(stdout, "plaintext expected:",
6455                         tdata->plaintext.data,
6456                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6457         } else {
6458                 if (ut_params->obuf)
6459                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6460                                         ciphertext_len, buffer);
6461                 else
6462                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6463                                         ciphertext_len, buffer);
6464
6465                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6466                         ciphertext_len);
6467                 debug_hexdump(stdout, "ciphertext expected:",
6468                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6469
6470                 if (ut_params->obuf)
6471                         digest = rte_pktmbuf_read(ut_params->obuf,
6472                                 (tdata->digest.offset_bytes == 0 ?
6473                                 plaintext_pad_len : tdata->digest.offset_bytes),
6474                                 tdata->digest.len, digest_buffer);
6475                 else
6476                         digest = rte_pktmbuf_read(ut_params->ibuf,
6477                                 (tdata->digest.offset_bytes == 0 ?
6478                                 plaintext_pad_len : tdata->digest.offset_bytes),
6479                                 tdata->digest.len, digest_buffer);
6480
6481                 debug_hexdump(stdout, "digest:", digest,
6482                         tdata->digest.len);
6483                 debug_hexdump(stdout, "digest expected:",
6484                         tdata->digest.data, tdata->digest.len);
6485         }
6486
6487         /* Validate obuf */
6488         if (verify) {
6489                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6490                         plaintext,
6491                         tdata->plaintext.data,
6492                         tdata->plaintext.len >> 3,
6493                         "ZUC Plaintext data not as expected");
6494         } else {
6495                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6496                         ciphertext,
6497                         tdata->ciphertext.data,
6498                         tdata->validDataLenInBits.len,
6499                         "ZUC Ciphertext data not as expected");
6500
6501                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6502                         digest,
6503                         tdata->digest.data,
6504                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6505                         "ZUC Generated auth tag not as expected");
6506         }
6507         return 0;
6508 }
6509
6510 static int
6511 test_kasumi_encryption_test_case_1(void)
6512 {
6513         return test_kasumi_encryption(&kasumi_test_case_1);
6514 }
6515
6516 static int
6517 test_kasumi_encryption_test_case_1_sgl(void)
6518 {
6519         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6520 }
6521
6522 static int
6523 test_kasumi_encryption_test_case_1_oop(void)
6524 {
6525         return test_kasumi_encryption_oop(&kasumi_test_case_1);
6526 }
6527
6528 static int
6529 test_kasumi_encryption_test_case_1_oop_sgl(void)
6530 {
6531         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6532 }
6533
6534 static int
6535 test_kasumi_encryption_test_case_2(void)
6536 {
6537         return test_kasumi_encryption(&kasumi_test_case_2);
6538 }
6539
6540 static int
6541 test_kasumi_encryption_test_case_3(void)
6542 {
6543         return test_kasumi_encryption(&kasumi_test_case_3);
6544 }
6545
6546 static int
6547 test_kasumi_encryption_test_case_4(void)
6548 {
6549         return test_kasumi_encryption(&kasumi_test_case_4);
6550 }
6551
6552 static int
6553 test_kasumi_encryption_test_case_5(void)
6554 {
6555         return test_kasumi_encryption(&kasumi_test_case_5);
6556 }
6557
6558 static int
6559 test_kasumi_decryption_test_case_1(void)
6560 {
6561         return test_kasumi_decryption(&kasumi_test_case_1);
6562 }
6563
6564 static int
6565 test_kasumi_decryption_test_case_1_oop(void)
6566 {
6567         return test_kasumi_decryption_oop(&kasumi_test_case_1);
6568 }
6569
6570 static int
6571 test_kasumi_decryption_test_case_2(void)
6572 {
6573         return test_kasumi_decryption(&kasumi_test_case_2);
6574 }
6575
6576 static int
6577 test_kasumi_decryption_test_case_3(void)
6578 {
6579         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6580         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6581                 return TEST_SKIPPED;
6582         return test_kasumi_decryption(&kasumi_test_case_3);
6583 }
6584
6585 static int
6586 test_kasumi_decryption_test_case_4(void)
6587 {
6588         return test_kasumi_decryption(&kasumi_test_case_4);
6589 }
6590
6591 static int
6592 test_kasumi_decryption_test_case_5(void)
6593 {
6594         return test_kasumi_decryption(&kasumi_test_case_5);
6595 }
6596 static int
6597 test_snow3g_encryption_test_case_1(void)
6598 {
6599         return test_snow3g_encryption(&snow3g_test_case_1);
6600 }
6601
6602 static int
6603 test_snow3g_encryption_test_case_1_oop(void)
6604 {
6605         return test_snow3g_encryption_oop(&snow3g_test_case_1);
6606 }
6607
6608 static int
6609 test_snow3g_encryption_test_case_1_oop_sgl(void)
6610 {
6611         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6612 }
6613
6614
6615 static int
6616 test_snow3g_encryption_test_case_1_offset_oop(void)
6617 {
6618         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6619 }
6620
6621 static int
6622 test_snow3g_encryption_test_case_2(void)
6623 {
6624         return test_snow3g_encryption(&snow3g_test_case_2);
6625 }
6626
6627 static int
6628 test_snow3g_encryption_test_case_3(void)
6629 {
6630         return test_snow3g_encryption(&snow3g_test_case_3);
6631 }
6632
6633 static int
6634 test_snow3g_encryption_test_case_4(void)
6635 {
6636         return test_snow3g_encryption(&snow3g_test_case_4);
6637 }
6638
6639 static int
6640 test_snow3g_encryption_test_case_5(void)
6641 {
6642         return test_snow3g_encryption(&snow3g_test_case_5);
6643 }
6644
6645 static int
6646 test_snow3g_decryption_test_case_1(void)
6647 {
6648         return test_snow3g_decryption(&snow3g_test_case_1);
6649 }
6650
6651 static int
6652 test_snow3g_decryption_test_case_1_oop(void)
6653 {
6654         return test_snow3g_decryption_oop(&snow3g_test_case_1);
6655 }
6656
6657 static int
6658 test_snow3g_decryption_test_case_2(void)
6659 {
6660         return test_snow3g_decryption(&snow3g_test_case_2);
6661 }
6662
6663 static int
6664 test_snow3g_decryption_test_case_3(void)
6665 {
6666         return test_snow3g_decryption(&snow3g_test_case_3);
6667 }
6668
6669 static int
6670 test_snow3g_decryption_test_case_4(void)
6671 {
6672         return test_snow3g_decryption(&snow3g_test_case_4);
6673 }
6674
6675 static int
6676 test_snow3g_decryption_test_case_5(void)
6677 {
6678         return test_snow3g_decryption(&snow3g_test_case_5);
6679 }
6680
6681 /*
6682  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6683  * Pattern digest from snow3g_test_data must be allocated as
6684  * 4 last bytes in plaintext.
6685  */
6686 static void
6687 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6688                 struct snow3g_hash_test_data *output)
6689 {
6690         if ((pattern != NULL) && (output != NULL)) {
6691                 output->key.len = pattern->key.len;
6692
6693                 memcpy(output->key.data,
6694                 pattern->key.data, pattern->key.len);
6695
6696                 output->auth_iv.len = pattern->auth_iv.len;
6697
6698                 memcpy(output->auth_iv.data,
6699                 pattern->auth_iv.data, pattern->auth_iv.len);
6700
6701                 output->plaintext.len = pattern->plaintext.len;
6702
6703                 memcpy(output->plaintext.data,
6704                 pattern->plaintext.data, pattern->plaintext.len >> 3);
6705
6706                 output->digest.len = pattern->digest.len;
6707
6708                 memcpy(output->digest.data,
6709                 &pattern->plaintext.data[pattern->digest.offset_bytes],
6710                 pattern->digest.len);
6711
6712                 output->validAuthLenInBits.len =
6713                 pattern->validAuthLenInBits.len;
6714         }
6715 }
6716
6717 /*
6718  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6719  */
6720 static int
6721 test_snow3g_decryption_with_digest_test_case_1(void)
6722 {
6723         struct snow3g_hash_test_data snow3g_hash_data;
6724         struct rte_cryptodev_info dev_info;
6725         struct crypto_testsuite_params *ts_params = &testsuite_params;
6726
6727         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6728         uint64_t feat_flags = dev_info.feature_flags;
6729
6730         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6731                 printf("Device doesn't support encrypted digest operations.\n");
6732                 return TEST_SKIPPED;
6733         }
6734
6735         /*
6736          * Function prepare data for hash veryfication test case.
6737          * Digest is allocated in 4 last bytes in plaintext, pattern.
6738          */
6739         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6740
6741         return test_snow3g_decryption(&snow3g_test_case_7) &
6742                         test_snow3g_authentication_verify(&snow3g_hash_data);
6743 }
6744
6745 static int
6746 test_snow3g_cipher_auth_test_case_1(void)
6747 {
6748         return test_snow3g_cipher_auth(&snow3g_test_case_3);
6749 }
6750
6751 static int
6752 test_snow3g_auth_cipher_test_case_1(void)
6753 {
6754         return test_snow3g_auth_cipher(
6755                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6756 }
6757
6758 static int
6759 test_snow3g_auth_cipher_test_case_2(void)
6760 {
6761         return test_snow3g_auth_cipher(
6762                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6763 }
6764
6765 static int
6766 test_snow3g_auth_cipher_test_case_2_oop(void)
6767 {
6768         return test_snow3g_auth_cipher(
6769                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6770 }
6771
6772 static int
6773 test_snow3g_auth_cipher_part_digest_enc(void)
6774 {
6775         return test_snow3g_auth_cipher(
6776                 &snow3g_auth_cipher_partial_digest_encryption,
6777                         IN_PLACE, 0);
6778 }
6779
6780 static int
6781 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6782 {
6783         return test_snow3g_auth_cipher(
6784                 &snow3g_auth_cipher_partial_digest_encryption,
6785                         OUT_OF_PLACE, 0);
6786 }
6787
6788 static int
6789 test_snow3g_auth_cipher_test_case_3_sgl(void)
6790 {
6791         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6792         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6793                 return TEST_SKIPPED;
6794         return test_snow3g_auth_cipher_sgl(
6795                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6796 }
6797
6798 static int
6799 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6800 {
6801         return test_snow3g_auth_cipher_sgl(
6802                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6803 }
6804
6805 static int
6806 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6807 {
6808         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6809         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6810                 return TEST_SKIPPED;
6811         return test_snow3g_auth_cipher_sgl(
6812                 &snow3g_auth_cipher_partial_digest_encryption,
6813                         IN_PLACE, 0);
6814 }
6815
6816 static int
6817 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6818 {
6819         return test_snow3g_auth_cipher_sgl(
6820                 &snow3g_auth_cipher_partial_digest_encryption,
6821                         OUT_OF_PLACE, 0);
6822 }
6823
6824 static int
6825 test_snow3g_auth_cipher_verify_test_case_1(void)
6826 {
6827         return test_snow3g_auth_cipher(
6828                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6829 }
6830
6831 static int
6832 test_snow3g_auth_cipher_verify_test_case_2(void)
6833 {
6834         return test_snow3g_auth_cipher(
6835                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6836 }
6837
6838 static int
6839 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6840 {
6841         return test_snow3g_auth_cipher(
6842                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6843 }
6844
6845 static int
6846 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6847 {
6848         return test_snow3g_auth_cipher(
6849                 &snow3g_auth_cipher_partial_digest_encryption,
6850                         IN_PLACE, 1);
6851 }
6852
6853 static int
6854 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6855 {
6856         return test_snow3g_auth_cipher(
6857                 &snow3g_auth_cipher_partial_digest_encryption,
6858                         OUT_OF_PLACE, 1);
6859 }
6860
6861 static int
6862 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6863 {
6864         return test_snow3g_auth_cipher_sgl(
6865                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6866 }
6867
6868 static int
6869 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6870 {
6871         return test_snow3g_auth_cipher_sgl(
6872                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6873 }
6874
6875 static int
6876 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6877 {
6878         return test_snow3g_auth_cipher_sgl(
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_sgl(void)
6885 {
6886         return test_snow3g_auth_cipher_sgl(
6887                 &snow3g_auth_cipher_partial_digest_encryption,
6888                         OUT_OF_PLACE, 1);
6889 }
6890
6891 static int
6892 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6893 {
6894         return test_snow3g_auth_cipher(
6895                 &snow3g_test_case_7, IN_PLACE, 0);
6896 }
6897
6898 static int
6899 test_kasumi_auth_cipher_test_case_1(void)
6900 {
6901         return test_kasumi_auth_cipher(
6902                 &kasumi_test_case_3, IN_PLACE, 0);
6903 }
6904
6905 static int
6906 test_kasumi_auth_cipher_test_case_2(void)
6907 {
6908         return test_kasumi_auth_cipher(
6909                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6910 }
6911
6912 static int
6913 test_kasumi_auth_cipher_test_case_2_oop(void)
6914 {
6915         return test_kasumi_auth_cipher(
6916                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6917 }
6918
6919 static int
6920 test_kasumi_auth_cipher_test_case_2_sgl(void)
6921 {
6922         return test_kasumi_auth_cipher_sgl(
6923                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6924 }
6925
6926 static int
6927 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6928 {
6929         return test_kasumi_auth_cipher_sgl(
6930                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6931 }
6932
6933 static int
6934 test_kasumi_auth_cipher_verify_test_case_1(void)
6935 {
6936         return test_kasumi_auth_cipher(
6937                 &kasumi_test_case_3, IN_PLACE, 1);
6938 }
6939
6940 static int
6941 test_kasumi_auth_cipher_verify_test_case_2(void)
6942 {
6943         return test_kasumi_auth_cipher(
6944                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6945 }
6946
6947 static int
6948 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6949 {
6950         return test_kasumi_auth_cipher(
6951                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6952 }
6953
6954 static int
6955 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6956 {
6957         return test_kasumi_auth_cipher_sgl(
6958                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6959 }
6960
6961 static int
6962 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6963 {
6964         return test_kasumi_auth_cipher_sgl(
6965                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6966 }
6967
6968 static int
6969 test_kasumi_cipher_auth_test_case_1(void)
6970 {
6971         return test_kasumi_cipher_auth(&kasumi_test_case_6);
6972 }
6973
6974 static int
6975 test_zuc_encryption_test_case_1(void)
6976 {
6977         return test_zuc_encryption(&zuc_test_case_cipher_193b);
6978 }
6979
6980 static int
6981 test_zuc_encryption_test_case_2(void)
6982 {
6983         return test_zuc_encryption(&zuc_test_case_cipher_800b);
6984 }
6985
6986 static int
6987 test_zuc_encryption_test_case_3(void)
6988 {
6989         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
6990 }
6991
6992 static int
6993 test_zuc_encryption_test_case_4(void)
6994 {
6995         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
6996 }
6997
6998 static int
6999 test_zuc_encryption_test_case_5(void)
7000 {
7001         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7002 }
7003
7004 static int
7005 test_zuc_encryption_test_case_6_sgl(void)
7006 {
7007         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7008 }
7009
7010 static int
7011 test_zuc_hash_generate_test_case_1(void)
7012 {
7013         return test_zuc_authentication(&zuc_test_case_auth_1b);
7014 }
7015
7016 static int
7017 test_zuc_hash_generate_test_case_2(void)
7018 {
7019         return test_zuc_authentication(&zuc_test_case_auth_90b);
7020 }
7021
7022 static int
7023 test_zuc_hash_generate_test_case_3(void)
7024 {
7025         return test_zuc_authentication(&zuc_test_case_auth_577b);
7026 }
7027
7028 static int
7029 test_zuc_hash_generate_test_case_4(void)
7030 {
7031         return test_zuc_authentication(&zuc_test_case_auth_2079b);
7032 }
7033
7034 static int
7035 test_zuc_hash_generate_test_case_5(void)
7036 {
7037         return test_zuc_authentication(&zuc_test_auth_5670b);
7038 }
7039
7040 static int
7041 test_zuc_hash_generate_test_case_6(void)
7042 {
7043         return test_zuc_authentication(&zuc_test_case_auth_128b);
7044 }
7045
7046 static int
7047 test_zuc_hash_generate_test_case_7(void)
7048 {
7049         return test_zuc_authentication(&zuc_test_case_auth_2080b);
7050 }
7051
7052 static int
7053 test_zuc_hash_generate_test_case_8(void)
7054 {
7055         return test_zuc_authentication(&zuc_test_case_auth_584b);
7056 }
7057
7058 static int
7059 test_zuc_cipher_auth_test_case_1(void)
7060 {
7061         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7062 }
7063
7064 static int
7065 test_zuc_cipher_auth_test_case_2(void)
7066 {
7067         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7068 }
7069
7070 static int
7071 test_zuc_auth_cipher_test_case_1(void)
7072 {
7073         return test_zuc_auth_cipher(
7074                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7075 }
7076
7077 static int
7078 test_zuc_auth_cipher_test_case_1_oop(void)
7079 {
7080         return test_zuc_auth_cipher(
7081                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7082 }
7083
7084 static int
7085 test_zuc_auth_cipher_test_case_1_sgl(void)
7086 {
7087         return test_zuc_auth_cipher_sgl(
7088                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7089 }
7090
7091 static int
7092 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7093 {
7094         return test_zuc_auth_cipher_sgl(
7095                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7096 }
7097
7098 static int
7099 test_zuc_auth_cipher_verify_test_case_1(void)
7100 {
7101         return test_zuc_auth_cipher(
7102                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7103 }
7104
7105 static int
7106 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7107 {
7108         return test_zuc_auth_cipher(
7109                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7110 }
7111
7112 static int
7113 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7114 {
7115         return test_zuc_auth_cipher_sgl(
7116                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7117 }
7118
7119 static int
7120 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7121 {
7122         return test_zuc_auth_cipher_sgl(
7123                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7124 }
7125
7126 static int
7127 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7128 {
7129         uint8_t dev_id = testsuite_params.valid_devs[0];
7130
7131         struct rte_cryptodev_sym_capability_idx cap_idx;
7132
7133         /* Check if device supports particular cipher algorithm */
7134         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7135         cap_idx.algo.cipher = tdata->cipher_algo;
7136         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7137                 return TEST_SKIPPED;
7138
7139         /* Check if device supports particular hash algorithm */
7140         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7141         cap_idx.algo.auth = tdata->auth_algo;
7142         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7143                 return TEST_SKIPPED;
7144
7145         return 0;
7146 }
7147
7148 static int
7149 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7150         uint8_t op_mode, uint8_t verify)
7151 {
7152         struct crypto_testsuite_params *ts_params = &testsuite_params;
7153         struct crypto_unittest_params *ut_params = &unittest_params;
7154
7155         int retval;
7156
7157         uint8_t *plaintext = NULL, *ciphertext = NULL;
7158         unsigned int plaintext_pad_len;
7159         unsigned int plaintext_len;
7160         unsigned int ciphertext_pad_len;
7161         unsigned int ciphertext_len;
7162
7163         struct rte_cryptodev_info dev_info;
7164         struct rte_crypto_op *op;
7165
7166         /* Check if device supports particular algorithms separately */
7167         if (test_mixed_check_if_unsupported(tdata))
7168                 return TEST_SKIPPED;
7169         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7170                 return TEST_SKIPPED;
7171
7172         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7173
7174         uint64_t feat_flags = dev_info.feature_flags;
7175
7176         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7177                 printf("Device doesn't support digest encrypted.\n");
7178                 return TEST_SKIPPED;
7179         }
7180
7181         /* Create the session */
7182         if (verify)
7183                 retval = create_wireless_algo_cipher_auth_session(
7184                                 ts_params->valid_devs[0],
7185                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7186                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7187                                 tdata->auth_algo,
7188                                 tdata->cipher_algo,
7189                                 tdata->auth_key.data, tdata->auth_key.len,
7190                                 tdata->auth_iv.len, tdata->digest_enc.len,
7191                                 tdata->cipher_iv.len);
7192         else
7193                 retval = create_wireless_algo_auth_cipher_session(
7194                                 ts_params->valid_devs[0],
7195                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7196                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7197                                 tdata->auth_algo,
7198                                 tdata->cipher_algo,
7199                                 tdata->auth_key.data, tdata->auth_key.len,
7200                                 tdata->auth_iv.len, tdata->digest_enc.len,
7201                                 tdata->cipher_iv.len);
7202         if (retval != 0)
7203                 return retval;
7204
7205         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7206         if (op_mode == OUT_OF_PLACE)
7207                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7208
7209         /* clear mbuf payload */
7210         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7211                 rte_pktmbuf_tailroom(ut_params->ibuf));
7212         if (op_mode == OUT_OF_PLACE) {
7213
7214                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7215                                 rte_pktmbuf_tailroom(ut_params->obuf));
7216         }
7217
7218         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7219         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7220         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7221         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7222
7223         if (verify) {
7224                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7225                                 ciphertext_pad_len);
7226                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7227                 if (op_mode == OUT_OF_PLACE)
7228                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7229                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7230                                 ciphertext_len);
7231         } else {
7232                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7233                                 plaintext_pad_len);
7234                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7235                 if (op_mode == OUT_OF_PLACE)
7236                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7237                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7238         }
7239
7240         /* Create the operation */
7241         retval = create_wireless_algo_auth_cipher_operation(
7242                         tdata->digest_enc.data, tdata->digest_enc.len,
7243                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7244                         tdata->auth_iv.data, tdata->auth_iv.len,
7245                         (tdata->digest_enc.offset == 0 ?
7246                                 plaintext_pad_len
7247                                 : tdata->digest_enc.offset),
7248                         tdata->validCipherLen.len_bits,
7249                         tdata->cipher.offset_bits,
7250                         tdata->validAuthLen.len_bits,
7251                         tdata->auth.offset_bits,
7252                         op_mode, 0, verify);
7253
7254         if (retval < 0)
7255                 return retval;
7256
7257         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7258
7259         /* Check if the op failed because the device doesn't */
7260         /* support this particular combination of algorithms */
7261         if (op == NULL && ut_params->op->status ==
7262                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7263                 printf("Device doesn't support this mixed combination. "
7264                                 "Test Skipped.\n");
7265                 return TEST_SKIPPED;
7266         }
7267         ut_params->op = op;
7268
7269         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7270
7271         ut_params->obuf = (op_mode == IN_PLACE ?
7272                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7273
7274         if (verify) {
7275                 if (ut_params->obuf)
7276                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7277                                                         uint8_t *);
7278                 else
7279                         plaintext = ciphertext +
7280                                         (tdata->cipher.offset_bits >> 3);
7281
7282                 debug_hexdump(stdout, "plaintext:", plaintext,
7283                                 tdata->plaintext.len_bits >> 3);
7284                 debug_hexdump(stdout, "plaintext expected:",
7285                                 tdata->plaintext.data,
7286                                 tdata->plaintext.len_bits >> 3);
7287         } else {
7288                 if (ut_params->obuf)
7289                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7290                                         uint8_t *);
7291                 else
7292                         ciphertext = plaintext;
7293
7294                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7295                                 ciphertext_len);
7296                 debug_hexdump(stdout, "ciphertext expected:",
7297                                 tdata->ciphertext.data,
7298                                 tdata->ciphertext.len_bits >> 3);
7299
7300                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7301                                 + (tdata->digest_enc.offset == 0 ?
7302                 plaintext_pad_len : tdata->digest_enc.offset);
7303
7304                 debug_hexdump(stdout, "digest:", ut_params->digest,
7305                                 tdata->digest_enc.len);
7306                 debug_hexdump(stdout, "digest expected:",
7307                                 tdata->digest_enc.data,
7308                                 tdata->digest_enc.len);
7309         }
7310
7311         /* Validate obuf */
7312         if (verify) {
7313                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7314                                 plaintext,
7315                                 tdata->plaintext.data,
7316                                 tdata->plaintext.len_bits >> 3,
7317                                 "Plaintext data not as expected");
7318         } else {
7319                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7320                                 ciphertext,
7321                                 tdata->ciphertext.data,
7322                                 tdata->validDataLen.len_bits,
7323                                 "Ciphertext data not as expected");
7324
7325                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7326                                 ut_params->digest,
7327                                 tdata->digest_enc.data,
7328                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7329                                 "Generated auth tag not as expected");
7330         }
7331
7332         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7333                         "crypto op processing failed");
7334
7335         return 0;
7336 }
7337
7338 static int
7339 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7340         uint8_t op_mode, uint8_t verify)
7341 {
7342         struct crypto_testsuite_params *ts_params = &testsuite_params;
7343         struct crypto_unittest_params *ut_params = &unittest_params;
7344
7345         int retval;
7346
7347         const uint8_t *plaintext = NULL;
7348         const uint8_t *ciphertext = NULL;
7349         const uint8_t *digest = NULL;
7350         unsigned int plaintext_pad_len;
7351         unsigned int plaintext_len;
7352         unsigned int ciphertext_pad_len;
7353         unsigned int ciphertext_len;
7354         uint8_t buffer[10000];
7355         uint8_t digest_buffer[10000];
7356
7357         struct rte_cryptodev_info dev_info;
7358         struct rte_crypto_op *op;
7359
7360         /* Check if device supports particular algorithms */
7361         if (test_mixed_check_if_unsupported(tdata))
7362                 return TEST_SKIPPED;
7363         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7364                 return TEST_SKIPPED;
7365
7366         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7367
7368         uint64_t feat_flags = dev_info.feature_flags;
7369
7370         if (op_mode == IN_PLACE) {
7371                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7372                         printf("Device doesn't support in-place scatter-gather "
7373                                         "in both input and output mbufs.\n");
7374                         return TEST_SKIPPED;
7375                 }
7376         } else {
7377                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7378                         printf("Device doesn't support out-of-place scatter-gather "
7379                                         "in both input and output mbufs.\n");
7380                         return TEST_SKIPPED;
7381                 }
7382                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7383                         printf("Device doesn't support digest encrypted.\n");
7384                         return TEST_SKIPPED;
7385                 }
7386         }
7387
7388         /* Create the session */
7389         if (verify)
7390                 retval = create_wireless_algo_cipher_auth_session(
7391                                 ts_params->valid_devs[0],
7392                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7393                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7394                                 tdata->auth_algo,
7395                                 tdata->cipher_algo,
7396                                 tdata->auth_key.data, tdata->auth_key.len,
7397                                 tdata->auth_iv.len, tdata->digest_enc.len,
7398                                 tdata->cipher_iv.len);
7399         else
7400                 retval = create_wireless_algo_auth_cipher_session(
7401                                 ts_params->valid_devs[0],
7402                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7403                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7404                                 tdata->auth_algo,
7405                                 tdata->cipher_algo,
7406                                 tdata->auth_key.data, tdata->auth_key.len,
7407                                 tdata->auth_iv.len, tdata->digest_enc.len,
7408                                 tdata->cipher_iv.len);
7409         if (retval != 0)
7410                 return retval;
7411
7412         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7413         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7414         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7415         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7416
7417         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7418                         ciphertext_pad_len, 15, 0);
7419         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7420                         "Failed to allocate input buffer in mempool");
7421
7422         if (op_mode == OUT_OF_PLACE) {
7423                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7424                                 plaintext_pad_len, 15, 0);
7425                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
7426                                 "Failed to allocate output buffer in mempool");
7427         }
7428
7429         if (verify) {
7430                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7431                         tdata->ciphertext.data);
7432                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7433                                         ciphertext_len, buffer);
7434                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7435                         ciphertext_len);
7436         } else {
7437                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7438                         tdata->plaintext.data);
7439                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7440                                         plaintext_len, buffer);
7441                 debug_hexdump(stdout, "plaintext:", plaintext,
7442                         plaintext_len);
7443         }
7444         memset(buffer, 0, sizeof(buffer));
7445
7446         /* Create the operation */
7447         retval = create_wireless_algo_auth_cipher_operation(
7448                         tdata->digest_enc.data, tdata->digest_enc.len,
7449                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7450                         tdata->auth_iv.data, tdata->auth_iv.len,
7451                         (tdata->digest_enc.offset == 0 ?
7452                                 plaintext_pad_len
7453                                 : tdata->digest_enc.offset),
7454                         tdata->validCipherLen.len_bits,
7455                         tdata->cipher.offset_bits,
7456                         tdata->validAuthLen.len_bits,
7457                         tdata->auth.offset_bits,
7458                         op_mode, 1, verify);
7459
7460         if (retval < 0)
7461                 return retval;
7462
7463         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7464
7465         /* Check if the op failed because the device doesn't */
7466         /* support this particular combination of algorithms */
7467         if (op == NULL && ut_params->op->status ==
7468                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7469                 printf("Device doesn't support this mixed combination. "
7470                                 "Test Skipped.\n");
7471                 return TEST_SKIPPED;
7472         }
7473         ut_params->op = op;
7474
7475         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7476
7477         ut_params->obuf = (op_mode == IN_PLACE ?
7478                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7479
7480         if (verify) {
7481                 if (ut_params->obuf)
7482                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7483                                         plaintext_len, buffer);
7484                 else
7485                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7486                                         plaintext_len, buffer);
7487
7488                 debug_hexdump(stdout, "plaintext:", plaintext,
7489                                 (tdata->plaintext.len_bits >> 3) -
7490                                 tdata->digest_enc.len);
7491                 debug_hexdump(stdout, "plaintext expected:",
7492                                 tdata->plaintext.data,
7493                                 (tdata->plaintext.len_bits >> 3) -
7494                                 tdata->digest_enc.len);
7495         } else {
7496                 if (ut_params->obuf)
7497                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7498                                         ciphertext_len, buffer);
7499                 else
7500                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7501                                         ciphertext_len, buffer);
7502
7503                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7504                         ciphertext_len);
7505                 debug_hexdump(stdout, "ciphertext expected:",
7506                         tdata->ciphertext.data,
7507                         tdata->ciphertext.len_bits >> 3);
7508
7509                 if (ut_params->obuf)
7510                         digest = rte_pktmbuf_read(ut_params->obuf,
7511                                         (tdata->digest_enc.offset == 0 ?
7512                                                 plaintext_pad_len :
7513                                                 tdata->digest_enc.offset),
7514                                         tdata->digest_enc.len, digest_buffer);
7515                 else
7516                         digest = rte_pktmbuf_read(ut_params->ibuf,
7517                                         (tdata->digest_enc.offset == 0 ?
7518                                                 plaintext_pad_len :
7519                                                 tdata->digest_enc.offset),
7520                                         tdata->digest_enc.len, digest_buffer);
7521
7522                 debug_hexdump(stdout, "digest:", digest,
7523                                 tdata->digest_enc.len);
7524                 debug_hexdump(stdout, "digest expected:",
7525                                 tdata->digest_enc.data, tdata->digest_enc.len);
7526         }
7527
7528         /* Validate obuf */
7529         if (verify) {
7530                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7531                                 plaintext,
7532                                 tdata->plaintext.data,
7533                                 tdata->plaintext.len_bits >> 3,
7534                                 "Plaintext data not as expected");
7535         } else {
7536                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7537                                 ciphertext,
7538                                 tdata->ciphertext.data,
7539                                 tdata->validDataLen.len_bits,
7540                                 "Ciphertext data not as expected");
7541                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7542                                 digest,
7543                                 tdata->digest_enc.data,
7544                                 tdata->digest_enc.len,
7545                                 "Generated auth tag not as expected");
7546         }
7547
7548         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7549                         "crypto op processing failed");
7550
7551         return 0;
7552 }
7553
7554 /** AUTH AES CMAC + CIPHER AES CTR */
7555
7556 static int
7557 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7558 {
7559         return test_mixed_auth_cipher(
7560                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7561 }
7562
7563 static int
7564 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7565 {
7566         return test_mixed_auth_cipher(
7567                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7568 }
7569
7570 static int
7571 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7572 {
7573         return test_mixed_auth_cipher_sgl(
7574                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7575 }
7576
7577 static int
7578 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7579 {
7580         return test_mixed_auth_cipher_sgl(
7581                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7582 }
7583
7584 static int
7585 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7586 {
7587         return test_mixed_auth_cipher(
7588                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7589 }
7590
7591 static int
7592 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7593 {
7594         return test_mixed_auth_cipher(
7595                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7596 }
7597
7598 static int
7599 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7600 {
7601         return test_mixed_auth_cipher_sgl(
7602                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7603 }
7604
7605 static int
7606 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7607 {
7608         return test_mixed_auth_cipher_sgl(
7609                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7610 }
7611
7612 /** MIXED AUTH + CIPHER */
7613
7614 static int
7615 test_auth_zuc_cipher_snow_test_case_1(void)
7616 {
7617         return test_mixed_auth_cipher(
7618                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7619 }
7620
7621 static int
7622 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7623 {
7624         return test_mixed_auth_cipher(
7625                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7626 }
7627
7628 static int
7629 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7630 {
7631         return test_mixed_auth_cipher(
7632                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7633 }
7634
7635 static int
7636 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7637 {
7638         return test_mixed_auth_cipher(
7639                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7640 }
7641
7642 static int
7643 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7644 {
7645         return test_mixed_auth_cipher(
7646                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7647 }
7648
7649 static int
7650 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7651 {
7652         return test_mixed_auth_cipher(
7653                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7654 }
7655
7656 static int
7657 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7658 {
7659         return test_mixed_auth_cipher(
7660                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7661 }
7662
7663 static int
7664 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7665 {
7666         return test_mixed_auth_cipher(
7667                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7668 }
7669
7670 static int
7671 test_auth_snow_cipher_zuc_test_case_1(void)
7672 {
7673         return test_mixed_auth_cipher(
7674                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7675 }
7676
7677 static int
7678 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7679 {
7680         return test_mixed_auth_cipher(
7681                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7682 }
7683
7684 static int
7685 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7686 {
7687         return test_mixed_auth_cipher(
7688                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7689 }
7690
7691 static int
7692 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7693 {
7694         return test_mixed_auth_cipher(
7695                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7696 }
7697
7698 static int
7699 test_auth_null_cipher_snow_test_case_1(void)
7700 {
7701         return test_mixed_auth_cipher(
7702                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7703 }
7704
7705 static int
7706 test_verify_auth_null_cipher_snow_test_case_1(void)
7707 {
7708         return test_mixed_auth_cipher(
7709                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7710 }
7711
7712 static int
7713 test_auth_null_cipher_zuc_test_case_1(void)
7714 {
7715         return test_mixed_auth_cipher(
7716                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7717 }
7718
7719 static int
7720 test_verify_auth_null_cipher_zuc_test_case_1(void)
7721 {
7722         return test_mixed_auth_cipher(
7723                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7724 }
7725
7726 static int
7727 test_auth_snow_cipher_null_test_case_1(void)
7728 {
7729         return test_mixed_auth_cipher(
7730                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7731 }
7732
7733 static int
7734 test_verify_auth_snow_cipher_null_test_case_1(void)
7735 {
7736         return test_mixed_auth_cipher(
7737                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7738 }
7739
7740 static int
7741 test_auth_zuc_cipher_null_test_case_1(void)
7742 {
7743         return test_mixed_auth_cipher(
7744                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7745 }
7746
7747 static int
7748 test_verify_auth_zuc_cipher_null_test_case_1(void)
7749 {
7750         return test_mixed_auth_cipher(
7751                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7752 }
7753
7754 static int
7755 test_auth_null_cipher_aes_ctr_test_case_1(void)
7756 {
7757         return test_mixed_auth_cipher(
7758                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7759 }
7760
7761 static int
7762 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7763 {
7764         return test_mixed_auth_cipher(
7765                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7766 }
7767
7768 static int
7769 test_auth_aes_cmac_cipher_null_test_case_1(void)
7770 {
7771         return test_mixed_auth_cipher(
7772                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7773 }
7774
7775 static int
7776 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7777 {
7778         return test_mixed_auth_cipher(
7779                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7780 }
7781
7782 /* ***** AEAD algorithm Tests ***** */
7783
7784 static int
7785 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7786                 enum rte_crypto_aead_operation op,
7787                 const uint8_t *key, const uint8_t key_len,
7788                 const uint16_t aad_len, const uint8_t auth_len,
7789                 uint8_t iv_len)
7790 {
7791         uint8_t aead_key[key_len];
7792
7793         struct crypto_testsuite_params *ts_params = &testsuite_params;
7794         struct crypto_unittest_params *ut_params = &unittest_params;
7795
7796         memcpy(aead_key, key, key_len);
7797
7798         /* Setup AEAD Parameters */
7799         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7800         ut_params->aead_xform.next = NULL;
7801         ut_params->aead_xform.aead.algo = algo;
7802         ut_params->aead_xform.aead.op = op;
7803         ut_params->aead_xform.aead.key.data = aead_key;
7804         ut_params->aead_xform.aead.key.length = key_len;
7805         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7806         ut_params->aead_xform.aead.iv.length = iv_len;
7807         ut_params->aead_xform.aead.digest_length = auth_len;
7808         ut_params->aead_xform.aead.aad_length = aad_len;
7809
7810         debug_hexdump(stdout, "key:", key, key_len);
7811
7812         /* Create Crypto session*/
7813         ut_params->sess = rte_cryptodev_sym_session_create(
7814                         ts_params->session_mpool);
7815
7816         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7817                         &ut_params->aead_xform,
7818                         ts_params->session_priv_mpool);
7819
7820         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7821
7822         return 0;
7823 }
7824
7825 static int
7826 create_aead_xform(struct rte_crypto_op *op,
7827                 enum rte_crypto_aead_algorithm algo,
7828                 enum rte_crypto_aead_operation aead_op,
7829                 uint8_t *key, const uint8_t key_len,
7830                 const uint8_t aad_len, const uint8_t auth_len,
7831                 uint8_t iv_len)
7832 {
7833         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7834                         "failed to allocate space for crypto transform");
7835
7836         struct rte_crypto_sym_op *sym_op = op->sym;
7837
7838         /* Setup AEAD Parameters */
7839         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7840         sym_op->xform->next = NULL;
7841         sym_op->xform->aead.algo = algo;
7842         sym_op->xform->aead.op = aead_op;
7843         sym_op->xform->aead.key.data = key;
7844         sym_op->xform->aead.key.length = key_len;
7845         sym_op->xform->aead.iv.offset = IV_OFFSET;
7846         sym_op->xform->aead.iv.length = iv_len;
7847         sym_op->xform->aead.digest_length = auth_len;
7848         sym_op->xform->aead.aad_length = aad_len;
7849
7850         debug_hexdump(stdout, "key:", key, key_len);
7851
7852         return 0;
7853 }
7854
7855 static int
7856 create_aead_operation(enum rte_crypto_aead_operation op,
7857                 const struct aead_test_data *tdata)
7858 {
7859         struct crypto_testsuite_params *ts_params = &testsuite_params;
7860         struct crypto_unittest_params *ut_params = &unittest_params;
7861
7862         uint8_t *plaintext, *ciphertext;
7863         unsigned int aad_pad_len, plaintext_pad_len;
7864
7865         /* Generate Crypto op data structure */
7866         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7867                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7868         TEST_ASSERT_NOT_NULL(ut_params->op,
7869                         "Failed to allocate symmetric crypto operation struct");
7870
7871         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7872
7873         /* Append aad data */
7874         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7875                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7876                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7877                                 aad_pad_len);
7878                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7879                                 "no room to append aad");
7880
7881                 sym_op->aead.aad.phys_addr =
7882                                 rte_pktmbuf_iova(ut_params->ibuf);
7883                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
7884                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7885                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7886                         tdata->aad.len);
7887
7888                 /* Append IV at the end of the crypto operation*/
7889                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7890                                 uint8_t *, IV_OFFSET);
7891
7892                 /* Copy IV 1 byte after the IV pointer, according to the API */
7893                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7894                 debug_hexdump(stdout, "iv:", iv_ptr,
7895                         tdata->iv.len);
7896         } else {
7897                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7898                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7899                                 aad_pad_len);
7900                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7901                                 "no room to append aad");
7902
7903                 sym_op->aead.aad.phys_addr =
7904                                 rte_pktmbuf_iova(ut_params->ibuf);
7905                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7906                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7907                         tdata->aad.len);
7908
7909                 /* Append IV at the end of the crypto operation*/
7910                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7911                                 uint8_t *, IV_OFFSET);
7912
7913                 if (tdata->iv.len == 0) {
7914                         rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7915                         debug_hexdump(stdout, "iv:", iv_ptr,
7916                                 AES_GCM_J0_LENGTH);
7917                 } else {
7918                         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7919                         debug_hexdump(stdout, "iv:", iv_ptr,
7920                                 tdata->iv.len);
7921                 }
7922         }
7923
7924         /* Append plaintext/ciphertext */
7925         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7926                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7927                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7928                                 plaintext_pad_len);
7929                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7930
7931                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7932                 debug_hexdump(stdout, "plaintext:", plaintext,
7933                                 tdata->plaintext.len);
7934
7935                 if (ut_params->obuf) {
7936                         ciphertext = (uint8_t *)rte_pktmbuf_append(
7937                                         ut_params->obuf,
7938                                         plaintext_pad_len + aad_pad_len);
7939                         TEST_ASSERT_NOT_NULL(ciphertext,
7940                                         "no room to append ciphertext");
7941
7942                         memset(ciphertext + aad_pad_len, 0,
7943                                         tdata->ciphertext.len);
7944                 }
7945         } else {
7946                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7947                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7948                                 plaintext_pad_len);
7949                 TEST_ASSERT_NOT_NULL(ciphertext,
7950                                 "no room to append ciphertext");
7951
7952                 memcpy(ciphertext, tdata->ciphertext.data,
7953                                 tdata->ciphertext.len);
7954                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7955                                 tdata->ciphertext.len);
7956
7957                 if (ut_params->obuf) {
7958                         plaintext = (uint8_t *)rte_pktmbuf_append(
7959                                         ut_params->obuf,
7960                                         plaintext_pad_len + aad_pad_len);
7961                         TEST_ASSERT_NOT_NULL(plaintext,
7962                                         "no room to append plaintext");
7963
7964                         memset(plaintext + aad_pad_len, 0,
7965                                         tdata->plaintext.len);
7966                 }
7967         }
7968
7969         /* Append digest data */
7970         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7971                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7972                                 ut_params->obuf ? ut_params->obuf :
7973                                                 ut_params->ibuf,
7974                                                 tdata->auth_tag.len);
7975                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7976                                 "no room to append digest");
7977                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
7978                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7979                                 ut_params->obuf ? ut_params->obuf :
7980                                                 ut_params->ibuf,
7981                                                 plaintext_pad_len +
7982                                                 aad_pad_len);
7983         } else {
7984                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7985                                 ut_params->ibuf, tdata->auth_tag.len);
7986                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7987                                 "no room to append digest");
7988                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7989                                 ut_params->ibuf,
7990                                 plaintext_pad_len + aad_pad_len);
7991
7992                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
7993                         tdata->auth_tag.len);
7994                 debug_hexdump(stdout, "digest:",
7995                         sym_op->aead.digest.data,
7996                         tdata->auth_tag.len);
7997         }
7998
7999         sym_op->aead.data.length = tdata->plaintext.len;
8000         sym_op->aead.data.offset = aad_pad_len;
8001
8002         return 0;
8003 }
8004
8005 static int
8006 test_authenticated_encryption(const struct aead_test_data *tdata)
8007 {
8008         struct crypto_testsuite_params *ts_params = &testsuite_params;
8009         struct crypto_unittest_params *ut_params = &unittest_params;
8010
8011         int retval;
8012         uint8_t *ciphertext, *auth_tag;
8013         uint16_t plaintext_pad_len;
8014         uint32_t i;
8015         struct rte_cryptodev_info dev_info;
8016
8017         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8018         uint64_t feat_flags = dev_info.feature_flags;
8019
8020         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8021                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8022                 printf("Device doesn't support RAW data-path APIs.\n");
8023                 return TEST_SKIPPED;
8024         }
8025
8026         /* Verify the capabilities */
8027         struct rte_cryptodev_sym_capability_idx cap_idx;
8028         const struct rte_cryptodev_symmetric_capability *capability;
8029         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8030         cap_idx.algo.aead = tdata->algo;
8031         capability = rte_cryptodev_sym_capability_get(
8032                         ts_params->valid_devs[0], &cap_idx);
8033         if (capability == NULL)
8034                 return TEST_SKIPPED;
8035         if (rte_cryptodev_sym_capability_check_aead(
8036                         capability, tdata->key.len, tdata->auth_tag.len,
8037                         tdata->aad.len, tdata->iv.len))
8038                 return TEST_SKIPPED;
8039
8040         /* Create AEAD session */
8041         retval = create_aead_session(ts_params->valid_devs[0],
8042                         tdata->algo,
8043                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8044                         tdata->key.data, tdata->key.len,
8045                         tdata->aad.len, tdata->auth_tag.len,
8046                         tdata->iv.len);
8047         if (retval < 0)
8048                 return retval;
8049
8050         if (tdata->aad.len > MBUF_SIZE) {
8051                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8052                 /* Populate full size of add data */
8053                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8054                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8055         } else
8056                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8057
8058         /* clear mbuf payload */
8059         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8060                         rte_pktmbuf_tailroom(ut_params->ibuf));
8061
8062         /* Create AEAD operation */
8063         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8064         if (retval < 0)
8065                 return retval;
8066
8067         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8068
8069         ut_params->op->sym->m_src = ut_params->ibuf;
8070
8071         /* Process crypto operation */
8072         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8073                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8074         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8075                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8076                                 ut_params->op, 0, 0, 0, 0);
8077         else
8078                 TEST_ASSERT_NOT_NULL(
8079                         process_crypto_request(ts_params->valid_devs[0],
8080                         ut_params->op), "failed to process sym crypto op");
8081
8082         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8083                         "crypto op processing failed");
8084
8085         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8086
8087         if (ut_params->op->sym->m_dst) {
8088                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8089                                 uint8_t *);
8090                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8091                                 uint8_t *, plaintext_pad_len);
8092         } else {
8093                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8094                                 uint8_t *,
8095                                 ut_params->op->sym->cipher.data.offset);
8096                 auth_tag = ciphertext + plaintext_pad_len;
8097         }
8098
8099         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8100         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8101
8102         /* Validate obuf */
8103         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8104                         ciphertext,
8105                         tdata->ciphertext.data,
8106                         tdata->ciphertext.len,
8107                         "Ciphertext data not as expected");
8108
8109         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8110                         auth_tag,
8111                         tdata->auth_tag.data,
8112                         tdata->auth_tag.len,
8113                         "Generated auth tag not as expected");
8114
8115         return 0;
8116
8117 }
8118
8119 #ifdef RTE_LIB_SECURITY
8120 static int
8121 security_proto_supported(enum rte_security_session_action_type action,
8122         enum rte_security_session_protocol proto)
8123 {
8124         struct crypto_testsuite_params *ts_params = &testsuite_params;
8125
8126         const struct rte_security_capability *capabilities;
8127         const struct rte_security_capability *capability;
8128         uint16_t i = 0;
8129
8130         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8131                                 rte_cryptodev_get_sec_ctx(
8132                                 ts_params->valid_devs[0]);
8133
8134
8135         capabilities = rte_security_capabilities_get(ctx);
8136
8137         if (capabilities == NULL)
8138                 return -ENOTSUP;
8139
8140         while ((capability = &capabilities[i++])->action !=
8141                         RTE_SECURITY_ACTION_TYPE_NONE) {
8142                 if (capability->action == action &&
8143                                 capability->protocol == proto)
8144                         return 0;
8145         }
8146
8147         return -ENOTSUP;
8148 }
8149
8150 /* Basic algorithm run function for async inplace mode.
8151  * Creates a session from input parameters and runs one operation
8152  * on input_vec. Checks the output of the crypto operation against
8153  * output_vec.
8154  */
8155 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8156                            enum rte_crypto_auth_operation opa,
8157                            const uint8_t *input_vec, unsigned int input_vec_len,
8158                            const uint8_t *output_vec,
8159                            unsigned int output_vec_len,
8160                            enum rte_crypto_cipher_algorithm cipher_alg,
8161                            const uint8_t *cipher_key, uint32_t cipher_key_len,
8162                            enum rte_crypto_auth_algorithm auth_alg,
8163                            const uint8_t *auth_key, uint32_t auth_key_len,
8164                            uint8_t bearer, enum rte_security_pdcp_domain domain,
8165                            uint8_t packet_direction, uint8_t sn_size,
8166                            uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8167 {
8168         struct crypto_testsuite_params *ts_params = &testsuite_params;
8169         struct crypto_unittest_params *ut_params = &unittest_params;
8170         uint8_t *plaintext;
8171         int ret = TEST_SUCCESS;
8172         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8173                                 rte_cryptodev_get_sec_ctx(
8174                                 ts_params->valid_devs[0]);
8175
8176         /* Verify the capabilities */
8177         struct rte_security_capability_idx sec_cap_idx;
8178
8179         sec_cap_idx.action = ut_params->type;
8180         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8181         sec_cap_idx.pdcp.domain = domain;
8182         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8183                 return TEST_SKIPPED;
8184
8185         /* Generate test mbuf data */
8186         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8187
8188         /* clear mbuf payload */
8189         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8190                         rte_pktmbuf_tailroom(ut_params->ibuf));
8191
8192         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8193                                                   input_vec_len);
8194         memcpy(plaintext, input_vec, input_vec_len);
8195
8196         /* Out of place support */
8197         if (oop) {
8198                 /*
8199                  * For out-op-place we need to alloc another mbuf
8200                  */
8201                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8202                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8203         }
8204
8205         /* Setup Cipher Parameters */
8206         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8207         ut_params->cipher_xform.cipher.algo = cipher_alg;
8208         ut_params->cipher_xform.cipher.op = opc;
8209         ut_params->cipher_xform.cipher.key.data = cipher_key;
8210         ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8211         ut_params->cipher_xform.cipher.iv.length =
8212                                 packet_direction ? 4 : 0;
8213         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8214
8215         /* Setup HMAC Parameters if ICV header is required */
8216         if (auth_alg != 0) {
8217                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8218                 ut_params->auth_xform.next = NULL;
8219                 ut_params->auth_xform.auth.algo = auth_alg;
8220                 ut_params->auth_xform.auth.op = opa;
8221                 ut_params->auth_xform.auth.key.data = auth_key;
8222                 ut_params->auth_xform.auth.key.length = auth_key_len;
8223
8224                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8225         } else {
8226                 ut_params->cipher_xform.next = NULL;
8227         }
8228
8229         struct rte_security_session_conf sess_conf = {
8230                 .action_type = ut_params->type,
8231                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8232                 {.pdcp = {
8233                         .bearer = bearer,
8234                         .domain = domain,
8235                         .pkt_dir = packet_direction,
8236                         .sn_size = sn_size,
8237                         .hfn = packet_direction ? 0 : hfn,
8238                         /**
8239                          * hfn can be set as pdcp_test_hfn[i]
8240                          * if hfn_ovrd is not set. Here, PDCP
8241                          * packet direction is just used to
8242                          * run half of the cases with session
8243                          * HFN and other half with per packet
8244                          * HFN.
8245                          */
8246                         .hfn_threshold = hfn_threshold,
8247                         .hfn_ovrd = packet_direction ? 1 : 0,
8248                         .sdap_enabled = sdap,
8249                 } },
8250                 .crypto_xform = &ut_params->cipher_xform
8251         };
8252
8253         /* Create security session */
8254         ut_params->sec_session = rte_security_session_create(ctx,
8255                                 &sess_conf, ts_params->session_mpool,
8256                                 ts_params->session_priv_mpool);
8257
8258         if (!ut_params->sec_session) {
8259                 printf("TestCase %s()-%d line %d failed %s: ",
8260                         __func__, i, __LINE__, "Failed to allocate session");
8261                 ret = TEST_FAILED;
8262                 goto on_err;
8263         }
8264
8265         /* Generate crypto op data structure */
8266         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8267                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8268         if (!ut_params->op) {
8269                 printf("TestCase %s()-%d line %d failed %s: ",
8270                         __func__, i, __LINE__,
8271                         "Failed to allocate symmetric crypto operation struct");
8272                 ret = TEST_FAILED;
8273                 goto on_err;
8274         }
8275
8276         uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8277                                         uint32_t *, IV_OFFSET);
8278         *per_pkt_hfn = packet_direction ? hfn : 0;
8279
8280         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8281
8282         /* set crypto operation source mbuf */
8283         ut_params->op->sym->m_src = ut_params->ibuf;
8284         if (oop)
8285                 ut_params->op->sym->m_dst = ut_params->obuf;
8286
8287         /* Process crypto operation */
8288         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8289                 == NULL) {
8290                 printf("TestCase %s()-%d line %d failed %s: ",
8291                         __func__, i, __LINE__,
8292                         "failed to process sym crypto op");
8293                 ret = TEST_FAILED;
8294                 goto on_err;
8295         }
8296
8297         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8298                 printf("TestCase %s()-%d line %d failed %s: ",
8299                         __func__, i, __LINE__, "crypto op processing failed");
8300                 ret = TEST_FAILED;
8301                 goto on_err;
8302         }
8303
8304         /* Validate obuf */
8305         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8306                         uint8_t *);
8307         if (oop) {
8308                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8309                                 uint8_t *);
8310         }
8311
8312         if (memcmp(ciphertext, output_vec, output_vec_len)) {
8313                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8314                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8315                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8316                 ret = TEST_FAILED;
8317                 goto on_err;
8318         }
8319
8320 on_err:
8321         rte_crypto_op_free(ut_params->op);
8322         ut_params->op = NULL;
8323
8324         if (ut_params->sec_session)
8325                 rte_security_session_destroy(ctx, ut_params->sec_session);
8326         ut_params->sec_session = NULL;
8327
8328         rte_pktmbuf_free(ut_params->ibuf);
8329         ut_params->ibuf = NULL;
8330         if (oop) {
8331                 rte_pktmbuf_free(ut_params->obuf);
8332                 ut_params->obuf = NULL;
8333         }
8334
8335         return ret;
8336 }
8337
8338 static int
8339 test_pdcp_proto_SGL(int i, int oop,
8340         enum rte_crypto_cipher_operation opc,
8341         enum rte_crypto_auth_operation opa,
8342         uint8_t *input_vec,
8343         unsigned int input_vec_len,
8344         uint8_t *output_vec,
8345         unsigned int output_vec_len,
8346         uint32_t fragsz,
8347         uint32_t fragsz_oop)
8348 {
8349         struct crypto_testsuite_params *ts_params = &testsuite_params;
8350         struct crypto_unittest_params *ut_params = &unittest_params;
8351         uint8_t *plaintext;
8352         struct rte_mbuf *buf, *buf_oop = NULL;
8353         int ret = TEST_SUCCESS;
8354         int to_trn = 0;
8355         int to_trn_tbl[16];
8356         int segs = 1;
8357         unsigned int trn_data = 0;
8358         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8359                                 rte_cryptodev_get_sec_ctx(
8360                                 ts_params->valid_devs[0]);
8361
8362         /* Verify the capabilities */
8363         struct rte_security_capability_idx sec_cap_idx;
8364
8365         sec_cap_idx.action = ut_params->type;
8366         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8367         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8368         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8369                 return TEST_SKIPPED;
8370
8371         if (fragsz > input_vec_len)
8372                 fragsz = input_vec_len;
8373
8374         uint16_t plaintext_len = fragsz;
8375         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8376
8377         if (fragsz_oop > output_vec_len)
8378                 frag_size_oop = output_vec_len;
8379
8380         int ecx = 0;
8381         if (input_vec_len % fragsz != 0) {
8382                 if (input_vec_len / fragsz + 1 > 16)
8383                         return 1;
8384         } else if (input_vec_len / fragsz > 16)
8385                 return 1;
8386
8387         /* Out of place support */
8388         if (oop) {
8389                 /*
8390                  * For out-op-place we need to alloc another mbuf
8391                  */
8392                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8393                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8394                 buf_oop = ut_params->obuf;
8395         }
8396
8397         /* Generate test mbuf data */
8398         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8399
8400         /* clear mbuf payload */
8401         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8402                         rte_pktmbuf_tailroom(ut_params->ibuf));
8403
8404         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8405                                                   plaintext_len);
8406         memcpy(plaintext, input_vec, plaintext_len);
8407         trn_data += plaintext_len;
8408
8409         buf = ut_params->ibuf;
8410
8411         /*
8412          * Loop until no more fragments
8413          */
8414
8415         while (trn_data < input_vec_len) {
8416                 ++segs;
8417                 to_trn = (input_vec_len - trn_data < fragsz) ?
8418                                 (input_vec_len - trn_data) : fragsz;
8419
8420                 to_trn_tbl[ecx++] = to_trn;
8421
8422                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8423                 buf = buf->next;
8424
8425                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8426                                 rte_pktmbuf_tailroom(buf));
8427
8428                 /* OOP */
8429                 if (oop && !fragsz_oop) {
8430                         buf_oop->next =
8431                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8432                         buf_oop = buf_oop->next;
8433                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8434                                         0, rte_pktmbuf_tailroom(buf_oop));
8435                         rte_pktmbuf_append(buf_oop, to_trn);
8436                 }
8437
8438                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8439                                 to_trn);
8440
8441                 memcpy(plaintext, input_vec + trn_data, to_trn);
8442                 trn_data += to_trn;
8443         }
8444
8445         ut_params->ibuf->nb_segs = segs;
8446
8447         segs = 1;
8448         if (fragsz_oop && oop) {
8449                 to_trn = 0;
8450                 ecx = 0;
8451
8452                 trn_data = frag_size_oop;
8453                 while (trn_data < output_vec_len) {
8454                         ++segs;
8455                         to_trn =
8456                                 (output_vec_len - trn_data <
8457                                                 frag_size_oop) ?
8458                                 (output_vec_len - trn_data) :
8459                                                 frag_size_oop;
8460
8461                         to_trn_tbl[ecx++] = to_trn;
8462
8463                         buf_oop->next =
8464                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
8465                         buf_oop = buf_oop->next;
8466                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8467                                         0, rte_pktmbuf_tailroom(buf_oop));
8468                         rte_pktmbuf_append(buf_oop, to_trn);
8469
8470                         trn_data += to_trn;
8471                 }
8472                 ut_params->obuf->nb_segs = segs;
8473         }
8474
8475         /* Setup Cipher Parameters */
8476         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8477         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8478         ut_params->cipher_xform.cipher.op = opc;
8479         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8480         ut_params->cipher_xform.cipher.key.length =
8481                                         pdcp_test_params[i].cipher_key_len;
8482         ut_params->cipher_xform.cipher.iv.length = 0;
8483
8484         /* Setup HMAC Parameters if ICV header is required */
8485         if (pdcp_test_params[i].auth_alg != 0) {
8486                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8487                 ut_params->auth_xform.next = NULL;
8488                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8489                 ut_params->auth_xform.auth.op = opa;
8490                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8491                 ut_params->auth_xform.auth.key.length =
8492                                         pdcp_test_params[i].auth_key_len;
8493
8494                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8495         } else {
8496                 ut_params->cipher_xform.next = NULL;
8497         }
8498
8499         struct rte_security_session_conf sess_conf = {
8500                 .action_type = ut_params->type,
8501                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8502                 {.pdcp = {
8503                         .bearer = pdcp_test_bearer[i],
8504                         .domain = pdcp_test_params[i].domain,
8505                         .pkt_dir = pdcp_test_packet_direction[i],
8506                         .sn_size = pdcp_test_data_sn_size[i],
8507                         .hfn = pdcp_test_hfn[i],
8508                         .hfn_threshold = pdcp_test_hfn_threshold[i],
8509                         .hfn_ovrd = 0,
8510                 } },
8511                 .crypto_xform = &ut_params->cipher_xform
8512         };
8513
8514         /* Create security session */
8515         ut_params->sec_session = rte_security_session_create(ctx,
8516                                 &sess_conf, ts_params->session_mpool,
8517                                 ts_params->session_priv_mpool);
8518
8519         if (!ut_params->sec_session) {
8520                 printf("TestCase %s()-%d line %d failed %s: ",
8521                         __func__, i, __LINE__, "Failed to allocate session");
8522                 ret = TEST_FAILED;
8523                 goto on_err;
8524         }
8525
8526         /* Generate crypto op data structure */
8527         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8528                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8529         if (!ut_params->op) {
8530                 printf("TestCase %s()-%d line %d failed %s: ",
8531                         __func__, i, __LINE__,
8532                         "Failed to allocate symmetric crypto operation struct");
8533                 ret = TEST_FAILED;
8534                 goto on_err;
8535         }
8536
8537         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8538
8539         /* set crypto operation source mbuf */
8540         ut_params->op->sym->m_src = ut_params->ibuf;
8541         if (oop)
8542                 ut_params->op->sym->m_dst = ut_params->obuf;
8543
8544         /* Process crypto operation */
8545         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8546                 == NULL) {
8547                 printf("TestCase %s()-%d line %d failed %s: ",
8548                         __func__, i, __LINE__,
8549                         "failed to process sym crypto op");
8550                 ret = TEST_FAILED;
8551                 goto on_err;
8552         }
8553
8554         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8555                 printf("TestCase %s()-%d line %d failed %s: ",
8556                         __func__, i, __LINE__, "crypto op processing failed");
8557                 ret = TEST_FAILED;
8558                 goto on_err;
8559         }
8560
8561         /* Validate obuf */
8562         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8563                         uint8_t *);
8564         if (oop) {
8565                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8566                                 uint8_t *);
8567         }
8568         if (fragsz_oop)
8569                 fragsz = frag_size_oop;
8570         if (memcmp(ciphertext, output_vec, fragsz)) {
8571                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8572                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8573                 rte_hexdump(stdout, "reference", output_vec, fragsz);
8574                 ret = TEST_FAILED;
8575                 goto on_err;
8576         }
8577
8578         buf = ut_params->op->sym->m_src->next;
8579         if (oop)
8580                 buf = ut_params->op->sym->m_dst->next;
8581
8582         unsigned int off = fragsz;
8583
8584         ecx = 0;
8585         while (buf) {
8586                 ciphertext = rte_pktmbuf_mtod(buf,
8587                                 uint8_t *);
8588                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8589                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8590                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8591                         rte_hexdump(stdout, "reference", output_vec + off,
8592                                         to_trn_tbl[ecx]);
8593                         ret = TEST_FAILED;
8594                         goto on_err;
8595                 }
8596                 off += to_trn_tbl[ecx++];
8597                 buf = buf->next;
8598         }
8599 on_err:
8600         rte_crypto_op_free(ut_params->op);
8601         ut_params->op = NULL;
8602
8603         if (ut_params->sec_session)
8604                 rte_security_session_destroy(ctx, ut_params->sec_session);
8605         ut_params->sec_session = NULL;
8606
8607         rte_pktmbuf_free(ut_params->ibuf);
8608         ut_params->ibuf = NULL;
8609         if (oop) {
8610                 rte_pktmbuf_free(ut_params->obuf);
8611                 ut_params->obuf = NULL;
8612         }
8613
8614         return ret;
8615 }
8616
8617 int
8618 test_pdcp_proto_cplane_encap(int i)
8619 {
8620         return test_pdcp_proto(
8621                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8622                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8623                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8624                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8625                 pdcp_test_params[i].cipher_key_len,
8626                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8627                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8628                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8629                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8630                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8631 }
8632
8633 int
8634 test_pdcp_proto_uplane_encap(int i)
8635 {
8636         return test_pdcp_proto(
8637                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8638                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8639                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8640                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8641                 pdcp_test_params[i].cipher_key_len,
8642                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8643                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8644                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8645                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8646                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8647 }
8648
8649 int
8650 test_pdcp_proto_uplane_encap_with_int(int i)
8651 {
8652         return test_pdcp_proto(
8653                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8654                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8655                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8656                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8657                 pdcp_test_params[i].cipher_key_len,
8658                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8659                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8660                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8661                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8662                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8663 }
8664
8665 int
8666 test_pdcp_proto_cplane_decap(int i)
8667 {
8668         return test_pdcp_proto(
8669                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8670                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8671                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8672                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8673                 pdcp_test_params[i].cipher_key_len,
8674                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8675                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8676                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8677                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8678                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8679 }
8680
8681 int
8682 test_pdcp_proto_uplane_decap(int i)
8683 {
8684         return test_pdcp_proto(
8685                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8686                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8687                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8688                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8689                 pdcp_test_params[i].cipher_key_len,
8690                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8691                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8692                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8693                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8694                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8695 }
8696
8697 int
8698 test_pdcp_proto_uplane_decap_with_int(int i)
8699 {
8700         return test_pdcp_proto(
8701                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8702                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8703                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8704                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8705                 pdcp_test_params[i].cipher_key_len,
8706                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8707                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8708                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8709                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8710                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8711 }
8712
8713 static int
8714 test_PDCP_PROTO_SGL_in_place_32B(void)
8715 {
8716         /* i can be used for running any PDCP case
8717          * In this case it is uplane 12-bit AES-SNOW DL encap
8718          */
8719         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8720         return test_pdcp_proto_SGL(i, IN_PLACE,
8721                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8722                         RTE_CRYPTO_AUTH_OP_GENERATE,
8723                         pdcp_test_data_in[i],
8724                         pdcp_test_data_in_len[i],
8725                         pdcp_test_data_out[i],
8726                         pdcp_test_data_in_len[i]+4,
8727                         32, 0);
8728 }
8729 static int
8730 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8731 {
8732         /* i can be used for running any PDCP case
8733          * In this case it is uplane 18-bit NULL-NULL DL encap
8734          */
8735         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8736         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8737                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8738                         RTE_CRYPTO_AUTH_OP_GENERATE,
8739                         pdcp_test_data_in[i],
8740                         pdcp_test_data_in_len[i],
8741                         pdcp_test_data_out[i],
8742                         pdcp_test_data_in_len[i]+4,
8743                         32, 128);
8744 }
8745 static int
8746 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8747 {
8748         /* i can be used for running any PDCP case
8749          * In this case it is uplane 18-bit AES DL encap
8750          */
8751         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8752                         + DOWNLINK;
8753         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8754                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8755                         RTE_CRYPTO_AUTH_OP_GENERATE,
8756                         pdcp_test_data_in[i],
8757                         pdcp_test_data_in_len[i],
8758                         pdcp_test_data_out[i],
8759                         pdcp_test_data_in_len[i],
8760                         32, 40);
8761 }
8762 static int
8763 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8764 {
8765         /* i can be used for running any PDCP case
8766          * In this case it is cplane 12-bit AES-ZUC DL encap
8767          */
8768         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8769         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8770                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8771                         RTE_CRYPTO_AUTH_OP_GENERATE,
8772                         pdcp_test_data_in[i],
8773                         pdcp_test_data_in_len[i],
8774                         pdcp_test_data_out[i],
8775                         pdcp_test_data_in_len[i]+4,
8776                         128, 32);
8777 }
8778
8779 static int
8780 test_PDCP_SDAP_PROTO_encap_all(void)
8781 {
8782         int i = 0, size = 0;
8783         int err, all_err = TEST_SUCCESS;
8784         const struct pdcp_sdap_test *cur_test;
8785
8786         size = RTE_DIM(list_pdcp_sdap_tests);
8787
8788         for (i = 0; i < size; i++) {
8789                 cur_test = &list_pdcp_sdap_tests[i];
8790                 err = test_pdcp_proto(
8791                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8792                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8793                         cur_test->in_len, cur_test->data_out,
8794                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8795                         cur_test->param.cipher_alg, cur_test->cipher_key,
8796                         cur_test->param.cipher_key_len,
8797                         cur_test->param.auth_alg,
8798                         cur_test->auth_key, cur_test->param.auth_key_len,
8799                         cur_test->bearer, cur_test->param.domain,
8800                         cur_test->packet_direction, cur_test->sn_size,
8801                         cur_test->hfn,
8802                         cur_test->hfn_threshold, SDAP_ENABLED);
8803                 if (err) {
8804                         printf("\t%d) %s: Encapsulation failed\n",
8805                                         cur_test->test_idx,
8806                                         cur_test->param.name);
8807                         err = TEST_FAILED;
8808                 } else {
8809                         printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8810                                         cur_test->param.name);
8811                         err = TEST_SUCCESS;
8812                 }
8813                 all_err += err;
8814         }
8815
8816         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8817
8818         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8819 }
8820
8821 static int
8822 test_PDCP_PROTO_short_mac(void)
8823 {
8824         int i = 0, size = 0;
8825         int err, all_err = TEST_SUCCESS;
8826         const struct pdcp_short_mac_test *cur_test;
8827
8828         size = RTE_DIM(list_pdcp_smac_tests);
8829
8830         for (i = 0; i < size; i++) {
8831                 cur_test = &list_pdcp_smac_tests[i];
8832                 err = test_pdcp_proto(
8833                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8834                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8835                         cur_test->in_len, cur_test->data_out,
8836                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8837                         RTE_CRYPTO_CIPHER_NULL, NULL,
8838                         0, cur_test->param.auth_alg,
8839                         cur_test->auth_key, cur_test->param.auth_key_len,
8840                         0, cur_test->param.domain, 0, 0,
8841                         0, 0, 0);
8842                 if (err) {
8843                         printf("\t%d) %s: Short MAC test failed\n",
8844                                         cur_test->test_idx,
8845                                         cur_test->param.name);
8846                         err = TEST_FAILED;
8847                 } else {
8848                         printf("\t%d) %s: Short MAC test PASS\n",
8849                                         cur_test->test_idx,
8850                                         cur_test->param.name);
8851                         rte_hexdump(stdout, "MAC I",
8852                                     cur_test->data_out + cur_test->in_len + 2,
8853                                     2);
8854                         err = TEST_SUCCESS;
8855                 }
8856                 all_err += err;
8857         }
8858
8859         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8860
8861         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8862
8863 }
8864
8865 static int
8866 test_PDCP_SDAP_PROTO_decap_all(void)
8867 {
8868         int i = 0, size = 0;
8869         int err, all_err = TEST_SUCCESS;
8870         const struct pdcp_sdap_test *cur_test;
8871
8872         size = RTE_DIM(list_pdcp_sdap_tests);
8873
8874         for (i = 0; i < size; i++) {
8875                 cur_test = &list_pdcp_sdap_tests[i];
8876                 err = test_pdcp_proto(
8877                         i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8878                         RTE_CRYPTO_AUTH_OP_VERIFY,
8879                         cur_test->data_out,
8880                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8881                         cur_test->data_in, cur_test->in_len,
8882                         cur_test->param.cipher_alg,
8883                         cur_test->cipher_key, cur_test->param.cipher_key_len,
8884                         cur_test->param.auth_alg, cur_test->auth_key,
8885                         cur_test->param.auth_key_len, cur_test->bearer,
8886                         cur_test->param.domain, cur_test->packet_direction,
8887                         cur_test->sn_size, cur_test->hfn,
8888                         cur_test->hfn_threshold, SDAP_ENABLED);
8889                 if (err) {
8890                         printf("\t%d) %s: Decapsulation failed\n",
8891                                         cur_test->test_idx,
8892                                         cur_test->param.name);
8893                         err = TEST_FAILED;
8894                 } else {
8895                         printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8896                                         cur_test->param.name);
8897                         err = TEST_SUCCESS;
8898                 }
8899                 all_err += err;
8900         }
8901
8902         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8903
8904         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8905 }
8906
8907 static int
8908 test_ipsec_proto_process(const struct ipsec_test_data td[],
8909                          struct ipsec_test_data res_d[],
8910                          int nb_td,
8911                          bool silent,
8912                          const struct ipsec_test_flags *flags)
8913 {
8914         struct crypto_testsuite_params *ts_params = &testsuite_params;
8915         struct crypto_unittest_params *ut_params = &unittest_params;
8916         struct rte_security_capability_idx sec_cap_idx;
8917         const struct rte_security_capability *sec_cap;
8918         struct rte_security_ipsec_xform ipsec_xform;
8919         uint8_t dev_id = ts_params->valid_devs[0];
8920         enum rte_security_ipsec_sa_direction dir;
8921         struct ipsec_test_data *res_d_tmp = NULL;
8922         uint32_t src = RTE_IPV4(192, 168, 1, 0);
8923         uint32_t dst = RTE_IPV4(192, 168, 1, 1);
8924         int salt_len, i, ret = TEST_SUCCESS;
8925         struct rte_security_ctx *ctx;
8926         uint8_t *input_text;
8927         uint32_t verify;
8928
8929         ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
8930         gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
8931
8932         /* Use first test data to create session */
8933
8934         /* Copy IPsec xform */
8935         memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
8936
8937         dir = ipsec_xform.direction;
8938         verify = flags->tunnel_hdr_verify;
8939
8940         if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
8941                 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
8942                         src += 1;
8943                 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
8944                         dst += 1;
8945         }
8946
8947         memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src));
8948         memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst));
8949
8950         ctx = rte_cryptodev_get_sec_ctx(dev_id);
8951
8952         sec_cap_idx.action = ut_params->type;
8953         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
8954         sec_cap_idx.ipsec.proto = ipsec_xform.proto;
8955         sec_cap_idx.ipsec.mode = ipsec_xform.mode;
8956         sec_cap_idx.ipsec.direction = ipsec_xform.direction;
8957
8958         if (flags->udp_encap)
8959                 ipsec_xform.options.udp_encap = 1;
8960
8961         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8962         if (sec_cap == NULL)
8963                 return TEST_SKIPPED;
8964
8965         /* Copy cipher session parameters */
8966         if (td[0].aead) {
8967                 memcpy(&ut_params->aead_xform, &td[0].xform.aead,
8968                        sizeof(ut_params->aead_xform));
8969                 ut_params->aead_xform.aead.key.data = td[0].key.data;
8970                 ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
8971
8972                 /* Verify crypto capabilities */
8973                 if (test_ipsec_crypto_caps_aead_verify(
8974                                 sec_cap,
8975                                 &ut_params->aead_xform) != 0) {
8976                         if (!silent)
8977                                 RTE_LOG(INFO, USER1,
8978                                         "Crypto capabilities not supported\n");
8979                         return TEST_SKIPPED;
8980                 }
8981         } else {
8982                 /* Only AEAD supported now */
8983                 return TEST_SKIPPED;
8984         }
8985
8986         if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
8987                 return TEST_SKIPPED;
8988
8989         salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
8990         memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
8991
8992         struct rte_security_session_conf sess_conf = {
8993                 .action_type = ut_params->type,
8994                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
8995                 .ipsec = ipsec_xform,
8996                 .crypto_xform = &ut_params->aead_xform,
8997         };
8998
8999         /* Create security session */
9000         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9001                                         ts_params->session_mpool,
9002                                         ts_params->session_priv_mpool);
9003
9004         if (ut_params->sec_session == NULL)
9005                 return TEST_SKIPPED;
9006
9007         for (i = 0; i < nb_td; i++) {
9008                 /* Setup source mbuf payload */
9009                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9010                 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9011                                 rte_pktmbuf_tailroom(ut_params->ibuf));
9012
9013                 input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9014                                 td[i].input_text.len);
9015
9016                 memcpy(input_text, td[i].input_text.data,
9017                        td[i].input_text.len);
9018
9019                 /* Generate crypto op data structure */
9020                 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9021                                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9022                 if (!ut_params->op) {
9023                         printf("TestCase %s line %d: %s\n",
9024                                 __func__, __LINE__,
9025                                 "failed to allocate crypto op");
9026                         ret = TEST_FAILED;
9027                         goto crypto_op_free;
9028                 }
9029
9030                 /* Attach session to operation */
9031                 rte_security_attach_session(ut_params->op,
9032                                             ut_params->sec_session);
9033
9034                 /* Set crypto operation mbufs */
9035                 ut_params->op->sym->m_src = ut_params->ibuf;
9036                 ut_params->op->sym->m_dst = NULL;
9037
9038                 /* Copy IV in crypto operation when IV generation is disabled */
9039                 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
9040                     ipsec_xform.options.iv_gen_disable == 1) {
9041                         uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
9042                                                                 uint8_t *,
9043                                                                 IV_OFFSET);
9044                         int len;
9045
9046                         if (td[i].aead)
9047                                 len = td[i].xform.aead.aead.iv.length;
9048                         else
9049                                 len = td[i].xform.chain.cipher.cipher.iv.length;
9050
9051                         memcpy(iv, td[i].iv.data, len);
9052                 }
9053
9054                 /* Process crypto operation */
9055                 process_crypto_request(dev_id, ut_params->op);
9056
9057                 ret = test_ipsec_status_check(ut_params->op, flags, dir, i + 1);
9058                 if (ret != TEST_SUCCESS)
9059                         goto crypto_op_free;
9060
9061                 if (res_d != NULL)
9062                         res_d_tmp = &res_d[i];
9063
9064                 ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
9065                                               res_d_tmp, silent, flags);
9066                 if (ret != TEST_SUCCESS)
9067                         goto crypto_op_free;
9068
9069                 rte_crypto_op_free(ut_params->op);
9070                 ut_params->op = NULL;
9071
9072                 rte_pktmbuf_free(ut_params->ibuf);
9073                 ut_params->ibuf = NULL;
9074         }
9075
9076 crypto_op_free:
9077         rte_crypto_op_free(ut_params->op);
9078         ut_params->op = NULL;
9079
9080         rte_pktmbuf_free(ut_params->ibuf);
9081         ut_params->ibuf = NULL;
9082
9083         if (ut_params->sec_session)
9084                 rte_security_session_destroy(ctx, ut_params->sec_session);
9085         ut_params->sec_session = NULL;
9086
9087         return ret;
9088 }
9089
9090 static int
9091 test_ipsec_proto_known_vec(const void *test_data)
9092 {
9093         struct ipsec_test_data td_outb;
9094         struct ipsec_test_flags flags;
9095
9096         memset(&flags, 0, sizeof(flags));
9097
9098         memcpy(&td_outb, test_data, sizeof(td_outb));
9099
9100         /* Disable IV gen to be able to test with known vectors */
9101         td_outb.ipsec_xform.options.iv_gen_disable = 1;
9102
9103         return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9104 }
9105
9106 static int
9107 test_ipsec_proto_known_vec_inb(const void *td_outb)
9108 {
9109         struct ipsec_test_flags flags;
9110         struct ipsec_test_data td_inb;
9111
9112         memset(&flags, 0, sizeof(flags));
9113
9114         test_ipsec_td_in_from_out(td_outb, &td_inb);
9115
9116         return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
9117 }
9118
9119 static int
9120 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
9121 {
9122         struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9123         struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9124         unsigned int i, nb_pkts = 1, pass_cnt = 0;
9125         int ret;
9126
9127         if (flags->iv_gen ||
9128             flags->sa_expiry_pkts_soft ||
9129             flags->sa_expiry_pkts_hard)
9130                 nb_pkts = IPSEC_TEST_PACKETS_MAX;
9131
9132         for (i = 0; i < RTE_DIM(aead_list); i++) {
9133                 test_ipsec_td_prepare(&aead_list[i],
9134                                       NULL,
9135                                       flags,
9136                                       td_outb,
9137                                       nb_pkts);
9138
9139                 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9140                                                flags);
9141                 if (ret == TEST_SKIPPED)
9142                         continue;
9143
9144                 if (ret == TEST_FAILED)
9145                         return TEST_FAILED;
9146
9147                 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9148
9149                 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9150                                                flags);
9151                 if (ret == TEST_SKIPPED)
9152                         continue;
9153
9154                 if (ret == TEST_FAILED)
9155                         return TEST_FAILED;
9156
9157                 if (flags->display_alg)
9158                         test_ipsec_display_alg(&aead_list[i], NULL);
9159
9160                 pass_cnt++;
9161         }
9162
9163         if (pass_cnt > 0)
9164                 return TEST_SUCCESS;
9165         else
9166                 return TEST_SKIPPED;
9167 }
9168
9169 static int
9170 test_ipsec_proto_display_list(const void *data __rte_unused)
9171 {
9172         struct ipsec_test_flags flags;
9173
9174         memset(&flags, 0, sizeof(flags));
9175
9176         flags.display_alg = true;
9177
9178         return test_ipsec_proto_all(&flags);
9179 }
9180
9181 static int
9182 test_ipsec_proto_iv_gen(const void *data __rte_unused)
9183 {
9184         struct ipsec_test_flags flags;
9185
9186         memset(&flags, 0, sizeof(flags));
9187
9188         flags.iv_gen = true;
9189
9190         return test_ipsec_proto_all(&flags);
9191 }
9192
9193 static int
9194 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused)
9195 {
9196         struct ipsec_test_flags flags;
9197
9198         memset(&flags, 0, sizeof(flags));
9199
9200         flags.sa_expiry_pkts_soft = true;
9201
9202         return test_ipsec_proto_all(&flags);
9203 }
9204
9205 static int
9206 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused)
9207 {
9208         struct ipsec_test_flags flags;
9209
9210         memset(&flags, 0, sizeof(flags));
9211
9212         flags.sa_expiry_pkts_hard = true;
9213
9214         return test_ipsec_proto_all(&flags);
9215 }
9216
9217 static int
9218 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused)
9219 {
9220         struct ipsec_test_flags flags;
9221
9222         memset(&flags, 0, sizeof(flags));
9223
9224         flags.icv_corrupt = true;
9225
9226         return test_ipsec_proto_all(&flags);
9227 }
9228
9229 static int
9230 test_ipsec_proto_udp_encap(const void *data __rte_unused)
9231 {
9232         struct ipsec_test_flags flags;
9233
9234         memset(&flags, 0, sizeof(flags));
9235
9236         flags.udp_encap = true;
9237
9238         return test_ipsec_proto_all(&flags);
9239 }
9240
9241 static int
9242 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
9243 {
9244         struct ipsec_test_flags flags;
9245
9246         memset(&flags, 0, sizeof(flags));
9247
9248         flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
9249
9250         return test_ipsec_proto_all(&flags);
9251 }
9252
9253 static int
9254 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
9255 {
9256         struct ipsec_test_flags flags;
9257
9258         memset(&flags, 0, sizeof(flags));
9259
9260         flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
9261
9262         return test_ipsec_proto_all(&flags);
9263 }
9264
9265 static int
9266 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused)
9267 {
9268         struct ipsec_test_flags flags;
9269
9270         memset(&flags, 0, sizeof(flags));
9271
9272         flags.udp_encap = true;
9273         flags.udp_ports_verify = true;
9274
9275         return test_ipsec_proto_all(&flags);
9276 }
9277
9278 static int
9279 test_PDCP_PROTO_all(void)
9280 {
9281         struct crypto_testsuite_params *ts_params = &testsuite_params;
9282         struct crypto_unittest_params *ut_params = &unittest_params;
9283         struct rte_cryptodev_info dev_info;
9284         int status;
9285
9286         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9287         uint64_t feat_flags = dev_info.feature_flags;
9288
9289         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9290                 return TEST_SKIPPED;
9291
9292         /* Set action type */
9293         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9294                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9295                 gbl_action_type;
9296
9297         if (security_proto_supported(ut_params->type,
9298                         RTE_SECURITY_PROTOCOL_PDCP) < 0)
9299                 return TEST_SKIPPED;
9300
9301         status = test_PDCP_PROTO_cplane_encap_all();
9302         status += test_PDCP_PROTO_cplane_decap_all();
9303         status += test_PDCP_PROTO_uplane_encap_all();
9304         status += test_PDCP_PROTO_uplane_decap_all();
9305         status += test_PDCP_PROTO_SGL_in_place_32B();
9306         status += test_PDCP_PROTO_SGL_oop_32B_128B();
9307         status += test_PDCP_PROTO_SGL_oop_32B_40B();
9308         status += test_PDCP_PROTO_SGL_oop_128B_32B();
9309         status += test_PDCP_SDAP_PROTO_encap_all();
9310         status += test_PDCP_SDAP_PROTO_decap_all();
9311         status += test_PDCP_PROTO_short_mac();
9312
9313         if (status)
9314                 return TEST_FAILED;
9315         else
9316                 return TEST_SUCCESS;
9317 }
9318
9319 static int
9320 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
9321 {
9322         struct crypto_testsuite_params *ts_params = &testsuite_params;
9323         struct crypto_unittest_params *ut_params = &unittest_params;
9324         uint8_t *plaintext, *ciphertext;
9325         uint8_t *iv_ptr;
9326         int32_t cipher_len, crc_len;
9327         uint32_t crc_data_len;
9328         int ret = TEST_SUCCESS;
9329
9330         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9331                                         rte_cryptodev_get_sec_ctx(
9332                                                 ts_params->valid_devs[0]);
9333
9334         /* Verify the capabilities */
9335         struct rte_security_capability_idx sec_cap_idx;
9336         const struct rte_security_capability *sec_cap;
9337         const struct rte_cryptodev_capabilities *crypto_cap;
9338         const struct rte_cryptodev_symmetric_capability *sym_cap;
9339         int j = 0;
9340
9341         sec_cap_idx.action = ut_params->type;
9342         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9343         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
9344
9345         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9346         if (sec_cap == NULL)
9347                 return TEST_SKIPPED;
9348
9349         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9350                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9351                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9352                                 crypto_cap->sym.xform_type ==
9353                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9354                                 crypto_cap->sym.cipher.algo ==
9355                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9356                         sym_cap = &crypto_cap->sym;
9357                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9358                                                 d_td->key.len,
9359                                                 d_td->iv.len) == 0)
9360                                 break;
9361                 }
9362         }
9363
9364         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9365                 return TEST_SKIPPED;
9366
9367         /* Setup source mbuf payload */
9368         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9369         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9370                         rte_pktmbuf_tailroom(ut_params->ibuf));
9371
9372         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9373                         d_td->ciphertext.len);
9374
9375         memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
9376
9377         /* Setup cipher session parameters */
9378         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9379         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9380         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
9381         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9382         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9383         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9384         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9385         ut_params->cipher_xform.next = NULL;
9386
9387         /* Setup DOCSIS session parameters */
9388         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
9389
9390         struct rte_security_session_conf sess_conf = {
9391                 .action_type = ut_params->type,
9392                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9393                 .docsis = ut_params->docsis_xform,
9394                 .crypto_xform = &ut_params->cipher_xform,
9395         };
9396
9397         /* Create security session */
9398         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9399                                         ts_params->session_mpool,
9400                                         ts_params->session_priv_mpool);
9401
9402         if (!ut_params->sec_session) {
9403                 printf("TestCase %s(%d) line %d: %s\n",
9404                         __func__, i, __LINE__, "failed to allocate session");
9405                 ret = TEST_FAILED;
9406                 goto on_err;
9407         }
9408
9409         /* Generate crypto op data structure */
9410         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9411                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9412         if (!ut_params->op) {
9413                 printf("TestCase %s(%d) line %d: %s\n",
9414                         __func__, i, __LINE__,
9415                         "failed to allocate symmetric crypto operation");
9416                 ret = TEST_FAILED;
9417                 goto on_err;
9418         }
9419
9420         /* Setup CRC operation parameters */
9421         crc_len = d_td->ciphertext.no_crc == false ?
9422                         (d_td->ciphertext.len -
9423                                 d_td->ciphertext.crc_offset -
9424                                 RTE_ETHER_CRC_LEN) :
9425                         0;
9426         crc_len = crc_len > 0 ? crc_len : 0;
9427         crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
9428         ut_params->op->sym->auth.data.length = crc_len;
9429         ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
9430
9431         /* Setup cipher operation parameters */
9432         cipher_len = d_td->ciphertext.no_cipher == false ?
9433                         (d_td->ciphertext.len -
9434                                 d_td->ciphertext.cipher_offset) :
9435                         0;
9436         cipher_len = cipher_len > 0 ? cipher_len : 0;
9437         ut_params->op->sym->cipher.data.length = cipher_len;
9438         ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
9439
9440         /* Setup cipher IV */
9441         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9442         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9443
9444         /* Attach session to operation */
9445         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9446
9447         /* Set crypto operation mbufs */
9448         ut_params->op->sym->m_src = ut_params->ibuf;
9449         ut_params->op->sym->m_dst = NULL;
9450
9451         /* Process crypto operation */
9452         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9453                         NULL) {
9454                 printf("TestCase %s(%d) line %d: %s\n",
9455                         __func__, i, __LINE__,
9456                         "failed to process security crypto op");
9457                 ret = TEST_FAILED;
9458                 goto on_err;
9459         }
9460
9461         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9462                 printf("TestCase %s(%d) line %d: %s\n",
9463                         __func__, i, __LINE__, "crypto op processing failed");
9464                 ret = TEST_FAILED;
9465                 goto on_err;
9466         }
9467
9468         /* Validate plaintext */
9469         plaintext = ciphertext;
9470
9471         if (memcmp(plaintext, d_td->plaintext.data,
9472                         d_td->plaintext.len - crc_data_len)) {
9473                 printf("TestCase %s(%d) line %d: %s\n",
9474                         __func__, i, __LINE__, "plaintext not as expected\n");
9475                 rte_hexdump(stdout, "expected", d_td->plaintext.data,
9476                                 d_td->plaintext.len);
9477                 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9478                 ret = TEST_FAILED;
9479                 goto on_err;
9480         }
9481
9482 on_err:
9483         rte_crypto_op_free(ut_params->op);
9484         ut_params->op = NULL;
9485
9486         if (ut_params->sec_session)
9487                 rte_security_session_destroy(ctx, ut_params->sec_session);
9488         ut_params->sec_session = NULL;
9489
9490         rte_pktmbuf_free(ut_params->ibuf);
9491         ut_params->ibuf = NULL;
9492
9493         return ret;
9494 }
9495
9496 static int
9497 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9498 {
9499         struct crypto_testsuite_params *ts_params = &testsuite_params;
9500         struct crypto_unittest_params *ut_params = &unittest_params;
9501         uint8_t *plaintext, *ciphertext;
9502         uint8_t *iv_ptr;
9503         int32_t cipher_len, crc_len;
9504         int ret = TEST_SUCCESS;
9505
9506         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9507                                         rte_cryptodev_get_sec_ctx(
9508                                                 ts_params->valid_devs[0]);
9509
9510         /* Verify the capabilities */
9511         struct rte_security_capability_idx sec_cap_idx;
9512         const struct rte_security_capability *sec_cap;
9513         const struct rte_cryptodev_capabilities *crypto_cap;
9514         const struct rte_cryptodev_symmetric_capability *sym_cap;
9515         int j = 0;
9516
9517         sec_cap_idx.action = ut_params->type;
9518         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9519         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9520
9521         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9522         if (sec_cap == NULL)
9523                 return TEST_SKIPPED;
9524
9525         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9526                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9527                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9528                                 crypto_cap->sym.xform_type ==
9529                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9530                                 crypto_cap->sym.cipher.algo ==
9531                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9532                         sym_cap = &crypto_cap->sym;
9533                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9534                                                 d_td->key.len,
9535                                                 d_td->iv.len) == 0)
9536                                 break;
9537                 }
9538         }
9539
9540         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9541                 return TEST_SKIPPED;
9542
9543         /* Setup source mbuf payload */
9544         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9545         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9546                         rte_pktmbuf_tailroom(ut_params->ibuf));
9547
9548         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9549                         d_td->plaintext.len);
9550
9551         memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9552
9553         /* Setup cipher session parameters */
9554         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9555         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9556         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9557         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9558         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9559         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9560         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9561         ut_params->cipher_xform.next = NULL;
9562
9563         /* Setup DOCSIS session parameters */
9564         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9565
9566         struct rte_security_session_conf sess_conf = {
9567                 .action_type = ut_params->type,
9568                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9569                 .docsis = ut_params->docsis_xform,
9570                 .crypto_xform = &ut_params->cipher_xform,
9571         };
9572
9573         /* Create security session */
9574         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9575                                         ts_params->session_mpool,
9576                                         ts_params->session_priv_mpool);
9577
9578         if (!ut_params->sec_session) {
9579                 printf("TestCase %s(%d) line %d: %s\n",
9580                         __func__, i, __LINE__, "failed to allocate session");
9581                 ret = TEST_FAILED;
9582                 goto on_err;
9583         }
9584
9585         /* Generate crypto op data structure */
9586         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9587                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9588         if (!ut_params->op) {
9589                 printf("TestCase %s(%d) line %d: %s\n",
9590                         __func__, i, __LINE__,
9591                         "failed to allocate security crypto operation");
9592                 ret = TEST_FAILED;
9593                 goto on_err;
9594         }
9595
9596         /* Setup CRC operation parameters */
9597         crc_len = d_td->plaintext.no_crc == false ?
9598                         (d_td->plaintext.len -
9599                                 d_td->plaintext.crc_offset -
9600                                 RTE_ETHER_CRC_LEN) :
9601                         0;
9602         crc_len = crc_len > 0 ? crc_len : 0;
9603         ut_params->op->sym->auth.data.length = crc_len;
9604         ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9605
9606         /* Setup cipher operation parameters */
9607         cipher_len = d_td->plaintext.no_cipher == false ?
9608                         (d_td->plaintext.len -
9609                                 d_td->plaintext.cipher_offset) :
9610                         0;
9611         cipher_len = cipher_len > 0 ? cipher_len : 0;
9612         ut_params->op->sym->cipher.data.length = cipher_len;
9613         ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9614
9615         /* Setup cipher IV */
9616         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9617         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9618
9619         /* Attach session to operation */
9620         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9621
9622         /* Set crypto operation mbufs */
9623         ut_params->op->sym->m_src = ut_params->ibuf;
9624         ut_params->op->sym->m_dst = NULL;
9625
9626         /* Process crypto operation */
9627         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9628                         NULL) {
9629                 printf("TestCase %s(%d) line %d: %s\n",
9630                         __func__, i, __LINE__,
9631                         "failed to process security crypto op");
9632                 ret = TEST_FAILED;
9633                 goto on_err;
9634         }
9635
9636         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9637                 printf("TestCase %s(%d) line %d: %s\n",
9638                         __func__, i, __LINE__, "crypto op processing failed");
9639                 ret = TEST_FAILED;
9640                 goto on_err;
9641         }
9642
9643         /* Validate ciphertext */
9644         ciphertext = plaintext;
9645
9646         if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9647                 printf("TestCase %s(%d) line %d: %s\n",
9648                         __func__, i, __LINE__, "ciphertext not as expected\n");
9649                 rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9650                                 d_td->ciphertext.len);
9651                 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9652                 ret = TEST_FAILED;
9653                 goto on_err;
9654         }
9655
9656 on_err:
9657         rte_crypto_op_free(ut_params->op);
9658         ut_params->op = NULL;
9659
9660         if (ut_params->sec_session)
9661                 rte_security_session_destroy(ctx, ut_params->sec_session);
9662         ut_params->sec_session = NULL;
9663
9664         rte_pktmbuf_free(ut_params->ibuf);
9665         ut_params->ibuf = NULL;
9666
9667         return ret;
9668 }
9669
9670 #define TEST_DOCSIS_COUNT(func) do {                    \
9671         int ret = func;                                 \
9672         if (ret == TEST_SUCCESS)  {                     \
9673                 printf("\t%2d)", n++);                  \
9674                 printf("+++++ PASSED:" #func"\n");      \
9675                 p++;                                    \
9676         } else if (ret == TEST_SKIPPED) {               \
9677                 printf("\t%2d)", n++);                  \
9678                 printf("~~~~~ SKIPPED:" #func"\n");     \
9679                 s++;                                    \
9680         } else {                                        \
9681                 printf("\t%2d)", n++);                  \
9682                 printf("----- FAILED:" #func"\n");      \
9683                 f++;                                    \
9684         }                                               \
9685 } while (0)
9686
9687 static int
9688 test_DOCSIS_PROTO_uplink_all(void)
9689 {
9690         int p = 0, s = 0, f = 0, n = 0;
9691
9692         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9693         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9694         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9695         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9696         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9697         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9698         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9699         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9700         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9701         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9702         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9703         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9704         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9705         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9706         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9707         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9708         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9709         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9710         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9711         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9712         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9713         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9714         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9715         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9716         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9717         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9718
9719         if (f)
9720                 printf("## %s: %d passed out of %d (%d skipped)\n",
9721                         __func__, p, n, s);
9722
9723         return f;
9724 };
9725
9726 static int
9727 test_DOCSIS_PROTO_downlink_all(void)
9728 {
9729         int p = 0, s = 0, f = 0, n = 0;
9730
9731         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9732         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9733         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9734         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9735         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9736         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9737         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9738         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9739         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9740         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9741         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9742         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9743         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9744         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9745         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9746         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9747         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9748         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9749         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9750         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9751         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9752         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9753         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9754         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9755         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9756         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9757
9758         if (f)
9759                 printf("## %s: %d passed out of %d (%d skipped)\n",
9760                         __func__, p, n, s);
9761
9762         return f;
9763 };
9764
9765 static int
9766 test_DOCSIS_PROTO_all(void)
9767 {
9768         struct crypto_testsuite_params *ts_params = &testsuite_params;
9769         struct crypto_unittest_params *ut_params = &unittest_params;
9770         struct rte_cryptodev_info dev_info;
9771         int status;
9772
9773         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9774         uint64_t feat_flags = dev_info.feature_flags;
9775
9776         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9777                 return TEST_SKIPPED;
9778
9779         /* Set action type */
9780         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9781                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9782                 gbl_action_type;
9783
9784         if (security_proto_supported(ut_params->type,
9785                         RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9786                 return TEST_SKIPPED;
9787
9788         status = test_DOCSIS_PROTO_uplink_all();
9789         status += test_DOCSIS_PROTO_downlink_all();
9790
9791         if (status)
9792                 return TEST_FAILED;
9793         else
9794                 return TEST_SUCCESS;
9795 }
9796 #endif
9797
9798 static int
9799 test_AES_GCM_authenticated_encryption_test_case_1(void)
9800 {
9801         return test_authenticated_encryption(&gcm_test_case_1);
9802 }
9803
9804 static int
9805 test_AES_GCM_authenticated_encryption_test_case_2(void)
9806 {
9807         return test_authenticated_encryption(&gcm_test_case_2);
9808 }
9809
9810 static int
9811 test_AES_GCM_authenticated_encryption_test_case_3(void)
9812 {
9813         return test_authenticated_encryption(&gcm_test_case_3);
9814 }
9815
9816 static int
9817 test_AES_GCM_authenticated_encryption_test_case_4(void)
9818 {
9819         return test_authenticated_encryption(&gcm_test_case_4);
9820 }
9821
9822 static int
9823 test_AES_GCM_authenticated_encryption_test_case_5(void)
9824 {
9825         return test_authenticated_encryption(&gcm_test_case_5);
9826 }
9827
9828 static int
9829 test_AES_GCM_authenticated_encryption_test_case_6(void)
9830 {
9831         return test_authenticated_encryption(&gcm_test_case_6);
9832 }
9833
9834 static int
9835 test_AES_GCM_authenticated_encryption_test_case_7(void)
9836 {
9837         return test_authenticated_encryption(&gcm_test_case_7);
9838 }
9839
9840 static int
9841 test_AES_GCM_authenticated_encryption_test_case_8(void)
9842 {
9843         return test_authenticated_encryption(&gcm_test_case_8);
9844 }
9845
9846 static int
9847 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9848 {
9849         return test_authenticated_encryption(&gcm_J0_test_case_1);
9850 }
9851
9852 static int
9853 test_AES_GCM_auth_encryption_test_case_192_1(void)
9854 {
9855         return test_authenticated_encryption(&gcm_test_case_192_1);
9856 }
9857
9858 static int
9859 test_AES_GCM_auth_encryption_test_case_192_2(void)
9860 {
9861         return test_authenticated_encryption(&gcm_test_case_192_2);
9862 }
9863
9864 static int
9865 test_AES_GCM_auth_encryption_test_case_192_3(void)
9866 {
9867         return test_authenticated_encryption(&gcm_test_case_192_3);
9868 }
9869
9870 static int
9871 test_AES_GCM_auth_encryption_test_case_192_4(void)
9872 {
9873         return test_authenticated_encryption(&gcm_test_case_192_4);
9874 }
9875
9876 static int
9877 test_AES_GCM_auth_encryption_test_case_192_5(void)
9878 {
9879         return test_authenticated_encryption(&gcm_test_case_192_5);
9880 }
9881
9882 static int
9883 test_AES_GCM_auth_encryption_test_case_192_6(void)
9884 {
9885         return test_authenticated_encryption(&gcm_test_case_192_6);
9886 }
9887
9888 static int
9889 test_AES_GCM_auth_encryption_test_case_192_7(void)
9890 {
9891         return test_authenticated_encryption(&gcm_test_case_192_7);
9892 }
9893
9894 static int
9895 test_AES_GCM_auth_encryption_test_case_256_1(void)
9896 {
9897         return test_authenticated_encryption(&gcm_test_case_256_1);
9898 }
9899
9900 static int
9901 test_AES_GCM_auth_encryption_test_case_256_2(void)
9902 {
9903         return test_authenticated_encryption(&gcm_test_case_256_2);
9904 }
9905
9906 static int
9907 test_AES_GCM_auth_encryption_test_case_256_3(void)
9908 {
9909         return test_authenticated_encryption(&gcm_test_case_256_3);
9910 }
9911
9912 static int
9913 test_AES_GCM_auth_encryption_test_case_256_4(void)
9914 {
9915         return test_authenticated_encryption(&gcm_test_case_256_4);
9916 }
9917
9918 static int
9919 test_AES_GCM_auth_encryption_test_case_256_5(void)
9920 {
9921         return test_authenticated_encryption(&gcm_test_case_256_5);
9922 }
9923
9924 static int
9925 test_AES_GCM_auth_encryption_test_case_256_6(void)
9926 {
9927         return test_authenticated_encryption(&gcm_test_case_256_6);
9928 }
9929
9930 static int
9931 test_AES_GCM_auth_encryption_test_case_256_7(void)
9932 {
9933         return test_authenticated_encryption(&gcm_test_case_256_7);
9934 }
9935
9936 static int
9937 test_AES_GCM_auth_encryption_test_case_aad_1(void)
9938 {
9939         return test_authenticated_encryption(&gcm_test_case_aad_1);
9940 }
9941
9942 static int
9943 test_AES_GCM_auth_encryption_test_case_aad_2(void)
9944 {
9945         return test_authenticated_encryption(&gcm_test_case_aad_2);
9946 }
9947
9948 static int
9949 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
9950 {
9951         struct aead_test_data tdata;
9952         int res;
9953
9954         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9955         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9956         tdata.iv.data[0] += 1;
9957         res = test_authenticated_encryption(&tdata);
9958         if (res == TEST_SKIPPED)
9959                 return res;
9960         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9961         return TEST_SUCCESS;
9962 }
9963
9964 static int
9965 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
9966 {
9967         struct aead_test_data tdata;
9968         int res;
9969
9970         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9971         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9972         tdata.plaintext.data[0] += 1;
9973         res = test_authenticated_encryption(&tdata);
9974         if (res == TEST_SKIPPED)
9975                 return res;
9976         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9977         return TEST_SUCCESS;
9978 }
9979
9980 static int
9981 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
9982 {
9983         struct aead_test_data tdata;
9984         int res;
9985
9986         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9987         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9988         tdata.ciphertext.data[0] += 1;
9989         res = test_authenticated_encryption(&tdata);
9990         if (res == TEST_SKIPPED)
9991                 return res;
9992         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9993         return TEST_SUCCESS;
9994 }
9995
9996 static int
9997 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
9998 {
9999         struct aead_test_data tdata;
10000         int res;
10001
10002         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10003         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10004         tdata.aad.len += 1;
10005         res = test_authenticated_encryption(&tdata);
10006         if (res == TEST_SKIPPED)
10007                 return res;
10008         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10009         return TEST_SUCCESS;
10010 }
10011
10012 static int
10013 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
10014 {
10015         struct aead_test_data tdata;
10016         uint8_t aad[gcm_test_case_7.aad.len];
10017         int res;
10018
10019         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10020         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10021         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10022         aad[0] += 1;
10023         tdata.aad.data = aad;
10024         res = test_authenticated_encryption(&tdata);
10025         if (res == TEST_SKIPPED)
10026                 return res;
10027         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10028         return TEST_SUCCESS;
10029 }
10030
10031 static int
10032 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
10033 {
10034         struct aead_test_data tdata;
10035         int res;
10036
10037         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10038         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10039         tdata.auth_tag.data[0] += 1;
10040         res = test_authenticated_encryption(&tdata);
10041         if (res == TEST_SKIPPED)
10042                 return res;
10043         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10044         return TEST_SUCCESS;
10045 }
10046
10047 static int
10048 test_authenticated_decryption(const struct aead_test_data *tdata)
10049 {
10050         struct crypto_testsuite_params *ts_params = &testsuite_params;
10051         struct crypto_unittest_params *ut_params = &unittest_params;
10052
10053         int retval;
10054         uint8_t *plaintext;
10055         uint32_t i;
10056         struct rte_cryptodev_info dev_info;
10057
10058         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10059         uint64_t feat_flags = dev_info.feature_flags;
10060
10061         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10062                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10063                 printf("Device doesn't support RAW data-path APIs.\n");
10064                 return TEST_SKIPPED;
10065         }
10066
10067         /* Verify the capabilities */
10068         struct rte_cryptodev_sym_capability_idx cap_idx;
10069         const struct rte_cryptodev_symmetric_capability *capability;
10070         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10071         cap_idx.algo.aead = tdata->algo;
10072         capability = rte_cryptodev_sym_capability_get(
10073                         ts_params->valid_devs[0], &cap_idx);
10074         if (capability == NULL)
10075                 return TEST_SKIPPED;
10076         if (rte_cryptodev_sym_capability_check_aead(
10077                         capability, tdata->key.len, tdata->auth_tag.len,
10078                         tdata->aad.len, tdata->iv.len))
10079                 return TEST_SKIPPED;
10080
10081         /* Create AEAD session */
10082         retval = create_aead_session(ts_params->valid_devs[0],
10083                         tdata->algo,
10084                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10085                         tdata->key.data, tdata->key.len,
10086                         tdata->aad.len, tdata->auth_tag.len,
10087                         tdata->iv.len);
10088         if (retval < 0)
10089                 return retval;
10090
10091         /* alloc mbuf and set payload */
10092         if (tdata->aad.len > MBUF_SIZE) {
10093                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10094                 /* Populate full size of add data */
10095                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
10096                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
10097         } else
10098                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10099
10100         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10101                         rte_pktmbuf_tailroom(ut_params->ibuf));
10102
10103         /* Create AEAD operation */
10104         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10105         if (retval < 0)
10106                 return retval;
10107
10108         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10109
10110         ut_params->op->sym->m_src = ut_params->ibuf;
10111
10112         /* Process crypto operation */
10113         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10114                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
10115         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10116                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10117                                 ut_params->op, 0, 0, 0, 0);
10118         else
10119                 TEST_ASSERT_NOT_NULL(
10120                         process_crypto_request(ts_params->valid_devs[0],
10121                         ut_params->op), "failed to process sym crypto op");
10122
10123         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10124                         "crypto op processing failed");
10125
10126         if (ut_params->op->sym->m_dst)
10127                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
10128                                 uint8_t *);
10129         else
10130                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
10131                                 uint8_t *,
10132                                 ut_params->op->sym->cipher.data.offset);
10133
10134         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10135
10136         /* Validate obuf */
10137         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10138                         plaintext,
10139                         tdata->plaintext.data,
10140                         tdata->plaintext.len,
10141                         "Plaintext data not as expected");
10142
10143         TEST_ASSERT_EQUAL(ut_params->op->status,
10144                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10145                         "Authentication failed");
10146
10147         return 0;
10148 }
10149
10150 static int
10151 test_AES_GCM_authenticated_decryption_test_case_1(void)
10152 {
10153         return test_authenticated_decryption(&gcm_test_case_1);
10154 }
10155
10156 static int
10157 test_AES_GCM_authenticated_decryption_test_case_2(void)
10158 {
10159         return test_authenticated_decryption(&gcm_test_case_2);
10160 }
10161
10162 static int
10163 test_AES_GCM_authenticated_decryption_test_case_3(void)
10164 {
10165         return test_authenticated_decryption(&gcm_test_case_3);
10166 }
10167
10168 static int
10169 test_AES_GCM_authenticated_decryption_test_case_4(void)
10170 {
10171         return test_authenticated_decryption(&gcm_test_case_4);
10172 }
10173
10174 static int
10175 test_AES_GCM_authenticated_decryption_test_case_5(void)
10176 {
10177         return test_authenticated_decryption(&gcm_test_case_5);
10178 }
10179
10180 static int
10181 test_AES_GCM_authenticated_decryption_test_case_6(void)
10182 {
10183         return test_authenticated_decryption(&gcm_test_case_6);
10184 }
10185
10186 static int
10187 test_AES_GCM_authenticated_decryption_test_case_7(void)
10188 {
10189         return test_authenticated_decryption(&gcm_test_case_7);
10190 }
10191
10192 static int
10193 test_AES_GCM_authenticated_decryption_test_case_8(void)
10194 {
10195         return test_authenticated_decryption(&gcm_test_case_8);
10196 }
10197
10198 static int
10199 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
10200 {
10201         return test_authenticated_decryption(&gcm_J0_test_case_1);
10202 }
10203
10204 static int
10205 test_AES_GCM_auth_decryption_test_case_192_1(void)
10206 {
10207         return test_authenticated_decryption(&gcm_test_case_192_1);
10208 }
10209
10210 static int
10211 test_AES_GCM_auth_decryption_test_case_192_2(void)
10212 {
10213         return test_authenticated_decryption(&gcm_test_case_192_2);
10214 }
10215
10216 static int
10217 test_AES_GCM_auth_decryption_test_case_192_3(void)
10218 {
10219         return test_authenticated_decryption(&gcm_test_case_192_3);
10220 }
10221
10222 static int
10223 test_AES_GCM_auth_decryption_test_case_192_4(void)
10224 {
10225         return test_authenticated_decryption(&gcm_test_case_192_4);
10226 }
10227
10228 static int
10229 test_AES_GCM_auth_decryption_test_case_192_5(void)
10230 {
10231         return test_authenticated_decryption(&gcm_test_case_192_5);
10232 }
10233
10234 static int
10235 test_AES_GCM_auth_decryption_test_case_192_6(void)
10236 {
10237         return test_authenticated_decryption(&gcm_test_case_192_6);
10238 }
10239
10240 static int
10241 test_AES_GCM_auth_decryption_test_case_192_7(void)
10242 {
10243         return test_authenticated_decryption(&gcm_test_case_192_7);
10244 }
10245
10246 static int
10247 test_AES_GCM_auth_decryption_test_case_256_1(void)
10248 {
10249         return test_authenticated_decryption(&gcm_test_case_256_1);
10250 }
10251
10252 static int
10253 test_AES_GCM_auth_decryption_test_case_256_2(void)
10254 {
10255         return test_authenticated_decryption(&gcm_test_case_256_2);
10256 }
10257
10258 static int
10259 test_AES_GCM_auth_decryption_test_case_256_3(void)
10260 {
10261         return test_authenticated_decryption(&gcm_test_case_256_3);
10262 }
10263
10264 static int
10265 test_AES_GCM_auth_decryption_test_case_256_4(void)
10266 {
10267         return test_authenticated_decryption(&gcm_test_case_256_4);
10268 }
10269
10270 static int
10271 test_AES_GCM_auth_decryption_test_case_256_5(void)
10272 {
10273         return test_authenticated_decryption(&gcm_test_case_256_5);
10274 }
10275
10276 static int
10277 test_AES_GCM_auth_decryption_test_case_256_6(void)
10278 {
10279         return test_authenticated_decryption(&gcm_test_case_256_6);
10280 }
10281
10282 static int
10283 test_AES_GCM_auth_decryption_test_case_256_7(void)
10284 {
10285         return test_authenticated_decryption(&gcm_test_case_256_7);
10286 }
10287
10288 static int
10289 test_AES_GCM_auth_decryption_test_case_aad_1(void)
10290 {
10291         return test_authenticated_decryption(&gcm_test_case_aad_1);
10292 }
10293
10294 static int
10295 test_AES_GCM_auth_decryption_test_case_aad_2(void)
10296 {
10297         return test_authenticated_decryption(&gcm_test_case_aad_2);
10298 }
10299
10300 static int
10301 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
10302 {
10303         struct aead_test_data tdata;
10304         int res;
10305
10306         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10307         tdata.iv.data[0] += 1;
10308         res = test_authenticated_decryption(&tdata);
10309         if (res == TEST_SKIPPED)
10310                 return res;
10311         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10312         return TEST_SUCCESS;
10313 }
10314
10315 static int
10316 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
10317 {
10318         struct aead_test_data tdata;
10319         int res;
10320
10321         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10322         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10323         tdata.plaintext.data[0] += 1;
10324         res = test_authenticated_decryption(&tdata);
10325         if (res == TEST_SKIPPED)
10326                 return res;
10327         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10328         return TEST_SUCCESS;
10329 }
10330
10331 static int
10332 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
10333 {
10334         struct aead_test_data tdata;
10335         int res;
10336
10337         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10338         tdata.ciphertext.data[0] += 1;
10339         res = test_authenticated_decryption(&tdata);
10340         if (res == TEST_SKIPPED)
10341                 return res;
10342         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10343         return TEST_SUCCESS;
10344 }
10345
10346 static int
10347 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
10348 {
10349         struct aead_test_data tdata;
10350         int res;
10351
10352         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10353         tdata.aad.len += 1;
10354         res = test_authenticated_decryption(&tdata);
10355         if (res == TEST_SKIPPED)
10356                 return res;
10357         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10358         return TEST_SUCCESS;
10359 }
10360
10361 static int
10362 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
10363 {
10364         struct aead_test_data tdata;
10365         uint8_t aad[gcm_test_case_7.aad.len];
10366         int res;
10367
10368         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10369         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10370         aad[0] += 1;
10371         tdata.aad.data = aad;
10372         res = test_authenticated_decryption(&tdata);
10373         if (res == TEST_SKIPPED)
10374                 return res;
10375         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10376         return TEST_SUCCESS;
10377 }
10378
10379 static int
10380 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
10381 {
10382         struct aead_test_data tdata;
10383         int res;
10384
10385         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10386         tdata.auth_tag.data[0] += 1;
10387         res = test_authenticated_decryption(&tdata);
10388         if (res == TEST_SKIPPED)
10389                 return res;
10390         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
10391         return TEST_SUCCESS;
10392 }
10393
10394 static int
10395 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
10396 {
10397         struct crypto_testsuite_params *ts_params = &testsuite_params;
10398         struct crypto_unittest_params *ut_params = &unittest_params;
10399
10400         int retval;
10401         uint8_t *ciphertext, *auth_tag;
10402         uint16_t plaintext_pad_len;
10403
10404         /* Verify the capabilities */
10405         struct rte_cryptodev_sym_capability_idx cap_idx;
10406         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10407         cap_idx.algo.aead = tdata->algo;
10408         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10409                         &cap_idx) == NULL)
10410                 return TEST_SKIPPED;
10411
10412         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10413                 return TEST_SKIPPED;
10414
10415         /* not supported with CPU crypto */
10416         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10417                 return TEST_SKIPPED;
10418
10419         /* Create AEAD session */
10420         retval = create_aead_session(ts_params->valid_devs[0],
10421                         tdata->algo,
10422                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10423                         tdata->key.data, tdata->key.len,
10424                         tdata->aad.len, tdata->auth_tag.len,
10425                         tdata->iv.len);
10426         if (retval < 0)
10427                 return retval;
10428
10429         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10430         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10431
10432         /* clear mbuf payload */
10433         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10434                         rte_pktmbuf_tailroom(ut_params->ibuf));
10435         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10436                         rte_pktmbuf_tailroom(ut_params->obuf));
10437
10438         /* Create AEAD operation */
10439         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10440         if (retval < 0)
10441                 return retval;
10442
10443         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10444
10445         ut_params->op->sym->m_src = ut_params->ibuf;
10446         ut_params->op->sym->m_dst = ut_params->obuf;
10447
10448         /* Process crypto operation */
10449         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10450                         ut_params->op), "failed to process sym crypto op");
10451
10452         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10453                         "crypto op processing failed");
10454
10455         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10456
10457         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10458                         ut_params->op->sym->cipher.data.offset);
10459         auth_tag = ciphertext + plaintext_pad_len;
10460
10461         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10462         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10463
10464         /* Validate obuf */
10465         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10466                         ciphertext,
10467                         tdata->ciphertext.data,
10468                         tdata->ciphertext.len,
10469                         "Ciphertext data not as expected");
10470
10471         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10472                         auth_tag,
10473                         tdata->auth_tag.data,
10474                         tdata->auth_tag.len,
10475                         "Generated auth tag not as expected");
10476
10477         return 0;
10478
10479 }
10480
10481 static int
10482 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10483 {
10484         return test_authenticated_encryption_oop(&gcm_test_case_5);
10485 }
10486
10487 static int
10488 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10489 {
10490         struct crypto_testsuite_params *ts_params = &testsuite_params;
10491         struct crypto_unittest_params *ut_params = &unittest_params;
10492
10493         int retval;
10494         uint8_t *plaintext;
10495
10496         /* Verify the capabilities */
10497         struct rte_cryptodev_sym_capability_idx cap_idx;
10498         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10499         cap_idx.algo.aead = tdata->algo;
10500         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10501                         &cap_idx) == NULL)
10502                 return TEST_SKIPPED;
10503
10504         /* not supported with CPU crypto and raw data-path APIs*/
10505         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10506                         global_api_test_type == CRYPTODEV_RAW_API_TEST)
10507                 return TEST_SKIPPED;
10508
10509         /* Create AEAD session */
10510         retval = create_aead_session(ts_params->valid_devs[0],
10511                         tdata->algo,
10512                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10513                         tdata->key.data, tdata->key.len,
10514                         tdata->aad.len, tdata->auth_tag.len,
10515                         tdata->iv.len);
10516         if (retval < 0)
10517                 return retval;
10518
10519         /* alloc mbuf and set payload */
10520         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10521         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10522
10523         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10524                         rte_pktmbuf_tailroom(ut_params->ibuf));
10525         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10526                         rte_pktmbuf_tailroom(ut_params->obuf));
10527
10528         /* Create AEAD operation */
10529         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10530         if (retval < 0)
10531                 return retval;
10532
10533         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10534
10535         ut_params->op->sym->m_src = ut_params->ibuf;
10536         ut_params->op->sym->m_dst = ut_params->obuf;
10537
10538         /* Process crypto operation */
10539         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10540                         ut_params->op), "failed to process sym crypto op");
10541
10542         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10543                         "crypto op processing failed");
10544
10545         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10546                         ut_params->op->sym->cipher.data.offset);
10547
10548         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10549
10550         /* Validate obuf */
10551         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10552                         plaintext,
10553                         tdata->plaintext.data,
10554                         tdata->plaintext.len,
10555                         "Plaintext data not as expected");
10556
10557         TEST_ASSERT_EQUAL(ut_params->op->status,
10558                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10559                         "Authentication failed");
10560         return 0;
10561 }
10562
10563 static int
10564 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10565 {
10566         return test_authenticated_decryption_oop(&gcm_test_case_5);
10567 }
10568
10569 static int
10570 test_authenticated_encryption_sessionless(
10571                 const struct aead_test_data *tdata)
10572 {
10573         struct crypto_testsuite_params *ts_params = &testsuite_params;
10574         struct crypto_unittest_params *ut_params = &unittest_params;
10575
10576         int retval;
10577         uint8_t *ciphertext, *auth_tag;
10578         uint16_t plaintext_pad_len;
10579         uint8_t key[tdata->key.len + 1];
10580         struct rte_cryptodev_info dev_info;
10581
10582         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10583         uint64_t feat_flags = dev_info.feature_flags;
10584
10585         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10586                 printf("Device doesn't support Sessionless ops.\n");
10587                 return TEST_SKIPPED;
10588         }
10589
10590         /* not supported with CPU crypto */
10591         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10592                 return TEST_SKIPPED;
10593
10594         /* Verify the capabilities */
10595         struct rte_cryptodev_sym_capability_idx cap_idx;
10596         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10597         cap_idx.algo.aead = tdata->algo;
10598         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10599                         &cap_idx) == NULL)
10600                 return TEST_SKIPPED;
10601
10602         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10603
10604         /* clear mbuf payload */
10605         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10606                         rte_pktmbuf_tailroom(ut_params->ibuf));
10607
10608         /* Create AEAD operation */
10609         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10610         if (retval < 0)
10611                 return retval;
10612
10613         /* Create GCM xform */
10614         memcpy(key, tdata->key.data, tdata->key.len);
10615         retval = create_aead_xform(ut_params->op,
10616                         tdata->algo,
10617                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10618                         key, tdata->key.len,
10619                         tdata->aad.len, tdata->auth_tag.len,
10620                         tdata->iv.len);
10621         if (retval < 0)
10622                 return retval;
10623
10624         ut_params->op->sym->m_src = ut_params->ibuf;
10625
10626         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10627                         RTE_CRYPTO_OP_SESSIONLESS,
10628                         "crypto op session type not sessionless");
10629
10630         /* Process crypto operation */
10631         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10632                         ut_params->op), "failed to process sym crypto op");
10633
10634         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10635
10636         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10637                         "crypto op status not success");
10638
10639         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10640
10641         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10642                         ut_params->op->sym->cipher.data.offset);
10643         auth_tag = ciphertext + plaintext_pad_len;
10644
10645         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10646         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10647
10648         /* Validate obuf */
10649         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10650                         ciphertext,
10651                         tdata->ciphertext.data,
10652                         tdata->ciphertext.len,
10653                         "Ciphertext data not as expected");
10654
10655         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10656                         auth_tag,
10657                         tdata->auth_tag.data,
10658                         tdata->auth_tag.len,
10659                         "Generated auth tag not as expected");
10660
10661         return 0;
10662
10663 }
10664
10665 static int
10666 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10667 {
10668         return test_authenticated_encryption_sessionless(
10669                         &gcm_test_case_5);
10670 }
10671
10672 static int
10673 test_authenticated_decryption_sessionless(
10674                 const struct aead_test_data *tdata)
10675 {
10676         struct crypto_testsuite_params *ts_params = &testsuite_params;
10677         struct crypto_unittest_params *ut_params = &unittest_params;
10678
10679         int retval;
10680         uint8_t *plaintext;
10681         uint8_t key[tdata->key.len + 1];
10682         struct rte_cryptodev_info dev_info;
10683
10684         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10685         uint64_t feat_flags = dev_info.feature_flags;
10686
10687         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10688                 printf("Device doesn't support Sessionless ops.\n");
10689                 return TEST_SKIPPED;
10690         }
10691
10692         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10693                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10694                 printf("Device doesn't support RAW data-path APIs.\n");
10695                 return TEST_SKIPPED;
10696         }
10697
10698         /* not supported with CPU crypto */
10699         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10700                 return TEST_SKIPPED;
10701
10702         /* Verify the capabilities */
10703         struct rte_cryptodev_sym_capability_idx cap_idx;
10704         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10705         cap_idx.algo.aead = tdata->algo;
10706         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10707                         &cap_idx) == NULL)
10708                 return TEST_SKIPPED;
10709
10710         /* alloc mbuf and set payload */
10711         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10712
10713         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10714                         rte_pktmbuf_tailroom(ut_params->ibuf));
10715
10716         /* Create AEAD operation */
10717         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10718         if (retval < 0)
10719                 return retval;
10720
10721         /* Create AEAD xform */
10722         memcpy(key, tdata->key.data, tdata->key.len);
10723         retval = create_aead_xform(ut_params->op,
10724                         tdata->algo,
10725                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10726                         key, tdata->key.len,
10727                         tdata->aad.len, tdata->auth_tag.len,
10728                         tdata->iv.len);
10729         if (retval < 0)
10730                 return retval;
10731
10732         ut_params->op->sym->m_src = ut_params->ibuf;
10733
10734         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10735                         RTE_CRYPTO_OP_SESSIONLESS,
10736                         "crypto op session type not sessionless");
10737
10738         /* Process crypto operation */
10739         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10740                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10741                                 ut_params->op, 0, 0, 0, 0);
10742         else
10743                 TEST_ASSERT_NOT_NULL(process_crypto_request(
10744                         ts_params->valid_devs[0], ut_params->op),
10745                                 "failed to process sym crypto op");
10746
10747         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10748
10749         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10750                         "crypto op status not success");
10751
10752         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10753                         ut_params->op->sym->cipher.data.offset);
10754
10755         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10756
10757         /* Validate obuf */
10758         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10759                         plaintext,
10760                         tdata->plaintext.data,
10761                         tdata->plaintext.len,
10762                         "Plaintext data not as expected");
10763
10764         TEST_ASSERT_EQUAL(ut_params->op->status,
10765                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10766                         "Authentication failed");
10767         return 0;
10768 }
10769
10770 static int
10771 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
10772 {
10773         return test_authenticated_decryption_sessionless(
10774                         &gcm_test_case_5);
10775 }
10776
10777 static int
10778 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
10779 {
10780         return test_authenticated_encryption(&ccm_test_case_128_1);
10781 }
10782
10783 static int
10784 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
10785 {
10786         return test_authenticated_encryption(&ccm_test_case_128_2);
10787 }
10788
10789 static int
10790 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
10791 {
10792         return test_authenticated_encryption(&ccm_test_case_128_3);
10793 }
10794
10795 static int
10796 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
10797 {
10798         return test_authenticated_decryption(&ccm_test_case_128_1);
10799 }
10800
10801 static int
10802 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
10803 {
10804         return test_authenticated_decryption(&ccm_test_case_128_2);
10805 }
10806
10807 static int
10808 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10809 {
10810         return test_authenticated_decryption(&ccm_test_case_128_3);
10811 }
10812
10813 static int
10814 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10815 {
10816         return test_authenticated_encryption(&ccm_test_case_192_1);
10817 }
10818
10819 static int
10820 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10821 {
10822         return test_authenticated_encryption(&ccm_test_case_192_2);
10823 }
10824
10825 static int
10826 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10827 {
10828         return test_authenticated_encryption(&ccm_test_case_192_3);
10829 }
10830
10831 static int
10832 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10833 {
10834         return test_authenticated_decryption(&ccm_test_case_192_1);
10835 }
10836
10837 static int
10838 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10839 {
10840         return test_authenticated_decryption(&ccm_test_case_192_2);
10841 }
10842
10843 static int
10844 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10845 {
10846         return test_authenticated_decryption(&ccm_test_case_192_3);
10847 }
10848
10849 static int
10850 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
10851 {
10852         return test_authenticated_encryption(&ccm_test_case_256_1);
10853 }
10854
10855 static int
10856 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
10857 {
10858         return test_authenticated_encryption(&ccm_test_case_256_2);
10859 }
10860
10861 static int
10862 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
10863 {
10864         return test_authenticated_encryption(&ccm_test_case_256_3);
10865 }
10866
10867 static int
10868 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
10869 {
10870         return test_authenticated_decryption(&ccm_test_case_256_1);
10871 }
10872
10873 static int
10874 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
10875 {
10876         return test_authenticated_decryption(&ccm_test_case_256_2);
10877 }
10878
10879 static int
10880 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
10881 {
10882         return test_authenticated_decryption(&ccm_test_case_256_3);
10883 }
10884
10885 static int
10886 test_stats(void)
10887 {
10888         struct crypto_testsuite_params *ts_params = &testsuite_params;
10889         struct rte_cryptodev_stats stats;
10890
10891         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10892                 return TEST_SKIPPED;
10893
10894         /* Verify the capabilities */
10895         struct rte_cryptodev_sym_capability_idx cap_idx;
10896         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10897         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
10898         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10899                         &cap_idx) == NULL)
10900                 return TEST_SKIPPED;
10901         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10902         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10903         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10904                         &cap_idx) == NULL)
10905                 return TEST_SKIPPED;
10906
10907         if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
10908                         == -ENOTSUP)
10909                 return TEST_SKIPPED;
10910
10911         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10912         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
10913                         &stats) == -ENODEV),
10914                 "rte_cryptodev_stats_get invalid dev failed");
10915         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
10916                 "rte_cryptodev_stats_get invalid Param failed");
10917
10918         /* Test expected values */
10919         test_AES_CBC_HMAC_SHA1_encrypt_digest();
10920         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10921                         &stats),
10922                 "rte_cryptodev_stats_get failed");
10923         TEST_ASSERT((stats.enqueued_count == 1),
10924                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10925         TEST_ASSERT((stats.dequeued_count == 1),
10926                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10927         TEST_ASSERT((stats.enqueue_err_count == 0),
10928                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10929         TEST_ASSERT((stats.dequeue_err_count == 0),
10930                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10931
10932         /* invalid device but should ignore and not reset device stats*/
10933         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
10934         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10935                         &stats),
10936                 "rte_cryptodev_stats_get failed");
10937         TEST_ASSERT((stats.enqueued_count == 1),
10938                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10939
10940         /* check that a valid reset clears stats */
10941         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10942         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10943                         &stats),
10944                                           "rte_cryptodev_stats_get failed");
10945         TEST_ASSERT((stats.enqueued_count == 0),
10946                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10947         TEST_ASSERT((stats.dequeued_count == 0),
10948                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10949
10950         return TEST_SUCCESS;
10951 }
10952
10953 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
10954                                    struct crypto_unittest_params *ut_params,
10955                                    enum rte_crypto_auth_operation op,
10956                                    const struct HMAC_MD5_vector *test_case)
10957 {
10958         uint8_t key[64];
10959
10960         memcpy(key, test_case->key.data, test_case->key.len);
10961
10962         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10963         ut_params->auth_xform.next = NULL;
10964         ut_params->auth_xform.auth.op = op;
10965
10966         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
10967
10968         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
10969         ut_params->auth_xform.auth.key.length = test_case->key.len;
10970         ut_params->auth_xform.auth.key.data = key;
10971
10972         ut_params->sess = rte_cryptodev_sym_session_create(
10973                         ts_params->session_mpool);
10974
10975         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10976                         ut_params->sess, &ut_params->auth_xform,
10977                         ts_params->session_priv_mpool);
10978
10979         if (ut_params->sess == NULL)
10980                 return TEST_FAILED;
10981
10982         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10983
10984         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10985                         rte_pktmbuf_tailroom(ut_params->ibuf));
10986
10987         return 0;
10988 }
10989
10990 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
10991                               const struct HMAC_MD5_vector *test_case,
10992                               uint8_t **plaintext)
10993 {
10994         uint16_t plaintext_pad_len;
10995
10996         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10997
10998         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10999                                 16);
11000
11001         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11002                         plaintext_pad_len);
11003         memcpy(*plaintext, test_case->plaintext.data,
11004                         test_case->plaintext.len);
11005
11006         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11007                         ut_params->ibuf, MD5_DIGEST_LEN);
11008         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11009                         "no room to append digest");
11010         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11011                         ut_params->ibuf, plaintext_pad_len);
11012
11013         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11014                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
11015                            test_case->auth_tag.len);
11016         }
11017
11018         sym_op->auth.data.offset = 0;
11019         sym_op->auth.data.length = test_case->plaintext.len;
11020
11021         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11022         ut_params->op->sym->m_src = ut_params->ibuf;
11023
11024         return 0;
11025 }
11026
11027 static int
11028 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
11029 {
11030         uint16_t plaintext_pad_len;
11031         uint8_t *plaintext, *auth_tag;
11032
11033         struct crypto_testsuite_params *ts_params = &testsuite_params;
11034         struct crypto_unittest_params *ut_params = &unittest_params;
11035         struct rte_cryptodev_info dev_info;
11036
11037         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11038         uint64_t feat_flags = dev_info.feature_flags;
11039
11040         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11041                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11042                 printf("Device doesn't support RAW data-path APIs.\n");
11043                 return TEST_SKIPPED;
11044         }
11045
11046         /* Verify the capabilities */
11047         struct rte_cryptodev_sym_capability_idx cap_idx;
11048         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11049         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11050         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11051                         &cap_idx) == NULL)
11052                 return TEST_SKIPPED;
11053
11054         if (MD5_HMAC_create_session(ts_params, ut_params,
11055                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
11056                 return TEST_FAILED;
11057
11058         /* Generate Crypto op data structure */
11059         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11060                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11061         TEST_ASSERT_NOT_NULL(ut_params->op,
11062                         "Failed to allocate symmetric crypto operation struct");
11063
11064         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11065                                 16);
11066
11067         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11068                 return TEST_FAILED;
11069
11070         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11071                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11072                         ut_params->op);
11073         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11074                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11075                                 ut_params->op, 0, 1, 0, 0);
11076         else
11077                 TEST_ASSERT_NOT_NULL(
11078                         process_crypto_request(ts_params->valid_devs[0],
11079                                 ut_params->op),
11080                                 "failed to process sym crypto op");
11081
11082         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11083                         "crypto op processing failed");
11084
11085         if (ut_params->op->sym->m_dst) {
11086                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11087                                 uint8_t *, plaintext_pad_len);
11088         } else {
11089                 auth_tag = plaintext + plaintext_pad_len;
11090         }
11091
11092         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11093                         auth_tag,
11094                         test_case->auth_tag.data,
11095                         test_case->auth_tag.len,
11096                         "HMAC_MD5 generated tag not as expected");
11097
11098         return TEST_SUCCESS;
11099 }
11100
11101 static int
11102 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
11103 {
11104         uint8_t *plaintext;
11105
11106         struct crypto_testsuite_params *ts_params = &testsuite_params;
11107         struct crypto_unittest_params *ut_params = &unittest_params;
11108         struct rte_cryptodev_info dev_info;
11109
11110         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11111         uint64_t feat_flags = dev_info.feature_flags;
11112
11113         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11114                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11115                 printf("Device doesn't support RAW data-path APIs.\n");
11116                 return TEST_SKIPPED;
11117         }
11118
11119         /* Verify the capabilities */
11120         struct rte_cryptodev_sym_capability_idx cap_idx;
11121         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11122         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11123         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11124                         &cap_idx) == NULL)
11125                 return TEST_SKIPPED;
11126
11127         if (MD5_HMAC_create_session(ts_params, ut_params,
11128                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
11129                 return TEST_FAILED;
11130         }
11131
11132         /* Generate Crypto op data structure */
11133         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11134                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11135         TEST_ASSERT_NOT_NULL(ut_params->op,
11136                         "Failed to allocate symmetric crypto operation struct");
11137
11138         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11139                 return TEST_FAILED;
11140
11141         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11142                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11143                         ut_params->op);
11144         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11145                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11146                                 ut_params->op, 0, 1, 0, 0);
11147         else
11148                 TEST_ASSERT_NOT_NULL(
11149                         process_crypto_request(ts_params->valid_devs[0],
11150                                 ut_params->op),
11151                                 "failed to process sym crypto op");
11152
11153         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11154                         "HMAC_MD5 crypto op processing failed");
11155
11156         return TEST_SUCCESS;
11157 }
11158
11159 static int
11160 test_MD5_HMAC_generate_case_1(void)
11161 {
11162         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
11163 }
11164
11165 static int
11166 test_MD5_HMAC_verify_case_1(void)
11167 {
11168         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
11169 }
11170
11171 static int
11172 test_MD5_HMAC_generate_case_2(void)
11173 {
11174         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
11175 }
11176
11177 static int
11178 test_MD5_HMAC_verify_case_2(void)
11179 {
11180         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
11181 }
11182
11183 static int
11184 test_multi_session(void)
11185 {
11186         struct crypto_testsuite_params *ts_params = &testsuite_params;
11187         struct crypto_unittest_params *ut_params = &unittest_params;
11188
11189         struct rte_cryptodev_info dev_info;
11190         struct rte_cryptodev_sym_session **sessions;
11191
11192         uint16_t i;
11193
11194         /* Verify the capabilities */
11195         struct rte_cryptodev_sym_capability_idx cap_idx;
11196         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11197         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11198         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11199                         &cap_idx) == NULL)
11200                 return TEST_SKIPPED;
11201         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11202         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11203         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11204                         &cap_idx) == NULL)
11205                 return TEST_SKIPPED;
11206
11207         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
11208                         aes_cbc_key, hmac_sha512_key);
11209
11210
11211         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11212
11213         sessions = rte_malloc(NULL,
11214                         sizeof(struct rte_cryptodev_sym_session *) *
11215                         (MAX_NB_SESSIONS + 1), 0);
11216
11217         /* Create multiple crypto sessions*/
11218         for (i = 0; i < MAX_NB_SESSIONS; i++) {
11219
11220                 sessions[i] = rte_cryptodev_sym_session_create(
11221                                 ts_params->session_mpool);
11222
11223                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11224                                 sessions[i], &ut_params->auth_xform,
11225                                 ts_params->session_priv_mpool);
11226                 TEST_ASSERT_NOT_NULL(sessions[i],
11227                                 "Session creation failed at session number %u",
11228                                 i);
11229
11230                 /* Attempt to send a request on each session */
11231                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
11232                         sessions[i],
11233                         ut_params,
11234                         ts_params,
11235                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
11236                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
11237                         aes_cbc_iv),
11238                         "Failed to perform decrypt on request number %u.", i);
11239                 /* free crypto operation structure */
11240                 if (ut_params->op)
11241                         rte_crypto_op_free(ut_params->op);
11242
11243                 /*
11244                  * free mbuf - both obuf and ibuf are usually the same,
11245                  * so check if they point at the same address is necessary,
11246                  * to avoid freeing the mbuf twice.
11247                  */
11248                 if (ut_params->obuf) {
11249                         rte_pktmbuf_free(ut_params->obuf);
11250                         if (ut_params->ibuf == ut_params->obuf)
11251                                 ut_params->ibuf = 0;
11252                         ut_params->obuf = 0;
11253                 }
11254                 if (ut_params->ibuf) {
11255                         rte_pktmbuf_free(ut_params->ibuf);
11256                         ut_params->ibuf = 0;
11257                 }
11258         }
11259
11260         sessions[i] = NULL;
11261         /* Next session create should fail */
11262         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11263                         sessions[i], &ut_params->auth_xform,
11264                         ts_params->session_priv_mpool);
11265         TEST_ASSERT_NULL(sessions[i],
11266                         "Session creation succeeded unexpectedly!");
11267
11268         for (i = 0; i < MAX_NB_SESSIONS; i++) {
11269                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11270                                 sessions[i]);
11271                 rte_cryptodev_sym_session_free(sessions[i]);
11272         }
11273
11274         rte_free(sessions);
11275
11276         return TEST_SUCCESS;
11277 }
11278
11279 struct multi_session_params {
11280         struct crypto_unittest_params ut_params;
11281         uint8_t *cipher_key;
11282         uint8_t *hmac_key;
11283         const uint8_t *cipher;
11284         const uint8_t *digest;
11285         uint8_t *iv;
11286 };
11287
11288 #define MB_SESSION_NUMBER 3
11289
11290 static int
11291 test_multi_session_random_usage(void)
11292 {
11293         struct crypto_testsuite_params *ts_params = &testsuite_params;
11294         struct rte_cryptodev_info dev_info;
11295         struct rte_cryptodev_sym_session **sessions;
11296         uint32_t i, j;
11297         struct multi_session_params ut_paramz[] = {
11298
11299                 {
11300                         .cipher_key = ms_aes_cbc_key0,
11301                         .hmac_key = ms_hmac_key0,
11302                         .cipher = ms_aes_cbc_cipher0,
11303                         .digest = ms_hmac_digest0,
11304                         .iv = ms_aes_cbc_iv0
11305                 },
11306                 {
11307                         .cipher_key = ms_aes_cbc_key1,
11308                         .hmac_key = ms_hmac_key1,
11309                         .cipher = ms_aes_cbc_cipher1,
11310                         .digest = ms_hmac_digest1,
11311                         .iv = ms_aes_cbc_iv1
11312                 },
11313                 {
11314                         .cipher_key = ms_aes_cbc_key2,
11315                         .hmac_key = ms_hmac_key2,
11316                         .cipher = ms_aes_cbc_cipher2,
11317                         .digest = ms_hmac_digest2,
11318                         .iv = ms_aes_cbc_iv2
11319                 },
11320
11321         };
11322
11323         /* Verify the capabilities */
11324         struct rte_cryptodev_sym_capability_idx cap_idx;
11325         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11326         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11327         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11328                         &cap_idx) == NULL)
11329                 return TEST_SKIPPED;
11330         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11331         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11332         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11333                         &cap_idx) == NULL)
11334                 return TEST_SKIPPED;
11335
11336         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11337
11338         sessions = rte_malloc(NULL,
11339                         (sizeof(struct rte_cryptodev_sym_session *)
11340                                         * MAX_NB_SESSIONS) + 1, 0);
11341
11342         for (i = 0; i < MB_SESSION_NUMBER; i++) {
11343                 sessions[i] = rte_cryptodev_sym_session_create(
11344                                 ts_params->session_mpool);
11345
11346                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
11347                                 sizeof(struct crypto_unittest_params));
11348
11349                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
11350                                 &ut_paramz[i].ut_params,
11351                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
11352
11353                 /* Create multiple crypto sessions*/
11354                 rte_cryptodev_sym_session_init(
11355                                 ts_params->valid_devs[0],
11356                                 sessions[i],
11357                                 &ut_paramz[i].ut_params.auth_xform,
11358                                 ts_params->session_priv_mpool);
11359
11360                 TEST_ASSERT_NOT_NULL(sessions[i],
11361                                 "Session creation failed at session number %u",
11362                                 i);
11363
11364         }
11365
11366         srand(time(NULL));
11367         for (i = 0; i < 40000; i++) {
11368
11369                 j = rand() % MB_SESSION_NUMBER;
11370
11371                 TEST_ASSERT_SUCCESS(
11372                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
11373                                         sessions[j],
11374                                         &ut_paramz[j].ut_params,
11375                                         ts_params, ut_paramz[j].cipher,
11376                                         ut_paramz[j].digest,
11377                                         ut_paramz[j].iv),
11378                         "Failed to perform decrypt on request number %u.", i);
11379
11380                 if (ut_paramz[j].ut_params.op)
11381                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
11382
11383                 /*
11384                  * free mbuf - both obuf and ibuf are usually the same,
11385                  * so check if they point at the same address is necessary,
11386                  * to avoid freeing the mbuf twice.
11387                  */
11388                 if (ut_paramz[j].ut_params.obuf) {
11389                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
11390                         if (ut_paramz[j].ut_params.ibuf
11391                                         == ut_paramz[j].ut_params.obuf)
11392                                 ut_paramz[j].ut_params.ibuf = 0;
11393                         ut_paramz[j].ut_params.obuf = 0;
11394                 }
11395                 if (ut_paramz[j].ut_params.ibuf) {
11396                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
11397                         ut_paramz[j].ut_params.ibuf = 0;
11398                 }
11399         }
11400
11401         for (i = 0; i < MB_SESSION_NUMBER; i++) {
11402                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11403                                 sessions[i]);
11404                 rte_cryptodev_sym_session_free(sessions[i]);
11405         }
11406
11407         rte_free(sessions);
11408
11409         return TEST_SUCCESS;
11410 }
11411
11412 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
11413                         0xab, 0xab, 0xab, 0xab,
11414                         0xab, 0xab, 0xab, 0xab,
11415                         0xab, 0xab, 0xab, 0xab};
11416
11417 static int
11418 test_null_invalid_operation(void)
11419 {
11420         struct crypto_testsuite_params *ts_params = &testsuite_params;
11421         struct crypto_unittest_params *ut_params = &unittest_params;
11422         int ret;
11423
11424         /* This test is for NULL PMD only */
11425         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11426                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11427                 return TEST_SKIPPED;
11428
11429         /* Setup Cipher Parameters */
11430         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11431         ut_params->cipher_xform.next = NULL;
11432
11433         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
11434         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11435
11436         ut_params->sess = rte_cryptodev_sym_session_create(
11437                         ts_params->session_mpool);
11438
11439         /* Create Crypto session*/
11440         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11441                         ut_params->sess, &ut_params->cipher_xform,
11442                         ts_params->session_priv_mpool);
11443         TEST_ASSERT(ret < 0,
11444                         "Session creation succeeded unexpectedly");
11445
11446
11447         /* Setup HMAC Parameters */
11448         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11449         ut_params->auth_xform.next = NULL;
11450
11451         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
11452         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11453
11454         ut_params->sess = rte_cryptodev_sym_session_create(
11455                         ts_params->session_mpool);
11456
11457         /* Create Crypto session*/
11458         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11459                         ut_params->sess, &ut_params->auth_xform,
11460                         ts_params->session_priv_mpool);
11461         TEST_ASSERT(ret < 0,
11462                         "Session creation succeeded unexpectedly");
11463
11464         return TEST_SUCCESS;
11465 }
11466
11467
11468 #define NULL_BURST_LENGTH (32)
11469
11470 static int
11471 test_null_burst_operation(void)
11472 {
11473         struct crypto_testsuite_params *ts_params = &testsuite_params;
11474         struct crypto_unittest_params *ut_params = &unittest_params;
11475
11476         unsigned i, burst_len = NULL_BURST_LENGTH;
11477
11478         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11479         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11480
11481         /* This test is for NULL PMD only */
11482         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11483                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11484                 return TEST_SKIPPED;
11485
11486         /* Setup Cipher Parameters */
11487         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11488         ut_params->cipher_xform.next = &ut_params->auth_xform;
11489
11490         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11491         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11492
11493         /* Setup HMAC Parameters */
11494         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11495         ut_params->auth_xform.next = NULL;
11496
11497         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11498         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11499
11500         ut_params->sess = rte_cryptodev_sym_session_create(
11501                         ts_params->session_mpool);
11502
11503         /* Create Crypto session*/
11504         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11505                         ut_params->sess, &ut_params->cipher_xform,
11506                         ts_params->session_priv_mpool);
11507         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11508
11509         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11510                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11511                         burst_len, "failed to generate burst of crypto ops");
11512
11513         /* Generate an operation for each mbuf in burst */
11514         for (i = 0; i < burst_len; i++) {
11515                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11516
11517                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11518
11519                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11520                                 sizeof(unsigned));
11521                 *data = i;
11522
11523                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11524
11525                 burst[i]->sym->m_src = m;
11526         }
11527
11528         /* Process crypto operation */
11529         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11530                         0, burst, burst_len),
11531                         burst_len,
11532                         "Error enqueuing burst");
11533
11534         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11535                         0, burst_dequeued, burst_len),
11536                         burst_len,
11537                         "Error dequeuing burst");
11538
11539
11540         for (i = 0; i < burst_len; i++) {
11541                 TEST_ASSERT_EQUAL(
11542                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11543                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11544                                         uint32_t *),
11545                         "data not as expected");
11546
11547                 rte_pktmbuf_free(burst[i]->sym->m_src);
11548                 rte_crypto_op_free(burst[i]);
11549         }
11550
11551         return TEST_SUCCESS;
11552 }
11553
11554 static uint16_t
11555 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11556                   uint16_t nb_ops, void *user_param)
11557 {
11558         RTE_SET_USED(dev_id);
11559         RTE_SET_USED(qp_id);
11560         RTE_SET_USED(ops);
11561         RTE_SET_USED(user_param);
11562
11563         printf("crypto enqueue callback called\n");
11564         return nb_ops;
11565 }
11566
11567 static uint16_t
11568 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11569                   uint16_t nb_ops, void *user_param)
11570 {
11571         RTE_SET_USED(dev_id);
11572         RTE_SET_USED(qp_id);
11573         RTE_SET_USED(ops);
11574         RTE_SET_USED(user_param);
11575
11576         printf("crypto dequeue callback called\n");
11577         return nb_ops;
11578 }
11579
11580 /*
11581  * Thread using enqueue/dequeue callback with RCU.
11582  */
11583 static int
11584 test_enqdeq_callback_thread(void *arg)
11585 {
11586         RTE_SET_USED(arg);
11587         /* DP thread calls rte_cryptodev_enqueue_burst()/
11588          * rte_cryptodev_dequeue_burst() and invokes callback.
11589          */
11590         test_null_burst_operation();
11591         return 0;
11592 }
11593
11594 static int
11595 test_enq_callback_setup(void)
11596 {
11597         struct crypto_testsuite_params *ts_params = &testsuite_params;
11598         struct rte_cryptodev_info dev_info;
11599         struct rte_cryptodev_qp_conf qp_conf = {
11600                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11601         };
11602
11603         struct rte_cryptodev_cb *cb;
11604         uint16_t qp_id = 0;
11605
11606         /* Stop the device in case it's started so it can be configured */
11607         rte_cryptodev_stop(ts_params->valid_devs[0]);
11608
11609         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11610
11611         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11612                         &ts_params->conf),
11613                         "Failed to configure cryptodev %u",
11614                         ts_params->valid_devs[0]);
11615
11616         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11617         qp_conf.mp_session = ts_params->session_mpool;
11618         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11619
11620         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11621                         ts_params->valid_devs[0], qp_id, &qp_conf,
11622                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11623                         "Failed test for "
11624                         "rte_cryptodev_queue_pair_setup: num_inflights "
11625                         "%u on qp %u on cryptodev %u",
11626                         qp_conf.nb_descriptors, qp_id,
11627                         ts_params->valid_devs[0]);
11628
11629         /* Test with invalid crypto device */
11630         cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11631                         qp_id, test_enq_callback, NULL);
11632         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11633                         "cryptodev %u did not fail",
11634                         qp_id, RTE_CRYPTO_MAX_DEVS);
11635
11636         /* Test with invalid queue pair */
11637         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11638                         dev_info.max_nb_queue_pairs + 1,
11639                         test_enq_callback, NULL);
11640         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11641                         "cryptodev %u did not fail",
11642                         dev_info.max_nb_queue_pairs + 1,
11643                         ts_params->valid_devs[0]);
11644
11645         /* Test with NULL callback */
11646         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11647                         qp_id, NULL, NULL);
11648         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11649                         "cryptodev %u did not fail",
11650                         qp_id, ts_params->valid_devs[0]);
11651
11652         /* Test with valid configuration */
11653         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11654                         qp_id, test_enq_callback, NULL);
11655         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11656                         "qp %u on cryptodev %u",
11657                         qp_id, ts_params->valid_devs[0]);
11658
11659         rte_cryptodev_start(ts_params->valid_devs[0]);
11660
11661         /* Launch a thread */
11662         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11663                                 rte_get_next_lcore(-1, 1, 0));
11664
11665         /* Wait until reader exited. */
11666         rte_eal_mp_wait_lcore();
11667
11668         /* Test with invalid crypto device */
11669         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11670                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11671                         "Expected call to fail as crypto device is invalid");
11672
11673         /* Test with invalid queue pair */
11674         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11675                         ts_params->valid_devs[0],
11676                         dev_info.max_nb_queue_pairs + 1, cb),
11677                         "Expected call to fail as queue pair is invalid");
11678
11679         /* Test with NULL callback */
11680         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11681                         ts_params->valid_devs[0], qp_id, NULL),
11682                         "Expected call to fail as callback is NULL");
11683
11684         /* Test with valid configuration */
11685         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11686                         ts_params->valid_devs[0], qp_id, cb),
11687                         "Failed test to remove callback on "
11688                         "qp %u on cryptodev %u",
11689                         qp_id, ts_params->valid_devs[0]);
11690
11691         return TEST_SUCCESS;
11692 }
11693
11694 static int
11695 test_deq_callback_setup(void)
11696 {
11697         struct crypto_testsuite_params *ts_params = &testsuite_params;
11698         struct rte_cryptodev_info dev_info;
11699         struct rte_cryptodev_qp_conf qp_conf = {
11700                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11701         };
11702
11703         struct rte_cryptodev_cb *cb;
11704         uint16_t qp_id = 0;
11705
11706         /* Stop the device in case it's started so it can be configured */
11707         rte_cryptodev_stop(ts_params->valid_devs[0]);
11708
11709         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11710
11711         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11712                         &ts_params->conf),
11713                         "Failed to configure cryptodev %u",
11714                         ts_params->valid_devs[0]);
11715
11716         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11717         qp_conf.mp_session = ts_params->session_mpool;
11718         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11719
11720         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11721                         ts_params->valid_devs[0], qp_id, &qp_conf,
11722                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11723                         "Failed test for "
11724                         "rte_cryptodev_queue_pair_setup: num_inflights "
11725                         "%u on qp %u on cryptodev %u",
11726                         qp_conf.nb_descriptors, qp_id,
11727                         ts_params->valid_devs[0]);
11728
11729         /* Test with invalid crypto device */
11730         cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11731                         qp_id, test_deq_callback, NULL);
11732         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11733                         "cryptodev %u did not fail",
11734                         qp_id, RTE_CRYPTO_MAX_DEVS);
11735
11736         /* Test with invalid queue pair */
11737         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11738                         dev_info.max_nb_queue_pairs + 1,
11739                         test_deq_callback, NULL);
11740         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11741                         "cryptodev %u did not fail",
11742                         dev_info.max_nb_queue_pairs + 1,
11743                         ts_params->valid_devs[0]);
11744
11745         /* Test with NULL callback */
11746         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11747                         qp_id, NULL, NULL);
11748         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11749                         "cryptodev %u did not fail",
11750                         qp_id, ts_params->valid_devs[0]);
11751
11752         /* Test with valid configuration */
11753         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11754                         qp_id, test_deq_callback, NULL);
11755         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11756                         "qp %u on cryptodev %u",
11757                         qp_id, ts_params->valid_devs[0]);
11758
11759         rte_cryptodev_start(ts_params->valid_devs[0]);
11760
11761         /* Launch a thread */
11762         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11763                                 rte_get_next_lcore(-1, 1, 0));
11764
11765         /* Wait until reader exited. */
11766         rte_eal_mp_wait_lcore();
11767
11768         /* Test with invalid crypto device */
11769         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11770                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11771                         "Expected call to fail as crypto device is invalid");
11772
11773         /* Test with invalid queue pair */
11774         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11775                         ts_params->valid_devs[0],
11776                         dev_info.max_nb_queue_pairs + 1, cb),
11777                         "Expected call to fail as queue pair is invalid");
11778
11779         /* Test with NULL callback */
11780         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11781                         ts_params->valid_devs[0], qp_id, NULL),
11782                         "Expected call to fail as callback is NULL");
11783
11784         /* Test with valid configuration */
11785         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
11786                         ts_params->valid_devs[0], qp_id, cb),
11787                         "Failed test to remove callback on "
11788                         "qp %u on cryptodev %u",
11789                         qp_id, ts_params->valid_devs[0]);
11790
11791         return TEST_SUCCESS;
11792 }
11793
11794 static void
11795 generate_gmac_large_plaintext(uint8_t *data)
11796 {
11797         uint16_t i;
11798
11799         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
11800                 memcpy(&data[i], &data[0], 32);
11801 }
11802
11803 static int
11804 create_gmac_operation(enum rte_crypto_auth_operation op,
11805                 const struct gmac_test_data *tdata)
11806 {
11807         struct crypto_testsuite_params *ts_params = &testsuite_params;
11808         struct crypto_unittest_params *ut_params = &unittest_params;
11809         struct rte_crypto_sym_op *sym_op;
11810
11811         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11812
11813         /* Generate Crypto op data structure */
11814         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11815                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11816         TEST_ASSERT_NOT_NULL(ut_params->op,
11817                         "Failed to allocate symmetric crypto operation struct");
11818
11819         sym_op = ut_params->op->sym;
11820
11821         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11822                         ut_params->ibuf, tdata->gmac_tag.len);
11823         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11824                         "no room to append digest");
11825
11826         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11827                         ut_params->ibuf, plaintext_pad_len);
11828
11829         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11830                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11831                                 tdata->gmac_tag.len);
11832                 debug_hexdump(stdout, "digest:",
11833                                 sym_op->auth.digest.data,
11834                                 tdata->gmac_tag.len);
11835         }
11836
11837         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11838                         uint8_t *, IV_OFFSET);
11839
11840         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11841
11842         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11843
11844         sym_op->cipher.data.length = 0;
11845         sym_op->cipher.data.offset = 0;
11846
11847         sym_op->auth.data.offset = 0;
11848         sym_op->auth.data.length = tdata->plaintext.len;
11849
11850         return 0;
11851 }
11852
11853 static int
11854 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
11855                 const struct gmac_test_data *tdata,
11856                 void *digest_mem, uint64_t digest_phys)
11857 {
11858         struct crypto_testsuite_params *ts_params = &testsuite_params;
11859         struct crypto_unittest_params *ut_params = &unittest_params;
11860         struct rte_crypto_sym_op *sym_op;
11861
11862         /* Generate Crypto op data structure */
11863         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11864                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11865         TEST_ASSERT_NOT_NULL(ut_params->op,
11866                         "Failed to allocate symmetric crypto operation struct");
11867
11868         sym_op = ut_params->op->sym;
11869
11870         sym_op->auth.digest.data = digest_mem;
11871         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11872                         "no room to append digest");
11873
11874         sym_op->auth.digest.phys_addr = digest_phys;
11875
11876         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11877                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11878                                 tdata->gmac_tag.len);
11879                 debug_hexdump(stdout, "digest:",
11880                                 sym_op->auth.digest.data,
11881                                 tdata->gmac_tag.len);
11882         }
11883
11884         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11885                         uint8_t *, IV_OFFSET);
11886
11887         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11888
11889         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11890
11891         sym_op->cipher.data.length = 0;
11892         sym_op->cipher.data.offset = 0;
11893
11894         sym_op->auth.data.offset = 0;
11895         sym_op->auth.data.length = tdata->plaintext.len;
11896
11897         return 0;
11898 }
11899
11900 static int create_gmac_session(uint8_t dev_id,
11901                 const struct gmac_test_data *tdata,
11902                 enum rte_crypto_auth_operation auth_op)
11903 {
11904         uint8_t auth_key[tdata->key.len];
11905
11906         struct crypto_testsuite_params *ts_params = &testsuite_params;
11907         struct crypto_unittest_params *ut_params = &unittest_params;
11908
11909         memcpy(auth_key, tdata->key.data, tdata->key.len);
11910
11911         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11912         ut_params->auth_xform.next = NULL;
11913
11914         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
11915         ut_params->auth_xform.auth.op = auth_op;
11916         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
11917         ut_params->auth_xform.auth.key.length = tdata->key.len;
11918         ut_params->auth_xform.auth.key.data = auth_key;
11919         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11920         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
11921
11922
11923         ut_params->sess = rte_cryptodev_sym_session_create(
11924                         ts_params->session_mpool);
11925
11926         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11927                         &ut_params->auth_xform,
11928                         ts_params->session_priv_mpool);
11929
11930         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11931
11932         return 0;
11933 }
11934
11935 static int
11936 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
11937 {
11938         struct crypto_testsuite_params *ts_params = &testsuite_params;
11939         struct crypto_unittest_params *ut_params = &unittest_params;
11940         struct rte_cryptodev_info dev_info;
11941
11942         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11943         uint64_t feat_flags = dev_info.feature_flags;
11944
11945         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11946                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11947                 printf("Device doesn't support RAW data-path APIs.\n");
11948                 return TEST_SKIPPED;
11949         }
11950
11951         int retval;
11952
11953         uint8_t *auth_tag, *plaintext;
11954         uint16_t plaintext_pad_len;
11955
11956         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11957                               "No GMAC length in the source data");
11958
11959         /* Verify the capabilities */
11960         struct rte_cryptodev_sym_capability_idx cap_idx;
11961         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11962         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11963         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11964                         &cap_idx) == NULL)
11965                 return TEST_SKIPPED;
11966
11967         retval = create_gmac_session(ts_params->valid_devs[0],
11968                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11969
11970         if (retval < 0)
11971                 return retval;
11972
11973         if (tdata->plaintext.len > MBUF_SIZE)
11974                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11975         else
11976                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11977         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11978                         "Failed to allocate input buffer in mempool");
11979
11980         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11981                         rte_pktmbuf_tailroom(ut_params->ibuf));
11982
11983         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11984         /*
11985          * Runtime generate the large plain text instead of use hard code
11986          * plain text vector. It is done to avoid create huge source file
11987          * with the test vector.
11988          */
11989         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11990                 generate_gmac_large_plaintext(tdata->plaintext.data);
11991
11992         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11993                                 plaintext_pad_len);
11994         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11995
11996         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11997         debug_hexdump(stdout, "plaintext:", plaintext,
11998                         tdata->plaintext.len);
11999
12000         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
12001                         tdata);
12002
12003         if (retval < 0)
12004                 return retval;
12005
12006         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12007
12008         ut_params->op->sym->m_src = ut_params->ibuf;
12009
12010         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12011                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12012                         ut_params->op);
12013         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12014                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12015                                 ut_params->op, 0, 1, 0, 0);
12016         else
12017                 TEST_ASSERT_NOT_NULL(
12018                         process_crypto_request(ts_params->valid_devs[0],
12019                         ut_params->op), "failed to process sym crypto op");
12020
12021         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12022                         "crypto op processing failed");
12023
12024         if (ut_params->op->sym->m_dst) {
12025                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12026                                 uint8_t *, plaintext_pad_len);
12027         } else {
12028                 auth_tag = plaintext + plaintext_pad_len;
12029         }
12030
12031         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12032
12033         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12034                         auth_tag,
12035                         tdata->gmac_tag.data,
12036                         tdata->gmac_tag.len,
12037                         "GMAC Generated auth tag not as expected");
12038
12039         return 0;
12040 }
12041
12042 static int
12043 test_AES_GMAC_authentication_test_case_1(void)
12044 {
12045         return test_AES_GMAC_authentication(&gmac_test_case_1);
12046 }
12047
12048 static int
12049 test_AES_GMAC_authentication_test_case_2(void)
12050 {
12051         return test_AES_GMAC_authentication(&gmac_test_case_2);
12052 }
12053
12054 static int
12055 test_AES_GMAC_authentication_test_case_3(void)
12056 {
12057         return test_AES_GMAC_authentication(&gmac_test_case_3);
12058 }
12059
12060 static int
12061 test_AES_GMAC_authentication_test_case_4(void)
12062 {
12063         return test_AES_GMAC_authentication(&gmac_test_case_4);
12064 }
12065
12066 static int
12067 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
12068 {
12069         struct crypto_testsuite_params *ts_params = &testsuite_params;
12070         struct crypto_unittest_params *ut_params = &unittest_params;
12071         int retval;
12072         uint32_t plaintext_pad_len;
12073         uint8_t *plaintext;
12074         struct rte_cryptodev_info dev_info;
12075
12076         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12077         uint64_t feat_flags = dev_info.feature_flags;
12078
12079         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12080                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12081                 printf("Device doesn't support RAW data-path APIs.\n");
12082                 return TEST_SKIPPED;
12083         }
12084
12085         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12086                               "No GMAC length in the source data");
12087
12088         /* Verify the capabilities */
12089         struct rte_cryptodev_sym_capability_idx cap_idx;
12090         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12091         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12092         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12093                         &cap_idx) == NULL)
12094                 return TEST_SKIPPED;
12095
12096         retval = create_gmac_session(ts_params->valid_devs[0],
12097                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
12098
12099         if (retval < 0)
12100                 return retval;
12101
12102         if (tdata->plaintext.len > MBUF_SIZE)
12103                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12104         else
12105                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12106         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12107                         "Failed to allocate input buffer in mempool");
12108
12109         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12110                         rte_pktmbuf_tailroom(ut_params->ibuf));
12111
12112         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12113
12114         /*
12115          * Runtime generate the large plain text instead of use hard code
12116          * plain text vector. It is done to avoid create huge source file
12117          * with the test vector.
12118          */
12119         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12120                 generate_gmac_large_plaintext(tdata->plaintext.data);
12121
12122         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12123                                 plaintext_pad_len);
12124         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12125
12126         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12127         debug_hexdump(stdout, "plaintext:", plaintext,
12128                         tdata->plaintext.len);
12129
12130         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
12131                         tdata);
12132
12133         if (retval < 0)
12134                 return retval;
12135
12136         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12137
12138         ut_params->op->sym->m_src = ut_params->ibuf;
12139
12140         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12141                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12142                         ut_params->op);
12143         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12144                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12145                                 ut_params->op, 0, 1, 0, 0);
12146         else
12147                 TEST_ASSERT_NOT_NULL(
12148                         process_crypto_request(ts_params->valid_devs[0],
12149                         ut_params->op), "failed to process sym crypto op");
12150
12151         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12152                         "crypto op processing failed");
12153
12154         return 0;
12155
12156 }
12157
12158 static int
12159 test_AES_GMAC_authentication_verify_test_case_1(void)
12160 {
12161         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
12162 }
12163
12164 static int
12165 test_AES_GMAC_authentication_verify_test_case_2(void)
12166 {
12167         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
12168 }
12169
12170 static int
12171 test_AES_GMAC_authentication_verify_test_case_3(void)
12172 {
12173         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
12174 }
12175
12176 static int
12177 test_AES_GMAC_authentication_verify_test_case_4(void)
12178 {
12179         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
12180 }
12181
12182 static int
12183 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
12184                                 uint32_t fragsz)
12185 {
12186         struct crypto_testsuite_params *ts_params = &testsuite_params;
12187         struct crypto_unittest_params *ut_params = &unittest_params;
12188         struct rte_cryptodev_info dev_info;
12189         uint64_t feature_flags;
12190         unsigned int trn_data = 0;
12191         void *digest_mem = NULL;
12192         uint32_t segs = 1;
12193         unsigned int to_trn = 0;
12194         struct rte_mbuf *buf = NULL;
12195         uint8_t *auth_tag, *plaintext;
12196         int retval;
12197
12198         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12199                               "No GMAC length in the source data");
12200
12201         /* Verify the capabilities */
12202         struct rte_cryptodev_sym_capability_idx cap_idx;
12203         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12204         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12205         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12206                         &cap_idx) == NULL)
12207                 return TEST_SKIPPED;
12208
12209         /* Check for any input SGL support */
12210         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12211         feature_flags = dev_info.feature_flags;
12212
12213         if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
12214                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
12215                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
12216                 return TEST_SKIPPED;
12217
12218         if (fragsz > tdata->plaintext.len)
12219                 fragsz = tdata->plaintext.len;
12220
12221         uint16_t plaintext_len = fragsz;
12222
12223         retval = create_gmac_session(ts_params->valid_devs[0],
12224                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12225
12226         if (retval < 0)
12227                 return retval;
12228
12229         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12230         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12231                         "Failed to allocate input buffer in mempool");
12232
12233         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12234                         rte_pktmbuf_tailroom(ut_params->ibuf));
12235
12236         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12237                                 plaintext_len);
12238         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12239
12240         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12241
12242         trn_data += plaintext_len;
12243
12244         buf = ut_params->ibuf;
12245
12246         /*
12247          * Loop until no more fragments
12248          */
12249
12250         while (trn_data < tdata->plaintext.len) {
12251                 ++segs;
12252                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
12253                                 (tdata->plaintext.len - trn_data) : fragsz;
12254
12255                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12256                 buf = buf->next;
12257
12258                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
12259                                 rte_pktmbuf_tailroom(buf));
12260
12261                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
12262                                 to_trn);
12263
12264                 memcpy(plaintext, tdata->plaintext.data + trn_data,
12265                                 to_trn);
12266                 trn_data += to_trn;
12267                 if (trn_data  == tdata->plaintext.len)
12268                         digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
12269                                         tdata->gmac_tag.len);
12270         }
12271         ut_params->ibuf->nb_segs = segs;
12272
12273         /*
12274          * Place digest at the end of the last buffer
12275          */
12276         uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
12277
12278         if (!digest_mem) {
12279                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12280                                 + tdata->gmac_tag.len);
12281                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
12282                                 tdata->plaintext.len);
12283         }
12284
12285         retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
12286                         tdata, digest_mem, digest_phys);
12287
12288         if (retval < 0)
12289                 return retval;
12290
12291         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12292
12293         ut_params->op->sym->m_src = ut_params->ibuf;
12294
12295         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12296                 return TEST_SKIPPED;
12297
12298         TEST_ASSERT_NOT_NULL(
12299                 process_crypto_request(ts_params->valid_devs[0],
12300                 ut_params->op), "failed to process sym crypto op");
12301
12302         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12303                         "crypto op processing failed");
12304
12305         auth_tag = digest_mem;
12306         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12307         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12308                         auth_tag,
12309                         tdata->gmac_tag.data,
12310                         tdata->gmac_tag.len,
12311                         "GMAC Generated auth tag not as expected");
12312
12313         return 0;
12314 }
12315
12316 /* Segment size not multiple of block size (16B) */
12317 static int
12318 test_AES_GMAC_authentication_SGL_40B(void)
12319 {
12320         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
12321 }
12322
12323 static int
12324 test_AES_GMAC_authentication_SGL_80B(void)
12325 {
12326         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
12327 }
12328
12329 static int
12330 test_AES_GMAC_authentication_SGL_2048B(void)
12331 {
12332         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
12333 }
12334
12335 /* Segment size not multiple of block size (16B) */
12336 static int
12337 test_AES_GMAC_authentication_SGL_2047B(void)
12338 {
12339         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
12340 }
12341
12342 struct test_crypto_vector {
12343         enum rte_crypto_cipher_algorithm crypto_algo;
12344         unsigned int cipher_offset;
12345         unsigned int cipher_len;
12346
12347         struct {
12348                 uint8_t data[64];
12349                 unsigned int len;
12350         } cipher_key;
12351
12352         struct {
12353                 uint8_t data[64];
12354                 unsigned int len;
12355         } iv;
12356
12357         struct {
12358                 const uint8_t *data;
12359                 unsigned int len;
12360         } plaintext;
12361
12362         struct {
12363                 const uint8_t *data;
12364                 unsigned int len;
12365         } ciphertext;
12366
12367         enum rte_crypto_auth_algorithm auth_algo;
12368         unsigned int auth_offset;
12369
12370         struct {
12371                 uint8_t data[128];
12372                 unsigned int len;
12373         } auth_key;
12374
12375         struct {
12376                 const uint8_t *data;
12377                 unsigned int len;
12378         } aad;
12379
12380         struct {
12381                 uint8_t data[128];
12382                 unsigned int len;
12383         } digest;
12384 };
12385
12386 static const struct test_crypto_vector
12387 hmac_sha1_test_crypto_vector = {
12388         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12389         .plaintext = {
12390                 .data = plaintext_hash,
12391                 .len = 512
12392         },
12393         .auth_key = {
12394                 .data = {
12395                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12396                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12397                         0xDE, 0xF4, 0xDE, 0xAD
12398                 },
12399                 .len = 20
12400         },
12401         .digest = {
12402                 .data = {
12403                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
12404                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
12405                         0x3F, 0x91, 0x64, 0x59
12406                 },
12407                 .len = 20
12408         }
12409 };
12410
12411 static const struct test_crypto_vector
12412 aes128_gmac_test_vector = {
12413         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
12414         .plaintext = {
12415                 .data = plaintext_hash,
12416                 .len = 512
12417         },
12418         .iv = {
12419                 .data = {
12420                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12421                         0x08, 0x09, 0x0A, 0x0B
12422                 },
12423                 .len = 12
12424         },
12425         .auth_key = {
12426                 .data = {
12427                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12428                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
12429                 },
12430                 .len = 16
12431         },
12432         .digest = {
12433                 .data = {
12434                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
12435                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
12436                 },
12437                 .len = 16
12438         }
12439 };
12440
12441 static const struct test_crypto_vector
12442 aes128cbc_hmac_sha1_test_vector = {
12443         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12444         .cipher_offset = 0,
12445         .cipher_len = 512,
12446         .cipher_key = {
12447                 .data = {
12448                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12449                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12450                 },
12451                 .len = 16
12452         },
12453         .iv = {
12454                 .data = {
12455                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12456                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12457                 },
12458                 .len = 16
12459         },
12460         .plaintext = {
12461                 .data = plaintext_hash,
12462                 .len = 512
12463         },
12464         .ciphertext = {
12465                 .data = ciphertext512_aes128cbc,
12466                 .len = 512
12467         },
12468         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12469         .auth_offset = 0,
12470         .auth_key = {
12471                 .data = {
12472                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12473                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12474                         0xDE, 0xF4, 0xDE, 0xAD
12475                 },
12476                 .len = 20
12477         },
12478         .digest = {
12479                 .data = {
12480                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12481                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12482                         0x18, 0x8C, 0x1D, 0x32
12483                 },
12484                 .len = 20
12485         }
12486 };
12487
12488 static const struct test_crypto_vector
12489 aes128cbc_hmac_sha1_aad_test_vector = {
12490         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12491         .cipher_offset = 8,
12492         .cipher_len = 496,
12493         .cipher_key = {
12494                 .data = {
12495                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12496                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12497                 },
12498                 .len = 16
12499         },
12500         .iv = {
12501                 .data = {
12502                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12503                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12504                 },
12505                 .len = 16
12506         },
12507         .plaintext = {
12508                 .data = plaintext_hash,
12509                 .len = 512
12510         },
12511         .ciphertext = {
12512                 .data = ciphertext512_aes128cbc_aad,
12513                 .len = 512
12514         },
12515         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12516         .auth_offset = 0,
12517         .auth_key = {
12518                 .data = {
12519                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12520                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12521                         0xDE, 0xF4, 0xDE, 0xAD
12522                 },
12523                 .len = 20
12524         },
12525         .digest = {
12526                 .data = {
12527                         0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12528                         0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12529                         0x62, 0x0F, 0xFB, 0x10
12530                 },
12531                 .len = 20
12532         }
12533 };
12534
12535 static void
12536 data_corruption(uint8_t *data)
12537 {
12538         data[0] += 1;
12539 }
12540
12541 static void
12542 tag_corruption(uint8_t *data, unsigned int tag_offset)
12543 {
12544         data[tag_offset] += 1;
12545 }
12546
12547 static int
12548 create_auth_session(struct crypto_unittest_params *ut_params,
12549                 uint8_t dev_id,
12550                 const struct test_crypto_vector *reference,
12551                 enum rte_crypto_auth_operation auth_op)
12552 {
12553         struct crypto_testsuite_params *ts_params = &testsuite_params;
12554         uint8_t auth_key[reference->auth_key.len + 1];
12555
12556         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12557
12558         /* Setup Authentication Parameters */
12559         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12560         ut_params->auth_xform.auth.op = auth_op;
12561         ut_params->auth_xform.next = NULL;
12562         ut_params->auth_xform.auth.algo = reference->auth_algo;
12563         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12564         ut_params->auth_xform.auth.key.data = auth_key;
12565         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12566
12567         /* Create Crypto session*/
12568         ut_params->sess = rte_cryptodev_sym_session_create(
12569                         ts_params->session_mpool);
12570
12571         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12572                                 &ut_params->auth_xform,
12573                                 ts_params->session_priv_mpool);
12574
12575         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12576
12577         return 0;
12578 }
12579
12580 static int
12581 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12582                 uint8_t dev_id,
12583                 const struct test_crypto_vector *reference,
12584                 enum rte_crypto_auth_operation auth_op,
12585                 enum rte_crypto_cipher_operation cipher_op)
12586 {
12587         struct crypto_testsuite_params *ts_params = &testsuite_params;
12588         uint8_t cipher_key[reference->cipher_key.len + 1];
12589         uint8_t auth_key[reference->auth_key.len + 1];
12590
12591         memcpy(cipher_key, reference->cipher_key.data,
12592                         reference->cipher_key.len);
12593         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12594
12595         /* Setup Authentication Parameters */
12596         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12597         ut_params->auth_xform.auth.op = auth_op;
12598         ut_params->auth_xform.auth.algo = reference->auth_algo;
12599         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12600         ut_params->auth_xform.auth.key.data = auth_key;
12601         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12602
12603         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12604                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12605                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
12606         } else {
12607                 ut_params->auth_xform.next = &ut_params->cipher_xform;
12608
12609                 /* Setup Cipher Parameters */
12610                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12611                 ut_params->cipher_xform.next = NULL;
12612                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12613                 ut_params->cipher_xform.cipher.op = cipher_op;
12614                 ut_params->cipher_xform.cipher.key.data = cipher_key;
12615                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12616                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12617                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12618         }
12619
12620         /* Create Crypto session*/
12621         ut_params->sess = rte_cryptodev_sym_session_create(
12622                         ts_params->session_mpool);
12623
12624         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12625                                 &ut_params->auth_xform,
12626                                 ts_params->session_priv_mpool);
12627
12628         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12629
12630         return 0;
12631 }
12632
12633 static int
12634 create_auth_operation(struct crypto_testsuite_params *ts_params,
12635                 struct crypto_unittest_params *ut_params,
12636                 const struct test_crypto_vector *reference,
12637                 unsigned int auth_generate)
12638 {
12639         /* Generate Crypto op data structure */
12640         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12641                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12642         TEST_ASSERT_NOT_NULL(ut_params->op,
12643                         "Failed to allocate pktmbuf offload");
12644
12645         /* Set crypto operation data parameters */
12646         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12647
12648         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12649
12650         /* set crypto operation source mbuf */
12651         sym_op->m_src = ut_params->ibuf;
12652
12653         /* digest */
12654         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12655                         ut_params->ibuf, reference->digest.len);
12656
12657         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12658                         "no room to append auth tag");
12659
12660         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12661                         ut_params->ibuf, reference->plaintext.len);
12662
12663         if (auth_generate)
12664                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12665         else
12666                 memcpy(sym_op->auth.digest.data,
12667                                 reference->digest.data,
12668                                 reference->digest.len);
12669
12670         debug_hexdump(stdout, "digest:",
12671                         sym_op->auth.digest.data,
12672                         reference->digest.len);
12673
12674         sym_op->auth.data.length = reference->plaintext.len;
12675         sym_op->auth.data.offset = 0;
12676
12677         return 0;
12678 }
12679
12680 static int
12681 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12682                 struct crypto_unittest_params *ut_params,
12683                 const struct test_crypto_vector *reference,
12684                 unsigned int auth_generate)
12685 {
12686         /* Generate Crypto op data structure */
12687         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12688                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12689         TEST_ASSERT_NOT_NULL(ut_params->op,
12690                         "Failed to allocate pktmbuf offload");
12691
12692         /* Set crypto operation data parameters */
12693         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12694
12695         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12696
12697         /* set crypto operation source mbuf */
12698         sym_op->m_src = ut_params->ibuf;
12699
12700         /* digest */
12701         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12702                         ut_params->ibuf, reference->digest.len);
12703
12704         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12705                         "no room to append auth tag");
12706
12707         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12708                         ut_params->ibuf, reference->ciphertext.len);
12709
12710         if (auth_generate)
12711                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12712         else
12713                 memcpy(sym_op->auth.digest.data,
12714                                 reference->digest.data,
12715                                 reference->digest.len);
12716
12717         debug_hexdump(stdout, "digest:",
12718                         sym_op->auth.digest.data,
12719                         reference->digest.len);
12720
12721         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12722                         reference->iv.data, reference->iv.len);
12723
12724         sym_op->cipher.data.length = 0;
12725         sym_op->cipher.data.offset = 0;
12726
12727         sym_op->auth.data.length = reference->plaintext.len;
12728         sym_op->auth.data.offset = 0;
12729
12730         return 0;
12731 }
12732
12733 static int
12734 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12735                 struct crypto_unittest_params *ut_params,
12736                 const struct test_crypto_vector *reference,
12737                 unsigned int auth_generate)
12738 {
12739         /* Generate Crypto op data structure */
12740         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12741                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12742         TEST_ASSERT_NOT_NULL(ut_params->op,
12743                         "Failed to allocate pktmbuf offload");
12744
12745         /* Set crypto operation data parameters */
12746         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12747
12748         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12749
12750         /* set crypto operation source mbuf */
12751         sym_op->m_src = ut_params->ibuf;
12752
12753         /* digest */
12754         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12755                         ut_params->ibuf, reference->digest.len);
12756
12757         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12758                         "no room to append auth tag");
12759
12760         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12761                         ut_params->ibuf, reference->ciphertext.len);
12762
12763         if (auth_generate)
12764                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12765         else
12766                 memcpy(sym_op->auth.digest.data,
12767                                 reference->digest.data,
12768                                 reference->digest.len);
12769
12770         debug_hexdump(stdout, "digest:",
12771                         sym_op->auth.digest.data,
12772                         reference->digest.len);
12773
12774         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12775                         reference->iv.data, reference->iv.len);
12776
12777         sym_op->cipher.data.length = reference->cipher_len;
12778         sym_op->cipher.data.offset = reference->cipher_offset;
12779
12780         sym_op->auth.data.length = reference->plaintext.len;
12781         sym_op->auth.data.offset = reference->auth_offset;
12782
12783         return 0;
12784 }
12785
12786 static int
12787 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12788                 struct crypto_unittest_params *ut_params,
12789                 const struct test_crypto_vector *reference)
12790 {
12791         return create_auth_operation(ts_params, ut_params, reference, 0);
12792 }
12793
12794 static int
12795 create_auth_verify_GMAC_operation(
12796                 struct crypto_testsuite_params *ts_params,
12797                 struct crypto_unittest_params *ut_params,
12798                 const struct test_crypto_vector *reference)
12799 {
12800         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
12801 }
12802
12803 static int
12804 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12805                 struct crypto_unittest_params *ut_params,
12806                 const struct test_crypto_vector *reference)
12807 {
12808         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12809 }
12810
12811 static int
12812 test_authentication_verify_fail_when_data_corruption(
12813                 struct crypto_testsuite_params *ts_params,
12814                 struct crypto_unittest_params *ut_params,
12815                 const struct test_crypto_vector *reference,
12816                 unsigned int data_corrupted)
12817 {
12818         int retval;
12819
12820         uint8_t *plaintext;
12821         struct rte_cryptodev_info dev_info;
12822
12823         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12824         uint64_t feat_flags = dev_info.feature_flags;
12825
12826         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12827                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12828                 printf("Device doesn't support RAW data-path APIs.\n");
12829                 return TEST_SKIPPED;
12830         }
12831
12832         /* Verify the capabilities */
12833         struct rte_cryptodev_sym_capability_idx cap_idx;
12834         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12835         cap_idx.algo.auth = reference->auth_algo;
12836         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12837                         &cap_idx) == NULL)
12838                 return TEST_SKIPPED;
12839
12840
12841         /* Create session */
12842         retval = create_auth_session(ut_params,
12843                         ts_params->valid_devs[0],
12844                         reference,
12845                         RTE_CRYPTO_AUTH_OP_VERIFY);
12846         if (retval < 0)
12847                 return retval;
12848
12849         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12850         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12851                         "Failed to allocate input buffer in mempool");
12852
12853         /* clear mbuf payload */
12854         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12855                         rte_pktmbuf_tailroom(ut_params->ibuf));
12856
12857         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12858                         reference->plaintext.len);
12859         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12860         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12861
12862         debug_hexdump(stdout, "plaintext:", plaintext,
12863                 reference->plaintext.len);
12864
12865         /* Create operation */
12866         retval = create_auth_verify_operation(ts_params, ut_params, reference);
12867
12868         if (retval < 0)
12869                 return retval;
12870
12871         if (data_corrupted)
12872                 data_corruption(plaintext);
12873         else
12874                 tag_corruption(plaintext, reference->plaintext.len);
12875
12876         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12877                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12878                         ut_params->op);
12879                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12880                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12881                         "authentication not failed");
12882         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12883                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12884                                 ut_params->op, 0, 1, 0, 0);
12885         else {
12886                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12887                         ut_params->op);
12888                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12889         }
12890
12891         return 0;
12892 }
12893
12894 static int
12895 test_authentication_verify_GMAC_fail_when_corruption(
12896                 struct crypto_testsuite_params *ts_params,
12897                 struct crypto_unittest_params *ut_params,
12898                 const struct test_crypto_vector *reference,
12899                 unsigned int data_corrupted)
12900 {
12901         int retval;
12902         uint8_t *plaintext;
12903         struct rte_cryptodev_info dev_info;
12904
12905         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12906         uint64_t feat_flags = dev_info.feature_flags;
12907
12908         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12909                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12910                 printf("Device doesn't support RAW data-path APIs.\n");
12911                 return TEST_SKIPPED;
12912         }
12913
12914         /* Verify the capabilities */
12915         struct rte_cryptodev_sym_capability_idx cap_idx;
12916         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12917         cap_idx.algo.auth = reference->auth_algo;
12918         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12919                         &cap_idx) == NULL)
12920                 return TEST_SKIPPED;
12921
12922         /* Create session */
12923         retval = create_auth_cipher_session(ut_params,
12924                         ts_params->valid_devs[0],
12925                         reference,
12926                         RTE_CRYPTO_AUTH_OP_VERIFY,
12927                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12928         if (retval < 0)
12929                 return retval;
12930
12931         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12932         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12933                         "Failed to allocate input buffer in mempool");
12934
12935         /* clear mbuf payload */
12936         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12937                         rte_pktmbuf_tailroom(ut_params->ibuf));
12938
12939         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12940                         reference->plaintext.len);
12941         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12942         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12943
12944         debug_hexdump(stdout, "plaintext:", plaintext,
12945                 reference->plaintext.len);
12946
12947         /* Create operation */
12948         retval = create_auth_verify_GMAC_operation(ts_params,
12949                         ut_params,
12950                         reference);
12951
12952         if (retval < 0)
12953                 return retval;
12954
12955         if (data_corrupted)
12956                 data_corruption(plaintext);
12957         else
12958                 tag_corruption(plaintext, reference->aad.len);
12959
12960         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12961                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12962                         ut_params->op);
12963                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12964                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12965                         "authentication not failed");
12966         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12967                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12968                                 ut_params->op, 0, 1, 0, 0);
12969         else {
12970                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12971                         ut_params->op);
12972                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12973         }
12974
12975         return 0;
12976 }
12977
12978 static int
12979 test_authenticated_decryption_fail_when_corruption(
12980                 struct crypto_testsuite_params *ts_params,
12981                 struct crypto_unittest_params *ut_params,
12982                 const struct test_crypto_vector *reference,
12983                 unsigned int data_corrupted)
12984 {
12985         int retval;
12986
12987         uint8_t *ciphertext;
12988         struct rte_cryptodev_info dev_info;
12989
12990         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12991         uint64_t feat_flags = dev_info.feature_flags;
12992
12993         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12994                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12995                 printf("Device doesn't support RAW data-path APIs.\n");
12996                 return TEST_SKIPPED;
12997         }
12998
12999         /* Verify the capabilities */
13000         struct rte_cryptodev_sym_capability_idx cap_idx;
13001         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13002         cap_idx.algo.auth = reference->auth_algo;
13003         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13004                         &cap_idx) == NULL)
13005                 return TEST_SKIPPED;
13006         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13007         cap_idx.algo.cipher = reference->crypto_algo;
13008         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13009                         &cap_idx) == NULL)
13010                 return TEST_SKIPPED;
13011
13012         /* Create session */
13013         retval = create_auth_cipher_session(ut_params,
13014                         ts_params->valid_devs[0],
13015                         reference,
13016                         RTE_CRYPTO_AUTH_OP_VERIFY,
13017                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
13018         if (retval < 0)
13019                 return retval;
13020
13021         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13022         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13023                         "Failed to allocate input buffer in mempool");
13024
13025         /* clear mbuf payload */
13026         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13027                         rte_pktmbuf_tailroom(ut_params->ibuf));
13028
13029         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13030                         reference->ciphertext.len);
13031         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13032         memcpy(ciphertext, reference->ciphertext.data,
13033                         reference->ciphertext.len);
13034
13035         /* Create operation */
13036         retval = create_cipher_auth_verify_operation(ts_params,
13037                         ut_params,
13038                         reference);
13039
13040         if (retval < 0)
13041                 return retval;
13042
13043         if (data_corrupted)
13044                 data_corruption(ciphertext);
13045         else
13046                 tag_corruption(ciphertext, reference->ciphertext.len);
13047
13048         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13049                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13050                         ut_params->op);
13051                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13052                         RTE_CRYPTO_OP_STATUS_SUCCESS,
13053                         "authentication not failed");
13054         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13055                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13056                                 ut_params->op, 1, 1, 0, 0);
13057         else {
13058                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13059                         ut_params->op);
13060                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13061         }
13062
13063         return 0;
13064 }
13065
13066 static int
13067 test_authenticated_encrypt_with_esn(
13068                 struct crypto_testsuite_params *ts_params,
13069                 struct crypto_unittest_params *ut_params,
13070                 const struct test_crypto_vector *reference)
13071 {
13072         int retval;
13073
13074         uint8_t *authciphertext, *plaintext, *auth_tag;
13075         uint16_t plaintext_pad_len;
13076         uint8_t cipher_key[reference->cipher_key.len + 1];
13077         uint8_t auth_key[reference->auth_key.len + 1];
13078         struct rte_cryptodev_info dev_info;
13079
13080         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13081         uint64_t feat_flags = dev_info.feature_flags;
13082
13083         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13084                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13085                 printf("Device doesn't support RAW data-path APIs.\n");
13086                 return TEST_SKIPPED;
13087         }
13088
13089         /* Verify the capabilities */
13090         struct rte_cryptodev_sym_capability_idx cap_idx;
13091         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13092         cap_idx.algo.auth = reference->auth_algo;
13093         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13094                         &cap_idx) == NULL)
13095                 return TEST_SKIPPED;
13096         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13097         cap_idx.algo.cipher = reference->crypto_algo;
13098         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13099                         &cap_idx) == NULL)
13100                 return TEST_SKIPPED;
13101
13102         /* Create session */
13103         memcpy(cipher_key, reference->cipher_key.data,
13104                         reference->cipher_key.len);
13105         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13106
13107         /* Setup Cipher Parameters */
13108         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13109         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13110         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
13111         ut_params->cipher_xform.cipher.key.data = cipher_key;
13112         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13113         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13114         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13115
13116         ut_params->cipher_xform.next = &ut_params->auth_xform;
13117
13118         /* Setup Authentication Parameters */
13119         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13120         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
13121         ut_params->auth_xform.auth.algo = reference->auth_algo;
13122         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13123         ut_params->auth_xform.auth.key.data = auth_key;
13124         ut_params->auth_xform.auth.digest_length = reference->digest.len;
13125         ut_params->auth_xform.next = NULL;
13126
13127         /* Create Crypto session*/
13128         ut_params->sess = rte_cryptodev_sym_session_create(
13129                         ts_params->session_mpool);
13130
13131         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13132                                 ut_params->sess,
13133                                 &ut_params->cipher_xform,
13134                                 ts_params->session_priv_mpool);
13135
13136         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13137
13138         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13139         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13140                         "Failed to allocate input buffer in mempool");
13141
13142         /* clear mbuf payload */
13143         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13144                         rte_pktmbuf_tailroom(ut_params->ibuf));
13145
13146         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13147                         reference->plaintext.len);
13148         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13149         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13150
13151         /* Create operation */
13152         retval = create_cipher_auth_operation(ts_params,
13153                         ut_params,
13154                         reference, 0);
13155
13156         if (retval < 0)
13157                 return retval;
13158
13159         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13160                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13161                         ut_params->op);
13162         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13163                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13164                                 ut_params->op, 1, 1, 0, 0);
13165         else
13166                 ut_params->op = process_crypto_request(
13167                         ts_params->valid_devs[0], ut_params->op);
13168
13169         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
13170
13171         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13172                         "crypto op processing failed");
13173
13174         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
13175
13176         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
13177                         ut_params->op->sym->auth.data.offset);
13178         auth_tag = authciphertext + plaintext_pad_len;
13179         debug_hexdump(stdout, "ciphertext:", authciphertext,
13180                         reference->ciphertext.len);
13181         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
13182
13183         /* Validate obuf */
13184         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13185                         authciphertext,
13186                         reference->ciphertext.data,
13187                         reference->ciphertext.len,
13188                         "Ciphertext data not as expected");
13189
13190         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13191                         auth_tag,
13192                         reference->digest.data,
13193                         reference->digest.len,
13194                         "Generated digest not as expected");
13195
13196         return TEST_SUCCESS;
13197
13198 }
13199
13200 static int
13201 test_authenticated_decrypt_with_esn(
13202                 struct crypto_testsuite_params *ts_params,
13203                 struct crypto_unittest_params *ut_params,
13204                 const struct test_crypto_vector *reference)
13205 {
13206         int retval;
13207
13208         uint8_t *ciphertext;
13209         uint8_t cipher_key[reference->cipher_key.len + 1];
13210         uint8_t auth_key[reference->auth_key.len + 1];
13211         struct rte_cryptodev_info dev_info;
13212
13213         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13214         uint64_t feat_flags = dev_info.feature_flags;
13215
13216         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13217                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13218                 printf("Device doesn't support RAW data-path APIs.\n");
13219                 return TEST_SKIPPED;
13220         }
13221
13222         /* Verify the capabilities */
13223         struct rte_cryptodev_sym_capability_idx cap_idx;
13224         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13225         cap_idx.algo.auth = reference->auth_algo;
13226         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13227                         &cap_idx) == NULL)
13228                 return TEST_SKIPPED;
13229         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13230         cap_idx.algo.cipher = reference->crypto_algo;
13231         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13232                         &cap_idx) == NULL)
13233                 return TEST_SKIPPED;
13234
13235         /* Create session */
13236         memcpy(cipher_key, reference->cipher_key.data,
13237                         reference->cipher_key.len);
13238         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13239
13240         /* Setup Authentication Parameters */
13241         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13242         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
13243         ut_params->auth_xform.auth.algo = reference->auth_algo;
13244         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13245         ut_params->auth_xform.auth.key.data = auth_key;
13246         ut_params->auth_xform.auth.digest_length = reference->digest.len;
13247         ut_params->auth_xform.next = &ut_params->cipher_xform;
13248
13249         /* Setup Cipher Parameters */
13250         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13251         ut_params->cipher_xform.next = NULL;
13252         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13253         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
13254         ut_params->cipher_xform.cipher.key.data = cipher_key;
13255         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13256         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13257         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13258
13259         /* Create Crypto session*/
13260         ut_params->sess = rte_cryptodev_sym_session_create(
13261                         ts_params->session_mpool);
13262
13263         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13264                                 ut_params->sess,
13265                                 &ut_params->auth_xform,
13266                                 ts_params->session_priv_mpool);
13267
13268         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13269
13270         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13271         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13272                         "Failed to allocate input buffer in mempool");
13273
13274         /* clear mbuf payload */
13275         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13276                         rte_pktmbuf_tailroom(ut_params->ibuf));
13277
13278         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13279                         reference->ciphertext.len);
13280         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13281         memcpy(ciphertext, reference->ciphertext.data,
13282                         reference->ciphertext.len);
13283
13284         /* Create operation */
13285         retval = create_cipher_auth_verify_operation(ts_params,
13286                         ut_params,
13287                         reference);
13288
13289         if (retval < 0)
13290                 return retval;
13291
13292         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13293                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13294                         ut_params->op);
13295         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13296                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13297                                 ut_params->op, 1, 1, 0, 0);
13298         else
13299                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13300                         ut_params->op);
13301
13302         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
13303         TEST_ASSERT_EQUAL(ut_params->op->status,
13304                         RTE_CRYPTO_OP_STATUS_SUCCESS,
13305                         "crypto op processing passed");
13306
13307         ut_params->obuf = ut_params->op->sym->m_src;
13308         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
13309
13310         return 0;
13311 }
13312
13313 static int
13314 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
13315                 const struct aead_test_data *tdata,
13316                 void *digest_mem, uint64_t digest_phys)
13317 {
13318         struct crypto_testsuite_params *ts_params = &testsuite_params;
13319         struct crypto_unittest_params *ut_params = &unittest_params;
13320
13321         const unsigned int auth_tag_len = tdata->auth_tag.len;
13322         const unsigned int iv_len = tdata->iv.len;
13323         unsigned int aad_len = tdata->aad.len;
13324         unsigned int aad_len_pad = 0;
13325
13326         /* Generate Crypto op data structure */
13327         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13328                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13329         TEST_ASSERT_NOT_NULL(ut_params->op,
13330                 "Failed to allocate symmetric crypto operation struct");
13331
13332         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13333
13334         sym_op->aead.digest.data = digest_mem;
13335
13336         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
13337                         "no room to append digest");
13338
13339         sym_op->aead.digest.phys_addr = digest_phys;
13340
13341         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
13342                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
13343                                 auth_tag_len);
13344                 debug_hexdump(stdout, "digest:",
13345                                 sym_op->aead.digest.data,
13346                                 auth_tag_len);
13347         }
13348
13349         /* Append aad data */
13350         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
13351                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13352                                 uint8_t *, IV_OFFSET);
13353
13354                 /* Copy IV 1 byte after the IV pointer, according to the API */
13355                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
13356
13357                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
13358
13359                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13360                                 ut_params->ibuf, aad_len);
13361                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13362                                 "no room to prepend aad");
13363                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13364                                 ut_params->ibuf);
13365
13366                 memset(sym_op->aead.aad.data, 0, aad_len);
13367                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
13368                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13369
13370                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13371                 debug_hexdump(stdout, "aad:",
13372                                 sym_op->aead.aad.data, aad_len);
13373         } else {
13374                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13375                                 uint8_t *, IV_OFFSET);
13376
13377                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
13378
13379                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
13380
13381                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13382                                 ut_params->ibuf, aad_len_pad);
13383                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13384                                 "no room to prepend aad");
13385                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13386                                 ut_params->ibuf);
13387
13388                 memset(sym_op->aead.aad.data, 0, aad_len);
13389                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13390
13391                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13392                 debug_hexdump(stdout, "aad:",
13393                                 sym_op->aead.aad.data, aad_len);
13394         }
13395
13396         sym_op->aead.data.length = tdata->plaintext.len;
13397         sym_op->aead.data.offset = aad_len_pad;
13398
13399         return 0;
13400 }
13401
13402 #define SGL_MAX_NO      16
13403
13404 static int
13405 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
13406                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
13407 {
13408         struct crypto_testsuite_params *ts_params = &testsuite_params;
13409         struct crypto_unittest_params *ut_params = &unittest_params;
13410         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
13411         int retval;
13412         int to_trn = 0;
13413         int to_trn_tbl[SGL_MAX_NO];
13414         int segs = 1;
13415         unsigned int trn_data = 0;
13416         uint8_t *plaintext, *ciphertext, *auth_tag;
13417         struct rte_cryptodev_info dev_info;
13418
13419         /* Verify the capabilities */
13420         struct rte_cryptodev_sym_capability_idx cap_idx;
13421         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13422         cap_idx.algo.aead = tdata->algo;
13423         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13424                         &cap_idx) == NULL)
13425                 return TEST_SKIPPED;
13426
13427         /* OOP not supported with CPU crypto */
13428         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13429                 return TEST_SKIPPED;
13430
13431         /* Detailed check for the particular SGL support flag */
13432         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13433         if (!oop) {
13434                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
13435                 if (sgl_in && (!(dev_info.feature_flags &
13436                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
13437                         return TEST_SKIPPED;
13438
13439                 uint64_t feat_flags = dev_info.feature_flags;
13440
13441                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13442                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13443                         printf("Device doesn't support RAW data-path APIs.\n");
13444                         return TEST_SKIPPED;
13445                 }
13446         } else {
13447                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
13448                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
13449                                 tdata->plaintext.len;
13450                 /* Raw data path API does not support OOP */
13451                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13452                         return TEST_SKIPPED;
13453                 if (sgl_in && !sgl_out) {
13454                         if (!(dev_info.feature_flags &
13455                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
13456                                 return TEST_SKIPPED;
13457                 } else if (!sgl_in && sgl_out) {
13458                         if (!(dev_info.feature_flags &
13459                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
13460                                 return TEST_SKIPPED;
13461                 } else if (sgl_in && sgl_out) {
13462                         if (!(dev_info.feature_flags &
13463                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13464                                 return TEST_SKIPPED;
13465                 }
13466         }
13467
13468         if (fragsz > tdata->plaintext.len)
13469                 fragsz = tdata->plaintext.len;
13470
13471         uint16_t plaintext_len = fragsz;
13472         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13473
13474         if (fragsz_oop > tdata->plaintext.len)
13475                 frag_size_oop = tdata->plaintext.len;
13476
13477         int ecx = 0;
13478         void *digest_mem = NULL;
13479
13480         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13481
13482         if (tdata->plaintext.len % fragsz != 0) {
13483                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13484                         return 1;
13485         }       else {
13486                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13487                         return 1;
13488         }
13489
13490         /*
13491          * For out-op-place we need to alloc another mbuf
13492          */
13493         if (oop) {
13494                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13495                 rte_pktmbuf_append(ut_params->obuf,
13496                                 frag_size_oop + prepend_len);
13497                 buf_oop = ut_params->obuf;
13498         }
13499
13500         /* Create AEAD session */
13501         retval = create_aead_session(ts_params->valid_devs[0],
13502                         tdata->algo,
13503                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
13504                         tdata->key.data, tdata->key.len,
13505                         tdata->aad.len, tdata->auth_tag.len,
13506                         tdata->iv.len);
13507         if (retval < 0)
13508                 return retval;
13509
13510         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13511
13512         /* clear mbuf payload */
13513         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13514                         rte_pktmbuf_tailroom(ut_params->ibuf));
13515
13516         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13517                         plaintext_len);
13518
13519         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13520
13521         trn_data += plaintext_len;
13522
13523         buf = ut_params->ibuf;
13524
13525         /*
13526          * Loop until no more fragments
13527          */
13528
13529         while (trn_data < tdata->plaintext.len) {
13530                 ++segs;
13531                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13532                                 (tdata->plaintext.len - trn_data) : fragsz;
13533
13534                 to_trn_tbl[ecx++] = to_trn;
13535
13536                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13537                 buf = buf->next;
13538
13539                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13540                                 rte_pktmbuf_tailroom(buf));
13541
13542                 /* OOP */
13543                 if (oop && !fragsz_oop) {
13544                         buf_last_oop = buf_oop->next =
13545                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13546                         buf_oop = buf_oop->next;
13547                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13548                                         0, rte_pktmbuf_tailroom(buf_oop));
13549                         rte_pktmbuf_append(buf_oop, to_trn);
13550                 }
13551
13552                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13553                                 to_trn);
13554
13555                 memcpy(plaintext, tdata->plaintext.data + trn_data,
13556                                 to_trn);
13557                 trn_data += to_trn;
13558                 if (trn_data  == tdata->plaintext.len) {
13559                         if (oop) {
13560                                 if (!fragsz_oop)
13561                                         digest_mem = rte_pktmbuf_append(buf_oop,
13562                                                 tdata->auth_tag.len);
13563                         } else
13564                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13565                                         tdata->auth_tag.len);
13566                 }
13567         }
13568
13569         uint64_t digest_phys = 0;
13570
13571         ut_params->ibuf->nb_segs = segs;
13572
13573         segs = 1;
13574         if (fragsz_oop && oop) {
13575                 to_trn = 0;
13576                 ecx = 0;
13577
13578                 if (frag_size_oop == tdata->plaintext.len) {
13579                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
13580                                 tdata->auth_tag.len);
13581
13582                         digest_phys = rte_pktmbuf_iova_offset(
13583                                         ut_params->obuf,
13584                                         tdata->plaintext.len + prepend_len);
13585                 }
13586
13587                 trn_data = frag_size_oop;
13588                 while (trn_data < tdata->plaintext.len) {
13589                         ++segs;
13590                         to_trn =
13591                                 (tdata->plaintext.len - trn_data <
13592                                                 frag_size_oop) ?
13593                                 (tdata->plaintext.len - trn_data) :
13594                                                 frag_size_oop;
13595
13596                         to_trn_tbl[ecx++] = to_trn;
13597
13598                         buf_last_oop = buf_oop->next =
13599                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13600                         buf_oop = buf_oop->next;
13601                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13602                                         0, rte_pktmbuf_tailroom(buf_oop));
13603                         rte_pktmbuf_append(buf_oop, to_trn);
13604
13605                         trn_data += to_trn;
13606
13607                         if (trn_data  == tdata->plaintext.len) {
13608                                 digest_mem = rte_pktmbuf_append(buf_oop,
13609                                         tdata->auth_tag.len);
13610                         }
13611                 }
13612
13613                 ut_params->obuf->nb_segs = segs;
13614         }
13615
13616         /*
13617          * Place digest at the end of the last buffer
13618          */
13619         if (!digest_phys)
13620                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13621         if (oop && buf_last_oop)
13622                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13623
13624         if (!digest_mem && !oop) {
13625                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13626                                 + tdata->auth_tag.len);
13627                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13628                                 tdata->plaintext.len);
13629         }
13630
13631         /* Create AEAD operation */
13632         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13633                         tdata, digest_mem, digest_phys);
13634
13635         if (retval < 0)
13636                 return retval;
13637
13638         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13639
13640         ut_params->op->sym->m_src = ut_params->ibuf;
13641         if (oop)
13642                 ut_params->op->sym->m_dst = ut_params->obuf;
13643
13644         /* Process crypto operation */
13645         if (oop == IN_PLACE &&
13646                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13647                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13648         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13649                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13650                                 ut_params->op, 0, 0, 0, 0);
13651         else
13652                 TEST_ASSERT_NOT_NULL(
13653                         process_crypto_request(ts_params->valid_devs[0],
13654                         ut_params->op), "failed to process sym crypto op");
13655
13656         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13657                         "crypto op processing failed");
13658
13659
13660         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13661                         uint8_t *, prepend_len);
13662         if (oop) {
13663                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13664                                 uint8_t *, prepend_len);
13665         }
13666
13667         if (fragsz_oop)
13668                 fragsz = fragsz_oop;
13669
13670         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13671                         ciphertext,
13672                         tdata->ciphertext.data,
13673                         fragsz,
13674                         "Ciphertext data not as expected");
13675
13676         buf = ut_params->op->sym->m_src->next;
13677         if (oop)
13678                 buf = ut_params->op->sym->m_dst->next;
13679
13680         unsigned int off = fragsz;
13681
13682         ecx = 0;
13683         while (buf) {
13684                 ciphertext = rte_pktmbuf_mtod(buf,
13685                                 uint8_t *);
13686
13687                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
13688                                 ciphertext,
13689                                 tdata->ciphertext.data + off,
13690                                 to_trn_tbl[ecx],
13691                                 "Ciphertext data not as expected");
13692
13693                 off += to_trn_tbl[ecx++];
13694                 buf = buf->next;
13695         }
13696
13697         auth_tag = digest_mem;
13698         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13699                         auth_tag,
13700                         tdata->auth_tag.data,
13701                         tdata->auth_tag.len,
13702                         "Generated auth tag not as expected");
13703
13704         return 0;
13705 }
13706
13707 static int
13708 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13709 {
13710         return test_authenticated_encryption_SGL(
13711                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13712 }
13713
13714 static int
13715 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13716 {
13717         return test_authenticated_encryption_SGL(
13718                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13719 }
13720
13721 static int
13722 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13723 {
13724         return test_authenticated_encryption_SGL(
13725                         &gcm_test_case_8, OUT_OF_PLACE, 400,
13726                         gcm_test_case_8.plaintext.len);
13727 }
13728
13729 static int
13730 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13731 {
13732         /* This test is not for OPENSSL PMD */
13733         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13734                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13735                 return TEST_SKIPPED;
13736
13737         return test_authenticated_encryption_SGL(
13738                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13739 }
13740
13741 static int
13742 test_authentication_verify_fail_when_data_corrupted(
13743                 struct crypto_testsuite_params *ts_params,
13744                 struct crypto_unittest_params *ut_params,
13745                 const struct test_crypto_vector *reference)
13746 {
13747         return test_authentication_verify_fail_when_data_corruption(
13748                         ts_params, ut_params, reference, 1);
13749 }
13750
13751 static int
13752 test_authentication_verify_fail_when_tag_corrupted(
13753                 struct crypto_testsuite_params *ts_params,
13754                 struct crypto_unittest_params *ut_params,
13755                 const struct test_crypto_vector *reference)
13756 {
13757         return test_authentication_verify_fail_when_data_corruption(
13758                         ts_params, ut_params, reference, 0);
13759 }
13760
13761 static int
13762 test_authentication_verify_GMAC_fail_when_data_corrupted(
13763                 struct crypto_testsuite_params *ts_params,
13764                 struct crypto_unittest_params *ut_params,
13765                 const struct test_crypto_vector *reference)
13766 {
13767         return test_authentication_verify_GMAC_fail_when_corruption(
13768                         ts_params, ut_params, reference, 1);
13769 }
13770
13771 static int
13772 test_authentication_verify_GMAC_fail_when_tag_corrupted(
13773                 struct crypto_testsuite_params *ts_params,
13774                 struct crypto_unittest_params *ut_params,
13775                 const struct test_crypto_vector *reference)
13776 {
13777         return test_authentication_verify_GMAC_fail_when_corruption(
13778                         ts_params, ut_params, reference, 0);
13779 }
13780
13781 static int
13782 test_authenticated_decryption_fail_when_data_corrupted(
13783                 struct crypto_testsuite_params *ts_params,
13784                 struct crypto_unittest_params *ut_params,
13785                 const struct test_crypto_vector *reference)
13786 {
13787         return test_authenticated_decryption_fail_when_corruption(
13788                         ts_params, ut_params, reference, 1);
13789 }
13790
13791 static int
13792 test_authenticated_decryption_fail_when_tag_corrupted(
13793                 struct crypto_testsuite_params *ts_params,
13794                 struct crypto_unittest_params *ut_params,
13795                 const struct test_crypto_vector *reference)
13796 {
13797         return test_authenticated_decryption_fail_when_corruption(
13798                         ts_params, ut_params, reference, 0);
13799 }
13800
13801 static int
13802 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
13803 {
13804         return test_authentication_verify_fail_when_data_corrupted(
13805                         &testsuite_params, &unittest_params,
13806                         &hmac_sha1_test_crypto_vector);
13807 }
13808
13809 static int
13810 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13811 {
13812         return test_authentication_verify_fail_when_tag_corrupted(
13813                         &testsuite_params, &unittest_params,
13814                         &hmac_sha1_test_crypto_vector);
13815 }
13816
13817 static int
13818 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
13819 {
13820         return test_authentication_verify_GMAC_fail_when_data_corrupted(
13821                         &testsuite_params, &unittest_params,
13822                         &aes128_gmac_test_vector);
13823 }
13824
13825 static int
13826 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
13827 {
13828         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
13829                         &testsuite_params, &unittest_params,
13830                         &aes128_gmac_test_vector);
13831 }
13832
13833 static int
13834 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
13835 {
13836         return test_authenticated_decryption_fail_when_data_corrupted(
13837                         &testsuite_params,
13838                         &unittest_params,
13839                         &aes128cbc_hmac_sha1_test_vector);
13840 }
13841
13842 static int
13843 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
13844 {
13845         return test_authenticated_decryption_fail_when_tag_corrupted(
13846                         &testsuite_params,
13847                         &unittest_params,
13848                         &aes128cbc_hmac_sha1_test_vector);
13849 }
13850
13851 static int
13852 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13853 {
13854         return test_authenticated_encrypt_with_esn(
13855                         &testsuite_params,
13856                         &unittest_params,
13857                         &aes128cbc_hmac_sha1_aad_test_vector);
13858 }
13859
13860 static int
13861 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13862 {
13863         return test_authenticated_decrypt_with_esn(
13864                         &testsuite_params,
13865                         &unittest_params,
13866                         &aes128cbc_hmac_sha1_aad_test_vector);
13867 }
13868
13869 static int
13870 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
13871 {
13872         return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
13873 }
13874
13875 static int
13876 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
13877 {
13878         return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
13879 }
13880
13881 #ifdef RTE_CRYPTO_SCHEDULER
13882
13883 /* global AESNI worker IDs for the scheduler test */
13884 uint8_t aesni_ids[2];
13885
13886 static int
13887 scheduler_testsuite_setup(void)
13888 {
13889         uint32_t i = 0;
13890         int32_t nb_devs, ret;
13891         char vdev_args[VDEV_ARGS_SIZE] = {""};
13892         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
13893                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
13894         uint16_t worker_core_count = 0;
13895         uint16_t socket_id = 0;
13896
13897         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13898                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
13899
13900                 /* Identify the Worker Cores
13901                  * Use 2 worker cores for the device args
13902                  */
13903                 RTE_LCORE_FOREACH_WORKER(i) {
13904                         if (worker_core_count > 1)
13905                                 break;
13906                         snprintf(vdev_args, sizeof(vdev_args),
13907                                         "%s%d", temp_str, i);
13908                         strcpy(temp_str, vdev_args);
13909                         strlcat(temp_str, ";", sizeof(temp_str));
13910                         worker_core_count++;
13911                         socket_id = rte_lcore_to_socket_id(i);
13912                 }
13913                 if (worker_core_count != 2) {
13914                         RTE_LOG(ERR, USER1,
13915                                 "Cryptodev scheduler test require at least "
13916                                 "two worker cores to run. "
13917                                 "Please use the correct coremask.\n");
13918                         return TEST_FAILED;
13919                 }
13920                 strcpy(temp_str, vdev_args);
13921                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
13922                                 temp_str, socket_id);
13923                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
13924                 nb_devs = rte_cryptodev_device_count_by_driver(
13925                                 rte_cryptodev_driver_id_get(
13926                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
13927                 if (nb_devs < 1) {
13928                         ret = rte_vdev_init(
13929                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
13930                                         vdev_args);
13931                         TEST_ASSERT(ret == 0,
13932                                 "Failed to create instance %u of pmd : %s",
13933                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13934                 }
13935         }
13936         return testsuite_setup();
13937 }
13938
13939 static int
13940 test_scheduler_attach_worker_op(void)
13941 {
13942         struct crypto_testsuite_params *ts_params = &testsuite_params;
13943         uint8_t sched_id = ts_params->valid_devs[0];
13944         uint32_t i, nb_devs_attached = 0;
13945         int ret;
13946         char vdev_name[32];
13947         unsigned int count = rte_cryptodev_count();
13948
13949         /* create 2 AESNI_MB vdevs on top of existing devices */
13950         for (i = count; i < count + 2; i++) {
13951                 snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
13952                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
13953                                 i);
13954                 ret = rte_vdev_init(vdev_name, NULL);
13955
13956                 TEST_ASSERT(ret == 0,
13957                         "Failed to create instance %u of"
13958                         " pmd : %s",
13959                         i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13960
13961                 if (ret < 0) {
13962                         RTE_LOG(ERR, USER1,
13963                                 "Failed to create 2 AESNI MB PMDs.\n");
13964                         return TEST_SKIPPED;
13965                 }
13966         }
13967
13968         /* attach 2 AESNI_MB cdevs */
13969         for (i = count; i < count + 2; i++) {
13970                 struct rte_cryptodev_info info;
13971                 unsigned int session_size;
13972
13973                 rte_cryptodev_info_get(i, &info);
13974                 if (info.driver_id != rte_cryptodev_driver_id_get(
13975                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
13976                         continue;
13977
13978                 session_size = rte_cryptodev_sym_get_private_session_size(i);
13979                 /*
13980                  * Create the session mempool again, since now there are new devices
13981                  * to use the mempool.
13982                  */
13983                 if (ts_params->session_mpool) {
13984                         rte_mempool_free(ts_params->session_mpool);
13985                         ts_params->session_mpool = NULL;
13986                 }
13987                 if (ts_params->session_priv_mpool) {
13988                         rte_mempool_free(ts_params->session_priv_mpool);
13989                         ts_params->session_priv_mpool = NULL;
13990                 }
13991
13992                 if (info.sym.max_nb_sessions != 0 &&
13993                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
13994                         RTE_LOG(ERR, USER1,
13995                                         "Device does not support "
13996                                         "at least %u sessions\n",
13997                                         MAX_NB_SESSIONS);
13998                         return TEST_FAILED;
13999                 }
14000                 /*
14001                  * Create mempool with maximum number of sessions,
14002                  * to include the session headers
14003                  */
14004                 if (ts_params->session_mpool == NULL) {
14005                         ts_params->session_mpool =
14006                                 rte_cryptodev_sym_session_pool_create(
14007                                                 "test_sess_mp",
14008                                                 MAX_NB_SESSIONS, 0, 0, 0,
14009                                                 SOCKET_ID_ANY);
14010                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
14011                                         "session mempool allocation failed");
14012                 }
14013
14014                 /*
14015                  * Create mempool with maximum number of sessions,
14016                  * to include device specific session private data
14017                  */
14018                 if (ts_params->session_priv_mpool == NULL) {
14019                         ts_params->session_priv_mpool = rte_mempool_create(
14020                                         "test_sess_mp_priv",
14021                                         MAX_NB_SESSIONS,
14022                                         session_size,
14023                                         0, 0, NULL, NULL, NULL,
14024                                         NULL, SOCKET_ID_ANY,
14025                                         0);
14026
14027                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
14028                                         "session mempool allocation failed");
14029                 }
14030
14031                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
14032                 ts_params->qp_conf.mp_session_private =
14033                                 ts_params->session_priv_mpool;
14034
14035                 ret = rte_cryptodev_scheduler_worker_attach(sched_id,
14036                                 (uint8_t)i);
14037
14038                 TEST_ASSERT(ret == 0,
14039                         "Failed to attach device %u of pmd : %s", i,
14040                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14041
14042                 aesni_ids[nb_devs_attached] = (uint8_t)i;
14043
14044                 nb_devs_attached++;
14045         }
14046
14047         return 0;
14048 }
14049
14050 static int
14051 test_scheduler_detach_worker_op(void)
14052 {
14053         struct crypto_testsuite_params *ts_params = &testsuite_params;
14054         uint8_t sched_id = ts_params->valid_devs[0];
14055         uint32_t i;
14056         int ret;
14057
14058         for (i = 0; i < 2; i++) {
14059                 ret = rte_cryptodev_scheduler_worker_detach(sched_id,
14060                                 aesni_ids[i]);
14061                 TEST_ASSERT(ret == 0,
14062                         "Failed to detach device %u", aesni_ids[i]);
14063         }
14064
14065         return 0;
14066 }
14067
14068 static int
14069 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
14070 {
14071         struct crypto_testsuite_params *ts_params = &testsuite_params;
14072         uint8_t sched_id = ts_params->valid_devs[0];
14073         /* set mode */
14074         return rte_cryptodev_scheduler_mode_set(sched_id,
14075                 scheduler_mode);
14076 }
14077
14078 static int
14079 test_scheduler_mode_roundrobin_op(void)
14080 {
14081         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
14082                         0, "Failed to set roundrobin mode");
14083         return 0;
14084
14085 }
14086
14087 static int
14088 test_scheduler_mode_multicore_op(void)
14089 {
14090         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
14091                         0, "Failed to set multicore mode");
14092
14093         return 0;
14094 }
14095
14096 static int
14097 test_scheduler_mode_failover_op(void)
14098 {
14099         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
14100                         0, "Failed to set failover mode");
14101
14102         return 0;
14103 }
14104
14105 static int
14106 test_scheduler_mode_pkt_size_distr_op(void)
14107 {
14108         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
14109                         0, "Failed to set pktsize mode");
14110
14111         return 0;
14112 }
14113
14114 static int
14115 scheduler_multicore_testsuite_setup(void)
14116 {
14117         if (test_scheduler_attach_worker_op() < 0)
14118                 return TEST_SKIPPED;
14119         if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
14120                 return TEST_SKIPPED;
14121         return 0;
14122 }
14123
14124 static int
14125 scheduler_roundrobin_testsuite_setup(void)
14126 {
14127         if (test_scheduler_attach_worker_op() < 0)
14128                 return TEST_SKIPPED;
14129         if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
14130                 return TEST_SKIPPED;
14131         return 0;
14132 }
14133
14134 static int
14135 scheduler_failover_testsuite_setup(void)
14136 {
14137         if (test_scheduler_attach_worker_op() < 0)
14138                 return TEST_SKIPPED;
14139         if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
14140                 return TEST_SKIPPED;
14141         return 0;
14142 }
14143
14144 static int
14145 scheduler_pkt_size_distr_testsuite_setup(void)
14146 {
14147         if (test_scheduler_attach_worker_op() < 0)
14148                 return TEST_SKIPPED;
14149         if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
14150                 return TEST_SKIPPED;
14151         return 0;
14152 }
14153
14154 static void
14155 scheduler_mode_testsuite_teardown(void)
14156 {
14157         test_scheduler_detach_worker_op();
14158 }
14159
14160 #endif /* RTE_CRYPTO_SCHEDULER */
14161
14162 static struct unit_test_suite end_testsuite = {
14163         .suite_name = NULL,
14164         .setup = NULL,
14165         .teardown = NULL,
14166         .unit_test_suites = NULL
14167 };
14168
14169 #ifdef RTE_LIB_SECURITY
14170 static struct unit_test_suite ipsec_proto_testsuite  = {
14171         .suite_name = "IPsec Proto Unit Test Suite",
14172         .setup = ipsec_proto_testsuite_setup,
14173         .unit_test_cases = {
14174                 TEST_CASE_NAMED_WITH_DATA(
14175                         "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14176                         ut_setup_security, ut_teardown,
14177                         test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
14178                 TEST_CASE_NAMED_WITH_DATA(
14179                         "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14180                         ut_setup_security, ut_teardown,
14181                         test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
14182                 TEST_CASE_NAMED_WITH_DATA(
14183                         "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14184                         ut_setup_security, ut_teardown,
14185                         test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
14186                 TEST_CASE_NAMED_WITH_DATA(
14187                         "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14188                         ut_setup_security, ut_teardown,
14189                         test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
14190                 TEST_CASE_NAMED_WITH_DATA(
14191                         "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14192                         ut_setup_security, ut_teardown,
14193                         test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
14194                 TEST_CASE_NAMED_WITH_DATA(
14195                         "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14196                         ut_setup_security, ut_teardown,
14197                         test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
14198                 TEST_CASE_NAMED_ST(
14199                         "Combined test alg list",
14200                         ut_setup_security, ut_teardown,
14201                         test_ipsec_proto_display_list),
14202                 TEST_CASE_NAMED_ST(
14203                         "IV generation",
14204                         ut_setup_security, ut_teardown,
14205                         test_ipsec_proto_iv_gen),
14206                 TEST_CASE_NAMED_ST(
14207                         "UDP encapsulation",
14208                         ut_setup_security, ut_teardown,
14209                         test_ipsec_proto_udp_encap),
14210                 TEST_CASE_NAMED_ST(
14211                         "UDP encapsulation ports verification test",
14212                         ut_setup_security, ut_teardown,
14213                         test_ipsec_proto_udp_ports_verify),
14214                 TEST_CASE_NAMED_ST(
14215                         "SA expiry packets soft",
14216                         ut_setup_security, ut_teardown,
14217                         test_ipsec_proto_sa_exp_pkts_soft),
14218                 TEST_CASE_NAMED_ST(
14219                         "SA expiry packets hard",
14220                         ut_setup_security, ut_teardown,
14221                         test_ipsec_proto_sa_exp_pkts_hard),
14222                 TEST_CASE_NAMED_ST(
14223                         "Negative test: ICV corruption",
14224                         ut_setup_security, ut_teardown,
14225                         test_ipsec_proto_err_icv_corrupt),
14226                 TEST_CASE_NAMED_ST(
14227                         "Tunnel dst addr verification",
14228                         ut_setup_security, ut_teardown,
14229                         test_ipsec_proto_tunnel_dst_addr_verify),
14230                 TEST_CASE_NAMED_ST(
14231                         "Tunnel src and dst addr verification",
14232                         ut_setup_security, ut_teardown,
14233                         test_ipsec_proto_tunnel_src_dst_addr_verify),
14234                 TEST_CASES_END() /**< NULL terminate unit test array */
14235         }
14236 };
14237
14238 static struct unit_test_suite pdcp_proto_testsuite  = {
14239         .suite_name = "PDCP Proto Unit Test Suite",
14240         .setup = pdcp_proto_testsuite_setup,
14241         .unit_test_cases = {
14242                 TEST_CASE_ST(ut_setup_security, ut_teardown,
14243                         test_PDCP_PROTO_all),
14244                 TEST_CASES_END() /**< NULL terminate unit test array */
14245         }
14246 };
14247
14248 static struct unit_test_suite docsis_proto_testsuite  = {
14249         .suite_name = "Docsis Proto Unit Test Suite",
14250         .setup = docsis_proto_testsuite_setup,
14251         .unit_test_cases = {
14252                 TEST_CASE_ST(ut_setup_security, ut_teardown,
14253                         test_DOCSIS_PROTO_all),
14254                 TEST_CASES_END() /**< NULL terminate unit test array */
14255         }
14256 };
14257 #endif
14258
14259 static struct unit_test_suite cryptodev_gen_testsuite  = {
14260         .suite_name = "Crypto General Unit Test Suite",
14261         .setup = crypto_gen_testsuite_setup,
14262         .unit_test_cases = {
14263                 TEST_CASE_ST(ut_setup, ut_teardown,
14264                                 test_device_configure_invalid_dev_id),
14265                 TEST_CASE_ST(ut_setup, ut_teardown,
14266                                 test_queue_pair_descriptor_setup),
14267                 TEST_CASE_ST(ut_setup, ut_teardown,
14268                                 test_device_configure_invalid_queue_pair_ids),
14269                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
14270                 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
14271                 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
14272                 TEST_CASES_END() /**< NULL terminate unit test array */
14273         }
14274 };
14275
14276 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
14277         .suite_name = "Negative HMAC SHA1 Unit Test Suite",
14278         .setup = negative_hmac_sha1_testsuite_setup,
14279         .unit_test_cases = {
14280                 /** Negative tests */
14281                 TEST_CASE_ST(ut_setup, ut_teardown,
14282                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
14283                 TEST_CASE_ST(ut_setup, ut_teardown,
14284                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
14285                 TEST_CASE_ST(ut_setup, ut_teardown,
14286                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
14287                 TEST_CASE_ST(ut_setup, ut_teardown,
14288                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
14289
14290                 TEST_CASES_END() /**< NULL terminate unit test array */
14291         }
14292 };
14293
14294 static struct unit_test_suite cryptodev_multi_session_testsuite = {
14295         .suite_name = "Multi Session Unit Test Suite",
14296         .setup = multi_session_testsuite_setup,
14297         .unit_test_cases = {
14298                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
14299                 TEST_CASE_ST(ut_setup, ut_teardown,
14300                                 test_multi_session_random_usage),
14301
14302                 TEST_CASES_END() /**< NULL terminate unit test array */
14303         }
14304 };
14305
14306 static struct unit_test_suite cryptodev_null_testsuite  = {
14307         .suite_name = "NULL Test Suite",
14308         .setup = null_testsuite_setup,
14309         .unit_test_cases = {
14310                 TEST_CASE_ST(ut_setup, ut_teardown,
14311                         test_null_invalid_operation),
14312                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
14313                 TEST_CASES_END()
14314         }
14315 };
14316
14317 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
14318         .suite_name = "AES CCM Authenticated Test Suite",
14319         .setup = aes_ccm_auth_testsuite_setup,
14320         .unit_test_cases = {
14321                 /** AES CCM Authenticated Encryption 128 bits key*/
14322                 TEST_CASE_ST(ut_setup, ut_teardown,
14323                         test_AES_CCM_authenticated_encryption_test_case_128_1),
14324                 TEST_CASE_ST(ut_setup, ut_teardown,
14325                         test_AES_CCM_authenticated_encryption_test_case_128_2),
14326                 TEST_CASE_ST(ut_setup, ut_teardown,
14327                         test_AES_CCM_authenticated_encryption_test_case_128_3),
14328
14329                 /** AES CCM Authenticated Decryption 128 bits key*/
14330                 TEST_CASE_ST(ut_setup, ut_teardown,
14331                         test_AES_CCM_authenticated_decryption_test_case_128_1),
14332                 TEST_CASE_ST(ut_setup, ut_teardown,
14333                         test_AES_CCM_authenticated_decryption_test_case_128_2),
14334                 TEST_CASE_ST(ut_setup, ut_teardown,
14335                         test_AES_CCM_authenticated_decryption_test_case_128_3),
14336
14337                 /** AES CCM Authenticated Encryption 192 bits key */
14338                 TEST_CASE_ST(ut_setup, ut_teardown,
14339                         test_AES_CCM_authenticated_encryption_test_case_192_1),
14340                 TEST_CASE_ST(ut_setup, ut_teardown,
14341                         test_AES_CCM_authenticated_encryption_test_case_192_2),
14342                 TEST_CASE_ST(ut_setup, ut_teardown,
14343                         test_AES_CCM_authenticated_encryption_test_case_192_3),
14344
14345                 /** AES CCM Authenticated Decryption 192 bits key*/
14346                 TEST_CASE_ST(ut_setup, ut_teardown,
14347                         test_AES_CCM_authenticated_decryption_test_case_192_1),
14348                 TEST_CASE_ST(ut_setup, ut_teardown,
14349                         test_AES_CCM_authenticated_decryption_test_case_192_2),
14350                 TEST_CASE_ST(ut_setup, ut_teardown,
14351                         test_AES_CCM_authenticated_decryption_test_case_192_3),
14352
14353                 /** AES CCM Authenticated Encryption 256 bits key */
14354                 TEST_CASE_ST(ut_setup, ut_teardown,
14355                         test_AES_CCM_authenticated_encryption_test_case_256_1),
14356                 TEST_CASE_ST(ut_setup, ut_teardown,
14357                         test_AES_CCM_authenticated_encryption_test_case_256_2),
14358                 TEST_CASE_ST(ut_setup, ut_teardown,
14359                         test_AES_CCM_authenticated_encryption_test_case_256_3),
14360
14361                 /** AES CCM Authenticated Decryption 256 bits key*/
14362                 TEST_CASE_ST(ut_setup, ut_teardown,
14363                         test_AES_CCM_authenticated_decryption_test_case_256_1),
14364                 TEST_CASE_ST(ut_setup, ut_teardown,
14365                         test_AES_CCM_authenticated_decryption_test_case_256_2),
14366                 TEST_CASE_ST(ut_setup, ut_teardown,
14367                         test_AES_CCM_authenticated_decryption_test_case_256_3),
14368                 TEST_CASES_END()
14369         }
14370 };
14371
14372 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
14373         .suite_name = "AES GCM Authenticated Test Suite",
14374         .setup = aes_gcm_auth_testsuite_setup,
14375         .unit_test_cases = {
14376                 /** AES GCM Authenticated Encryption */
14377                 TEST_CASE_ST(ut_setup, ut_teardown,
14378                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
14379                 TEST_CASE_ST(ut_setup, ut_teardown,
14380                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
14381                 TEST_CASE_ST(ut_setup, ut_teardown,
14382                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
14383                 TEST_CASE_ST(ut_setup, ut_teardown,
14384                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
14385                 TEST_CASE_ST(ut_setup, ut_teardown,
14386                         test_AES_GCM_authenticated_encryption_test_case_1),
14387                 TEST_CASE_ST(ut_setup, ut_teardown,
14388                         test_AES_GCM_authenticated_encryption_test_case_2),
14389                 TEST_CASE_ST(ut_setup, ut_teardown,
14390                         test_AES_GCM_authenticated_encryption_test_case_3),
14391                 TEST_CASE_ST(ut_setup, ut_teardown,
14392                         test_AES_GCM_authenticated_encryption_test_case_4),
14393                 TEST_CASE_ST(ut_setup, ut_teardown,
14394                         test_AES_GCM_authenticated_encryption_test_case_5),
14395                 TEST_CASE_ST(ut_setup, ut_teardown,
14396                         test_AES_GCM_authenticated_encryption_test_case_6),
14397                 TEST_CASE_ST(ut_setup, ut_teardown,
14398                         test_AES_GCM_authenticated_encryption_test_case_7),
14399                 TEST_CASE_ST(ut_setup, ut_teardown,
14400                         test_AES_GCM_authenticated_encryption_test_case_8),
14401                 TEST_CASE_ST(ut_setup, ut_teardown,
14402                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
14403
14404                 /** AES GCM Authenticated Decryption */
14405                 TEST_CASE_ST(ut_setup, ut_teardown,
14406                         test_AES_GCM_authenticated_decryption_test_case_1),
14407                 TEST_CASE_ST(ut_setup, ut_teardown,
14408                         test_AES_GCM_authenticated_decryption_test_case_2),
14409                 TEST_CASE_ST(ut_setup, ut_teardown,
14410                         test_AES_GCM_authenticated_decryption_test_case_3),
14411                 TEST_CASE_ST(ut_setup, ut_teardown,
14412                         test_AES_GCM_authenticated_decryption_test_case_4),
14413                 TEST_CASE_ST(ut_setup, ut_teardown,
14414                         test_AES_GCM_authenticated_decryption_test_case_5),
14415                 TEST_CASE_ST(ut_setup, ut_teardown,
14416                         test_AES_GCM_authenticated_decryption_test_case_6),
14417                 TEST_CASE_ST(ut_setup, ut_teardown,
14418                         test_AES_GCM_authenticated_decryption_test_case_7),
14419                 TEST_CASE_ST(ut_setup, ut_teardown,
14420                         test_AES_GCM_authenticated_decryption_test_case_8),
14421                 TEST_CASE_ST(ut_setup, ut_teardown,
14422                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
14423
14424                 /** AES GCM Authenticated Encryption 192 bits key */
14425                 TEST_CASE_ST(ut_setup, ut_teardown,
14426                         test_AES_GCM_auth_encryption_test_case_192_1),
14427                 TEST_CASE_ST(ut_setup, ut_teardown,
14428                         test_AES_GCM_auth_encryption_test_case_192_2),
14429                 TEST_CASE_ST(ut_setup, ut_teardown,
14430                         test_AES_GCM_auth_encryption_test_case_192_3),
14431                 TEST_CASE_ST(ut_setup, ut_teardown,
14432                         test_AES_GCM_auth_encryption_test_case_192_4),
14433                 TEST_CASE_ST(ut_setup, ut_teardown,
14434                         test_AES_GCM_auth_encryption_test_case_192_5),
14435                 TEST_CASE_ST(ut_setup, ut_teardown,
14436                         test_AES_GCM_auth_encryption_test_case_192_6),
14437                 TEST_CASE_ST(ut_setup, ut_teardown,
14438                         test_AES_GCM_auth_encryption_test_case_192_7),
14439
14440                 /** AES GCM Authenticated Decryption 192 bits key */
14441                 TEST_CASE_ST(ut_setup, ut_teardown,
14442                         test_AES_GCM_auth_decryption_test_case_192_1),
14443                 TEST_CASE_ST(ut_setup, ut_teardown,
14444                         test_AES_GCM_auth_decryption_test_case_192_2),
14445                 TEST_CASE_ST(ut_setup, ut_teardown,
14446                         test_AES_GCM_auth_decryption_test_case_192_3),
14447                 TEST_CASE_ST(ut_setup, ut_teardown,
14448                         test_AES_GCM_auth_decryption_test_case_192_4),
14449                 TEST_CASE_ST(ut_setup, ut_teardown,
14450                         test_AES_GCM_auth_decryption_test_case_192_5),
14451                 TEST_CASE_ST(ut_setup, ut_teardown,
14452                         test_AES_GCM_auth_decryption_test_case_192_6),
14453                 TEST_CASE_ST(ut_setup, ut_teardown,
14454                         test_AES_GCM_auth_decryption_test_case_192_7),
14455
14456                 /** AES GCM Authenticated Encryption 256 bits key */
14457                 TEST_CASE_ST(ut_setup, ut_teardown,
14458                         test_AES_GCM_auth_encryption_test_case_256_1),
14459                 TEST_CASE_ST(ut_setup, ut_teardown,
14460                         test_AES_GCM_auth_encryption_test_case_256_2),
14461                 TEST_CASE_ST(ut_setup, ut_teardown,
14462                         test_AES_GCM_auth_encryption_test_case_256_3),
14463                 TEST_CASE_ST(ut_setup, ut_teardown,
14464                         test_AES_GCM_auth_encryption_test_case_256_4),
14465                 TEST_CASE_ST(ut_setup, ut_teardown,
14466                         test_AES_GCM_auth_encryption_test_case_256_5),
14467                 TEST_CASE_ST(ut_setup, ut_teardown,
14468                         test_AES_GCM_auth_encryption_test_case_256_6),
14469                 TEST_CASE_ST(ut_setup, ut_teardown,
14470                         test_AES_GCM_auth_encryption_test_case_256_7),
14471
14472                 /** AES GCM Authenticated Decryption 256 bits key */
14473                 TEST_CASE_ST(ut_setup, ut_teardown,
14474                         test_AES_GCM_auth_decryption_test_case_256_1),
14475                 TEST_CASE_ST(ut_setup, ut_teardown,
14476                         test_AES_GCM_auth_decryption_test_case_256_2),
14477                 TEST_CASE_ST(ut_setup, ut_teardown,
14478                         test_AES_GCM_auth_decryption_test_case_256_3),
14479                 TEST_CASE_ST(ut_setup, ut_teardown,
14480                         test_AES_GCM_auth_decryption_test_case_256_4),
14481                 TEST_CASE_ST(ut_setup, ut_teardown,
14482                         test_AES_GCM_auth_decryption_test_case_256_5),
14483                 TEST_CASE_ST(ut_setup, ut_teardown,
14484                         test_AES_GCM_auth_decryption_test_case_256_6),
14485                 TEST_CASE_ST(ut_setup, ut_teardown,
14486                         test_AES_GCM_auth_decryption_test_case_256_7),
14487
14488                 /** AES GCM Authenticated Encryption big aad size */
14489                 TEST_CASE_ST(ut_setup, ut_teardown,
14490                         test_AES_GCM_auth_encryption_test_case_aad_1),
14491                 TEST_CASE_ST(ut_setup, ut_teardown,
14492                         test_AES_GCM_auth_encryption_test_case_aad_2),
14493
14494                 /** AES GCM Authenticated Decryption big aad size */
14495                 TEST_CASE_ST(ut_setup, ut_teardown,
14496                         test_AES_GCM_auth_decryption_test_case_aad_1),
14497                 TEST_CASE_ST(ut_setup, ut_teardown,
14498                         test_AES_GCM_auth_decryption_test_case_aad_2),
14499
14500                 /** Out of place tests */
14501                 TEST_CASE_ST(ut_setup, ut_teardown,
14502                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
14503                 TEST_CASE_ST(ut_setup, ut_teardown,
14504                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
14505
14506                 /** Session-less tests */
14507                 TEST_CASE_ST(ut_setup, ut_teardown,
14508                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
14509                 TEST_CASE_ST(ut_setup, ut_teardown,
14510                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
14511
14512                 TEST_CASES_END()
14513         }
14514 };
14515
14516 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
14517         .suite_name = "AES GMAC Authentication Test Suite",
14518         .setup = aes_gmac_auth_testsuite_setup,
14519         .unit_test_cases = {
14520                 TEST_CASE_ST(ut_setup, ut_teardown,
14521                         test_AES_GMAC_authentication_test_case_1),
14522                 TEST_CASE_ST(ut_setup, ut_teardown,
14523                         test_AES_GMAC_authentication_verify_test_case_1),
14524                 TEST_CASE_ST(ut_setup, ut_teardown,
14525                         test_AES_GMAC_authentication_test_case_2),
14526                 TEST_CASE_ST(ut_setup, ut_teardown,
14527                         test_AES_GMAC_authentication_verify_test_case_2),
14528                 TEST_CASE_ST(ut_setup, ut_teardown,
14529                         test_AES_GMAC_authentication_test_case_3),
14530                 TEST_CASE_ST(ut_setup, ut_teardown,
14531                         test_AES_GMAC_authentication_verify_test_case_3),
14532                 TEST_CASE_ST(ut_setup, ut_teardown,
14533                         test_AES_GMAC_authentication_test_case_4),
14534                 TEST_CASE_ST(ut_setup, ut_teardown,
14535                         test_AES_GMAC_authentication_verify_test_case_4),
14536                 TEST_CASE_ST(ut_setup, ut_teardown,
14537                         test_AES_GMAC_authentication_SGL_40B),
14538                 TEST_CASE_ST(ut_setup, ut_teardown,
14539                         test_AES_GMAC_authentication_SGL_80B),
14540                 TEST_CASE_ST(ut_setup, ut_teardown,
14541                         test_AES_GMAC_authentication_SGL_2048B),
14542                 TEST_CASE_ST(ut_setup, ut_teardown,
14543                         test_AES_GMAC_authentication_SGL_2047B),
14544
14545                 TEST_CASES_END()
14546         }
14547 };
14548
14549 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14550         .suite_name = "Chacha20-Poly1305 Test Suite",
14551         .setup = chacha20_poly1305_testsuite_setup,
14552         .unit_test_cases = {
14553                 TEST_CASE_ST(ut_setup, ut_teardown,
14554                         test_chacha20_poly1305_encrypt_test_case_rfc8439),
14555                 TEST_CASE_ST(ut_setup, ut_teardown,
14556                         test_chacha20_poly1305_decrypt_test_case_rfc8439),
14557                 TEST_CASES_END()
14558         }
14559 };
14560
14561 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14562         .suite_name = "SNOW 3G Test Suite",
14563         .setup = snow3g_testsuite_setup,
14564         .unit_test_cases = {
14565                 /** SNOW 3G encrypt only (UEA2) */
14566                 TEST_CASE_ST(ut_setup, ut_teardown,
14567                         test_snow3g_encryption_test_case_1),
14568                 TEST_CASE_ST(ut_setup, ut_teardown,
14569                         test_snow3g_encryption_test_case_2),
14570                 TEST_CASE_ST(ut_setup, ut_teardown,
14571                         test_snow3g_encryption_test_case_3),
14572                 TEST_CASE_ST(ut_setup, ut_teardown,
14573                         test_snow3g_encryption_test_case_4),
14574                 TEST_CASE_ST(ut_setup, ut_teardown,
14575                         test_snow3g_encryption_test_case_5),
14576
14577                 TEST_CASE_ST(ut_setup, ut_teardown,
14578                         test_snow3g_encryption_test_case_1_oop),
14579                 TEST_CASE_ST(ut_setup, ut_teardown,
14580                         test_snow3g_encryption_test_case_1_oop_sgl),
14581                 TEST_CASE_ST(ut_setup, ut_teardown,
14582                         test_snow3g_encryption_test_case_1_offset_oop),
14583                 TEST_CASE_ST(ut_setup, ut_teardown,
14584                         test_snow3g_decryption_test_case_1_oop),
14585
14586                 /** SNOW 3G generate auth, then encrypt (UEA2) */
14587                 TEST_CASE_ST(ut_setup, ut_teardown,
14588                         test_snow3g_auth_cipher_test_case_1),
14589                 TEST_CASE_ST(ut_setup, ut_teardown,
14590                         test_snow3g_auth_cipher_test_case_2),
14591                 TEST_CASE_ST(ut_setup, ut_teardown,
14592                         test_snow3g_auth_cipher_test_case_2_oop),
14593                 TEST_CASE_ST(ut_setup, ut_teardown,
14594                         test_snow3g_auth_cipher_part_digest_enc),
14595                 TEST_CASE_ST(ut_setup, ut_teardown,
14596                         test_snow3g_auth_cipher_part_digest_enc_oop),
14597                 TEST_CASE_ST(ut_setup, ut_teardown,
14598                         test_snow3g_auth_cipher_test_case_3_sgl),
14599                 TEST_CASE_ST(ut_setup, ut_teardown,
14600                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
14601                 TEST_CASE_ST(ut_setup, ut_teardown,
14602                         test_snow3g_auth_cipher_part_digest_enc_sgl),
14603                 TEST_CASE_ST(ut_setup, ut_teardown,
14604                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14605
14606                 /** SNOW 3G decrypt (UEA2), then verify auth */
14607                 TEST_CASE_ST(ut_setup, ut_teardown,
14608                         test_snow3g_auth_cipher_verify_test_case_1),
14609                 TEST_CASE_ST(ut_setup, ut_teardown,
14610                         test_snow3g_auth_cipher_verify_test_case_2),
14611                 TEST_CASE_ST(ut_setup, ut_teardown,
14612                         test_snow3g_auth_cipher_verify_test_case_2_oop),
14613                 TEST_CASE_ST(ut_setup, ut_teardown,
14614                         test_snow3g_auth_cipher_verify_part_digest_enc),
14615                 TEST_CASE_ST(ut_setup, ut_teardown,
14616                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14617                 TEST_CASE_ST(ut_setup, ut_teardown,
14618                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
14619                 TEST_CASE_ST(ut_setup, ut_teardown,
14620                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14621                 TEST_CASE_ST(ut_setup, ut_teardown,
14622                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14623                 TEST_CASE_ST(ut_setup, ut_teardown,
14624                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14625
14626                 /** SNOW 3G decrypt only (UEA2) */
14627                 TEST_CASE_ST(ut_setup, ut_teardown,
14628                         test_snow3g_decryption_test_case_1),
14629                 TEST_CASE_ST(ut_setup, ut_teardown,
14630                         test_snow3g_decryption_test_case_2),
14631                 TEST_CASE_ST(ut_setup, ut_teardown,
14632                         test_snow3g_decryption_test_case_3),
14633                 TEST_CASE_ST(ut_setup, ut_teardown,
14634                         test_snow3g_decryption_test_case_4),
14635                 TEST_CASE_ST(ut_setup, ut_teardown,
14636                         test_snow3g_decryption_test_case_5),
14637                 TEST_CASE_ST(ut_setup, ut_teardown,
14638                         test_snow3g_decryption_with_digest_test_case_1),
14639                 TEST_CASE_ST(ut_setup, ut_teardown,
14640                         test_snow3g_hash_generate_test_case_1),
14641                 TEST_CASE_ST(ut_setup, ut_teardown,
14642                         test_snow3g_hash_generate_test_case_2),
14643                 TEST_CASE_ST(ut_setup, ut_teardown,
14644                         test_snow3g_hash_generate_test_case_3),
14645
14646                 /* Tests with buffers which length is not byte-aligned */
14647                 TEST_CASE_ST(ut_setup, ut_teardown,
14648                         test_snow3g_hash_generate_test_case_4),
14649                 TEST_CASE_ST(ut_setup, ut_teardown,
14650                         test_snow3g_hash_generate_test_case_5),
14651                 TEST_CASE_ST(ut_setup, ut_teardown,
14652                         test_snow3g_hash_generate_test_case_6),
14653                 TEST_CASE_ST(ut_setup, ut_teardown,
14654                         test_snow3g_hash_verify_test_case_1),
14655                 TEST_CASE_ST(ut_setup, ut_teardown,
14656                         test_snow3g_hash_verify_test_case_2),
14657                 TEST_CASE_ST(ut_setup, ut_teardown,
14658                         test_snow3g_hash_verify_test_case_3),
14659
14660                 /* Tests with buffers which length is not byte-aligned */
14661                 TEST_CASE_ST(ut_setup, ut_teardown,
14662                         test_snow3g_hash_verify_test_case_4),
14663                 TEST_CASE_ST(ut_setup, ut_teardown,
14664                         test_snow3g_hash_verify_test_case_5),
14665                 TEST_CASE_ST(ut_setup, ut_teardown,
14666                         test_snow3g_hash_verify_test_case_6),
14667                 TEST_CASE_ST(ut_setup, ut_teardown,
14668                         test_snow3g_cipher_auth_test_case_1),
14669                 TEST_CASE_ST(ut_setup, ut_teardown,
14670                         test_snow3g_auth_cipher_with_digest_test_case_1),
14671                 TEST_CASES_END()
14672         }
14673 };
14674
14675 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14676         .suite_name = "ZUC Test Suite",
14677         .setup = zuc_testsuite_setup,
14678         .unit_test_cases = {
14679                 /** ZUC encrypt only (EEA3) */
14680                 TEST_CASE_ST(ut_setup, ut_teardown,
14681                         test_zuc_encryption_test_case_1),
14682                 TEST_CASE_ST(ut_setup, ut_teardown,
14683                         test_zuc_encryption_test_case_2),
14684                 TEST_CASE_ST(ut_setup, ut_teardown,
14685                         test_zuc_encryption_test_case_3),
14686                 TEST_CASE_ST(ut_setup, ut_teardown,
14687                         test_zuc_encryption_test_case_4),
14688                 TEST_CASE_ST(ut_setup, ut_teardown,
14689                         test_zuc_encryption_test_case_5),
14690                 TEST_CASE_ST(ut_setup, ut_teardown,
14691                         test_zuc_encryption_test_case_6_sgl),
14692
14693                 /** ZUC authenticate (EIA3) */
14694                 TEST_CASE_ST(ut_setup, ut_teardown,
14695                         test_zuc_hash_generate_test_case_1),
14696                 TEST_CASE_ST(ut_setup, ut_teardown,
14697                         test_zuc_hash_generate_test_case_2),
14698                 TEST_CASE_ST(ut_setup, ut_teardown,
14699                         test_zuc_hash_generate_test_case_3),
14700                 TEST_CASE_ST(ut_setup, ut_teardown,
14701                         test_zuc_hash_generate_test_case_4),
14702                 TEST_CASE_ST(ut_setup, ut_teardown,
14703                         test_zuc_hash_generate_test_case_5),
14704                 TEST_CASE_ST(ut_setup, ut_teardown,
14705                         test_zuc_hash_generate_test_case_6),
14706                 TEST_CASE_ST(ut_setup, ut_teardown,
14707                         test_zuc_hash_generate_test_case_7),
14708                 TEST_CASE_ST(ut_setup, ut_teardown,
14709                         test_zuc_hash_generate_test_case_8),
14710
14711                 /** ZUC alg-chain (EEA3/EIA3) */
14712                 TEST_CASE_ST(ut_setup, ut_teardown,
14713                         test_zuc_cipher_auth_test_case_1),
14714                 TEST_CASE_ST(ut_setup, ut_teardown,
14715                         test_zuc_cipher_auth_test_case_2),
14716
14717                 /** ZUC generate auth, then encrypt (EEA3) */
14718                 TEST_CASE_ST(ut_setup, ut_teardown,
14719                         test_zuc_auth_cipher_test_case_1),
14720                 TEST_CASE_ST(ut_setup, ut_teardown,
14721                         test_zuc_auth_cipher_test_case_1_oop),
14722                 TEST_CASE_ST(ut_setup, ut_teardown,
14723                         test_zuc_auth_cipher_test_case_1_sgl),
14724                 TEST_CASE_ST(ut_setup, ut_teardown,
14725                         test_zuc_auth_cipher_test_case_1_oop_sgl),
14726
14727                 /** ZUC decrypt (EEA3), then verify auth */
14728                 TEST_CASE_ST(ut_setup, ut_teardown,
14729                         test_zuc_auth_cipher_verify_test_case_1),
14730                 TEST_CASE_ST(ut_setup, ut_teardown,
14731                         test_zuc_auth_cipher_verify_test_case_1_oop),
14732                 TEST_CASE_ST(ut_setup, ut_teardown,
14733                         test_zuc_auth_cipher_verify_test_case_1_sgl),
14734                 TEST_CASE_ST(ut_setup, ut_teardown,
14735                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
14736                 TEST_CASES_END()
14737         }
14738 };
14739
14740 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
14741         .suite_name = "HMAC_MD5 Authentication Test Suite",
14742         .setup = hmac_md5_auth_testsuite_setup,
14743         .unit_test_cases = {
14744                 TEST_CASE_ST(ut_setup, ut_teardown,
14745                         test_MD5_HMAC_generate_case_1),
14746                 TEST_CASE_ST(ut_setup, ut_teardown,
14747                         test_MD5_HMAC_verify_case_1),
14748                 TEST_CASE_ST(ut_setup, ut_teardown,
14749                         test_MD5_HMAC_generate_case_2),
14750                 TEST_CASE_ST(ut_setup, ut_teardown,
14751                         test_MD5_HMAC_verify_case_2),
14752                 TEST_CASES_END()
14753         }
14754 };
14755
14756 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
14757         .suite_name = "Kasumi Test Suite",
14758         .setup = kasumi_testsuite_setup,
14759         .unit_test_cases = {
14760                 /** KASUMI hash only (UIA1) */
14761                 TEST_CASE_ST(ut_setup, ut_teardown,
14762                         test_kasumi_hash_generate_test_case_1),
14763                 TEST_CASE_ST(ut_setup, ut_teardown,
14764                         test_kasumi_hash_generate_test_case_2),
14765                 TEST_CASE_ST(ut_setup, ut_teardown,
14766                         test_kasumi_hash_generate_test_case_3),
14767                 TEST_CASE_ST(ut_setup, ut_teardown,
14768                         test_kasumi_hash_generate_test_case_4),
14769                 TEST_CASE_ST(ut_setup, ut_teardown,
14770                         test_kasumi_hash_generate_test_case_5),
14771                 TEST_CASE_ST(ut_setup, ut_teardown,
14772                         test_kasumi_hash_generate_test_case_6),
14773
14774                 TEST_CASE_ST(ut_setup, ut_teardown,
14775                         test_kasumi_hash_verify_test_case_1),
14776                 TEST_CASE_ST(ut_setup, ut_teardown,
14777                         test_kasumi_hash_verify_test_case_2),
14778                 TEST_CASE_ST(ut_setup, ut_teardown,
14779                         test_kasumi_hash_verify_test_case_3),
14780                 TEST_CASE_ST(ut_setup, ut_teardown,
14781                         test_kasumi_hash_verify_test_case_4),
14782                 TEST_CASE_ST(ut_setup, ut_teardown,
14783                         test_kasumi_hash_verify_test_case_5),
14784
14785                 /** KASUMI encrypt only (UEA1) */
14786                 TEST_CASE_ST(ut_setup, ut_teardown,
14787                         test_kasumi_encryption_test_case_1),
14788                 TEST_CASE_ST(ut_setup, ut_teardown,
14789                         test_kasumi_encryption_test_case_1_sgl),
14790                 TEST_CASE_ST(ut_setup, ut_teardown,
14791                         test_kasumi_encryption_test_case_1_oop),
14792                 TEST_CASE_ST(ut_setup, ut_teardown,
14793                         test_kasumi_encryption_test_case_1_oop_sgl),
14794                 TEST_CASE_ST(ut_setup, ut_teardown,
14795                         test_kasumi_encryption_test_case_2),
14796                 TEST_CASE_ST(ut_setup, ut_teardown,
14797                         test_kasumi_encryption_test_case_3),
14798                 TEST_CASE_ST(ut_setup, ut_teardown,
14799                         test_kasumi_encryption_test_case_4),
14800                 TEST_CASE_ST(ut_setup, ut_teardown,
14801                         test_kasumi_encryption_test_case_5),
14802
14803                 /** KASUMI decrypt only (UEA1) */
14804                 TEST_CASE_ST(ut_setup, ut_teardown,
14805                         test_kasumi_decryption_test_case_1),
14806                 TEST_CASE_ST(ut_setup, ut_teardown,
14807                         test_kasumi_decryption_test_case_2),
14808                 TEST_CASE_ST(ut_setup, ut_teardown,
14809                         test_kasumi_decryption_test_case_3),
14810                 TEST_CASE_ST(ut_setup, ut_teardown,
14811                         test_kasumi_decryption_test_case_4),
14812                 TEST_CASE_ST(ut_setup, ut_teardown,
14813                         test_kasumi_decryption_test_case_5),
14814                 TEST_CASE_ST(ut_setup, ut_teardown,
14815                         test_kasumi_decryption_test_case_1_oop),
14816                 TEST_CASE_ST(ut_setup, ut_teardown,
14817                         test_kasumi_cipher_auth_test_case_1),
14818
14819                 /** KASUMI generate auth, then encrypt (F8) */
14820                 TEST_CASE_ST(ut_setup, ut_teardown,
14821                         test_kasumi_auth_cipher_test_case_1),
14822                 TEST_CASE_ST(ut_setup, ut_teardown,
14823                         test_kasumi_auth_cipher_test_case_2),
14824                 TEST_CASE_ST(ut_setup, ut_teardown,
14825                         test_kasumi_auth_cipher_test_case_2_oop),
14826                 TEST_CASE_ST(ut_setup, ut_teardown,
14827                         test_kasumi_auth_cipher_test_case_2_sgl),
14828                 TEST_CASE_ST(ut_setup, ut_teardown,
14829                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
14830
14831                 /** KASUMI decrypt (F8), then verify auth */
14832                 TEST_CASE_ST(ut_setup, ut_teardown,
14833                         test_kasumi_auth_cipher_verify_test_case_1),
14834                 TEST_CASE_ST(ut_setup, ut_teardown,
14835                         test_kasumi_auth_cipher_verify_test_case_2),
14836                 TEST_CASE_ST(ut_setup, ut_teardown,
14837                         test_kasumi_auth_cipher_verify_test_case_2_oop),
14838                 TEST_CASE_ST(ut_setup, ut_teardown,
14839                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
14840                 TEST_CASE_ST(ut_setup, ut_teardown,
14841                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
14842
14843                 TEST_CASES_END()
14844         }
14845 };
14846
14847 static struct unit_test_suite cryptodev_esn_testsuite  = {
14848         .suite_name = "ESN Test Suite",
14849         .setup = esn_testsuite_setup,
14850         .unit_test_cases = {
14851                 TEST_CASE_ST(ut_setup, ut_teardown,
14852                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
14853                 TEST_CASE_ST(ut_setup, ut_teardown,
14854                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
14855                 TEST_CASES_END()
14856         }
14857 };
14858
14859 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
14860         .suite_name = "Negative AES GCM Test Suite",
14861         .setup = negative_aes_gcm_testsuite_setup,
14862         .unit_test_cases = {
14863                 TEST_CASE_ST(ut_setup, ut_teardown,
14864                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
14865                 TEST_CASE_ST(ut_setup, ut_teardown,
14866                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
14867                 TEST_CASE_ST(ut_setup, ut_teardown,
14868                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
14869                 TEST_CASE_ST(ut_setup, ut_teardown,
14870                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
14871                 TEST_CASE_ST(ut_setup, ut_teardown,
14872                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
14873                 TEST_CASE_ST(ut_setup, ut_teardown,
14874                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
14875                 TEST_CASE_ST(ut_setup, ut_teardown,
14876                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
14877                 TEST_CASE_ST(ut_setup, ut_teardown,
14878                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
14879                 TEST_CASE_ST(ut_setup, ut_teardown,
14880                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
14881                 TEST_CASE_ST(ut_setup, ut_teardown,
14882                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
14883                 TEST_CASE_ST(ut_setup, ut_teardown,
14884                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
14885                 TEST_CASE_ST(ut_setup, ut_teardown,
14886                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
14887
14888                 TEST_CASES_END()
14889         }
14890 };
14891
14892 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
14893         .suite_name = "Negative AES GMAC Test Suite",
14894         .setup = negative_aes_gmac_testsuite_setup,
14895         .unit_test_cases = {
14896                 TEST_CASE_ST(ut_setup, ut_teardown,
14897                         authentication_verify_AES128_GMAC_fail_data_corrupt),
14898                 TEST_CASE_ST(ut_setup, ut_teardown,
14899                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
14900
14901                 TEST_CASES_END()
14902         }
14903 };
14904
14905 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
14906         .suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
14907         .setup = mixed_cipher_hash_testsuite_setup,
14908         .unit_test_cases = {
14909                 /** AUTH AES CMAC + CIPHER AES CTR */
14910                 TEST_CASE_ST(ut_setup, ut_teardown,
14911                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
14912                 TEST_CASE_ST(ut_setup, ut_teardown,
14913                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14914                 TEST_CASE_ST(ut_setup, ut_teardown,
14915                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14916                 TEST_CASE_ST(ut_setup, ut_teardown,
14917                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14918                 TEST_CASE_ST(ut_setup, ut_teardown,
14919                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
14920                 TEST_CASE_ST(ut_setup, ut_teardown,
14921                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14922                 TEST_CASE_ST(ut_setup, ut_teardown,
14923                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14924                 TEST_CASE_ST(ut_setup, ut_teardown,
14925                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14926
14927                 /** AUTH ZUC + CIPHER SNOW3G */
14928                 TEST_CASE_ST(ut_setup, ut_teardown,
14929                         test_auth_zuc_cipher_snow_test_case_1),
14930                 TEST_CASE_ST(ut_setup, ut_teardown,
14931                         test_verify_auth_zuc_cipher_snow_test_case_1),
14932                 /** AUTH AES CMAC + CIPHER SNOW3G */
14933                 TEST_CASE_ST(ut_setup, ut_teardown,
14934                         test_auth_aes_cmac_cipher_snow_test_case_1),
14935                 TEST_CASE_ST(ut_setup, ut_teardown,
14936                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
14937                 /** AUTH ZUC + CIPHER AES CTR */
14938                 TEST_CASE_ST(ut_setup, ut_teardown,
14939                         test_auth_zuc_cipher_aes_ctr_test_case_1),
14940                 TEST_CASE_ST(ut_setup, ut_teardown,
14941                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
14942                 /** AUTH SNOW3G + CIPHER AES CTR */
14943                 TEST_CASE_ST(ut_setup, ut_teardown,
14944                         test_auth_snow_cipher_aes_ctr_test_case_1),
14945                 TEST_CASE_ST(ut_setup, ut_teardown,
14946                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
14947                 /** AUTH SNOW3G + CIPHER ZUC */
14948                 TEST_CASE_ST(ut_setup, ut_teardown,
14949                         test_auth_snow_cipher_zuc_test_case_1),
14950                 TEST_CASE_ST(ut_setup, ut_teardown,
14951                         test_verify_auth_snow_cipher_zuc_test_case_1),
14952                 /** AUTH AES CMAC + CIPHER ZUC */
14953                 TEST_CASE_ST(ut_setup, ut_teardown,
14954                         test_auth_aes_cmac_cipher_zuc_test_case_1),
14955                 TEST_CASE_ST(ut_setup, ut_teardown,
14956                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
14957
14958                 /** AUTH NULL + CIPHER SNOW3G */
14959                 TEST_CASE_ST(ut_setup, ut_teardown,
14960                         test_auth_null_cipher_snow_test_case_1),
14961                 TEST_CASE_ST(ut_setup, ut_teardown,
14962                         test_verify_auth_null_cipher_snow_test_case_1),
14963                 /** AUTH NULL + CIPHER ZUC */
14964                 TEST_CASE_ST(ut_setup, ut_teardown,
14965                         test_auth_null_cipher_zuc_test_case_1),
14966                 TEST_CASE_ST(ut_setup, ut_teardown,
14967                         test_verify_auth_null_cipher_zuc_test_case_1),
14968                 /** AUTH SNOW3G + CIPHER NULL */
14969                 TEST_CASE_ST(ut_setup, ut_teardown,
14970                         test_auth_snow_cipher_null_test_case_1),
14971                 TEST_CASE_ST(ut_setup, ut_teardown,
14972                         test_verify_auth_snow_cipher_null_test_case_1),
14973                 /** AUTH ZUC + CIPHER NULL */
14974                 TEST_CASE_ST(ut_setup, ut_teardown,
14975                         test_auth_zuc_cipher_null_test_case_1),
14976                 TEST_CASE_ST(ut_setup, ut_teardown,
14977                         test_verify_auth_zuc_cipher_null_test_case_1),
14978                 /** AUTH NULL + CIPHER AES CTR */
14979                 TEST_CASE_ST(ut_setup, ut_teardown,
14980                         test_auth_null_cipher_aes_ctr_test_case_1),
14981                 TEST_CASE_ST(ut_setup, ut_teardown,
14982                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
14983                 /** AUTH AES CMAC + CIPHER NULL */
14984                 TEST_CASE_ST(ut_setup, ut_teardown,
14985                         test_auth_aes_cmac_cipher_null_test_case_1),
14986                 TEST_CASE_ST(ut_setup, ut_teardown,
14987                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
14988                 TEST_CASES_END()
14989         }
14990 };
14991
14992 static int
14993 run_cryptodev_testsuite(const char *pmd_name)
14994 {
14995         uint8_t ret, j, i = 0, blk_start_idx = 0;
14996         const enum blockcipher_test_type blk_suites[] = {
14997                 BLKCIPHER_AES_CHAIN_TYPE,
14998                 BLKCIPHER_AES_CIPHERONLY_TYPE,
14999                 BLKCIPHER_AES_DOCSIS_TYPE,
15000                 BLKCIPHER_3DES_CHAIN_TYPE,
15001                 BLKCIPHER_3DES_CIPHERONLY_TYPE,
15002                 BLKCIPHER_DES_CIPHERONLY_TYPE,
15003                 BLKCIPHER_DES_DOCSIS_TYPE,
15004                 BLKCIPHER_AUTHONLY_TYPE};
15005         struct unit_test_suite *static_suites[] = {
15006                 &cryptodev_multi_session_testsuite,
15007                 &cryptodev_null_testsuite,
15008                 &cryptodev_aes_ccm_auth_testsuite,
15009                 &cryptodev_aes_gcm_auth_testsuite,
15010                 &cryptodev_aes_gmac_auth_testsuite,
15011                 &cryptodev_snow3g_testsuite,
15012                 &cryptodev_chacha20_poly1305_testsuite,
15013                 &cryptodev_zuc_testsuite,
15014                 &cryptodev_hmac_md5_auth_testsuite,
15015                 &cryptodev_kasumi_testsuite,
15016                 &cryptodev_esn_testsuite,
15017                 &cryptodev_negative_aes_gcm_testsuite,
15018                 &cryptodev_negative_aes_gmac_testsuite,
15019                 &cryptodev_mixed_cipher_hash_testsuite,
15020                 &cryptodev_negative_hmac_sha1_testsuite,
15021                 &cryptodev_gen_testsuite,
15022 #ifdef RTE_LIB_SECURITY
15023                 &ipsec_proto_testsuite,
15024                 &pdcp_proto_testsuite,
15025                 &docsis_proto_testsuite,
15026 #endif
15027                 &end_testsuite
15028         };
15029         static struct unit_test_suite ts = {
15030                 .suite_name = "Cryptodev Unit Test Suite",
15031                 .setup = testsuite_setup,
15032                 .teardown = testsuite_teardown,
15033                 .unit_test_cases = {TEST_CASES_END()}
15034         };
15035
15036         gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
15037
15038         if (gbl_driver_id == -1) {
15039                 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
15040                 return TEST_SKIPPED;
15041         }
15042
15043         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15044                         (RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
15045
15046         ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
15047         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15048         ret = unit_test_suite_runner(&ts);
15049
15050         FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
15051         free(ts.unit_test_suites);
15052         return ret;
15053 }
15054
15055 static int
15056 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
15057 {
15058         struct rte_cryptodev_info dev_info;
15059         uint8_t i, nb_devs;
15060         int driver_id;
15061
15062         driver_id = rte_cryptodev_driver_id_get(pmd_name);
15063         if (driver_id == -1) {
15064                 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
15065                 return TEST_SKIPPED;
15066         }
15067
15068         nb_devs = rte_cryptodev_count();
15069         if (nb_devs < 1) {
15070                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
15071                 return TEST_SKIPPED;
15072         }
15073
15074         for (i = 0; i < nb_devs; i++) {
15075                 rte_cryptodev_info_get(i, &dev_info);
15076                 if (dev_info.driver_id == driver_id) {
15077                         if (!(dev_info.feature_flags & flag)) {
15078                                 RTE_LOG(INFO, USER1, "%s not supported\n",
15079                                                 flag_name);
15080                                 return TEST_SKIPPED;
15081                         }
15082                         return 0; /* found */
15083                 }
15084         }
15085
15086         RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
15087         return TEST_SKIPPED;
15088 }
15089
15090 static int
15091 test_cryptodev_qat(void)
15092 {
15093         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
15094 }
15095
15096 static int
15097 test_cryptodev_virtio(void)
15098 {
15099         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
15100 }
15101
15102 static int
15103 test_cryptodev_aesni_mb(void)
15104 {
15105         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15106 }
15107
15108 static int
15109 test_cryptodev_cpu_aesni_mb(void)
15110 {
15111         int32_t rc;
15112         enum rte_security_session_action_type at = gbl_action_type;
15113         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15114         rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15115         gbl_action_type = at;
15116         return rc;
15117 }
15118
15119 static int
15120 test_cryptodev_openssl(void)
15121 {
15122         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
15123 }
15124
15125 static int
15126 test_cryptodev_aesni_gcm(void)
15127 {
15128         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15129 }
15130
15131 static int
15132 test_cryptodev_cpu_aesni_gcm(void)
15133 {
15134         int32_t rc;
15135         enum rte_security_session_action_type at = gbl_action_type;
15136         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15137         rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15138         gbl_action_type = at;
15139         return rc;
15140 }
15141
15142 static int
15143 test_cryptodev_mlx5(void)
15144 {
15145         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
15146 }
15147
15148 static int
15149 test_cryptodev_null(void)
15150 {
15151         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
15152 }
15153
15154 static int
15155 test_cryptodev_sw_snow3g(void)
15156 {
15157         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
15158 }
15159
15160 static int
15161 test_cryptodev_sw_kasumi(void)
15162 {
15163         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
15164 }
15165
15166 static int
15167 test_cryptodev_sw_zuc(void)
15168 {
15169         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
15170 }
15171
15172 static int
15173 test_cryptodev_armv8(void)
15174 {
15175         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
15176 }
15177
15178 static int
15179 test_cryptodev_mrvl(void)
15180 {
15181         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
15182 }
15183
15184 #ifdef RTE_CRYPTO_SCHEDULER
15185
15186 static int
15187 test_cryptodev_scheduler(void)
15188 {
15189         uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
15190         const enum blockcipher_test_type blk_suites[] = {
15191                 BLKCIPHER_AES_CHAIN_TYPE,
15192                 BLKCIPHER_AES_CIPHERONLY_TYPE,
15193                 BLKCIPHER_AUTHONLY_TYPE
15194         };
15195         static struct unit_test_suite scheduler_multicore = {
15196                 .suite_name = "Scheduler Multicore Unit Test Suite",
15197                 .setup = scheduler_multicore_testsuite_setup,
15198                 .teardown = scheduler_mode_testsuite_teardown,
15199                 .unit_test_cases = {TEST_CASES_END()}
15200         };
15201         static struct unit_test_suite scheduler_round_robin = {
15202                 .suite_name = "Scheduler Round Robin Unit Test Suite",
15203                 .setup = scheduler_roundrobin_testsuite_setup,
15204                 .teardown = scheduler_mode_testsuite_teardown,
15205                 .unit_test_cases = {TEST_CASES_END()}
15206         };
15207         static struct unit_test_suite scheduler_failover = {
15208                 .suite_name = "Scheduler Failover Unit Test Suite",
15209                 .setup = scheduler_failover_testsuite_setup,
15210                 .teardown = scheduler_mode_testsuite_teardown,
15211                 .unit_test_cases = {TEST_CASES_END()}
15212         };
15213         static struct unit_test_suite scheduler_pkt_size_distr = {
15214                 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
15215                 .setup = scheduler_pkt_size_distr_testsuite_setup,
15216                 .teardown = scheduler_mode_testsuite_teardown,
15217                 .unit_test_cases = {TEST_CASES_END()}
15218         };
15219         struct unit_test_suite *sched_mode_suites[] = {
15220                 &scheduler_multicore,
15221                 &scheduler_round_robin,
15222                 &scheduler_failover,
15223                 &scheduler_pkt_size_distr
15224         };
15225         static struct unit_test_suite scheduler_config = {
15226                 .suite_name = "Crypto Device Scheduler Config Unit Test Suite",
15227                 .unit_test_cases = {
15228                         TEST_CASE(test_scheduler_attach_worker_op),
15229                         TEST_CASE(test_scheduler_mode_multicore_op),
15230                         TEST_CASE(test_scheduler_mode_roundrobin_op),
15231                         TEST_CASE(test_scheduler_mode_failover_op),
15232                         TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
15233                         TEST_CASE(test_scheduler_detach_worker_op),
15234
15235                         TEST_CASES_END() /**< NULL terminate array */
15236                 }
15237         };
15238         struct unit_test_suite *static_suites[] = {
15239                 &scheduler_config,
15240                 &end_testsuite
15241         };
15242         static struct unit_test_suite ts = {
15243                 .suite_name = "Scheduler Unit Test Suite",
15244                 .setup = scheduler_testsuite_setup,
15245                 .teardown = testsuite_teardown,
15246                 .unit_test_cases = {TEST_CASES_END()}
15247         };
15248
15249         gbl_driver_id = rte_cryptodev_driver_id_get(
15250                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
15251
15252         if (gbl_driver_id == -1) {
15253                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
15254                 return TEST_SKIPPED;
15255         }
15256
15257         if (rte_cryptodev_driver_id_get(
15258                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
15259                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
15260                 return TEST_SKIPPED;
15261         }
15262
15263         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15264                 uint8_t blk_i = 0;
15265                 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
15266                                 (struct unit_test_suite *) *
15267                                 (RTE_DIM(blk_suites) + 1));
15268                 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
15269                                 blk_suites, RTE_DIM(blk_suites));
15270                 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
15271         }
15272
15273         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15274                         (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
15275         ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
15276                         RTE_DIM(sched_mode_suites));
15277         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15278         ret = unit_test_suite_runner(&ts);
15279
15280         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15281                 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
15282                                 (*sched_mode_suites[sched_i]),
15283                                 RTE_DIM(blk_suites));
15284                 free(sched_mode_suites[sched_i]->unit_test_suites);
15285         }
15286         free(ts.unit_test_suites);
15287         return ret;
15288 }
15289
15290 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
15291
15292 #endif
15293
15294 static int
15295 test_cryptodev_dpaa2_sec(void)
15296 {
15297         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
15298 }
15299
15300 static int
15301 test_cryptodev_dpaa_sec(void)
15302 {
15303         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
15304 }
15305
15306 static int
15307 test_cryptodev_ccp(void)
15308 {
15309         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
15310 }
15311
15312 static int
15313 test_cryptodev_octeontx(void)
15314 {
15315         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
15316 }
15317
15318 static int
15319 test_cryptodev_octeontx2(void)
15320 {
15321         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
15322 }
15323
15324 static int
15325 test_cryptodev_caam_jr(void)
15326 {
15327         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
15328 }
15329
15330 static int
15331 test_cryptodev_nitrox(void)
15332 {
15333         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
15334 }
15335
15336 static int
15337 test_cryptodev_bcmfs(void)
15338 {
15339         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
15340 }
15341
15342 static int
15343 test_cryptodev_qat_raw_api(void)
15344 {
15345         static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
15346         int ret;
15347
15348         ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15349                         "RAW API");
15350         if (ret)
15351                 return ret;
15352
15353         global_api_test_type = CRYPTODEV_RAW_API_TEST;
15354         ret = run_cryptodev_testsuite(pmd_name);
15355         global_api_test_type = CRYPTODEV_API_TEST;
15356
15357         return ret;
15358 }
15359
15360 static int
15361 test_cryptodev_cn9k(void)
15362 {
15363         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
15364 }
15365
15366 static int
15367 test_cryptodev_cn10k(void)
15368 {
15369         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
15370 }
15371
15372 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
15373                 test_cryptodev_qat_raw_api);
15374 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
15375 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
15376 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
15377         test_cryptodev_cpu_aesni_mb);
15378 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
15379 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
15380 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
15381         test_cryptodev_cpu_aesni_gcm);
15382 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
15383 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
15384 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
15385 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
15386 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
15387 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
15388 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
15389 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
15390 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
15391 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
15392 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
15393 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
15394 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
15395 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
15396 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
15397 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
15398 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
15399 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);