e6ceeb487f7aa9be6c7618a84c0e94f5ffeb6900
[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         if (status == -ENOTSUP)
2407                 return TEST_SKIPPED;
2408
2409         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2410         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2411         return 0;
2412 }
2413
2414 static int
2415 create_wireless_algo_cipher_session(uint8_t dev_id,
2416                         enum rte_crypto_cipher_operation op,
2417                         enum rte_crypto_cipher_algorithm algo,
2418                         const uint8_t *key, const uint8_t key_len,
2419                         uint8_t iv_len)
2420 {
2421         uint8_t cipher_key[key_len];
2422         int status;
2423         struct crypto_testsuite_params *ts_params = &testsuite_params;
2424         struct crypto_unittest_params *ut_params = &unittest_params;
2425
2426         memcpy(cipher_key, key, key_len);
2427
2428         /* Setup Cipher Parameters */
2429         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2430         ut_params->cipher_xform.next = NULL;
2431
2432         ut_params->cipher_xform.cipher.algo = algo;
2433         ut_params->cipher_xform.cipher.op = op;
2434         ut_params->cipher_xform.cipher.key.data = cipher_key;
2435         ut_params->cipher_xform.cipher.key.length = key_len;
2436         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2437         ut_params->cipher_xform.cipher.iv.length = iv_len;
2438
2439         debug_hexdump(stdout, "key:", key, key_len);
2440
2441         /* Create Crypto session */
2442         ut_params->sess = rte_cryptodev_sym_session_create(
2443                         ts_params->session_mpool);
2444
2445         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2446                         &ut_params->cipher_xform,
2447                         ts_params->session_priv_mpool);
2448         if (status == -ENOTSUP)
2449                 return TEST_SKIPPED;
2450
2451         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2452         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2453         return 0;
2454 }
2455
2456 static int
2457 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2458                         unsigned int cipher_len,
2459                         unsigned int cipher_offset)
2460 {
2461         struct crypto_testsuite_params *ts_params = &testsuite_params;
2462         struct crypto_unittest_params *ut_params = &unittest_params;
2463
2464         /* Generate Crypto op data structure */
2465         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2466                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2467         TEST_ASSERT_NOT_NULL(ut_params->op,
2468                                 "Failed to allocate pktmbuf offload");
2469
2470         /* Set crypto operation data parameters */
2471         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2472
2473         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2474
2475         /* set crypto operation source mbuf */
2476         sym_op->m_src = ut_params->ibuf;
2477
2478         /* iv */
2479         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2480                         iv, iv_len);
2481         sym_op->cipher.data.length = cipher_len;
2482         sym_op->cipher.data.offset = cipher_offset;
2483         return 0;
2484 }
2485
2486 static int
2487 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2488                         unsigned int cipher_len,
2489                         unsigned int cipher_offset)
2490 {
2491         struct crypto_testsuite_params *ts_params = &testsuite_params;
2492         struct crypto_unittest_params *ut_params = &unittest_params;
2493
2494         /* Generate Crypto op data structure */
2495         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2496                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2497         TEST_ASSERT_NOT_NULL(ut_params->op,
2498                                 "Failed to allocate pktmbuf offload");
2499
2500         /* Set crypto operation data parameters */
2501         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2502
2503         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2504
2505         /* set crypto operation source mbuf */
2506         sym_op->m_src = ut_params->ibuf;
2507         sym_op->m_dst = ut_params->obuf;
2508
2509         /* iv */
2510         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2511                         iv, iv_len);
2512         sym_op->cipher.data.length = cipher_len;
2513         sym_op->cipher.data.offset = cipher_offset;
2514         return 0;
2515 }
2516
2517 static int
2518 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2519                 enum rte_crypto_cipher_operation cipher_op,
2520                 enum rte_crypto_auth_operation auth_op,
2521                 enum rte_crypto_auth_algorithm auth_algo,
2522                 enum rte_crypto_cipher_algorithm cipher_algo,
2523                 const uint8_t *key, uint8_t key_len,
2524                 uint8_t auth_iv_len, uint8_t auth_len,
2525                 uint8_t cipher_iv_len)
2526
2527 {
2528         uint8_t cipher_auth_key[key_len];
2529         int status;
2530
2531         struct crypto_testsuite_params *ts_params = &testsuite_params;
2532         struct crypto_unittest_params *ut_params = &unittest_params;
2533
2534         memcpy(cipher_auth_key, key, key_len);
2535
2536         /* Setup Authentication Parameters */
2537         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2538         ut_params->auth_xform.next = NULL;
2539
2540         ut_params->auth_xform.auth.op = auth_op;
2541         ut_params->auth_xform.auth.algo = auth_algo;
2542         ut_params->auth_xform.auth.key.length = key_len;
2543         /* Hash key = cipher key */
2544         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2545         ut_params->auth_xform.auth.digest_length = auth_len;
2546         /* Auth IV will be after cipher IV */
2547         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2548         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2549
2550         /* Setup Cipher Parameters */
2551         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2552         ut_params->cipher_xform.next = &ut_params->auth_xform;
2553
2554         ut_params->cipher_xform.cipher.algo = cipher_algo;
2555         ut_params->cipher_xform.cipher.op = cipher_op;
2556         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2557         ut_params->cipher_xform.cipher.key.length = key_len;
2558         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2559         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2560
2561         debug_hexdump(stdout, "key:", key, key_len);
2562
2563         /* Create Crypto session*/
2564         ut_params->sess = rte_cryptodev_sym_session_create(
2565                         ts_params->session_mpool);
2566         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2567
2568         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2569                         &ut_params->cipher_xform,
2570                         ts_params->session_priv_mpool);
2571         if (status == -ENOTSUP)
2572                 return TEST_SKIPPED;
2573
2574         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2575         return 0;
2576 }
2577
2578 static int
2579 create_wireless_cipher_auth_session(uint8_t dev_id,
2580                 enum rte_crypto_cipher_operation cipher_op,
2581                 enum rte_crypto_auth_operation auth_op,
2582                 enum rte_crypto_auth_algorithm auth_algo,
2583                 enum rte_crypto_cipher_algorithm cipher_algo,
2584                 const struct wireless_test_data *tdata)
2585 {
2586         const uint8_t key_len = tdata->key.len;
2587         uint8_t cipher_auth_key[key_len];
2588         int status;
2589
2590         struct crypto_testsuite_params *ts_params = &testsuite_params;
2591         struct crypto_unittest_params *ut_params = &unittest_params;
2592         const uint8_t *key = tdata->key.data;
2593         const uint8_t auth_len = tdata->digest.len;
2594         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2595         uint8_t auth_iv_len = tdata->auth_iv.len;
2596
2597         memcpy(cipher_auth_key, key, key_len);
2598
2599         /* Setup Authentication Parameters */
2600         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2601         ut_params->auth_xform.next = NULL;
2602
2603         ut_params->auth_xform.auth.op = auth_op;
2604         ut_params->auth_xform.auth.algo = auth_algo;
2605         ut_params->auth_xform.auth.key.length = key_len;
2606         /* Hash key = cipher key */
2607         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2608         ut_params->auth_xform.auth.digest_length = auth_len;
2609         /* Auth IV will be after cipher IV */
2610         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2611         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2612
2613         /* Setup Cipher Parameters */
2614         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2615         ut_params->cipher_xform.next = &ut_params->auth_xform;
2616
2617         ut_params->cipher_xform.cipher.algo = cipher_algo;
2618         ut_params->cipher_xform.cipher.op = cipher_op;
2619         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2620         ut_params->cipher_xform.cipher.key.length = key_len;
2621         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2622         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2623
2624
2625         debug_hexdump(stdout, "key:", key, key_len);
2626
2627         /* Create Crypto session*/
2628         ut_params->sess = rte_cryptodev_sym_session_create(
2629                         ts_params->session_mpool);
2630
2631         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2632                         &ut_params->cipher_xform,
2633                         ts_params->session_priv_mpool);
2634         if (status == -ENOTSUP)
2635                 return TEST_SKIPPED;
2636
2637         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2638         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2639         return 0;
2640 }
2641
2642 static int
2643 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2644                 const struct wireless_test_data *tdata)
2645 {
2646         return create_wireless_cipher_auth_session(dev_id,
2647                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2648                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2649                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2650 }
2651
2652 static int
2653 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2654                 enum rte_crypto_cipher_operation cipher_op,
2655                 enum rte_crypto_auth_operation auth_op,
2656                 enum rte_crypto_auth_algorithm auth_algo,
2657                 enum rte_crypto_cipher_algorithm cipher_algo,
2658                 const uint8_t *key, const uint8_t key_len,
2659                 uint8_t auth_iv_len, uint8_t auth_len,
2660                 uint8_t cipher_iv_len)
2661 {
2662         uint8_t auth_cipher_key[key_len];
2663         int status;
2664         struct crypto_testsuite_params *ts_params = &testsuite_params;
2665         struct crypto_unittest_params *ut_params = &unittest_params;
2666
2667         memcpy(auth_cipher_key, key, key_len);
2668
2669         /* Setup Authentication Parameters */
2670         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2671         ut_params->auth_xform.auth.op = auth_op;
2672         ut_params->auth_xform.next = &ut_params->cipher_xform;
2673         ut_params->auth_xform.auth.algo = auth_algo;
2674         ut_params->auth_xform.auth.key.length = key_len;
2675         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2676         ut_params->auth_xform.auth.digest_length = auth_len;
2677         /* Auth IV will be after cipher IV */
2678         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2679         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2680
2681         /* Setup Cipher Parameters */
2682         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2683         ut_params->cipher_xform.next = NULL;
2684         ut_params->cipher_xform.cipher.algo = cipher_algo;
2685         ut_params->cipher_xform.cipher.op = cipher_op;
2686         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2687         ut_params->cipher_xform.cipher.key.length = key_len;
2688         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2689         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2690
2691         debug_hexdump(stdout, "key:", key, key_len);
2692
2693         /* Create Crypto session*/
2694         ut_params->sess = rte_cryptodev_sym_session_create(
2695                         ts_params->session_mpool);
2696         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2697
2698         if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2699                 ut_params->auth_xform.next = NULL;
2700                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2701                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2702                                 &ut_params->cipher_xform,
2703                                 ts_params->session_priv_mpool);
2704
2705         } else
2706                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2707                                 &ut_params->auth_xform,
2708                                 ts_params->session_priv_mpool);
2709
2710         if (status == -ENOTSUP)
2711                 return TEST_SKIPPED;
2712
2713         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2714
2715         return 0;
2716 }
2717
2718 static int
2719 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2720                 unsigned int auth_tag_len,
2721                 const uint8_t *iv, unsigned int iv_len,
2722                 unsigned int data_pad_len,
2723                 enum rte_crypto_auth_operation op,
2724                 unsigned int auth_len, unsigned int auth_offset)
2725 {
2726         struct crypto_testsuite_params *ts_params = &testsuite_params;
2727
2728         struct crypto_unittest_params *ut_params = &unittest_params;
2729
2730         /* Generate Crypto op data structure */
2731         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2732                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2733         TEST_ASSERT_NOT_NULL(ut_params->op,
2734                 "Failed to allocate pktmbuf offload");
2735
2736         /* Set crypto operation data parameters */
2737         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2738
2739         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2740
2741         /* set crypto operation source mbuf */
2742         sym_op->m_src = ut_params->ibuf;
2743
2744         /* iv */
2745         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2746                         iv, iv_len);
2747         /* digest */
2748         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2749                                         ut_params->ibuf, auth_tag_len);
2750
2751         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2752                                 "no room to append auth tag");
2753         ut_params->digest = sym_op->auth.digest.data;
2754         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2755                         ut_params->ibuf, data_pad_len);
2756         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2757                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2758         else
2759                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2760
2761         debug_hexdump(stdout, "digest:",
2762                 sym_op->auth.digest.data,
2763                 auth_tag_len);
2764
2765         sym_op->auth.data.length = auth_len;
2766         sym_op->auth.data.offset = auth_offset;
2767
2768         return 0;
2769 }
2770
2771 static int
2772 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2773         enum rte_crypto_auth_operation op)
2774 {
2775         struct crypto_testsuite_params *ts_params = &testsuite_params;
2776         struct crypto_unittest_params *ut_params = &unittest_params;
2777
2778         const uint8_t *auth_tag = tdata->digest.data;
2779         const unsigned int auth_tag_len = tdata->digest.len;
2780         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2781         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2782
2783         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2784         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2785         const uint8_t *auth_iv = tdata->auth_iv.data;
2786         const uint8_t auth_iv_len = tdata->auth_iv.len;
2787         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2788         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2789
2790         /* Generate Crypto op data structure */
2791         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2792                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2793         TEST_ASSERT_NOT_NULL(ut_params->op,
2794                         "Failed to allocate pktmbuf offload");
2795         /* Set crypto operation data parameters */
2796         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2797
2798         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2799
2800         /* set crypto operation source mbuf */
2801         sym_op->m_src = ut_params->ibuf;
2802
2803         /* digest */
2804         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2805                         ut_params->ibuf, auth_tag_len);
2806
2807         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2808                         "no room to append auth tag");
2809         ut_params->digest = sym_op->auth.digest.data;
2810         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2811                         ut_params->ibuf, data_pad_len);
2812         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2813                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2814         else
2815                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2816
2817         debug_hexdump(stdout, "digest:",
2818                 sym_op->auth.digest.data,
2819                 auth_tag_len);
2820
2821         /* Copy cipher and auth IVs at the end of the crypto operation */
2822         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2823                                                 IV_OFFSET);
2824         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2825         iv_ptr += cipher_iv_len;
2826         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2827
2828         sym_op->cipher.data.length = cipher_len;
2829         sym_op->cipher.data.offset = 0;
2830         sym_op->auth.data.length = auth_len;
2831         sym_op->auth.data.offset = 0;
2832
2833         return 0;
2834 }
2835
2836 static int
2837 create_zuc_cipher_hash_generate_operation(
2838                 const struct wireless_test_data *tdata)
2839 {
2840         return create_wireless_cipher_hash_operation(tdata,
2841                 RTE_CRYPTO_AUTH_OP_GENERATE);
2842 }
2843
2844 static int
2845 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2846                 const unsigned auth_tag_len,
2847                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2848                 unsigned data_pad_len,
2849                 enum rte_crypto_auth_operation op,
2850                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2851                 const unsigned cipher_len, const unsigned cipher_offset,
2852                 const unsigned auth_len, const unsigned auth_offset)
2853 {
2854         struct crypto_testsuite_params *ts_params = &testsuite_params;
2855         struct crypto_unittest_params *ut_params = &unittest_params;
2856
2857         enum rte_crypto_cipher_algorithm cipher_algo =
2858                         ut_params->cipher_xform.cipher.algo;
2859         enum rte_crypto_auth_algorithm auth_algo =
2860                         ut_params->auth_xform.auth.algo;
2861
2862         /* Generate Crypto op data structure */
2863         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2864                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2865         TEST_ASSERT_NOT_NULL(ut_params->op,
2866                         "Failed to allocate pktmbuf offload");
2867         /* Set crypto operation data parameters */
2868         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2869
2870         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2871
2872         /* set crypto operation source mbuf */
2873         sym_op->m_src = ut_params->ibuf;
2874
2875         /* digest */
2876         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2877                         ut_params->ibuf, auth_tag_len);
2878
2879         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2880                         "no room to append auth tag");
2881         ut_params->digest = sym_op->auth.digest.data;
2882
2883         if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2884                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2885                                 ut_params->ibuf, data_pad_len);
2886         } else {
2887                 struct rte_mbuf *m = ut_params->ibuf;
2888                 unsigned int offset = data_pad_len;
2889
2890                 while (offset > m->data_len && m->next != NULL) {
2891                         offset -= m->data_len;
2892                         m = m->next;
2893                 }
2894                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2895                         m, offset);
2896         }
2897
2898         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2899                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2900         else
2901                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2902
2903         debug_hexdump(stdout, "digest:",
2904                 sym_op->auth.digest.data,
2905                 auth_tag_len);
2906
2907         /* Copy cipher and auth IVs at the end of the crypto operation */
2908         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2909                                                 IV_OFFSET);
2910         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2911         iv_ptr += cipher_iv_len;
2912         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2913
2914         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2915                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2916                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2917                 sym_op->cipher.data.length = cipher_len;
2918                 sym_op->cipher.data.offset = cipher_offset;
2919         } else {
2920                 sym_op->cipher.data.length = cipher_len >> 3;
2921                 sym_op->cipher.data.offset = cipher_offset >> 3;
2922         }
2923
2924         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2925                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2926                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2927                 sym_op->auth.data.length = auth_len;
2928                 sym_op->auth.data.offset = auth_offset;
2929         } else {
2930                 sym_op->auth.data.length = auth_len >> 3;
2931                 sym_op->auth.data.offset = auth_offset >> 3;
2932         }
2933
2934         return 0;
2935 }
2936
2937 static int
2938 create_wireless_algo_auth_cipher_operation(
2939                 const uint8_t *auth_tag, unsigned int auth_tag_len,
2940                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2941                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2942                 unsigned int data_pad_len,
2943                 unsigned int cipher_len, unsigned int cipher_offset,
2944                 unsigned int auth_len, unsigned int auth_offset,
2945                 uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2946 {
2947         struct crypto_testsuite_params *ts_params = &testsuite_params;
2948         struct crypto_unittest_params *ut_params = &unittest_params;
2949
2950         enum rte_crypto_cipher_algorithm cipher_algo =
2951                         ut_params->cipher_xform.cipher.algo;
2952         enum rte_crypto_auth_algorithm auth_algo =
2953                         ut_params->auth_xform.auth.algo;
2954
2955         /* Generate Crypto op data structure */
2956         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2957                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2958         TEST_ASSERT_NOT_NULL(ut_params->op,
2959                         "Failed to allocate pktmbuf offload");
2960
2961         /* Set crypto operation data parameters */
2962         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2963
2964         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2965
2966         /* set crypto operation mbufs */
2967         sym_op->m_src = ut_params->ibuf;
2968         if (op_mode == OUT_OF_PLACE)
2969                 sym_op->m_dst = ut_params->obuf;
2970
2971         /* digest */
2972         if (!do_sgl) {
2973                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2974                         (op_mode == IN_PLACE ?
2975                                 ut_params->ibuf : ut_params->obuf),
2976                         uint8_t *, data_pad_len);
2977                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2978                         (op_mode == IN_PLACE ?
2979                                 ut_params->ibuf : ut_params->obuf),
2980                         data_pad_len);
2981                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2982         } else {
2983                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2984                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2985                                 sym_op->m_src : sym_op->m_dst);
2986                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2987                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2988                         sgl_buf = sgl_buf->next;
2989                 }
2990                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2991                                 uint8_t *, remaining_off);
2992                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2993                                 remaining_off);
2994                 memset(sym_op->auth.digest.data, 0, remaining_off);
2995                 while (sgl_buf->next != NULL) {
2996                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2997                                 0, rte_pktmbuf_data_len(sgl_buf));
2998                         sgl_buf = sgl_buf->next;
2999                 }
3000         }
3001
3002         /* Copy digest for the verification */
3003         if (verify)
3004                 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3005
3006         /* Copy cipher and auth IVs at the end of the crypto operation */
3007         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3008                         ut_params->op, uint8_t *, IV_OFFSET);
3009
3010         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3011         iv_ptr += cipher_iv_len;
3012         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3013
3014         /* Only copy over the offset data needed from src to dst in OOP,
3015          * if the auth and cipher offsets are not aligned
3016          */
3017         if (op_mode == OUT_OF_PLACE) {
3018                 if (cipher_offset > auth_offset)
3019                         rte_memcpy(
3020                                 rte_pktmbuf_mtod_offset(
3021                                         sym_op->m_dst,
3022                                         uint8_t *, auth_offset >> 3),
3023                                 rte_pktmbuf_mtod_offset(
3024                                         sym_op->m_src,
3025                                         uint8_t *, auth_offset >> 3),
3026                                 ((cipher_offset >> 3) - (auth_offset >> 3)));
3027         }
3028
3029         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3030                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3031                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3032                 sym_op->cipher.data.length = cipher_len;
3033                 sym_op->cipher.data.offset = cipher_offset;
3034         } else {
3035                 sym_op->cipher.data.length = cipher_len >> 3;
3036                 sym_op->cipher.data.offset = cipher_offset >> 3;
3037         }
3038
3039         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3040                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3041                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3042                 sym_op->auth.data.length = auth_len;
3043                 sym_op->auth.data.offset = auth_offset;
3044         } else {
3045                 sym_op->auth.data.length = auth_len >> 3;
3046                 sym_op->auth.data.offset = auth_offset >> 3;
3047         }
3048
3049         return 0;
3050 }
3051
3052 static int
3053 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3054 {
3055         struct crypto_testsuite_params *ts_params = &testsuite_params;
3056         struct crypto_unittest_params *ut_params = &unittest_params;
3057
3058         int retval;
3059         unsigned plaintext_pad_len;
3060         unsigned plaintext_len;
3061         uint8_t *plaintext;
3062         struct rte_cryptodev_info dev_info;
3063
3064         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3065         uint64_t feat_flags = dev_info.feature_flags;
3066
3067         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3068                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3069                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3070                 return TEST_SKIPPED;
3071         }
3072
3073         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3074                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3075                 printf("Device doesn't support RAW data-path APIs.\n");
3076                 return TEST_SKIPPED;
3077         }
3078
3079         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3080                 return TEST_SKIPPED;
3081
3082         /* Verify the capabilities */
3083         struct rte_cryptodev_sym_capability_idx cap_idx;
3084         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3085         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3086         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3087                         &cap_idx) == NULL)
3088                 return TEST_SKIPPED;
3089
3090         /* Create SNOW 3G session */
3091         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3092                         tdata->key.data, tdata->key.len,
3093                         tdata->auth_iv.len, tdata->digest.len,
3094                         RTE_CRYPTO_AUTH_OP_GENERATE,
3095                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3096         if (retval < 0)
3097                 return retval;
3098
3099         /* alloc mbuf and set payload */
3100         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3101
3102         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3103         rte_pktmbuf_tailroom(ut_params->ibuf));
3104
3105         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3106         /* Append data which is padded to a multiple of */
3107         /* the algorithms block size */
3108         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3109         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3110                                 plaintext_pad_len);
3111         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3112
3113         /* Create SNOW 3G operation */
3114         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3115                         tdata->auth_iv.data, tdata->auth_iv.len,
3116                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3117                         tdata->validAuthLenInBits.len,
3118                         0);
3119         if (retval < 0)
3120                 return retval;
3121
3122         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3123                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3124                                 ut_params->op, 0, 1, 1, 0);
3125         else
3126                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3127                                 ut_params->op);
3128         ut_params->obuf = ut_params->op->sym->m_src;
3129         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3130         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3131                         + plaintext_pad_len;
3132
3133         /* Validate obuf */
3134         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3135         ut_params->digest,
3136         tdata->digest.data,
3137         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3138         "SNOW 3G Generated auth tag not as expected");
3139
3140         return 0;
3141 }
3142
3143 static int
3144 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3145 {
3146         struct crypto_testsuite_params *ts_params = &testsuite_params;
3147         struct crypto_unittest_params *ut_params = &unittest_params;
3148
3149         int retval;
3150         unsigned plaintext_pad_len;
3151         unsigned plaintext_len;
3152         uint8_t *plaintext;
3153         struct rte_cryptodev_info dev_info;
3154
3155         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3156         uint64_t feat_flags = dev_info.feature_flags;
3157
3158         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3159                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3160                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3161                 return TEST_SKIPPED;
3162         }
3163
3164         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3165                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3166                 printf("Device doesn't support RAW data-path APIs.\n");
3167                 return TEST_SKIPPED;
3168         }
3169
3170         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3171                 return TEST_SKIPPED;
3172
3173         /* Verify the capabilities */
3174         struct rte_cryptodev_sym_capability_idx cap_idx;
3175         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3176         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3177         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3178                         &cap_idx) == NULL)
3179                 return TEST_SKIPPED;
3180
3181         /* Create SNOW 3G session */
3182         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3183                                 tdata->key.data, tdata->key.len,
3184                                 tdata->auth_iv.len, tdata->digest.len,
3185                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3186                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3187         if (retval < 0)
3188                 return retval;
3189         /* alloc mbuf and set payload */
3190         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3191
3192         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3193         rte_pktmbuf_tailroom(ut_params->ibuf));
3194
3195         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3196         /* Append data which is padded to a multiple of */
3197         /* the algorithms block size */
3198         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3199         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3200                                 plaintext_pad_len);
3201         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3202
3203         /* Create SNOW 3G operation */
3204         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3205                         tdata->digest.len,
3206                         tdata->auth_iv.data, tdata->auth_iv.len,
3207                         plaintext_pad_len,
3208                         RTE_CRYPTO_AUTH_OP_VERIFY,
3209                         tdata->validAuthLenInBits.len,
3210                         0);
3211         if (retval < 0)
3212                 return retval;
3213
3214         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3215                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3216                                 ut_params->op, 0, 1, 1, 0);
3217         else
3218                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3219                                 ut_params->op);
3220         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3221         ut_params->obuf = ut_params->op->sym->m_src;
3222         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3223                                 + plaintext_pad_len;
3224
3225         /* Validate obuf */
3226         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3227                 return 0;
3228         else
3229                 return -1;
3230
3231         return 0;
3232 }
3233
3234 static int
3235 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3236 {
3237         struct crypto_testsuite_params *ts_params = &testsuite_params;
3238         struct crypto_unittest_params *ut_params = &unittest_params;
3239
3240         int retval;
3241         unsigned plaintext_pad_len;
3242         unsigned plaintext_len;
3243         uint8_t *plaintext;
3244         struct rte_cryptodev_info dev_info;
3245
3246         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3247         uint64_t feat_flags = dev_info.feature_flags;
3248
3249         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3250                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3251                 printf("Device doesn't support RAW data-path APIs.\n");
3252                 return TEST_SKIPPED;
3253         }
3254
3255         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3256                 return TEST_SKIPPED;
3257
3258         /* Verify the capabilities */
3259         struct rte_cryptodev_sym_capability_idx cap_idx;
3260         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3261         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3262         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3263                         &cap_idx) == NULL)
3264                 return TEST_SKIPPED;
3265
3266         /* Create KASUMI session */
3267         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3268                         tdata->key.data, tdata->key.len,
3269                         0, tdata->digest.len,
3270                         RTE_CRYPTO_AUTH_OP_GENERATE,
3271                         RTE_CRYPTO_AUTH_KASUMI_F9);
3272         if (retval < 0)
3273                 return retval;
3274
3275         /* alloc mbuf and set payload */
3276         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3277
3278         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3279         rte_pktmbuf_tailroom(ut_params->ibuf));
3280
3281         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3282         /* Append data which is padded to a multiple of */
3283         /* the algorithms block size */
3284         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3285         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3286                                 plaintext_pad_len);
3287         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3288
3289         /* Create KASUMI operation */
3290         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3291                         NULL, 0,
3292                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3293                         tdata->plaintext.len,
3294                         0);
3295         if (retval < 0)
3296                 return retval;
3297
3298         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3299                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3300                         ut_params->op);
3301         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3302                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3303                                 ut_params->op, 0, 1, 1, 0);
3304         else
3305                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3306                         ut_params->op);
3307
3308         ut_params->obuf = ut_params->op->sym->m_src;
3309         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3310         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3311                         + plaintext_pad_len;
3312
3313         /* Validate obuf */
3314         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3315         ut_params->digest,
3316         tdata->digest.data,
3317         DIGEST_BYTE_LENGTH_KASUMI_F9,
3318         "KASUMI Generated auth tag not as expected");
3319
3320         return 0;
3321 }
3322
3323 static int
3324 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3325 {
3326         struct crypto_testsuite_params *ts_params = &testsuite_params;
3327         struct crypto_unittest_params *ut_params = &unittest_params;
3328
3329         int retval;
3330         unsigned plaintext_pad_len;
3331         unsigned plaintext_len;
3332         uint8_t *plaintext;
3333         struct rte_cryptodev_info dev_info;
3334
3335         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3336         uint64_t feat_flags = dev_info.feature_flags;
3337
3338         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3339                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3340                 printf("Device doesn't support RAW data-path APIs.\n");
3341                 return TEST_SKIPPED;
3342         }
3343
3344         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3345                 return TEST_SKIPPED;
3346
3347         /* Verify the capabilities */
3348         struct rte_cryptodev_sym_capability_idx cap_idx;
3349         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3350         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3351         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3352                         &cap_idx) == NULL)
3353                 return TEST_SKIPPED;
3354
3355         /* Create KASUMI session */
3356         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3357                                 tdata->key.data, tdata->key.len,
3358                                 0, tdata->digest.len,
3359                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3360                                 RTE_CRYPTO_AUTH_KASUMI_F9);
3361         if (retval < 0)
3362                 return retval;
3363         /* alloc mbuf and set payload */
3364         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3365
3366         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3367         rte_pktmbuf_tailroom(ut_params->ibuf));
3368
3369         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3370         /* Append data which is padded to a multiple */
3371         /* of the algorithms block size */
3372         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3373         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3374                                 plaintext_pad_len);
3375         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3376
3377         /* Create KASUMI operation */
3378         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3379                         tdata->digest.len,
3380                         NULL, 0,
3381                         plaintext_pad_len,
3382                         RTE_CRYPTO_AUTH_OP_VERIFY,
3383                         tdata->plaintext.len,
3384                         0);
3385         if (retval < 0)
3386                 return retval;
3387
3388         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3389                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3390                                 ut_params->op, 0, 1, 1, 0);
3391         else
3392                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3393                                 ut_params->op);
3394         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3395         ut_params->obuf = ut_params->op->sym->m_src;
3396         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3397                                 + plaintext_pad_len;
3398
3399         /* Validate obuf */
3400         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3401                 return 0;
3402         else
3403                 return -1;
3404
3405         return 0;
3406 }
3407
3408 static int
3409 test_snow3g_hash_generate_test_case_1(void)
3410 {
3411         return test_snow3g_authentication(&snow3g_hash_test_case_1);
3412 }
3413
3414 static int
3415 test_snow3g_hash_generate_test_case_2(void)
3416 {
3417         return test_snow3g_authentication(&snow3g_hash_test_case_2);
3418 }
3419
3420 static int
3421 test_snow3g_hash_generate_test_case_3(void)
3422 {
3423         return test_snow3g_authentication(&snow3g_hash_test_case_3);
3424 }
3425
3426 static int
3427 test_snow3g_hash_generate_test_case_4(void)
3428 {
3429         return test_snow3g_authentication(&snow3g_hash_test_case_4);
3430 }
3431
3432 static int
3433 test_snow3g_hash_generate_test_case_5(void)
3434 {
3435         return test_snow3g_authentication(&snow3g_hash_test_case_5);
3436 }
3437
3438 static int
3439 test_snow3g_hash_generate_test_case_6(void)
3440 {
3441         return test_snow3g_authentication(&snow3g_hash_test_case_6);
3442 }
3443
3444 static int
3445 test_snow3g_hash_verify_test_case_1(void)
3446 {
3447         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3448
3449 }
3450
3451 static int
3452 test_snow3g_hash_verify_test_case_2(void)
3453 {
3454         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3455 }
3456
3457 static int
3458 test_snow3g_hash_verify_test_case_3(void)
3459 {
3460         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3461 }
3462
3463 static int
3464 test_snow3g_hash_verify_test_case_4(void)
3465 {
3466         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3467 }
3468
3469 static int
3470 test_snow3g_hash_verify_test_case_5(void)
3471 {
3472         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3473 }
3474
3475 static int
3476 test_snow3g_hash_verify_test_case_6(void)
3477 {
3478         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3479 }
3480
3481 static int
3482 test_kasumi_hash_generate_test_case_1(void)
3483 {
3484         return test_kasumi_authentication(&kasumi_hash_test_case_1);
3485 }
3486
3487 static int
3488 test_kasumi_hash_generate_test_case_2(void)
3489 {
3490         return test_kasumi_authentication(&kasumi_hash_test_case_2);
3491 }
3492
3493 static int
3494 test_kasumi_hash_generate_test_case_3(void)
3495 {
3496         return test_kasumi_authentication(&kasumi_hash_test_case_3);
3497 }
3498
3499 static int
3500 test_kasumi_hash_generate_test_case_4(void)
3501 {
3502         return test_kasumi_authentication(&kasumi_hash_test_case_4);
3503 }
3504
3505 static int
3506 test_kasumi_hash_generate_test_case_5(void)
3507 {
3508         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3509 }
3510
3511 static int
3512 test_kasumi_hash_generate_test_case_6(void)
3513 {
3514         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3515 }
3516
3517 static int
3518 test_kasumi_hash_verify_test_case_1(void)
3519 {
3520         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3521 }
3522
3523 static int
3524 test_kasumi_hash_verify_test_case_2(void)
3525 {
3526         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3527 }
3528
3529 static int
3530 test_kasumi_hash_verify_test_case_3(void)
3531 {
3532         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3533 }
3534
3535 static int
3536 test_kasumi_hash_verify_test_case_4(void)
3537 {
3538         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3539 }
3540
3541 static int
3542 test_kasumi_hash_verify_test_case_5(void)
3543 {
3544         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3545 }
3546
3547 static int
3548 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3549 {
3550         struct crypto_testsuite_params *ts_params = &testsuite_params;
3551         struct crypto_unittest_params *ut_params = &unittest_params;
3552
3553         int retval;
3554         uint8_t *plaintext, *ciphertext;
3555         unsigned plaintext_pad_len;
3556         unsigned plaintext_len;
3557         struct rte_cryptodev_info dev_info;
3558
3559         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3560         uint64_t feat_flags = dev_info.feature_flags;
3561
3562         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3563                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3564                 printf("Device doesn't support RAW data-path APIs.\n");
3565                 return TEST_SKIPPED;
3566         }
3567
3568         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3569                 return TEST_SKIPPED;
3570
3571         /* Verify the capabilities */
3572         struct rte_cryptodev_sym_capability_idx cap_idx;
3573         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3574         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3575         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3576                         &cap_idx) == NULL)
3577                 return TEST_SKIPPED;
3578
3579         /* Create KASUMI session */
3580         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3581                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3582                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3583                                         tdata->key.data, tdata->key.len,
3584                                         tdata->cipher_iv.len);
3585         if (retval < 0)
3586                 return retval;
3587
3588         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3589
3590         /* Clear mbuf payload */
3591         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3592                rte_pktmbuf_tailroom(ut_params->ibuf));
3593
3594         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3595         /* Append data which is padded to a multiple */
3596         /* of the algorithms block size */
3597         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3598         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3599                                 plaintext_pad_len);
3600         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3601
3602         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3603
3604         /* Create KASUMI operation */
3605         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3606                                 tdata->cipher_iv.len,
3607                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3608                                 tdata->validCipherOffsetInBits.len);
3609         if (retval < 0)
3610                 return retval;
3611
3612         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3613                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3614                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3615         else
3616                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3617                                 ut_params->op);
3618         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3619
3620         ut_params->obuf = ut_params->op->sym->m_dst;
3621         if (ut_params->obuf)
3622                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3623         else
3624                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3625
3626         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3627
3628         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3629                                 (tdata->validCipherOffsetInBits.len >> 3);
3630         /* Validate obuf */
3631         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3632                 ciphertext,
3633                 reference_ciphertext,
3634                 tdata->validCipherLenInBits.len,
3635                 "KASUMI Ciphertext data not as expected");
3636         return 0;
3637 }
3638
3639 static int
3640 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3641 {
3642         struct crypto_testsuite_params *ts_params = &testsuite_params;
3643         struct crypto_unittest_params *ut_params = &unittest_params;
3644
3645         int retval;
3646
3647         unsigned int plaintext_pad_len;
3648         unsigned int plaintext_len;
3649
3650         uint8_t buffer[10000];
3651         const uint8_t *ciphertext;
3652
3653         struct rte_cryptodev_info dev_info;
3654
3655         /* Verify the capabilities */
3656         struct rte_cryptodev_sym_capability_idx cap_idx;
3657         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3658         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3659         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3660                         &cap_idx) == NULL)
3661                 return TEST_SKIPPED;
3662
3663         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3664
3665         uint64_t feat_flags = dev_info.feature_flags;
3666
3667         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3668                 printf("Device doesn't support in-place scatter-gather. "
3669                                 "Test Skipped.\n");
3670                 return TEST_SKIPPED;
3671         }
3672
3673         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3674                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3675                 printf("Device doesn't support RAW data-path APIs.\n");
3676                 return TEST_SKIPPED;
3677         }
3678
3679         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3680                 return TEST_SKIPPED;
3681
3682         /* Create KASUMI session */
3683         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3684                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3685                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3686                                         tdata->key.data, tdata->key.len,
3687                                         tdata->cipher_iv.len);
3688         if (retval < 0)
3689                 return retval;
3690
3691         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3692
3693
3694         /* Append data which is padded to a multiple */
3695         /* of the algorithms block size */
3696         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3697
3698         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3699                         plaintext_pad_len, 10, 0);
3700
3701         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3702
3703         /* Create KASUMI operation */
3704         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3705                                 tdata->cipher_iv.len,
3706                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3707                                 tdata->validCipherOffsetInBits.len);
3708         if (retval < 0)
3709                 return retval;
3710
3711         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3712                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3713                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3714         else
3715                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3716                                                 ut_params->op);
3717         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3718
3719         ut_params->obuf = ut_params->op->sym->m_dst;
3720
3721         if (ut_params->obuf)
3722                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3723                                 plaintext_len, buffer);
3724         else
3725                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3726                                 tdata->validCipherOffsetInBits.len >> 3,
3727                                 plaintext_len, buffer);
3728
3729         /* Validate obuf */
3730         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3731
3732         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3733                                 (tdata->validCipherOffsetInBits.len >> 3);
3734         /* Validate obuf */
3735         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3736                 ciphertext,
3737                 reference_ciphertext,
3738                 tdata->validCipherLenInBits.len,
3739                 "KASUMI Ciphertext data not as expected");
3740         return 0;
3741 }
3742
3743 static int
3744 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3745 {
3746         struct crypto_testsuite_params *ts_params = &testsuite_params;
3747         struct crypto_unittest_params *ut_params = &unittest_params;
3748
3749         int retval;
3750         uint8_t *plaintext, *ciphertext;
3751         unsigned plaintext_pad_len;
3752         unsigned plaintext_len;
3753
3754         /* Verify the capabilities */
3755         struct rte_cryptodev_sym_capability_idx cap_idx;
3756         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3757         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3758         /* Data-path service does not support OOP */
3759         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3760                         &cap_idx) == NULL)
3761                 return TEST_SKIPPED;
3762
3763         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3764                 return TEST_SKIPPED;
3765
3766         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3767                 return TEST_SKIPPED;
3768
3769         /* Create KASUMI session */
3770         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3771                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3772                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3773                                         tdata->key.data, tdata->key.len,
3774                                         tdata->cipher_iv.len);
3775         if (retval < 0)
3776                 return retval;
3777
3778         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3779         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3780
3781         /* Clear mbuf payload */
3782         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3783                rte_pktmbuf_tailroom(ut_params->ibuf));
3784
3785         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3786         /* Append data which is padded to a multiple */
3787         /* of the algorithms block size */
3788         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3789         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3790                                 plaintext_pad_len);
3791         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3792         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3793
3794         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3795
3796         /* Create KASUMI operation */
3797         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3798                                 tdata->cipher_iv.len,
3799                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3800                                 tdata->validCipherOffsetInBits.len);
3801         if (retval < 0)
3802                 return retval;
3803
3804         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3805                                                 ut_params->op);
3806         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3807
3808         ut_params->obuf = ut_params->op->sym->m_dst;
3809         if (ut_params->obuf)
3810                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3811         else
3812                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3813
3814         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3815
3816         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3817                                 (tdata->validCipherOffsetInBits.len >> 3);
3818         /* Validate obuf */
3819         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3820                 ciphertext,
3821                 reference_ciphertext,
3822                 tdata->validCipherLenInBits.len,
3823                 "KASUMI Ciphertext data not as expected");
3824         return 0;
3825 }
3826
3827 static int
3828 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3829 {
3830         struct crypto_testsuite_params *ts_params = &testsuite_params;
3831         struct crypto_unittest_params *ut_params = &unittest_params;
3832
3833         int retval;
3834         unsigned int plaintext_pad_len;
3835         unsigned int plaintext_len;
3836
3837         const uint8_t *ciphertext;
3838         uint8_t buffer[2048];
3839
3840         struct rte_cryptodev_info dev_info;
3841
3842         /* Verify the capabilities */
3843         struct rte_cryptodev_sym_capability_idx cap_idx;
3844         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3845         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3846         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3847                         &cap_idx) == NULL)
3848                 return TEST_SKIPPED;
3849
3850         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3851                 return TEST_SKIPPED;
3852
3853         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3854                 return TEST_SKIPPED;
3855
3856         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3857
3858         uint64_t feat_flags = dev_info.feature_flags;
3859         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3860                 printf("Device doesn't support out-of-place scatter-gather "
3861                                 "in both input and output mbufs. "
3862                                 "Test Skipped.\n");
3863                 return TEST_SKIPPED;
3864         }
3865
3866         /* Create KASUMI session */
3867         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3868                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3869                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3870                                         tdata->key.data, tdata->key.len,
3871                                         tdata->cipher_iv.len);
3872         if (retval < 0)
3873                 return retval;
3874
3875         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3876         /* Append data which is padded to a multiple */
3877         /* of the algorithms block size */
3878         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3879
3880         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3881                         plaintext_pad_len, 10, 0);
3882         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3883                         plaintext_pad_len, 3, 0);
3884
3885         /* Append data which is padded to a multiple */
3886         /* of the algorithms block size */
3887         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3888
3889         /* Create KASUMI operation */
3890         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3891                                 tdata->cipher_iv.len,
3892                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3893                                 tdata->validCipherOffsetInBits.len);
3894         if (retval < 0)
3895                 return retval;
3896
3897         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3898                                                 ut_params->op);
3899         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3900
3901         ut_params->obuf = ut_params->op->sym->m_dst;
3902         if (ut_params->obuf)
3903                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3904                                 plaintext_pad_len, buffer);
3905         else
3906                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3907                                 tdata->validCipherOffsetInBits.len >> 3,
3908                                 plaintext_pad_len, buffer);
3909
3910         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3911                                 (tdata->validCipherOffsetInBits.len >> 3);
3912         /* Validate obuf */
3913         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3914                 ciphertext,
3915                 reference_ciphertext,
3916                 tdata->validCipherLenInBits.len,
3917                 "KASUMI Ciphertext data not as expected");
3918         return 0;
3919 }
3920
3921
3922 static int
3923 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3924 {
3925         struct crypto_testsuite_params *ts_params = &testsuite_params;
3926         struct crypto_unittest_params *ut_params = &unittest_params;
3927
3928         int retval;
3929         uint8_t *ciphertext, *plaintext;
3930         unsigned ciphertext_pad_len;
3931         unsigned ciphertext_len;
3932
3933         /* Verify the capabilities */
3934         struct rte_cryptodev_sym_capability_idx cap_idx;
3935         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3936         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3937         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3938                         &cap_idx) == NULL)
3939                 return TEST_SKIPPED;
3940
3941         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3942                 return TEST_SKIPPED;
3943
3944         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3945                 return TEST_SKIPPED;
3946
3947         /* Create KASUMI session */
3948         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3949                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3950                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3951                                         tdata->key.data, tdata->key.len,
3952                                         tdata->cipher_iv.len);
3953         if (retval < 0)
3954                 return retval;
3955
3956         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3957         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3958
3959         /* Clear mbuf payload */
3960         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3961                rte_pktmbuf_tailroom(ut_params->ibuf));
3962
3963         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3964         /* Append data which is padded to a multiple */
3965         /* of the algorithms block size */
3966         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3967         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3968                                 ciphertext_pad_len);
3969         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3970         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3971
3972         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3973
3974         /* Create KASUMI operation */
3975         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3976                                 tdata->cipher_iv.len,
3977                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3978                                 tdata->validCipherOffsetInBits.len);
3979         if (retval < 0)
3980                 return retval;
3981
3982         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3983                                                 ut_params->op);
3984         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3985
3986         ut_params->obuf = ut_params->op->sym->m_dst;
3987         if (ut_params->obuf)
3988                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3989         else
3990                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3991
3992         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3993
3994         const uint8_t *reference_plaintext = tdata->plaintext.data +
3995                                 (tdata->validCipherOffsetInBits.len >> 3);
3996         /* Validate obuf */
3997         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3998                 plaintext,
3999                 reference_plaintext,
4000                 tdata->validCipherLenInBits.len,
4001                 "KASUMI Plaintext data not as expected");
4002         return 0;
4003 }
4004
4005 static int
4006 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4007 {
4008         struct crypto_testsuite_params *ts_params = &testsuite_params;
4009         struct crypto_unittest_params *ut_params = &unittest_params;
4010
4011         int retval;
4012         uint8_t *ciphertext, *plaintext;
4013         unsigned ciphertext_pad_len;
4014         unsigned ciphertext_len;
4015         struct rte_cryptodev_info dev_info;
4016
4017         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4018         uint64_t feat_flags = dev_info.feature_flags;
4019
4020         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4021                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4022                 printf("Device doesn't support RAW data-path APIs.\n");
4023                 return TEST_SKIPPED;
4024         }
4025
4026         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4027                 return TEST_SKIPPED;
4028
4029         /* Verify the capabilities */
4030         struct rte_cryptodev_sym_capability_idx cap_idx;
4031         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4032         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4033         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4034                         &cap_idx) == NULL)
4035                 return TEST_SKIPPED;
4036
4037         /* Create KASUMI session */
4038         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4039                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4040                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4041                                         tdata->key.data, tdata->key.len,
4042                                         tdata->cipher_iv.len);
4043         if (retval < 0)
4044                 return retval;
4045
4046         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4047
4048         /* Clear mbuf payload */
4049         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4050                rte_pktmbuf_tailroom(ut_params->ibuf));
4051
4052         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4053         /* Append data which is padded to a multiple */
4054         /* of the algorithms block size */
4055         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4056         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4057                                 ciphertext_pad_len);
4058         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4059
4060         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4061
4062         /* Create KASUMI operation */
4063         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4064                                         tdata->cipher_iv.len,
4065                                         tdata->ciphertext.len,
4066                                         tdata->validCipherOffsetInBits.len);
4067         if (retval < 0)
4068                 return retval;
4069
4070         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4071                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4072                                 ut_params->op, 1, 0, 1, 0);
4073         else
4074                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4075                                                 ut_params->op);
4076         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4077
4078         ut_params->obuf = ut_params->op->sym->m_dst;
4079         if (ut_params->obuf)
4080                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4081         else
4082                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4083
4084         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4085
4086         const uint8_t *reference_plaintext = tdata->plaintext.data +
4087                                 (tdata->validCipherOffsetInBits.len >> 3);
4088         /* Validate obuf */
4089         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4090                 plaintext,
4091                 reference_plaintext,
4092                 tdata->validCipherLenInBits.len,
4093                 "KASUMI Plaintext data not as expected");
4094         return 0;
4095 }
4096
4097 static int
4098 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4099 {
4100         struct crypto_testsuite_params *ts_params = &testsuite_params;
4101         struct crypto_unittest_params *ut_params = &unittest_params;
4102
4103         int retval;
4104         uint8_t *plaintext, *ciphertext;
4105         unsigned plaintext_pad_len;
4106         unsigned plaintext_len;
4107         struct rte_cryptodev_info dev_info;
4108
4109         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4110         uint64_t feat_flags = dev_info.feature_flags;
4111
4112         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4113                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4114                 printf("Device doesn't support RAW data-path APIs.\n");
4115                 return TEST_SKIPPED;
4116         }
4117
4118         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4119                 return TEST_SKIPPED;
4120
4121         /* Verify the capabilities */
4122         struct rte_cryptodev_sym_capability_idx cap_idx;
4123         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4124         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4125         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4126                         &cap_idx) == NULL)
4127                 return TEST_SKIPPED;
4128
4129         /* Create SNOW 3G session */
4130         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4131                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4132                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4133                                         tdata->key.data, tdata->key.len,
4134                                         tdata->cipher_iv.len);
4135         if (retval < 0)
4136                 return retval;
4137
4138         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4139
4140         /* Clear mbuf payload */
4141         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4142                rte_pktmbuf_tailroom(ut_params->ibuf));
4143
4144         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4145         /* Append data which is padded to a multiple of */
4146         /* the algorithms block size */
4147         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4148         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4149                                 plaintext_pad_len);
4150         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4151
4152         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4153
4154         /* Create SNOW 3G operation */
4155         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4156                                         tdata->cipher_iv.len,
4157                                         tdata->validCipherLenInBits.len,
4158                                         0);
4159         if (retval < 0)
4160                 return retval;
4161
4162         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4163                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4164                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4165         else
4166                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4167                                                 ut_params->op);
4168         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4169
4170         ut_params->obuf = ut_params->op->sym->m_dst;
4171         if (ut_params->obuf)
4172                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4173         else
4174                 ciphertext = plaintext;
4175
4176         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4177
4178         /* Validate obuf */
4179         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4180                 ciphertext,
4181                 tdata->ciphertext.data,
4182                 tdata->validDataLenInBits.len,
4183                 "SNOW 3G Ciphertext data not as expected");
4184         return 0;
4185 }
4186
4187
4188 static int
4189 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4190 {
4191         struct crypto_testsuite_params *ts_params = &testsuite_params;
4192         struct crypto_unittest_params *ut_params = &unittest_params;
4193         uint8_t *plaintext, *ciphertext;
4194
4195         int retval;
4196         unsigned plaintext_pad_len;
4197         unsigned plaintext_len;
4198
4199         /* Verify the capabilities */
4200         struct rte_cryptodev_sym_capability_idx cap_idx;
4201         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4202         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4203         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4204                         &cap_idx) == NULL)
4205                 return TEST_SKIPPED;
4206
4207         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4208                 return TEST_SKIPPED;
4209
4210         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4211                 return TEST_SKIPPED;
4212
4213         /* Create SNOW 3G session */
4214         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4215                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4216                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4217                                         tdata->key.data, tdata->key.len,
4218                                         tdata->cipher_iv.len);
4219         if (retval < 0)
4220                 return retval;
4221
4222         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4223         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4224
4225         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4226                         "Failed to allocate input buffer in mempool");
4227         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4228                         "Failed to allocate output buffer in mempool");
4229
4230         /* Clear mbuf payload */
4231         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4232                rte_pktmbuf_tailroom(ut_params->ibuf));
4233
4234         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4235         /* Append data which is padded to a multiple of */
4236         /* the algorithms block size */
4237         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4238         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4239                                 plaintext_pad_len);
4240         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4241         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4242
4243         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4244
4245         /* Create SNOW 3G operation */
4246         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4247                                         tdata->cipher_iv.len,
4248                                         tdata->validCipherLenInBits.len,
4249                                         0);
4250         if (retval < 0)
4251                 return retval;
4252
4253         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4254                                                 ut_params->op);
4255         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4256
4257         ut_params->obuf = ut_params->op->sym->m_dst;
4258         if (ut_params->obuf)
4259                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4260         else
4261                 ciphertext = plaintext;
4262
4263         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4264
4265         /* Validate obuf */
4266         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4267                 ciphertext,
4268                 tdata->ciphertext.data,
4269                 tdata->validDataLenInBits.len,
4270                 "SNOW 3G Ciphertext data not as expected");
4271         return 0;
4272 }
4273
4274 static int
4275 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4276 {
4277         struct crypto_testsuite_params *ts_params = &testsuite_params;
4278         struct crypto_unittest_params *ut_params = &unittest_params;
4279
4280         int retval;
4281         unsigned int plaintext_pad_len;
4282         unsigned int plaintext_len;
4283         uint8_t buffer[10000];
4284         const uint8_t *ciphertext;
4285
4286         struct rte_cryptodev_info dev_info;
4287
4288         /* Verify the capabilities */
4289         struct rte_cryptodev_sym_capability_idx cap_idx;
4290         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4291         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4292         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4293                         &cap_idx) == NULL)
4294                 return TEST_SKIPPED;
4295
4296         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4297                 return TEST_SKIPPED;
4298
4299         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4300                 return TEST_SKIPPED;
4301
4302         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4303
4304         uint64_t feat_flags = dev_info.feature_flags;
4305
4306         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4307                 printf("Device doesn't support out-of-place scatter-gather "
4308                                 "in both input and output mbufs. "
4309                                 "Test Skipped.\n");
4310                 return TEST_SKIPPED;
4311         }
4312
4313         /* Create SNOW 3G session */
4314         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4315                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4316                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4317                                         tdata->key.data, tdata->key.len,
4318                                         tdata->cipher_iv.len);
4319         if (retval < 0)
4320                 return retval;
4321
4322         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4323         /* Append data which is padded to a multiple of */
4324         /* the algorithms block size */
4325         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4326
4327         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4328                         plaintext_pad_len, 10, 0);
4329         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4330                         plaintext_pad_len, 3, 0);
4331
4332         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4333                         "Failed to allocate input buffer in mempool");
4334         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4335                         "Failed to allocate output buffer in mempool");
4336
4337         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4338
4339         /* Create SNOW 3G operation */
4340         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4341                                         tdata->cipher_iv.len,
4342                                         tdata->validCipherLenInBits.len,
4343                                         0);
4344         if (retval < 0)
4345                 return retval;
4346
4347         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4348                                                 ut_params->op);
4349         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4350
4351         ut_params->obuf = ut_params->op->sym->m_dst;
4352         if (ut_params->obuf)
4353                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4354                                 plaintext_len, buffer);
4355         else
4356                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4357                                 plaintext_len, buffer);
4358
4359         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4360
4361         /* Validate obuf */
4362         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4363                 ciphertext,
4364                 tdata->ciphertext.data,
4365                 tdata->validDataLenInBits.len,
4366                 "SNOW 3G Ciphertext data not as expected");
4367
4368         return 0;
4369 }
4370
4371 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4372 static void
4373 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4374 {
4375         uint8_t curr_byte, prev_byte;
4376         uint32_t length_in_bytes = ceil_byte_length(length + offset);
4377         uint8_t lower_byte_mask = (1 << offset) - 1;
4378         unsigned i;
4379
4380         prev_byte = buffer[0];
4381         buffer[0] >>= offset;
4382
4383         for (i = 1; i < length_in_bytes; i++) {
4384                 curr_byte = buffer[i];
4385                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4386                                 (curr_byte >> offset);
4387                 prev_byte = curr_byte;
4388         }
4389 }
4390
4391 static int
4392 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4393 {
4394         struct crypto_testsuite_params *ts_params = &testsuite_params;
4395         struct crypto_unittest_params *ut_params = &unittest_params;
4396         uint8_t *plaintext, *ciphertext;
4397         int retval;
4398         uint32_t plaintext_len;
4399         uint32_t plaintext_pad_len;
4400         uint8_t extra_offset = 4;
4401         uint8_t *expected_ciphertext_shifted;
4402         struct rte_cryptodev_info dev_info;
4403
4404         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4405         uint64_t feat_flags = dev_info.feature_flags;
4406
4407         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4408                         ((tdata->validDataLenInBits.len % 8) != 0)) {
4409                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4410                 return TEST_SKIPPED;
4411         }
4412
4413         /* Verify the capabilities */
4414         struct rte_cryptodev_sym_capability_idx cap_idx;
4415         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4416         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4417         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4418                         &cap_idx) == NULL)
4419                 return TEST_SKIPPED;
4420
4421         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4422                 return TEST_SKIPPED;
4423
4424         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4425                 return TEST_SKIPPED;
4426
4427         /* Create SNOW 3G session */
4428         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4429                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4430                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4431                                         tdata->key.data, tdata->key.len,
4432                                         tdata->cipher_iv.len);
4433         if (retval < 0)
4434                 return retval;
4435
4436         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4437         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4438
4439         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4440                         "Failed to allocate input buffer in mempool");
4441         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4442                         "Failed to allocate output buffer in mempool");
4443
4444         /* Clear mbuf payload */
4445         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4446                rte_pktmbuf_tailroom(ut_params->ibuf));
4447
4448         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4449         /*
4450          * Append data which is padded to a
4451          * multiple of the algorithms block size
4452          */
4453         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4454
4455         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4456                                                 plaintext_pad_len);
4457
4458         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4459
4460         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4461         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4462
4463 #ifdef RTE_APP_TEST_DEBUG
4464         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4465 #endif
4466         /* Create SNOW 3G operation */
4467         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4468                                         tdata->cipher_iv.len,
4469                                         tdata->validCipherLenInBits.len,
4470                                         extra_offset);
4471         if (retval < 0)
4472                 return retval;
4473
4474         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4475                                                 ut_params->op);
4476         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4477
4478         ut_params->obuf = ut_params->op->sym->m_dst;
4479         if (ut_params->obuf)
4480                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4481         else
4482                 ciphertext = plaintext;
4483
4484 #ifdef RTE_APP_TEST_DEBUG
4485         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4486 #endif
4487
4488         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4489
4490         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4491                         "failed to reserve memory for ciphertext shifted\n");
4492
4493         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4494                         ceil_byte_length(tdata->ciphertext.len));
4495         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4496                         extra_offset);
4497         /* Validate obuf */
4498         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4499                 ciphertext,
4500                 expected_ciphertext_shifted,
4501                 tdata->validDataLenInBits.len,
4502                 extra_offset,
4503                 "SNOW 3G Ciphertext data not as expected");
4504         return 0;
4505 }
4506
4507 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4508 {
4509         struct crypto_testsuite_params *ts_params = &testsuite_params;
4510         struct crypto_unittest_params *ut_params = &unittest_params;
4511
4512         int retval;
4513
4514         uint8_t *plaintext, *ciphertext;
4515         unsigned ciphertext_pad_len;
4516         unsigned ciphertext_len;
4517         struct rte_cryptodev_info dev_info;
4518
4519         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4520         uint64_t feat_flags = dev_info.feature_flags;
4521
4522         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4523                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4524                 printf("Device doesn't support RAW data-path APIs.\n");
4525                 return TEST_SKIPPED;
4526         }
4527
4528         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4529                 return TEST_SKIPPED;
4530
4531         /* Verify the capabilities */
4532         struct rte_cryptodev_sym_capability_idx cap_idx;
4533         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4534         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4535         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4536                         &cap_idx) == NULL)
4537                 return TEST_SKIPPED;
4538
4539         /* Create SNOW 3G session */
4540         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4541                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4542                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4543                                         tdata->key.data, tdata->key.len,
4544                                         tdata->cipher_iv.len);
4545         if (retval < 0)
4546                 return retval;
4547
4548         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4549
4550         /* Clear mbuf payload */
4551         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4552                rte_pktmbuf_tailroom(ut_params->ibuf));
4553
4554         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4555         /* Append data which is padded to a multiple of */
4556         /* the algorithms block size */
4557         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4558         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4559                                 ciphertext_pad_len);
4560         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4561
4562         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4563
4564         /* Create SNOW 3G operation */
4565         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4566                                         tdata->cipher_iv.len,
4567                                         tdata->validCipherLenInBits.len,
4568                                         tdata->cipher.offset_bits);
4569         if (retval < 0)
4570                 return retval;
4571
4572         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4573                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4574                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4575         else
4576                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4577                                                 ut_params->op);
4578         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4579         ut_params->obuf = ut_params->op->sym->m_dst;
4580         if (ut_params->obuf)
4581                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4582         else
4583                 plaintext = ciphertext;
4584
4585         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4586
4587         /* Validate obuf */
4588         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4589                                 tdata->plaintext.data,
4590                                 tdata->validDataLenInBits.len,
4591                                 "SNOW 3G Plaintext data not as expected");
4592         return 0;
4593 }
4594
4595 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4596 {
4597         struct crypto_testsuite_params *ts_params = &testsuite_params;
4598         struct crypto_unittest_params *ut_params = &unittest_params;
4599
4600         int retval;
4601
4602         uint8_t *plaintext, *ciphertext;
4603         unsigned ciphertext_pad_len;
4604         unsigned ciphertext_len;
4605
4606         /* Verify the capabilities */
4607         struct rte_cryptodev_sym_capability_idx cap_idx;
4608         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4609         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4610         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4611                         &cap_idx) == NULL)
4612                 return TEST_SKIPPED;
4613
4614         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4615                 return TEST_SKIPPED;
4616
4617         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4618                 return TEST_SKIPPED;
4619
4620         /* Create SNOW 3G session */
4621         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4622                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4623                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4624                                         tdata->key.data, tdata->key.len,
4625                                         tdata->cipher_iv.len);
4626         if (retval < 0)
4627                 return retval;
4628
4629         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4630         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4631
4632         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4633                         "Failed to allocate input buffer");
4634         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4635                         "Failed to allocate output buffer");
4636
4637         /* Clear mbuf payload */
4638         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4639                rte_pktmbuf_tailroom(ut_params->ibuf));
4640
4641         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4642                        rte_pktmbuf_tailroom(ut_params->obuf));
4643
4644         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4645         /* Append data which is padded to a multiple of */
4646         /* the algorithms block size */
4647         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4648         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4649                                 ciphertext_pad_len);
4650         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4651         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4652
4653         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4654
4655         /* Create SNOW 3G operation */
4656         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4657                                         tdata->cipher_iv.len,
4658                                         tdata->validCipherLenInBits.len,
4659                                         0);
4660         if (retval < 0)
4661                 return retval;
4662
4663         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4664                                                 ut_params->op);
4665         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4666         ut_params->obuf = ut_params->op->sym->m_dst;
4667         if (ut_params->obuf)
4668                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4669         else
4670                 plaintext = ciphertext;
4671
4672         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4673
4674         /* Validate obuf */
4675         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4676                                 tdata->plaintext.data,
4677                                 tdata->validDataLenInBits.len,
4678                                 "SNOW 3G Plaintext data not as expected");
4679         return 0;
4680 }
4681
4682 static int
4683 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4684 {
4685         struct crypto_testsuite_params *ts_params = &testsuite_params;
4686         struct crypto_unittest_params *ut_params = &unittest_params;
4687
4688         int retval;
4689
4690         uint8_t *plaintext, *ciphertext;
4691         unsigned int plaintext_pad_len;
4692         unsigned int plaintext_len;
4693
4694         struct rte_cryptodev_info dev_info;
4695         struct rte_cryptodev_sym_capability_idx cap_idx;
4696
4697         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4698         uint64_t feat_flags = dev_info.feature_flags;
4699
4700         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4701                         ((tdata->validAuthLenInBits.len % 8 != 0) ||
4702                         (tdata->validDataLenInBits.len % 8 != 0))) {
4703                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4704                 return TEST_SKIPPED;
4705         }
4706
4707         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4708                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4709                 printf("Device doesn't support RAW data-path APIs.\n");
4710                 return TEST_SKIPPED;
4711         }
4712
4713         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4714                 return TEST_SKIPPED;
4715
4716         /* Check if device supports ZUC EEA3 */
4717         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4718         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4719
4720         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4721                         &cap_idx) == NULL)
4722                 return TEST_SKIPPED;
4723
4724         /* Check if device supports ZUC EIA3 */
4725         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4726         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4727
4728         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4729                         &cap_idx) == NULL)
4730                 return TEST_SKIPPED;
4731
4732         /* Create ZUC session */
4733         retval = create_zuc_cipher_auth_encrypt_generate_session(
4734                         ts_params->valid_devs[0],
4735                         tdata);
4736         if (retval != 0)
4737                 return retval;
4738         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4739
4740         /* clear mbuf payload */
4741         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4742                         rte_pktmbuf_tailroom(ut_params->ibuf));
4743
4744         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4745         /* Append data which is padded to a multiple of */
4746         /* the algorithms block size */
4747         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4748         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4749                                 plaintext_pad_len);
4750         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4751
4752         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4753
4754         /* Create ZUC operation */
4755         retval = create_zuc_cipher_hash_generate_operation(tdata);
4756         if (retval < 0)
4757                 return retval;
4758
4759         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4760                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4761                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4762         else
4763                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4764                         ut_params->op);
4765         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4766         ut_params->obuf = ut_params->op->sym->m_src;
4767         if (ut_params->obuf)
4768                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4769         else
4770                 ciphertext = plaintext;
4771
4772         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4773         /* Validate obuf */
4774         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4775                         ciphertext,
4776                         tdata->ciphertext.data,
4777                         tdata->validDataLenInBits.len,
4778                         "ZUC Ciphertext data not as expected");
4779
4780         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4781             + plaintext_pad_len;
4782
4783         /* Validate obuf */
4784         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4785                         ut_params->digest,
4786                         tdata->digest.data,
4787                         4,
4788                         "ZUC Generated auth tag not as expected");
4789         return 0;
4790 }
4791
4792 static int
4793 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4794 {
4795         struct crypto_testsuite_params *ts_params = &testsuite_params;
4796         struct crypto_unittest_params *ut_params = &unittest_params;
4797
4798         int retval;
4799
4800         uint8_t *plaintext, *ciphertext;
4801         unsigned plaintext_pad_len;
4802         unsigned plaintext_len;
4803         struct rte_cryptodev_info dev_info;
4804
4805         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4806         uint64_t feat_flags = dev_info.feature_flags;
4807
4808         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4809                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4810                 printf("Device doesn't support RAW data-path APIs.\n");
4811                 return TEST_SKIPPED;
4812         }
4813
4814         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4815                 return TEST_SKIPPED;
4816
4817         /* Verify the capabilities */
4818         struct rte_cryptodev_sym_capability_idx cap_idx;
4819         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4820         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4821         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4822                         &cap_idx) == NULL)
4823                 return TEST_SKIPPED;
4824         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4825         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4826         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4827                         &cap_idx) == NULL)
4828                 return TEST_SKIPPED;
4829
4830         /* Create SNOW 3G session */
4831         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4832                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4833                         RTE_CRYPTO_AUTH_OP_GENERATE,
4834                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4835                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4836                         tdata->key.data, tdata->key.len,
4837                         tdata->auth_iv.len, tdata->digest.len,
4838                         tdata->cipher_iv.len);
4839         if (retval != 0)
4840                 return retval;
4841         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4842
4843         /* clear mbuf payload */
4844         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4845                         rte_pktmbuf_tailroom(ut_params->ibuf));
4846
4847         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4848         /* Append data which is padded to a multiple of */
4849         /* the algorithms block size */
4850         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4851         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4852                                 plaintext_pad_len);
4853         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4854
4855         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4856
4857         /* Create SNOW 3G operation */
4858         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4859                         tdata->digest.len, tdata->auth_iv.data,
4860                         tdata->auth_iv.len,
4861                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4862                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4863                         tdata->validCipherLenInBits.len,
4864                         0,
4865                         tdata->validAuthLenInBits.len,
4866                         0
4867                         );
4868         if (retval < 0)
4869                 return retval;
4870
4871         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4872                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4873                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4874         else
4875                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4876                         ut_params->op);
4877         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4878         ut_params->obuf = ut_params->op->sym->m_src;
4879         if (ut_params->obuf)
4880                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4881         else
4882                 ciphertext = plaintext;
4883
4884         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4885         /* Validate obuf */
4886         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4887                         ciphertext,
4888                         tdata->ciphertext.data,
4889                         tdata->validDataLenInBits.len,
4890                         "SNOW 3G Ciphertext data not as expected");
4891
4892         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4893             + plaintext_pad_len;
4894
4895         /* Validate obuf */
4896         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4897                         ut_params->digest,
4898                         tdata->digest.data,
4899                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4900                         "SNOW 3G Generated auth tag not as expected");
4901         return 0;
4902 }
4903
4904 static int
4905 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4906         uint8_t op_mode, uint8_t verify)
4907 {
4908         struct crypto_testsuite_params *ts_params = &testsuite_params;
4909         struct crypto_unittest_params *ut_params = &unittest_params;
4910
4911         int retval;
4912
4913         uint8_t *plaintext = NULL, *ciphertext = NULL;
4914         unsigned int plaintext_pad_len;
4915         unsigned int plaintext_len;
4916         unsigned int ciphertext_pad_len;
4917         unsigned int ciphertext_len;
4918
4919         struct rte_cryptodev_info dev_info;
4920
4921         /* Verify the capabilities */
4922         struct rte_cryptodev_sym_capability_idx cap_idx;
4923         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4924         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4925         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4926                         &cap_idx) == NULL)
4927                 return TEST_SKIPPED;
4928         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4929         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4930         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4931                         &cap_idx) == NULL)
4932                 return TEST_SKIPPED;
4933
4934         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4935                 return TEST_SKIPPED;
4936
4937         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4938
4939         uint64_t feat_flags = dev_info.feature_flags;
4940
4941         if (op_mode == OUT_OF_PLACE) {
4942                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4943                         printf("Device doesn't support digest encrypted.\n");
4944                         return TEST_SKIPPED;
4945                 }
4946                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4947                         return TEST_SKIPPED;
4948         }
4949
4950         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4951                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4952                 printf("Device doesn't support RAW data-path APIs.\n");
4953                 return TEST_SKIPPED;
4954         }
4955
4956         /* Create SNOW 3G session */
4957         retval = create_wireless_algo_auth_cipher_session(
4958                         ts_params->valid_devs[0],
4959                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4960                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4961                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4962                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4963                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4964                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4965                         tdata->key.data, tdata->key.len,
4966                         tdata->auth_iv.len, tdata->digest.len,
4967                         tdata->cipher_iv.len);
4968         if (retval != 0)
4969                 return retval;
4970
4971         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4972         if (op_mode == OUT_OF_PLACE)
4973                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4974
4975         /* clear mbuf payload */
4976         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4977                 rte_pktmbuf_tailroom(ut_params->ibuf));
4978         if (op_mode == OUT_OF_PLACE)
4979                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4980                         rte_pktmbuf_tailroom(ut_params->obuf));
4981
4982         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4983         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4984         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4985         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4986
4987         if (verify) {
4988                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4989                                         ciphertext_pad_len);
4990                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4991                 if (op_mode == OUT_OF_PLACE)
4992                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4993                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4994                         ciphertext_len);
4995         } else {
4996                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4997                                         plaintext_pad_len);
4998                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4999                 if (op_mode == OUT_OF_PLACE)
5000                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5001                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5002         }
5003
5004         /* Create SNOW 3G operation */
5005         retval = create_wireless_algo_auth_cipher_operation(
5006                 tdata->digest.data, tdata->digest.len,
5007                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5008                 tdata->auth_iv.data, tdata->auth_iv.len,
5009                 (tdata->digest.offset_bytes == 0 ?
5010                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5011                         : tdata->digest.offset_bytes),
5012                 tdata->validCipherLenInBits.len,
5013                 tdata->cipher.offset_bits,
5014                 tdata->validAuthLenInBits.len,
5015                 tdata->auth.offset_bits,
5016                 op_mode, 0, verify);
5017
5018         if (retval < 0)
5019                 return retval;
5020
5021         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5022                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5023                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5024         else
5025                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5026                         ut_params->op);
5027
5028         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5029
5030         ut_params->obuf = (op_mode == IN_PLACE ?
5031                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5032
5033         if (verify) {
5034                 if (ut_params->obuf)
5035                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5036                                                         uint8_t *);
5037                 else
5038                         plaintext = ciphertext +
5039                                 (tdata->cipher.offset_bits >> 3);
5040
5041                 debug_hexdump(stdout, "plaintext:", plaintext,
5042                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5043                 debug_hexdump(stdout, "plaintext expected:",
5044                         tdata->plaintext.data,
5045                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5046         } else {
5047                 if (ut_params->obuf)
5048                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5049                                                         uint8_t *);
5050                 else
5051                         ciphertext = plaintext;
5052
5053                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5054                         ciphertext_len);
5055                 debug_hexdump(stdout, "ciphertext expected:",
5056                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5057
5058                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5059                         + (tdata->digest.offset_bytes == 0 ?
5060                 plaintext_pad_len : tdata->digest.offset_bytes);
5061
5062                 debug_hexdump(stdout, "digest:", ut_params->digest,
5063                         tdata->digest.len);
5064                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5065                                 tdata->digest.len);
5066         }
5067
5068         /* Validate obuf */
5069         if (verify) {
5070                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5071                         plaintext,
5072                         tdata->plaintext.data,
5073                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5074                          (tdata->digest.len << 3)),
5075                         tdata->cipher.offset_bits,
5076                         "SNOW 3G Plaintext data not as expected");
5077         } else {
5078                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5079                         ciphertext,
5080                         tdata->ciphertext.data,
5081                         (tdata->validDataLenInBits.len -
5082                          tdata->cipher.offset_bits),
5083                         tdata->cipher.offset_bits,
5084                         "SNOW 3G Ciphertext data not as expected");
5085
5086                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5087                         ut_params->digest,
5088                         tdata->digest.data,
5089                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5090                         "SNOW 3G Generated auth tag not as expected");
5091         }
5092         return 0;
5093 }
5094
5095 static int
5096 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5097         uint8_t op_mode, uint8_t verify)
5098 {
5099         struct crypto_testsuite_params *ts_params = &testsuite_params;
5100         struct crypto_unittest_params *ut_params = &unittest_params;
5101
5102         int retval;
5103
5104         const uint8_t *plaintext = NULL;
5105         const uint8_t *ciphertext = NULL;
5106         const uint8_t *digest = NULL;
5107         unsigned int plaintext_pad_len;
5108         unsigned int plaintext_len;
5109         unsigned int ciphertext_pad_len;
5110         unsigned int ciphertext_len;
5111         uint8_t buffer[10000];
5112         uint8_t digest_buffer[10000];
5113
5114         struct rte_cryptodev_info dev_info;
5115
5116         /* Verify the capabilities */
5117         struct rte_cryptodev_sym_capability_idx cap_idx;
5118         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5119         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5120         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5121                         &cap_idx) == NULL)
5122                 return TEST_SKIPPED;
5123         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5124         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5125         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5126                         &cap_idx) == NULL)
5127                 return TEST_SKIPPED;
5128
5129         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5130                 return TEST_SKIPPED;
5131
5132         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5133
5134         uint64_t feat_flags = dev_info.feature_flags;
5135
5136         if (op_mode == IN_PLACE) {
5137                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5138                         printf("Device doesn't support in-place scatter-gather "
5139                                         "in both input and output mbufs.\n");
5140                         return TEST_SKIPPED;
5141                 }
5142                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5143                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5144                         printf("Device doesn't support RAW data-path APIs.\n");
5145                         return TEST_SKIPPED;
5146                 }
5147         } else {
5148                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5149                         return TEST_SKIPPED;
5150                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5151                         printf("Device doesn't support out-of-place scatter-gather "
5152                                         "in both input and output mbufs.\n");
5153                         return TEST_SKIPPED;
5154                 }
5155                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5156                         printf("Device doesn't support digest encrypted.\n");
5157                         return TEST_SKIPPED;
5158                 }
5159         }
5160
5161         /* Create SNOW 3G session */
5162         retval = create_wireless_algo_auth_cipher_session(
5163                         ts_params->valid_devs[0],
5164                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5165                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5166                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5167                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5168                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5169                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5170                         tdata->key.data, tdata->key.len,
5171                         tdata->auth_iv.len, tdata->digest.len,
5172                         tdata->cipher_iv.len);
5173
5174         if (retval != 0)
5175                 return retval;
5176
5177         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5178         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5179         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5180         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5181
5182         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5183                         plaintext_pad_len, 15, 0);
5184         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5185                         "Failed to allocate input buffer in mempool");
5186
5187         if (op_mode == OUT_OF_PLACE) {
5188                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5189                                 plaintext_pad_len, 15, 0);
5190                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5191                                 "Failed to allocate output buffer in mempool");
5192         }
5193
5194         if (verify) {
5195                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5196                         tdata->ciphertext.data);
5197                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5198                                         ciphertext_len, buffer);
5199                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5200                         ciphertext_len);
5201         } else {
5202                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5203                         tdata->plaintext.data);
5204                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5205                                         plaintext_len, buffer);
5206                 debug_hexdump(stdout, "plaintext:", plaintext,
5207                         plaintext_len);
5208         }
5209         memset(buffer, 0, sizeof(buffer));
5210
5211         /* Create SNOW 3G operation */
5212         retval = create_wireless_algo_auth_cipher_operation(
5213                 tdata->digest.data, tdata->digest.len,
5214                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5215                 tdata->auth_iv.data, tdata->auth_iv.len,
5216                 (tdata->digest.offset_bytes == 0 ?
5217                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5218                         : tdata->digest.offset_bytes),
5219                 tdata->validCipherLenInBits.len,
5220                 tdata->cipher.offset_bits,
5221                 tdata->validAuthLenInBits.len,
5222                 tdata->auth.offset_bits,
5223                 op_mode, 1, verify);
5224
5225         if (retval < 0)
5226                 return retval;
5227
5228         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5229                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5230                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5231         else
5232                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5233                         ut_params->op);
5234
5235         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5236
5237         ut_params->obuf = (op_mode == IN_PLACE ?
5238                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5239
5240         if (verify) {
5241                 if (ut_params->obuf)
5242                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5243                                         plaintext_len, buffer);
5244                 else
5245                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5246                                         plaintext_len, buffer);
5247
5248                 debug_hexdump(stdout, "plaintext:", plaintext,
5249                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5250                 debug_hexdump(stdout, "plaintext expected:",
5251                         tdata->plaintext.data,
5252                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5253         } else {
5254                 if (ut_params->obuf)
5255                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5256                                         ciphertext_len, buffer);
5257                 else
5258                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5259                                         ciphertext_len, buffer);
5260
5261                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5262                         ciphertext_len);
5263                 debug_hexdump(stdout, "ciphertext expected:",
5264                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5265
5266                 if (ut_params->obuf)
5267                         digest = rte_pktmbuf_read(ut_params->obuf,
5268                                 (tdata->digest.offset_bytes == 0 ?
5269                                 plaintext_pad_len : tdata->digest.offset_bytes),
5270                                 tdata->digest.len, digest_buffer);
5271                 else
5272                         digest = rte_pktmbuf_read(ut_params->ibuf,
5273                                 (tdata->digest.offset_bytes == 0 ?
5274                                 plaintext_pad_len : tdata->digest.offset_bytes),
5275                                 tdata->digest.len, digest_buffer);
5276
5277                 debug_hexdump(stdout, "digest:", digest,
5278                         tdata->digest.len);
5279                 debug_hexdump(stdout, "digest expected:",
5280                         tdata->digest.data, tdata->digest.len);
5281         }
5282
5283         /* Validate obuf */
5284         if (verify) {
5285                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5286                         plaintext,
5287                         tdata->plaintext.data,
5288                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5289                          (tdata->digest.len << 3)),
5290                         tdata->cipher.offset_bits,
5291                         "SNOW 3G Plaintext data not as expected");
5292         } else {
5293                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5294                         ciphertext,
5295                         tdata->ciphertext.data,
5296                         (tdata->validDataLenInBits.len -
5297                          tdata->cipher.offset_bits),
5298                         tdata->cipher.offset_bits,
5299                         "SNOW 3G Ciphertext data not as expected");
5300
5301                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5302                         digest,
5303                         tdata->digest.data,
5304                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5305                         "SNOW 3G Generated auth tag not as expected");
5306         }
5307         return 0;
5308 }
5309
5310 static int
5311 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5312         uint8_t op_mode, uint8_t verify)
5313 {
5314         struct crypto_testsuite_params *ts_params = &testsuite_params;
5315         struct crypto_unittest_params *ut_params = &unittest_params;
5316
5317         int retval;
5318
5319         uint8_t *plaintext = NULL, *ciphertext = NULL;
5320         unsigned int plaintext_pad_len;
5321         unsigned int plaintext_len;
5322         unsigned int ciphertext_pad_len;
5323         unsigned int ciphertext_len;
5324
5325         struct rte_cryptodev_info dev_info;
5326
5327         /* Verify the capabilities */
5328         struct rte_cryptodev_sym_capability_idx cap_idx;
5329         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5330         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5331         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5332                         &cap_idx) == NULL)
5333                 return TEST_SKIPPED;
5334         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5335         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5336         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5337                         &cap_idx) == NULL)
5338                 return TEST_SKIPPED;
5339
5340         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5341
5342         uint64_t feat_flags = dev_info.feature_flags;
5343
5344         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5345                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5346                 printf("Device doesn't support RAW data-path APIs.\n");
5347                 return TEST_SKIPPED;
5348         }
5349
5350         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5351                 return TEST_SKIPPED;
5352
5353         if (op_mode == OUT_OF_PLACE) {
5354                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5355                         return TEST_SKIPPED;
5356                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5357                         printf("Device doesn't support digest encrypted.\n");
5358                         return TEST_SKIPPED;
5359                 }
5360         }
5361
5362         /* Create KASUMI session */
5363         retval = create_wireless_algo_auth_cipher_session(
5364                         ts_params->valid_devs[0],
5365                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5366                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5367                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5368                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5369                         RTE_CRYPTO_AUTH_KASUMI_F9,
5370                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5371                         tdata->key.data, tdata->key.len,
5372                         0, tdata->digest.len,
5373                         tdata->cipher_iv.len);
5374
5375         if (retval != 0)
5376                 return retval;
5377
5378         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5379         if (op_mode == OUT_OF_PLACE)
5380                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5381
5382         /* clear mbuf payload */
5383         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5384                 rte_pktmbuf_tailroom(ut_params->ibuf));
5385         if (op_mode == OUT_OF_PLACE)
5386                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5387                         rte_pktmbuf_tailroom(ut_params->obuf));
5388
5389         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5390         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5391         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5392         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5393
5394         if (verify) {
5395                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5396                                         ciphertext_pad_len);
5397                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5398                 if (op_mode == OUT_OF_PLACE)
5399                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5400                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5401                         ciphertext_len);
5402         } else {
5403                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5404                                         plaintext_pad_len);
5405                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5406                 if (op_mode == OUT_OF_PLACE)
5407                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5408                 debug_hexdump(stdout, "plaintext:", plaintext,
5409                         plaintext_len);
5410         }
5411
5412         /* Create KASUMI operation */
5413         retval = create_wireless_algo_auth_cipher_operation(
5414                 tdata->digest.data, tdata->digest.len,
5415                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5416                 NULL, 0,
5417                 (tdata->digest.offset_bytes == 0 ?
5418                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5419                         : tdata->digest.offset_bytes),
5420                 tdata->validCipherLenInBits.len,
5421                 tdata->validCipherOffsetInBits.len,
5422                 tdata->validAuthLenInBits.len,
5423                 0,
5424                 op_mode, 0, verify);
5425
5426         if (retval < 0)
5427                 return retval;
5428
5429         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5430                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5431                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5432         else
5433                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5434                         ut_params->op);
5435
5436         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5437
5438         ut_params->obuf = (op_mode == IN_PLACE ?
5439                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5440
5441
5442         if (verify) {
5443                 if (ut_params->obuf)
5444                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5445                                                         uint8_t *);
5446                 else
5447                         plaintext = ciphertext;
5448
5449                 debug_hexdump(stdout, "plaintext:", plaintext,
5450                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5451                 debug_hexdump(stdout, "plaintext expected:",
5452                         tdata->plaintext.data,
5453                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5454         } else {
5455                 if (ut_params->obuf)
5456                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5457                                                         uint8_t *);
5458                 else
5459                         ciphertext = plaintext;
5460
5461                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5462                         ciphertext_len);
5463                 debug_hexdump(stdout, "ciphertext expected:",
5464                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5465
5466                 ut_params->digest = rte_pktmbuf_mtod(
5467                         ut_params->obuf, uint8_t *) +
5468                         (tdata->digest.offset_bytes == 0 ?
5469                         plaintext_pad_len : tdata->digest.offset_bytes);
5470
5471                 debug_hexdump(stdout, "digest:", ut_params->digest,
5472                         tdata->digest.len);
5473                 debug_hexdump(stdout, "digest expected:",
5474                         tdata->digest.data, tdata->digest.len);
5475         }
5476
5477         /* Validate obuf */
5478         if (verify) {
5479                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5480                         plaintext,
5481                         tdata->plaintext.data,
5482                         tdata->plaintext.len >> 3,
5483                         "KASUMI Plaintext data not as expected");
5484         } else {
5485                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5486                         ciphertext,
5487                         tdata->ciphertext.data,
5488                         tdata->ciphertext.len >> 3,
5489                         "KASUMI Ciphertext data not as expected");
5490
5491                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5492                         ut_params->digest,
5493                         tdata->digest.data,
5494                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5495                         "KASUMI Generated auth tag not as expected");
5496         }
5497         return 0;
5498 }
5499
5500 static int
5501 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5502         uint8_t op_mode, uint8_t verify)
5503 {
5504         struct crypto_testsuite_params *ts_params = &testsuite_params;
5505         struct crypto_unittest_params *ut_params = &unittest_params;
5506
5507         int retval;
5508
5509         const uint8_t *plaintext = NULL;
5510         const uint8_t *ciphertext = NULL;
5511         const uint8_t *digest = NULL;
5512         unsigned int plaintext_pad_len;
5513         unsigned int plaintext_len;
5514         unsigned int ciphertext_pad_len;
5515         unsigned int ciphertext_len;
5516         uint8_t buffer[10000];
5517         uint8_t digest_buffer[10000];
5518
5519         struct rte_cryptodev_info dev_info;
5520
5521         /* Verify the capabilities */
5522         struct rte_cryptodev_sym_capability_idx cap_idx;
5523         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5524         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5525         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5526                         &cap_idx) == NULL)
5527                 return TEST_SKIPPED;
5528         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5529         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5530         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5531                         &cap_idx) == NULL)
5532                 return TEST_SKIPPED;
5533
5534         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5535                 return TEST_SKIPPED;
5536
5537         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5538
5539         uint64_t feat_flags = dev_info.feature_flags;
5540
5541         if (op_mode == IN_PLACE) {
5542                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5543                         printf("Device doesn't support in-place scatter-gather "
5544                                         "in both input and output mbufs.\n");
5545                         return TEST_SKIPPED;
5546                 }
5547                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5548                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5549                         printf("Device doesn't support RAW data-path APIs.\n");
5550                         return TEST_SKIPPED;
5551                 }
5552         } else {
5553                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5554                         return TEST_SKIPPED;
5555                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5556                         printf("Device doesn't support out-of-place scatter-gather "
5557                                         "in both input and output mbufs.\n");
5558                         return TEST_SKIPPED;
5559                 }
5560                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5561                         printf("Device doesn't support digest encrypted.\n");
5562                         return TEST_SKIPPED;
5563                 }
5564         }
5565
5566         /* Create KASUMI session */
5567         retval = create_wireless_algo_auth_cipher_session(
5568                         ts_params->valid_devs[0],
5569                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5570                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5571                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5572                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5573                         RTE_CRYPTO_AUTH_KASUMI_F9,
5574                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5575                         tdata->key.data, tdata->key.len,
5576                         0, tdata->digest.len,
5577                         tdata->cipher_iv.len);
5578
5579         if (retval != 0)
5580                 return retval;
5581
5582         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5583         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5584         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5585         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5586
5587         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5588                         plaintext_pad_len, 15, 0);
5589         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5590                         "Failed to allocate input buffer in mempool");
5591
5592         if (op_mode == OUT_OF_PLACE) {
5593                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5594                                 plaintext_pad_len, 15, 0);
5595                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5596                                 "Failed to allocate output buffer in mempool");
5597         }
5598
5599         if (verify) {
5600                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5601                         tdata->ciphertext.data);
5602                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5603                                         ciphertext_len, buffer);
5604                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5605                         ciphertext_len);
5606         } else {
5607                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5608                         tdata->plaintext.data);
5609                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5610                                         plaintext_len, buffer);
5611                 debug_hexdump(stdout, "plaintext:", plaintext,
5612                         plaintext_len);
5613         }
5614         memset(buffer, 0, sizeof(buffer));
5615
5616         /* Create KASUMI operation */
5617         retval = create_wireless_algo_auth_cipher_operation(
5618                 tdata->digest.data, tdata->digest.len,
5619                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5620                 NULL, 0,
5621                 (tdata->digest.offset_bytes == 0 ?
5622                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5623                         : tdata->digest.offset_bytes),
5624                 tdata->validCipherLenInBits.len,
5625                 tdata->validCipherOffsetInBits.len,
5626                 tdata->validAuthLenInBits.len,
5627                 0,
5628                 op_mode, 1, verify);
5629
5630         if (retval < 0)
5631                 return retval;
5632
5633         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5634                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5635                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5636         else
5637                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5638                         ut_params->op);
5639
5640         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5641
5642         ut_params->obuf = (op_mode == IN_PLACE ?
5643                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5644
5645         if (verify) {
5646                 if (ut_params->obuf)
5647                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5648                                         plaintext_len, buffer);
5649                 else
5650                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5651                                         plaintext_len, buffer);
5652
5653                 debug_hexdump(stdout, "plaintext:", plaintext,
5654                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5655                 debug_hexdump(stdout, "plaintext expected:",
5656                         tdata->plaintext.data,
5657                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5658         } else {
5659                 if (ut_params->obuf)
5660                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5661                                         ciphertext_len, buffer);
5662                 else
5663                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5664                                         ciphertext_len, buffer);
5665
5666                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5667                         ciphertext_len);
5668                 debug_hexdump(stdout, "ciphertext expected:",
5669                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5670
5671                 if (ut_params->obuf)
5672                         digest = rte_pktmbuf_read(ut_params->obuf,
5673                                 (tdata->digest.offset_bytes == 0 ?
5674                                 plaintext_pad_len : tdata->digest.offset_bytes),
5675                                 tdata->digest.len, digest_buffer);
5676                 else
5677                         digest = rte_pktmbuf_read(ut_params->ibuf,
5678                                 (tdata->digest.offset_bytes == 0 ?
5679                                 plaintext_pad_len : tdata->digest.offset_bytes),
5680                                 tdata->digest.len, digest_buffer);
5681
5682                 debug_hexdump(stdout, "digest:", digest,
5683                         tdata->digest.len);
5684                 debug_hexdump(stdout, "digest expected:",
5685                         tdata->digest.data, tdata->digest.len);
5686         }
5687
5688         /* Validate obuf */
5689         if (verify) {
5690                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5691                         plaintext,
5692                         tdata->plaintext.data,
5693                         tdata->plaintext.len >> 3,
5694                         "KASUMI Plaintext data not as expected");
5695         } else {
5696                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5697                         ciphertext,
5698                         tdata->ciphertext.data,
5699                         tdata->validDataLenInBits.len,
5700                         "KASUMI Ciphertext data not as expected");
5701
5702                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5703                         digest,
5704                         tdata->digest.data,
5705                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5706                         "KASUMI Generated auth tag not as expected");
5707         }
5708         return 0;
5709 }
5710
5711 static int
5712 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5713 {
5714         struct crypto_testsuite_params *ts_params = &testsuite_params;
5715         struct crypto_unittest_params *ut_params = &unittest_params;
5716
5717         int retval;
5718
5719         uint8_t *plaintext, *ciphertext;
5720         unsigned plaintext_pad_len;
5721         unsigned plaintext_len;
5722         struct rte_cryptodev_info dev_info;
5723
5724         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5725         uint64_t feat_flags = dev_info.feature_flags;
5726
5727         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5728                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5729                 printf("Device doesn't support RAW data-path APIs.\n");
5730                 return TEST_SKIPPED;
5731         }
5732
5733         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5734                 return TEST_SKIPPED;
5735
5736         /* Verify the capabilities */
5737         struct rte_cryptodev_sym_capability_idx cap_idx;
5738         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5739         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5740         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5741                         &cap_idx) == NULL)
5742                 return TEST_SKIPPED;
5743         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5744         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5745         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5746                         &cap_idx) == NULL)
5747                 return TEST_SKIPPED;
5748
5749         /* Create KASUMI session */
5750         retval = create_wireless_algo_cipher_auth_session(
5751                         ts_params->valid_devs[0],
5752                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5753                         RTE_CRYPTO_AUTH_OP_GENERATE,
5754                         RTE_CRYPTO_AUTH_KASUMI_F9,
5755                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5756                         tdata->key.data, tdata->key.len,
5757                         0, tdata->digest.len,
5758                         tdata->cipher_iv.len);
5759         if (retval != 0)
5760                 return retval;
5761
5762         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5763
5764         /* clear mbuf payload */
5765         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5766                         rte_pktmbuf_tailroom(ut_params->ibuf));
5767
5768         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5769         /* Append data which is padded to a multiple of */
5770         /* the algorithms block size */
5771         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5772         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5773                                 plaintext_pad_len);
5774         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5775
5776         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5777
5778         /* Create KASUMI operation */
5779         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5780                                 tdata->digest.len, NULL, 0,
5781                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5782                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5783                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5784                                 tdata->validCipherOffsetInBits.len,
5785                                 tdata->validAuthLenInBits.len,
5786                                 0
5787                                 );
5788         if (retval < 0)
5789                 return retval;
5790
5791         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5792                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5793                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5794         else
5795                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5796                         ut_params->op);
5797         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5798
5799         if (ut_params->op->sym->m_dst)
5800                 ut_params->obuf = ut_params->op->sym->m_dst;
5801         else
5802                 ut_params->obuf = ut_params->op->sym->m_src;
5803
5804         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5805                                 tdata->validCipherOffsetInBits.len >> 3);
5806
5807         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5808                         + plaintext_pad_len;
5809
5810         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5811                                 (tdata->validCipherOffsetInBits.len >> 3);
5812         /* Validate obuf */
5813         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5814                 ciphertext,
5815                 reference_ciphertext,
5816                 tdata->validCipherLenInBits.len,
5817                 "KASUMI Ciphertext data not as expected");
5818
5819         /* Validate obuf */
5820         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5821                 ut_params->digest,
5822                 tdata->digest.data,
5823                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5824                 "KASUMI Generated auth tag not as expected");
5825         return 0;
5826 }
5827
5828 static int
5829 test_zuc_encryption(const struct wireless_test_data *tdata)
5830 {
5831         struct crypto_testsuite_params *ts_params = &testsuite_params;
5832         struct crypto_unittest_params *ut_params = &unittest_params;
5833
5834         int retval;
5835         uint8_t *plaintext, *ciphertext;
5836         unsigned plaintext_pad_len;
5837         unsigned plaintext_len;
5838         struct rte_cryptodev_info dev_info;
5839
5840         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5841         uint64_t feat_flags = dev_info.feature_flags;
5842
5843         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5844                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5845                 printf("Device doesn't support RAW data-path APIs.\n");
5846                 return TEST_SKIPPED;
5847         }
5848
5849         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5850                 return TEST_SKIPPED;
5851
5852         struct rte_cryptodev_sym_capability_idx cap_idx;
5853
5854         /* Check if device supports ZUC EEA3 */
5855         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5856         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5857
5858         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5859                         &cap_idx) == NULL)
5860                 return TEST_SKIPPED;
5861
5862         /* Create ZUC session */
5863         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5864                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5865                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5866                                         tdata->key.data, tdata->key.len,
5867                                         tdata->cipher_iv.len);
5868         if (retval != 0)
5869                 return retval;
5870
5871         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5872
5873         /* Clear mbuf payload */
5874         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5875                rte_pktmbuf_tailroom(ut_params->ibuf));
5876
5877         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5878         /* Append data which is padded to a multiple */
5879         /* of the algorithms block size */
5880         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5881         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5882                                 plaintext_pad_len);
5883         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5884
5885         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5886
5887         /* Create ZUC operation */
5888         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5889                                         tdata->cipher_iv.len,
5890                                         tdata->plaintext.len,
5891                                         0);
5892         if (retval < 0)
5893                 return retval;
5894
5895         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5896                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5897                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5898         else
5899                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5900                                                 ut_params->op);
5901         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5902
5903         ut_params->obuf = ut_params->op->sym->m_dst;
5904         if (ut_params->obuf)
5905                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5906         else
5907                 ciphertext = plaintext;
5908
5909         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5910
5911         /* Validate obuf */
5912         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5913                 ciphertext,
5914                 tdata->ciphertext.data,
5915                 tdata->validCipherLenInBits.len,
5916                 "ZUC Ciphertext data not as expected");
5917         return 0;
5918 }
5919
5920 static int
5921 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5922 {
5923         struct crypto_testsuite_params *ts_params = &testsuite_params;
5924         struct crypto_unittest_params *ut_params = &unittest_params;
5925
5926         int retval;
5927
5928         unsigned int plaintext_pad_len;
5929         unsigned int plaintext_len;
5930         const uint8_t *ciphertext;
5931         uint8_t ciphertext_buffer[2048];
5932         struct rte_cryptodev_info dev_info;
5933
5934         struct rte_cryptodev_sym_capability_idx cap_idx;
5935
5936         /* Check if device supports ZUC EEA3 */
5937         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5938         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5939
5940         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5941                         &cap_idx) == NULL)
5942                 return TEST_SKIPPED;
5943
5944         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5945                 return TEST_SKIPPED;
5946
5947         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5948
5949         uint64_t feat_flags = dev_info.feature_flags;
5950
5951         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5952                 printf("Device doesn't support in-place scatter-gather. "
5953                                 "Test Skipped.\n");
5954                 return TEST_SKIPPED;
5955         }
5956
5957         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5958                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5959                 printf("Device doesn't support RAW data-path APIs.\n");
5960                 return TEST_SKIPPED;
5961         }
5962
5963         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5964
5965         /* Append data which is padded to a multiple */
5966         /* of the algorithms block size */
5967         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5968
5969         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5970                         plaintext_pad_len, 10, 0);
5971
5972         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5973                         tdata->plaintext.data);
5974
5975         /* Create ZUC session */
5976         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5977                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5978                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5979                         tdata->key.data, tdata->key.len,
5980                         tdata->cipher_iv.len);
5981         if (retval < 0)
5982                 return retval;
5983
5984         /* Clear mbuf payload */
5985
5986         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5987
5988         /* Create ZUC operation */
5989         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5990                         tdata->cipher_iv.len, tdata->plaintext.len,
5991                         0);
5992         if (retval < 0)
5993                 return retval;
5994
5995         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5996                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5997                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5998         else
5999                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6000                                                 ut_params->op);
6001         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6002
6003         ut_params->obuf = ut_params->op->sym->m_dst;
6004         if (ut_params->obuf)
6005                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
6006                         0, plaintext_len, ciphertext_buffer);
6007         else
6008                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6009                         0, plaintext_len, ciphertext_buffer);
6010
6011         /* Validate obuf */
6012         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6013
6014         /* Validate obuf */
6015         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6016                 ciphertext,
6017                 tdata->ciphertext.data,
6018                 tdata->validCipherLenInBits.len,
6019                 "ZUC Ciphertext data not as expected");
6020
6021         return 0;
6022 }
6023
6024 static int
6025 test_zuc_authentication(const struct wireless_test_data *tdata)
6026 {
6027         struct crypto_testsuite_params *ts_params = &testsuite_params;
6028         struct crypto_unittest_params *ut_params = &unittest_params;
6029
6030         int retval;
6031         unsigned plaintext_pad_len;
6032         unsigned plaintext_len;
6033         uint8_t *plaintext;
6034
6035         struct rte_cryptodev_sym_capability_idx cap_idx;
6036         struct rte_cryptodev_info dev_info;
6037
6038         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6039         uint64_t feat_flags = dev_info.feature_flags;
6040
6041         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6042                         (tdata->validAuthLenInBits.len % 8 != 0)) {
6043                 printf("Device doesn't support NON-Byte Aligned Data.\n");
6044                 return TEST_SKIPPED;
6045         }
6046
6047         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6048                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6049                 printf("Device doesn't support RAW data-path APIs.\n");
6050                 return TEST_SKIPPED;
6051         }
6052
6053         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6054                 return TEST_SKIPPED;
6055
6056         /* Check if device supports ZUC EIA3 */
6057         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6058         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6059
6060         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6061                         &cap_idx) == NULL)
6062                 return TEST_SKIPPED;
6063
6064         /* Create ZUC session */
6065         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6066                         tdata->key.data, tdata->key.len,
6067                         tdata->auth_iv.len, tdata->digest.len,
6068                         RTE_CRYPTO_AUTH_OP_GENERATE,
6069                         RTE_CRYPTO_AUTH_ZUC_EIA3);
6070         if (retval != 0)
6071                 return retval;
6072
6073         /* alloc mbuf and set payload */
6074         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6075
6076         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6077         rte_pktmbuf_tailroom(ut_params->ibuf));
6078
6079         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6080         /* Append data which is padded to a multiple of */
6081         /* the algorithms block size */
6082         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6083         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6084                                 plaintext_pad_len);
6085         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6086
6087         /* Create ZUC operation */
6088         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6089                         tdata->auth_iv.data, tdata->auth_iv.len,
6090                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6091                         tdata->validAuthLenInBits.len,
6092                         0);
6093         if (retval < 0)
6094                 return retval;
6095
6096         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6097                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6098                                 ut_params->op, 0, 1, 1, 0);
6099         else
6100                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6101                                 ut_params->op);
6102         ut_params->obuf = ut_params->op->sym->m_src;
6103         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6104         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6105                         + plaintext_pad_len;
6106
6107         /* Validate obuf */
6108         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6109         ut_params->digest,
6110         tdata->digest.data,
6111         tdata->digest.len,
6112         "ZUC Generated auth tag not as expected");
6113
6114         return 0;
6115 }
6116
6117 static int
6118 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6119         uint8_t op_mode, uint8_t verify)
6120 {
6121         struct crypto_testsuite_params *ts_params = &testsuite_params;
6122         struct crypto_unittest_params *ut_params = &unittest_params;
6123
6124         int retval;
6125
6126         uint8_t *plaintext = NULL, *ciphertext = NULL;
6127         unsigned int plaintext_pad_len;
6128         unsigned int plaintext_len;
6129         unsigned int ciphertext_pad_len;
6130         unsigned int ciphertext_len;
6131
6132         struct rte_cryptodev_info dev_info;
6133         struct rte_cryptodev_sym_capability_idx cap_idx;
6134
6135         /* Check if device supports ZUC EIA3 */
6136         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6137         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6138
6139         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6140                         &cap_idx) == NULL)
6141                 return TEST_SKIPPED;
6142
6143         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6144
6145         uint64_t feat_flags = dev_info.feature_flags;
6146
6147         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6148                 printf("Device doesn't support digest encrypted.\n");
6149                 return TEST_SKIPPED;
6150         }
6151         if (op_mode == IN_PLACE) {
6152                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6153                         printf("Device doesn't support in-place scatter-gather "
6154                                         "in both input and output mbufs.\n");
6155                         return TEST_SKIPPED;
6156                 }
6157
6158                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6159                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6160                         printf("Device doesn't support RAW data-path APIs.\n");
6161                         return TEST_SKIPPED;
6162                 }
6163         } else {
6164                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6165                         return TEST_SKIPPED;
6166                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6167                         printf("Device doesn't support out-of-place scatter-gather "
6168                                         "in both input and output mbufs.\n");
6169                         return TEST_SKIPPED;
6170                 }
6171         }
6172
6173         /* Create ZUC session */
6174         retval = create_wireless_algo_auth_cipher_session(
6175                         ts_params->valid_devs[0],
6176                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6177                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6178                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6179                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6180                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6181                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6182                         tdata->key.data, tdata->key.len,
6183                         tdata->auth_iv.len, tdata->digest.len,
6184                         tdata->cipher_iv.len);
6185
6186         if (retval != 0)
6187                 return retval;
6188
6189         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6190         if (op_mode == OUT_OF_PLACE)
6191                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6192
6193         /* clear mbuf payload */
6194         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6195                 rte_pktmbuf_tailroom(ut_params->ibuf));
6196         if (op_mode == OUT_OF_PLACE)
6197                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6198                         rte_pktmbuf_tailroom(ut_params->obuf));
6199
6200         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6201         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6202         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6203         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6204
6205         if (verify) {
6206                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6207                                         ciphertext_pad_len);
6208                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6209                 if (op_mode == OUT_OF_PLACE)
6210                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6211                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6212                         ciphertext_len);
6213         } else {
6214                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6215                                         plaintext_pad_len);
6216                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6217                 if (op_mode == OUT_OF_PLACE)
6218                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6219                 debug_hexdump(stdout, "plaintext:", plaintext,
6220                         plaintext_len);
6221         }
6222
6223         /* Create ZUC operation */
6224         retval = create_wireless_algo_auth_cipher_operation(
6225                 tdata->digest.data, tdata->digest.len,
6226                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6227                 tdata->auth_iv.data, tdata->auth_iv.len,
6228                 (tdata->digest.offset_bytes == 0 ?
6229                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6230                         : tdata->digest.offset_bytes),
6231                 tdata->validCipherLenInBits.len,
6232                 tdata->validCipherOffsetInBits.len,
6233                 tdata->validAuthLenInBits.len,
6234                 0,
6235                 op_mode, 0, verify);
6236
6237         if (retval < 0)
6238                 return retval;
6239
6240         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6241                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6242                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6243         else
6244                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6245                         ut_params->op);
6246
6247         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6248
6249         ut_params->obuf = (op_mode == IN_PLACE ?
6250                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6251
6252
6253         if (verify) {
6254                 if (ut_params->obuf)
6255                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6256                                                         uint8_t *);
6257                 else
6258                         plaintext = ciphertext;
6259
6260                 debug_hexdump(stdout, "plaintext:", plaintext,
6261                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6262                 debug_hexdump(stdout, "plaintext expected:",
6263                         tdata->plaintext.data,
6264                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6265         } else {
6266                 if (ut_params->obuf)
6267                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6268                                                         uint8_t *);
6269                 else
6270                         ciphertext = plaintext;
6271
6272                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6273                         ciphertext_len);
6274                 debug_hexdump(stdout, "ciphertext expected:",
6275                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6276
6277                 ut_params->digest = rte_pktmbuf_mtod(
6278                         ut_params->obuf, uint8_t *) +
6279                         (tdata->digest.offset_bytes == 0 ?
6280                         plaintext_pad_len : tdata->digest.offset_bytes);
6281
6282                 debug_hexdump(stdout, "digest:", ut_params->digest,
6283                         tdata->digest.len);
6284                 debug_hexdump(stdout, "digest expected:",
6285                         tdata->digest.data, tdata->digest.len);
6286         }
6287
6288         /* Validate obuf */
6289         if (verify) {
6290                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6291                         plaintext,
6292                         tdata->plaintext.data,
6293                         tdata->plaintext.len >> 3,
6294                         "ZUC Plaintext data not as expected");
6295         } else {
6296                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6297                         ciphertext,
6298                         tdata->ciphertext.data,
6299                         tdata->ciphertext.len >> 3,
6300                         "ZUC Ciphertext data not as expected");
6301
6302                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6303                         ut_params->digest,
6304                         tdata->digest.data,
6305                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6306                         "ZUC Generated auth tag not as expected");
6307         }
6308         return 0;
6309 }
6310
6311 static int
6312 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6313         uint8_t op_mode, uint8_t verify)
6314 {
6315         struct crypto_testsuite_params *ts_params = &testsuite_params;
6316         struct crypto_unittest_params *ut_params = &unittest_params;
6317
6318         int retval;
6319
6320         const uint8_t *plaintext = NULL;
6321         const uint8_t *ciphertext = NULL;
6322         const uint8_t *digest = NULL;
6323         unsigned int plaintext_pad_len;
6324         unsigned int plaintext_len;
6325         unsigned int ciphertext_pad_len;
6326         unsigned int ciphertext_len;
6327         uint8_t buffer[10000];
6328         uint8_t digest_buffer[10000];
6329
6330         struct rte_cryptodev_info dev_info;
6331         struct rte_cryptodev_sym_capability_idx cap_idx;
6332
6333         /* Check if device supports ZUC EIA3 */
6334         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6335         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6336
6337         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6338                         &cap_idx) == NULL)
6339                 return TEST_SKIPPED;
6340
6341         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6342
6343         uint64_t feat_flags = dev_info.feature_flags;
6344
6345         if (op_mode == IN_PLACE) {
6346                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6347                         printf("Device doesn't support in-place scatter-gather "
6348                                         "in both input and output mbufs.\n");
6349                         return TEST_SKIPPED;
6350                 }
6351
6352                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6353                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6354                         printf("Device doesn't support RAW data-path APIs.\n");
6355                         return TEST_SKIPPED;
6356                 }
6357         } else {
6358                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6359                         return TEST_SKIPPED;
6360                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6361                         printf("Device doesn't support out-of-place scatter-gather "
6362                                         "in both input and output mbufs.\n");
6363                         return TEST_SKIPPED;
6364                 }
6365                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6366                         printf("Device doesn't support digest encrypted.\n");
6367                         return TEST_SKIPPED;
6368                 }
6369         }
6370
6371         /* Create ZUC session */
6372         retval = create_wireless_algo_auth_cipher_session(
6373                         ts_params->valid_devs[0],
6374                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6375                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6376                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6377                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6378                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6379                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6380                         tdata->key.data, tdata->key.len,
6381                         tdata->auth_iv.len, tdata->digest.len,
6382                         tdata->cipher_iv.len);
6383
6384         if (retval != 0)
6385                 return retval;
6386
6387         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6388         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6389         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6390         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6391
6392         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6393                         plaintext_pad_len, 15, 0);
6394         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6395                         "Failed to allocate input buffer in mempool");
6396
6397         if (op_mode == OUT_OF_PLACE) {
6398                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6399                                 plaintext_pad_len, 15, 0);
6400                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6401                                 "Failed to allocate output buffer in mempool");
6402         }
6403
6404         if (verify) {
6405                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6406                         tdata->ciphertext.data);
6407                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6408                                         ciphertext_len, buffer);
6409                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6410                         ciphertext_len);
6411         } else {
6412                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6413                         tdata->plaintext.data);
6414                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6415                                         plaintext_len, buffer);
6416                 debug_hexdump(stdout, "plaintext:", plaintext,
6417                         plaintext_len);
6418         }
6419         memset(buffer, 0, sizeof(buffer));
6420
6421         /* Create ZUC operation */
6422         retval = create_wireless_algo_auth_cipher_operation(
6423                 tdata->digest.data, tdata->digest.len,
6424                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6425                 NULL, 0,
6426                 (tdata->digest.offset_bytes == 0 ?
6427                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6428                         : tdata->digest.offset_bytes),
6429                 tdata->validCipherLenInBits.len,
6430                 tdata->validCipherOffsetInBits.len,
6431                 tdata->validAuthLenInBits.len,
6432                 0,
6433                 op_mode, 1, verify);
6434
6435         if (retval < 0)
6436                 return retval;
6437
6438         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6439                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6440                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6441         else
6442                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6443                         ut_params->op);
6444
6445         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6446
6447         ut_params->obuf = (op_mode == IN_PLACE ?
6448                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6449
6450         if (verify) {
6451                 if (ut_params->obuf)
6452                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6453                                         plaintext_len, buffer);
6454                 else
6455                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6456                                         plaintext_len, buffer);
6457
6458                 debug_hexdump(stdout, "plaintext:", plaintext,
6459                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6460                 debug_hexdump(stdout, "plaintext expected:",
6461                         tdata->plaintext.data,
6462                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6463         } else {
6464                 if (ut_params->obuf)
6465                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6466                                         ciphertext_len, buffer);
6467                 else
6468                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6469                                         ciphertext_len, buffer);
6470
6471                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6472                         ciphertext_len);
6473                 debug_hexdump(stdout, "ciphertext expected:",
6474                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6475
6476                 if (ut_params->obuf)
6477                         digest = rte_pktmbuf_read(ut_params->obuf,
6478                                 (tdata->digest.offset_bytes == 0 ?
6479                                 plaintext_pad_len : tdata->digest.offset_bytes),
6480                                 tdata->digest.len, digest_buffer);
6481                 else
6482                         digest = rte_pktmbuf_read(ut_params->ibuf,
6483                                 (tdata->digest.offset_bytes == 0 ?
6484                                 plaintext_pad_len : tdata->digest.offset_bytes),
6485                                 tdata->digest.len, digest_buffer);
6486
6487                 debug_hexdump(stdout, "digest:", digest,
6488                         tdata->digest.len);
6489                 debug_hexdump(stdout, "digest expected:",
6490                         tdata->digest.data, tdata->digest.len);
6491         }
6492
6493         /* Validate obuf */
6494         if (verify) {
6495                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6496                         plaintext,
6497                         tdata->plaintext.data,
6498                         tdata->plaintext.len >> 3,
6499                         "ZUC Plaintext data not as expected");
6500         } else {
6501                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6502                         ciphertext,
6503                         tdata->ciphertext.data,
6504                         tdata->validDataLenInBits.len,
6505                         "ZUC Ciphertext data not as expected");
6506
6507                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6508                         digest,
6509                         tdata->digest.data,
6510                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6511                         "ZUC Generated auth tag not as expected");
6512         }
6513         return 0;
6514 }
6515
6516 static int
6517 test_kasumi_encryption_test_case_1(void)
6518 {
6519         return test_kasumi_encryption(&kasumi_test_case_1);
6520 }
6521
6522 static int
6523 test_kasumi_encryption_test_case_1_sgl(void)
6524 {
6525         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6526 }
6527
6528 static int
6529 test_kasumi_encryption_test_case_1_oop(void)
6530 {
6531         return test_kasumi_encryption_oop(&kasumi_test_case_1);
6532 }
6533
6534 static int
6535 test_kasumi_encryption_test_case_1_oop_sgl(void)
6536 {
6537         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6538 }
6539
6540 static int
6541 test_kasumi_encryption_test_case_2(void)
6542 {
6543         return test_kasumi_encryption(&kasumi_test_case_2);
6544 }
6545
6546 static int
6547 test_kasumi_encryption_test_case_3(void)
6548 {
6549         return test_kasumi_encryption(&kasumi_test_case_3);
6550 }
6551
6552 static int
6553 test_kasumi_encryption_test_case_4(void)
6554 {
6555         return test_kasumi_encryption(&kasumi_test_case_4);
6556 }
6557
6558 static int
6559 test_kasumi_encryption_test_case_5(void)
6560 {
6561         return test_kasumi_encryption(&kasumi_test_case_5);
6562 }
6563
6564 static int
6565 test_kasumi_decryption_test_case_1(void)
6566 {
6567         return test_kasumi_decryption(&kasumi_test_case_1);
6568 }
6569
6570 static int
6571 test_kasumi_decryption_test_case_1_oop(void)
6572 {
6573         return test_kasumi_decryption_oop(&kasumi_test_case_1);
6574 }
6575
6576 static int
6577 test_kasumi_decryption_test_case_2(void)
6578 {
6579         return test_kasumi_decryption(&kasumi_test_case_2);
6580 }
6581
6582 static int
6583 test_kasumi_decryption_test_case_3(void)
6584 {
6585         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6586         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6587                 return TEST_SKIPPED;
6588         return test_kasumi_decryption(&kasumi_test_case_3);
6589 }
6590
6591 static int
6592 test_kasumi_decryption_test_case_4(void)
6593 {
6594         return test_kasumi_decryption(&kasumi_test_case_4);
6595 }
6596
6597 static int
6598 test_kasumi_decryption_test_case_5(void)
6599 {
6600         return test_kasumi_decryption(&kasumi_test_case_5);
6601 }
6602 static int
6603 test_snow3g_encryption_test_case_1(void)
6604 {
6605         return test_snow3g_encryption(&snow3g_test_case_1);
6606 }
6607
6608 static int
6609 test_snow3g_encryption_test_case_1_oop(void)
6610 {
6611         return test_snow3g_encryption_oop(&snow3g_test_case_1);
6612 }
6613
6614 static int
6615 test_snow3g_encryption_test_case_1_oop_sgl(void)
6616 {
6617         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6618 }
6619
6620
6621 static int
6622 test_snow3g_encryption_test_case_1_offset_oop(void)
6623 {
6624         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6625 }
6626
6627 static int
6628 test_snow3g_encryption_test_case_2(void)
6629 {
6630         return test_snow3g_encryption(&snow3g_test_case_2);
6631 }
6632
6633 static int
6634 test_snow3g_encryption_test_case_3(void)
6635 {
6636         return test_snow3g_encryption(&snow3g_test_case_3);
6637 }
6638
6639 static int
6640 test_snow3g_encryption_test_case_4(void)
6641 {
6642         return test_snow3g_encryption(&snow3g_test_case_4);
6643 }
6644
6645 static int
6646 test_snow3g_encryption_test_case_5(void)
6647 {
6648         return test_snow3g_encryption(&snow3g_test_case_5);
6649 }
6650
6651 static int
6652 test_snow3g_decryption_test_case_1(void)
6653 {
6654         return test_snow3g_decryption(&snow3g_test_case_1);
6655 }
6656
6657 static int
6658 test_snow3g_decryption_test_case_1_oop(void)
6659 {
6660         return test_snow3g_decryption_oop(&snow3g_test_case_1);
6661 }
6662
6663 static int
6664 test_snow3g_decryption_test_case_2(void)
6665 {
6666         return test_snow3g_decryption(&snow3g_test_case_2);
6667 }
6668
6669 static int
6670 test_snow3g_decryption_test_case_3(void)
6671 {
6672         return test_snow3g_decryption(&snow3g_test_case_3);
6673 }
6674
6675 static int
6676 test_snow3g_decryption_test_case_4(void)
6677 {
6678         return test_snow3g_decryption(&snow3g_test_case_4);
6679 }
6680
6681 static int
6682 test_snow3g_decryption_test_case_5(void)
6683 {
6684         return test_snow3g_decryption(&snow3g_test_case_5);
6685 }
6686
6687 /*
6688  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6689  * Pattern digest from snow3g_test_data must be allocated as
6690  * 4 last bytes in plaintext.
6691  */
6692 static void
6693 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6694                 struct snow3g_hash_test_data *output)
6695 {
6696         if ((pattern != NULL) && (output != NULL)) {
6697                 output->key.len = pattern->key.len;
6698
6699                 memcpy(output->key.data,
6700                 pattern->key.data, pattern->key.len);
6701
6702                 output->auth_iv.len = pattern->auth_iv.len;
6703
6704                 memcpy(output->auth_iv.data,
6705                 pattern->auth_iv.data, pattern->auth_iv.len);
6706
6707                 output->plaintext.len = pattern->plaintext.len;
6708
6709                 memcpy(output->plaintext.data,
6710                 pattern->plaintext.data, pattern->plaintext.len >> 3);
6711
6712                 output->digest.len = pattern->digest.len;
6713
6714                 memcpy(output->digest.data,
6715                 &pattern->plaintext.data[pattern->digest.offset_bytes],
6716                 pattern->digest.len);
6717
6718                 output->validAuthLenInBits.len =
6719                 pattern->validAuthLenInBits.len;
6720         }
6721 }
6722
6723 /*
6724  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6725  */
6726 static int
6727 test_snow3g_decryption_with_digest_test_case_1(void)
6728 {
6729         struct snow3g_hash_test_data snow3g_hash_data;
6730         struct rte_cryptodev_info dev_info;
6731         struct crypto_testsuite_params *ts_params = &testsuite_params;
6732
6733         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6734         uint64_t feat_flags = dev_info.feature_flags;
6735
6736         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6737                 printf("Device doesn't support encrypted digest operations.\n");
6738                 return TEST_SKIPPED;
6739         }
6740
6741         /*
6742          * Function prepare data for hash veryfication test case.
6743          * Digest is allocated in 4 last bytes in plaintext, pattern.
6744          */
6745         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6746
6747         return test_snow3g_decryption(&snow3g_test_case_7) &
6748                         test_snow3g_authentication_verify(&snow3g_hash_data);
6749 }
6750
6751 static int
6752 test_snow3g_cipher_auth_test_case_1(void)
6753 {
6754         return test_snow3g_cipher_auth(&snow3g_test_case_3);
6755 }
6756
6757 static int
6758 test_snow3g_auth_cipher_test_case_1(void)
6759 {
6760         return test_snow3g_auth_cipher(
6761                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6762 }
6763
6764 static int
6765 test_snow3g_auth_cipher_test_case_2(void)
6766 {
6767         return test_snow3g_auth_cipher(
6768                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6769 }
6770
6771 static int
6772 test_snow3g_auth_cipher_test_case_2_oop(void)
6773 {
6774         return test_snow3g_auth_cipher(
6775                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6776 }
6777
6778 static int
6779 test_snow3g_auth_cipher_part_digest_enc(void)
6780 {
6781         return test_snow3g_auth_cipher(
6782                 &snow3g_auth_cipher_partial_digest_encryption,
6783                         IN_PLACE, 0);
6784 }
6785
6786 static int
6787 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6788 {
6789         return test_snow3g_auth_cipher(
6790                 &snow3g_auth_cipher_partial_digest_encryption,
6791                         OUT_OF_PLACE, 0);
6792 }
6793
6794 static int
6795 test_snow3g_auth_cipher_test_case_3_sgl(void)
6796 {
6797         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6798         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6799                 return TEST_SKIPPED;
6800         return test_snow3g_auth_cipher_sgl(
6801                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6802 }
6803
6804 static int
6805 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6806 {
6807         return test_snow3g_auth_cipher_sgl(
6808                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6809 }
6810
6811 static int
6812 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6813 {
6814         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6815         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6816                 return TEST_SKIPPED;
6817         return test_snow3g_auth_cipher_sgl(
6818                 &snow3g_auth_cipher_partial_digest_encryption,
6819                         IN_PLACE, 0);
6820 }
6821
6822 static int
6823 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6824 {
6825         return test_snow3g_auth_cipher_sgl(
6826                 &snow3g_auth_cipher_partial_digest_encryption,
6827                         OUT_OF_PLACE, 0);
6828 }
6829
6830 static int
6831 test_snow3g_auth_cipher_verify_test_case_1(void)
6832 {
6833         return test_snow3g_auth_cipher(
6834                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6835 }
6836
6837 static int
6838 test_snow3g_auth_cipher_verify_test_case_2(void)
6839 {
6840         return test_snow3g_auth_cipher(
6841                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6842 }
6843
6844 static int
6845 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6846 {
6847         return test_snow3g_auth_cipher(
6848                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6849 }
6850
6851 static int
6852 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6853 {
6854         return test_snow3g_auth_cipher(
6855                 &snow3g_auth_cipher_partial_digest_encryption,
6856                         IN_PLACE, 1);
6857 }
6858
6859 static int
6860 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6861 {
6862         return test_snow3g_auth_cipher(
6863                 &snow3g_auth_cipher_partial_digest_encryption,
6864                         OUT_OF_PLACE, 1);
6865 }
6866
6867 static int
6868 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6869 {
6870         return test_snow3g_auth_cipher_sgl(
6871                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6872 }
6873
6874 static int
6875 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6876 {
6877         return test_snow3g_auth_cipher_sgl(
6878                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6879 }
6880
6881 static int
6882 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6883 {
6884         return test_snow3g_auth_cipher_sgl(
6885                 &snow3g_auth_cipher_partial_digest_encryption,
6886                         IN_PLACE, 1);
6887 }
6888
6889 static int
6890 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6891 {
6892         return test_snow3g_auth_cipher_sgl(
6893                 &snow3g_auth_cipher_partial_digest_encryption,
6894                         OUT_OF_PLACE, 1);
6895 }
6896
6897 static int
6898 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6899 {
6900         return test_snow3g_auth_cipher(
6901                 &snow3g_test_case_7, IN_PLACE, 0);
6902 }
6903
6904 static int
6905 test_kasumi_auth_cipher_test_case_1(void)
6906 {
6907         return test_kasumi_auth_cipher(
6908                 &kasumi_test_case_3, IN_PLACE, 0);
6909 }
6910
6911 static int
6912 test_kasumi_auth_cipher_test_case_2(void)
6913 {
6914         return test_kasumi_auth_cipher(
6915                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6916 }
6917
6918 static int
6919 test_kasumi_auth_cipher_test_case_2_oop(void)
6920 {
6921         return test_kasumi_auth_cipher(
6922                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6923 }
6924
6925 static int
6926 test_kasumi_auth_cipher_test_case_2_sgl(void)
6927 {
6928         return test_kasumi_auth_cipher_sgl(
6929                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6930 }
6931
6932 static int
6933 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6934 {
6935         return test_kasumi_auth_cipher_sgl(
6936                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6937 }
6938
6939 static int
6940 test_kasumi_auth_cipher_verify_test_case_1(void)
6941 {
6942         return test_kasumi_auth_cipher(
6943                 &kasumi_test_case_3, IN_PLACE, 1);
6944 }
6945
6946 static int
6947 test_kasumi_auth_cipher_verify_test_case_2(void)
6948 {
6949         return test_kasumi_auth_cipher(
6950                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6951 }
6952
6953 static int
6954 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6955 {
6956         return test_kasumi_auth_cipher(
6957                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6958 }
6959
6960 static int
6961 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6962 {
6963         return test_kasumi_auth_cipher_sgl(
6964                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6965 }
6966
6967 static int
6968 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6969 {
6970         return test_kasumi_auth_cipher_sgl(
6971                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6972 }
6973
6974 static int
6975 test_kasumi_cipher_auth_test_case_1(void)
6976 {
6977         return test_kasumi_cipher_auth(&kasumi_test_case_6);
6978 }
6979
6980 static int
6981 test_zuc_encryption_test_case_1(void)
6982 {
6983         return test_zuc_encryption(&zuc_test_case_cipher_193b);
6984 }
6985
6986 static int
6987 test_zuc_encryption_test_case_2(void)
6988 {
6989         return test_zuc_encryption(&zuc_test_case_cipher_800b);
6990 }
6991
6992 static int
6993 test_zuc_encryption_test_case_3(void)
6994 {
6995         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
6996 }
6997
6998 static int
6999 test_zuc_encryption_test_case_4(void)
7000 {
7001         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
7002 }
7003
7004 static int
7005 test_zuc_encryption_test_case_5(void)
7006 {
7007         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7008 }
7009
7010 static int
7011 test_zuc_encryption_test_case_6_sgl(void)
7012 {
7013         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7014 }
7015
7016 static int
7017 test_zuc_encryption_test_case_7(void)
7018 {
7019         return test_zuc_encryption(&zuc_test_case_cipher_800b_key_256b);
7020 }
7021
7022 static int
7023 test_zuc_hash_generate_test_case_1(void)
7024 {
7025         return test_zuc_authentication(&zuc_test_case_auth_1b);
7026 }
7027
7028 static int
7029 test_zuc_hash_generate_test_case_2(void)
7030 {
7031         return test_zuc_authentication(&zuc_test_case_auth_90b);
7032 }
7033
7034 static int
7035 test_zuc_hash_generate_test_case_3(void)
7036 {
7037         return test_zuc_authentication(&zuc_test_case_auth_577b);
7038 }
7039
7040 static int
7041 test_zuc_hash_generate_test_case_4(void)
7042 {
7043         return test_zuc_authentication(&zuc_test_case_auth_2079b);
7044 }
7045
7046 static int
7047 test_zuc_hash_generate_test_case_5(void)
7048 {
7049         return test_zuc_authentication(&zuc_test_auth_5670b);
7050 }
7051
7052 static int
7053 test_zuc_hash_generate_test_case_6(void)
7054 {
7055         return test_zuc_authentication(&zuc_test_case_auth_128b);
7056 }
7057
7058 static int
7059 test_zuc_hash_generate_test_case_7(void)
7060 {
7061         return test_zuc_authentication(&zuc_test_case_auth_2080b);
7062 }
7063
7064 static int
7065 test_zuc_hash_generate_test_case_8(void)
7066 {
7067         return test_zuc_authentication(&zuc_test_case_auth_584b);
7068 }
7069
7070 static int
7071 test_zuc_hash_generate_test_case_9(void)
7072 {
7073         return test_zuc_authentication(&zuc_test_case_auth_584b_mac_64b);
7074 }
7075
7076 static int
7077 test_zuc_hash_generate_test_case_10(void)
7078 {
7079         return test_zuc_authentication(&zuc_test_case_auth_2080b_mac_128b);
7080 }
7081
7082 static int
7083 test_zuc_cipher_auth_test_case_1(void)
7084 {
7085         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7086 }
7087
7088 static int
7089 test_zuc_cipher_auth_test_case_2(void)
7090 {
7091         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7092 }
7093
7094 static int
7095 test_zuc_auth_cipher_test_case_1(void)
7096 {
7097         return test_zuc_auth_cipher(
7098                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7099 }
7100
7101 static int
7102 test_zuc_auth_cipher_test_case_1_oop(void)
7103 {
7104         return test_zuc_auth_cipher(
7105                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7106 }
7107
7108 static int
7109 test_zuc_auth_cipher_test_case_1_sgl(void)
7110 {
7111         return test_zuc_auth_cipher_sgl(
7112                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7113 }
7114
7115 static int
7116 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7117 {
7118         return test_zuc_auth_cipher_sgl(
7119                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7120 }
7121
7122 static int
7123 test_zuc_auth_cipher_verify_test_case_1(void)
7124 {
7125         return test_zuc_auth_cipher(
7126                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7127 }
7128
7129 static int
7130 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7131 {
7132         return test_zuc_auth_cipher(
7133                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7134 }
7135
7136 static int
7137 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7138 {
7139         return test_zuc_auth_cipher_sgl(
7140                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7141 }
7142
7143 static int
7144 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7145 {
7146         return test_zuc_auth_cipher_sgl(
7147                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7148 }
7149
7150 static int
7151 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7152 {
7153         uint8_t dev_id = testsuite_params.valid_devs[0];
7154
7155         struct rte_cryptodev_sym_capability_idx cap_idx;
7156
7157         /* Check if device supports particular cipher algorithm */
7158         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7159         cap_idx.algo.cipher = tdata->cipher_algo;
7160         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7161                 return TEST_SKIPPED;
7162
7163         /* Check if device supports particular hash algorithm */
7164         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7165         cap_idx.algo.auth = tdata->auth_algo;
7166         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7167                 return TEST_SKIPPED;
7168
7169         return 0;
7170 }
7171
7172 static int
7173 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7174         uint8_t op_mode, uint8_t verify)
7175 {
7176         struct crypto_testsuite_params *ts_params = &testsuite_params;
7177         struct crypto_unittest_params *ut_params = &unittest_params;
7178
7179         int retval;
7180
7181         uint8_t *plaintext = NULL, *ciphertext = NULL;
7182         unsigned int plaintext_pad_len;
7183         unsigned int plaintext_len;
7184         unsigned int ciphertext_pad_len;
7185         unsigned int ciphertext_len;
7186
7187         struct rte_cryptodev_info dev_info;
7188         struct rte_crypto_op *op;
7189
7190         /* Check if device supports particular algorithms separately */
7191         if (test_mixed_check_if_unsupported(tdata))
7192                 return TEST_SKIPPED;
7193         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7194                 return TEST_SKIPPED;
7195
7196         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7197
7198         uint64_t feat_flags = dev_info.feature_flags;
7199
7200         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7201                 printf("Device doesn't support digest encrypted.\n");
7202                 return TEST_SKIPPED;
7203         }
7204
7205         /* Create the session */
7206         if (verify)
7207                 retval = create_wireless_algo_cipher_auth_session(
7208                                 ts_params->valid_devs[0],
7209                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7210                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7211                                 tdata->auth_algo,
7212                                 tdata->cipher_algo,
7213                                 tdata->auth_key.data, tdata->auth_key.len,
7214                                 tdata->auth_iv.len, tdata->digest_enc.len,
7215                                 tdata->cipher_iv.len);
7216         else
7217                 retval = create_wireless_algo_auth_cipher_session(
7218                                 ts_params->valid_devs[0],
7219                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7220                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7221                                 tdata->auth_algo,
7222                                 tdata->cipher_algo,
7223                                 tdata->auth_key.data, tdata->auth_key.len,
7224                                 tdata->auth_iv.len, tdata->digest_enc.len,
7225                                 tdata->cipher_iv.len);
7226         if (retval != 0)
7227                 return retval;
7228
7229         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7230         if (op_mode == OUT_OF_PLACE)
7231                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7232
7233         /* clear mbuf payload */
7234         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7235                 rte_pktmbuf_tailroom(ut_params->ibuf));
7236         if (op_mode == OUT_OF_PLACE) {
7237
7238                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7239                                 rte_pktmbuf_tailroom(ut_params->obuf));
7240         }
7241
7242         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7243         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7244         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7245         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7246
7247         if (verify) {
7248                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7249                                 ciphertext_pad_len);
7250                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7251                 if (op_mode == OUT_OF_PLACE)
7252                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7253                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7254                                 ciphertext_len);
7255         } else {
7256                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7257                                 plaintext_pad_len);
7258                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7259                 if (op_mode == OUT_OF_PLACE)
7260                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7261                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7262         }
7263
7264         /* Create the operation */
7265         retval = create_wireless_algo_auth_cipher_operation(
7266                         tdata->digest_enc.data, tdata->digest_enc.len,
7267                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7268                         tdata->auth_iv.data, tdata->auth_iv.len,
7269                         (tdata->digest_enc.offset == 0 ?
7270                                 plaintext_pad_len
7271                                 : tdata->digest_enc.offset),
7272                         tdata->validCipherLen.len_bits,
7273                         tdata->cipher.offset_bits,
7274                         tdata->validAuthLen.len_bits,
7275                         tdata->auth.offset_bits,
7276                         op_mode, 0, verify);
7277
7278         if (retval < 0)
7279                 return retval;
7280
7281         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7282
7283         /* Check if the op failed because the device doesn't */
7284         /* support this particular combination of algorithms */
7285         if (op == NULL && ut_params->op->status ==
7286                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7287                 printf("Device doesn't support this mixed combination. "
7288                                 "Test Skipped.\n");
7289                 return TEST_SKIPPED;
7290         }
7291         ut_params->op = op;
7292
7293         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7294
7295         ut_params->obuf = (op_mode == IN_PLACE ?
7296                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7297
7298         if (verify) {
7299                 if (ut_params->obuf)
7300                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7301                                                         uint8_t *);
7302                 else
7303                         plaintext = ciphertext +
7304                                         (tdata->cipher.offset_bits >> 3);
7305
7306                 debug_hexdump(stdout, "plaintext:", plaintext,
7307                                 tdata->plaintext.len_bits >> 3);
7308                 debug_hexdump(stdout, "plaintext expected:",
7309                                 tdata->plaintext.data,
7310                                 tdata->plaintext.len_bits >> 3);
7311         } else {
7312                 if (ut_params->obuf)
7313                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7314                                         uint8_t *);
7315                 else
7316                         ciphertext = plaintext;
7317
7318                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7319                                 ciphertext_len);
7320                 debug_hexdump(stdout, "ciphertext expected:",
7321                                 tdata->ciphertext.data,
7322                                 tdata->ciphertext.len_bits >> 3);
7323
7324                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7325                                 + (tdata->digest_enc.offset == 0 ?
7326                 plaintext_pad_len : tdata->digest_enc.offset);
7327
7328                 debug_hexdump(stdout, "digest:", ut_params->digest,
7329                                 tdata->digest_enc.len);
7330                 debug_hexdump(stdout, "digest expected:",
7331                                 tdata->digest_enc.data,
7332                                 tdata->digest_enc.len);
7333         }
7334
7335         /* Validate obuf */
7336         if (verify) {
7337                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7338                                 plaintext,
7339                                 tdata->plaintext.data,
7340                                 tdata->plaintext.len_bits >> 3,
7341                                 "Plaintext data not as expected");
7342         } else {
7343                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7344                                 ciphertext,
7345                                 tdata->ciphertext.data,
7346                                 tdata->validDataLen.len_bits,
7347                                 "Ciphertext data not as expected");
7348
7349                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7350                                 ut_params->digest,
7351                                 tdata->digest_enc.data,
7352                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7353                                 "Generated auth tag not as expected");
7354         }
7355
7356         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7357                         "crypto op processing failed");
7358
7359         return 0;
7360 }
7361
7362 static int
7363 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7364         uint8_t op_mode, uint8_t verify)
7365 {
7366         struct crypto_testsuite_params *ts_params = &testsuite_params;
7367         struct crypto_unittest_params *ut_params = &unittest_params;
7368
7369         int retval;
7370
7371         const uint8_t *plaintext = NULL;
7372         const uint8_t *ciphertext = NULL;
7373         const uint8_t *digest = NULL;
7374         unsigned int plaintext_pad_len;
7375         unsigned int plaintext_len;
7376         unsigned int ciphertext_pad_len;
7377         unsigned int ciphertext_len;
7378         uint8_t buffer[10000];
7379         uint8_t digest_buffer[10000];
7380
7381         struct rte_cryptodev_info dev_info;
7382         struct rte_crypto_op *op;
7383
7384         /* Check if device supports particular algorithms */
7385         if (test_mixed_check_if_unsupported(tdata))
7386                 return TEST_SKIPPED;
7387         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7388                 return TEST_SKIPPED;
7389
7390         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7391
7392         uint64_t feat_flags = dev_info.feature_flags;
7393
7394         if (op_mode == IN_PLACE) {
7395                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7396                         printf("Device doesn't support in-place scatter-gather "
7397                                         "in both input and output mbufs.\n");
7398                         return TEST_SKIPPED;
7399                 }
7400         } else {
7401                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7402                         printf("Device doesn't support out-of-place scatter-gather "
7403                                         "in both input and output mbufs.\n");
7404                         return TEST_SKIPPED;
7405                 }
7406                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7407                         printf("Device doesn't support digest encrypted.\n");
7408                         return TEST_SKIPPED;
7409                 }
7410         }
7411
7412         /* Create the session */
7413         if (verify)
7414                 retval = create_wireless_algo_cipher_auth_session(
7415                                 ts_params->valid_devs[0],
7416                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7417                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7418                                 tdata->auth_algo,
7419                                 tdata->cipher_algo,
7420                                 tdata->auth_key.data, tdata->auth_key.len,
7421                                 tdata->auth_iv.len, tdata->digest_enc.len,
7422                                 tdata->cipher_iv.len);
7423         else
7424                 retval = create_wireless_algo_auth_cipher_session(
7425                                 ts_params->valid_devs[0],
7426                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7427                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7428                                 tdata->auth_algo,
7429                                 tdata->cipher_algo,
7430                                 tdata->auth_key.data, tdata->auth_key.len,
7431                                 tdata->auth_iv.len, tdata->digest_enc.len,
7432                                 tdata->cipher_iv.len);
7433         if (retval != 0)
7434                 return retval;
7435
7436         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7437         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7438         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7439         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7440
7441         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7442                         ciphertext_pad_len, 15, 0);
7443         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7444                         "Failed to allocate input buffer in mempool");
7445
7446         if (op_mode == OUT_OF_PLACE) {
7447                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7448                                 plaintext_pad_len, 15, 0);
7449                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
7450                                 "Failed to allocate output buffer in mempool");
7451         }
7452
7453         if (verify) {
7454                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7455                         tdata->ciphertext.data);
7456                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7457                                         ciphertext_len, buffer);
7458                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7459                         ciphertext_len);
7460         } else {
7461                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7462                         tdata->plaintext.data);
7463                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7464                                         plaintext_len, buffer);
7465                 debug_hexdump(stdout, "plaintext:", plaintext,
7466                         plaintext_len);
7467         }
7468         memset(buffer, 0, sizeof(buffer));
7469
7470         /* Create the operation */
7471         retval = create_wireless_algo_auth_cipher_operation(
7472                         tdata->digest_enc.data, tdata->digest_enc.len,
7473                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7474                         tdata->auth_iv.data, tdata->auth_iv.len,
7475                         (tdata->digest_enc.offset == 0 ?
7476                                 plaintext_pad_len
7477                                 : tdata->digest_enc.offset),
7478                         tdata->validCipherLen.len_bits,
7479                         tdata->cipher.offset_bits,
7480                         tdata->validAuthLen.len_bits,
7481                         tdata->auth.offset_bits,
7482                         op_mode, 1, verify);
7483
7484         if (retval < 0)
7485                 return retval;
7486
7487         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7488
7489         /* Check if the op failed because the device doesn't */
7490         /* support this particular combination of algorithms */
7491         if (op == NULL && ut_params->op->status ==
7492                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7493                 printf("Device doesn't support this mixed combination. "
7494                                 "Test Skipped.\n");
7495                 return TEST_SKIPPED;
7496         }
7497         ut_params->op = op;
7498
7499         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7500
7501         ut_params->obuf = (op_mode == IN_PLACE ?
7502                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7503
7504         if (verify) {
7505                 if (ut_params->obuf)
7506                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7507                                         plaintext_len, buffer);
7508                 else
7509                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7510                                         plaintext_len, buffer);
7511
7512                 debug_hexdump(stdout, "plaintext:", plaintext,
7513                                 (tdata->plaintext.len_bits >> 3) -
7514                                 tdata->digest_enc.len);
7515                 debug_hexdump(stdout, "plaintext expected:",
7516                                 tdata->plaintext.data,
7517                                 (tdata->plaintext.len_bits >> 3) -
7518                                 tdata->digest_enc.len);
7519         } else {
7520                 if (ut_params->obuf)
7521                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7522                                         ciphertext_len, buffer);
7523                 else
7524                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7525                                         ciphertext_len, buffer);
7526
7527                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7528                         ciphertext_len);
7529                 debug_hexdump(stdout, "ciphertext expected:",
7530                         tdata->ciphertext.data,
7531                         tdata->ciphertext.len_bits >> 3);
7532
7533                 if (ut_params->obuf)
7534                         digest = rte_pktmbuf_read(ut_params->obuf,
7535                                         (tdata->digest_enc.offset == 0 ?
7536                                                 plaintext_pad_len :
7537                                                 tdata->digest_enc.offset),
7538                                         tdata->digest_enc.len, digest_buffer);
7539                 else
7540                         digest = rte_pktmbuf_read(ut_params->ibuf,
7541                                         (tdata->digest_enc.offset == 0 ?
7542                                                 plaintext_pad_len :
7543                                                 tdata->digest_enc.offset),
7544                                         tdata->digest_enc.len, digest_buffer);
7545
7546                 debug_hexdump(stdout, "digest:", digest,
7547                                 tdata->digest_enc.len);
7548                 debug_hexdump(stdout, "digest expected:",
7549                                 tdata->digest_enc.data, tdata->digest_enc.len);
7550         }
7551
7552         /* Validate obuf */
7553         if (verify) {
7554                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7555                                 plaintext,
7556                                 tdata->plaintext.data,
7557                                 tdata->plaintext.len_bits >> 3,
7558                                 "Plaintext data not as expected");
7559         } else {
7560                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7561                                 ciphertext,
7562                                 tdata->ciphertext.data,
7563                                 tdata->validDataLen.len_bits,
7564                                 "Ciphertext data not as expected");
7565                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7566                                 digest,
7567                                 tdata->digest_enc.data,
7568                                 tdata->digest_enc.len,
7569                                 "Generated auth tag not as expected");
7570         }
7571
7572         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7573                         "crypto op processing failed");
7574
7575         return 0;
7576 }
7577
7578 /** AUTH AES CMAC + CIPHER AES CTR */
7579
7580 static int
7581 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7582 {
7583         return test_mixed_auth_cipher(
7584                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7585 }
7586
7587 static int
7588 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7589 {
7590         return test_mixed_auth_cipher(
7591                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7592 }
7593
7594 static int
7595 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7596 {
7597         return test_mixed_auth_cipher_sgl(
7598                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7599 }
7600
7601 static int
7602 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7603 {
7604         return test_mixed_auth_cipher_sgl(
7605                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7606 }
7607
7608 static int
7609 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7610 {
7611         return test_mixed_auth_cipher(
7612                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7613 }
7614
7615 static int
7616 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7617 {
7618         return test_mixed_auth_cipher(
7619                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7620 }
7621
7622 static int
7623 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7624 {
7625         return test_mixed_auth_cipher_sgl(
7626                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7627 }
7628
7629 static int
7630 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7631 {
7632         return test_mixed_auth_cipher_sgl(
7633                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7634 }
7635
7636 /** MIXED AUTH + CIPHER */
7637
7638 static int
7639 test_auth_zuc_cipher_snow_test_case_1(void)
7640 {
7641         return test_mixed_auth_cipher(
7642                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7643 }
7644
7645 static int
7646 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7647 {
7648         return test_mixed_auth_cipher(
7649                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7650 }
7651
7652 static int
7653 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7654 {
7655         return test_mixed_auth_cipher(
7656                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7657 }
7658
7659 static int
7660 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7661 {
7662         return test_mixed_auth_cipher(
7663                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7664 }
7665
7666 static int
7667 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7668 {
7669         return test_mixed_auth_cipher(
7670                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7671 }
7672
7673 static int
7674 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7675 {
7676         return test_mixed_auth_cipher(
7677                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7678 }
7679
7680 static int
7681 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7682 {
7683         return test_mixed_auth_cipher(
7684                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7685 }
7686
7687 static int
7688 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7689 {
7690         return test_mixed_auth_cipher(
7691                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7692 }
7693
7694 static int
7695 test_auth_snow_cipher_zuc_test_case_1(void)
7696 {
7697         return test_mixed_auth_cipher(
7698                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7699 }
7700
7701 static int
7702 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7703 {
7704         return test_mixed_auth_cipher(
7705                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7706 }
7707
7708 static int
7709 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7710 {
7711         return test_mixed_auth_cipher(
7712                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7713 }
7714
7715 static int
7716 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7717 {
7718         return test_mixed_auth_cipher(
7719                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7720 }
7721
7722 static int
7723 test_auth_null_cipher_snow_test_case_1(void)
7724 {
7725         return test_mixed_auth_cipher(
7726                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7727 }
7728
7729 static int
7730 test_verify_auth_null_cipher_snow_test_case_1(void)
7731 {
7732         return test_mixed_auth_cipher(
7733                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7734 }
7735
7736 static int
7737 test_auth_null_cipher_zuc_test_case_1(void)
7738 {
7739         return test_mixed_auth_cipher(
7740                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7741 }
7742
7743 static int
7744 test_verify_auth_null_cipher_zuc_test_case_1(void)
7745 {
7746         return test_mixed_auth_cipher(
7747                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7748 }
7749
7750 static int
7751 test_auth_snow_cipher_null_test_case_1(void)
7752 {
7753         return test_mixed_auth_cipher(
7754                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7755 }
7756
7757 static int
7758 test_verify_auth_snow_cipher_null_test_case_1(void)
7759 {
7760         return test_mixed_auth_cipher(
7761                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7762 }
7763
7764 static int
7765 test_auth_zuc_cipher_null_test_case_1(void)
7766 {
7767         return test_mixed_auth_cipher(
7768                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7769 }
7770
7771 static int
7772 test_verify_auth_zuc_cipher_null_test_case_1(void)
7773 {
7774         return test_mixed_auth_cipher(
7775                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7776 }
7777
7778 static int
7779 test_auth_null_cipher_aes_ctr_test_case_1(void)
7780 {
7781         return test_mixed_auth_cipher(
7782                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7783 }
7784
7785 static int
7786 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7787 {
7788         return test_mixed_auth_cipher(
7789                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7790 }
7791
7792 static int
7793 test_auth_aes_cmac_cipher_null_test_case_1(void)
7794 {
7795         return test_mixed_auth_cipher(
7796                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7797 }
7798
7799 static int
7800 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7801 {
7802         return test_mixed_auth_cipher(
7803                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7804 }
7805
7806 /* ***** AEAD algorithm Tests ***** */
7807
7808 static int
7809 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7810                 enum rte_crypto_aead_operation op,
7811                 const uint8_t *key, const uint8_t key_len,
7812                 const uint16_t aad_len, const uint8_t auth_len,
7813                 uint8_t iv_len)
7814 {
7815         uint8_t aead_key[key_len];
7816
7817         struct crypto_testsuite_params *ts_params = &testsuite_params;
7818         struct crypto_unittest_params *ut_params = &unittest_params;
7819
7820         memcpy(aead_key, key, key_len);
7821
7822         /* Setup AEAD Parameters */
7823         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7824         ut_params->aead_xform.next = NULL;
7825         ut_params->aead_xform.aead.algo = algo;
7826         ut_params->aead_xform.aead.op = op;
7827         ut_params->aead_xform.aead.key.data = aead_key;
7828         ut_params->aead_xform.aead.key.length = key_len;
7829         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7830         ut_params->aead_xform.aead.iv.length = iv_len;
7831         ut_params->aead_xform.aead.digest_length = auth_len;
7832         ut_params->aead_xform.aead.aad_length = aad_len;
7833
7834         debug_hexdump(stdout, "key:", key, key_len);
7835
7836         /* Create Crypto session*/
7837         ut_params->sess = rte_cryptodev_sym_session_create(
7838                         ts_params->session_mpool);
7839
7840         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7841                         &ut_params->aead_xform,
7842                         ts_params->session_priv_mpool);
7843
7844         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7845
7846         return 0;
7847 }
7848
7849 static int
7850 create_aead_xform(struct rte_crypto_op *op,
7851                 enum rte_crypto_aead_algorithm algo,
7852                 enum rte_crypto_aead_operation aead_op,
7853                 uint8_t *key, const uint8_t key_len,
7854                 const uint8_t aad_len, const uint8_t auth_len,
7855                 uint8_t iv_len)
7856 {
7857         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7858                         "failed to allocate space for crypto transform");
7859
7860         struct rte_crypto_sym_op *sym_op = op->sym;
7861
7862         /* Setup AEAD Parameters */
7863         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7864         sym_op->xform->next = NULL;
7865         sym_op->xform->aead.algo = algo;
7866         sym_op->xform->aead.op = aead_op;
7867         sym_op->xform->aead.key.data = key;
7868         sym_op->xform->aead.key.length = key_len;
7869         sym_op->xform->aead.iv.offset = IV_OFFSET;
7870         sym_op->xform->aead.iv.length = iv_len;
7871         sym_op->xform->aead.digest_length = auth_len;
7872         sym_op->xform->aead.aad_length = aad_len;
7873
7874         debug_hexdump(stdout, "key:", key, key_len);
7875
7876         return 0;
7877 }
7878
7879 static int
7880 create_aead_operation(enum rte_crypto_aead_operation op,
7881                 const struct aead_test_data *tdata)
7882 {
7883         struct crypto_testsuite_params *ts_params = &testsuite_params;
7884         struct crypto_unittest_params *ut_params = &unittest_params;
7885
7886         uint8_t *plaintext, *ciphertext;
7887         unsigned int aad_pad_len, plaintext_pad_len;
7888
7889         /* Generate Crypto op data structure */
7890         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7891                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7892         TEST_ASSERT_NOT_NULL(ut_params->op,
7893                         "Failed to allocate symmetric crypto operation struct");
7894
7895         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7896
7897         /* Append aad data */
7898         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7899                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7900                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7901                                 aad_pad_len);
7902                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7903                                 "no room to append aad");
7904
7905                 sym_op->aead.aad.phys_addr =
7906                                 rte_pktmbuf_iova(ut_params->ibuf);
7907                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
7908                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7909                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7910                         tdata->aad.len);
7911
7912                 /* Append IV at the end of the crypto operation*/
7913                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7914                                 uint8_t *, IV_OFFSET);
7915
7916                 /* Copy IV 1 byte after the IV pointer, according to the API */
7917                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7918                 debug_hexdump(stdout, "iv:", iv_ptr,
7919                         tdata->iv.len);
7920         } else {
7921                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7922                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7923                                 aad_pad_len);
7924                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7925                                 "no room to append aad");
7926
7927                 sym_op->aead.aad.phys_addr =
7928                                 rte_pktmbuf_iova(ut_params->ibuf);
7929                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7930                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7931                         tdata->aad.len);
7932
7933                 /* Append IV at the end of the crypto operation*/
7934                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7935                                 uint8_t *, IV_OFFSET);
7936
7937                 if (tdata->iv.len == 0) {
7938                         rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7939                         debug_hexdump(stdout, "iv:", iv_ptr,
7940                                 AES_GCM_J0_LENGTH);
7941                 } else {
7942                         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7943                         debug_hexdump(stdout, "iv:", iv_ptr,
7944                                 tdata->iv.len);
7945                 }
7946         }
7947
7948         /* Append plaintext/ciphertext */
7949         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7950                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7951                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7952                                 plaintext_pad_len);
7953                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7954
7955                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7956                 debug_hexdump(stdout, "plaintext:", plaintext,
7957                                 tdata->plaintext.len);
7958
7959                 if (ut_params->obuf) {
7960                         ciphertext = (uint8_t *)rte_pktmbuf_append(
7961                                         ut_params->obuf,
7962                                         plaintext_pad_len + aad_pad_len);
7963                         TEST_ASSERT_NOT_NULL(ciphertext,
7964                                         "no room to append ciphertext");
7965
7966                         memset(ciphertext + aad_pad_len, 0,
7967                                         tdata->ciphertext.len);
7968                 }
7969         } else {
7970                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7971                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7972                                 plaintext_pad_len);
7973                 TEST_ASSERT_NOT_NULL(ciphertext,
7974                                 "no room to append ciphertext");
7975
7976                 memcpy(ciphertext, tdata->ciphertext.data,
7977                                 tdata->ciphertext.len);
7978                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7979                                 tdata->ciphertext.len);
7980
7981                 if (ut_params->obuf) {
7982                         plaintext = (uint8_t *)rte_pktmbuf_append(
7983                                         ut_params->obuf,
7984                                         plaintext_pad_len + aad_pad_len);
7985                         TEST_ASSERT_NOT_NULL(plaintext,
7986                                         "no room to append plaintext");
7987
7988                         memset(plaintext + aad_pad_len, 0,
7989                                         tdata->plaintext.len);
7990                 }
7991         }
7992
7993         /* Append digest data */
7994         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7995                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7996                                 ut_params->obuf ? ut_params->obuf :
7997                                                 ut_params->ibuf,
7998                                                 tdata->auth_tag.len);
7999                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8000                                 "no room to append digest");
8001                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
8002                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8003                                 ut_params->obuf ? ut_params->obuf :
8004                                                 ut_params->ibuf,
8005                                                 plaintext_pad_len +
8006                                                 aad_pad_len);
8007         } else {
8008                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8009                                 ut_params->ibuf, tdata->auth_tag.len);
8010                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8011                                 "no room to append digest");
8012                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8013                                 ut_params->ibuf,
8014                                 plaintext_pad_len + aad_pad_len);
8015
8016                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8017                         tdata->auth_tag.len);
8018                 debug_hexdump(stdout, "digest:",
8019                         sym_op->aead.digest.data,
8020                         tdata->auth_tag.len);
8021         }
8022
8023         sym_op->aead.data.length = tdata->plaintext.len;
8024         sym_op->aead.data.offset = aad_pad_len;
8025
8026         return 0;
8027 }
8028
8029 static int
8030 test_authenticated_encryption(const struct aead_test_data *tdata)
8031 {
8032         struct crypto_testsuite_params *ts_params = &testsuite_params;
8033         struct crypto_unittest_params *ut_params = &unittest_params;
8034
8035         int retval;
8036         uint8_t *ciphertext, *auth_tag;
8037         uint16_t plaintext_pad_len;
8038         uint32_t i;
8039         struct rte_cryptodev_info dev_info;
8040
8041         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8042         uint64_t feat_flags = dev_info.feature_flags;
8043
8044         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8045                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8046                 printf("Device doesn't support RAW data-path APIs.\n");
8047                 return TEST_SKIPPED;
8048         }
8049
8050         /* Verify the capabilities */
8051         struct rte_cryptodev_sym_capability_idx cap_idx;
8052         const struct rte_cryptodev_symmetric_capability *capability;
8053         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8054         cap_idx.algo.aead = tdata->algo;
8055         capability = rte_cryptodev_sym_capability_get(
8056                         ts_params->valid_devs[0], &cap_idx);
8057         if (capability == NULL)
8058                 return TEST_SKIPPED;
8059         if (rte_cryptodev_sym_capability_check_aead(
8060                         capability, tdata->key.len, tdata->auth_tag.len,
8061                         tdata->aad.len, tdata->iv.len))
8062                 return TEST_SKIPPED;
8063
8064         /* Create AEAD session */
8065         retval = create_aead_session(ts_params->valid_devs[0],
8066                         tdata->algo,
8067                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8068                         tdata->key.data, tdata->key.len,
8069                         tdata->aad.len, tdata->auth_tag.len,
8070                         tdata->iv.len);
8071         if (retval < 0)
8072                 return retval;
8073
8074         if (tdata->aad.len > MBUF_SIZE) {
8075                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8076                 /* Populate full size of add data */
8077                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8078                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8079         } else
8080                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8081
8082         /* clear mbuf payload */
8083         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8084                         rte_pktmbuf_tailroom(ut_params->ibuf));
8085
8086         /* Create AEAD operation */
8087         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8088         if (retval < 0)
8089                 return retval;
8090
8091         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8092
8093         ut_params->op->sym->m_src = ut_params->ibuf;
8094
8095         /* Process crypto operation */
8096         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8097                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8098         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8099                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8100                                 ut_params->op, 0, 0, 0, 0);
8101         else
8102                 TEST_ASSERT_NOT_NULL(
8103                         process_crypto_request(ts_params->valid_devs[0],
8104                         ut_params->op), "failed to process sym crypto op");
8105
8106         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8107                         "crypto op processing failed");
8108
8109         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8110
8111         if (ut_params->op->sym->m_dst) {
8112                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8113                                 uint8_t *);
8114                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8115                                 uint8_t *, plaintext_pad_len);
8116         } else {
8117                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8118                                 uint8_t *,
8119                                 ut_params->op->sym->cipher.data.offset);
8120                 auth_tag = ciphertext + plaintext_pad_len;
8121         }
8122
8123         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8124         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8125
8126         /* Validate obuf */
8127         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8128                         ciphertext,
8129                         tdata->ciphertext.data,
8130                         tdata->ciphertext.len,
8131                         "Ciphertext data not as expected");
8132
8133         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8134                         auth_tag,
8135                         tdata->auth_tag.data,
8136                         tdata->auth_tag.len,
8137                         "Generated auth tag not as expected");
8138
8139         return 0;
8140
8141 }
8142
8143 #ifdef RTE_LIB_SECURITY
8144 static int
8145 security_proto_supported(enum rte_security_session_action_type action,
8146         enum rte_security_session_protocol proto)
8147 {
8148         struct crypto_testsuite_params *ts_params = &testsuite_params;
8149
8150         const struct rte_security_capability *capabilities;
8151         const struct rte_security_capability *capability;
8152         uint16_t i = 0;
8153
8154         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8155                                 rte_cryptodev_get_sec_ctx(
8156                                 ts_params->valid_devs[0]);
8157
8158
8159         capabilities = rte_security_capabilities_get(ctx);
8160
8161         if (capabilities == NULL)
8162                 return -ENOTSUP;
8163
8164         while ((capability = &capabilities[i++])->action !=
8165                         RTE_SECURITY_ACTION_TYPE_NONE) {
8166                 if (capability->action == action &&
8167                                 capability->protocol == proto)
8168                         return 0;
8169         }
8170
8171         return -ENOTSUP;
8172 }
8173
8174 /* Basic algorithm run function for async inplace mode.
8175  * Creates a session from input parameters and runs one operation
8176  * on input_vec. Checks the output of the crypto operation against
8177  * output_vec.
8178  */
8179 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8180                            enum rte_crypto_auth_operation opa,
8181                            const uint8_t *input_vec, unsigned int input_vec_len,
8182                            const uint8_t *output_vec,
8183                            unsigned int output_vec_len,
8184                            enum rte_crypto_cipher_algorithm cipher_alg,
8185                            const uint8_t *cipher_key, uint32_t cipher_key_len,
8186                            enum rte_crypto_auth_algorithm auth_alg,
8187                            const uint8_t *auth_key, uint32_t auth_key_len,
8188                            uint8_t bearer, enum rte_security_pdcp_domain domain,
8189                            uint8_t packet_direction, uint8_t sn_size,
8190                            uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8191 {
8192         struct crypto_testsuite_params *ts_params = &testsuite_params;
8193         struct crypto_unittest_params *ut_params = &unittest_params;
8194         uint8_t *plaintext;
8195         int ret = TEST_SUCCESS;
8196         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8197                                 rte_cryptodev_get_sec_ctx(
8198                                 ts_params->valid_devs[0]);
8199
8200         /* Verify the capabilities */
8201         struct rte_security_capability_idx sec_cap_idx;
8202
8203         sec_cap_idx.action = ut_params->type;
8204         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8205         sec_cap_idx.pdcp.domain = domain;
8206         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8207                 return TEST_SKIPPED;
8208
8209         /* Generate test mbuf data */
8210         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8211
8212         /* clear mbuf payload */
8213         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8214                         rte_pktmbuf_tailroom(ut_params->ibuf));
8215
8216         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8217                                                   input_vec_len);
8218         memcpy(plaintext, input_vec, input_vec_len);
8219
8220         /* Out of place support */
8221         if (oop) {
8222                 /*
8223                  * For out-op-place we need to alloc another mbuf
8224                  */
8225                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8226                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8227         }
8228
8229         /* Setup Cipher Parameters */
8230         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8231         ut_params->cipher_xform.cipher.algo = cipher_alg;
8232         ut_params->cipher_xform.cipher.op = opc;
8233         ut_params->cipher_xform.cipher.key.data = cipher_key;
8234         ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8235         ut_params->cipher_xform.cipher.iv.length =
8236                                 packet_direction ? 4 : 0;
8237         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8238
8239         /* Setup HMAC Parameters if ICV header is required */
8240         if (auth_alg != 0) {
8241                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8242                 ut_params->auth_xform.next = NULL;
8243                 ut_params->auth_xform.auth.algo = auth_alg;
8244                 ut_params->auth_xform.auth.op = opa;
8245                 ut_params->auth_xform.auth.key.data = auth_key;
8246                 ut_params->auth_xform.auth.key.length = auth_key_len;
8247
8248                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8249         } else {
8250                 ut_params->cipher_xform.next = NULL;
8251         }
8252
8253         struct rte_security_session_conf sess_conf = {
8254                 .action_type = ut_params->type,
8255                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8256                 {.pdcp = {
8257                         .bearer = bearer,
8258                         .domain = domain,
8259                         .pkt_dir = packet_direction,
8260                         .sn_size = sn_size,
8261                         .hfn = packet_direction ? 0 : hfn,
8262                         /**
8263                          * hfn can be set as pdcp_test_hfn[i]
8264                          * if hfn_ovrd is not set. Here, PDCP
8265                          * packet direction is just used to
8266                          * run half of the cases with session
8267                          * HFN and other half with per packet
8268                          * HFN.
8269                          */
8270                         .hfn_threshold = hfn_threshold,
8271                         .hfn_ovrd = packet_direction ? 1 : 0,
8272                         .sdap_enabled = sdap,
8273                 } },
8274                 .crypto_xform = &ut_params->cipher_xform
8275         };
8276
8277         /* Create security session */
8278         ut_params->sec_session = rte_security_session_create(ctx,
8279                                 &sess_conf, ts_params->session_mpool,
8280                                 ts_params->session_priv_mpool);
8281
8282         if (!ut_params->sec_session) {
8283                 printf("TestCase %s()-%d line %d failed %s: ",
8284                         __func__, i, __LINE__, "Failed to allocate session");
8285                 ret = TEST_FAILED;
8286                 goto on_err;
8287         }
8288
8289         /* Generate crypto op data structure */
8290         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8291                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8292         if (!ut_params->op) {
8293                 printf("TestCase %s()-%d line %d failed %s: ",
8294                         __func__, i, __LINE__,
8295                         "Failed to allocate symmetric crypto operation struct");
8296                 ret = TEST_FAILED;
8297                 goto on_err;
8298         }
8299
8300         uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8301                                         uint32_t *, IV_OFFSET);
8302         *per_pkt_hfn = packet_direction ? hfn : 0;
8303
8304         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8305
8306         /* set crypto operation source mbuf */
8307         ut_params->op->sym->m_src = ut_params->ibuf;
8308         if (oop)
8309                 ut_params->op->sym->m_dst = ut_params->obuf;
8310
8311         /* Process crypto operation */
8312         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8313                 == NULL) {
8314                 printf("TestCase %s()-%d line %d failed %s: ",
8315                         __func__, i, __LINE__,
8316                         "failed to process sym crypto op");
8317                 ret = TEST_FAILED;
8318                 goto on_err;
8319         }
8320
8321         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8322                 printf("TestCase %s()-%d line %d failed %s: ",
8323                         __func__, i, __LINE__, "crypto op processing failed");
8324                 ret = TEST_FAILED;
8325                 goto on_err;
8326         }
8327
8328         /* Validate obuf */
8329         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8330                         uint8_t *);
8331         if (oop) {
8332                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8333                                 uint8_t *);
8334         }
8335
8336         if (memcmp(ciphertext, output_vec, output_vec_len)) {
8337                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8338                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8339                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8340                 ret = TEST_FAILED;
8341                 goto on_err;
8342         }
8343
8344 on_err:
8345         rte_crypto_op_free(ut_params->op);
8346         ut_params->op = NULL;
8347
8348         if (ut_params->sec_session)
8349                 rte_security_session_destroy(ctx, ut_params->sec_session);
8350         ut_params->sec_session = NULL;
8351
8352         rte_pktmbuf_free(ut_params->ibuf);
8353         ut_params->ibuf = NULL;
8354         if (oop) {
8355                 rte_pktmbuf_free(ut_params->obuf);
8356                 ut_params->obuf = NULL;
8357         }
8358
8359         return ret;
8360 }
8361
8362 static int
8363 test_pdcp_proto_SGL(int i, int oop,
8364         enum rte_crypto_cipher_operation opc,
8365         enum rte_crypto_auth_operation opa,
8366         uint8_t *input_vec,
8367         unsigned int input_vec_len,
8368         uint8_t *output_vec,
8369         unsigned int output_vec_len,
8370         uint32_t fragsz,
8371         uint32_t fragsz_oop)
8372 {
8373         struct crypto_testsuite_params *ts_params = &testsuite_params;
8374         struct crypto_unittest_params *ut_params = &unittest_params;
8375         uint8_t *plaintext;
8376         struct rte_mbuf *buf, *buf_oop = NULL;
8377         int ret = TEST_SUCCESS;
8378         int to_trn = 0;
8379         int to_trn_tbl[16];
8380         int segs = 1;
8381         unsigned int trn_data = 0;
8382         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8383                                 rte_cryptodev_get_sec_ctx(
8384                                 ts_params->valid_devs[0]);
8385
8386         /* Verify the capabilities */
8387         struct rte_security_capability_idx sec_cap_idx;
8388
8389         sec_cap_idx.action = ut_params->type;
8390         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8391         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8392         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8393                 return TEST_SKIPPED;
8394
8395         if (fragsz > input_vec_len)
8396                 fragsz = input_vec_len;
8397
8398         uint16_t plaintext_len = fragsz;
8399         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8400
8401         if (fragsz_oop > output_vec_len)
8402                 frag_size_oop = output_vec_len;
8403
8404         int ecx = 0;
8405         if (input_vec_len % fragsz != 0) {
8406                 if (input_vec_len / fragsz + 1 > 16)
8407                         return 1;
8408         } else if (input_vec_len / fragsz > 16)
8409                 return 1;
8410
8411         /* Out of place support */
8412         if (oop) {
8413                 /*
8414                  * For out-op-place we need to alloc another mbuf
8415                  */
8416                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8417                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8418                 buf_oop = ut_params->obuf;
8419         }
8420
8421         /* Generate test mbuf data */
8422         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8423
8424         /* clear mbuf payload */
8425         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8426                         rte_pktmbuf_tailroom(ut_params->ibuf));
8427
8428         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8429                                                   plaintext_len);
8430         memcpy(plaintext, input_vec, plaintext_len);
8431         trn_data += plaintext_len;
8432
8433         buf = ut_params->ibuf;
8434
8435         /*
8436          * Loop until no more fragments
8437          */
8438
8439         while (trn_data < input_vec_len) {
8440                 ++segs;
8441                 to_trn = (input_vec_len - trn_data < fragsz) ?
8442                                 (input_vec_len - trn_data) : fragsz;
8443
8444                 to_trn_tbl[ecx++] = to_trn;
8445
8446                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8447                 buf = buf->next;
8448
8449                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8450                                 rte_pktmbuf_tailroom(buf));
8451
8452                 /* OOP */
8453                 if (oop && !fragsz_oop) {
8454                         buf_oop->next =
8455                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8456                         buf_oop = buf_oop->next;
8457                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8458                                         0, rte_pktmbuf_tailroom(buf_oop));
8459                         rte_pktmbuf_append(buf_oop, to_trn);
8460                 }
8461
8462                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8463                                 to_trn);
8464
8465                 memcpy(plaintext, input_vec + trn_data, to_trn);
8466                 trn_data += to_trn;
8467         }
8468
8469         ut_params->ibuf->nb_segs = segs;
8470
8471         segs = 1;
8472         if (fragsz_oop && oop) {
8473                 to_trn = 0;
8474                 ecx = 0;
8475
8476                 trn_data = frag_size_oop;
8477                 while (trn_data < output_vec_len) {
8478                         ++segs;
8479                         to_trn =
8480                                 (output_vec_len - trn_data <
8481                                                 frag_size_oop) ?
8482                                 (output_vec_len - trn_data) :
8483                                                 frag_size_oop;
8484
8485                         to_trn_tbl[ecx++] = to_trn;
8486
8487                         buf_oop->next =
8488                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
8489                         buf_oop = buf_oop->next;
8490                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8491                                         0, rte_pktmbuf_tailroom(buf_oop));
8492                         rte_pktmbuf_append(buf_oop, to_trn);
8493
8494                         trn_data += to_trn;
8495                 }
8496                 ut_params->obuf->nb_segs = segs;
8497         }
8498
8499         /* Setup Cipher Parameters */
8500         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8501         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8502         ut_params->cipher_xform.cipher.op = opc;
8503         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8504         ut_params->cipher_xform.cipher.key.length =
8505                                         pdcp_test_params[i].cipher_key_len;
8506         ut_params->cipher_xform.cipher.iv.length = 0;
8507
8508         /* Setup HMAC Parameters if ICV header is required */
8509         if (pdcp_test_params[i].auth_alg != 0) {
8510                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8511                 ut_params->auth_xform.next = NULL;
8512                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8513                 ut_params->auth_xform.auth.op = opa;
8514                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8515                 ut_params->auth_xform.auth.key.length =
8516                                         pdcp_test_params[i].auth_key_len;
8517
8518                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8519         } else {
8520                 ut_params->cipher_xform.next = NULL;
8521         }
8522
8523         struct rte_security_session_conf sess_conf = {
8524                 .action_type = ut_params->type,
8525                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8526                 {.pdcp = {
8527                         .bearer = pdcp_test_bearer[i],
8528                         .domain = pdcp_test_params[i].domain,
8529                         .pkt_dir = pdcp_test_packet_direction[i],
8530                         .sn_size = pdcp_test_data_sn_size[i],
8531                         .hfn = pdcp_test_hfn[i],
8532                         .hfn_threshold = pdcp_test_hfn_threshold[i],
8533                         .hfn_ovrd = 0,
8534                 } },
8535                 .crypto_xform = &ut_params->cipher_xform
8536         };
8537
8538         /* Create security session */
8539         ut_params->sec_session = rte_security_session_create(ctx,
8540                                 &sess_conf, ts_params->session_mpool,
8541                                 ts_params->session_priv_mpool);
8542
8543         if (!ut_params->sec_session) {
8544                 printf("TestCase %s()-%d line %d failed %s: ",
8545                         __func__, i, __LINE__, "Failed to allocate session");
8546                 ret = TEST_FAILED;
8547                 goto on_err;
8548         }
8549
8550         /* Generate crypto op data structure */
8551         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8552                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8553         if (!ut_params->op) {
8554                 printf("TestCase %s()-%d line %d failed %s: ",
8555                         __func__, i, __LINE__,
8556                         "Failed to allocate symmetric crypto operation struct");
8557                 ret = TEST_FAILED;
8558                 goto on_err;
8559         }
8560
8561         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8562
8563         /* set crypto operation source mbuf */
8564         ut_params->op->sym->m_src = ut_params->ibuf;
8565         if (oop)
8566                 ut_params->op->sym->m_dst = ut_params->obuf;
8567
8568         /* Process crypto operation */
8569         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8570                 == NULL) {
8571                 printf("TestCase %s()-%d line %d failed %s: ",
8572                         __func__, i, __LINE__,
8573                         "failed to process sym crypto op");
8574                 ret = TEST_FAILED;
8575                 goto on_err;
8576         }
8577
8578         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8579                 printf("TestCase %s()-%d line %d failed %s: ",
8580                         __func__, i, __LINE__, "crypto op processing failed");
8581                 ret = TEST_FAILED;
8582                 goto on_err;
8583         }
8584
8585         /* Validate obuf */
8586         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8587                         uint8_t *);
8588         if (oop) {
8589                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8590                                 uint8_t *);
8591         }
8592         if (fragsz_oop)
8593                 fragsz = frag_size_oop;
8594         if (memcmp(ciphertext, output_vec, fragsz)) {
8595                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8596                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8597                 rte_hexdump(stdout, "reference", output_vec, fragsz);
8598                 ret = TEST_FAILED;
8599                 goto on_err;
8600         }
8601
8602         buf = ut_params->op->sym->m_src->next;
8603         if (oop)
8604                 buf = ut_params->op->sym->m_dst->next;
8605
8606         unsigned int off = fragsz;
8607
8608         ecx = 0;
8609         while (buf) {
8610                 ciphertext = rte_pktmbuf_mtod(buf,
8611                                 uint8_t *);
8612                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8613                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8614                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8615                         rte_hexdump(stdout, "reference", output_vec + off,
8616                                         to_trn_tbl[ecx]);
8617                         ret = TEST_FAILED;
8618                         goto on_err;
8619                 }
8620                 off += to_trn_tbl[ecx++];
8621                 buf = buf->next;
8622         }
8623 on_err:
8624         rte_crypto_op_free(ut_params->op);
8625         ut_params->op = NULL;
8626
8627         if (ut_params->sec_session)
8628                 rte_security_session_destroy(ctx, ut_params->sec_session);
8629         ut_params->sec_session = NULL;
8630
8631         rte_pktmbuf_free(ut_params->ibuf);
8632         ut_params->ibuf = NULL;
8633         if (oop) {
8634                 rte_pktmbuf_free(ut_params->obuf);
8635                 ut_params->obuf = NULL;
8636         }
8637
8638         return ret;
8639 }
8640
8641 int
8642 test_pdcp_proto_cplane_encap(int i)
8643 {
8644         return test_pdcp_proto(
8645                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8646                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8647                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8648                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8649                 pdcp_test_params[i].cipher_key_len,
8650                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8651                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8652                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8653                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8654                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8655 }
8656
8657 int
8658 test_pdcp_proto_uplane_encap(int i)
8659 {
8660         return test_pdcp_proto(
8661                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8662                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8663                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8664                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8665                 pdcp_test_params[i].cipher_key_len,
8666                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8667                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8668                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8669                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8670                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8671 }
8672
8673 int
8674 test_pdcp_proto_uplane_encap_with_int(int i)
8675 {
8676         return test_pdcp_proto(
8677                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8678                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8679                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8680                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8681                 pdcp_test_params[i].cipher_key_len,
8682                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8683                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8684                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8685                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8686                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8687 }
8688
8689 int
8690 test_pdcp_proto_cplane_decap(int i)
8691 {
8692         return test_pdcp_proto(
8693                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8694                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8695                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8696                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8697                 pdcp_test_params[i].cipher_key_len,
8698                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8699                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8700                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8701                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8702                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8703 }
8704
8705 int
8706 test_pdcp_proto_uplane_decap(int i)
8707 {
8708         return test_pdcp_proto(
8709                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8710                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8711                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8712                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8713                 pdcp_test_params[i].cipher_key_len,
8714                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8715                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8716                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8717                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8718                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8719 }
8720
8721 int
8722 test_pdcp_proto_uplane_decap_with_int(int i)
8723 {
8724         return test_pdcp_proto(
8725                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8726                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8727                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8728                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8729                 pdcp_test_params[i].cipher_key_len,
8730                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8731                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8732                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8733                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8734                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8735 }
8736
8737 static int
8738 test_PDCP_PROTO_SGL_in_place_32B(void)
8739 {
8740         /* i can be used for running any PDCP case
8741          * In this case it is uplane 12-bit AES-SNOW DL encap
8742          */
8743         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8744         return test_pdcp_proto_SGL(i, IN_PLACE,
8745                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8746                         RTE_CRYPTO_AUTH_OP_GENERATE,
8747                         pdcp_test_data_in[i],
8748                         pdcp_test_data_in_len[i],
8749                         pdcp_test_data_out[i],
8750                         pdcp_test_data_in_len[i]+4,
8751                         32, 0);
8752 }
8753 static int
8754 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8755 {
8756         /* i can be used for running any PDCP case
8757          * In this case it is uplane 18-bit NULL-NULL DL encap
8758          */
8759         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8760         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8761                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8762                         RTE_CRYPTO_AUTH_OP_GENERATE,
8763                         pdcp_test_data_in[i],
8764                         pdcp_test_data_in_len[i],
8765                         pdcp_test_data_out[i],
8766                         pdcp_test_data_in_len[i]+4,
8767                         32, 128);
8768 }
8769 static int
8770 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8771 {
8772         /* i can be used for running any PDCP case
8773          * In this case it is uplane 18-bit AES DL encap
8774          */
8775         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8776                         + DOWNLINK;
8777         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8778                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8779                         RTE_CRYPTO_AUTH_OP_GENERATE,
8780                         pdcp_test_data_in[i],
8781                         pdcp_test_data_in_len[i],
8782                         pdcp_test_data_out[i],
8783                         pdcp_test_data_in_len[i],
8784                         32, 40);
8785 }
8786 static int
8787 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8788 {
8789         /* i can be used for running any PDCP case
8790          * In this case it is cplane 12-bit AES-ZUC DL encap
8791          */
8792         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8793         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8794                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8795                         RTE_CRYPTO_AUTH_OP_GENERATE,
8796                         pdcp_test_data_in[i],
8797                         pdcp_test_data_in_len[i],
8798                         pdcp_test_data_out[i],
8799                         pdcp_test_data_in_len[i]+4,
8800                         128, 32);
8801 }
8802
8803 static int
8804 test_PDCP_SDAP_PROTO_encap_all(void)
8805 {
8806         int i = 0, size = 0;
8807         int err, all_err = TEST_SUCCESS;
8808         const struct pdcp_sdap_test *cur_test;
8809
8810         size = RTE_DIM(list_pdcp_sdap_tests);
8811
8812         for (i = 0; i < size; i++) {
8813                 cur_test = &list_pdcp_sdap_tests[i];
8814                 err = test_pdcp_proto(
8815                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8816                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8817                         cur_test->in_len, cur_test->data_out,
8818                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8819                         cur_test->param.cipher_alg, cur_test->cipher_key,
8820                         cur_test->param.cipher_key_len,
8821                         cur_test->param.auth_alg,
8822                         cur_test->auth_key, cur_test->param.auth_key_len,
8823                         cur_test->bearer, cur_test->param.domain,
8824                         cur_test->packet_direction, cur_test->sn_size,
8825                         cur_test->hfn,
8826                         cur_test->hfn_threshold, SDAP_ENABLED);
8827                 if (err) {
8828                         printf("\t%d) %s: Encapsulation failed\n",
8829                                         cur_test->test_idx,
8830                                         cur_test->param.name);
8831                         err = TEST_FAILED;
8832                 } else {
8833                         printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8834                                         cur_test->param.name);
8835                         err = TEST_SUCCESS;
8836                 }
8837                 all_err += err;
8838         }
8839
8840         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8841
8842         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8843 }
8844
8845 static int
8846 test_PDCP_PROTO_short_mac(void)
8847 {
8848         int i = 0, size = 0;
8849         int err, all_err = TEST_SUCCESS;
8850         const struct pdcp_short_mac_test *cur_test;
8851
8852         size = RTE_DIM(list_pdcp_smac_tests);
8853
8854         for (i = 0; i < size; i++) {
8855                 cur_test = &list_pdcp_smac_tests[i];
8856                 err = test_pdcp_proto(
8857                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8858                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8859                         cur_test->in_len, cur_test->data_out,
8860                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8861                         RTE_CRYPTO_CIPHER_NULL, NULL,
8862                         0, cur_test->param.auth_alg,
8863                         cur_test->auth_key, cur_test->param.auth_key_len,
8864                         0, cur_test->param.domain, 0, 0,
8865                         0, 0, 0);
8866                 if (err) {
8867                         printf("\t%d) %s: Short MAC test failed\n",
8868                                         cur_test->test_idx,
8869                                         cur_test->param.name);
8870                         err = TEST_FAILED;
8871                 } else {
8872                         printf("\t%d) %s: Short MAC test PASS\n",
8873                                         cur_test->test_idx,
8874                                         cur_test->param.name);
8875                         rte_hexdump(stdout, "MAC I",
8876                                     cur_test->data_out + cur_test->in_len + 2,
8877                                     2);
8878                         err = TEST_SUCCESS;
8879                 }
8880                 all_err += err;
8881         }
8882
8883         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8884
8885         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8886
8887 }
8888
8889 static int
8890 test_PDCP_SDAP_PROTO_decap_all(void)
8891 {
8892         int i = 0, size = 0;
8893         int err, all_err = TEST_SUCCESS;
8894         const struct pdcp_sdap_test *cur_test;
8895
8896         size = RTE_DIM(list_pdcp_sdap_tests);
8897
8898         for (i = 0; i < size; i++) {
8899                 cur_test = &list_pdcp_sdap_tests[i];
8900                 err = test_pdcp_proto(
8901                         i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8902                         RTE_CRYPTO_AUTH_OP_VERIFY,
8903                         cur_test->data_out,
8904                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8905                         cur_test->data_in, cur_test->in_len,
8906                         cur_test->param.cipher_alg,
8907                         cur_test->cipher_key, cur_test->param.cipher_key_len,
8908                         cur_test->param.auth_alg, cur_test->auth_key,
8909                         cur_test->param.auth_key_len, cur_test->bearer,
8910                         cur_test->param.domain, cur_test->packet_direction,
8911                         cur_test->sn_size, cur_test->hfn,
8912                         cur_test->hfn_threshold, SDAP_ENABLED);
8913                 if (err) {
8914                         printf("\t%d) %s: Decapsulation failed\n",
8915                                         cur_test->test_idx,
8916                                         cur_test->param.name);
8917                         err = TEST_FAILED;
8918                 } else {
8919                         printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8920                                         cur_test->param.name);
8921                         err = TEST_SUCCESS;
8922                 }
8923                 all_err += err;
8924         }
8925
8926         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8927
8928         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8929 }
8930
8931 static int
8932 test_ipsec_proto_process(const struct ipsec_test_data td[],
8933                          struct ipsec_test_data res_d[],
8934                          int nb_td,
8935                          bool silent,
8936                          const struct ipsec_test_flags *flags)
8937 {
8938         struct crypto_testsuite_params *ts_params = &testsuite_params;
8939         struct crypto_unittest_params *ut_params = &unittest_params;
8940         struct rte_security_capability_idx sec_cap_idx;
8941         const struct rte_security_capability *sec_cap;
8942         struct rte_security_ipsec_xform ipsec_xform;
8943         uint8_t dev_id = ts_params->valid_devs[0];
8944         enum rte_security_ipsec_sa_direction dir;
8945         struct ipsec_test_data *res_d_tmp = NULL;
8946         uint32_t src = RTE_IPV4(192, 168, 1, 0);
8947         uint32_t dst = RTE_IPV4(192, 168, 1, 1);
8948         int salt_len, i, ret = TEST_SUCCESS;
8949         struct rte_security_ctx *ctx;
8950         uint8_t *input_text;
8951         uint32_t verify;
8952
8953         ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
8954         gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
8955
8956         /* Use first test data to create session */
8957
8958         /* Copy IPsec xform */
8959         memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
8960
8961         dir = ipsec_xform.direction;
8962         verify = flags->tunnel_hdr_verify;
8963
8964         if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
8965                 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
8966                         src += 1;
8967                 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
8968                         dst += 1;
8969         }
8970
8971         memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src));
8972         memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst));
8973
8974         ctx = rte_cryptodev_get_sec_ctx(dev_id);
8975
8976         sec_cap_idx.action = ut_params->type;
8977         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
8978         sec_cap_idx.ipsec.proto = ipsec_xform.proto;
8979         sec_cap_idx.ipsec.mode = ipsec_xform.mode;
8980         sec_cap_idx.ipsec.direction = ipsec_xform.direction;
8981
8982         if (flags->udp_encap)
8983                 ipsec_xform.options.udp_encap = 1;
8984
8985         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8986         if (sec_cap == NULL)
8987                 return TEST_SKIPPED;
8988
8989         /* Copy cipher session parameters */
8990         if (td[0].aead) {
8991                 memcpy(&ut_params->aead_xform, &td[0].xform.aead,
8992                        sizeof(ut_params->aead_xform));
8993                 ut_params->aead_xform.aead.key.data = td[0].key.data;
8994                 ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
8995
8996                 /* Verify crypto capabilities */
8997                 if (test_ipsec_crypto_caps_aead_verify(
8998                                 sec_cap,
8999                                 &ut_params->aead_xform) != 0) {
9000                         if (!silent)
9001                                 RTE_LOG(INFO, USER1,
9002                                         "Crypto capabilities not supported\n");
9003                         return TEST_SKIPPED;
9004                 }
9005         } else {
9006                 /* Only AEAD supported now */
9007                 return TEST_SKIPPED;
9008         }
9009
9010         if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
9011                 return TEST_SKIPPED;
9012
9013         salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
9014         memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
9015
9016         struct rte_security_session_conf sess_conf = {
9017                 .action_type = ut_params->type,
9018                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
9019                 .ipsec = ipsec_xform,
9020                 .crypto_xform = &ut_params->aead_xform,
9021         };
9022
9023         /* Create security session */
9024         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9025                                         ts_params->session_mpool,
9026                                         ts_params->session_priv_mpool);
9027
9028         if (ut_params->sec_session == NULL)
9029                 return TEST_SKIPPED;
9030
9031         for (i = 0; i < nb_td; i++) {
9032                 /* Setup source mbuf payload */
9033                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9034                 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9035                                 rte_pktmbuf_tailroom(ut_params->ibuf));
9036
9037                 input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9038                                 td[i].input_text.len);
9039
9040                 memcpy(input_text, td[i].input_text.data,
9041                        td[i].input_text.len);
9042
9043                 /* Generate crypto op data structure */
9044                 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9045                                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9046                 if (!ut_params->op) {
9047                         printf("TestCase %s line %d: %s\n",
9048                                 __func__, __LINE__,
9049                                 "failed to allocate crypto op");
9050                         ret = TEST_FAILED;
9051                         goto crypto_op_free;
9052                 }
9053
9054                 /* Attach session to operation */
9055                 rte_security_attach_session(ut_params->op,
9056                                             ut_params->sec_session);
9057
9058                 /* Set crypto operation mbufs */
9059                 ut_params->op->sym->m_src = ut_params->ibuf;
9060                 ut_params->op->sym->m_dst = NULL;
9061
9062                 /* Copy IV in crypto operation when IV generation is disabled */
9063                 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
9064                     ipsec_xform.options.iv_gen_disable == 1) {
9065                         uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
9066                                                                 uint8_t *,
9067                                                                 IV_OFFSET);
9068                         int len;
9069
9070                         if (td[i].aead)
9071                                 len = td[i].xform.aead.aead.iv.length;
9072                         else
9073                                 len = td[i].xform.chain.cipher.cipher.iv.length;
9074
9075                         memcpy(iv, td[i].iv.data, len);
9076                 }
9077
9078                 /* Process crypto operation */
9079                 process_crypto_request(dev_id, ut_params->op);
9080
9081                 ret = test_ipsec_status_check(ut_params->op, flags, dir, i + 1);
9082                 if (ret != TEST_SUCCESS)
9083                         goto crypto_op_free;
9084
9085                 if (res_d != NULL)
9086                         res_d_tmp = &res_d[i];
9087
9088                 ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
9089                                               res_d_tmp, silent, flags);
9090                 if (ret != TEST_SUCCESS)
9091                         goto crypto_op_free;
9092
9093                 rte_crypto_op_free(ut_params->op);
9094                 ut_params->op = NULL;
9095
9096                 rte_pktmbuf_free(ut_params->ibuf);
9097                 ut_params->ibuf = NULL;
9098         }
9099
9100 crypto_op_free:
9101         rte_crypto_op_free(ut_params->op);
9102         ut_params->op = NULL;
9103
9104         rte_pktmbuf_free(ut_params->ibuf);
9105         ut_params->ibuf = NULL;
9106
9107         if (ut_params->sec_session)
9108                 rte_security_session_destroy(ctx, ut_params->sec_session);
9109         ut_params->sec_session = NULL;
9110
9111         return ret;
9112 }
9113
9114 static int
9115 test_ipsec_proto_known_vec(const void *test_data)
9116 {
9117         struct ipsec_test_data td_outb;
9118         struct ipsec_test_flags flags;
9119
9120         memset(&flags, 0, sizeof(flags));
9121
9122         memcpy(&td_outb, test_data, sizeof(td_outb));
9123
9124         /* Disable IV gen to be able to test with known vectors */
9125         td_outb.ipsec_xform.options.iv_gen_disable = 1;
9126
9127         return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9128 }
9129
9130 static int
9131 test_ipsec_proto_known_vec_inb(const void *td_outb)
9132 {
9133         struct ipsec_test_flags flags;
9134         struct ipsec_test_data td_inb;
9135
9136         memset(&flags, 0, sizeof(flags));
9137
9138         test_ipsec_td_in_from_out(td_outb, &td_inb);
9139
9140         return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
9141 }
9142
9143 static int
9144 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
9145 {
9146         struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9147         struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9148         unsigned int i, nb_pkts = 1, pass_cnt = 0;
9149         int ret;
9150
9151         if (flags->iv_gen ||
9152             flags->sa_expiry_pkts_soft ||
9153             flags->sa_expiry_pkts_hard)
9154                 nb_pkts = IPSEC_TEST_PACKETS_MAX;
9155
9156         for (i = 0; i < RTE_DIM(aead_list); i++) {
9157                 test_ipsec_td_prepare(&aead_list[i],
9158                                       NULL,
9159                                       flags,
9160                                       td_outb,
9161                                       nb_pkts);
9162
9163                 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9164                                                flags);
9165                 if (ret == TEST_SKIPPED)
9166                         continue;
9167
9168                 if (ret == TEST_FAILED)
9169                         return TEST_FAILED;
9170
9171                 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9172
9173                 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9174                                                flags);
9175                 if (ret == TEST_SKIPPED)
9176                         continue;
9177
9178                 if (ret == TEST_FAILED)
9179                         return TEST_FAILED;
9180
9181                 if (flags->display_alg)
9182                         test_ipsec_display_alg(&aead_list[i], NULL);
9183
9184                 pass_cnt++;
9185         }
9186
9187         if (pass_cnt > 0)
9188                 return TEST_SUCCESS;
9189         else
9190                 return TEST_SKIPPED;
9191 }
9192
9193 static int
9194 test_ipsec_proto_display_list(const void *data __rte_unused)
9195 {
9196         struct ipsec_test_flags flags;
9197
9198         memset(&flags, 0, sizeof(flags));
9199
9200         flags.display_alg = true;
9201
9202         return test_ipsec_proto_all(&flags);
9203 }
9204
9205 static int
9206 test_ipsec_proto_iv_gen(const void *data __rte_unused)
9207 {
9208         struct ipsec_test_flags flags;
9209
9210         memset(&flags, 0, sizeof(flags));
9211
9212         flags.iv_gen = true;
9213
9214         return test_ipsec_proto_all(&flags);
9215 }
9216
9217 static int
9218 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused)
9219 {
9220         struct ipsec_test_flags flags;
9221
9222         memset(&flags, 0, sizeof(flags));
9223
9224         flags.sa_expiry_pkts_soft = true;
9225
9226         return test_ipsec_proto_all(&flags);
9227 }
9228
9229 static int
9230 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused)
9231 {
9232         struct ipsec_test_flags flags;
9233
9234         memset(&flags, 0, sizeof(flags));
9235
9236         flags.sa_expiry_pkts_hard = true;
9237
9238         return test_ipsec_proto_all(&flags);
9239 }
9240
9241 static int
9242 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused)
9243 {
9244         struct ipsec_test_flags flags;
9245
9246         memset(&flags, 0, sizeof(flags));
9247
9248         flags.icv_corrupt = true;
9249
9250         return test_ipsec_proto_all(&flags);
9251 }
9252
9253 static int
9254 test_ipsec_proto_udp_encap(const void *data __rte_unused)
9255 {
9256         struct ipsec_test_flags flags;
9257
9258         memset(&flags, 0, sizeof(flags));
9259
9260         flags.udp_encap = true;
9261
9262         return test_ipsec_proto_all(&flags);
9263 }
9264
9265 static int
9266 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
9267 {
9268         struct ipsec_test_flags flags;
9269
9270         memset(&flags, 0, sizeof(flags));
9271
9272         flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
9273
9274         return test_ipsec_proto_all(&flags);
9275 }
9276
9277 static int
9278 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
9279 {
9280         struct ipsec_test_flags flags;
9281
9282         memset(&flags, 0, sizeof(flags));
9283
9284         flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
9285
9286         return test_ipsec_proto_all(&flags);
9287 }
9288
9289 static int
9290 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused)
9291 {
9292         struct ipsec_test_flags flags;
9293
9294         memset(&flags, 0, sizeof(flags));
9295
9296         flags.udp_encap = true;
9297         flags.udp_ports_verify = true;
9298
9299         return test_ipsec_proto_all(&flags);
9300 }
9301
9302 static int
9303 test_PDCP_PROTO_all(void)
9304 {
9305         struct crypto_testsuite_params *ts_params = &testsuite_params;
9306         struct crypto_unittest_params *ut_params = &unittest_params;
9307         struct rte_cryptodev_info dev_info;
9308         int status;
9309
9310         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9311         uint64_t feat_flags = dev_info.feature_flags;
9312
9313         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9314                 return TEST_SKIPPED;
9315
9316         /* Set action type */
9317         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9318                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9319                 gbl_action_type;
9320
9321         if (security_proto_supported(ut_params->type,
9322                         RTE_SECURITY_PROTOCOL_PDCP) < 0)
9323                 return TEST_SKIPPED;
9324
9325         status = test_PDCP_PROTO_cplane_encap_all();
9326         status += test_PDCP_PROTO_cplane_decap_all();
9327         status += test_PDCP_PROTO_uplane_encap_all();
9328         status += test_PDCP_PROTO_uplane_decap_all();
9329         status += test_PDCP_PROTO_SGL_in_place_32B();
9330         status += test_PDCP_PROTO_SGL_oop_32B_128B();
9331         status += test_PDCP_PROTO_SGL_oop_32B_40B();
9332         status += test_PDCP_PROTO_SGL_oop_128B_32B();
9333         status += test_PDCP_SDAP_PROTO_encap_all();
9334         status += test_PDCP_SDAP_PROTO_decap_all();
9335         status += test_PDCP_PROTO_short_mac();
9336
9337         if (status)
9338                 return TEST_FAILED;
9339         else
9340                 return TEST_SUCCESS;
9341 }
9342
9343 static int
9344 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
9345 {
9346         struct crypto_testsuite_params *ts_params = &testsuite_params;
9347         struct crypto_unittest_params *ut_params = &unittest_params;
9348         uint8_t *plaintext, *ciphertext;
9349         uint8_t *iv_ptr;
9350         int32_t cipher_len, crc_len;
9351         uint32_t crc_data_len;
9352         int ret = TEST_SUCCESS;
9353
9354         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9355                                         rte_cryptodev_get_sec_ctx(
9356                                                 ts_params->valid_devs[0]);
9357
9358         /* Verify the capabilities */
9359         struct rte_security_capability_idx sec_cap_idx;
9360         const struct rte_security_capability *sec_cap;
9361         const struct rte_cryptodev_capabilities *crypto_cap;
9362         const struct rte_cryptodev_symmetric_capability *sym_cap;
9363         int j = 0;
9364
9365         sec_cap_idx.action = ut_params->type;
9366         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9367         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
9368
9369         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9370         if (sec_cap == NULL)
9371                 return TEST_SKIPPED;
9372
9373         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9374                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9375                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9376                                 crypto_cap->sym.xform_type ==
9377                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9378                                 crypto_cap->sym.cipher.algo ==
9379                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9380                         sym_cap = &crypto_cap->sym;
9381                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9382                                                 d_td->key.len,
9383                                                 d_td->iv.len) == 0)
9384                                 break;
9385                 }
9386         }
9387
9388         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9389                 return TEST_SKIPPED;
9390
9391         /* Setup source mbuf payload */
9392         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9393         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9394                         rte_pktmbuf_tailroom(ut_params->ibuf));
9395
9396         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9397                         d_td->ciphertext.len);
9398
9399         memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
9400
9401         /* Setup cipher session parameters */
9402         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9403         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9404         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
9405         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9406         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9407         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9408         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9409         ut_params->cipher_xform.next = NULL;
9410
9411         /* Setup DOCSIS session parameters */
9412         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
9413
9414         struct rte_security_session_conf sess_conf = {
9415                 .action_type = ut_params->type,
9416                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9417                 .docsis = ut_params->docsis_xform,
9418                 .crypto_xform = &ut_params->cipher_xform,
9419         };
9420
9421         /* Create security session */
9422         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9423                                         ts_params->session_mpool,
9424                                         ts_params->session_priv_mpool);
9425
9426         if (!ut_params->sec_session) {
9427                 printf("TestCase %s(%d) line %d: %s\n",
9428                         __func__, i, __LINE__, "failed to allocate session");
9429                 ret = TEST_FAILED;
9430                 goto on_err;
9431         }
9432
9433         /* Generate crypto op data structure */
9434         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9435                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9436         if (!ut_params->op) {
9437                 printf("TestCase %s(%d) line %d: %s\n",
9438                         __func__, i, __LINE__,
9439                         "failed to allocate symmetric crypto operation");
9440                 ret = TEST_FAILED;
9441                 goto on_err;
9442         }
9443
9444         /* Setup CRC operation parameters */
9445         crc_len = d_td->ciphertext.no_crc == false ?
9446                         (d_td->ciphertext.len -
9447                                 d_td->ciphertext.crc_offset -
9448                                 RTE_ETHER_CRC_LEN) :
9449                         0;
9450         crc_len = crc_len > 0 ? crc_len : 0;
9451         crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
9452         ut_params->op->sym->auth.data.length = crc_len;
9453         ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
9454
9455         /* Setup cipher operation parameters */
9456         cipher_len = d_td->ciphertext.no_cipher == false ?
9457                         (d_td->ciphertext.len -
9458                                 d_td->ciphertext.cipher_offset) :
9459                         0;
9460         cipher_len = cipher_len > 0 ? cipher_len : 0;
9461         ut_params->op->sym->cipher.data.length = cipher_len;
9462         ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
9463
9464         /* Setup cipher IV */
9465         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9466         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9467
9468         /* Attach session to operation */
9469         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9470
9471         /* Set crypto operation mbufs */
9472         ut_params->op->sym->m_src = ut_params->ibuf;
9473         ut_params->op->sym->m_dst = NULL;
9474
9475         /* Process crypto operation */
9476         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9477                         NULL) {
9478                 printf("TestCase %s(%d) line %d: %s\n",
9479                         __func__, i, __LINE__,
9480                         "failed to process security crypto op");
9481                 ret = TEST_FAILED;
9482                 goto on_err;
9483         }
9484
9485         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9486                 printf("TestCase %s(%d) line %d: %s\n",
9487                         __func__, i, __LINE__, "crypto op processing failed");
9488                 ret = TEST_FAILED;
9489                 goto on_err;
9490         }
9491
9492         /* Validate plaintext */
9493         plaintext = ciphertext;
9494
9495         if (memcmp(plaintext, d_td->plaintext.data,
9496                         d_td->plaintext.len - crc_data_len)) {
9497                 printf("TestCase %s(%d) line %d: %s\n",
9498                         __func__, i, __LINE__, "plaintext not as expected\n");
9499                 rte_hexdump(stdout, "expected", d_td->plaintext.data,
9500                                 d_td->plaintext.len);
9501                 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9502                 ret = TEST_FAILED;
9503                 goto on_err;
9504         }
9505
9506 on_err:
9507         rte_crypto_op_free(ut_params->op);
9508         ut_params->op = NULL;
9509
9510         if (ut_params->sec_session)
9511                 rte_security_session_destroy(ctx, ut_params->sec_session);
9512         ut_params->sec_session = NULL;
9513
9514         rte_pktmbuf_free(ut_params->ibuf);
9515         ut_params->ibuf = NULL;
9516
9517         return ret;
9518 }
9519
9520 static int
9521 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9522 {
9523         struct crypto_testsuite_params *ts_params = &testsuite_params;
9524         struct crypto_unittest_params *ut_params = &unittest_params;
9525         uint8_t *plaintext, *ciphertext;
9526         uint8_t *iv_ptr;
9527         int32_t cipher_len, crc_len;
9528         int ret = TEST_SUCCESS;
9529
9530         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9531                                         rte_cryptodev_get_sec_ctx(
9532                                                 ts_params->valid_devs[0]);
9533
9534         /* Verify the capabilities */
9535         struct rte_security_capability_idx sec_cap_idx;
9536         const struct rte_security_capability *sec_cap;
9537         const struct rte_cryptodev_capabilities *crypto_cap;
9538         const struct rte_cryptodev_symmetric_capability *sym_cap;
9539         int j = 0;
9540
9541         sec_cap_idx.action = ut_params->type;
9542         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9543         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9544
9545         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9546         if (sec_cap == NULL)
9547                 return TEST_SKIPPED;
9548
9549         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9550                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9551                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9552                                 crypto_cap->sym.xform_type ==
9553                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9554                                 crypto_cap->sym.cipher.algo ==
9555                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9556                         sym_cap = &crypto_cap->sym;
9557                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9558                                                 d_td->key.len,
9559                                                 d_td->iv.len) == 0)
9560                                 break;
9561                 }
9562         }
9563
9564         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9565                 return TEST_SKIPPED;
9566
9567         /* Setup source mbuf payload */
9568         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9569         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9570                         rte_pktmbuf_tailroom(ut_params->ibuf));
9571
9572         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9573                         d_td->plaintext.len);
9574
9575         memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9576
9577         /* Setup cipher session parameters */
9578         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9579         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9580         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9581         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9582         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9583         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9584         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9585         ut_params->cipher_xform.next = NULL;
9586
9587         /* Setup DOCSIS session parameters */
9588         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9589
9590         struct rte_security_session_conf sess_conf = {
9591                 .action_type = ut_params->type,
9592                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9593                 .docsis = ut_params->docsis_xform,
9594                 .crypto_xform = &ut_params->cipher_xform,
9595         };
9596
9597         /* Create security session */
9598         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9599                                         ts_params->session_mpool,
9600                                         ts_params->session_priv_mpool);
9601
9602         if (!ut_params->sec_session) {
9603                 printf("TestCase %s(%d) line %d: %s\n",
9604                         __func__, i, __LINE__, "failed to allocate session");
9605                 ret = TEST_FAILED;
9606                 goto on_err;
9607         }
9608
9609         /* Generate crypto op data structure */
9610         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9611                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9612         if (!ut_params->op) {
9613                 printf("TestCase %s(%d) line %d: %s\n",
9614                         __func__, i, __LINE__,
9615                         "failed to allocate security crypto operation");
9616                 ret = TEST_FAILED;
9617                 goto on_err;
9618         }
9619
9620         /* Setup CRC operation parameters */
9621         crc_len = d_td->plaintext.no_crc == false ?
9622                         (d_td->plaintext.len -
9623                                 d_td->plaintext.crc_offset -
9624                                 RTE_ETHER_CRC_LEN) :
9625                         0;
9626         crc_len = crc_len > 0 ? crc_len : 0;
9627         ut_params->op->sym->auth.data.length = crc_len;
9628         ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9629
9630         /* Setup cipher operation parameters */
9631         cipher_len = d_td->plaintext.no_cipher == false ?
9632                         (d_td->plaintext.len -
9633                                 d_td->plaintext.cipher_offset) :
9634                         0;
9635         cipher_len = cipher_len > 0 ? cipher_len : 0;
9636         ut_params->op->sym->cipher.data.length = cipher_len;
9637         ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9638
9639         /* Setup cipher IV */
9640         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9641         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9642
9643         /* Attach session to operation */
9644         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9645
9646         /* Set crypto operation mbufs */
9647         ut_params->op->sym->m_src = ut_params->ibuf;
9648         ut_params->op->sym->m_dst = NULL;
9649
9650         /* Process crypto operation */
9651         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9652                         NULL) {
9653                 printf("TestCase %s(%d) line %d: %s\n",
9654                         __func__, i, __LINE__,
9655                         "failed to process security crypto op");
9656                 ret = TEST_FAILED;
9657                 goto on_err;
9658         }
9659
9660         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9661                 printf("TestCase %s(%d) line %d: %s\n",
9662                         __func__, i, __LINE__, "crypto op processing failed");
9663                 ret = TEST_FAILED;
9664                 goto on_err;
9665         }
9666
9667         /* Validate ciphertext */
9668         ciphertext = plaintext;
9669
9670         if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9671                 printf("TestCase %s(%d) line %d: %s\n",
9672                         __func__, i, __LINE__, "ciphertext not as expected\n");
9673                 rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9674                                 d_td->ciphertext.len);
9675                 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9676                 ret = TEST_FAILED;
9677                 goto on_err;
9678         }
9679
9680 on_err:
9681         rte_crypto_op_free(ut_params->op);
9682         ut_params->op = NULL;
9683
9684         if (ut_params->sec_session)
9685                 rte_security_session_destroy(ctx, ut_params->sec_session);
9686         ut_params->sec_session = NULL;
9687
9688         rte_pktmbuf_free(ut_params->ibuf);
9689         ut_params->ibuf = NULL;
9690
9691         return ret;
9692 }
9693
9694 #define TEST_DOCSIS_COUNT(func) do {                    \
9695         int ret = func;                                 \
9696         if (ret == TEST_SUCCESS)  {                     \
9697                 printf("\t%2d)", n++);                  \
9698                 printf("+++++ PASSED:" #func"\n");      \
9699                 p++;                                    \
9700         } else if (ret == TEST_SKIPPED) {               \
9701                 printf("\t%2d)", n++);                  \
9702                 printf("~~~~~ SKIPPED:" #func"\n");     \
9703                 s++;                                    \
9704         } else {                                        \
9705                 printf("\t%2d)", n++);                  \
9706                 printf("----- FAILED:" #func"\n");      \
9707                 f++;                                    \
9708         }                                               \
9709 } while (0)
9710
9711 static int
9712 test_DOCSIS_PROTO_uplink_all(void)
9713 {
9714         int p = 0, s = 0, f = 0, n = 0;
9715
9716         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9717         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9718         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9719         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9720         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9721         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9722         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9723         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9724         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9725         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9726         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9727         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9728         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9729         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9730         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9731         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9732         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9733         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9734         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9735         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9736         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9737         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9738         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9739         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9740         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9741         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9742
9743         if (f)
9744                 printf("## %s: %d passed out of %d (%d skipped)\n",
9745                         __func__, p, n, s);
9746
9747         return f;
9748 };
9749
9750 static int
9751 test_DOCSIS_PROTO_downlink_all(void)
9752 {
9753         int p = 0, s = 0, f = 0, n = 0;
9754
9755         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9756         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9757         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9758         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9759         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9760         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9761         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9762         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9763         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9764         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9765         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9766         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9767         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9768         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9769         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9770         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9771         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9772         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9773         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9774         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9775         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9776         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9777         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9778         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9779         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9780         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9781
9782         if (f)
9783                 printf("## %s: %d passed out of %d (%d skipped)\n",
9784                         __func__, p, n, s);
9785
9786         return f;
9787 };
9788
9789 static int
9790 test_DOCSIS_PROTO_all(void)
9791 {
9792         struct crypto_testsuite_params *ts_params = &testsuite_params;
9793         struct crypto_unittest_params *ut_params = &unittest_params;
9794         struct rte_cryptodev_info dev_info;
9795         int status;
9796
9797         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9798         uint64_t feat_flags = dev_info.feature_flags;
9799
9800         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9801                 return TEST_SKIPPED;
9802
9803         /* Set action type */
9804         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9805                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9806                 gbl_action_type;
9807
9808         if (security_proto_supported(ut_params->type,
9809                         RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9810                 return TEST_SKIPPED;
9811
9812         status = test_DOCSIS_PROTO_uplink_all();
9813         status += test_DOCSIS_PROTO_downlink_all();
9814
9815         if (status)
9816                 return TEST_FAILED;
9817         else
9818                 return TEST_SUCCESS;
9819 }
9820 #endif
9821
9822 static int
9823 test_AES_GCM_authenticated_encryption_test_case_1(void)
9824 {
9825         return test_authenticated_encryption(&gcm_test_case_1);
9826 }
9827
9828 static int
9829 test_AES_GCM_authenticated_encryption_test_case_2(void)
9830 {
9831         return test_authenticated_encryption(&gcm_test_case_2);
9832 }
9833
9834 static int
9835 test_AES_GCM_authenticated_encryption_test_case_3(void)
9836 {
9837         return test_authenticated_encryption(&gcm_test_case_3);
9838 }
9839
9840 static int
9841 test_AES_GCM_authenticated_encryption_test_case_4(void)
9842 {
9843         return test_authenticated_encryption(&gcm_test_case_4);
9844 }
9845
9846 static int
9847 test_AES_GCM_authenticated_encryption_test_case_5(void)
9848 {
9849         return test_authenticated_encryption(&gcm_test_case_5);
9850 }
9851
9852 static int
9853 test_AES_GCM_authenticated_encryption_test_case_6(void)
9854 {
9855         return test_authenticated_encryption(&gcm_test_case_6);
9856 }
9857
9858 static int
9859 test_AES_GCM_authenticated_encryption_test_case_7(void)
9860 {
9861         return test_authenticated_encryption(&gcm_test_case_7);
9862 }
9863
9864 static int
9865 test_AES_GCM_authenticated_encryption_test_case_8(void)
9866 {
9867         return test_authenticated_encryption(&gcm_test_case_8);
9868 }
9869
9870 static int
9871 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9872 {
9873         return test_authenticated_encryption(&gcm_J0_test_case_1);
9874 }
9875
9876 static int
9877 test_AES_GCM_auth_encryption_test_case_192_1(void)
9878 {
9879         return test_authenticated_encryption(&gcm_test_case_192_1);
9880 }
9881
9882 static int
9883 test_AES_GCM_auth_encryption_test_case_192_2(void)
9884 {
9885         return test_authenticated_encryption(&gcm_test_case_192_2);
9886 }
9887
9888 static int
9889 test_AES_GCM_auth_encryption_test_case_192_3(void)
9890 {
9891         return test_authenticated_encryption(&gcm_test_case_192_3);
9892 }
9893
9894 static int
9895 test_AES_GCM_auth_encryption_test_case_192_4(void)
9896 {
9897         return test_authenticated_encryption(&gcm_test_case_192_4);
9898 }
9899
9900 static int
9901 test_AES_GCM_auth_encryption_test_case_192_5(void)
9902 {
9903         return test_authenticated_encryption(&gcm_test_case_192_5);
9904 }
9905
9906 static int
9907 test_AES_GCM_auth_encryption_test_case_192_6(void)
9908 {
9909         return test_authenticated_encryption(&gcm_test_case_192_6);
9910 }
9911
9912 static int
9913 test_AES_GCM_auth_encryption_test_case_192_7(void)
9914 {
9915         return test_authenticated_encryption(&gcm_test_case_192_7);
9916 }
9917
9918 static int
9919 test_AES_GCM_auth_encryption_test_case_256_1(void)
9920 {
9921         return test_authenticated_encryption(&gcm_test_case_256_1);
9922 }
9923
9924 static int
9925 test_AES_GCM_auth_encryption_test_case_256_2(void)
9926 {
9927         return test_authenticated_encryption(&gcm_test_case_256_2);
9928 }
9929
9930 static int
9931 test_AES_GCM_auth_encryption_test_case_256_3(void)
9932 {
9933         return test_authenticated_encryption(&gcm_test_case_256_3);
9934 }
9935
9936 static int
9937 test_AES_GCM_auth_encryption_test_case_256_4(void)
9938 {
9939         return test_authenticated_encryption(&gcm_test_case_256_4);
9940 }
9941
9942 static int
9943 test_AES_GCM_auth_encryption_test_case_256_5(void)
9944 {
9945         return test_authenticated_encryption(&gcm_test_case_256_5);
9946 }
9947
9948 static int
9949 test_AES_GCM_auth_encryption_test_case_256_6(void)
9950 {
9951         return test_authenticated_encryption(&gcm_test_case_256_6);
9952 }
9953
9954 static int
9955 test_AES_GCM_auth_encryption_test_case_256_7(void)
9956 {
9957         return test_authenticated_encryption(&gcm_test_case_256_7);
9958 }
9959
9960 static int
9961 test_AES_GCM_auth_encryption_test_case_aad_1(void)
9962 {
9963         return test_authenticated_encryption(&gcm_test_case_aad_1);
9964 }
9965
9966 static int
9967 test_AES_GCM_auth_encryption_test_case_aad_2(void)
9968 {
9969         return test_authenticated_encryption(&gcm_test_case_aad_2);
9970 }
9971
9972 static int
9973 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
9974 {
9975         struct aead_test_data tdata;
9976         int res;
9977
9978         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9979         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9980         tdata.iv.data[0] += 1;
9981         res = test_authenticated_encryption(&tdata);
9982         if (res == TEST_SKIPPED)
9983                 return res;
9984         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9985         return TEST_SUCCESS;
9986 }
9987
9988 static int
9989 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
9990 {
9991         struct aead_test_data tdata;
9992         int res;
9993
9994         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9995         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9996         tdata.plaintext.data[0] += 1;
9997         res = test_authenticated_encryption(&tdata);
9998         if (res == TEST_SKIPPED)
9999                 return res;
10000         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10001         return TEST_SUCCESS;
10002 }
10003
10004 static int
10005 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
10006 {
10007         struct aead_test_data tdata;
10008         int res;
10009
10010         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10011         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10012         tdata.ciphertext.data[0] += 1;
10013         res = test_authenticated_encryption(&tdata);
10014         if (res == TEST_SKIPPED)
10015                 return res;
10016         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10017         return TEST_SUCCESS;
10018 }
10019
10020 static int
10021 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
10022 {
10023         struct aead_test_data tdata;
10024         int res;
10025
10026         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10027         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10028         tdata.aad.len += 1;
10029         res = test_authenticated_encryption(&tdata);
10030         if (res == TEST_SKIPPED)
10031                 return res;
10032         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10033         return TEST_SUCCESS;
10034 }
10035
10036 static int
10037 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
10038 {
10039         struct aead_test_data tdata;
10040         uint8_t aad[gcm_test_case_7.aad.len];
10041         int res;
10042
10043         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10044         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10045         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10046         aad[0] += 1;
10047         tdata.aad.data = aad;
10048         res = test_authenticated_encryption(&tdata);
10049         if (res == TEST_SKIPPED)
10050                 return res;
10051         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10052         return TEST_SUCCESS;
10053 }
10054
10055 static int
10056 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
10057 {
10058         struct aead_test_data tdata;
10059         int res;
10060
10061         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10062         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10063         tdata.auth_tag.data[0] += 1;
10064         res = test_authenticated_encryption(&tdata);
10065         if (res == TEST_SKIPPED)
10066                 return res;
10067         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10068         return TEST_SUCCESS;
10069 }
10070
10071 static int
10072 test_authenticated_decryption(const struct aead_test_data *tdata)
10073 {
10074         struct crypto_testsuite_params *ts_params = &testsuite_params;
10075         struct crypto_unittest_params *ut_params = &unittest_params;
10076
10077         int retval;
10078         uint8_t *plaintext;
10079         uint32_t i;
10080         struct rte_cryptodev_info dev_info;
10081
10082         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10083         uint64_t feat_flags = dev_info.feature_flags;
10084
10085         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10086                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10087                 printf("Device doesn't support RAW data-path APIs.\n");
10088                 return TEST_SKIPPED;
10089         }
10090
10091         /* Verify the capabilities */
10092         struct rte_cryptodev_sym_capability_idx cap_idx;
10093         const struct rte_cryptodev_symmetric_capability *capability;
10094         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10095         cap_idx.algo.aead = tdata->algo;
10096         capability = rte_cryptodev_sym_capability_get(
10097                         ts_params->valid_devs[0], &cap_idx);
10098         if (capability == NULL)
10099                 return TEST_SKIPPED;
10100         if (rte_cryptodev_sym_capability_check_aead(
10101                         capability, tdata->key.len, tdata->auth_tag.len,
10102                         tdata->aad.len, tdata->iv.len))
10103                 return TEST_SKIPPED;
10104
10105         /* Create AEAD session */
10106         retval = create_aead_session(ts_params->valid_devs[0],
10107                         tdata->algo,
10108                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10109                         tdata->key.data, tdata->key.len,
10110                         tdata->aad.len, tdata->auth_tag.len,
10111                         tdata->iv.len);
10112         if (retval < 0)
10113                 return retval;
10114
10115         /* alloc mbuf and set payload */
10116         if (tdata->aad.len > MBUF_SIZE) {
10117                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10118                 /* Populate full size of add data */
10119                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
10120                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
10121         } else
10122                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10123
10124         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10125                         rte_pktmbuf_tailroom(ut_params->ibuf));
10126
10127         /* Create AEAD operation */
10128         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10129         if (retval < 0)
10130                 return retval;
10131
10132         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10133
10134         ut_params->op->sym->m_src = ut_params->ibuf;
10135
10136         /* Process crypto operation */
10137         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10138                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
10139         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10140                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10141                                 ut_params->op, 0, 0, 0, 0);
10142         else
10143                 TEST_ASSERT_NOT_NULL(
10144                         process_crypto_request(ts_params->valid_devs[0],
10145                         ut_params->op), "failed to process sym crypto op");
10146
10147         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10148                         "crypto op processing failed");
10149
10150         if (ut_params->op->sym->m_dst)
10151                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
10152                                 uint8_t *);
10153         else
10154                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
10155                                 uint8_t *,
10156                                 ut_params->op->sym->cipher.data.offset);
10157
10158         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10159
10160         /* Validate obuf */
10161         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10162                         plaintext,
10163                         tdata->plaintext.data,
10164                         tdata->plaintext.len,
10165                         "Plaintext data not as expected");
10166
10167         TEST_ASSERT_EQUAL(ut_params->op->status,
10168                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10169                         "Authentication failed");
10170
10171         return 0;
10172 }
10173
10174 static int
10175 test_AES_GCM_authenticated_decryption_test_case_1(void)
10176 {
10177         return test_authenticated_decryption(&gcm_test_case_1);
10178 }
10179
10180 static int
10181 test_AES_GCM_authenticated_decryption_test_case_2(void)
10182 {
10183         return test_authenticated_decryption(&gcm_test_case_2);
10184 }
10185
10186 static int
10187 test_AES_GCM_authenticated_decryption_test_case_3(void)
10188 {
10189         return test_authenticated_decryption(&gcm_test_case_3);
10190 }
10191
10192 static int
10193 test_AES_GCM_authenticated_decryption_test_case_4(void)
10194 {
10195         return test_authenticated_decryption(&gcm_test_case_4);
10196 }
10197
10198 static int
10199 test_AES_GCM_authenticated_decryption_test_case_5(void)
10200 {
10201         return test_authenticated_decryption(&gcm_test_case_5);
10202 }
10203
10204 static int
10205 test_AES_GCM_authenticated_decryption_test_case_6(void)
10206 {
10207         return test_authenticated_decryption(&gcm_test_case_6);
10208 }
10209
10210 static int
10211 test_AES_GCM_authenticated_decryption_test_case_7(void)
10212 {
10213         return test_authenticated_decryption(&gcm_test_case_7);
10214 }
10215
10216 static int
10217 test_AES_GCM_authenticated_decryption_test_case_8(void)
10218 {
10219         return test_authenticated_decryption(&gcm_test_case_8);
10220 }
10221
10222 static int
10223 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
10224 {
10225         return test_authenticated_decryption(&gcm_J0_test_case_1);
10226 }
10227
10228 static int
10229 test_AES_GCM_auth_decryption_test_case_192_1(void)
10230 {
10231         return test_authenticated_decryption(&gcm_test_case_192_1);
10232 }
10233
10234 static int
10235 test_AES_GCM_auth_decryption_test_case_192_2(void)
10236 {
10237         return test_authenticated_decryption(&gcm_test_case_192_2);
10238 }
10239
10240 static int
10241 test_AES_GCM_auth_decryption_test_case_192_3(void)
10242 {
10243         return test_authenticated_decryption(&gcm_test_case_192_3);
10244 }
10245
10246 static int
10247 test_AES_GCM_auth_decryption_test_case_192_4(void)
10248 {
10249         return test_authenticated_decryption(&gcm_test_case_192_4);
10250 }
10251
10252 static int
10253 test_AES_GCM_auth_decryption_test_case_192_5(void)
10254 {
10255         return test_authenticated_decryption(&gcm_test_case_192_5);
10256 }
10257
10258 static int
10259 test_AES_GCM_auth_decryption_test_case_192_6(void)
10260 {
10261         return test_authenticated_decryption(&gcm_test_case_192_6);
10262 }
10263
10264 static int
10265 test_AES_GCM_auth_decryption_test_case_192_7(void)
10266 {
10267         return test_authenticated_decryption(&gcm_test_case_192_7);
10268 }
10269
10270 static int
10271 test_AES_GCM_auth_decryption_test_case_256_1(void)
10272 {
10273         return test_authenticated_decryption(&gcm_test_case_256_1);
10274 }
10275
10276 static int
10277 test_AES_GCM_auth_decryption_test_case_256_2(void)
10278 {
10279         return test_authenticated_decryption(&gcm_test_case_256_2);
10280 }
10281
10282 static int
10283 test_AES_GCM_auth_decryption_test_case_256_3(void)
10284 {
10285         return test_authenticated_decryption(&gcm_test_case_256_3);
10286 }
10287
10288 static int
10289 test_AES_GCM_auth_decryption_test_case_256_4(void)
10290 {
10291         return test_authenticated_decryption(&gcm_test_case_256_4);
10292 }
10293
10294 static int
10295 test_AES_GCM_auth_decryption_test_case_256_5(void)
10296 {
10297         return test_authenticated_decryption(&gcm_test_case_256_5);
10298 }
10299
10300 static int
10301 test_AES_GCM_auth_decryption_test_case_256_6(void)
10302 {
10303         return test_authenticated_decryption(&gcm_test_case_256_6);
10304 }
10305
10306 static int
10307 test_AES_GCM_auth_decryption_test_case_256_7(void)
10308 {
10309         return test_authenticated_decryption(&gcm_test_case_256_7);
10310 }
10311
10312 static int
10313 test_AES_GCM_auth_decryption_test_case_aad_1(void)
10314 {
10315         return test_authenticated_decryption(&gcm_test_case_aad_1);
10316 }
10317
10318 static int
10319 test_AES_GCM_auth_decryption_test_case_aad_2(void)
10320 {
10321         return test_authenticated_decryption(&gcm_test_case_aad_2);
10322 }
10323
10324 static int
10325 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
10326 {
10327         struct aead_test_data tdata;
10328         int res;
10329
10330         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10331         tdata.iv.data[0] += 1;
10332         res = test_authenticated_decryption(&tdata);
10333         if (res == TEST_SKIPPED)
10334                 return res;
10335         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10336         return TEST_SUCCESS;
10337 }
10338
10339 static int
10340 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
10341 {
10342         struct aead_test_data tdata;
10343         int res;
10344
10345         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10346         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10347         tdata.plaintext.data[0] += 1;
10348         res = test_authenticated_decryption(&tdata);
10349         if (res == TEST_SKIPPED)
10350                 return res;
10351         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10352         return TEST_SUCCESS;
10353 }
10354
10355 static int
10356 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
10357 {
10358         struct aead_test_data tdata;
10359         int res;
10360
10361         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10362         tdata.ciphertext.data[0] += 1;
10363         res = test_authenticated_decryption(&tdata);
10364         if (res == TEST_SKIPPED)
10365                 return res;
10366         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10367         return TEST_SUCCESS;
10368 }
10369
10370 static int
10371 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
10372 {
10373         struct aead_test_data tdata;
10374         int res;
10375
10376         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10377         tdata.aad.len += 1;
10378         res = test_authenticated_decryption(&tdata);
10379         if (res == TEST_SKIPPED)
10380                 return res;
10381         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10382         return TEST_SUCCESS;
10383 }
10384
10385 static int
10386 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
10387 {
10388         struct aead_test_data tdata;
10389         uint8_t aad[gcm_test_case_7.aad.len];
10390         int res;
10391
10392         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10393         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10394         aad[0] += 1;
10395         tdata.aad.data = aad;
10396         res = test_authenticated_decryption(&tdata);
10397         if (res == TEST_SKIPPED)
10398                 return res;
10399         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10400         return TEST_SUCCESS;
10401 }
10402
10403 static int
10404 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
10405 {
10406         struct aead_test_data tdata;
10407         int res;
10408
10409         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10410         tdata.auth_tag.data[0] += 1;
10411         res = test_authenticated_decryption(&tdata);
10412         if (res == TEST_SKIPPED)
10413                 return res;
10414         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
10415         return TEST_SUCCESS;
10416 }
10417
10418 static int
10419 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
10420 {
10421         struct crypto_testsuite_params *ts_params = &testsuite_params;
10422         struct crypto_unittest_params *ut_params = &unittest_params;
10423
10424         int retval;
10425         uint8_t *ciphertext, *auth_tag;
10426         uint16_t plaintext_pad_len;
10427
10428         /* Verify the capabilities */
10429         struct rte_cryptodev_sym_capability_idx cap_idx;
10430         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10431         cap_idx.algo.aead = tdata->algo;
10432         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10433                         &cap_idx) == NULL)
10434                 return TEST_SKIPPED;
10435
10436         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10437                 return TEST_SKIPPED;
10438
10439         /* not supported with CPU crypto */
10440         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10441                 return TEST_SKIPPED;
10442
10443         /* Create AEAD session */
10444         retval = create_aead_session(ts_params->valid_devs[0],
10445                         tdata->algo,
10446                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10447                         tdata->key.data, tdata->key.len,
10448                         tdata->aad.len, tdata->auth_tag.len,
10449                         tdata->iv.len);
10450         if (retval < 0)
10451                 return retval;
10452
10453         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10454         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10455
10456         /* clear mbuf payload */
10457         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10458                         rte_pktmbuf_tailroom(ut_params->ibuf));
10459         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10460                         rte_pktmbuf_tailroom(ut_params->obuf));
10461
10462         /* Create AEAD operation */
10463         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10464         if (retval < 0)
10465                 return retval;
10466
10467         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10468
10469         ut_params->op->sym->m_src = ut_params->ibuf;
10470         ut_params->op->sym->m_dst = ut_params->obuf;
10471
10472         /* Process crypto operation */
10473         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10474                         ut_params->op), "failed to process sym crypto op");
10475
10476         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10477                         "crypto op processing failed");
10478
10479         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10480
10481         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10482                         ut_params->op->sym->cipher.data.offset);
10483         auth_tag = ciphertext + plaintext_pad_len;
10484
10485         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10486         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10487
10488         /* Validate obuf */
10489         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10490                         ciphertext,
10491                         tdata->ciphertext.data,
10492                         tdata->ciphertext.len,
10493                         "Ciphertext data not as expected");
10494
10495         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10496                         auth_tag,
10497                         tdata->auth_tag.data,
10498                         tdata->auth_tag.len,
10499                         "Generated auth tag not as expected");
10500
10501         return 0;
10502
10503 }
10504
10505 static int
10506 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10507 {
10508         return test_authenticated_encryption_oop(&gcm_test_case_5);
10509 }
10510
10511 static int
10512 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10513 {
10514         struct crypto_testsuite_params *ts_params = &testsuite_params;
10515         struct crypto_unittest_params *ut_params = &unittest_params;
10516
10517         int retval;
10518         uint8_t *plaintext;
10519
10520         /* Verify the capabilities */
10521         struct rte_cryptodev_sym_capability_idx cap_idx;
10522         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10523         cap_idx.algo.aead = tdata->algo;
10524         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10525                         &cap_idx) == NULL)
10526                 return TEST_SKIPPED;
10527
10528         /* not supported with CPU crypto and raw data-path APIs*/
10529         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10530                         global_api_test_type == CRYPTODEV_RAW_API_TEST)
10531                 return TEST_SKIPPED;
10532
10533         /* Create AEAD session */
10534         retval = create_aead_session(ts_params->valid_devs[0],
10535                         tdata->algo,
10536                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10537                         tdata->key.data, tdata->key.len,
10538                         tdata->aad.len, tdata->auth_tag.len,
10539                         tdata->iv.len);
10540         if (retval < 0)
10541                 return retval;
10542
10543         /* alloc mbuf and set payload */
10544         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10545         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10546
10547         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10548                         rte_pktmbuf_tailroom(ut_params->ibuf));
10549         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10550                         rte_pktmbuf_tailroom(ut_params->obuf));
10551
10552         /* Create AEAD operation */
10553         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10554         if (retval < 0)
10555                 return retval;
10556
10557         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10558
10559         ut_params->op->sym->m_src = ut_params->ibuf;
10560         ut_params->op->sym->m_dst = ut_params->obuf;
10561
10562         /* Process crypto operation */
10563         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10564                         ut_params->op), "failed to process sym crypto op");
10565
10566         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10567                         "crypto op processing failed");
10568
10569         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10570                         ut_params->op->sym->cipher.data.offset);
10571
10572         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10573
10574         /* Validate obuf */
10575         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10576                         plaintext,
10577                         tdata->plaintext.data,
10578                         tdata->plaintext.len,
10579                         "Plaintext data not as expected");
10580
10581         TEST_ASSERT_EQUAL(ut_params->op->status,
10582                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10583                         "Authentication failed");
10584         return 0;
10585 }
10586
10587 static int
10588 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10589 {
10590         return test_authenticated_decryption_oop(&gcm_test_case_5);
10591 }
10592
10593 static int
10594 test_authenticated_encryption_sessionless(
10595                 const struct aead_test_data *tdata)
10596 {
10597         struct crypto_testsuite_params *ts_params = &testsuite_params;
10598         struct crypto_unittest_params *ut_params = &unittest_params;
10599
10600         int retval;
10601         uint8_t *ciphertext, *auth_tag;
10602         uint16_t plaintext_pad_len;
10603         uint8_t key[tdata->key.len + 1];
10604         struct rte_cryptodev_info dev_info;
10605
10606         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10607         uint64_t feat_flags = dev_info.feature_flags;
10608
10609         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10610                 printf("Device doesn't support Sessionless ops.\n");
10611                 return TEST_SKIPPED;
10612         }
10613
10614         /* not supported with CPU crypto */
10615         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10616                 return TEST_SKIPPED;
10617
10618         /* Verify the capabilities */
10619         struct rte_cryptodev_sym_capability_idx cap_idx;
10620         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10621         cap_idx.algo.aead = tdata->algo;
10622         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10623                         &cap_idx) == NULL)
10624                 return TEST_SKIPPED;
10625
10626         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10627
10628         /* clear mbuf payload */
10629         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10630                         rte_pktmbuf_tailroom(ut_params->ibuf));
10631
10632         /* Create AEAD operation */
10633         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10634         if (retval < 0)
10635                 return retval;
10636
10637         /* Create GCM xform */
10638         memcpy(key, tdata->key.data, tdata->key.len);
10639         retval = create_aead_xform(ut_params->op,
10640                         tdata->algo,
10641                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10642                         key, tdata->key.len,
10643                         tdata->aad.len, tdata->auth_tag.len,
10644                         tdata->iv.len);
10645         if (retval < 0)
10646                 return retval;
10647
10648         ut_params->op->sym->m_src = ut_params->ibuf;
10649
10650         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10651                         RTE_CRYPTO_OP_SESSIONLESS,
10652                         "crypto op session type not sessionless");
10653
10654         /* Process crypto operation */
10655         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10656                         ut_params->op), "failed to process sym crypto op");
10657
10658         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10659
10660         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10661                         "crypto op status not success");
10662
10663         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10664
10665         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10666                         ut_params->op->sym->cipher.data.offset);
10667         auth_tag = ciphertext + plaintext_pad_len;
10668
10669         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10670         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10671
10672         /* Validate obuf */
10673         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10674                         ciphertext,
10675                         tdata->ciphertext.data,
10676                         tdata->ciphertext.len,
10677                         "Ciphertext data not as expected");
10678
10679         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10680                         auth_tag,
10681                         tdata->auth_tag.data,
10682                         tdata->auth_tag.len,
10683                         "Generated auth tag not as expected");
10684
10685         return 0;
10686
10687 }
10688
10689 static int
10690 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10691 {
10692         return test_authenticated_encryption_sessionless(
10693                         &gcm_test_case_5);
10694 }
10695
10696 static int
10697 test_authenticated_decryption_sessionless(
10698                 const struct aead_test_data *tdata)
10699 {
10700         struct crypto_testsuite_params *ts_params = &testsuite_params;
10701         struct crypto_unittest_params *ut_params = &unittest_params;
10702
10703         int retval;
10704         uint8_t *plaintext;
10705         uint8_t key[tdata->key.len + 1];
10706         struct rte_cryptodev_info dev_info;
10707
10708         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10709         uint64_t feat_flags = dev_info.feature_flags;
10710
10711         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10712                 printf("Device doesn't support Sessionless ops.\n");
10713                 return TEST_SKIPPED;
10714         }
10715
10716         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10717                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10718                 printf("Device doesn't support RAW data-path APIs.\n");
10719                 return TEST_SKIPPED;
10720         }
10721
10722         /* not supported with CPU crypto */
10723         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10724                 return TEST_SKIPPED;
10725
10726         /* Verify the capabilities */
10727         struct rte_cryptodev_sym_capability_idx cap_idx;
10728         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10729         cap_idx.algo.aead = tdata->algo;
10730         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10731                         &cap_idx) == NULL)
10732                 return TEST_SKIPPED;
10733
10734         /* alloc mbuf and set payload */
10735         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10736
10737         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10738                         rte_pktmbuf_tailroom(ut_params->ibuf));
10739
10740         /* Create AEAD operation */
10741         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10742         if (retval < 0)
10743                 return retval;
10744
10745         /* Create AEAD xform */
10746         memcpy(key, tdata->key.data, tdata->key.len);
10747         retval = create_aead_xform(ut_params->op,
10748                         tdata->algo,
10749                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10750                         key, tdata->key.len,
10751                         tdata->aad.len, tdata->auth_tag.len,
10752                         tdata->iv.len);
10753         if (retval < 0)
10754                 return retval;
10755
10756         ut_params->op->sym->m_src = ut_params->ibuf;
10757
10758         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10759                         RTE_CRYPTO_OP_SESSIONLESS,
10760                         "crypto op session type not sessionless");
10761
10762         /* Process crypto operation */
10763         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10764                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10765                                 ut_params->op, 0, 0, 0, 0);
10766         else
10767                 TEST_ASSERT_NOT_NULL(process_crypto_request(
10768                         ts_params->valid_devs[0], ut_params->op),
10769                                 "failed to process sym crypto op");
10770
10771         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10772
10773         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10774                         "crypto op status not success");
10775
10776         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10777                         ut_params->op->sym->cipher.data.offset);
10778
10779         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10780
10781         /* Validate obuf */
10782         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10783                         plaintext,
10784                         tdata->plaintext.data,
10785                         tdata->plaintext.len,
10786                         "Plaintext data not as expected");
10787
10788         TEST_ASSERT_EQUAL(ut_params->op->status,
10789                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10790                         "Authentication failed");
10791         return 0;
10792 }
10793
10794 static int
10795 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
10796 {
10797         return test_authenticated_decryption_sessionless(
10798                         &gcm_test_case_5);
10799 }
10800
10801 static int
10802 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
10803 {
10804         return test_authenticated_encryption(&ccm_test_case_128_1);
10805 }
10806
10807 static int
10808 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
10809 {
10810         return test_authenticated_encryption(&ccm_test_case_128_2);
10811 }
10812
10813 static int
10814 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
10815 {
10816         return test_authenticated_encryption(&ccm_test_case_128_3);
10817 }
10818
10819 static int
10820 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
10821 {
10822         return test_authenticated_decryption(&ccm_test_case_128_1);
10823 }
10824
10825 static int
10826 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
10827 {
10828         return test_authenticated_decryption(&ccm_test_case_128_2);
10829 }
10830
10831 static int
10832 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10833 {
10834         return test_authenticated_decryption(&ccm_test_case_128_3);
10835 }
10836
10837 static int
10838 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10839 {
10840         return test_authenticated_encryption(&ccm_test_case_192_1);
10841 }
10842
10843 static int
10844 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10845 {
10846         return test_authenticated_encryption(&ccm_test_case_192_2);
10847 }
10848
10849 static int
10850 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10851 {
10852         return test_authenticated_encryption(&ccm_test_case_192_3);
10853 }
10854
10855 static int
10856 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10857 {
10858         return test_authenticated_decryption(&ccm_test_case_192_1);
10859 }
10860
10861 static int
10862 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10863 {
10864         return test_authenticated_decryption(&ccm_test_case_192_2);
10865 }
10866
10867 static int
10868 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10869 {
10870         return test_authenticated_decryption(&ccm_test_case_192_3);
10871 }
10872
10873 static int
10874 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
10875 {
10876         return test_authenticated_encryption(&ccm_test_case_256_1);
10877 }
10878
10879 static int
10880 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
10881 {
10882         return test_authenticated_encryption(&ccm_test_case_256_2);
10883 }
10884
10885 static int
10886 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
10887 {
10888         return test_authenticated_encryption(&ccm_test_case_256_3);
10889 }
10890
10891 static int
10892 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
10893 {
10894         return test_authenticated_decryption(&ccm_test_case_256_1);
10895 }
10896
10897 static int
10898 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
10899 {
10900         return test_authenticated_decryption(&ccm_test_case_256_2);
10901 }
10902
10903 static int
10904 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
10905 {
10906         return test_authenticated_decryption(&ccm_test_case_256_3);
10907 }
10908
10909 static int
10910 test_stats(void)
10911 {
10912         struct crypto_testsuite_params *ts_params = &testsuite_params;
10913         struct rte_cryptodev_stats stats;
10914
10915         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10916                 return TEST_SKIPPED;
10917
10918         /* Verify the capabilities */
10919         struct rte_cryptodev_sym_capability_idx cap_idx;
10920         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10921         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
10922         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10923                         &cap_idx) == NULL)
10924                 return TEST_SKIPPED;
10925         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10926         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10927         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10928                         &cap_idx) == NULL)
10929                 return TEST_SKIPPED;
10930
10931         if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
10932                         == -ENOTSUP)
10933                 return TEST_SKIPPED;
10934
10935         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10936         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
10937                         &stats) == -ENODEV),
10938                 "rte_cryptodev_stats_get invalid dev failed");
10939         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
10940                 "rte_cryptodev_stats_get invalid Param failed");
10941
10942         /* Test expected values */
10943         test_AES_CBC_HMAC_SHA1_encrypt_digest();
10944         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10945                         &stats),
10946                 "rte_cryptodev_stats_get failed");
10947         TEST_ASSERT((stats.enqueued_count == 1),
10948                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10949         TEST_ASSERT((stats.dequeued_count == 1),
10950                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10951         TEST_ASSERT((stats.enqueue_err_count == 0),
10952                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10953         TEST_ASSERT((stats.dequeue_err_count == 0),
10954                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10955
10956         /* invalid device but should ignore and not reset device stats*/
10957         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
10958         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10959                         &stats),
10960                 "rte_cryptodev_stats_get failed");
10961         TEST_ASSERT((stats.enqueued_count == 1),
10962                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10963
10964         /* check that a valid reset clears stats */
10965         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10966         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10967                         &stats),
10968                                           "rte_cryptodev_stats_get failed");
10969         TEST_ASSERT((stats.enqueued_count == 0),
10970                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10971         TEST_ASSERT((stats.dequeued_count == 0),
10972                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10973
10974         return TEST_SUCCESS;
10975 }
10976
10977 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
10978                                    struct crypto_unittest_params *ut_params,
10979                                    enum rte_crypto_auth_operation op,
10980                                    const struct HMAC_MD5_vector *test_case)
10981 {
10982         uint8_t key[64];
10983
10984         memcpy(key, test_case->key.data, test_case->key.len);
10985
10986         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10987         ut_params->auth_xform.next = NULL;
10988         ut_params->auth_xform.auth.op = op;
10989
10990         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
10991
10992         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
10993         ut_params->auth_xform.auth.key.length = test_case->key.len;
10994         ut_params->auth_xform.auth.key.data = key;
10995
10996         ut_params->sess = rte_cryptodev_sym_session_create(
10997                         ts_params->session_mpool);
10998
10999         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11000                         ut_params->sess, &ut_params->auth_xform,
11001                         ts_params->session_priv_mpool);
11002
11003         if (ut_params->sess == NULL)
11004                 return TEST_FAILED;
11005
11006         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11007
11008         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11009                         rte_pktmbuf_tailroom(ut_params->ibuf));
11010
11011         return 0;
11012 }
11013
11014 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
11015                               const struct HMAC_MD5_vector *test_case,
11016                               uint8_t **plaintext)
11017 {
11018         uint16_t plaintext_pad_len;
11019
11020         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11021
11022         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11023                                 16);
11024
11025         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11026                         plaintext_pad_len);
11027         memcpy(*plaintext, test_case->plaintext.data,
11028                         test_case->plaintext.len);
11029
11030         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11031                         ut_params->ibuf, MD5_DIGEST_LEN);
11032         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11033                         "no room to append digest");
11034         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11035                         ut_params->ibuf, plaintext_pad_len);
11036
11037         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11038                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
11039                            test_case->auth_tag.len);
11040         }
11041
11042         sym_op->auth.data.offset = 0;
11043         sym_op->auth.data.length = test_case->plaintext.len;
11044
11045         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11046         ut_params->op->sym->m_src = ut_params->ibuf;
11047
11048         return 0;
11049 }
11050
11051 static int
11052 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
11053 {
11054         uint16_t plaintext_pad_len;
11055         uint8_t *plaintext, *auth_tag;
11056
11057         struct crypto_testsuite_params *ts_params = &testsuite_params;
11058         struct crypto_unittest_params *ut_params = &unittest_params;
11059         struct rte_cryptodev_info dev_info;
11060
11061         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11062         uint64_t feat_flags = dev_info.feature_flags;
11063
11064         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11065                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11066                 printf("Device doesn't support RAW data-path APIs.\n");
11067                 return TEST_SKIPPED;
11068         }
11069
11070         /* Verify the capabilities */
11071         struct rte_cryptodev_sym_capability_idx cap_idx;
11072         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11073         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11074         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11075                         &cap_idx) == NULL)
11076                 return TEST_SKIPPED;
11077
11078         if (MD5_HMAC_create_session(ts_params, ut_params,
11079                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
11080                 return TEST_FAILED;
11081
11082         /* Generate Crypto op data structure */
11083         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11084                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11085         TEST_ASSERT_NOT_NULL(ut_params->op,
11086                         "Failed to allocate symmetric crypto operation struct");
11087
11088         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11089                                 16);
11090
11091         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11092                 return TEST_FAILED;
11093
11094         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11095                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11096                         ut_params->op);
11097         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11098                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11099                                 ut_params->op, 0, 1, 0, 0);
11100         else
11101                 TEST_ASSERT_NOT_NULL(
11102                         process_crypto_request(ts_params->valid_devs[0],
11103                                 ut_params->op),
11104                                 "failed to process sym crypto op");
11105
11106         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11107                         "crypto op processing failed");
11108
11109         if (ut_params->op->sym->m_dst) {
11110                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11111                                 uint8_t *, plaintext_pad_len);
11112         } else {
11113                 auth_tag = plaintext + plaintext_pad_len;
11114         }
11115
11116         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11117                         auth_tag,
11118                         test_case->auth_tag.data,
11119                         test_case->auth_tag.len,
11120                         "HMAC_MD5 generated tag not as expected");
11121
11122         return TEST_SUCCESS;
11123 }
11124
11125 static int
11126 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
11127 {
11128         uint8_t *plaintext;
11129
11130         struct crypto_testsuite_params *ts_params = &testsuite_params;
11131         struct crypto_unittest_params *ut_params = &unittest_params;
11132         struct rte_cryptodev_info dev_info;
11133
11134         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11135         uint64_t feat_flags = dev_info.feature_flags;
11136
11137         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11138                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11139                 printf("Device doesn't support RAW data-path APIs.\n");
11140                 return TEST_SKIPPED;
11141         }
11142
11143         /* Verify the capabilities */
11144         struct rte_cryptodev_sym_capability_idx cap_idx;
11145         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11146         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11147         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11148                         &cap_idx) == NULL)
11149                 return TEST_SKIPPED;
11150
11151         if (MD5_HMAC_create_session(ts_params, ut_params,
11152                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
11153                 return TEST_FAILED;
11154         }
11155
11156         /* Generate Crypto op data structure */
11157         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11158                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11159         TEST_ASSERT_NOT_NULL(ut_params->op,
11160                         "Failed to allocate symmetric crypto operation struct");
11161
11162         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11163                 return TEST_FAILED;
11164
11165         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11166                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11167                         ut_params->op);
11168         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11169                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11170                                 ut_params->op, 0, 1, 0, 0);
11171         else
11172                 TEST_ASSERT_NOT_NULL(
11173                         process_crypto_request(ts_params->valid_devs[0],
11174                                 ut_params->op),
11175                                 "failed to process sym crypto op");
11176
11177         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11178                         "HMAC_MD5 crypto op processing failed");
11179
11180         return TEST_SUCCESS;
11181 }
11182
11183 static int
11184 test_MD5_HMAC_generate_case_1(void)
11185 {
11186         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
11187 }
11188
11189 static int
11190 test_MD5_HMAC_verify_case_1(void)
11191 {
11192         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
11193 }
11194
11195 static int
11196 test_MD5_HMAC_generate_case_2(void)
11197 {
11198         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
11199 }
11200
11201 static int
11202 test_MD5_HMAC_verify_case_2(void)
11203 {
11204         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
11205 }
11206
11207 static int
11208 test_multi_session(void)
11209 {
11210         struct crypto_testsuite_params *ts_params = &testsuite_params;
11211         struct crypto_unittest_params *ut_params = &unittest_params;
11212
11213         struct rte_cryptodev_info dev_info;
11214         struct rte_cryptodev_sym_session **sessions;
11215
11216         uint16_t i;
11217
11218         /* Verify the capabilities */
11219         struct rte_cryptodev_sym_capability_idx cap_idx;
11220         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11221         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11222         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11223                         &cap_idx) == NULL)
11224                 return TEST_SKIPPED;
11225         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11226         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11227         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11228                         &cap_idx) == NULL)
11229                 return TEST_SKIPPED;
11230
11231         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
11232                         aes_cbc_key, hmac_sha512_key);
11233
11234
11235         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11236
11237         sessions = rte_malloc(NULL,
11238                         sizeof(struct rte_cryptodev_sym_session *) *
11239                         (MAX_NB_SESSIONS + 1), 0);
11240
11241         /* Create multiple crypto sessions*/
11242         for (i = 0; i < MAX_NB_SESSIONS; i++) {
11243
11244                 sessions[i] = rte_cryptodev_sym_session_create(
11245                                 ts_params->session_mpool);
11246
11247                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11248                                 sessions[i], &ut_params->auth_xform,
11249                                 ts_params->session_priv_mpool);
11250                 TEST_ASSERT_NOT_NULL(sessions[i],
11251                                 "Session creation failed at session number %u",
11252                                 i);
11253
11254                 /* Attempt to send a request on each session */
11255                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
11256                         sessions[i],
11257                         ut_params,
11258                         ts_params,
11259                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
11260                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
11261                         aes_cbc_iv),
11262                         "Failed to perform decrypt on request number %u.", i);
11263                 /* free crypto operation structure */
11264                 if (ut_params->op)
11265                         rte_crypto_op_free(ut_params->op);
11266
11267                 /*
11268                  * free mbuf - both obuf and ibuf are usually the same,
11269                  * so check if they point at the same address is necessary,
11270                  * to avoid freeing the mbuf twice.
11271                  */
11272                 if (ut_params->obuf) {
11273                         rte_pktmbuf_free(ut_params->obuf);
11274                         if (ut_params->ibuf == ut_params->obuf)
11275                                 ut_params->ibuf = 0;
11276                         ut_params->obuf = 0;
11277                 }
11278                 if (ut_params->ibuf) {
11279                         rte_pktmbuf_free(ut_params->ibuf);
11280                         ut_params->ibuf = 0;
11281                 }
11282         }
11283
11284         sessions[i] = NULL;
11285         /* Next session create should fail */
11286         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11287                         sessions[i], &ut_params->auth_xform,
11288                         ts_params->session_priv_mpool);
11289         TEST_ASSERT_NULL(sessions[i],
11290                         "Session creation succeeded unexpectedly!");
11291
11292         for (i = 0; i < MAX_NB_SESSIONS; i++) {
11293                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11294                                 sessions[i]);
11295                 rte_cryptodev_sym_session_free(sessions[i]);
11296         }
11297
11298         rte_free(sessions);
11299
11300         return TEST_SUCCESS;
11301 }
11302
11303 struct multi_session_params {
11304         struct crypto_unittest_params ut_params;
11305         uint8_t *cipher_key;
11306         uint8_t *hmac_key;
11307         const uint8_t *cipher;
11308         const uint8_t *digest;
11309         uint8_t *iv;
11310 };
11311
11312 #define MB_SESSION_NUMBER 3
11313
11314 static int
11315 test_multi_session_random_usage(void)
11316 {
11317         struct crypto_testsuite_params *ts_params = &testsuite_params;
11318         struct rte_cryptodev_info dev_info;
11319         struct rte_cryptodev_sym_session **sessions;
11320         uint32_t i, j;
11321         struct multi_session_params ut_paramz[] = {
11322
11323                 {
11324                         .cipher_key = ms_aes_cbc_key0,
11325                         .hmac_key = ms_hmac_key0,
11326                         .cipher = ms_aes_cbc_cipher0,
11327                         .digest = ms_hmac_digest0,
11328                         .iv = ms_aes_cbc_iv0
11329                 },
11330                 {
11331                         .cipher_key = ms_aes_cbc_key1,
11332                         .hmac_key = ms_hmac_key1,
11333                         .cipher = ms_aes_cbc_cipher1,
11334                         .digest = ms_hmac_digest1,
11335                         .iv = ms_aes_cbc_iv1
11336                 },
11337                 {
11338                         .cipher_key = ms_aes_cbc_key2,
11339                         .hmac_key = ms_hmac_key2,
11340                         .cipher = ms_aes_cbc_cipher2,
11341                         .digest = ms_hmac_digest2,
11342                         .iv = ms_aes_cbc_iv2
11343                 },
11344
11345         };
11346
11347         /* Verify the capabilities */
11348         struct rte_cryptodev_sym_capability_idx cap_idx;
11349         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11350         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11351         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11352                         &cap_idx) == NULL)
11353                 return TEST_SKIPPED;
11354         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11355         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11356         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11357                         &cap_idx) == NULL)
11358                 return TEST_SKIPPED;
11359
11360         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11361
11362         sessions = rte_malloc(NULL,
11363                         (sizeof(struct rte_cryptodev_sym_session *)
11364                                         * MAX_NB_SESSIONS) + 1, 0);
11365
11366         for (i = 0; i < MB_SESSION_NUMBER; i++) {
11367                 sessions[i] = rte_cryptodev_sym_session_create(
11368                                 ts_params->session_mpool);
11369
11370                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
11371                                 sizeof(struct crypto_unittest_params));
11372
11373                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
11374                                 &ut_paramz[i].ut_params,
11375                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
11376
11377                 /* Create multiple crypto sessions*/
11378                 rte_cryptodev_sym_session_init(
11379                                 ts_params->valid_devs[0],
11380                                 sessions[i],
11381                                 &ut_paramz[i].ut_params.auth_xform,
11382                                 ts_params->session_priv_mpool);
11383
11384                 TEST_ASSERT_NOT_NULL(sessions[i],
11385                                 "Session creation failed at session number %u",
11386                                 i);
11387
11388         }
11389
11390         srand(time(NULL));
11391         for (i = 0; i < 40000; i++) {
11392
11393                 j = rand() % MB_SESSION_NUMBER;
11394
11395                 TEST_ASSERT_SUCCESS(
11396                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
11397                                         sessions[j],
11398                                         &ut_paramz[j].ut_params,
11399                                         ts_params, ut_paramz[j].cipher,
11400                                         ut_paramz[j].digest,
11401                                         ut_paramz[j].iv),
11402                         "Failed to perform decrypt on request number %u.", i);
11403
11404                 if (ut_paramz[j].ut_params.op)
11405                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
11406
11407                 /*
11408                  * free mbuf - both obuf and ibuf are usually the same,
11409                  * so check if they point at the same address is necessary,
11410                  * to avoid freeing the mbuf twice.
11411                  */
11412                 if (ut_paramz[j].ut_params.obuf) {
11413                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
11414                         if (ut_paramz[j].ut_params.ibuf
11415                                         == ut_paramz[j].ut_params.obuf)
11416                                 ut_paramz[j].ut_params.ibuf = 0;
11417                         ut_paramz[j].ut_params.obuf = 0;
11418                 }
11419                 if (ut_paramz[j].ut_params.ibuf) {
11420                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
11421                         ut_paramz[j].ut_params.ibuf = 0;
11422                 }
11423         }
11424
11425         for (i = 0; i < MB_SESSION_NUMBER; i++) {
11426                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11427                                 sessions[i]);
11428                 rte_cryptodev_sym_session_free(sessions[i]);
11429         }
11430
11431         rte_free(sessions);
11432
11433         return TEST_SUCCESS;
11434 }
11435
11436 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
11437                         0xab, 0xab, 0xab, 0xab,
11438                         0xab, 0xab, 0xab, 0xab,
11439                         0xab, 0xab, 0xab, 0xab};
11440
11441 static int
11442 test_null_invalid_operation(void)
11443 {
11444         struct crypto_testsuite_params *ts_params = &testsuite_params;
11445         struct crypto_unittest_params *ut_params = &unittest_params;
11446         int ret;
11447
11448         /* This test is for NULL PMD only */
11449         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11450                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11451                 return TEST_SKIPPED;
11452
11453         /* Setup Cipher Parameters */
11454         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11455         ut_params->cipher_xform.next = NULL;
11456
11457         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
11458         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11459
11460         ut_params->sess = rte_cryptodev_sym_session_create(
11461                         ts_params->session_mpool);
11462
11463         /* Create Crypto session*/
11464         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11465                         ut_params->sess, &ut_params->cipher_xform,
11466                         ts_params->session_priv_mpool);
11467         TEST_ASSERT(ret < 0,
11468                         "Session creation succeeded unexpectedly");
11469
11470
11471         /* Setup HMAC Parameters */
11472         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11473         ut_params->auth_xform.next = NULL;
11474
11475         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
11476         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11477
11478         ut_params->sess = rte_cryptodev_sym_session_create(
11479                         ts_params->session_mpool);
11480
11481         /* Create Crypto session*/
11482         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11483                         ut_params->sess, &ut_params->auth_xform,
11484                         ts_params->session_priv_mpool);
11485         TEST_ASSERT(ret < 0,
11486                         "Session creation succeeded unexpectedly");
11487
11488         return TEST_SUCCESS;
11489 }
11490
11491
11492 #define NULL_BURST_LENGTH (32)
11493
11494 static int
11495 test_null_burst_operation(void)
11496 {
11497         struct crypto_testsuite_params *ts_params = &testsuite_params;
11498         struct crypto_unittest_params *ut_params = &unittest_params;
11499
11500         unsigned i, burst_len = NULL_BURST_LENGTH;
11501
11502         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11503         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11504
11505         /* This test is for NULL PMD only */
11506         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11507                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11508                 return TEST_SKIPPED;
11509
11510         /* Setup Cipher Parameters */
11511         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11512         ut_params->cipher_xform.next = &ut_params->auth_xform;
11513
11514         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11515         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11516
11517         /* Setup HMAC Parameters */
11518         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11519         ut_params->auth_xform.next = NULL;
11520
11521         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11522         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11523
11524         ut_params->sess = rte_cryptodev_sym_session_create(
11525                         ts_params->session_mpool);
11526
11527         /* Create Crypto session*/
11528         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11529                         ut_params->sess, &ut_params->cipher_xform,
11530                         ts_params->session_priv_mpool);
11531         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11532
11533         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11534                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11535                         burst_len, "failed to generate burst of crypto ops");
11536
11537         /* Generate an operation for each mbuf in burst */
11538         for (i = 0; i < burst_len; i++) {
11539                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11540
11541                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11542
11543                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11544                                 sizeof(unsigned));
11545                 *data = i;
11546
11547                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11548
11549                 burst[i]->sym->m_src = m;
11550         }
11551
11552         /* Process crypto operation */
11553         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11554                         0, burst, burst_len),
11555                         burst_len,
11556                         "Error enqueuing burst");
11557
11558         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11559                         0, burst_dequeued, burst_len),
11560                         burst_len,
11561                         "Error dequeuing burst");
11562
11563
11564         for (i = 0; i < burst_len; i++) {
11565                 TEST_ASSERT_EQUAL(
11566                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11567                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11568                                         uint32_t *),
11569                         "data not as expected");
11570
11571                 rte_pktmbuf_free(burst[i]->sym->m_src);
11572                 rte_crypto_op_free(burst[i]);
11573         }
11574
11575         return TEST_SUCCESS;
11576 }
11577
11578 static uint16_t
11579 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11580                   uint16_t nb_ops, void *user_param)
11581 {
11582         RTE_SET_USED(dev_id);
11583         RTE_SET_USED(qp_id);
11584         RTE_SET_USED(ops);
11585         RTE_SET_USED(user_param);
11586
11587         printf("crypto enqueue callback called\n");
11588         return nb_ops;
11589 }
11590
11591 static uint16_t
11592 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11593                   uint16_t nb_ops, void *user_param)
11594 {
11595         RTE_SET_USED(dev_id);
11596         RTE_SET_USED(qp_id);
11597         RTE_SET_USED(ops);
11598         RTE_SET_USED(user_param);
11599
11600         printf("crypto dequeue callback called\n");
11601         return nb_ops;
11602 }
11603
11604 /*
11605  * Thread using enqueue/dequeue callback with RCU.
11606  */
11607 static int
11608 test_enqdeq_callback_thread(void *arg)
11609 {
11610         RTE_SET_USED(arg);
11611         /* DP thread calls rte_cryptodev_enqueue_burst()/
11612          * rte_cryptodev_dequeue_burst() and invokes callback.
11613          */
11614         test_null_burst_operation();
11615         return 0;
11616 }
11617
11618 static int
11619 test_enq_callback_setup(void)
11620 {
11621         struct crypto_testsuite_params *ts_params = &testsuite_params;
11622         struct rte_cryptodev_info dev_info;
11623         struct rte_cryptodev_qp_conf qp_conf = {
11624                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11625         };
11626
11627         struct rte_cryptodev_cb *cb;
11628         uint16_t qp_id = 0;
11629
11630         /* Stop the device in case it's started so it can be configured */
11631         rte_cryptodev_stop(ts_params->valid_devs[0]);
11632
11633         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11634
11635         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11636                         &ts_params->conf),
11637                         "Failed to configure cryptodev %u",
11638                         ts_params->valid_devs[0]);
11639
11640         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11641         qp_conf.mp_session = ts_params->session_mpool;
11642         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11643
11644         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11645                         ts_params->valid_devs[0], qp_id, &qp_conf,
11646                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11647                         "Failed test for "
11648                         "rte_cryptodev_queue_pair_setup: num_inflights "
11649                         "%u on qp %u on cryptodev %u",
11650                         qp_conf.nb_descriptors, qp_id,
11651                         ts_params->valid_devs[0]);
11652
11653         /* Test with invalid crypto device */
11654         cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11655                         qp_id, test_enq_callback, NULL);
11656         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11657                         "cryptodev %u did not fail",
11658                         qp_id, RTE_CRYPTO_MAX_DEVS);
11659
11660         /* Test with invalid queue pair */
11661         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11662                         dev_info.max_nb_queue_pairs + 1,
11663                         test_enq_callback, NULL);
11664         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11665                         "cryptodev %u did not fail",
11666                         dev_info.max_nb_queue_pairs + 1,
11667                         ts_params->valid_devs[0]);
11668
11669         /* Test with NULL callback */
11670         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11671                         qp_id, NULL, NULL);
11672         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11673                         "cryptodev %u did not fail",
11674                         qp_id, ts_params->valid_devs[0]);
11675
11676         /* Test with valid configuration */
11677         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11678                         qp_id, test_enq_callback, NULL);
11679         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11680                         "qp %u on cryptodev %u",
11681                         qp_id, ts_params->valid_devs[0]);
11682
11683         rte_cryptodev_start(ts_params->valid_devs[0]);
11684
11685         /* Launch a thread */
11686         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11687                                 rte_get_next_lcore(-1, 1, 0));
11688
11689         /* Wait until reader exited. */
11690         rte_eal_mp_wait_lcore();
11691
11692         /* Test with invalid crypto device */
11693         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11694                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11695                         "Expected call to fail as crypto device is invalid");
11696
11697         /* Test with invalid queue pair */
11698         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11699                         ts_params->valid_devs[0],
11700                         dev_info.max_nb_queue_pairs + 1, cb),
11701                         "Expected call to fail as queue pair is invalid");
11702
11703         /* Test with NULL callback */
11704         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11705                         ts_params->valid_devs[0], qp_id, NULL),
11706                         "Expected call to fail as callback is NULL");
11707
11708         /* Test with valid configuration */
11709         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11710                         ts_params->valid_devs[0], qp_id, cb),
11711                         "Failed test to remove callback on "
11712                         "qp %u on cryptodev %u",
11713                         qp_id, ts_params->valid_devs[0]);
11714
11715         return TEST_SUCCESS;
11716 }
11717
11718 static int
11719 test_deq_callback_setup(void)
11720 {
11721         struct crypto_testsuite_params *ts_params = &testsuite_params;
11722         struct rte_cryptodev_info dev_info;
11723         struct rte_cryptodev_qp_conf qp_conf = {
11724                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11725         };
11726
11727         struct rte_cryptodev_cb *cb;
11728         uint16_t qp_id = 0;
11729
11730         /* Stop the device in case it's started so it can be configured */
11731         rte_cryptodev_stop(ts_params->valid_devs[0]);
11732
11733         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11734
11735         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11736                         &ts_params->conf),
11737                         "Failed to configure cryptodev %u",
11738                         ts_params->valid_devs[0]);
11739
11740         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11741         qp_conf.mp_session = ts_params->session_mpool;
11742         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11743
11744         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11745                         ts_params->valid_devs[0], qp_id, &qp_conf,
11746                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11747                         "Failed test for "
11748                         "rte_cryptodev_queue_pair_setup: num_inflights "
11749                         "%u on qp %u on cryptodev %u",
11750                         qp_conf.nb_descriptors, qp_id,
11751                         ts_params->valid_devs[0]);
11752
11753         /* Test with invalid crypto device */
11754         cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11755                         qp_id, test_deq_callback, NULL);
11756         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11757                         "cryptodev %u did not fail",
11758                         qp_id, RTE_CRYPTO_MAX_DEVS);
11759
11760         /* Test with invalid queue pair */
11761         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11762                         dev_info.max_nb_queue_pairs + 1,
11763                         test_deq_callback, NULL);
11764         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11765                         "cryptodev %u did not fail",
11766                         dev_info.max_nb_queue_pairs + 1,
11767                         ts_params->valid_devs[0]);
11768
11769         /* Test with NULL callback */
11770         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11771                         qp_id, NULL, NULL);
11772         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11773                         "cryptodev %u did not fail",
11774                         qp_id, ts_params->valid_devs[0]);
11775
11776         /* Test with valid configuration */
11777         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11778                         qp_id, test_deq_callback, NULL);
11779         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11780                         "qp %u on cryptodev %u",
11781                         qp_id, ts_params->valid_devs[0]);
11782
11783         rte_cryptodev_start(ts_params->valid_devs[0]);
11784
11785         /* Launch a thread */
11786         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11787                                 rte_get_next_lcore(-1, 1, 0));
11788
11789         /* Wait until reader exited. */
11790         rte_eal_mp_wait_lcore();
11791
11792         /* Test with invalid crypto device */
11793         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11794                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11795                         "Expected call to fail as crypto device is invalid");
11796
11797         /* Test with invalid queue pair */
11798         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11799                         ts_params->valid_devs[0],
11800                         dev_info.max_nb_queue_pairs + 1, cb),
11801                         "Expected call to fail as queue pair is invalid");
11802
11803         /* Test with NULL callback */
11804         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11805                         ts_params->valid_devs[0], qp_id, NULL),
11806                         "Expected call to fail as callback is NULL");
11807
11808         /* Test with valid configuration */
11809         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
11810                         ts_params->valid_devs[0], qp_id, cb),
11811                         "Failed test to remove callback on "
11812                         "qp %u on cryptodev %u",
11813                         qp_id, ts_params->valid_devs[0]);
11814
11815         return TEST_SUCCESS;
11816 }
11817
11818 static void
11819 generate_gmac_large_plaintext(uint8_t *data)
11820 {
11821         uint16_t i;
11822
11823         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
11824                 memcpy(&data[i], &data[0], 32);
11825 }
11826
11827 static int
11828 create_gmac_operation(enum rte_crypto_auth_operation op,
11829                 const struct gmac_test_data *tdata)
11830 {
11831         struct crypto_testsuite_params *ts_params = &testsuite_params;
11832         struct crypto_unittest_params *ut_params = &unittest_params;
11833         struct rte_crypto_sym_op *sym_op;
11834
11835         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11836
11837         /* Generate Crypto op data structure */
11838         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11839                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11840         TEST_ASSERT_NOT_NULL(ut_params->op,
11841                         "Failed to allocate symmetric crypto operation struct");
11842
11843         sym_op = ut_params->op->sym;
11844
11845         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11846                         ut_params->ibuf, tdata->gmac_tag.len);
11847         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11848                         "no room to append digest");
11849
11850         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11851                         ut_params->ibuf, plaintext_pad_len);
11852
11853         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11854                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11855                                 tdata->gmac_tag.len);
11856                 debug_hexdump(stdout, "digest:",
11857                                 sym_op->auth.digest.data,
11858                                 tdata->gmac_tag.len);
11859         }
11860
11861         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11862                         uint8_t *, IV_OFFSET);
11863
11864         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11865
11866         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11867
11868         sym_op->cipher.data.length = 0;
11869         sym_op->cipher.data.offset = 0;
11870
11871         sym_op->auth.data.offset = 0;
11872         sym_op->auth.data.length = tdata->plaintext.len;
11873
11874         return 0;
11875 }
11876
11877 static int
11878 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
11879                 const struct gmac_test_data *tdata,
11880                 void *digest_mem, uint64_t digest_phys)
11881 {
11882         struct crypto_testsuite_params *ts_params = &testsuite_params;
11883         struct crypto_unittest_params *ut_params = &unittest_params;
11884         struct rte_crypto_sym_op *sym_op;
11885
11886         /* Generate Crypto op data structure */
11887         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11888                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11889         TEST_ASSERT_NOT_NULL(ut_params->op,
11890                         "Failed to allocate symmetric crypto operation struct");
11891
11892         sym_op = ut_params->op->sym;
11893
11894         sym_op->auth.digest.data = digest_mem;
11895         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11896                         "no room to append digest");
11897
11898         sym_op->auth.digest.phys_addr = digest_phys;
11899
11900         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11901                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11902                                 tdata->gmac_tag.len);
11903                 debug_hexdump(stdout, "digest:",
11904                                 sym_op->auth.digest.data,
11905                                 tdata->gmac_tag.len);
11906         }
11907
11908         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11909                         uint8_t *, IV_OFFSET);
11910
11911         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11912
11913         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11914
11915         sym_op->cipher.data.length = 0;
11916         sym_op->cipher.data.offset = 0;
11917
11918         sym_op->auth.data.offset = 0;
11919         sym_op->auth.data.length = tdata->plaintext.len;
11920
11921         return 0;
11922 }
11923
11924 static int create_gmac_session(uint8_t dev_id,
11925                 const struct gmac_test_data *tdata,
11926                 enum rte_crypto_auth_operation auth_op)
11927 {
11928         uint8_t auth_key[tdata->key.len];
11929
11930         struct crypto_testsuite_params *ts_params = &testsuite_params;
11931         struct crypto_unittest_params *ut_params = &unittest_params;
11932
11933         memcpy(auth_key, tdata->key.data, tdata->key.len);
11934
11935         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11936         ut_params->auth_xform.next = NULL;
11937
11938         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
11939         ut_params->auth_xform.auth.op = auth_op;
11940         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
11941         ut_params->auth_xform.auth.key.length = tdata->key.len;
11942         ut_params->auth_xform.auth.key.data = auth_key;
11943         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11944         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
11945
11946
11947         ut_params->sess = rte_cryptodev_sym_session_create(
11948                         ts_params->session_mpool);
11949
11950         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11951                         &ut_params->auth_xform,
11952                         ts_params->session_priv_mpool);
11953
11954         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11955
11956         return 0;
11957 }
11958
11959 static int
11960 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
11961 {
11962         struct crypto_testsuite_params *ts_params = &testsuite_params;
11963         struct crypto_unittest_params *ut_params = &unittest_params;
11964         struct rte_cryptodev_info dev_info;
11965
11966         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11967         uint64_t feat_flags = dev_info.feature_flags;
11968
11969         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11970                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11971                 printf("Device doesn't support RAW data-path APIs.\n");
11972                 return TEST_SKIPPED;
11973         }
11974
11975         int retval;
11976
11977         uint8_t *auth_tag, *plaintext;
11978         uint16_t plaintext_pad_len;
11979
11980         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11981                               "No GMAC length in the source data");
11982
11983         /* Verify the capabilities */
11984         struct rte_cryptodev_sym_capability_idx cap_idx;
11985         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11986         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11987         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11988                         &cap_idx) == NULL)
11989                 return TEST_SKIPPED;
11990
11991         retval = create_gmac_session(ts_params->valid_devs[0],
11992                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11993
11994         if (retval < 0)
11995                 return retval;
11996
11997         if (tdata->plaintext.len > MBUF_SIZE)
11998                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11999         else
12000                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12001         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12002                         "Failed to allocate input buffer in mempool");
12003
12004         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12005                         rte_pktmbuf_tailroom(ut_params->ibuf));
12006
12007         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12008         /*
12009          * Runtime generate the large plain text instead of use hard code
12010          * plain text vector. It is done to avoid create huge source file
12011          * with the test vector.
12012          */
12013         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12014                 generate_gmac_large_plaintext(tdata->plaintext.data);
12015
12016         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12017                                 plaintext_pad_len);
12018         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12019
12020         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12021         debug_hexdump(stdout, "plaintext:", plaintext,
12022                         tdata->plaintext.len);
12023
12024         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
12025                         tdata);
12026
12027         if (retval < 0)
12028                 return retval;
12029
12030         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12031
12032         ut_params->op->sym->m_src = ut_params->ibuf;
12033
12034         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12035                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12036                         ut_params->op);
12037         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12038                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12039                                 ut_params->op, 0, 1, 0, 0);
12040         else
12041                 TEST_ASSERT_NOT_NULL(
12042                         process_crypto_request(ts_params->valid_devs[0],
12043                         ut_params->op), "failed to process sym crypto op");
12044
12045         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12046                         "crypto op processing failed");
12047
12048         if (ut_params->op->sym->m_dst) {
12049                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12050                                 uint8_t *, plaintext_pad_len);
12051         } else {
12052                 auth_tag = plaintext + plaintext_pad_len;
12053         }
12054
12055         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12056
12057         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12058                         auth_tag,
12059                         tdata->gmac_tag.data,
12060                         tdata->gmac_tag.len,
12061                         "GMAC Generated auth tag not as expected");
12062
12063         return 0;
12064 }
12065
12066 static int
12067 test_AES_GMAC_authentication_test_case_1(void)
12068 {
12069         return test_AES_GMAC_authentication(&gmac_test_case_1);
12070 }
12071
12072 static int
12073 test_AES_GMAC_authentication_test_case_2(void)
12074 {
12075         return test_AES_GMAC_authentication(&gmac_test_case_2);
12076 }
12077
12078 static int
12079 test_AES_GMAC_authentication_test_case_3(void)
12080 {
12081         return test_AES_GMAC_authentication(&gmac_test_case_3);
12082 }
12083
12084 static int
12085 test_AES_GMAC_authentication_test_case_4(void)
12086 {
12087         return test_AES_GMAC_authentication(&gmac_test_case_4);
12088 }
12089
12090 static int
12091 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
12092 {
12093         struct crypto_testsuite_params *ts_params = &testsuite_params;
12094         struct crypto_unittest_params *ut_params = &unittest_params;
12095         int retval;
12096         uint32_t plaintext_pad_len;
12097         uint8_t *plaintext;
12098         struct rte_cryptodev_info dev_info;
12099
12100         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12101         uint64_t feat_flags = dev_info.feature_flags;
12102
12103         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12104                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12105                 printf("Device doesn't support RAW data-path APIs.\n");
12106                 return TEST_SKIPPED;
12107         }
12108
12109         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12110                               "No GMAC length in the source data");
12111
12112         /* Verify the capabilities */
12113         struct rte_cryptodev_sym_capability_idx cap_idx;
12114         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12115         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12116         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12117                         &cap_idx) == NULL)
12118                 return TEST_SKIPPED;
12119
12120         retval = create_gmac_session(ts_params->valid_devs[0],
12121                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
12122
12123         if (retval < 0)
12124                 return retval;
12125
12126         if (tdata->plaintext.len > MBUF_SIZE)
12127                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12128         else
12129                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12130         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12131                         "Failed to allocate input buffer in mempool");
12132
12133         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12134                         rte_pktmbuf_tailroom(ut_params->ibuf));
12135
12136         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12137
12138         /*
12139          * Runtime generate the large plain text instead of use hard code
12140          * plain text vector. It is done to avoid create huge source file
12141          * with the test vector.
12142          */
12143         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12144                 generate_gmac_large_plaintext(tdata->plaintext.data);
12145
12146         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12147                                 plaintext_pad_len);
12148         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12149
12150         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12151         debug_hexdump(stdout, "plaintext:", plaintext,
12152                         tdata->plaintext.len);
12153
12154         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
12155                         tdata);
12156
12157         if (retval < 0)
12158                 return retval;
12159
12160         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12161
12162         ut_params->op->sym->m_src = ut_params->ibuf;
12163
12164         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12165                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12166                         ut_params->op);
12167         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12168                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12169                                 ut_params->op, 0, 1, 0, 0);
12170         else
12171                 TEST_ASSERT_NOT_NULL(
12172                         process_crypto_request(ts_params->valid_devs[0],
12173                         ut_params->op), "failed to process sym crypto op");
12174
12175         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12176                         "crypto op processing failed");
12177
12178         return 0;
12179
12180 }
12181
12182 static int
12183 test_AES_GMAC_authentication_verify_test_case_1(void)
12184 {
12185         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
12186 }
12187
12188 static int
12189 test_AES_GMAC_authentication_verify_test_case_2(void)
12190 {
12191         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
12192 }
12193
12194 static int
12195 test_AES_GMAC_authentication_verify_test_case_3(void)
12196 {
12197         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
12198 }
12199
12200 static int
12201 test_AES_GMAC_authentication_verify_test_case_4(void)
12202 {
12203         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
12204 }
12205
12206 static int
12207 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
12208                                 uint32_t fragsz)
12209 {
12210         struct crypto_testsuite_params *ts_params = &testsuite_params;
12211         struct crypto_unittest_params *ut_params = &unittest_params;
12212         struct rte_cryptodev_info dev_info;
12213         uint64_t feature_flags;
12214         unsigned int trn_data = 0;
12215         void *digest_mem = NULL;
12216         uint32_t segs = 1;
12217         unsigned int to_trn = 0;
12218         struct rte_mbuf *buf = NULL;
12219         uint8_t *auth_tag, *plaintext;
12220         int retval;
12221
12222         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12223                               "No GMAC length in the source data");
12224
12225         /* Verify the capabilities */
12226         struct rte_cryptodev_sym_capability_idx cap_idx;
12227         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12228         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12229         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12230                         &cap_idx) == NULL)
12231                 return TEST_SKIPPED;
12232
12233         /* Check for any input SGL support */
12234         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12235         feature_flags = dev_info.feature_flags;
12236
12237         if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
12238                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
12239                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
12240                 return TEST_SKIPPED;
12241
12242         if (fragsz > tdata->plaintext.len)
12243                 fragsz = tdata->plaintext.len;
12244
12245         uint16_t plaintext_len = fragsz;
12246
12247         retval = create_gmac_session(ts_params->valid_devs[0],
12248                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12249
12250         if (retval < 0)
12251                 return retval;
12252
12253         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12254         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12255                         "Failed to allocate input buffer in mempool");
12256
12257         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12258                         rte_pktmbuf_tailroom(ut_params->ibuf));
12259
12260         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12261                                 plaintext_len);
12262         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12263
12264         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12265
12266         trn_data += plaintext_len;
12267
12268         buf = ut_params->ibuf;
12269
12270         /*
12271          * Loop until no more fragments
12272          */
12273
12274         while (trn_data < tdata->plaintext.len) {
12275                 ++segs;
12276                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
12277                                 (tdata->plaintext.len - trn_data) : fragsz;
12278
12279                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12280                 buf = buf->next;
12281
12282                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
12283                                 rte_pktmbuf_tailroom(buf));
12284
12285                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
12286                                 to_trn);
12287
12288                 memcpy(plaintext, tdata->plaintext.data + trn_data,
12289                                 to_trn);
12290                 trn_data += to_trn;
12291                 if (trn_data  == tdata->plaintext.len)
12292                         digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
12293                                         tdata->gmac_tag.len);
12294         }
12295         ut_params->ibuf->nb_segs = segs;
12296
12297         /*
12298          * Place digest at the end of the last buffer
12299          */
12300         uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
12301
12302         if (!digest_mem) {
12303                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12304                                 + tdata->gmac_tag.len);
12305                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
12306                                 tdata->plaintext.len);
12307         }
12308
12309         retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
12310                         tdata, digest_mem, digest_phys);
12311
12312         if (retval < 0)
12313                 return retval;
12314
12315         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12316
12317         ut_params->op->sym->m_src = ut_params->ibuf;
12318
12319         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12320                 return TEST_SKIPPED;
12321
12322         TEST_ASSERT_NOT_NULL(
12323                 process_crypto_request(ts_params->valid_devs[0],
12324                 ut_params->op), "failed to process sym crypto op");
12325
12326         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12327                         "crypto op processing failed");
12328
12329         auth_tag = digest_mem;
12330         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12331         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12332                         auth_tag,
12333                         tdata->gmac_tag.data,
12334                         tdata->gmac_tag.len,
12335                         "GMAC Generated auth tag not as expected");
12336
12337         return 0;
12338 }
12339
12340 /* Segment size not multiple of block size (16B) */
12341 static int
12342 test_AES_GMAC_authentication_SGL_40B(void)
12343 {
12344         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
12345 }
12346
12347 static int
12348 test_AES_GMAC_authentication_SGL_80B(void)
12349 {
12350         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
12351 }
12352
12353 static int
12354 test_AES_GMAC_authentication_SGL_2048B(void)
12355 {
12356         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
12357 }
12358
12359 /* Segment size not multiple of block size (16B) */
12360 static int
12361 test_AES_GMAC_authentication_SGL_2047B(void)
12362 {
12363         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
12364 }
12365
12366 struct test_crypto_vector {
12367         enum rte_crypto_cipher_algorithm crypto_algo;
12368         unsigned int cipher_offset;
12369         unsigned int cipher_len;
12370
12371         struct {
12372                 uint8_t data[64];
12373                 unsigned int len;
12374         } cipher_key;
12375
12376         struct {
12377                 uint8_t data[64];
12378                 unsigned int len;
12379         } iv;
12380
12381         struct {
12382                 const uint8_t *data;
12383                 unsigned int len;
12384         } plaintext;
12385
12386         struct {
12387                 const uint8_t *data;
12388                 unsigned int len;
12389         } ciphertext;
12390
12391         enum rte_crypto_auth_algorithm auth_algo;
12392         unsigned int auth_offset;
12393
12394         struct {
12395                 uint8_t data[128];
12396                 unsigned int len;
12397         } auth_key;
12398
12399         struct {
12400                 const uint8_t *data;
12401                 unsigned int len;
12402         } aad;
12403
12404         struct {
12405                 uint8_t data[128];
12406                 unsigned int len;
12407         } digest;
12408 };
12409
12410 static const struct test_crypto_vector
12411 hmac_sha1_test_crypto_vector = {
12412         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12413         .plaintext = {
12414                 .data = plaintext_hash,
12415                 .len = 512
12416         },
12417         .auth_key = {
12418                 .data = {
12419                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12420                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12421                         0xDE, 0xF4, 0xDE, 0xAD
12422                 },
12423                 .len = 20
12424         },
12425         .digest = {
12426                 .data = {
12427                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
12428                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
12429                         0x3F, 0x91, 0x64, 0x59
12430                 },
12431                 .len = 20
12432         }
12433 };
12434
12435 static const struct test_crypto_vector
12436 aes128_gmac_test_vector = {
12437         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
12438         .plaintext = {
12439                 .data = plaintext_hash,
12440                 .len = 512
12441         },
12442         .iv = {
12443                 .data = {
12444                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12445                         0x08, 0x09, 0x0A, 0x0B
12446                 },
12447                 .len = 12
12448         },
12449         .auth_key = {
12450                 .data = {
12451                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12452                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
12453                 },
12454                 .len = 16
12455         },
12456         .digest = {
12457                 .data = {
12458                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
12459                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
12460                 },
12461                 .len = 16
12462         }
12463 };
12464
12465 static const struct test_crypto_vector
12466 aes128cbc_hmac_sha1_test_vector = {
12467         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12468         .cipher_offset = 0,
12469         .cipher_len = 512,
12470         .cipher_key = {
12471                 .data = {
12472                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12473                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12474                 },
12475                 .len = 16
12476         },
12477         .iv = {
12478                 .data = {
12479                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12480                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12481                 },
12482                 .len = 16
12483         },
12484         .plaintext = {
12485                 .data = plaintext_hash,
12486                 .len = 512
12487         },
12488         .ciphertext = {
12489                 .data = ciphertext512_aes128cbc,
12490                 .len = 512
12491         },
12492         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12493         .auth_offset = 0,
12494         .auth_key = {
12495                 .data = {
12496                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12497                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12498                         0xDE, 0xF4, 0xDE, 0xAD
12499                 },
12500                 .len = 20
12501         },
12502         .digest = {
12503                 .data = {
12504                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12505                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12506                         0x18, 0x8C, 0x1D, 0x32
12507                 },
12508                 .len = 20
12509         }
12510 };
12511
12512 static const struct test_crypto_vector
12513 aes128cbc_hmac_sha1_aad_test_vector = {
12514         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12515         .cipher_offset = 8,
12516         .cipher_len = 496,
12517         .cipher_key = {
12518                 .data = {
12519                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12520                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12521                 },
12522                 .len = 16
12523         },
12524         .iv = {
12525                 .data = {
12526                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12527                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12528                 },
12529                 .len = 16
12530         },
12531         .plaintext = {
12532                 .data = plaintext_hash,
12533                 .len = 512
12534         },
12535         .ciphertext = {
12536                 .data = ciphertext512_aes128cbc_aad,
12537                 .len = 512
12538         },
12539         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12540         .auth_offset = 0,
12541         .auth_key = {
12542                 .data = {
12543                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12544                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12545                         0xDE, 0xF4, 0xDE, 0xAD
12546                 },
12547                 .len = 20
12548         },
12549         .digest = {
12550                 .data = {
12551                         0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12552                         0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12553                         0x62, 0x0F, 0xFB, 0x10
12554                 },
12555                 .len = 20
12556         }
12557 };
12558
12559 static void
12560 data_corruption(uint8_t *data)
12561 {
12562         data[0] += 1;
12563 }
12564
12565 static void
12566 tag_corruption(uint8_t *data, unsigned int tag_offset)
12567 {
12568         data[tag_offset] += 1;
12569 }
12570
12571 static int
12572 create_auth_session(struct crypto_unittest_params *ut_params,
12573                 uint8_t dev_id,
12574                 const struct test_crypto_vector *reference,
12575                 enum rte_crypto_auth_operation auth_op)
12576 {
12577         struct crypto_testsuite_params *ts_params = &testsuite_params;
12578         uint8_t auth_key[reference->auth_key.len + 1];
12579
12580         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12581
12582         /* Setup Authentication Parameters */
12583         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12584         ut_params->auth_xform.auth.op = auth_op;
12585         ut_params->auth_xform.next = NULL;
12586         ut_params->auth_xform.auth.algo = reference->auth_algo;
12587         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12588         ut_params->auth_xform.auth.key.data = auth_key;
12589         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12590
12591         /* Create Crypto session*/
12592         ut_params->sess = rte_cryptodev_sym_session_create(
12593                         ts_params->session_mpool);
12594
12595         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12596                                 &ut_params->auth_xform,
12597                                 ts_params->session_priv_mpool);
12598
12599         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12600
12601         return 0;
12602 }
12603
12604 static int
12605 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12606                 uint8_t dev_id,
12607                 const struct test_crypto_vector *reference,
12608                 enum rte_crypto_auth_operation auth_op,
12609                 enum rte_crypto_cipher_operation cipher_op)
12610 {
12611         struct crypto_testsuite_params *ts_params = &testsuite_params;
12612         uint8_t cipher_key[reference->cipher_key.len + 1];
12613         uint8_t auth_key[reference->auth_key.len + 1];
12614
12615         memcpy(cipher_key, reference->cipher_key.data,
12616                         reference->cipher_key.len);
12617         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12618
12619         /* Setup Authentication Parameters */
12620         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12621         ut_params->auth_xform.auth.op = auth_op;
12622         ut_params->auth_xform.auth.algo = reference->auth_algo;
12623         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12624         ut_params->auth_xform.auth.key.data = auth_key;
12625         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12626
12627         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12628                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12629                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
12630         } else {
12631                 ut_params->auth_xform.next = &ut_params->cipher_xform;
12632
12633                 /* Setup Cipher Parameters */
12634                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12635                 ut_params->cipher_xform.next = NULL;
12636                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12637                 ut_params->cipher_xform.cipher.op = cipher_op;
12638                 ut_params->cipher_xform.cipher.key.data = cipher_key;
12639                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12640                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12641                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12642         }
12643
12644         /* Create Crypto session*/
12645         ut_params->sess = rte_cryptodev_sym_session_create(
12646                         ts_params->session_mpool);
12647
12648         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12649                                 &ut_params->auth_xform,
12650                                 ts_params->session_priv_mpool);
12651
12652         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12653
12654         return 0;
12655 }
12656
12657 static int
12658 create_auth_operation(struct crypto_testsuite_params *ts_params,
12659                 struct crypto_unittest_params *ut_params,
12660                 const struct test_crypto_vector *reference,
12661                 unsigned int auth_generate)
12662 {
12663         /* Generate Crypto op data structure */
12664         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12665                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12666         TEST_ASSERT_NOT_NULL(ut_params->op,
12667                         "Failed to allocate pktmbuf offload");
12668
12669         /* Set crypto operation data parameters */
12670         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12671
12672         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12673
12674         /* set crypto operation source mbuf */
12675         sym_op->m_src = ut_params->ibuf;
12676
12677         /* digest */
12678         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12679                         ut_params->ibuf, reference->digest.len);
12680
12681         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12682                         "no room to append auth tag");
12683
12684         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12685                         ut_params->ibuf, reference->plaintext.len);
12686
12687         if (auth_generate)
12688                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12689         else
12690                 memcpy(sym_op->auth.digest.data,
12691                                 reference->digest.data,
12692                                 reference->digest.len);
12693
12694         debug_hexdump(stdout, "digest:",
12695                         sym_op->auth.digest.data,
12696                         reference->digest.len);
12697
12698         sym_op->auth.data.length = reference->plaintext.len;
12699         sym_op->auth.data.offset = 0;
12700
12701         return 0;
12702 }
12703
12704 static int
12705 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12706                 struct crypto_unittest_params *ut_params,
12707                 const struct test_crypto_vector *reference,
12708                 unsigned int auth_generate)
12709 {
12710         /* Generate Crypto op data structure */
12711         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12712                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12713         TEST_ASSERT_NOT_NULL(ut_params->op,
12714                         "Failed to allocate pktmbuf offload");
12715
12716         /* Set crypto operation data parameters */
12717         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12718
12719         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12720
12721         /* set crypto operation source mbuf */
12722         sym_op->m_src = ut_params->ibuf;
12723
12724         /* digest */
12725         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12726                         ut_params->ibuf, reference->digest.len);
12727
12728         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12729                         "no room to append auth tag");
12730
12731         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12732                         ut_params->ibuf, reference->ciphertext.len);
12733
12734         if (auth_generate)
12735                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12736         else
12737                 memcpy(sym_op->auth.digest.data,
12738                                 reference->digest.data,
12739                                 reference->digest.len);
12740
12741         debug_hexdump(stdout, "digest:",
12742                         sym_op->auth.digest.data,
12743                         reference->digest.len);
12744
12745         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12746                         reference->iv.data, reference->iv.len);
12747
12748         sym_op->cipher.data.length = 0;
12749         sym_op->cipher.data.offset = 0;
12750
12751         sym_op->auth.data.length = reference->plaintext.len;
12752         sym_op->auth.data.offset = 0;
12753
12754         return 0;
12755 }
12756
12757 static int
12758 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12759                 struct crypto_unittest_params *ut_params,
12760                 const struct test_crypto_vector *reference,
12761                 unsigned int auth_generate)
12762 {
12763         /* Generate Crypto op data structure */
12764         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12765                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12766         TEST_ASSERT_NOT_NULL(ut_params->op,
12767                         "Failed to allocate pktmbuf offload");
12768
12769         /* Set crypto operation data parameters */
12770         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12771
12772         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12773
12774         /* set crypto operation source mbuf */
12775         sym_op->m_src = ut_params->ibuf;
12776
12777         /* digest */
12778         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12779                         ut_params->ibuf, reference->digest.len);
12780
12781         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12782                         "no room to append auth tag");
12783
12784         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12785                         ut_params->ibuf, reference->ciphertext.len);
12786
12787         if (auth_generate)
12788                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12789         else
12790                 memcpy(sym_op->auth.digest.data,
12791                                 reference->digest.data,
12792                                 reference->digest.len);
12793
12794         debug_hexdump(stdout, "digest:",
12795                         sym_op->auth.digest.data,
12796                         reference->digest.len);
12797
12798         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12799                         reference->iv.data, reference->iv.len);
12800
12801         sym_op->cipher.data.length = reference->cipher_len;
12802         sym_op->cipher.data.offset = reference->cipher_offset;
12803
12804         sym_op->auth.data.length = reference->plaintext.len;
12805         sym_op->auth.data.offset = reference->auth_offset;
12806
12807         return 0;
12808 }
12809
12810 static int
12811 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12812                 struct crypto_unittest_params *ut_params,
12813                 const struct test_crypto_vector *reference)
12814 {
12815         return create_auth_operation(ts_params, ut_params, reference, 0);
12816 }
12817
12818 static int
12819 create_auth_verify_GMAC_operation(
12820                 struct crypto_testsuite_params *ts_params,
12821                 struct crypto_unittest_params *ut_params,
12822                 const struct test_crypto_vector *reference)
12823 {
12824         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
12825 }
12826
12827 static int
12828 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12829                 struct crypto_unittest_params *ut_params,
12830                 const struct test_crypto_vector *reference)
12831 {
12832         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12833 }
12834
12835 static int
12836 test_authentication_verify_fail_when_data_corruption(
12837                 struct crypto_testsuite_params *ts_params,
12838                 struct crypto_unittest_params *ut_params,
12839                 const struct test_crypto_vector *reference,
12840                 unsigned int data_corrupted)
12841 {
12842         int retval;
12843
12844         uint8_t *plaintext;
12845         struct rte_cryptodev_info dev_info;
12846
12847         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12848         uint64_t feat_flags = dev_info.feature_flags;
12849
12850         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12851                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12852                 printf("Device doesn't support RAW data-path APIs.\n");
12853                 return TEST_SKIPPED;
12854         }
12855
12856         /* Verify the capabilities */
12857         struct rte_cryptodev_sym_capability_idx cap_idx;
12858         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12859         cap_idx.algo.auth = reference->auth_algo;
12860         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12861                         &cap_idx) == NULL)
12862                 return TEST_SKIPPED;
12863
12864
12865         /* Create session */
12866         retval = create_auth_session(ut_params,
12867                         ts_params->valid_devs[0],
12868                         reference,
12869                         RTE_CRYPTO_AUTH_OP_VERIFY);
12870         if (retval < 0)
12871                 return retval;
12872
12873         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12874         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12875                         "Failed to allocate input buffer in mempool");
12876
12877         /* clear mbuf payload */
12878         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12879                         rte_pktmbuf_tailroom(ut_params->ibuf));
12880
12881         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12882                         reference->plaintext.len);
12883         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12884         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12885
12886         debug_hexdump(stdout, "plaintext:", plaintext,
12887                 reference->plaintext.len);
12888
12889         /* Create operation */
12890         retval = create_auth_verify_operation(ts_params, ut_params, reference);
12891
12892         if (retval < 0)
12893                 return retval;
12894
12895         if (data_corrupted)
12896                 data_corruption(plaintext);
12897         else
12898                 tag_corruption(plaintext, reference->plaintext.len);
12899
12900         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12901                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12902                         ut_params->op);
12903                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12904                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12905                         "authentication not failed");
12906         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12907                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12908                                 ut_params->op, 0, 1, 0, 0);
12909         else {
12910                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12911                         ut_params->op);
12912                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12913         }
12914
12915         return 0;
12916 }
12917
12918 static int
12919 test_authentication_verify_GMAC_fail_when_corruption(
12920                 struct crypto_testsuite_params *ts_params,
12921                 struct crypto_unittest_params *ut_params,
12922                 const struct test_crypto_vector *reference,
12923                 unsigned int data_corrupted)
12924 {
12925         int retval;
12926         uint8_t *plaintext;
12927         struct rte_cryptodev_info dev_info;
12928
12929         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12930         uint64_t feat_flags = dev_info.feature_flags;
12931
12932         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12933                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12934                 printf("Device doesn't support RAW data-path APIs.\n");
12935                 return TEST_SKIPPED;
12936         }
12937
12938         /* Verify the capabilities */
12939         struct rte_cryptodev_sym_capability_idx cap_idx;
12940         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12941         cap_idx.algo.auth = reference->auth_algo;
12942         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12943                         &cap_idx) == NULL)
12944                 return TEST_SKIPPED;
12945
12946         /* Create session */
12947         retval = create_auth_cipher_session(ut_params,
12948                         ts_params->valid_devs[0],
12949                         reference,
12950                         RTE_CRYPTO_AUTH_OP_VERIFY,
12951                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12952         if (retval < 0)
12953                 return retval;
12954
12955         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12956         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12957                         "Failed to allocate input buffer in mempool");
12958
12959         /* clear mbuf payload */
12960         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12961                         rte_pktmbuf_tailroom(ut_params->ibuf));
12962
12963         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12964                         reference->plaintext.len);
12965         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12966         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12967
12968         debug_hexdump(stdout, "plaintext:", plaintext,
12969                 reference->plaintext.len);
12970
12971         /* Create operation */
12972         retval = create_auth_verify_GMAC_operation(ts_params,
12973                         ut_params,
12974                         reference);
12975
12976         if (retval < 0)
12977                 return retval;
12978
12979         if (data_corrupted)
12980                 data_corruption(plaintext);
12981         else
12982                 tag_corruption(plaintext, reference->aad.len);
12983
12984         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12985                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12986                         ut_params->op);
12987                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12988                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12989                         "authentication not failed");
12990         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12991                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12992                                 ut_params->op, 0, 1, 0, 0);
12993         else {
12994                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12995                         ut_params->op);
12996                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12997         }
12998
12999         return 0;
13000 }
13001
13002 static int
13003 test_authenticated_decryption_fail_when_corruption(
13004                 struct crypto_testsuite_params *ts_params,
13005                 struct crypto_unittest_params *ut_params,
13006                 const struct test_crypto_vector *reference,
13007                 unsigned int data_corrupted)
13008 {
13009         int retval;
13010
13011         uint8_t *ciphertext;
13012         struct rte_cryptodev_info dev_info;
13013
13014         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13015         uint64_t feat_flags = dev_info.feature_flags;
13016
13017         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13018                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13019                 printf("Device doesn't support RAW data-path APIs.\n");
13020                 return TEST_SKIPPED;
13021         }
13022
13023         /* Verify the capabilities */
13024         struct rte_cryptodev_sym_capability_idx cap_idx;
13025         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13026         cap_idx.algo.auth = reference->auth_algo;
13027         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13028                         &cap_idx) == NULL)
13029                 return TEST_SKIPPED;
13030         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13031         cap_idx.algo.cipher = reference->crypto_algo;
13032         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13033                         &cap_idx) == NULL)
13034                 return TEST_SKIPPED;
13035
13036         /* Create session */
13037         retval = create_auth_cipher_session(ut_params,
13038                         ts_params->valid_devs[0],
13039                         reference,
13040                         RTE_CRYPTO_AUTH_OP_VERIFY,
13041                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
13042         if (retval < 0)
13043                 return retval;
13044
13045         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13046         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13047                         "Failed to allocate input buffer in mempool");
13048
13049         /* clear mbuf payload */
13050         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13051                         rte_pktmbuf_tailroom(ut_params->ibuf));
13052
13053         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13054                         reference->ciphertext.len);
13055         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13056         memcpy(ciphertext, reference->ciphertext.data,
13057                         reference->ciphertext.len);
13058
13059         /* Create operation */
13060         retval = create_cipher_auth_verify_operation(ts_params,
13061                         ut_params,
13062                         reference);
13063
13064         if (retval < 0)
13065                 return retval;
13066
13067         if (data_corrupted)
13068                 data_corruption(ciphertext);
13069         else
13070                 tag_corruption(ciphertext, reference->ciphertext.len);
13071
13072         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13073                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13074                         ut_params->op);
13075                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13076                         RTE_CRYPTO_OP_STATUS_SUCCESS,
13077                         "authentication not failed");
13078         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13079                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13080                                 ut_params->op, 1, 1, 0, 0);
13081         else {
13082                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13083                         ut_params->op);
13084                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13085         }
13086
13087         return 0;
13088 }
13089
13090 static int
13091 test_authenticated_encrypt_with_esn(
13092                 struct crypto_testsuite_params *ts_params,
13093                 struct crypto_unittest_params *ut_params,
13094                 const struct test_crypto_vector *reference)
13095 {
13096         int retval;
13097
13098         uint8_t *authciphertext, *plaintext, *auth_tag;
13099         uint16_t plaintext_pad_len;
13100         uint8_t cipher_key[reference->cipher_key.len + 1];
13101         uint8_t auth_key[reference->auth_key.len + 1];
13102         struct rte_cryptodev_info dev_info;
13103
13104         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13105         uint64_t feat_flags = dev_info.feature_flags;
13106
13107         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13108                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13109                 printf("Device doesn't support RAW data-path APIs.\n");
13110                 return TEST_SKIPPED;
13111         }
13112
13113         /* Verify the capabilities */
13114         struct rte_cryptodev_sym_capability_idx cap_idx;
13115         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13116         cap_idx.algo.auth = reference->auth_algo;
13117         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13118                         &cap_idx) == NULL)
13119                 return TEST_SKIPPED;
13120         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13121         cap_idx.algo.cipher = reference->crypto_algo;
13122         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13123                         &cap_idx) == NULL)
13124                 return TEST_SKIPPED;
13125
13126         /* Create session */
13127         memcpy(cipher_key, reference->cipher_key.data,
13128                         reference->cipher_key.len);
13129         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13130
13131         /* Setup Cipher Parameters */
13132         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13133         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13134         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
13135         ut_params->cipher_xform.cipher.key.data = cipher_key;
13136         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13137         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13138         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13139
13140         ut_params->cipher_xform.next = &ut_params->auth_xform;
13141
13142         /* Setup Authentication Parameters */
13143         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13144         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
13145         ut_params->auth_xform.auth.algo = reference->auth_algo;
13146         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13147         ut_params->auth_xform.auth.key.data = auth_key;
13148         ut_params->auth_xform.auth.digest_length = reference->digest.len;
13149         ut_params->auth_xform.next = NULL;
13150
13151         /* Create Crypto session*/
13152         ut_params->sess = rte_cryptodev_sym_session_create(
13153                         ts_params->session_mpool);
13154
13155         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13156                                 ut_params->sess,
13157                                 &ut_params->cipher_xform,
13158                                 ts_params->session_priv_mpool);
13159
13160         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13161
13162         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13163         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13164                         "Failed to allocate input buffer in mempool");
13165
13166         /* clear mbuf payload */
13167         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13168                         rte_pktmbuf_tailroom(ut_params->ibuf));
13169
13170         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13171                         reference->plaintext.len);
13172         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13173         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13174
13175         /* Create operation */
13176         retval = create_cipher_auth_operation(ts_params,
13177                         ut_params,
13178                         reference, 0);
13179
13180         if (retval < 0)
13181                 return retval;
13182
13183         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13184                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13185                         ut_params->op);
13186         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13187                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13188                                 ut_params->op, 1, 1, 0, 0);
13189         else
13190                 ut_params->op = process_crypto_request(
13191                         ts_params->valid_devs[0], ut_params->op);
13192
13193         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
13194
13195         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13196                         "crypto op processing failed");
13197
13198         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
13199
13200         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
13201                         ut_params->op->sym->auth.data.offset);
13202         auth_tag = authciphertext + plaintext_pad_len;
13203         debug_hexdump(stdout, "ciphertext:", authciphertext,
13204                         reference->ciphertext.len);
13205         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
13206
13207         /* Validate obuf */
13208         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13209                         authciphertext,
13210                         reference->ciphertext.data,
13211                         reference->ciphertext.len,
13212                         "Ciphertext data not as expected");
13213
13214         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13215                         auth_tag,
13216                         reference->digest.data,
13217                         reference->digest.len,
13218                         "Generated digest not as expected");
13219
13220         return TEST_SUCCESS;
13221
13222 }
13223
13224 static int
13225 test_authenticated_decrypt_with_esn(
13226                 struct crypto_testsuite_params *ts_params,
13227                 struct crypto_unittest_params *ut_params,
13228                 const struct test_crypto_vector *reference)
13229 {
13230         int retval;
13231
13232         uint8_t *ciphertext;
13233         uint8_t cipher_key[reference->cipher_key.len + 1];
13234         uint8_t auth_key[reference->auth_key.len + 1];
13235         struct rte_cryptodev_info dev_info;
13236
13237         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13238         uint64_t feat_flags = dev_info.feature_flags;
13239
13240         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13241                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13242                 printf("Device doesn't support RAW data-path APIs.\n");
13243                 return TEST_SKIPPED;
13244         }
13245
13246         /* Verify the capabilities */
13247         struct rte_cryptodev_sym_capability_idx cap_idx;
13248         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13249         cap_idx.algo.auth = reference->auth_algo;
13250         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13251                         &cap_idx) == NULL)
13252                 return TEST_SKIPPED;
13253         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13254         cap_idx.algo.cipher = reference->crypto_algo;
13255         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13256                         &cap_idx) == NULL)
13257                 return TEST_SKIPPED;
13258
13259         /* Create session */
13260         memcpy(cipher_key, reference->cipher_key.data,
13261                         reference->cipher_key.len);
13262         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13263
13264         /* Setup Authentication Parameters */
13265         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13266         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
13267         ut_params->auth_xform.auth.algo = reference->auth_algo;
13268         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13269         ut_params->auth_xform.auth.key.data = auth_key;
13270         ut_params->auth_xform.auth.digest_length = reference->digest.len;
13271         ut_params->auth_xform.next = &ut_params->cipher_xform;
13272
13273         /* Setup Cipher Parameters */
13274         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13275         ut_params->cipher_xform.next = NULL;
13276         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13277         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
13278         ut_params->cipher_xform.cipher.key.data = cipher_key;
13279         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13280         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13281         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13282
13283         /* Create Crypto session*/
13284         ut_params->sess = rte_cryptodev_sym_session_create(
13285                         ts_params->session_mpool);
13286
13287         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13288                                 ut_params->sess,
13289                                 &ut_params->auth_xform,
13290                                 ts_params->session_priv_mpool);
13291
13292         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13293
13294         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13295         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13296                         "Failed to allocate input buffer in mempool");
13297
13298         /* clear mbuf payload */
13299         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13300                         rte_pktmbuf_tailroom(ut_params->ibuf));
13301
13302         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13303                         reference->ciphertext.len);
13304         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13305         memcpy(ciphertext, reference->ciphertext.data,
13306                         reference->ciphertext.len);
13307
13308         /* Create operation */
13309         retval = create_cipher_auth_verify_operation(ts_params,
13310                         ut_params,
13311                         reference);
13312
13313         if (retval < 0)
13314                 return retval;
13315
13316         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13317                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13318                         ut_params->op);
13319         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13320                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13321                                 ut_params->op, 1, 1, 0, 0);
13322         else
13323                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13324                         ut_params->op);
13325
13326         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
13327         TEST_ASSERT_EQUAL(ut_params->op->status,
13328                         RTE_CRYPTO_OP_STATUS_SUCCESS,
13329                         "crypto op processing passed");
13330
13331         ut_params->obuf = ut_params->op->sym->m_src;
13332         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
13333
13334         return 0;
13335 }
13336
13337 static int
13338 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
13339                 const struct aead_test_data *tdata,
13340                 void *digest_mem, uint64_t digest_phys)
13341 {
13342         struct crypto_testsuite_params *ts_params = &testsuite_params;
13343         struct crypto_unittest_params *ut_params = &unittest_params;
13344
13345         const unsigned int auth_tag_len = tdata->auth_tag.len;
13346         const unsigned int iv_len = tdata->iv.len;
13347         unsigned int aad_len = tdata->aad.len;
13348         unsigned int aad_len_pad = 0;
13349
13350         /* Generate Crypto op data structure */
13351         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13352                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13353         TEST_ASSERT_NOT_NULL(ut_params->op,
13354                 "Failed to allocate symmetric crypto operation struct");
13355
13356         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13357
13358         sym_op->aead.digest.data = digest_mem;
13359
13360         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
13361                         "no room to append digest");
13362
13363         sym_op->aead.digest.phys_addr = digest_phys;
13364
13365         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
13366                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
13367                                 auth_tag_len);
13368                 debug_hexdump(stdout, "digest:",
13369                                 sym_op->aead.digest.data,
13370                                 auth_tag_len);
13371         }
13372
13373         /* Append aad data */
13374         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
13375                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13376                                 uint8_t *, IV_OFFSET);
13377
13378                 /* Copy IV 1 byte after the IV pointer, according to the API */
13379                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
13380
13381                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
13382
13383                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13384                                 ut_params->ibuf, aad_len);
13385                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13386                                 "no room to prepend aad");
13387                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13388                                 ut_params->ibuf);
13389
13390                 memset(sym_op->aead.aad.data, 0, aad_len);
13391                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
13392                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13393
13394                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13395                 debug_hexdump(stdout, "aad:",
13396                                 sym_op->aead.aad.data, aad_len);
13397         } else {
13398                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13399                                 uint8_t *, IV_OFFSET);
13400
13401                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
13402
13403                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
13404
13405                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13406                                 ut_params->ibuf, aad_len_pad);
13407                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13408                                 "no room to prepend aad");
13409                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13410                                 ut_params->ibuf);
13411
13412                 memset(sym_op->aead.aad.data, 0, aad_len);
13413                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13414
13415                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13416                 debug_hexdump(stdout, "aad:",
13417                                 sym_op->aead.aad.data, aad_len);
13418         }
13419
13420         sym_op->aead.data.length = tdata->plaintext.len;
13421         sym_op->aead.data.offset = aad_len_pad;
13422
13423         return 0;
13424 }
13425
13426 #define SGL_MAX_NO      16
13427
13428 static int
13429 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
13430                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
13431 {
13432         struct crypto_testsuite_params *ts_params = &testsuite_params;
13433         struct crypto_unittest_params *ut_params = &unittest_params;
13434         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
13435         int retval;
13436         int to_trn = 0;
13437         int to_trn_tbl[SGL_MAX_NO];
13438         int segs = 1;
13439         unsigned int trn_data = 0;
13440         uint8_t *plaintext, *ciphertext, *auth_tag;
13441         struct rte_cryptodev_info dev_info;
13442
13443         /* Verify the capabilities */
13444         struct rte_cryptodev_sym_capability_idx cap_idx;
13445         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13446         cap_idx.algo.aead = tdata->algo;
13447         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13448                         &cap_idx) == NULL)
13449                 return TEST_SKIPPED;
13450
13451         /* OOP not supported with CPU crypto */
13452         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13453                 return TEST_SKIPPED;
13454
13455         /* Detailed check for the particular SGL support flag */
13456         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13457         if (!oop) {
13458                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
13459                 if (sgl_in && (!(dev_info.feature_flags &
13460                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
13461                         return TEST_SKIPPED;
13462
13463                 uint64_t feat_flags = dev_info.feature_flags;
13464
13465                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13466                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13467                         printf("Device doesn't support RAW data-path APIs.\n");
13468                         return TEST_SKIPPED;
13469                 }
13470         } else {
13471                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
13472                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
13473                                 tdata->plaintext.len;
13474                 /* Raw data path API does not support OOP */
13475                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13476                         return TEST_SKIPPED;
13477                 if (sgl_in && !sgl_out) {
13478                         if (!(dev_info.feature_flags &
13479                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
13480                                 return TEST_SKIPPED;
13481                 } else if (!sgl_in && sgl_out) {
13482                         if (!(dev_info.feature_flags &
13483                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
13484                                 return TEST_SKIPPED;
13485                 } else if (sgl_in && sgl_out) {
13486                         if (!(dev_info.feature_flags &
13487                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13488                                 return TEST_SKIPPED;
13489                 }
13490         }
13491
13492         if (fragsz > tdata->plaintext.len)
13493                 fragsz = tdata->plaintext.len;
13494
13495         uint16_t plaintext_len = fragsz;
13496         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13497
13498         if (fragsz_oop > tdata->plaintext.len)
13499                 frag_size_oop = tdata->plaintext.len;
13500
13501         int ecx = 0;
13502         void *digest_mem = NULL;
13503
13504         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13505
13506         if (tdata->plaintext.len % fragsz != 0) {
13507                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13508                         return 1;
13509         }       else {
13510                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13511                         return 1;
13512         }
13513
13514         /*
13515          * For out-op-place we need to alloc another mbuf
13516          */
13517         if (oop) {
13518                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13519                 rte_pktmbuf_append(ut_params->obuf,
13520                                 frag_size_oop + prepend_len);
13521                 buf_oop = ut_params->obuf;
13522         }
13523
13524         /* Create AEAD session */
13525         retval = create_aead_session(ts_params->valid_devs[0],
13526                         tdata->algo,
13527                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
13528                         tdata->key.data, tdata->key.len,
13529                         tdata->aad.len, tdata->auth_tag.len,
13530                         tdata->iv.len);
13531         if (retval < 0)
13532                 return retval;
13533
13534         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13535
13536         /* clear mbuf payload */
13537         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13538                         rte_pktmbuf_tailroom(ut_params->ibuf));
13539
13540         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13541                         plaintext_len);
13542
13543         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13544
13545         trn_data += plaintext_len;
13546
13547         buf = ut_params->ibuf;
13548
13549         /*
13550          * Loop until no more fragments
13551          */
13552
13553         while (trn_data < tdata->plaintext.len) {
13554                 ++segs;
13555                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13556                                 (tdata->plaintext.len - trn_data) : fragsz;
13557
13558                 to_trn_tbl[ecx++] = to_trn;
13559
13560                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13561                 buf = buf->next;
13562
13563                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13564                                 rte_pktmbuf_tailroom(buf));
13565
13566                 /* OOP */
13567                 if (oop && !fragsz_oop) {
13568                         buf_last_oop = buf_oop->next =
13569                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13570                         buf_oop = buf_oop->next;
13571                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13572                                         0, rte_pktmbuf_tailroom(buf_oop));
13573                         rte_pktmbuf_append(buf_oop, to_trn);
13574                 }
13575
13576                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13577                                 to_trn);
13578
13579                 memcpy(plaintext, tdata->plaintext.data + trn_data,
13580                                 to_trn);
13581                 trn_data += to_trn;
13582                 if (trn_data  == tdata->plaintext.len) {
13583                         if (oop) {
13584                                 if (!fragsz_oop)
13585                                         digest_mem = rte_pktmbuf_append(buf_oop,
13586                                                 tdata->auth_tag.len);
13587                         } else
13588                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13589                                         tdata->auth_tag.len);
13590                 }
13591         }
13592
13593         uint64_t digest_phys = 0;
13594
13595         ut_params->ibuf->nb_segs = segs;
13596
13597         segs = 1;
13598         if (fragsz_oop && oop) {
13599                 to_trn = 0;
13600                 ecx = 0;
13601
13602                 if (frag_size_oop == tdata->plaintext.len) {
13603                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
13604                                 tdata->auth_tag.len);
13605
13606                         digest_phys = rte_pktmbuf_iova_offset(
13607                                         ut_params->obuf,
13608                                         tdata->plaintext.len + prepend_len);
13609                 }
13610
13611                 trn_data = frag_size_oop;
13612                 while (trn_data < tdata->plaintext.len) {
13613                         ++segs;
13614                         to_trn =
13615                                 (tdata->plaintext.len - trn_data <
13616                                                 frag_size_oop) ?
13617                                 (tdata->plaintext.len - trn_data) :
13618                                                 frag_size_oop;
13619
13620                         to_trn_tbl[ecx++] = to_trn;
13621
13622                         buf_last_oop = buf_oop->next =
13623                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13624                         buf_oop = buf_oop->next;
13625                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13626                                         0, rte_pktmbuf_tailroom(buf_oop));
13627                         rte_pktmbuf_append(buf_oop, to_trn);
13628
13629                         trn_data += to_trn;
13630
13631                         if (trn_data  == tdata->plaintext.len) {
13632                                 digest_mem = rte_pktmbuf_append(buf_oop,
13633                                         tdata->auth_tag.len);
13634                         }
13635                 }
13636
13637                 ut_params->obuf->nb_segs = segs;
13638         }
13639
13640         /*
13641          * Place digest at the end of the last buffer
13642          */
13643         if (!digest_phys)
13644                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13645         if (oop && buf_last_oop)
13646                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13647
13648         if (!digest_mem && !oop) {
13649                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13650                                 + tdata->auth_tag.len);
13651                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13652                                 tdata->plaintext.len);
13653         }
13654
13655         /* Create AEAD operation */
13656         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13657                         tdata, digest_mem, digest_phys);
13658
13659         if (retval < 0)
13660                 return retval;
13661
13662         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13663
13664         ut_params->op->sym->m_src = ut_params->ibuf;
13665         if (oop)
13666                 ut_params->op->sym->m_dst = ut_params->obuf;
13667
13668         /* Process crypto operation */
13669         if (oop == IN_PLACE &&
13670                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13671                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13672         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13673                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13674                                 ut_params->op, 0, 0, 0, 0);
13675         else
13676                 TEST_ASSERT_NOT_NULL(
13677                         process_crypto_request(ts_params->valid_devs[0],
13678                         ut_params->op), "failed to process sym crypto op");
13679
13680         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13681                         "crypto op processing failed");
13682
13683
13684         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13685                         uint8_t *, prepend_len);
13686         if (oop) {
13687                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13688                                 uint8_t *, prepend_len);
13689         }
13690
13691         if (fragsz_oop)
13692                 fragsz = fragsz_oop;
13693
13694         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13695                         ciphertext,
13696                         tdata->ciphertext.data,
13697                         fragsz,
13698                         "Ciphertext data not as expected");
13699
13700         buf = ut_params->op->sym->m_src->next;
13701         if (oop)
13702                 buf = ut_params->op->sym->m_dst->next;
13703
13704         unsigned int off = fragsz;
13705
13706         ecx = 0;
13707         while (buf) {
13708                 ciphertext = rte_pktmbuf_mtod(buf,
13709                                 uint8_t *);
13710
13711                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
13712                                 ciphertext,
13713                                 tdata->ciphertext.data + off,
13714                                 to_trn_tbl[ecx],
13715                                 "Ciphertext data not as expected");
13716
13717                 off += to_trn_tbl[ecx++];
13718                 buf = buf->next;
13719         }
13720
13721         auth_tag = digest_mem;
13722         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13723                         auth_tag,
13724                         tdata->auth_tag.data,
13725                         tdata->auth_tag.len,
13726                         "Generated auth tag not as expected");
13727
13728         return 0;
13729 }
13730
13731 static int
13732 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13733 {
13734         return test_authenticated_encryption_SGL(
13735                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13736 }
13737
13738 static int
13739 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13740 {
13741         return test_authenticated_encryption_SGL(
13742                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13743 }
13744
13745 static int
13746 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13747 {
13748         return test_authenticated_encryption_SGL(
13749                         &gcm_test_case_8, OUT_OF_PLACE, 400,
13750                         gcm_test_case_8.plaintext.len);
13751 }
13752
13753 static int
13754 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13755 {
13756         /* This test is not for OPENSSL PMD */
13757         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13758                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13759                 return TEST_SKIPPED;
13760
13761         return test_authenticated_encryption_SGL(
13762                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13763 }
13764
13765 static int
13766 test_authentication_verify_fail_when_data_corrupted(
13767                 struct crypto_testsuite_params *ts_params,
13768                 struct crypto_unittest_params *ut_params,
13769                 const struct test_crypto_vector *reference)
13770 {
13771         return test_authentication_verify_fail_when_data_corruption(
13772                         ts_params, ut_params, reference, 1);
13773 }
13774
13775 static int
13776 test_authentication_verify_fail_when_tag_corrupted(
13777                 struct crypto_testsuite_params *ts_params,
13778                 struct crypto_unittest_params *ut_params,
13779                 const struct test_crypto_vector *reference)
13780 {
13781         return test_authentication_verify_fail_when_data_corruption(
13782                         ts_params, ut_params, reference, 0);
13783 }
13784
13785 static int
13786 test_authentication_verify_GMAC_fail_when_data_corrupted(
13787                 struct crypto_testsuite_params *ts_params,
13788                 struct crypto_unittest_params *ut_params,
13789                 const struct test_crypto_vector *reference)
13790 {
13791         return test_authentication_verify_GMAC_fail_when_corruption(
13792                         ts_params, ut_params, reference, 1);
13793 }
13794
13795 static int
13796 test_authentication_verify_GMAC_fail_when_tag_corrupted(
13797                 struct crypto_testsuite_params *ts_params,
13798                 struct crypto_unittest_params *ut_params,
13799                 const struct test_crypto_vector *reference)
13800 {
13801         return test_authentication_verify_GMAC_fail_when_corruption(
13802                         ts_params, ut_params, reference, 0);
13803 }
13804
13805 static int
13806 test_authenticated_decryption_fail_when_data_corrupted(
13807                 struct crypto_testsuite_params *ts_params,
13808                 struct crypto_unittest_params *ut_params,
13809                 const struct test_crypto_vector *reference)
13810 {
13811         return test_authenticated_decryption_fail_when_corruption(
13812                         ts_params, ut_params, reference, 1);
13813 }
13814
13815 static int
13816 test_authenticated_decryption_fail_when_tag_corrupted(
13817                 struct crypto_testsuite_params *ts_params,
13818                 struct crypto_unittest_params *ut_params,
13819                 const struct test_crypto_vector *reference)
13820 {
13821         return test_authenticated_decryption_fail_when_corruption(
13822                         ts_params, ut_params, reference, 0);
13823 }
13824
13825 static int
13826 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
13827 {
13828         return test_authentication_verify_fail_when_data_corrupted(
13829                         &testsuite_params, &unittest_params,
13830                         &hmac_sha1_test_crypto_vector);
13831 }
13832
13833 static int
13834 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13835 {
13836         return test_authentication_verify_fail_when_tag_corrupted(
13837                         &testsuite_params, &unittest_params,
13838                         &hmac_sha1_test_crypto_vector);
13839 }
13840
13841 static int
13842 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
13843 {
13844         return test_authentication_verify_GMAC_fail_when_data_corrupted(
13845                         &testsuite_params, &unittest_params,
13846                         &aes128_gmac_test_vector);
13847 }
13848
13849 static int
13850 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
13851 {
13852         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
13853                         &testsuite_params, &unittest_params,
13854                         &aes128_gmac_test_vector);
13855 }
13856
13857 static int
13858 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
13859 {
13860         return test_authenticated_decryption_fail_when_data_corrupted(
13861                         &testsuite_params,
13862                         &unittest_params,
13863                         &aes128cbc_hmac_sha1_test_vector);
13864 }
13865
13866 static int
13867 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
13868 {
13869         return test_authenticated_decryption_fail_when_tag_corrupted(
13870                         &testsuite_params,
13871                         &unittest_params,
13872                         &aes128cbc_hmac_sha1_test_vector);
13873 }
13874
13875 static int
13876 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13877 {
13878         return test_authenticated_encrypt_with_esn(
13879                         &testsuite_params,
13880                         &unittest_params,
13881                         &aes128cbc_hmac_sha1_aad_test_vector);
13882 }
13883
13884 static int
13885 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13886 {
13887         return test_authenticated_decrypt_with_esn(
13888                         &testsuite_params,
13889                         &unittest_params,
13890                         &aes128cbc_hmac_sha1_aad_test_vector);
13891 }
13892
13893 static int
13894 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
13895 {
13896         return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
13897 }
13898
13899 static int
13900 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
13901 {
13902         return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
13903 }
13904
13905 #ifdef RTE_CRYPTO_SCHEDULER
13906
13907 /* global AESNI worker IDs for the scheduler test */
13908 uint8_t aesni_ids[2];
13909
13910 static int
13911 scheduler_testsuite_setup(void)
13912 {
13913         uint32_t i = 0;
13914         int32_t nb_devs, ret;
13915         char vdev_args[VDEV_ARGS_SIZE] = {""};
13916         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
13917                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
13918         uint16_t worker_core_count = 0;
13919         uint16_t socket_id = 0;
13920
13921         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13922                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
13923
13924                 /* Identify the Worker Cores
13925                  * Use 2 worker cores for the device args
13926                  */
13927                 RTE_LCORE_FOREACH_WORKER(i) {
13928                         if (worker_core_count > 1)
13929                                 break;
13930                         snprintf(vdev_args, sizeof(vdev_args),
13931                                         "%s%d", temp_str, i);
13932                         strcpy(temp_str, vdev_args);
13933                         strlcat(temp_str, ";", sizeof(temp_str));
13934                         worker_core_count++;
13935                         socket_id = rte_lcore_to_socket_id(i);
13936                 }
13937                 if (worker_core_count != 2) {
13938                         RTE_LOG(ERR, USER1,
13939                                 "Cryptodev scheduler test require at least "
13940                                 "two worker cores to run. "
13941                                 "Please use the correct coremask.\n");
13942                         return TEST_FAILED;
13943                 }
13944                 strcpy(temp_str, vdev_args);
13945                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
13946                                 temp_str, socket_id);
13947                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
13948                 nb_devs = rte_cryptodev_device_count_by_driver(
13949                                 rte_cryptodev_driver_id_get(
13950                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
13951                 if (nb_devs < 1) {
13952                         ret = rte_vdev_init(
13953                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
13954                                         vdev_args);
13955                         TEST_ASSERT(ret == 0,
13956                                 "Failed to create instance %u of pmd : %s",
13957                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13958                 }
13959         }
13960         return testsuite_setup();
13961 }
13962
13963 static int
13964 test_scheduler_attach_worker_op(void)
13965 {
13966         struct crypto_testsuite_params *ts_params = &testsuite_params;
13967         uint8_t sched_id = ts_params->valid_devs[0];
13968         uint32_t i, nb_devs_attached = 0;
13969         int ret;
13970         char vdev_name[32];
13971         unsigned int count = rte_cryptodev_count();
13972
13973         /* create 2 AESNI_MB vdevs on top of existing devices */
13974         for (i = count; i < count + 2; i++) {
13975                 snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
13976                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
13977                                 i);
13978                 ret = rte_vdev_init(vdev_name, NULL);
13979
13980                 TEST_ASSERT(ret == 0,
13981                         "Failed to create instance %u of"
13982                         " pmd : %s",
13983                         i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13984
13985                 if (ret < 0) {
13986                         RTE_LOG(ERR, USER1,
13987                                 "Failed to create 2 AESNI MB PMDs.\n");
13988                         return TEST_SKIPPED;
13989                 }
13990         }
13991
13992         /* attach 2 AESNI_MB cdevs */
13993         for (i = count; i < count + 2; i++) {
13994                 struct rte_cryptodev_info info;
13995                 unsigned int session_size;
13996
13997                 rte_cryptodev_info_get(i, &info);
13998                 if (info.driver_id != rte_cryptodev_driver_id_get(
13999                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
14000                         continue;
14001
14002                 session_size = rte_cryptodev_sym_get_private_session_size(i);
14003                 /*
14004                  * Create the session mempool again, since now there are new devices
14005                  * to use the mempool.
14006                  */
14007                 if (ts_params->session_mpool) {
14008                         rte_mempool_free(ts_params->session_mpool);
14009                         ts_params->session_mpool = NULL;
14010                 }
14011                 if (ts_params->session_priv_mpool) {
14012                         rte_mempool_free(ts_params->session_priv_mpool);
14013                         ts_params->session_priv_mpool = NULL;
14014                 }
14015
14016                 if (info.sym.max_nb_sessions != 0 &&
14017                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
14018                         RTE_LOG(ERR, USER1,
14019                                         "Device does not support "
14020                                         "at least %u sessions\n",
14021                                         MAX_NB_SESSIONS);
14022                         return TEST_FAILED;
14023                 }
14024                 /*
14025                  * Create mempool with maximum number of sessions,
14026                  * to include the session headers
14027                  */
14028                 if (ts_params->session_mpool == NULL) {
14029                         ts_params->session_mpool =
14030                                 rte_cryptodev_sym_session_pool_create(
14031                                                 "test_sess_mp",
14032                                                 MAX_NB_SESSIONS, 0, 0, 0,
14033                                                 SOCKET_ID_ANY);
14034                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
14035                                         "session mempool allocation failed");
14036                 }
14037
14038                 /*
14039                  * Create mempool with maximum number of sessions,
14040                  * to include device specific session private data
14041                  */
14042                 if (ts_params->session_priv_mpool == NULL) {
14043                         ts_params->session_priv_mpool = rte_mempool_create(
14044                                         "test_sess_mp_priv",
14045                                         MAX_NB_SESSIONS,
14046                                         session_size,
14047                                         0, 0, NULL, NULL, NULL,
14048                                         NULL, SOCKET_ID_ANY,
14049                                         0);
14050
14051                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
14052                                         "session mempool allocation failed");
14053                 }
14054
14055                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
14056                 ts_params->qp_conf.mp_session_private =
14057                                 ts_params->session_priv_mpool;
14058
14059                 ret = rte_cryptodev_scheduler_worker_attach(sched_id,
14060                                 (uint8_t)i);
14061
14062                 TEST_ASSERT(ret == 0,
14063                         "Failed to attach device %u of pmd : %s", i,
14064                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14065
14066                 aesni_ids[nb_devs_attached] = (uint8_t)i;
14067
14068                 nb_devs_attached++;
14069         }
14070
14071         return 0;
14072 }
14073
14074 static int
14075 test_scheduler_detach_worker_op(void)
14076 {
14077         struct crypto_testsuite_params *ts_params = &testsuite_params;
14078         uint8_t sched_id = ts_params->valid_devs[0];
14079         uint32_t i;
14080         int ret;
14081
14082         for (i = 0; i < 2; i++) {
14083                 ret = rte_cryptodev_scheduler_worker_detach(sched_id,
14084                                 aesni_ids[i]);
14085                 TEST_ASSERT(ret == 0,
14086                         "Failed to detach device %u", aesni_ids[i]);
14087         }
14088
14089         return 0;
14090 }
14091
14092 static int
14093 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
14094 {
14095         struct crypto_testsuite_params *ts_params = &testsuite_params;
14096         uint8_t sched_id = ts_params->valid_devs[0];
14097         /* set mode */
14098         return rte_cryptodev_scheduler_mode_set(sched_id,
14099                 scheduler_mode);
14100 }
14101
14102 static int
14103 test_scheduler_mode_roundrobin_op(void)
14104 {
14105         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
14106                         0, "Failed to set roundrobin mode");
14107         return 0;
14108
14109 }
14110
14111 static int
14112 test_scheduler_mode_multicore_op(void)
14113 {
14114         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
14115                         0, "Failed to set multicore mode");
14116
14117         return 0;
14118 }
14119
14120 static int
14121 test_scheduler_mode_failover_op(void)
14122 {
14123         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
14124                         0, "Failed to set failover mode");
14125
14126         return 0;
14127 }
14128
14129 static int
14130 test_scheduler_mode_pkt_size_distr_op(void)
14131 {
14132         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
14133                         0, "Failed to set pktsize mode");
14134
14135         return 0;
14136 }
14137
14138 static int
14139 scheduler_multicore_testsuite_setup(void)
14140 {
14141         if (test_scheduler_attach_worker_op() < 0)
14142                 return TEST_SKIPPED;
14143         if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
14144                 return TEST_SKIPPED;
14145         return 0;
14146 }
14147
14148 static int
14149 scheduler_roundrobin_testsuite_setup(void)
14150 {
14151         if (test_scheduler_attach_worker_op() < 0)
14152                 return TEST_SKIPPED;
14153         if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
14154                 return TEST_SKIPPED;
14155         return 0;
14156 }
14157
14158 static int
14159 scheduler_failover_testsuite_setup(void)
14160 {
14161         if (test_scheduler_attach_worker_op() < 0)
14162                 return TEST_SKIPPED;
14163         if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
14164                 return TEST_SKIPPED;
14165         return 0;
14166 }
14167
14168 static int
14169 scheduler_pkt_size_distr_testsuite_setup(void)
14170 {
14171         if (test_scheduler_attach_worker_op() < 0)
14172                 return TEST_SKIPPED;
14173         if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
14174                 return TEST_SKIPPED;
14175         return 0;
14176 }
14177
14178 static void
14179 scheduler_mode_testsuite_teardown(void)
14180 {
14181         test_scheduler_detach_worker_op();
14182 }
14183
14184 #endif /* RTE_CRYPTO_SCHEDULER */
14185
14186 static struct unit_test_suite end_testsuite = {
14187         .suite_name = NULL,
14188         .setup = NULL,
14189         .teardown = NULL,
14190         .unit_test_suites = NULL
14191 };
14192
14193 #ifdef RTE_LIB_SECURITY
14194 static struct unit_test_suite ipsec_proto_testsuite  = {
14195         .suite_name = "IPsec Proto Unit Test Suite",
14196         .setup = ipsec_proto_testsuite_setup,
14197         .unit_test_cases = {
14198                 TEST_CASE_NAMED_WITH_DATA(
14199                         "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14200                         ut_setup_security, ut_teardown,
14201                         test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
14202                 TEST_CASE_NAMED_WITH_DATA(
14203                         "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14204                         ut_setup_security, ut_teardown,
14205                         test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
14206                 TEST_CASE_NAMED_WITH_DATA(
14207                         "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14208                         ut_setup_security, ut_teardown,
14209                         test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
14210                 TEST_CASE_NAMED_WITH_DATA(
14211                         "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14212                         ut_setup_security, ut_teardown,
14213                         test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
14214                 TEST_CASE_NAMED_WITH_DATA(
14215                         "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14216                         ut_setup_security, ut_teardown,
14217                         test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
14218                 TEST_CASE_NAMED_WITH_DATA(
14219                         "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14220                         ut_setup_security, ut_teardown,
14221                         test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
14222                 TEST_CASE_NAMED_ST(
14223                         "Combined test alg list",
14224                         ut_setup_security, ut_teardown,
14225                         test_ipsec_proto_display_list),
14226                 TEST_CASE_NAMED_ST(
14227                         "IV generation",
14228                         ut_setup_security, ut_teardown,
14229                         test_ipsec_proto_iv_gen),
14230                 TEST_CASE_NAMED_ST(
14231                         "UDP encapsulation",
14232                         ut_setup_security, ut_teardown,
14233                         test_ipsec_proto_udp_encap),
14234                 TEST_CASE_NAMED_ST(
14235                         "UDP encapsulation ports verification test",
14236                         ut_setup_security, ut_teardown,
14237                         test_ipsec_proto_udp_ports_verify),
14238                 TEST_CASE_NAMED_ST(
14239                         "SA expiry packets soft",
14240                         ut_setup_security, ut_teardown,
14241                         test_ipsec_proto_sa_exp_pkts_soft),
14242                 TEST_CASE_NAMED_ST(
14243                         "SA expiry packets hard",
14244                         ut_setup_security, ut_teardown,
14245                         test_ipsec_proto_sa_exp_pkts_hard),
14246                 TEST_CASE_NAMED_ST(
14247                         "Negative test: ICV corruption",
14248                         ut_setup_security, ut_teardown,
14249                         test_ipsec_proto_err_icv_corrupt),
14250                 TEST_CASE_NAMED_ST(
14251                         "Tunnel dst addr verification",
14252                         ut_setup_security, ut_teardown,
14253                         test_ipsec_proto_tunnel_dst_addr_verify),
14254                 TEST_CASE_NAMED_ST(
14255                         "Tunnel src and dst addr verification",
14256                         ut_setup_security, ut_teardown,
14257                         test_ipsec_proto_tunnel_src_dst_addr_verify),
14258                 TEST_CASES_END() /**< NULL terminate unit test array */
14259         }
14260 };
14261
14262 static struct unit_test_suite pdcp_proto_testsuite  = {
14263         .suite_name = "PDCP Proto Unit Test Suite",
14264         .setup = pdcp_proto_testsuite_setup,
14265         .unit_test_cases = {
14266                 TEST_CASE_ST(ut_setup_security, ut_teardown,
14267                         test_PDCP_PROTO_all),
14268                 TEST_CASES_END() /**< NULL terminate unit test array */
14269         }
14270 };
14271
14272 static struct unit_test_suite docsis_proto_testsuite  = {
14273         .suite_name = "Docsis Proto Unit Test Suite",
14274         .setup = docsis_proto_testsuite_setup,
14275         .unit_test_cases = {
14276                 TEST_CASE_ST(ut_setup_security, ut_teardown,
14277                         test_DOCSIS_PROTO_all),
14278                 TEST_CASES_END() /**< NULL terminate unit test array */
14279         }
14280 };
14281 #endif
14282
14283 static struct unit_test_suite cryptodev_gen_testsuite  = {
14284         .suite_name = "Crypto General Unit Test Suite",
14285         .setup = crypto_gen_testsuite_setup,
14286         .unit_test_cases = {
14287                 TEST_CASE_ST(ut_setup, ut_teardown,
14288                                 test_device_configure_invalid_dev_id),
14289                 TEST_CASE_ST(ut_setup, ut_teardown,
14290                                 test_queue_pair_descriptor_setup),
14291                 TEST_CASE_ST(ut_setup, ut_teardown,
14292                                 test_device_configure_invalid_queue_pair_ids),
14293                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
14294                 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
14295                 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
14296                 TEST_CASES_END() /**< NULL terminate unit test array */
14297         }
14298 };
14299
14300 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
14301         .suite_name = "Negative HMAC SHA1 Unit Test Suite",
14302         .setup = negative_hmac_sha1_testsuite_setup,
14303         .unit_test_cases = {
14304                 /** Negative tests */
14305                 TEST_CASE_ST(ut_setup, ut_teardown,
14306                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
14307                 TEST_CASE_ST(ut_setup, ut_teardown,
14308                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
14309                 TEST_CASE_ST(ut_setup, ut_teardown,
14310                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
14311                 TEST_CASE_ST(ut_setup, ut_teardown,
14312                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
14313
14314                 TEST_CASES_END() /**< NULL terminate unit test array */
14315         }
14316 };
14317
14318 static struct unit_test_suite cryptodev_multi_session_testsuite = {
14319         .suite_name = "Multi Session Unit Test Suite",
14320         .setup = multi_session_testsuite_setup,
14321         .unit_test_cases = {
14322                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
14323                 TEST_CASE_ST(ut_setup, ut_teardown,
14324                                 test_multi_session_random_usage),
14325
14326                 TEST_CASES_END() /**< NULL terminate unit test array */
14327         }
14328 };
14329
14330 static struct unit_test_suite cryptodev_null_testsuite  = {
14331         .suite_name = "NULL Test Suite",
14332         .setup = null_testsuite_setup,
14333         .unit_test_cases = {
14334                 TEST_CASE_ST(ut_setup, ut_teardown,
14335                         test_null_invalid_operation),
14336                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
14337                 TEST_CASES_END()
14338         }
14339 };
14340
14341 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
14342         .suite_name = "AES CCM Authenticated Test Suite",
14343         .setup = aes_ccm_auth_testsuite_setup,
14344         .unit_test_cases = {
14345                 /** AES CCM Authenticated Encryption 128 bits key*/
14346                 TEST_CASE_ST(ut_setup, ut_teardown,
14347                         test_AES_CCM_authenticated_encryption_test_case_128_1),
14348                 TEST_CASE_ST(ut_setup, ut_teardown,
14349                         test_AES_CCM_authenticated_encryption_test_case_128_2),
14350                 TEST_CASE_ST(ut_setup, ut_teardown,
14351                         test_AES_CCM_authenticated_encryption_test_case_128_3),
14352
14353                 /** AES CCM Authenticated Decryption 128 bits key*/
14354                 TEST_CASE_ST(ut_setup, ut_teardown,
14355                         test_AES_CCM_authenticated_decryption_test_case_128_1),
14356                 TEST_CASE_ST(ut_setup, ut_teardown,
14357                         test_AES_CCM_authenticated_decryption_test_case_128_2),
14358                 TEST_CASE_ST(ut_setup, ut_teardown,
14359                         test_AES_CCM_authenticated_decryption_test_case_128_3),
14360
14361                 /** AES CCM Authenticated Encryption 192 bits key */
14362                 TEST_CASE_ST(ut_setup, ut_teardown,
14363                         test_AES_CCM_authenticated_encryption_test_case_192_1),
14364                 TEST_CASE_ST(ut_setup, ut_teardown,
14365                         test_AES_CCM_authenticated_encryption_test_case_192_2),
14366                 TEST_CASE_ST(ut_setup, ut_teardown,
14367                         test_AES_CCM_authenticated_encryption_test_case_192_3),
14368
14369                 /** AES CCM Authenticated Decryption 192 bits key*/
14370                 TEST_CASE_ST(ut_setup, ut_teardown,
14371                         test_AES_CCM_authenticated_decryption_test_case_192_1),
14372                 TEST_CASE_ST(ut_setup, ut_teardown,
14373                         test_AES_CCM_authenticated_decryption_test_case_192_2),
14374                 TEST_CASE_ST(ut_setup, ut_teardown,
14375                         test_AES_CCM_authenticated_decryption_test_case_192_3),
14376
14377                 /** AES CCM Authenticated Encryption 256 bits key */
14378                 TEST_CASE_ST(ut_setup, ut_teardown,
14379                         test_AES_CCM_authenticated_encryption_test_case_256_1),
14380                 TEST_CASE_ST(ut_setup, ut_teardown,
14381                         test_AES_CCM_authenticated_encryption_test_case_256_2),
14382                 TEST_CASE_ST(ut_setup, ut_teardown,
14383                         test_AES_CCM_authenticated_encryption_test_case_256_3),
14384
14385                 /** AES CCM Authenticated Decryption 256 bits key*/
14386                 TEST_CASE_ST(ut_setup, ut_teardown,
14387                         test_AES_CCM_authenticated_decryption_test_case_256_1),
14388                 TEST_CASE_ST(ut_setup, ut_teardown,
14389                         test_AES_CCM_authenticated_decryption_test_case_256_2),
14390                 TEST_CASE_ST(ut_setup, ut_teardown,
14391                         test_AES_CCM_authenticated_decryption_test_case_256_3),
14392                 TEST_CASES_END()
14393         }
14394 };
14395
14396 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
14397         .suite_name = "AES GCM Authenticated Test Suite",
14398         .setup = aes_gcm_auth_testsuite_setup,
14399         .unit_test_cases = {
14400                 /** AES GCM Authenticated Encryption */
14401                 TEST_CASE_ST(ut_setup, ut_teardown,
14402                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
14403                 TEST_CASE_ST(ut_setup, ut_teardown,
14404                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
14405                 TEST_CASE_ST(ut_setup, ut_teardown,
14406                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
14407                 TEST_CASE_ST(ut_setup, ut_teardown,
14408                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
14409                 TEST_CASE_ST(ut_setup, ut_teardown,
14410                         test_AES_GCM_authenticated_encryption_test_case_1),
14411                 TEST_CASE_ST(ut_setup, ut_teardown,
14412                         test_AES_GCM_authenticated_encryption_test_case_2),
14413                 TEST_CASE_ST(ut_setup, ut_teardown,
14414                         test_AES_GCM_authenticated_encryption_test_case_3),
14415                 TEST_CASE_ST(ut_setup, ut_teardown,
14416                         test_AES_GCM_authenticated_encryption_test_case_4),
14417                 TEST_CASE_ST(ut_setup, ut_teardown,
14418                         test_AES_GCM_authenticated_encryption_test_case_5),
14419                 TEST_CASE_ST(ut_setup, ut_teardown,
14420                         test_AES_GCM_authenticated_encryption_test_case_6),
14421                 TEST_CASE_ST(ut_setup, ut_teardown,
14422                         test_AES_GCM_authenticated_encryption_test_case_7),
14423                 TEST_CASE_ST(ut_setup, ut_teardown,
14424                         test_AES_GCM_authenticated_encryption_test_case_8),
14425                 TEST_CASE_ST(ut_setup, ut_teardown,
14426                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
14427
14428                 /** AES GCM Authenticated Decryption */
14429                 TEST_CASE_ST(ut_setup, ut_teardown,
14430                         test_AES_GCM_authenticated_decryption_test_case_1),
14431                 TEST_CASE_ST(ut_setup, ut_teardown,
14432                         test_AES_GCM_authenticated_decryption_test_case_2),
14433                 TEST_CASE_ST(ut_setup, ut_teardown,
14434                         test_AES_GCM_authenticated_decryption_test_case_3),
14435                 TEST_CASE_ST(ut_setup, ut_teardown,
14436                         test_AES_GCM_authenticated_decryption_test_case_4),
14437                 TEST_CASE_ST(ut_setup, ut_teardown,
14438                         test_AES_GCM_authenticated_decryption_test_case_5),
14439                 TEST_CASE_ST(ut_setup, ut_teardown,
14440                         test_AES_GCM_authenticated_decryption_test_case_6),
14441                 TEST_CASE_ST(ut_setup, ut_teardown,
14442                         test_AES_GCM_authenticated_decryption_test_case_7),
14443                 TEST_CASE_ST(ut_setup, ut_teardown,
14444                         test_AES_GCM_authenticated_decryption_test_case_8),
14445                 TEST_CASE_ST(ut_setup, ut_teardown,
14446                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
14447
14448                 /** AES GCM Authenticated Encryption 192 bits key */
14449                 TEST_CASE_ST(ut_setup, ut_teardown,
14450                         test_AES_GCM_auth_encryption_test_case_192_1),
14451                 TEST_CASE_ST(ut_setup, ut_teardown,
14452                         test_AES_GCM_auth_encryption_test_case_192_2),
14453                 TEST_CASE_ST(ut_setup, ut_teardown,
14454                         test_AES_GCM_auth_encryption_test_case_192_3),
14455                 TEST_CASE_ST(ut_setup, ut_teardown,
14456                         test_AES_GCM_auth_encryption_test_case_192_4),
14457                 TEST_CASE_ST(ut_setup, ut_teardown,
14458                         test_AES_GCM_auth_encryption_test_case_192_5),
14459                 TEST_CASE_ST(ut_setup, ut_teardown,
14460                         test_AES_GCM_auth_encryption_test_case_192_6),
14461                 TEST_CASE_ST(ut_setup, ut_teardown,
14462                         test_AES_GCM_auth_encryption_test_case_192_7),
14463
14464                 /** AES GCM Authenticated Decryption 192 bits key */
14465                 TEST_CASE_ST(ut_setup, ut_teardown,
14466                         test_AES_GCM_auth_decryption_test_case_192_1),
14467                 TEST_CASE_ST(ut_setup, ut_teardown,
14468                         test_AES_GCM_auth_decryption_test_case_192_2),
14469                 TEST_CASE_ST(ut_setup, ut_teardown,
14470                         test_AES_GCM_auth_decryption_test_case_192_3),
14471                 TEST_CASE_ST(ut_setup, ut_teardown,
14472                         test_AES_GCM_auth_decryption_test_case_192_4),
14473                 TEST_CASE_ST(ut_setup, ut_teardown,
14474                         test_AES_GCM_auth_decryption_test_case_192_5),
14475                 TEST_CASE_ST(ut_setup, ut_teardown,
14476                         test_AES_GCM_auth_decryption_test_case_192_6),
14477                 TEST_CASE_ST(ut_setup, ut_teardown,
14478                         test_AES_GCM_auth_decryption_test_case_192_7),
14479
14480                 /** AES GCM Authenticated Encryption 256 bits key */
14481                 TEST_CASE_ST(ut_setup, ut_teardown,
14482                         test_AES_GCM_auth_encryption_test_case_256_1),
14483                 TEST_CASE_ST(ut_setup, ut_teardown,
14484                         test_AES_GCM_auth_encryption_test_case_256_2),
14485                 TEST_CASE_ST(ut_setup, ut_teardown,
14486                         test_AES_GCM_auth_encryption_test_case_256_3),
14487                 TEST_CASE_ST(ut_setup, ut_teardown,
14488                         test_AES_GCM_auth_encryption_test_case_256_4),
14489                 TEST_CASE_ST(ut_setup, ut_teardown,
14490                         test_AES_GCM_auth_encryption_test_case_256_5),
14491                 TEST_CASE_ST(ut_setup, ut_teardown,
14492                         test_AES_GCM_auth_encryption_test_case_256_6),
14493                 TEST_CASE_ST(ut_setup, ut_teardown,
14494                         test_AES_GCM_auth_encryption_test_case_256_7),
14495
14496                 /** AES GCM Authenticated Decryption 256 bits key */
14497                 TEST_CASE_ST(ut_setup, ut_teardown,
14498                         test_AES_GCM_auth_decryption_test_case_256_1),
14499                 TEST_CASE_ST(ut_setup, ut_teardown,
14500                         test_AES_GCM_auth_decryption_test_case_256_2),
14501                 TEST_CASE_ST(ut_setup, ut_teardown,
14502                         test_AES_GCM_auth_decryption_test_case_256_3),
14503                 TEST_CASE_ST(ut_setup, ut_teardown,
14504                         test_AES_GCM_auth_decryption_test_case_256_4),
14505                 TEST_CASE_ST(ut_setup, ut_teardown,
14506                         test_AES_GCM_auth_decryption_test_case_256_5),
14507                 TEST_CASE_ST(ut_setup, ut_teardown,
14508                         test_AES_GCM_auth_decryption_test_case_256_6),
14509                 TEST_CASE_ST(ut_setup, ut_teardown,
14510                         test_AES_GCM_auth_decryption_test_case_256_7),
14511
14512                 /** AES GCM Authenticated Encryption big aad size */
14513                 TEST_CASE_ST(ut_setup, ut_teardown,
14514                         test_AES_GCM_auth_encryption_test_case_aad_1),
14515                 TEST_CASE_ST(ut_setup, ut_teardown,
14516                         test_AES_GCM_auth_encryption_test_case_aad_2),
14517
14518                 /** AES GCM Authenticated Decryption big aad size */
14519                 TEST_CASE_ST(ut_setup, ut_teardown,
14520                         test_AES_GCM_auth_decryption_test_case_aad_1),
14521                 TEST_CASE_ST(ut_setup, ut_teardown,
14522                         test_AES_GCM_auth_decryption_test_case_aad_2),
14523
14524                 /** Out of place tests */
14525                 TEST_CASE_ST(ut_setup, ut_teardown,
14526                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
14527                 TEST_CASE_ST(ut_setup, ut_teardown,
14528                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
14529
14530                 /** Session-less tests */
14531                 TEST_CASE_ST(ut_setup, ut_teardown,
14532                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
14533                 TEST_CASE_ST(ut_setup, ut_teardown,
14534                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
14535
14536                 TEST_CASES_END()
14537         }
14538 };
14539
14540 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
14541         .suite_name = "AES GMAC Authentication Test Suite",
14542         .setup = aes_gmac_auth_testsuite_setup,
14543         .unit_test_cases = {
14544                 TEST_CASE_ST(ut_setup, ut_teardown,
14545                         test_AES_GMAC_authentication_test_case_1),
14546                 TEST_CASE_ST(ut_setup, ut_teardown,
14547                         test_AES_GMAC_authentication_verify_test_case_1),
14548                 TEST_CASE_ST(ut_setup, ut_teardown,
14549                         test_AES_GMAC_authentication_test_case_2),
14550                 TEST_CASE_ST(ut_setup, ut_teardown,
14551                         test_AES_GMAC_authentication_verify_test_case_2),
14552                 TEST_CASE_ST(ut_setup, ut_teardown,
14553                         test_AES_GMAC_authentication_test_case_3),
14554                 TEST_CASE_ST(ut_setup, ut_teardown,
14555                         test_AES_GMAC_authentication_verify_test_case_3),
14556                 TEST_CASE_ST(ut_setup, ut_teardown,
14557                         test_AES_GMAC_authentication_test_case_4),
14558                 TEST_CASE_ST(ut_setup, ut_teardown,
14559                         test_AES_GMAC_authentication_verify_test_case_4),
14560                 TEST_CASE_ST(ut_setup, ut_teardown,
14561                         test_AES_GMAC_authentication_SGL_40B),
14562                 TEST_CASE_ST(ut_setup, ut_teardown,
14563                         test_AES_GMAC_authentication_SGL_80B),
14564                 TEST_CASE_ST(ut_setup, ut_teardown,
14565                         test_AES_GMAC_authentication_SGL_2048B),
14566                 TEST_CASE_ST(ut_setup, ut_teardown,
14567                         test_AES_GMAC_authentication_SGL_2047B),
14568
14569                 TEST_CASES_END()
14570         }
14571 };
14572
14573 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14574         .suite_name = "Chacha20-Poly1305 Test Suite",
14575         .setup = chacha20_poly1305_testsuite_setup,
14576         .unit_test_cases = {
14577                 TEST_CASE_ST(ut_setup, ut_teardown,
14578                         test_chacha20_poly1305_encrypt_test_case_rfc8439),
14579                 TEST_CASE_ST(ut_setup, ut_teardown,
14580                         test_chacha20_poly1305_decrypt_test_case_rfc8439),
14581                 TEST_CASES_END()
14582         }
14583 };
14584
14585 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14586         .suite_name = "SNOW 3G Test Suite",
14587         .setup = snow3g_testsuite_setup,
14588         .unit_test_cases = {
14589                 /** SNOW 3G encrypt only (UEA2) */
14590                 TEST_CASE_ST(ut_setup, ut_teardown,
14591                         test_snow3g_encryption_test_case_1),
14592                 TEST_CASE_ST(ut_setup, ut_teardown,
14593                         test_snow3g_encryption_test_case_2),
14594                 TEST_CASE_ST(ut_setup, ut_teardown,
14595                         test_snow3g_encryption_test_case_3),
14596                 TEST_CASE_ST(ut_setup, ut_teardown,
14597                         test_snow3g_encryption_test_case_4),
14598                 TEST_CASE_ST(ut_setup, ut_teardown,
14599                         test_snow3g_encryption_test_case_5),
14600
14601                 TEST_CASE_ST(ut_setup, ut_teardown,
14602                         test_snow3g_encryption_test_case_1_oop),
14603                 TEST_CASE_ST(ut_setup, ut_teardown,
14604                         test_snow3g_encryption_test_case_1_oop_sgl),
14605                 TEST_CASE_ST(ut_setup, ut_teardown,
14606                         test_snow3g_encryption_test_case_1_offset_oop),
14607                 TEST_CASE_ST(ut_setup, ut_teardown,
14608                         test_snow3g_decryption_test_case_1_oop),
14609
14610                 /** SNOW 3G generate auth, then encrypt (UEA2) */
14611                 TEST_CASE_ST(ut_setup, ut_teardown,
14612                         test_snow3g_auth_cipher_test_case_1),
14613                 TEST_CASE_ST(ut_setup, ut_teardown,
14614                         test_snow3g_auth_cipher_test_case_2),
14615                 TEST_CASE_ST(ut_setup, ut_teardown,
14616                         test_snow3g_auth_cipher_test_case_2_oop),
14617                 TEST_CASE_ST(ut_setup, ut_teardown,
14618                         test_snow3g_auth_cipher_part_digest_enc),
14619                 TEST_CASE_ST(ut_setup, ut_teardown,
14620                         test_snow3g_auth_cipher_part_digest_enc_oop),
14621                 TEST_CASE_ST(ut_setup, ut_teardown,
14622                         test_snow3g_auth_cipher_test_case_3_sgl),
14623                 TEST_CASE_ST(ut_setup, ut_teardown,
14624                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
14625                 TEST_CASE_ST(ut_setup, ut_teardown,
14626                         test_snow3g_auth_cipher_part_digest_enc_sgl),
14627                 TEST_CASE_ST(ut_setup, ut_teardown,
14628                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14629
14630                 /** SNOW 3G decrypt (UEA2), then verify auth */
14631                 TEST_CASE_ST(ut_setup, ut_teardown,
14632                         test_snow3g_auth_cipher_verify_test_case_1),
14633                 TEST_CASE_ST(ut_setup, ut_teardown,
14634                         test_snow3g_auth_cipher_verify_test_case_2),
14635                 TEST_CASE_ST(ut_setup, ut_teardown,
14636                         test_snow3g_auth_cipher_verify_test_case_2_oop),
14637                 TEST_CASE_ST(ut_setup, ut_teardown,
14638                         test_snow3g_auth_cipher_verify_part_digest_enc),
14639                 TEST_CASE_ST(ut_setup, ut_teardown,
14640                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14641                 TEST_CASE_ST(ut_setup, ut_teardown,
14642                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
14643                 TEST_CASE_ST(ut_setup, ut_teardown,
14644                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14645                 TEST_CASE_ST(ut_setup, ut_teardown,
14646                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14647                 TEST_CASE_ST(ut_setup, ut_teardown,
14648                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14649
14650                 /** SNOW 3G decrypt only (UEA2) */
14651                 TEST_CASE_ST(ut_setup, ut_teardown,
14652                         test_snow3g_decryption_test_case_1),
14653                 TEST_CASE_ST(ut_setup, ut_teardown,
14654                         test_snow3g_decryption_test_case_2),
14655                 TEST_CASE_ST(ut_setup, ut_teardown,
14656                         test_snow3g_decryption_test_case_3),
14657                 TEST_CASE_ST(ut_setup, ut_teardown,
14658                         test_snow3g_decryption_test_case_4),
14659                 TEST_CASE_ST(ut_setup, ut_teardown,
14660                         test_snow3g_decryption_test_case_5),
14661                 TEST_CASE_ST(ut_setup, ut_teardown,
14662                         test_snow3g_decryption_with_digest_test_case_1),
14663                 TEST_CASE_ST(ut_setup, ut_teardown,
14664                         test_snow3g_hash_generate_test_case_1),
14665                 TEST_CASE_ST(ut_setup, ut_teardown,
14666                         test_snow3g_hash_generate_test_case_2),
14667                 TEST_CASE_ST(ut_setup, ut_teardown,
14668                         test_snow3g_hash_generate_test_case_3),
14669
14670                 /* Tests with buffers which length is not byte-aligned */
14671                 TEST_CASE_ST(ut_setup, ut_teardown,
14672                         test_snow3g_hash_generate_test_case_4),
14673                 TEST_CASE_ST(ut_setup, ut_teardown,
14674                         test_snow3g_hash_generate_test_case_5),
14675                 TEST_CASE_ST(ut_setup, ut_teardown,
14676                         test_snow3g_hash_generate_test_case_6),
14677                 TEST_CASE_ST(ut_setup, ut_teardown,
14678                         test_snow3g_hash_verify_test_case_1),
14679                 TEST_CASE_ST(ut_setup, ut_teardown,
14680                         test_snow3g_hash_verify_test_case_2),
14681                 TEST_CASE_ST(ut_setup, ut_teardown,
14682                         test_snow3g_hash_verify_test_case_3),
14683
14684                 /* Tests with buffers which length is not byte-aligned */
14685                 TEST_CASE_ST(ut_setup, ut_teardown,
14686                         test_snow3g_hash_verify_test_case_4),
14687                 TEST_CASE_ST(ut_setup, ut_teardown,
14688                         test_snow3g_hash_verify_test_case_5),
14689                 TEST_CASE_ST(ut_setup, ut_teardown,
14690                         test_snow3g_hash_verify_test_case_6),
14691                 TEST_CASE_ST(ut_setup, ut_teardown,
14692                         test_snow3g_cipher_auth_test_case_1),
14693                 TEST_CASE_ST(ut_setup, ut_teardown,
14694                         test_snow3g_auth_cipher_with_digest_test_case_1),
14695                 TEST_CASES_END()
14696         }
14697 };
14698
14699 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14700         .suite_name = "ZUC Test Suite",
14701         .setup = zuc_testsuite_setup,
14702         .unit_test_cases = {
14703                 /** ZUC encrypt only (EEA3) */
14704                 TEST_CASE_ST(ut_setup, ut_teardown,
14705                         test_zuc_encryption_test_case_1),
14706                 TEST_CASE_ST(ut_setup, ut_teardown,
14707                         test_zuc_encryption_test_case_2),
14708                 TEST_CASE_ST(ut_setup, ut_teardown,
14709                         test_zuc_encryption_test_case_3),
14710                 TEST_CASE_ST(ut_setup, ut_teardown,
14711                         test_zuc_encryption_test_case_4),
14712                 TEST_CASE_ST(ut_setup, ut_teardown,
14713                         test_zuc_encryption_test_case_5),
14714                 TEST_CASE_ST(ut_setup, ut_teardown,
14715                         test_zuc_encryption_test_case_6_sgl),
14716                 TEST_CASE_ST(ut_setup, ut_teardown,
14717                         test_zuc_encryption_test_case_7),
14718
14719                 /** ZUC authenticate (EIA3) */
14720                 TEST_CASE_ST(ut_setup, ut_teardown,
14721                         test_zuc_hash_generate_test_case_1),
14722                 TEST_CASE_ST(ut_setup, ut_teardown,
14723                         test_zuc_hash_generate_test_case_2),
14724                 TEST_CASE_ST(ut_setup, ut_teardown,
14725                         test_zuc_hash_generate_test_case_3),
14726                 TEST_CASE_ST(ut_setup, ut_teardown,
14727                         test_zuc_hash_generate_test_case_4),
14728                 TEST_CASE_ST(ut_setup, ut_teardown,
14729                         test_zuc_hash_generate_test_case_5),
14730                 TEST_CASE_ST(ut_setup, ut_teardown,
14731                         test_zuc_hash_generate_test_case_6),
14732                 TEST_CASE_ST(ut_setup, ut_teardown,
14733                         test_zuc_hash_generate_test_case_7),
14734                 TEST_CASE_ST(ut_setup, ut_teardown,
14735                         test_zuc_hash_generate_test_case_8),
14736                 TEST_CASE_ST(ut_setup, ut_teardown,
14737                         test_zuc_hash_generate_test_case_9),
14738                 TEST_CASE_ST(ut_setup, ut_teardown,
14739                         test_zuc_hash_generate_test_case_10),
14740
14741
14742                 /** ZUC alg-chain (EEA3/EIA3) */
14743                 TEST_CASE_ST(ut_setup, ut_teardown,
14744                         test_zuc_cipher_auth_test_case_1),
14745                 TEST_CASE_ST(ut_setup, ut_teardown,
14746                         test_zuc_cipher_auth_test_case_2),
14747
14748                 /** ZUC generate auth, then encrypt (EEA3) */
14749                 TEST_CASE_ST(ut_setup, ut_teardown,
14750                         test_zuc_auth_cipher_test_case_1),
14751                 TEST_CASE_ST(ut_setup, ut_teardown,
14752                         test_zuc_auth_cipher_test_case_1_oop),
14753                 TEST_CASE_ST(ut_setup, ut_teardown,
14754                         test_zuc_auth_cipher_test_case_1_sgl),
14755                 TEST_CASE_ST(ut_setup, ut_teardown,
14756                         test_zuc_auth_cipher_test_case_1_oop_sgl),
14757
14758                 /** ZUC decrypt (EEA3), then verify auth */
14759                 TEST_CASE_ST(ut_setup, ut_teardown,
14760                         test_zuc_auth_cipher_verify_test_case_1),
14761                 TEST_CASE_ST(ut_setup, ut_teardown,
14762                         test_zuc_auth_cipher_verify_test_case_1_oop),
14763                 TEST_CASE_ST(ut_setup, ut_teardown,
14764                         test_zuc_auth_cipher_verify_test_case_1_sgl),
14765                 TEST_CASE_ST(ut_setup, ut_teardown,
14766                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
14767                 TEST_CASES_END()
14768         }
14769 };
14770
14771 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
14772         .suite_name = "HMAC_MD5 Authentication Test Suite",
14773         .setup = hmac_md5_auth_testsuite_setup,
14774         .unit_test_cases = {
14775                 TEST_CASE_ST(ut_setup, ut_teardown,
14776                         test_MD5_HMAC_generate_case_1),
14777                 TEST_CASE_ST(ut_setup, ut_teardown,
14778                         test_MD5_HMAC_verify_case_1),
14779                 TEST_CASE_ST(ut_setup, ut_teardown,
14780                         test_MD5_HMAC_generate_case_2),
14781                 TEST_CASE_ST(ut_setup, ut_teardown,
14782                         test_MD5_HMAC_verify_case_2),
14783                 TEST_CASES_END()
14784         }
14785 };
14786
14787 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
14788         .suite_name = "Kasumi Test Suite",
14789         .setup = kasumi_testsuite_setup,
14790         .unit_test_cases = {
14791                 /** KASUMI hash only (UIA1) */
14792                 TEST_CASE_ST(ut_setup, ut_teardown,
14793                         test_kasumi_hash_generate_test_case_1),
14794                 TEST_CASE_ST(ut_setup, ut_teardown,
14795                         test_kasumi_hash_generate_test_case_2),
14796                 TEST_CASE_ST(ut_setup, ut_teardown,
14797                         test_kasumi_hash_generate_test_case_3),
14798                 TEST_CASE_ST(ut_setup, ut_teardown,
14799                         test_kasumi_hash_generate_test_case_4),
14800                 TEST_CASE_ST(ut_setup, ut_teardown,
14801                         test_kasumi_hash_generate_test_case_5),
14802                 TEST_CASE_ST(ut_setup, ut_teardown,
14803                         test_kasumi_hash_generate_test_case_6),
14804
14805                 TEST_CASE_ST(ut_setup, ut_teardown,
14806                         test_kasumi_hash_verify_test_case_1),
14807                 TEST_CASE_ST(ut_setup, ut_teardown,
14808                         test_kasumi_hash_verify_test_case_2),
14809                 TEST_CASE_ST(ut_setup, ut_teardown,
14810                         test_kasumi_hash_verify_test_case_3),
14811                 TEST_CASE_ST(ut_setup, ut_teardown,
14812                         test_kasumi_hash_verify_test_case_4),
14813                 TEST_CASE_ST(ut_setup, ut_teardown,
14814                         test_kasumi_hash_verify_test_case_5),
14815
14816                 /** KASUMI encrypt only (UEA1) */
14817                 TEST_CASE_ST(ut_setup, ut_teardown,
14818                         test_kasumi_encryption_test_case_1),
14819                 TEST_CASE_ST(ut_setup, ut_teardown,
14820                         test_kasumi_encryption_test_case_1_sgl),
14821                 TEST_CASE_ST(ut_setup, ut_teardown,
14822                         test_kasumi_encryption_test_case_1_oop),
14823                 TEST_CASE_ST(ut_setup, ut_teardown,
14824                         test_kasumi_encryption_test_case_1_oop_sgl),
14825                 TEST_CASE_ST(ut_setup, ut_teardown,
14826                         test_kasumi_encryption_test_case_2),
14827                 TEST_CASE_ST(ut_setup, ut_teardown,
14828                         test_kasumi_encryption_test_case_3),
14829                 TEST_CASE_ST(ut_setup, ut_teardown,
14830                         test_kasumi_encryption_test_case_4),
14831                 TEST_CASE_ST(ut_setup, ut_teardown,
14832                         test_kasumi_encryption_test_case_5),
14833
14834                 /** KASUMI decrypt only (UEA1) */
14835                 TEST_CASE_ST(ut_setup, ut_teardown,
14836                         test_kasumi_decryption_test_case_1),
14837                 TEST_CASE_ST(ut_setup, ut_teardown,
14838                         test_kasumi_decryption_test_case_2),
14839                 TEST_CASE_ST(ut_setup, ut_teardown,
14840                         test_kasumi_decryption_test_case_3),
14841                 TEST_CASE_ST(ut_setup, ut_teardown,
14842                         test_kasumi_decryption_test_case_4),
14843                 TEST_CASE_ST(ut_setup, ut_teardown,
14844                         test_kasumi_decryption_test_case_5),
14845                 TEST_CASE_ST(ut_setup, ut_teardown,
14846                         test_kasumi_decryption_test_case_1_oop),
14847                 TEST_CASE_ST(ut_setup, ut_teardown,
14848                         test_kasumi_cipher_auth_test_case_1),
14849
14850                 /** KASUMI generate auth, then encrypt (F8) */
14851                 TEST_CASE_ST(ut_setup, ut_teardown,
14852                         test_kasumi_auth_cipher_test_case_1),
14853                 TEST_CASE_ST(ut_setup, ut_teardown,
14854                         test_kasumi_auth_cipher_test_case_2),
14855                 TEST_CASE_ST(ut_setup, ut_teardown,
14856                         test_kasumi_auth_cipher_test_case_2_oop),
14857                 TEST_CASE_ST(ut_setup, ut_teardown,
14858                         test_kasumi_auth_cipher_test_case_2_sgl),
14859                 TEST_CASE_ST(ut_setup, ut_teardown,
14860                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
14861
14862                 /** KASUMI decrypt (F8), then verify auth */
14863                 TEST_CASE_ST(ut_setup, ut_teardown,
14864                         test_kasumi_auth_cipher_verify_test_case_1),
14865                 TEST_CASE_ST(ut_setup, ut_teardown,
14866                         test_kasumi_auth_cipher_verify_test_case_2),
14867                 TEST_CASE_ST(ut_setup, ut_teardown,
14868                         test_kasumi_auth_cipher_verify_test_case_2_oop),
14869                 TEST_CASE_ST(ut_setup, ut_teardown,
14870                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
14871                 TEST_CASE_ST(ut_setup, ut_teardown,
14872                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
14873
14874                 TEST_CASES_END()
14875         }
14876 };
14877
14878 static struct unit_test_suite cryptodev_esn_testsuite  = {
14879         .suite_name = "ESN Test Suite",
14880         .setup = esn_testsuite_setup,
14881         .unit_test_cases = {
14882                 TEST_CASE_ST(ut_setup, ut_teardown,
14883                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
14884                 TEST_CASE_ST(ut_setup, ut_teardown,
14885                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
14886                 TEST_CASES_END()
14887         }
14888 };
14889
14890 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
14891         .suite_name = "Negative AES GCM Test Suite",
14892         .setup = negative_aes_gcm_testsuite_setup,
14893         .unit_test_cases = {
14894                 TEST_CASE_ST(ut_setup, ut_teardown,
14895                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
14896                 TEST_CASE_ST(ut_setup, ut_teardown,
14897                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
14898                 TEST_CASE_ST(ut_setup, ut_teardown,
14899                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
14900                 TEST_CASE_ST(ut_setup, ut_teardown,
14901                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
14902                 TEST_CASE_ST(ut_setup, ut_teardown,
14903                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
14904                 TEST_CASE_ST(ut_setup, ut_teardown,
14905                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
14906                 TEST_CASE_ST(ut_setup, ut_teardown,
14907                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
14908                 TEST_CASE_ST(ut_setup, ut_teardown,
14909                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
14910                 TEST_CASE_ST(ut_setup, ut_teardown,
14911                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
14912                 TEST_CASE_ST(ut_setup, ut_teardown,
14913                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
14914                 TEST_CASE_ST(ut_setup, ut_teardown,
14915                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
14916                 TEST_CASE_ST(ut_setup, ut_teardown,
14917                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
14918
14919                 TEST_CASES_END()
14920         }
14921 };
14922
14923 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
14924         .suite_name = "Negative AES GMAC Test Suite",
14925         .setup = negative_aes_gmac_testsuite_setup,
14926         .unit_test_cases = {
14927                 TEST_CASE_ST(ut_setup, ut_teardown,
14928                         authentication_verify_AES128_GMAC_fail_data_corrupt),
14929                 TEST_CASE_ST(ut_setup, ut_teardown,
14930                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
14931
14932                 TEST_CASES_END()
14933         }
14934 };
14935
14936 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
14937         .suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
14938         .setup = mixed_cipher_hash_testsuite_setup,
14939         .unit_test_cases = {
14940                 /** AUTH AES CMAC + CIPHER AES CTR */
14941                 TEST_CASE_ST(ut_setup, ut_teardown,
14942                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
14943                 TEST_CASE_ST(ut_setup, ut_teardown,
14944                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14945                 TEST_CASE_ST(ut_setup, ut_teardown,
14946                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14947                 TEST_CASE_ST(ut_setup, ut_teardown,
14948                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14949                 TEST_CASE_ST(ut_setup, ut_teardown,
14950                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
14951                 TEST_CASE_ST(ut_setup, ut_teardown,
14952                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14953                 TEST_CASE_ST(ut_setup, ut_teardown,
14954                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14955                 TEST_CASE_ST(ut_setup, ut_teardown,
14956                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14957
14958                 /** AUTH ZUC + CIPHER SNOW3G */
14959                 TEST_CASE_ST(ut_setup, ut_teardown,
14960                         test_auth_zuc_cipher_snow_test_case_1),
14961                 TEST_CASE_ST(ut_setup, ut_teardown,
14962                         test_verify_auth_zuc_cipher_snow_test_case_1),
14963                 /** AUTH AES CMAC + CIPHER SNOW3G */
14964                 TEST_CASE_ST(ut_setup, ut_teardown,
14965                         test_auth_aes_cmac_cipher_snow_test_case_1),
14966                 TEST_CASE_ST(ut_setup, ut_teardown,
14967                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
14968                 /** AUTH ZUC + CIPHER AES CTR */
14969                 TEST_CASE_ST(ut_setup, ut_teardown,
14970                         test_auth_zuc_cipher_aes_ctr_test_case_1),
14971                 TEST_CASE_ST(ut_setup, ut_teardown,
14972                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
14973                 /** AUTH SNOW3G + CIPHER AES CTR */
14974                 TEST_CASE_ST(ut_setup, ut_teardown,
14975                         test_auth_snow_cipher_aes_ctr_test_case_1),
14976                 TEST_CASE_ST(ut_setup, ut_teardown,
14977                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
14978                 /** AUTH SNOW3G + CIPHER ZUC */
14979                 TEST_CASE_ST(ut_setup, ut_teardown,
14980                         test_auth_snow_cipher_zuc_test_case_1),
14981                 TEST_CASE_ST(ut_setup, ut_teardown,
14982                         test_verify_auth_snow_cipher_zuc_test_case_1),
14983                 /** AUTH AES CMAC + CIPHER ZUC */
14984                 TEST_CASE_ST(ut_setup, ut_teardown,
14985                         test_auth_aes_cmac_cipher_zuc_test_case_1),
14986                 TEST_CASE_ST(ut_setup, ut_teardown,
14987                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
14988
14989                 /** AUTH NULL + CIPHER SNOW3G */
14990                 TEST_CASE_ST(ut_setup, ut_teardown,
14991                         test_auth_null_cipher_snow_test_case_1),
14992                 TEST_CASE_ST(ut_setup, ut_teardown,
14993                         test_verify_auth_null_cipher_snow_test_case_1),
14994                 /** AUTH NULL + CIPHER ZUC */
14995                 TEST_CASE_ST(ut_setup, ut_teardown,
14996                         test_auth_null_cipher_zuc_test_case_1),
14997                 TEST_CASE_ST(ut_setup, ut_teardown,
14998                         test_verify_auth_null_cipher_zuc_test_case_1),
14999                 /** AUTH SNOW3G + CIPHER NULL */
15000                 TEST_CASE_ST(ut_setup, ut_teardown,
15001                         test_auth_snow_cipher_null_test_case_1),
15002                 TEST_CASE_ST(ut_setup, ut_teardown,
15003                         test_verify_auth_snow_cipher_null_test_case_1),
15004                 /** AUTH ZUC + CIPHER NULL */
15005                 TEST_CASE_ST(ut_setup, ut_teardown,
15006                         test_auth_zuc_cipher_null_test_case_1),
15007                 TEST_CASE_ST(ut_setup, ut_teardown,
15008                         test_verify_auth_zuc_cipher_null_test_case_1),
15009                 /** AUTH NULL + CIPHER AES CTR */
15010                 TEST_CASE_ST(ut_setup, ut_teardown,
15011                         test_auth_null_cipher_aes_ctr_test_case_1),
15012                 TEST_CASE_ST(ut_setup, ut_teardown,
15013                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
15014                 /** AUTH AES CMAC + CIPHER NULL */
15015                 TEST_CASE_ST(ut_setup, ut_teardown,
15016                         test_auth_aes_cmac_cipher_null_test_case_1),
15017                 TEST_CASE_ST(ut_setup, ut_teardown,
15018                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
15019                 TEST_CASES_END()
15020         }
15021 };
15022
15023 static int
15024 run_cryptodev_testsuite(const char *pmd_name)
15025 {
15026         uint8_t ret, j, i = 0, blk_start_idx = 0;
15027         const enum blockcipher_test_type blk_suites[] = {
15028                 BLKCIPHER_AES_CHAIN_TYPE,
15029                 BLKCIPHER_AES_CIPHERONLY_TYPE,
15030                 BLKCIPHER_AES_DOCSIS_TYPE,
15031                 BLKCIPHER_3DES_CHAIN_TYPE,
15032                 BLKCIPHER_3DES_CIPHERONLY_TYPE,
15033                 BLKCIPHER_DES_CIPHERONLY_TYPE,
15034                 BLKCIPHER_DES_DOCSIS_TYPE,
15035                 BLKCIPHER_AUTHONLY_TYPE};
15036         struct unit_test_suite *static_suites[] = {
15037                 &cryptodev_multi_session_testsuite,
15038                 &cryptodev_null_testsuite,
15039                 &cryptodev_aes_ccm_auth_testsuite,
15040                 &cryptodev_aes_gcm_auth_testsuite,
15041                 &cryptodev_aes_gmac_auth_testsuite,
15042                 &cryptodev_snow3g_testsuite,
15043                 &cryptodev_chacha20_poly1305_testsuite,
15044                 &cryptodev_zuc_testsuite,
15045                 &cryptodev_hmac_md5_auth_testsuite,
15046                 &cryptodev_kasumi_testsuite,
15047                 &cryptodev_esn_testsuite,
15048                 &cryptodev_negative_aes_gcm_testsuite,
15049                 &cryptodev_negative_aes_gmac_testsuite,
15050                 &cryptodev_mixed_cipher_hash_testsuite,
15051                 &cryptodev_negative_hmac_sha1_testsuite,
15052                 &cryptodev_gen_testsuite,
15053 #ifdef RTE_LIB_SECURITY
15054                 &ipsec_proto_testsuite,
15055                 &pdcp_proto_testsuite,
15056                 &docsis_proto_testsuite,
15057 #endif
15058                 &end_testsuite
15059         };
15060         static struct unit_test_suite ts = {
15061                 .suite_name = "Cryptodev Unit Test Suite",
15062                 .setup = testsuite_setup,
15063                 .teardown = testsuite_teardown,
15064                 .unit_test_cases = {TEST_CASES_END()}
15065         };
15066
15067         gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
15068
15069         if (gbl_driver_id == -1) {
15070                 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
15071                 return TEST_SKIPPED;
15072         }
15073
15074         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15075                         (RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
15076
15077         ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
15078         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15079         ret = unit_test_suite_runner(&ts);
15080
15081         FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
15082         free(ts.unit_test_suites);
15083         return ret;
15084 }
15085
15086 static int
15087 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
15088 {
15089         struct rte_cryptodev_info dev_info;
15090         uint8_t i, nb_devs;
15091         int driver_id;
15092
15093         driver_id = rte_cryptodev_driver_id_get(pmd_name);
15094         if (driver_id == -1) {
15095                 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
15096                 return TEST_SKIPPED;
15097         }
15098
15099         nb_devs = rte_cryptodev_count();
15100         if (nb_devs < 1) {
15101                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
15102                 return TEST_SKIPPED;
15103         }
15104
15105         for (i = 0; i < nb_devs; i++) {
15106                 rte_cryptodev_info_get(i, &dev_info);
15107                 if (dev_info.driver_id == driver_id) {
15108                         if (!(dev_info.feature_flags & flag)) {
15109                                 RTE_LOG(INFO, USER1, "%s not supported\n",
15110                                                 flag_name);
15111                                 return TEST_SKIPPED;
15112                         }
15113                         return 0; /* found */
15114                 }
15115         }
15116
15117         RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
15118         return TEST_SKIPPED;
15119 }
15120
15121 static int
15122 test_cryptodev_qat(void)
15123 {
15124         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
15125 }
15126
15127 static int
15128 test_cryptodev_virtio(void)
15129 {
15130         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
15131 }
15132
15133 static int
15134 test_cryptodev_aesni_mb(void)
15135 {
15136         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15137 }
15138
15139 static int
15140 test_cryptodev_cpu_aesni_mb(void)
15141 {
15142         int32_t rc;
15143         enum rte_security_session_action_type at = gbl_action_type;
15144         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15145         rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15146         gbl_action_type = at;
15147         return rc;
15148 }
15149
15150 static int
15151 test_cryptodev_openssl(void)
15152 {
15153         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
15154 }
15155
15156 static int
15157 test_cryptodev_aesni_gcm(void)
15158 {
15159         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15160 }
15161
15162 static int
15163 test_cryptodev_cpu_aesni_gcm(void)
15164 {
15165         int32_t rc;
15166         enum rte_security_session_action_type at = gbl_action_type;
15167         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15168         rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15169         gbl_action_type = at;
15170         return rc;
15171 }
15172
15173 static int
15174 test_cryptodev_mlx5(void)
15175 {
15176         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
15177 }
15178
15179 static int
15180 test_cryptodev_null(void)
15181 {
15182         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
15183 }
15184
15185 static int
15186 test_cryptodev_sw_snow3g(void)
15187 {
15188         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
15189 }
15190
15191 static int
15192 test_cryptodev_sw_kasumi(void)
15193 {
15194         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
15195 }
15196
15197 static int
15198 test_cryptodev_sw_zuc(void)
15199 {
15200         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
15201 }
15202
15203 static int
15204 test_cryptodev_armv8(void)
15205 {
15206         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
15207 }
15208
15209 static int
15210 test_cryptodev_mrvl(void)
15211 {
15212         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
15213 }
15214
15215 #ifdef RTE_CRYPTO_SCHEDULER
15216
15217 static int
15218 test_cryptodev_scheduler(void)
15219 {
15220         uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
15221         const enum blockcipher_test_type blk_suites[] = {
15222                 BLKCIPHER_AES_CHAIN_TYPE,
15223                 BLKCIPHER_AES_CIPHERONLY_TYPE,
15224                 BLKCIPHER_AUTHONLY_TYPE
15225         };
15226         static struct unit_test_suite scheduler_multicore = {
15227                 .suite_name = "Scheduler Multicore Unit Test Suite",
15228                 .setup = scheduler_multicore_testsuite_setup,
15229                 .teardown = scheduler_mode_testsuite_teardown,
15230                 .unit_test_cases = {TEST_CASES_END()}
15231         };
15232         static struct unit_test_suite scheduler_round_robin = {
15233                 .suite_name = "Scheduler Round Robin Unit Test Suite",
15234                 .setup = scheduler_roundrobin_testsuite_setup,
15235                 .teardown = scheduler_mode_testsuite_teardown,
15236                 .unit_test_cases = {TEST_CASES_END()}
15237         };
15238         static struct unit_test_suite scheduler_failover = {
15239                 .suite_name = "Scheduler Failover Unit Test Suite",
15240                 .setup = scheduler_failover_testsuite_setup,
15241                 .teardown = scheduler_mode_testsuite_teardown,
15242                 .unit_test_cases = {TEST_CASES_END()}
15243         };
15244         static struct unit_test_suite scheduler_pkt_size_distr = {
15245                 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
15246                 .setup = scheduler_pkt_size_distr_testsuite_setup,
15247                 .teardown = scheduler_mode_testsuite_teardown,
15248                 .unit_test_cases = {TEST_CASES_END()}
15249         };
15250         struct unit_test_suite *sched_mode_suites[] = {
15251                 &scheduler_multicore,
15252                 &scheduler_round_robin,
15253                 &scheduler_failover,
15254                 &scheduler_pkt_size_distr
15255         };
15256         static struct unit_test_suite scheduler_config = {
15257                 .suite_name = "Crypto Device Scheduler Config Unit Test Suite",
15258                 .unit_test_cases = {
15259                         TEST_CASE(test_scheduler_attach_worker_op),
15260                         TEST_CASE(test_scheduler_mode_multicore_op),
15261                         TEST_CASE(test_scheduler_mode_roundrobin_op),
15262                         TEST_CASE(test_scheduler_mode_failover_op),
15263                         TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
15264                         TEST_CASE(test_scheduler_detach_worker_op),
15265
15266                         TEST_CASES_END() /**< NULL terminate array */
15267                 }
15268         };
15269         struct unit_test_suite *static_suites[] = {
15270                 &scheduler_config,
15271                 &end_testsuite
15272         };
15273         static struct unit_test_suite ts = {
15274                 .suite_name = "Scheduler Unit Test Suite",
15275                 .setup = scheduler_testsuite_setup,
15276                 .teardown = testsuite_teardown,
15277                 .unit_test_cases = {TEST_CASES_END()}
15278         };
15279
15280         gbl_driver_id = rte_cryptodev_driver_id_get(
15281                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
15282
15283         if (gbl_driver_id == -1) {
15284                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
15285                 return TEST_SKIPPED;
15286         }
15287
15288         if (rte_cryptodev_driver_id_get(
15289                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
15290                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
15291                 return TEST_SKIPPED;
15292         }
15293
15294         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15295                 uint8_t blk_i = 0;
15296                 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
15297                                 (struct unit_test_suite *) *
15298                                 (RTE_DIM(blk_suites) + 1));
15299                 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
15300                                 blk_suites, RTE_DIM(blk_suites));
15301                 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
15302         }
15303
15304         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15305                         (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
15306         ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
15307                         RTE_DIM(sched_mode_suites));
15308         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15309         ret = unit_test_suite_runner(&ts);
15310
15311         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15312                 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
15313                                 (*sched_mode_suites[sched_i]),
15314                                 RTE_DIM(blk_suites));
15315                 free(sched_mode_suites[sched_i]->unit_test_suites);
15316         }
15317         free(ts.unit_test_suites);
15318         return ret;
15319 }
15320
15321 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
15322
15323 #endif
15324
15325 static int
15326 test_cryptodev_dpaa2_sec(void)
15327 {
15328         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
15329 }
15330
15331 static int
15332 test_cryptodev_dpaa_sec(void)
15333 {
15334         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
15335 }
15336
15337 static int
15338 test_cryptodev_ccp(void)
15339 {
15340         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
15341 }
15342
15343 static int
15344 test_cryptodev_octeontx(void)
15345 {
15346         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
15347 }
15348
15349 static int
15350 test_cryptodev_octeontx2(void)
15351 {
15352         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
15353 }
15354
15355 static int
15356 test_cryptodev_caam_jr(void)
15357 {
15358         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
15359 }
15360
15361 static int
15362 test_cryptodev_nitrox(void)
15363 {
15364         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
15365 }
15366
15367 static int
15368 test_cryptodev_bcmfs(void)
15369 {
15370         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
15371 }
15372
15373 static int
15374 test_cryptodev_qat_raw_api(void)
15375 {
15376         static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
15377         int ret;
15378
15379         ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15380                         "RAW API");
15381         if (ret)
15382                 return ret;
15383
15384         global_api_test_type = CRYPTODEV_RAW_API_TEST;
15385         ret = run_cryptodev_testsuite(pmd_name);
15386         global_api_test_type = CRYPTODEV_API_TEST;
15387
15388         return ret;
15389 }
15390
15391 static int
15392 test_cryptodev_cn9k(void)
15393 {
15394         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
15395 }
15396
15397 static int
15398 test_cryptodev_cn10k(void)
15399 {
15400         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
15401 }
15402
15403 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
15404                 test_cryptodev_qat_raw_api);
15405 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
15406 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
15407 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
15408         test_cryptodev_cpu_aesni_mb);
15409 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
15410 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
15411 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
15412         test_cryptodev_cpu_aesni_gcm);
15413 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
15414 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
15415 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
15416 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
15417 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
15418 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
15419 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
15420 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
15421 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
15422 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
15423 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
15424 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
15425 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
15426 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
15427 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
15428 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
15429 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
15430 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);