test/crypto: add raw API test for dpaax
[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 #include <rte_tcp.h>
22 #include <rte_udp.h>
23
24 #ifdef RTE_CRYPTO_SCHEDULER
25 #include <rte_cryptodev_scheduler.h>
26 #include <rte_cryptodev_scheduler_operations.h>
27 #endif
28
29 #include <rte_lcore.h>
30
31 #include "test.h"
32 #include "test_cryptodev.h"
33
34 #include "test_cryptodev_blockcipher.h"
35 #include "test_cryptodev_aes_test_vectors.h"
36 #include "test_cryptodev_des_test_vectors.h"
37 #include "test_cryptodev_hash_test_vectors.h"
38 #include "test_cryptodev_kasumi_test_vectors.h"
39 #include "test_cryptodev_kasumi_hash_test_vectors.h"
40 #include "test_cryptodev_snow3g_test_vectors.h"
41 #include "test_cryptodev_snow3g_hash_test_vectors.h"
42 #include "test_cryptodev_zuc_test_vectors.h"
43 #include "test_cryptodev_aead_test_vectors.h"
44 #include "test_cryptodev_hmac_test_vectors.h"
45 #include "test_cryptodev_mixed_test_vectors.h"
46 #ifdef RTE_LIB_SECURITY
47 #include "test_cryptodev_security_ipsec.h"
48 #include "test_cryptodev_security_ipsec_test_vectors.h"
49 #include "test_cryptodev_security_pdcp_test_vectors.h"
50 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
51 #include "test_cryptodev_security_pdcp_test_func.h"
52 #include "test_cryptodev_security_docsis_test_vectors.h"
53
54 #define SDAP_DISABLED   0
55 #define SDAP_ENABLED    1
56 #endif
57
58 #define VDEV_ARGS_SIZE 100
59 #define MAX_NB_SESSIONS 4
60
61 #define MAX_DRV_SERVICE_CTX_SIZE 256
62
63 #define MAX_RAW_DEQUEUE_COUNT   65535
64
65 #define IN_PLACE 0
66 #define OUT_OF_PLACE 1
67
68 static int gbl_driver_id;
69
70 static enum rte_security_session_action_type gbl_action_type =
71         RTE_SECURITY_ACTION_TYPE_NONE;
72
73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
74
75 struct crypto_unittest_params {
76         struct rte_crypto_sym_xform cipher_xform;
77         struct rte_crypto_sym_xform auth_xform;
78         struct rte_crypto_sym_xform aead_xform;
79 #ifdef RTE_LIB_SECURITY
80         struct rte_security_docsis_xform docsis_xform;
81 #endif
82
83         union {
84                 struct rte_cryptodev_sym_session *sess;
85 #ifdef RTE_LIB_SECURITY
86                 struct rte_security_session *sec_session;
87 #endif
88         };
89 #ifdef RTE_LIB_SECURITY
90         enum rte_security_session_action_type type;
91 #endif
92         struct rte_crypto_op *op;
93
94         struct rte_mbuf *obuf, *ibuf;
95
96         uint8_t *digest;
97 };
98
99 #define ALIGN_POW2_ROUNDUP(num, align) \
100         (((num) + (align) - 1) & ~((align) - 1))
101
102 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)  \
103         for (j = 0; j < num_child_ts; index++, j++)                     \
104                 parent_ts.unit_test_suites[index] = child_ts[j]
105
106 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)   \
107         for (j = 0; j < num_blk_types; index++, j++)                            \
108                 parent_ts.unit_test_suites[index] =                             \
109                                 build_blockcipher_test_suite(blk_types[j])
110
111 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)             \
112         for (j = index; j < index + num_blk_types; j++)                         \
113                 free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
114
115 /*
116  * Forward declarations.
117  */
118 static int
119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
120                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
121                 uint8_t *hmac_key);
122
123 static int
124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
125                 struct crypto_unittest_params *ut_params,
126                 struct crypto_testsuite_params *ts_param,
127                 const uint8_t *cipher,
128                 const uint8_t *digest,
129                 const uint8_t *iv);
130
131 static int
132 security_proto_supported(enum rte_security_session_action_type action,
133         enum rte_security_session_protocol proto);
134
135 static int
136 dev_configure_and_start(uint64_t ff_disable);
137
138 static struct rte_mbuf *
139 setup_test_string(struct rte_mempool *mpool,
140                 const char *string, size_t len, uint8_t blocksize)
141 {
142         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
143         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
144
145         if (m) {
146                 char *dst;
147
148                 memset(m->buf_addr, 0, m->buf_len);
149                 dst = rte_pktmbuf_append(m, t_len);
150                 if (!dst) {
151                         rte_pktmbuf_free(m);
152                         return NULL;
153                 }
154                 if (string != NULL)
155                         rte_memcpy(dst, string, t_len);
156                 else
157                         memset(dst, 0, t_len);
158         }
159
160         return m;
161 }
162
163 /* Get number of bytes in X bits (rounding up) */
164 static uint32_t
165 ceil_byte_length(uint32_t num_bits)
166 {
167         if (num_bits % 8)
168                 return ((num_bits >> 3) + 1);
169         else
170                 return (num_bits >> 3);
171 }
172
173 static void
174 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused,
175                 uint8_t is_op_success)
176 {
177         struct rte_crypto_op *op = user_data;
178         op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
179                         RTE_CRYPTO_OP_STATUS_ERROR;
180 }
181
182 void
183 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
184                 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
185                 uint8_t len_in_bits, uint8_t cipher_iv_len)
186 {
187         struct rte_crypto_sym_op *sop = op->sym;
188         struct rte_crypto_op *ret_op = NULL;
189         struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX];
190         struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
191         union rte_crypto_sym_ofs ofs;
192         struct rte_crypto_sym_vec vec;
193         struct rte_crypto_sgl sgl, dest_sgl;
194         uint32_t max_len;
195         union rte_cryptodev_session_ctx sess;
196         uint32_t count = 0;
197         struct rte_crypto_raw_dp_ctx *ctx;
198         uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
199                         auth_len = 0;
200         int32_t n;
201         uint32_t n_success;
202         int ctx_service_size;
203         int32_t status = 0;
204         int enqueue_status, dequeue_status;
205
206         ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
207         if (ctx_service_size < 0) {
208                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
209                 return;
210         }
211
212         ctx = malloc(ctx_service_size);
213         if (!ctx) {
214                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
215                 return;
216         }
217
218         /* Both are enums, setting crypto_sess will suit any session type */
219         sess.crypto_sess = op->sym->session;
220
221         if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
222                         op->sess_type, sess, 0) < 0) {
223                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
224                 goto exit;
225         }
226
227         cipher_iv.iova = 0;
228         cipher_iv.va = NULL;
229         aad_auth_iv.iova = 0;
230         aad_auth_iv.va = NULL;
231         digest.iova = 0;
232         digest.va = NULL;
233         sgl.vec = data_vec;
234         vec.num = 1;
235         vec.src_sgl = &sgl;
236         vec.iv = &cipher_iv;
237         vec.digest = &digest;
238         vec.aad = &aad_auth_iv;
239         vec.status = &status;
240
241         ofs.raw = 0;
242
243         if (is_cipher && is_auth) {
244                 cipher_offset = sop->cipher.data.offset;
245                 cipher_len = sop->cipher.data.length;
246                 auth_offset = sop->auth.data.offset;
247                 auth_len = sop->auth.data.length;
248                 max_len = RTE_MAX(cipher_offset + cipher_len,
249                                 auth_offset + auth_len);
250                 if (len_in_bits) {
251                         max_len = max_len >> 3;
252                         cipher_offset = cipher_offset >> 3;
253                         auth_offset = auth_offset >> 3;
254                         cipher_len = cipher_len >> 3;
255                         auth_len = auth_len >> 3;
256                 }
257                 ofs.ofs.cipher.head = cipher_offset;
258                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
259                 ofs.ofs.auth.head = auth_offset;
260                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
261                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
262                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
263                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
264                                 op, void *, IV_OFFSET + cipher_iv_len);
265                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
266                                 cipher_iv_len);
267                 digest.va = (void *)sop->auth.digest.data;
268                 digest.iova = sop->auth.digest.phys_addr;
269
270         } else if (is_cipher) {
271                 cipher_offset = sop->cipher.data.offset;
272                 cipher_len = sop->cipher.data.length;
273                 max_len = cipher_len + cipher_offset;
274                 if (len_in_bits) {
275                         max_len = max_len >> 3;
276                         cipher_offset = cipher_offset >> 3;
277                         cipher_len = cipher_len >> 3;
278                 }
279                 ofs.ofs.cipher.head = cipher_offset;
280                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
281                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
282                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
283
284         } else if (is_auth) {
285                 auth_offset = sop->auth.data.offset;
286                 auth_len = sop->auth.data.length;
287                 max_len = auth_len + auth_offset;
288                 if (len_in_bits) {
289                         max_len = max_len >> 3;
290                         auth_offset = auth_offset >> 3;
291                         auth_len = auth_len >> 3;
292                 }
293                 ofs.ofs.auth.head = auth_offset;
294                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
295                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
296                                 op, void *, IV_OFFSET + cipher_iv_len);
297                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
298                                 cipher_iv_len);
299                 digest.va = (void *)sop->auth.digest.data;
300                 digest.iova = sop->auth.digest.phys_addr;
301
302         } else { /* aead */
303                 cipher_offset = sop->aead.data.offset;
304                 cipher_len = sop->aead.data.length;
305                 max_len = cipher_len + cipher_offset;
306                 if (len_in_bits) {
307                         max_len = max_len >> 3;
308                         cipher_offset = cipher_offset >> 3;
309                         cipher_len = cipher_len >> 3;
310                 }
311                 ofs.ofs.cipher.head = cipher_offset;
312                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
313                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
314                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
315                 aad_auth_iv.va = (void *)sop->aead.aad.data;
316                 aad_auth_iv.iova = sop->aead.aad.phys_addr;
317                 digest.va = (void *)sop->aead.digest.data;
318                 digest.iova = sop->aead.digest.phys_addr;
319         }
320
321         n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
322                         data_vec, RTE_DIM(data_vec));
323         if (n < 0 || n > sop->m_src->nb_segs) {
324                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
325                 goto exit;
326         }
327
328         sgl.num = n;
329         /* Out of place */
330         if (sop->m_dst != NULL) {
331                 dest_sgl.vec = dest_data_vec;
332                 vec.dest_sgl = &dest_sgl;
333                 n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len,
334                                 dest_data_vec, RTE_DIM(dest_data_vec));
335                 if (n < 0 || n > sop->m_dst->nb_segs) {
336                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
337                         goto exit;
338                 }
339                 dest_sgl.num = n;
340         } else
341                 vec.dest_sgl = NULL;
342
343         if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
344                         &enqueue_status) < 1) {
345                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
346                 goto exit;
347         }
348
349         if (enqueue_status == 0) {
350                 status = rte_cryptodev_raw_enqueue_done(ctx, 1);
351                 if (status < 0) {
352                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
353                         goto exit;
354                 }
355         } else if (enqueue_status < 0) {
356                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
357                 goto exit;
358         }
359
360         n = n_success = 0;
361         while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
362                 n = rte_cryptodev_raw_dequeue_burst(ctx,
363                         NULL, 1, post_process_raw_dp_op,
364                                 (void **)&ret_op, 0, &n_success,
365                                 &dequeue_status);
366                 if (dequeue_status < 0) {
367                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
368                         goto exit;
369                 }
370                 if (n == 0)
371                         rte_pause();
372         }
373
374         if (n == 1 && dequeue_status == 0) {
375                 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
376                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
377                         goto exit;
378                 }
379         }
380
381         op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
382                         n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
383                                         RTE_CRYPTO_OP_STATUS_SUCCESS;
384
385 exit:
386         free(ctx);
387 }
388
389 static void
390 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
391 {
392         int32_t n, st;
393         struct rte_crypto_sym_op *sop;
394         union rte_crypto_sym_ofs ofs;
395         struct rte_crypto_sgl sgl;
396         struct rte_crypto_sym_vec symvec;
397         struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
398         struct rte_crypto_vec vec[UINT8_MAX];
399
400         sop = op->sym;
401
402         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
403                 sop->aead.data.length, vec, RTE_DIM(vec));
404
405         if (n < 0 || n != sop->m_src->nb_segs) {
406                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
407                 return;
408         }
409
410         sgl.vec = vec;
411         sgl.num = n;
412         symvec.src_sgl = &sgl;
413         symvec.iv = &iv_ptr;
414         symvec.digest = &digest_ptr;
415         symvec.aad = &aad_ptr;
416         symvec.status = &st;
417         symvec.num = 1;
418
419         /* for CPU crypto the IOVA address is not required */
420         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
421         digest_ptr.va = (void *)sop->aead.digest.data;
422         aad_ptr.va = (void *)sop->aead.aad.data;
423
424         ofs.raw = 0;
425
426         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
427                 &symvec);
428
429         if (n != 1)
430                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
431         else
432                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
433 }
434
435 static void
436 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
437 {
438         int32_t n, st;
439         struct rte_crypto_sym_op *sop;
440         union rte_crypto_sym_ofs ofs;
441         struct rte_crypto_sgl sgl;
442         struct rte_crypto_sym_vec symvec;
443         struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
444         struct rte_crypto_vec vec[UINT8_MAX];
445
446         sop = op->sym;
447
448         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
449                 sop->auth.data.length, vec, RTE_DIM(vec));
450
451         if (n < 0 || n != sop->m_src->nb_segs) {
452                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
453                 return;
454         }
455
456         sgl.vec = vec;
457         sgl.num = n;
458         symvec.src_sgl = &sgl;
459         symvec.iv = &iv_ptr;
460         symvec.digest = &digest_ptr;
461         symvec.status = &st;
462         symvec.num = 1;
463
464         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
465         digest_ptr.va = (void *)sop->auth.digest.data;
466
467         ofs.raw = 0;
468         ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
469         ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
470                 (sop->cipher.data.offset + sop->cipher.data.length);
471
472         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
473                 &symvec);
474
475         if (n != 1)
476                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
477         else
478                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
479 }
480
481 static struct rte_crypto_op *
482 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
483 {
484
485         RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
486
487         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
488                 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
489                 return NULL;
490         }
491
492         op = NULL;
493
494         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
495                 rte_pause();
496
497         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
498                 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
499                 return NULL;
500         }
501
502         return op;
503 }
504
505 static struct crypto_testsuite_params testsuite_params = { NULL };
506 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
507 static struct crypto_unittest_params unittest_params;
508
509 static int
510 testsuite_setup(void)
511 {
512         struct crypto_testsuite_params *ts_params = &testsuite_params;
513         struct rte_cryptodev_info info;
514         uint32_t i = 0, nb_devs, dev_id;
515         uint16_t qp_id;
516
517         memset(ts_params, 0, sizeof(*ts_params));
518
519         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
520         if (ts_params->mbuf_pool == NULL) {
521                 /* Not already created so create */
522                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
523                                 "CRYPTO_MBUFPOOL",
524                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
525                                 rte_socket_id());
526                 if (ts_params->mbuf_pool == NULL) {
527                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
528                         return TEST_FAILED;
529                 }
530         }
531
532         ts_params->large_mbuf_pool = rte_mempool_lookup(
533                         "CRYPTO_LARGE_MBUFPOOL");
534         if (ts_params->large_mbuf_pool == NULL) {
535                 /* Not already created so create */
536                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
537                                 "CRYPTO_LARGE_MBUFPOOL",
538                                 1, 0, 0, UINT16_MAX,
539                                 rte_socket_id());
540                 if (ts_params->large_mbuf_pool == NULL) {
541                         RTE_LOG(ERR, USER1,
542                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
543                         return TEST_FAILED;
544                 }
545         }
546
547         ts_params->op_mpool = rte_crypto_op_pool_create(
548                         "MBUF_CRYPTO_SYM_OP_POOL",
549                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
550                         NUM_MBUFS, MBUF_CACHE_SIZE,
551                         DEFAULT_NUM_XFORMS *
552                         sizeof(struct rte_crypto_sym_xform) +
553                         MAXIMUM_IV_LENGTH,
554                         rte_socket_id());
555         if (ts_params->op_mpool == NULL) {
556                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
557                 return TEST_FAILED;
558         }
559
560         nb_devs = rte_cryptodev_count();
561         if (nb_devs < 1) {
562                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
563                 return TEST_SKIPPED;
564         }
565
566         if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
567                 RTE_LOG(WARNING, USER1, "No %s devices found?\n",
568                                 rte_cryptodev_driver_name_get(gbl_driver_id));
569                 return TEST_SKIPPED;
570         }
571
572         /* Create list of valid crypto devs */
573         for (i = 0; i < nb_devs; i++) {
574                 rte_cryptodev_info_get(i, &info);
575                 if (info.driver_id == gbl_driver_id)
576                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
577         }
578
579         if (ts_params->valid_dev_count < 1)
580                 return TEST_FAILED;
581
582         /* Set up all the qps on the first of the valid devices found */
583
584         dev_id = ts_params->valid_devs[0];
585
586         rte_cryptodev_info_get(dev_id, &info);
587
588         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
589         ts_params->conf.socket_id = SOCKET_ID_ANY;
590         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
591
592         unsigned int session_size =
593                 rte_cryptodev_sym_get_private_session_size(dev_id);
594
595 #ifdef RTE_LIB_SECURITY
596         unsigned int security_session_size = rte_security_session_get_size(
597                         rte_cryptodev_get_sec_ctx(dev_id));
598
599         if (session_size < security_session_size)
600                 session_size = security_session_size;
601 #endif
602         /*
603          * Create mempool with maximum number of sessions.
604          */
605         if (info.sym.max_nb_sessions != 0 &&
606                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
607                 RTE_LOG(ERR, USER1, "Device does not support "
608                                 "at least %u sessions\n",
609                                 MAX_NB_SESSIONS);
610                 return TEST_FAILED;
611         }
612
613         ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
614                         "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
615                         SOCKET_ID_ANY);
616         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
617                         "session mempool allocation failed");
618
619         ts_params->session_priv_mpool = rte_mempool_create(
620                         "test_sess_mp_priv",
621                         MAX_NB_SESSIONS,
622                         session_size,
623                         0, 0, NULL, NULL, NULL,
624                         NULL, SOCKET_ID_ANY,
625                         0);
626         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
627                         "session mempool allocation failed");
628
629
630
631         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
632                         &ts_params->conf),
633                         "Failed to configure cryptodev %u with %u qps",
634                         dev_id, ts_params->conf.nb_queue_pairs);
635
636         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
637         ts_params->qp_conf.mp_session = ts_params->session_mpool;
638         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
639
640         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
641                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
642                         dev_id, qp_id, &ts_params->qp_conf,
643                         rte_cryptodev_socket_id(dev_id)),
644                         "Failed to setup queue pair %u on cryptodev %u",
645                         qp_id, dev_id);
646         }
647
648         return TEST_SUCCESS;
649 }
650
651 static void
652 testsuite_teardown(void)
653 {
654         struct crypto_testsuite_params *ts_params = &testsuite_params;
655         int res;
656
657         if (ts_params->mbuf_pool != NULL) {
658                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
659                 rte_mempool_avail_count(ts_params->mbuf_pool));
660         }
661
662         if (ts_params->op_mpool != NULL) {
663                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
664                 rte_mempool_avail_count(ts_params->op_mpool));
665         }
666
667         /* Free session mempools */
668         if (ts_params->session_priv_mpool != NULL) {
669                 rte_mempool_free(ts_params->session_priv_mpool);
670                 ts_params->session_priv_mpool = NULL;
671         }
672
673         if (ts_params->session_mpool != NULL) {
674                 rte_mempool_free(ts_params->session_mpool);
675                 ts_params->session_mpool = NULL;
676         }
677
678         res = rte_cryptodev_close(ts_params->valid_devs[0]);
679         if (res)
680                 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
681 }
682
683 static int
684 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
685                 const int *algs, uint16_t num_algs)
686 {
687         uint8_t dev_id = testsuite_params.valid_devs[0];
688         bool some_alg_supported = FALSE;
689         uint16_t i;
690
691         for (i = 0; i < num_algs && !some_alg_supported; i++) {
692                 struct rte_cryptodev_sym_capability_idx alg = {
693                         type, {algs[i]}
694                 };
695                 if (rte_cryptodev_sym_capability_get(dev_id,
696                                 &alg) != NULL)
697                         some_alg_supported = TRUE;
698         }
699         if (!some_alg_supported)
700                 return TEST_SKIPPED;
701
702         return 0;
703 }
704
705 int
706 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
707                 uint16_t num_ciphers)
708 {
709         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
710                         (const int *) ciphers, num_ciphers);
711 }
712
713 int
714 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
715                 uint16_t num_auths)
716 {
717         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
718                         (const int *) auths, num_auths);
719 }
720
721 int
722 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
723                 uint16_t num_aeads)
724 {
725         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
726                         (const int *) aeads, num_aeads);
727 }
728
729 static int
730 null_testsuite_setup(void)
731 {
732         struct crypto_testsuite_params *ts_params = &testsuite_params;
733         uint8_t dev_id = ts_params->valid_devs[0];
734         struct rte_cryptodev_info dev_info;
735         const enum rte_crypto_cipher_algorithm ciphers[] = {
736                 RTE_CRYPTO_CIPHER_NULL
737         };
738         const enum rte_crypto_auth_algorithm auths[] = {
739                 RTE_CRYPTO_AUTH_NULL
740         };
741
742         rte_cryptodev_info_get(dev_id, &dev_info);
743
744         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
745                 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
746                                 "testsuite not met\n");
747                 return TEST_SKIPPED;
748         }
749
750         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
751                         && check_auth_capabilities_supported(auths,
752                         RTE_DIM(auths)) != 0) {
753                 RTE_LOG(INFO, USER1, "Capability requirements for NULL "
754                                 "testsuite not met\n");
755                 return TEST_SKIPPED;
756         }
757
758         return 0;
759 }
760
761 static int
762 crypto_gen_testsuite_setup(void)
763 {
764         struct crypto_testsuite_params *ts_params = &testsuite_params;
765         uint8_t dev_id = ts_params->valid_devs[0];
766         struct rte_cryptodev_info dev_info;
767
768         rte_cryptodev_info_get(dev_id, &dev_info);
769
770         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
771                 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
772                                 "testsuite not met\n");
773                 return TEST_SKIPPED;
774         }
775
776         return 0;
777 }
778
779 #ifdef RTE_LIB_SECURITY
780 static int
781 ipsec_proto_testsuite_setup(void)
782 {
783         struct crypto_testsuite_params *ts_params = &testsuite_params;
784         struct crypto_unittest_params *ut_params = &unittest_params;
785         struct rte_cryptodev_info dev_info;
786         int ret = 0;
787
788         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
789
790         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
791                 RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto "
792                                 "testsuite not met\n");
793                 return TEST_SKIPPED;
794         }
795
796         /* Reconfigure to enable security */
797         ret = dev_configure_and_start(0);
798         if (ret != TEST_SUCCESS)
799                 return ret;
800
801         /* Set action type */
802         ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
803
804         if (security_proto_supported(
805                         RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
806                         RTE_SECURITY_PROTOCOL_IPSEC) < 0) {
807                 RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto "
808                                 "test not met\n");
809                 ret = TEST_SKIPPED;
810         }
811
812         /*
813          * Stop the device. Device would be started again by individual test
814          * case setup routine.
815          */
816         rte_cryptodev_stop(ts_params->valid_devs[0]);
817
818         return ret;
819 }
820
821 static int
822 pdcp_proto_testsuite_setup(void)
823 {
824         struct crypto_testsuite_params *ts_params = &testsuite_params;
825         uint8_t dev_id = ts_params->valid_devs[0];
826         struct rte_cryptodev_info dev_info;
827         const enum rte_crypto_cipher_algorithm ciphers[] = {
828                 RTE_CRYPTO_CIPHER_NULL,
829                 RTE_CRYPTO_CIPHER_AES_CTR,
830                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
831                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
832         };
833         const enum rte_crypto_auth_algorithm auths[] = {
834                 RTE_CRYPTO_AUTH_NULL,
835                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
836                 RTE_CRYPTO_AUTH_AES_CMAC,
837                 RTE_CRYPTO_AUTH_ZUC_EIA3
838         };
839
840         rte_cryptodev_info_get(dev_id, &dev_info);
841
842         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
843                         !(dev_info.feature_flags &
844                         RTE_CRYPTODEV_FF_SECURITY)) {
845                 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
846                                 "testsuite not met\n");
847                 return TEST_SKIPPED;
848         }
849
850         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
851                         && check_auth_capabilities_supported(auths,
852                         RTE_DIM(auths)) != 0) {
853                 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
854                                 "testsuite not met\n");
855                 return TEST_SKIPPED;
856         }
857
858         return 0;
859 }
860
861 static int
862 docsis_proto_testsuite_setup(void)
863 {
864         struct crypto_testsuite_params *ts_params = &testsuite_params;
865         uint8_t dev_id = ts_params->valid_devs[0];
866         struct rte_cryptodev_info dev_info;
867         const enum rte_crypto_cipher_algorithm ciphers[] = {
868                 RTE_CRYPTO_CIPHER_AES_DOCSISBPI
869         };
870
871         rte_cryptodev_info_get(dev_id, &dev_info);
872
873         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
874                         !(dev_info.feature_flags &
875                         RTE_CRYPTODEV_FF_SECURITY)) {
876                 RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis "
877                                 "Proto testsuite not met\n");
878                 return TEST_SKIPPED;
879         }
880
881         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
882                 RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto "
883                                 "testsuite not met\n");
884                 return TEST_SKIPPED;
885         }
886
887         return 0;
888 }
889 #endif
890
891 static int
892 aes_ccm_auth_testsuite_setup(void)
893 {
894         struct crypto_testsuite_params *ts_params = &testsuite_params;
895         uint8_t dev_id = ts_params->valid_devs[0];
896         struct rte_cryptodev_info dev_info;
897         const enum rte_crypto_aead_algorithm aeads[] = {
898                 RTE_CRYPTO_AEAD_AES_CCM
899         };
900
901         rte_cryptodev_info_get(dev_id, &dev_info);
902
903         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
904                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
905                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
906                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
907                                 "testsuite not met\n");
908                 return TEST_SKIPPED;
909         }
910
911         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
912                 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
913                                 "testsuite not met\n");
914                 return TEST_SKIPPED;
915         }
916
917         return 0;
918 }
919
920 static int
921 aes_gcm_auth_testsuite_setup(void)
922 {
923         struct crypto_testsuite_params *ts_params = &testsuite_params;
924         uint8_t dev_id = ts_params->valid_devs[0];
925         struct rte_cryptodev_info dev_info;
926         const enum rte_crypto_aead_algorithm aeads[] = {
927                 RTE_CRYPTO_AEAD_AES_GCM
928         };
929
930         rte_cryptodev_info_get(dev_id, &dev_info);
931
932         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
933                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
934                                 "testsuite not met\n");
935                 return TEST_SKIPPED;
936         }
937
938         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
939                 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
940                                 "testsuite not met\n");
941                 return TEST_SKIPPED;
942         }
943
944         return 0;
945 }
946
947 static int
948 aes_gmac_auth_testsuite_setup(void)
949 {
950         struct crypto_testsuite_params *ts_params = &testsuite_params;
951         uint8_t dev_id = ts_params->valid_devs[0];
952         struct rte_cryptodev_info dev_info;
953         const enum rte_crypto_auth_algorithm auths[] = {
954                 RTE_CRYPTO_AUTH_AES_GMAC
955         };
956
957         rte_cryptodev_info_get(dev_id, &dev_info);
958
959         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
960                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
961                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
962                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
963                                 "testsuite not met\n");
964                 return TEST_SKIPPED;
965         }
966
967         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
968                 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
969                                 "testsuite not met\n");
970                 return TEST_SKIPPED;
971         }
972
973         return 0;
974 }
975
976 static int
977 chacha20_poly1305_testsuite_setup(void)
978 {
979         struct crypto_testsuite_params *ts_params = &testsuite_params;
980         uint8_t dev_id = ts_params->valid_devs[0];
981         struct rte_cryptodev_info dev_info;
982         const enum rte_crypto_aead_algorithm aeads[] = {
983                 RTE_CRYPTO_AEAD_CHACHA20_POLY1305
984         };
985
986         rte_cryptodev_info_get(dev_id, &dev_info);
987
988         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
989                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
990                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
991                 RTE_LOG(INFO, USER1, "Feature flag requirements for "
992                                 "Chacha20-Poly1305 testsuite not met\n");
993                 return TEST_SKIPPED;
994         }
995
996         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
997                 RTE_LOG(INFO, USER1, "Capability requirements for "
998                                 "Chacha20-Poly1305 testsuite not met\n");
999                 return TEST_SKIPPED;
1000         }
1001
1002         return 0;
1003 }
1004
1005 static int
1006 snow3g_testsuite_setup(void)
1007 {
1008         struct crypto_testsuite_params *ts_params = &testsuite_params;
1009         uint8_t dev_id = ts_params->valid_devs[0];
1010         struct rte_cryptodev_info dev_info;
1011         const enum rte_crypto_cipher_algorithm ciphers[] = {
1012                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1013
1014         };
1015         const enum rte_crypto_auth_algorithm auths[] = {
1016                 RTE_CRYPTO_AUTH_SNOW3G_UIA2
1017         };
1018
1019         rte_cryptodev_info_get(dev_id, &dev_info);
1020
1021         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1022                 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
1023                                 "testsuite not met\n");
1024                 return TEST_SKIPPED;
1025         }
1026
1027         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1028                         && check_auth_capabilities_supported(auths,
1029                         RTE_DIM(auths)) != 0) {
1030                 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
1031                                 "testsuite not met\n");
1032                 return TEST_SKIPPED;
1033         }
1034
1035         return 0;
1036 }
1037
1038 static int
1039 zuc_testsuite_setup(void)
1040 {
1041         struct crypto_testsuite_params *ts_params = &testsuite_params;
1042         uint8_t dev_id = ts_params->valid_devs[0];
1043         struct rte_cryptodev_info dev_info;
1044         const enum rte_crypto_cipher_algorithm ciphers[] = {
1045                 RTE_CRYPTO_CIPHER_ZUC_EEA3
1046         };
1047         const enum rte_crypto_auth_algorithm auths[] = {
1048                 RTE_CRYPTO_AUTH_ZUC_EIA3
1049         };
1050
1051         rte_cryptodev_info_get(dev_id, &dev_info);
1052
1053         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1054                 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
1055                                 "testsuite not met\n");
1056                 return TEST_SKIPPED;
1057         }
1058
1059         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1060                         && check_auth_capabilities_supported(auths,
1061                         RTE_DIM(auths)) != 0) {
1062                 RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1063                                 "testsuite not met\n");
1064                 return TEST_SKIPPED;
1065         }
1066
1067         return 0;
1068 }
1069
1070 static int
1071 hmac_md5_auth_testsuite_setup(void)
1072 {
1073         struct crypto_testsuite_params *ts_params = &testsuite_params;
1074         uint8_t dev_id = ts_params->valid_devs[0];
1075         struct rte_cryptodev_info dev_info;
1076         const enum rte_crypto_auth_algorithm auths[] = {
1077                 RTE_CRYPTO_AUTH_MD5_HMAC
1078         };
1079
1080         rte_cryptodev_info_get(dev_id, &dev_info);
1081
1082         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1083                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1084                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1085                 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1086                                 "Auth testsuite not met\n");
1087                 return TEST_SKIPPED;
1088         }
1089
1090         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1091                 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1092                                 "testsuite not met\n");
1093                 return TEST_SKIPPED;
1094         }
1095
1096         return 0;
1097 }
1098
1099 static int
1100 kasumi_testsuite_setup(void)
1101 {
1102         struct crypto_testsuite_params *ts_params = &testsuite_params;
1103         uint8_t dev_id = ts_params->valid_devs[0];
1104         struct rte_cryptodev_info dev_info;
1105         const enum rte_crypto_cipher_algorithm ciphers[] = {
1106                 RTE_CRYPTO_CIPHER_KASUMI_F8
1107         };
1108         const enum rte_crypto_auth_algorithm auths[] = {
1109                 RTE_CRYPTO_AUTH_KASUMI_F9
1110         };
1111
1112         rte_cryptodev_info_get(dev_id, &dev_info);
1113
1114         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1115                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1116                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1117                 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1118                                 "testsuite not met\n");
1119                 return TEST_SKIPPED;
1120         }
1121
1122         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1123                         && check_auth_capabilities_supported(auths,
1124                         RTE_DIM(auths)) != 0) {
1125                 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1126                                 "testsuite not met\n");
1127                 return TEST_SKIPPED;
1128         }
1129
1130         return 0;
1131 }
1132
1133 static int
1134 negative_aes_gcm_testsuite_setup(void)
1135 {
1136         struct crypto_testsuite_params *ts_params = &testsuite_params;
1137         uint8_t dev_id = ts_params->valid_devs[0];
1138         struct rte_cryptodev_info dev_info;
1139         const enum rte_crypto_aead_algorithm aeads[] = {
1140                 RTE_CRYPTO_AEAD_AES_GCM
1141         };
1142
1143         rte_cryptodev_info_get(dev_id, &dev_info);
1144
1145         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1146                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1147                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1148                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1149                                 "AES GCM testsuite not met\n");
1150                 return TEST_SKIPPED;
1151         }
1152
1153         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1154                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1155                                 "AES GCM testsuite not met\n");
1156                 return TEST_SKIPPED;
1157         }
1158
1159         return 0;
1160 }
1161
1162 static int
1163 negative_aes_gmac_testsuite_setup(void)
1164 {
1165         struct crypto_testsuite_params *ts_params = &testsuite_params;
1166         uint8_t dev_id = ts_params->valid_devs[0];
1167         struct rte_cryptodev_info dev_info;
1168         const enum rte_crypto_auth_algorithm auths[] = {
1169                 RTE_CRYPTO_AUTH_AES_GMAC
1170         };
1171
1172         rte_cryptodev_info_get(dev_id, &dev_info);
1173
1174         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1175                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1176                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1177                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1178                                 "AES GMAC testsuite not met\n");
1179                 return TEST_SKIPPED;
1180         }
1181
1182         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1183                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1184                                 "AES GMAC testsuite not met\n");
1185                 return TEST_SKIPPED;
1186         }
1187
1188         return 0;
1189 }
1190
1191 static int
1192 mixed_cipher_hash_testsuite_setup(void)
1193 {
1194         struct crypto_testsuite_params *ts_params = &testsuite_params;
1195         uint8_t dev_id = ts_params->valid_devs[0];
1196         struct rte_cryptodev_info dev_info;
1197         uint64_t feat_flags;
1198         const enum rte_crypto_cipher_algorithm ciphers[] = {
1199                 RTE_CRYPTO_CIPHER_NULL,
1200                 RTE_CRYPTO_CIPHER_AES_CTR,
1201                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
1202                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1203         };
1204         const enum rte_crypto_auth_algorithm auths[] = {
1205                 RTE_CRYPTO_AUTH_NULL,
1206                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1207                 RTE_CRYPTO_AUTH_AES_CMAC,
1208                 RTE_CRYPTO_AUTH_ZUC_EIA3
1209         };
1210
1211         rte_cryptodev_info_get(dev_id, &dev_info);
1212         feat_flags = dev_info.feature_flags;
1213
1214         if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1215                         (global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1216                 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1217                                 "Cipher Hash testsuite not met\n");
1218                 return TEST_SKIPPED;
1219         }
1220
1221         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1222                         && check_auth_capabilities_supported(auths,
1223                         RTE_DIM(auths)) != 0) {
1224                 RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1225                                 "Cipher Hash testsuite not met\n");
1226                 return TEST_SKIPPED;
1227         }
1228
1229         return 0;
1230 }
1231
1232 static int
1233 esn_testsuite_setup(void)
1234 {
1235         struct crypto_testsuite_params *ts_params = &testsuite_params;
1236         uint8_t dev_id = ts_params->valid_devs[0];
1237         struct rte_cryptodev_info dev_info;
1238         const enum rte_crypto_cipher_algorithm ciphers[] = {
1239                 RTE_CRYPTO_CIPHER_AES_CBC
1240         };
1241         const enum rte_crypto_auth_algorithm auths[] = {
1242                 RTE_CRYPTO_AUTH_SHA1_HMAC
1243         };
1244
1245         rte_cryptodev_info_get(dev_id, &dev_info);
1246
1247         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1248                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1249                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1250                 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1251                                 "testsuite not met\n");
1252                 return TEST_SKIPPED;
1253         }
1254
1255         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1256                         && check_auth_capabilities_supported(auths,
1257                         RTE_DIM(auths)) != 0) {
1258                 RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1259                                 "testsuite not met\n");
1260                 return TEST_SKIPPED;
1261         }
1262
1263         return 0;
1264 }
1265
1266 static int
1267 multi_session_testsuite_setup(void)
1268 {
1269         struct crypto_testsuite_params *ts_params = &testsuite_params;
1270         uint8_t dev_id = ts_params->valid_devs[0];
1271         struct rte_cryptodev_info dev_info;
1272         const enum rte_crypto_cipher_algorithm ciphers[] = {
1273                 RTE_CRYPTO_CIPHER_AES_CBC
1274         };
1275         const enum rte_crypto_auth_algorithm auths[] = {
1276                 RTE_CRYPTO_AUTH_SHA512_HMAC
1277         };
1278
1279         rte_cryptodev_info_get(dev_id, &dev_info);
1280
1281         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1282                 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1283                                 "Session testsuite not met\n");
1284                 return TEST_SKIPPED;
1285         }
1286
1287         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1288                         && check_auth_capabilities_supported(auths,
1289                         RTE_DIM(auths)) != 0) {
1290                 RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1291                                 "Session testsuite not met\n");
1292                 return TEST_SKIPPED;
1293         }
1294
1295         return 0;
1296 }
1297
1298 static int
1299 negative_hmac_sha1_testsuite_setup(void)
1300 {
1301         struct crypto_testsuite_params *ts_params = &testsuite_params;
1302         uint8_t dev_id = ts_params->valid_devs[0];
1303         struct rte_cryptodev_info dev_info;
1304         const enum rte_crypto_cipher_algorithm ciphers[] = {
1305                 RTE_CRYPTO_CIPHER_AES_CBC
1306         };
1307         const enum rte_crypto_auth_algorithm auths[] = {
1308                 RTE_CRYPTO_AUTH_SHA1_HMAC
1309         };
1310
1311         rte_cryptodev_info_get(dev_id, &dev_info);
1312
1313         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1314                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1315                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1316                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1317                                 "HMAC SHA1 testsuite not met\n");
1318                 return TEST_SKIPPED;
1319         }
1320
1321         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1322                         && check_auth_capabilities_supported(auths,
1323                         RTE_DIM(auths)) != 0) {
1324                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1325                                 "HMAC SHA1 testsuite not met\n");
1326                 return TEST_SKIPPED;
1327         }
1328
1329         return 0;
1330 }
1331
1332 static int
1333 dev_configure_and_start(uint64_t ff_disable)
1334 {
1335         struct crypto_testsuite_params *ts_params = &testsuite_params;
1336         struct crypto_unittest_params *ut_params = &unittest_params;
1337
1338         uint16_t qp_id;
1339
1340         /* Clear unit test parameters before running test */
1341         memset(ut_params, 0, sizeof(*ut_params));
1342
1343         /* Reconfigure device to default parameters */
1344         ts_params->conf.socket_id = SOCKET_ID_ANY;
1345         ts_params->conf.ff_disable = ff_disable;
1346         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1347         ts_params->qp_conf.mp_session = ts_params->session_mpool;
1348         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1349
1350         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1351                         &ts_params->conf),
1352                         "Failed to configure cryptodev %u",
1353                         ts_params->valid_devs[0]);
1354
1355         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1356                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1357                         ts_params->valid_devs[0], qp_id,
1358                         &ts_params->qp_conf,
1359                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1360                         "Failed to setup queue pair %u on cryptodev %u",
1361                         qp_id, ts_params->valid_devs[0]);
1362         }
1363
1364
1365         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1366
1367         /* Start the device */
1368         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1369                         "Failed to start cryptodev %u",
1370                         ts_params->valid_devs[0]);
1371
1372         return TEST_SUCCESS;
1373 }
1374
1375 int
1376 ut_setup(void)
1377 {
1378         /* Configure and start the device with security feature disabled */
1379         return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1380 }
1381
1382 static int
1383 ut_setup_security(void)
1384 {
1385         /* Configure and start the device with no features disabled */
1386         return dev_configure_and_start(0);
1387 }
1388
1389 void
1390 ut_teardown(void)
1391 {
1392         struct crypto_testsuite_params *ts_params = &testsuite_params;
1393         struct crypto_unittest_params *ut_params = &unittest_params;
1394         struct rte_cryptodev_stats stats;
1395
1396         /* free crypto session structure */
1397 #ifdef RTE_LIB_SECURITY
1398         if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1399                 if (ut_params->sec_session) {
1400                         rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1401                                                 (ts_params->valid_devs[0]),
1402                                                 ut_params->sec_session);
1403                         ut_params->sec_session = NULL;
1404                 }
1405         } else
1406 #endif
1407         {
1408                 if (ut_params->sess) {
1409                         rte_cryptodev_sym_session_clear(
1410                                         ts_params->valid_devs[0],
1411                                         ut_params->sess);
1412                         rte_cryptodev_sym_session_free(ut_params->sess);
1413                         ut_params->sess = NULL;
1414                 }
1415         }
1416
1417         /* free crypto operation structure */
1418         if (ut_params->op)
1419                 rte_crypto_op_free(ut_params->op);
1420
1421         /*
1422          * free mbuf - both obuf and ibuf are usually the same,
1423          * so check if they point at the same address is necessary,
1424          * to avoid freeing the mbuf twice.
1425          */
1426         if (ut_params->obuf) {
1427                 rte_pktmbuf_free(ut_params->obuf);
1428                 if (ut_params->ibuf == ut_params->obuf)
1429                         ut_params->ibuf = 0;
1430                 ut_params->obuf = 0;
1431         }
1432         if (ut_params->ibuf) {
1433                 rte_pktmbuf_free(ut_params->ibuf);
1434                 ut_params->ibuf = 0;
1435         }
1436
1437         if (ts_params->mbuf_pool != NULL)
1438                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1439                         rte_mempool_avail_count(ts_params->mbuf_pool));
1440
1441         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1442
1443         /* Stop the device */
1444         rte_cryptodev_stop(ts_params->valid_devs[0]);
1445 }
1446
1447 static int
1448 test_device_configure_invalid_dev_id(void)
1449 {
1450         struct crypto_testsuite_params *ts_params = &testsuite_params;
1451         uint16_t dev_id, num_devs = 0;
1452
1453         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1454                         "Need at least %d devices for test", 1);
1455
1456         /* valid dev_id values */
1457         dev_id = ts_params->valid_devs[0];
1458
1459         /* Stop the device in case it's started so it can be configured */
1460         rte_cryptodev_stop(dev_id);
1461
1462         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1463                         "Failed test for rte_cryptodev_configure: "
1464                         "invalid dev_num %u", dev_id);
1465
1466         /* invalid dev_id values */
1467         dev_id = num_devs;
1468
1469         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1470                         "Failed test for rte_cryptodev_configure: "
1471                         "invalid dev_num %u", dev_id);
1472
1473         dev_id = 0xff;
1474
1475         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1476                         "Failed test for rte_cryptodev_configure:"
1477                         "invalid dev_num %u", dev_id);
1478
1479         return TEST_SUCCESS;
1480 }
1481
1482 static int
1483 test_device_configure_invalid_queue_pair_ids(void)
1484 {
1485         struct crypto_testsuite_params *ts_params = &testsuite_params;
1486         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1487
1488         /* Stop the device in case it's started so it can be configured */
1489         rte_cryptodev_stop(ts_params->valid_devs[0]);
1490
1491         /* valid - max value queue pairs */
1492         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1493
1494         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1495                         &ts_params->conf),
1496                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1497                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1498
1499         /* valid - one queue pairs */
1500         ts_params->conf.nb_queue_pairs = 1;
1501
1502         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1503                         &ts_params->conf),
1504                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1505                         ts_params->valid_devs[0],
1506                         ts_params->conf.nb_queue_pairs);
1507
1508
1509         /* invalid - zero queue pairs */
1510         ts_params->conf.nb_queue_pairs = 0;
1511
1512         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1513                         &ts_params->conf),
1514                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1515                         " invalid qps: %u",
1516                         ts_params->valid_devs[0],
1517                         ts_params->conf.nb_queue_pairs);
1518
1519
1520         /* invalid - max value supported by field queue pairs */
1521         ts_params->conf.nb_queue_pairs = UINT16_MAX;
1522
1523         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1524                         &ts_params->conf),
1525                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1526                         " invalid qps: %u",
1527                         ts_params->valid_devs[0],
1528                         ts_params->conf.nb_queue_pairs);
1529
1530
1531         /* invalid - max value + 1 queue pairs */
1532         ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1533
1534         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1535                         &ts_params->conf),
1536                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1537                         " invalid qps: %u",
1538                         ts_params->valid_devs[0],
1539                         ts_params->conf.nb_queue_pairs);
1540
1541         /* revert to original testsuite value */
1542         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1543
1544         return TEST_SUCCESS;
1545 }
1546
1547 static int
1548 test_queue_pair_descriptor_setup(void)
1549 {
1550         struct crypto_testsuite_params *ts_params = &testsuite_params;
1551         struct rte_cryptodev_qp_conf qp_conf = {
1552                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
1553         };
1554         uint16_t qp_id;
1555
1556         /* Stop the device in case it's started so it can be configured */
1557         rte_cryptodev_stop(ts_params->valid_devs[0]);
1558
1559         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1560                         &ts_params->conf),
1561                         "Failed to configure cryptodev %u",
1562                         ts_params->valid_devs[0]);
1563
1564         /*
1565          * Test various ring sizes on this device. memzones can't be
1566          * freed so are re-used if ring is released and re-created.
1567          */
1568         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1569         qp_conf.mp_session = ts_params->session_mpool;
1570         qp_conf.mp_session_private = ts_params->session_priv_mpool;
1571
1572         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1573                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1574                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1575                                 rte_cryptodev_socket_id(
1576                                                 ts_params->valid_devs[0])),
1577                                 "Failed test for "
1578                                 "rte_cryptodev_queue_pair_setup: num_inflights "
1579                                 "%u on qp %u on cryptodev %u",
1580                                 qp_conf.nb_descriptors, qp_id,
1581                                 ts_params->valid_devs[0]);
1582         }
1583
1584         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1585
1586         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1587                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1588                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1589                                 rte_cryptodev_socket_id(
1590                                                 ts_params->valid_devs[0])),
1591                                 "Failed test for"
1592                                 " rte_cryptodev_queue_pair_setup: num_inflights"
1593                                 " %u on qp %u on cryptodev %u",
1594                                 qp_conf.nb_descriptors, qp_id,
1595                                 ts_params->valid_devs[0]);
1596         }
1597
1598         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1599
1600         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1601                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1602                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1603                                 rte_cryptodev_socket_id(
1604                                                 ts_params->valid_devs[0])),
1605                                 "Failed test for "
1606                                 "rte_cryptodev_queue_pair_setup: num_inflights"
1607                                 " %u on qp %u on cryptodev %u",
1608                                 qp_conf.nb_descriptors, qp_id,
1609                                 ts_params->valid_devs[0]);
1610         }
1611
1612         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1613
1614         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1615                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1616                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1617                                 rte_cryptodev_socket_id(
1618                                                 ts_params->valid_devs[0])),
1619                                 "Failed test for"
1620                                 " rte_cryptodev_queue_pair_setup:"
1621                                 "num_inflights %u on qp %u on cryptodev %u",
1622                                 qp_conf.nb_descriptors, qp_id,
1623                                 ts_params->valid_devs[0]);
1624         }
1625
1626         /* test invalid queue pair id */
1627         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
1628
1629         qp_id = ts_params->conf.nb_queue_pairs;         /*invalid */
1630
1631         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1632                         ts_params->valid_devs[0],
1633                         qp_id, &qp_conf,
1634                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1635                         "Failed test for rte_cryptodev_queue_pair_setup:"
1636                         "invalid qp %u on cryptodev %u",
1637                         qp_id, ts_params->valid_devs[0]);
1638
1639         qp_id = 0xffff; /*invalid*/
1640
1641         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1642                         ts_params->valid_devs[0],
1643                         qp_id, &qp_conf,
1644                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1645                         "Failed test for rte_cryptodev_queue_pair_setup:"
1646                         "invalid qp %u on cryptodev %u",
1647                         qp_id, ts_params->valid_devs[0]);
1648
1649         return TEST_SUCCESS;
1650 }
1651
1652 /* ***** Plaintext data for tests ***** */
1653
1654 const char catch_22_quote_1[] =
1655                 "There was only one catch and that was Catch-22, which "
1656                 "specified that a concern for one's safety in the face of "
1657                 "dangers that were real and immediate was the process of a "
1658                 "rational mind. Orr was crazy and could be grounded. All he "
1659                 "had to do was ask; and as soon as he did, he would no longer "
1660                 "be crazy and would have to fly more missions. Orr would be "
1661                 "crazy to fly more missions and sane if he didn't, but if he "
1662                 "was sane he had to fly them. If he flew them he was crazy "
1663                 "and didn't have to; but if he didn't want to he was sane and "
1664                 "had to. Yossarian was moved very deeply by the absolute "
1665                 "simplicity of this clause of Catch-22 and let out a "
1666                 "respectful whistle. \"That's some catch, that Catch-22\", he "
1667                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
1668
1669 const char catch_22_quote[] =
1670                 "What a lousy earth! He wondered how many people were "
1671                 "destitute that same night even in his own prosperous country, "
1672                 "how many homes were shanties, how many husbands were drunk "
1673                 "and wives socked, and how many children were bullied, abused, "
1674                 "or abandoned. How many families hungered for food they could "
1675                 "not afford to buy? How many hearts were broken? How many "
1676                 "suicides would take place that same night, how many people "
1677                 "would go insane? How many cockroaches and landlords would "
1678                 "triumph? How many winners were losers, successes failures, "
1679                 "and rich men poor men? How many wise guys were stupid? How "
1680                 "many happy endings were unhappy endings? How many honest men "
1681                 "were liars, brave men cowards, loyal men traitors, how many "
1682                 "sainted men were corrupt, how many people in positions of "
1683                 "trust had sold their souls to bodyguards, how many had never "
1684                 "had souls? How many straight-and-narrow paths were crooked "
1685                 "paths? How many best families were worst families and how "
1686                 "many good people were bad people? When you added them all up "
1687                 "and then subtracted, you might be left with only the children, "
1688                 "and perhaps with Albert Einstein and an old violinist or "
1689                 "sculptor somewhere.";
1690
1691 #define QUOTE_480_BYTES         (480)
1692 #define QUOTE_512_BYTES         (512)
1693 #define QUOTE_768_BYTES         (768)
1694 #define QUOTE_1024_BYTES        (1024)
1695
1696
1697
1698 /* ***** SHA1 Hash Tests ***** */
1699
1700 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
1701
1702 static uint8_t hmac_sha1_key[] = {
1703         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1704         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1705         0xDE, 0xF4, 0xDE, 0xAD };
1706
1707 /* ***** SHA224 Hash Tests ***** */
1708
1709 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
1710
1711
1712 /* ***** AES-CBC Cipher Tests ***** */
1713
1714 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
1715 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
1716
1717 static uint8_t aes_cbc_key[] = {
1718         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1719         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1720
1721 static uint8_t aes_cbc_iv[] = {
1722         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1723         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1724
1725
1726 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1727
1728 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1729         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1730         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1731         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1732         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1733         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1734         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1735         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1736         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1737         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1738         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1739         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1740         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1741         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1742         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1743         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1744         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1745         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1746         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1747         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1748         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1749         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1750         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1751         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1752         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1753         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1754         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1755         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1756         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1757         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1758         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1759         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1760         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1761         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1762         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1763         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1764         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1765         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1766         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1767         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1768         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1769         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1770         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1771         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1772         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1773         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1774         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1775         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1776         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1777         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1778         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1779         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1780         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1781         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1782         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1783         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1784         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1785         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1786         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1787         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1788         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1789         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1790         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1791         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1792         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1793 };
1794
1795 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1796         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1797         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1798         0x18, 0x8c, 0x1d, 0x32
1799 };
1800
1801
1802 /* Multisession Vector context Test */
1803 /*Begin Session 0 */
1804 static uint8_t ms_aes_cbc_key0[] = {
1805         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1806         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1807 };
1808
1809 static uint8_t ms_aes_cbc_iv0[] = {
1810         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1811         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1812 };
1813
1814 static const uint8_t ms_aes_cbc_cipher0[] = {
1815                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1816                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1817                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1818                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1819                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1820                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1821                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1822                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1823                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1824                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1825                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1826                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1827                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1828                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1829                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1830                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1831                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1832                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1833                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1834                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1835                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1836                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1837                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1838                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1839                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1840                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1841                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1842                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1843                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1844                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1845                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1846                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1847                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1848                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1849                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1850                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1851                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1852                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1853                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1854                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1855                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1856                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1857                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1858                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1859                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1860                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1861                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1862                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1863                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1864                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1865                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1866                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1867                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1868                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1869                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1870                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1871                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1872                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1873                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1874                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1875                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1876                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1877                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1878                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1879 };
1880
1881
1882 static  uint8_t ms_hmac_key0[] = {
1883                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1884                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1885                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1886                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1887                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1888                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1889                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1890                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1891 };
1892
1893 static const uint8_t ms_hmac_digest0[] = {
1894                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1895                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1896                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1897                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1898                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1899                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1900                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1901                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1902                 };
1903
1904 /* End Session 0 */
1905 /* Begin session 1 */
1906
1907 static  uint8_t ms_aes_cbc_key1[] = {
1908                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1909                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1910 };
1911
1912 static  uint8_t ms_aes_cbc_iv1[] = {
1913         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1914         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1915 };
1916
1917 static const uint8_t ms_aes_cbc_cipher1[] = {
1918                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1919                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1920                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1921                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1922                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1923                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1924                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1925                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1926                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1927                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1928                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1929                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1930                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1931                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1932                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1933                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1934                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1935                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1936                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1937                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1938                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1939                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1940                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1941                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1942                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1943                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1944                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1945                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1946                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1947                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1948                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1949                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1950                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1951                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1952                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1953                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1954                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1955                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1956                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1957                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1958                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1959                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1960                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1961                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1962                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1963                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1964                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1965                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1966                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1967                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1968                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1969                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1970                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1971                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1972                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1973                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1974                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1975                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1976                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1977                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1978                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1979                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1980                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1981                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1982
1983 };
1984
1985 static uint8_t ms_hmac_key1[] = {
1986                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1987                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1988                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1989                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1990                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1991                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1992                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1993                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1994 };
1995
1996 static const uint8_t ms_hmac_digest1[] = {
1997                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1998                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1999                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
2000                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
2001                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
2002                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
2003                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
2004                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
2005 };
2006 /* End Session 1  */
2007 /* Begin Session 2 */
2008 static  uint8_t ms_aes_cbc_key2[] = {
2009                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2010                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2011 };
2012
2013 static  uint8_t ms_aes_cbc_iv2[] = {
2014                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2015                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2016 };
2017
2018 static const uint8_t ms_aes_cbc_cipher2[] = {
2019                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
2020                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
2021                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
2022                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
2023                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
2024                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
2025                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
2026                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
2027                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
2028                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
2029                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
2030                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
2031                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
2032                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
2033                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
2034                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
2035                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
2036                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
2037                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
2038                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
2039                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
2040                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
2041                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
2042                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
2043                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
2044                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
2045                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
2046                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
2047                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
2048                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
2049                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
2050                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
2051                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
2052                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
2053                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
2054                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
2055                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
2056                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
2057                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
2058                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2059                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2060                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2061                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2062                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2063                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2064                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2065                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2066                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2067                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2068                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2069                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2070                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2071                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2072                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2073                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2074                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2075                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2076                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2077                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2078                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2079                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2080                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2081                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2082                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2083 };
2084
2085 static  uint8_t ms_hmac_key2[] = {
2086                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2087                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2088                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2089                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2090                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2091                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2092                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2093                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2094 };
2095
2096 static const uint8_t ms_hmac_digest2[] = {
2097                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2098                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2099                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2100                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2101                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2102                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2103                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2104                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2105 };
2106
2107 /* End Session 2 */
2108
2109
2110 static int
2111 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2112 {
2113         struct crypto_testsuite_params *ts_params = &testsuite_params;
2114         struct crypto_unittest_params *ut_params = &unittest_params;
2115
2116         /* Verify the capabilities */
2117         struct rte_cryptodev_sym_capability_idx cap_idx;
2118         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2119         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2120         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2121                         &cap_idx) == NULL)
2122                 return TEST_SKIPPED;
2123         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2124         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2125         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2126                         &cap_idx) == NULL)
2127                 return TEST_SKIPPED;
2128
2129         /* Generate test mbuf data and space for digest */
2130         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2131                         catch_22_quote, QUOTE_512_BYTES, 0);
2132
2133         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2134                         DIGEST_BYTE_LENGTH_SHA1);
2135         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2136
2137         /* Setup Cipher Parameters */
2138         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2139         ut_params->cipher_xform.next = &ut_params->auth_xform;
2140
2141         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2142         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2143         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2144         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2145         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2146         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2147
2148         /* Setup HMAC Parameters */
2149         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2150
2151         ut_params->auth_xform.next = NULL;
2152
2153         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2154         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2155         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2156         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2157         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2158
2159         ut_params->sess = rte_cryptodev_sym_session_create(
2160                         ts_params->session_mpool);
2161
2162         /* Create crypto session*/
2163         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2164                         ut_params->sess, &ut_params->cipher_xform,
2165                         ts_params->session_priv_mpool);
2166         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2167
2168         /* Generate crypto op data structure */
2169         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2170                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2171         TEST_ASSERT_NOT_NULL(ut_params->op,
2172                         "Failed to allocate symmetric crypto operation struct");
2173
2174         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2175
2176         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2177
2178         /* set crypto operation source mbuf */
2179         sym_op->m_src = ut_params->ibuf;
2180
2181         /* Set crypto operation authentication parameters */
2182         sym_op->auth.digest.data = ut_params->digest;
2183         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2184                         ut_params->ibuf, QUOTE_512_BYTES);
2185
2186         sym_op->auth.data.offset = 0;
2187         sym_op->auth.data.length = QUOTE_512_BYTES;
2188
2189         /* Copy IV at the end of the crypto operation */
2190         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2191                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2192
2193         /* Set crypto operation cipher parameters */
2194         sym_op->cipher.data.offset = 0;
2195         sym_op->cipher.data.length = QUOTE_512_BYTES;
2196
2197         /* Process crypto operation */
2198         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2199                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2200                         ut_params->op);
2201         else
2202                 TEST_ASSERT_NOT_NULL(
2203                         process_crypto_request(ts_params->valid_devs[0],
2204                                 ut_params->op),
2205                                 "failed to process sym crypto op");
2206
2207         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2208                         "crypto op processing failed");
2209
2210         /* Validate obuf */
2211         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2212                         uint8_t *);
2213
2214         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2215                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2216                         QUOTE_512_BYTES,
2217                         "ciphertext data not as expected");
2218
2219         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2220
2221         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2222                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2223                         gbl_driver_id == rte_cryptodev_driver_id_get(
2224                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2225                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2226                                         DIGEST_BYTE_LENGTH_SHA1,
2227                         "Generated digest data not as expected");
2228
2229         return TEST_SUCCESS;
2230 }
2231
2232 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2233
2234 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2235
2236 static uint8_t hmac_sha512_key[] = {
2237         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2238         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2239         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2240         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2241         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2242         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2243         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2244         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2245
2246 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2247         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2248         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2249         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2250         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2251         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2252         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2253         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2254         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2255
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 static int
2265 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2266                 struct crypto_unittest_params *ut_params,
2267                 struct crypto_testsuite_params *ts_params,
2268                 const uint8_t *cipher,
2269                 const uint8_t *digest,
2270                 const uint8_t *iv);
2271
2272
2273 static int
2274 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2275                 struct crypto_unittest_params *ut_params,
2276                 uint8_t *cipher_key,
2277                 uint8_t *hmac_key)
2278 {
2279
2280         /* Setup Cipher Parameters */
2281         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2282         ut_params->cipher_xform.next = NULL;
2283
2284         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2285         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2286         ut_params->cipher_xform.cipher.key.data = cipher_key;
2287         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2288         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2289         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2290
2291         /* Setup HMAC Parameters */
2292         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2293         ut_params->auth_xform.next = &ut_params->cipher_xform;
2294
2295         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2296         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2297         ut_params->auth_xform.auth.key.data = hmac_key;
2298         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2299         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2300
2301         return TEST_SUCCESS;
2302 }
2303
2304
2305 static int
2306 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2307                 struct crypto_unittest_params *ut_params,
2308                 struct crypto_testsuite_params *ts_params,
2309                 const uint8_t *cipher,
2310                 const uint8_t *digest,
2311                 const uint8_t *iv)
2312 {
2313         /* Generate test mbuf data and digest */
2314         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2315                         (const char *)
2316                         cipher,
2317                         QUOTE_512_BYTES, 0);
2318
2319         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2320                         DIGEST_BYTE_LENGTH_SHA512);
2321         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2322
2323         rte_memcpy(ut_params->digest,
2324                         digest,
2325                         DIGEST_BYTE_LENGTH_SHA512);
2326
2327         /* Generate Crypto op data structure */
2328         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2329                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2330         TEST_ASSERT_NOT_NULL(ut_params->op,
2331                         "Failed to allocate symmetric crypto operation struct");
2332
2333         rte_crypto_op_attach_sym_session(ut_params->op, sess);
2334
2335         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2336
2337         /* set crypto operation source mbuf */
2338         sym_op->m_src = ut_params->ibuf;
2339
2340         sym_op->auth.digest.data = ut_params->digest;
2341         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2342                         ut_params->ibuf, QUOTE_512_BYTES);
2343
2344         sym_op->auth.data.offset = 0;
2345         sym_op->auth.data.length = QUOTE_512_BYTES;
2346
2347         /* Copy IV at the end of the crypto operation */
2348         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2349                         iv, CIPHER_IV_LENGTH_AES_CBC);
2350
2351         sym_op->cipher.data.offset = 0;
2352         sym_op->cipher.data.length = QUOTE_512_BYTES;
2353
2354         /* Process crypto operation */
2355         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2356                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2357                         ut_params->op);
2358         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2359                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2360                                 ut_params->op, 1, 1, 0, 0);
2361         else
2362                 TEST_ASSERT_NOT_NULL(
2363                                 process_crypto_request(ts_params->valid_devs[0],
2364                                         ut_params->op),
2365                                         "failed to process sym crypto op");
2366
2367         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2368                         "crypto op processing failed");
2369
2370         ut_params->obuf = ut_params->op->sym->m_src;
2371
2372         /* Validate obuf */
2373         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2374                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2375                         catch_22_quote,
2376                         QUOTE_512_BYTES,
2377                         "Plaintext data not as expected");
2378
2379         /* Validate obuf */
2380         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2381                         "Digest verification failed");
2382
2383         return TEST_SUCCESS;
2384 }
2385
2386 /* ***** SNOW 3G Tests ***** */
2387 static int
2388 create_wireless_algo_hash_session(uint8_t dev_id,
2389         const uint8_t *key, const uint8_t key_len,
2390         const uint8_t iv_len, const uint8_t auth_len,
2391         enum rte_crypto_auth_operation op,
2392         enum rte_crypto_auth_algorithm algo)
2393 {
2394         uint8_t hash_key[key_len];
2395         int status;
2396
2397         struct crypto_testsuite_params *ts_params = &testsuite_params;
2398         struct crypto_unittest_params *ut_params = &unittest_params;
2399
2400         memcpy(hash_key, key, key_len);
2401
2402         debug_hexdump(stdout, "key:", key, key_len);
2403
2404         /* Setup Authentication Parameters */
2405         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2406         ut_params->auth_xform.next = NULL;
2407
2408         ut_params->auth_xform.auth.op = op;
2409         ut_params->auth_xform.auth.algo = algo;
2410         ut_params->auth_xform.auth.key.length = key_len;
2411         ut_params->auth_xform.auth.key.data = hash_key;
2412         ut_params->auth_xform.auth.digest_length = auth_len;
2413         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2414         ut_params->auth_xform.auth.iv.length = iv_len;
2415         ut_params->sess = rte_cryptodev_sym_session_create(
2416                         ts_params->session_mpool);
2417
2418         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2419                         &ut_params->auth_xform,
2420                         ts_params->session_priv_mpool);
2421         if (status == -ENOTSUP)
2422                 return TEST_SKIPPED;
2423
2424         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2425         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2426         return 0;
2427 }
2428
2429 static int
2430 create_wireless_algo_cipher_session(uint8_t dev_id,
2431                         enum rte_crypto_cipher_operation op,
2432                         enum rte_crypto_cipher_algorithm algo,
2433                         const uint8_t *key, const uint8_t key_len,
2434                         uint8_t iv_len)
2435 {
2436         uint8_t cipher_key[key_len];
2437         int status;
2438         struct crypto_testsuite_params *ts_params = &testsuite_params;
2439         struct crypto_unittest_params *ut_params = &unittest_params;
2440
2441         memcpy(cipher_key, key, key_len);
2442
2443         /* Setup Cipher Parameters */
2444         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2445         ut_params->cipher_xform.next = NULL;
2446
2447         ut_params->cipher_xform.cipher.algo = algo;
2448         ut_params->cipher_xform.cipher.op = op;
2449         ut_params->cipher_xform.cipher.key.data = cipher_key;
2450         ut_params->cipher_xform.cipher.key.length = key_len;
2451         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2452         ut_params->cipher_xform.cipher.iv.length = iv_len;
2453
2454         debug_hexdump(stdout, "key:", key, key_len);
2455
2456         /* Create Crypto session */
2457         ut_params->sess = rte_cryptodev_sym_session_create(
2458                         ts_params->session_mpool);
2459
2460         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2461                         &ut_params->cipher_xform,
2462                         ts_params->session_priv_mpool);
2463         if (status == -ENOTSUP)
2464                 return TEST_SKIPPED;
2465
2466         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2467         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2468         return 0;
2469 }
2470
2471 static int
2472 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2473                         unsigned int cipher_len,
2474                         unsigned int cipher_offset)
2475 {
2476         struct crypto_testsuite_params *ts_params = &testsuite_params;
2477         struct crypto_unittest_params *ut_params = &unittest_params;
2478
2479         /* Generate Crypto op data structure */
2480         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2481                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2482         TEST_ASSERT_NOT_NULL(ut_params->op,
2483                                 "Failed to allocate pktmbuf offload");
2484
2485         /* Set crypto operation data parameters */
2486         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2487
2488         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2489
2490         /* set crypto operation source mbuf */
2491         sym_op->m_src = ut_params->ibuf;
2492
2493         /* iv */
2494         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2495                         iv, iv_len);
2496         sym_op->cipher.data.length = cipher_len;
2497         sym_op->cipher.data.offset = cipher_offset;
2498         return 0;
2499 }
2500
2501 static int
2502 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2503                         unsigned int cipher_len,
2504                         unsigned int cipher_offset)
2505 {
2506         struct crypto_testsuite_params *ts_params = &testsuite_params;
2507         struct crypto_unittest_params *ut_params = &unittest_params;
2508
2509         /* Generate Crypto op data structure */
2510         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2511                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2512         TEST_ASSERT_NOT_NULL(ut_params->op,
2513                                 "Failed to allocate pktmbuf offload");
2514
2515         /* Set crypto operation data parameters */
2516         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2517
2518         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2519
2520         /* set crypto operation source mbuf */
2521         sym_op->m_src = ut_params->ibuf;
2522         sym_op->m_dst = ut_params->obuf;
2523
2524         /* iv */
2525         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2526                         iv, iv_len);
2527         sym_op->cipher.data.length = cipher_len;
2528         sym_op->cipher.data.offset = cipher_offset;
2529         return 0;
2530 }
2531
2532 static int
2533 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2534                 enum rte_crypto_cipher_operation cipher_op,
2535                 enum rte_crypto_auth_operation auth_op,
2536                 enum rte_crypto_auth_algorithm auth_algo,
2537                 enum rte_crypto_cipher_algorithm cipher_algo,
2538                 const uint8_t *key, uint8_t key_len,
2539                 uint8_t auth_iv_len, uint8_t auth_len,
2540                 uint8_t cipher_iv_len)
2541
2542 {
2543         uint8_t cipher_auth_key[key_len];
2544         int status;
2545
2546         struct crypto_testsuite_params *ts_params = &testsuite_params;
2547         struct crypto_unittest_params *ut_params = &unittest_params;
2548
2549         memcpy(cipher_auth_key, key, key_len);
2550
2551         /* Setup Authentication Parameters */
2552         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2553         ut_params->auth_xform.next = NULL;
2554
2555         ut_params->auth_xform.auth.op = auth_op;
2556         ut_params->auth_xform.auth.algo = auth_algo;
2557         ut_params->auth_xform.auth.key.length = key_len;
2558         /* Hash key = cipher key */
2559         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2560         ut_params->auth_xform.auth.digest_length = auth_len;
2561         /* Auth IV will be after cipher IV */
2562         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2563         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2564
2565         /* Setup Cipher Parameters */
2566         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2567         ut_params->cipher_xform.next = &ut_params->auth_xform;
2568
2569         ut_params->cipher_xform.cipher.algo = cipher_algo;
2570         ut_params->cipher_xform.cipher.op = cipher_op;
2571         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2572         ut_params->cipher_xform.cipher.key.length = key_len;
2573         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2574         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2575
2576         debug_hexdump(stdout, "key:", key, key_len);
2577
2578         /* Create Crypto session*/
2579         ut_params->sess = rte_cryptodev_sym_session_create(
2580                         ts_params->session_mpool);
2581         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2582
2583         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2584                         &ut_params->cipher_xform,
2585                         ts_params->session_priv_mpool);
2586         if (status == -ENOTSUP)
2587                 return TEST_SKIPPED;
2588
2589         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2590         return 0;
2591 }
2592
2593 static int
2594 create_wireless_cipher_auth_session(uint8_t dev_id,
2595                 enum rte_crypto_cipher_operation cipher_op,
2596                 enum rte_crypto_auth_operation auth_op,
2597                 enum rte_crypto_auth_algorithm auth_algo,
2598                 enum rte_crypto_cipher_algorithm cipher_algo,
2599                 const struct wireless_test_data *tdata)
2600 {
2601         const uint8_t key_len = tdata->key.len;
2602         uint8_t cipher_auth_key[key_len];
2603         int status;
2604
2605         struct crypto_testsuite_params *ts_params = &testsuite_params;
2606         struct crypto_unittest_params *ut_params = &unittest_params;
2607         const uint8_t *key = tdata->key.data;
2608         const uint8_t auth_len = tdata->digest.len;
2609         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2610         uint8_t auth_iv_len = tdata->auth_iv.len;
2611
2612         memcpy(cipher_auth_key, key, key_len);
2613
2614         /* Setup Authentication Parameters */
2615         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2616         ut_params->auth_xform.next = NULL;
2617
2618         ut_params->auth_xform.auth.op = auth_op;
2619         ut_params->auth_xform.auth.algo = auth_algo;
2620         ut_params->auth_xform.auth.key.length = key_len;
2621         /* Hash key = cipher key */
2622         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2623         ut_params->auth_xform.auth.digest_length = auth_len;
2624         /* Auth IV will be after cipher IV */
2625         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2626         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2627
2628         /* Setup Cipher Parameters */
2629         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2630         ut_params->cipher_xform.next = &ut_params->auth_xform;
2631
2632         ut_params->cipher_xform.cipher.algo = cipher_algo;
2633         ut_params->cipher_xform.cipher.op = cipher_op;
2634         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2635         ut_params->cipher_xform.cipher.key.length = key_len;
2636         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2637         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2638
2639
2640         debug_hexdump(stdout, "key:", key, key_len);
2641
2642         /* Create Crypto session*/
2643         ut_params->sess = rte_cryptodev_sym_session_create(
2644                         ts_params->session_mpool);
2645
2646         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2647                         &ut_params->cipher_xform,
2648                         ts_params->session_priv_mpool);
2649         if (status == -ENOTSUP)
2650                 return TEST_SKIPPED;
2651
2652         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2653         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2654         return 0;
2655 }
2656
2657 static int
2658 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2659                 const struct wireless_test_data *tdata)
2660 {
2661         return create_wireless_cipher_auth_session(dev_id,
2662                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2663                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2664                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2665 }
2666
2667 static int
2668 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2669                 enum rte_crypto_cipher_operation cipher_op,
2670                 enum rte_crypto_auth_operation auth_op,
2671                 enum rte_crypto_auth_algorithm auth_algo,
2672                 enum rte_crypto_cipher_algorithm cipher_algo,
2673                 const uint8_t *key, const uint8_t key_len,
2674                 uint8_t auth_iv_len, uint8_t auth_len,
2675                 uint8_t cipher_iv_len)
2676 {
2677         uint8_t auth_cipher_key[key_len];
2678         int status;
2679         struct crypto_testsuite_params *ts_params = &testsuite_params;
2680         struct crypto_unittest_params *ut_params = &unittest_params;
2681
2682         memcpy(auth_cipher_key, key, key_len);
2683
2684         /* Setup Authentication Parameters */
2685         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2686         ut_params->auth_xform.auth.op = auth_op;
2687         ut_params->auth_xform.next = &ut_params->cipher_xform;
2688         ut_params->auth_xform.auth.algo = auth_algo;
2689         ut_params->auth_xform.auth.key.length = key_len;
2690         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2691         ut_params->auth_xform.auth.digest_length = auth_len;
2692         /* Auth IV will be after cipher IV */
2693         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2694         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2695
2696         /* Setup Cipher Parameters */
2697         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2698         ut_params->cipher_xform.next = NULL;
2699         ut_params->cipher_xform.cipher.algo = cipher_algo;
2700         ut_params->cipher_xform.cipher.op = cipher_op;
2701         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2702         ut_params->cipher_xform.cipher.key.length = key_len;
2703         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2704         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2705
2706         debug_hexdump(stdout, "key:", key, key_len);
2707
2708         /* Create Crypto session*/
2709         ut_params->sess = rte_cryptodev_sym_session_create(
2710                         ts_params->session_mpool);
2711         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2712
2713         if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2714                 ut_params->auth_xform.next = NULL;
2715                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2716                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2717                                 &ut_params->cipher_xform,
2718                                 ts_params->session_priv_mpool);
2719
2720         } else
2721                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2722                                 &ut_params->auth_xform,
2723                                 ts_params->session_priv_mpool);
2724
2725         if (status == -ENOTSUP)
2726                 return TEST_SKIPPED;
2727
2728         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2729
2730         return 0;
2731 }
2732
2733 static int
2734 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2735                 unsigned int auth_tag_len,
2736                 const uint8_t *iv, unsigned int iv_len,
2737                 unsigned int data_pad_len,
2738                 enum rte_crypto_auth_operation op,
2739                 unsigned int auth_len, unsigned int auth_offset)
2740 {
2741         struct crypto_testsuite_params *ts_params = &testsuite_params;
2742
2743         struct crypto_unittest_params *ut_params = &unittest_params;
2744
2745         /* Generate Crypto op data structure */
2746         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2747                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2748         TEST_ASSERT_NOT_NULL(ut_params->op,
2749                 "Failed to allocate pktmbuf offload");
2750
2751         /* Set crypto operation data parameters */
2752         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2753
2754         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2755
2756         /* set crypto operation source mbuf */
2757         sym_op->m_src = ut_params->ibuf;
2758
2759         /* iv */
2760         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2761                         iv, iv_len);
2762         /* digest */
2763         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2764                                         ut_params->ibuf, auth_tag_len);
2765
2766         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2767                                 "no room to append auth tag");
2768         ut_params->digest = sym_op->auth.digest.data;
2769         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2770                         ut_params->ibuf, data_pad_len);
2771         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2772                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2773         else
2774                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2775
2776         debug_hexdump(stdout, "digest:",
2777                 sym_op->auth.digest.data,
2778                 auth_tag_len);
2779
2780         sym_op->auth.data.length = auth_len;
2781         sym_op->auth.data.offset = auth_offset;
2782
2783         return 0;
2784 }
2785
2786 static int
2787 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2788         enum rte_crypto_auth_operation op)
2789 {
2790         struct crypto_testsuite_params *ts_params = &testsuite_params;
2791         struct crypto_unittest_params *ut_params = &unittest_params;
2792
2793         const uint8_t *auth_tag = tdata->digest.data;
2794         const unsigned int auth_tag_len = tdata->digest.len;
2795         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2796         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2797
2798         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2799         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2800         const uint8_t *auth_iv = tdata->auth_iv.data;
2801         const uint8_t auth_iv_len = tdata->auth_iv.len;
2802         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2803         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2804
2805         /* Generate Crypto op data structure */
2806         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2807                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2808         TEST_ASSERT_NOT_NULL(ut_params->op,
2809                         "Failed to allocate pktmbuf offload");
2810         /* Set crypto operation data parameters */
2811         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2812
2813         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2814
2815         /* set crypto operation source mbuf */
2816         sym_op->m_src = ut_params->ibuf;
2817
2818         /* digest */
2819         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2820                         ut_params->ibuf, auth_tag_len);
2821
2822         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2823                         "no room to append auth tag");
2824         ut_params->digest = sym_op->auth.digest.data;
2825         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2826                         ut_params->ibuf, data_pad_len);
2827         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2828                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2829         else
2830                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2831
2832         debug_hexdump(stdout, "digest:",
2833                 sym_op->auth.digest.data,
2834                 auth_tag_len);
2835
2836         /* Copy cipher and auth IVs at the end of the crypto operation */
2837         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2838                                                 IV_OFFSET);
2839         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2840         iv_ptr += cipher_iv_len;
2841         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2842
2843         sym_op->cipher.data.length = cipher_len;
2844         sym_op->cipher.data.offset = 0;
2845         sym_op->auth.data.length = auth_len;
2846         sym_op->auth.data.offset = 0;
2847
2848         return 0;
2849 }
2850
2851 static int
2852 create_zuc_cipher_hash_generate_operation(
2853                 const struct wireless_test_data *tdata)
2854 {
2855         return create_wireless_cipher_hash_operation(tdata,
2856                 RTE_CRYPTO_AUTH_OP_GENERATE);
2857 }
2858
2859 static int
2860 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2861                 const unsigned auth_tag_len,
2862                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2863                 unsigned data_pad_len,
2864                 enum rte_crypto_auth_operation op,
2865                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2866                 const unsigned cipher_len, const unsigned cipher_offset,
2867                 const unsigned auth_len, const unsigned auth_offset)
2868 {
2869         struct crypto_testsuite_params *ts_params = &testsuite_params;
2870         struct crypto_unittest_params *ut_params = &unittest_params;
2871
2872         enum rte_crypto_cipher_algorithm cipher_algo =
2873                         ut_params->cipher_xform.cipher.algo;
2874         enum rte_crypto_auth_algorithm auth_algo =
2875                         ut_params->auth_xform.auth.algo;
2876
2877         /* Generate Crypto op data structure */
2878         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2879                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2880         TEST_ASSERT_NOT_NULL(ut_params->op,
2881                         "Failed to allocate pktmbuf offload");
2882         /* Set crypto operation data parameters */
2883         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2884
2885         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2886
2887         /* set crypto operation source mbuf */
2888         sym_op->m_src = ut_params->ibuf;
2889
2890         /* digest */
2891         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2892                         ut_params->ibuf, auth_tag_len);
2893
2894         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2895                         "no room to append auth tag");
2896         ut_params->digest = sym_op->auth.digest.data;
2897
2898         if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2899                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2900                                 ut_params->ibuf, data_pad_len);
2901         } else {
2902                 struct rte_mbuf *m = ut_params->ibuf;
2903                 unsigned int offset = data_pad_len;
2904
2905                 while (offset > m->data_len && m->next != NULL) {
2906                         offset -= m->data_len;
2907                         m = m->next;
2908                 }
2909                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2910                         m, offset);
2911         }
2912
2913         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2914                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2915         else
2916                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2917
2918         debug_hexdump(stdout, "digest:",
2919                 sym_op->auth.digest.data,
2920                 auth_tag_len);
2921
2922         /* Copy cipher and auth IVs at the end of the crypto operation */
2923         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2924                                                 IV_OFFSET);
2925         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2926         iv_ptr += cipher_iv_len;
2927         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2928
2929         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2930                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2931                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2932                 sym_op->cipher.data.length = cipher_len;
2933                 sym_op->cipher.data.offset = cipher_offset;
2934         } else {
2935                 sym_op->cipher.data.length = cipher_len >> 3;
2936                 sym_op->cipher.data.offset = cipher_offset >> 3;
2937         }
2938
2939         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2940                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2941                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2942                 sym_op->auth.data.length = auth_len;
2943                 sym_op->auth.data.offset = auth_offset;
2944         } else {
2945                 sym_op->auth.data.length = auth_len >> 3;
2946                 sym_op->auth.data.offset = auth_offset >> 3;
2947         }
2948
2949         return 0;
2950 }
2951
2952 static int
2953 create_wireless_algo_auth_cipher_operation(
2954                 const uint8_t *auth_tag, unsigned int auth_tag_len,
2955                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2956                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2957                 unsigned int data_pad_len,
2958                 unsigned int cipher_len, unsigned int cipher_offset,
2959                 unsigned int auth_len, unsigned int auth_offset,
2960                 uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2961 {
2962         struct crypto_testsuite_params *ts_params = &testsuite_params;
2963         struct crypto_unittest_params *ut_params = &unittest_params;
2964
2965         enum rte_crypto_cipher_algorithm cipher_algo =
2966                         ut_params->cipher_xform.cipher.algo;
2967         enum rte_crypto_auth_algorithm auth_algo =
2968                         ut_params->auth_xform.auth.algo;
2969
2970         /* Generate Crypto op data structure */
2971         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2972                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2973         TEST_ASSERT_NOT_NULL(ut_params->op,
2974                         "Failed to allocate pktmbuf offload");
2975
2976         /* Set crypto operation data parameters */
2977         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2978
2979         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2980
2981         /* set crypto operation mbufs */
2982         sym_op->m_src = ut_params->ibuf;
2983         if (op_mode == OUT_OF_PLACE)
2984                 sym_op->m_dst = ut_params->obuf;
2985
2986         /* digest */
2987         if (!do_sgl) {
2988                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2989                         (op_mode == IN_PLACE ?
2990                                 ut_params->ibuf : ut_params->obuf),
2991                         uint8_t *, data_pad_len);
2992                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2993                         (op_mode == IN_PLACE ?
2994                                 ut_params->ibuf : ut_params->obuf),
2995                         data_pad_len);
2996                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2997         } else {
2998                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2999                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
3000                                 sym_op->m_src : sym_op->m_dst);
3001                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
3002                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
3003                         sgl_buf = sgl_buf->next;
3004                 }
3005                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
3006                                 uint8_t *, remaining_off);
3007                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
3008                                 remaining_off);
3009                 memset(sym_op->auth.digest.data, 0, remaining_off);
3010                 while (sgl_buf->next != NULL) {
3011                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
3012                                 0, rte_pktmbuf_data_len(sgl_buf));
3013                         sgl_buf = sgl_buf->next;
3014                 }
3015         }
3016
3017         /* Copy digest for the verification */
3018         if (verify)
3019                 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3020
3021         /* Copy cipher and auth IVs at the end of the crypto operation */
3022         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3023                         ut_params->op, uint8_t *, IV_OFFSET);
3024
3025         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3026         iv_ptr += cipher_iv_len;
3027         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3028
3029         /* Only copy over the offset data needed from src to dst in OOP,
3030          * if the auth and cipher offsets are not aligned
3031          */
3032         if (op_mode == OUT_OF_PLACE) {
3033                 if (cipher_offset > auth_offset)
3034                         rte_memcpy(
3035                                 rte_pktmbuf_mtod_offset(
3036                                         sym_op->m_dst,
3037                                         uint8_t *, auth_offset >> 3),
3038                                 rte_pktmbuf_mtod_offset(
3039                                         sym_op->m_src,
3040                                         uint8_t *, auth_offset >> 3),
3041                                 ((cipher_offset >> 3) - (auth_offset >> 3)));
3042         }
3043
3044         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3045                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3046                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3047                 sym_op->cipher.data.length = cipher_len;
3048                 sym_op->cipher.data.offset = cipher_offset;
3049         } else {
3050                 sym_op->cipher.data.length = cipher_len >> 3;
3051                 sym_op->cipher.data.offset = cipher_offset >> 3;
3052         }
3053
3054         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3055                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3056                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3057                 sym_op->auth.data.length = auth_len;
3058                 sym_op->auth.data.offset = auth_offset;
3059         } else {
3060                 sym_op->auth.data.length = auth_len >> 3;
3061                 sym_op->auth.data.offset = auth_offset >> 3;
3062         }
3063
3064         return 0;
3065 }
3066
3067 static int
3068 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3069 {
3070         struct crypto_testsuite_params *ts_params = &testsuite_params;
3071         struct crypto_unittest_params *ut_params = &unittest_params;
3072
3073         int retval;
3074         unsigned plaintext_pad_len;
3075         unsigned plaintext_len;
3076         uint8_t *plaintext;
3077         struct rte_cryptodev_info dev_info;
3078
3079         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3080         uint64_t feat_flags = dev_info.feature_flags;
3081
3082         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3083                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3084                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3085                 return TEST_SKIPPED;
3086         }
3087
3088         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3089                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3090                 printf("Device doesn't support RAW data-path APIs.\n");
3091                 return TEST_SKIPPED;
3092         }
3093
3094         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3095                 return TEST_SKIPPED;
3096
3097         /* Verify the capabilities */
3098         struct rte_cryptodev_sym_capability_idx cap_idx;
3099         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3100         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3101         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3102                         &cap_idx) == NULL)
3103                 return TEST_SKIPPED;
3104
3105         /* Create SNOW 3G session */
3106         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3107                         tdata->key.data, tdata->key.len,
3108                         tdata->auth_iv.len, tdata->digest.len,
3109                         RTE_CRYPTO_AUTH_OP_GENERATE,
3110                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3111         if (retval < 0)
3112                 return retval;
3113
3114         /* alloc mbuf and set payload */
3115         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3116
3117         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3118         rte_pktmbuf_tailroom(ut_params->ibuf));
3119
3120         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3121         /* Append data which is padded to a multiple of */
3122         /* the algorithms block size */
3123         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3124         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3125                                 plaintext_pad_len);
3126         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3127
3128         /* Create SNOW 3G operation */
3129         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3130                         tdata->auth_iv.data, tdata->auth_iv.len,
3131                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3132                         tdata->validAuthLenInBits.len,
3133                         0);
3134         if (retval < 0)
3135                 return retval;
3136
3137         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3138                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3139                                 ut_params->op, 0, 1, 1, 0);
3140         else
3141                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3142                                 ut_params->op);
3143         ut_params->obuf = ut_params->op->sym->m_src;
3144         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3145         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3146                         + plaintext_pad_len;
3147
3148         /* Validate obuf */
3149         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3150         ut_params->digest,
3151         tdata->digest.data,
3152         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3153         "SNOW 3G Generated auth tag not as expected");
3154
3155         return 0;
3156 }
3157
3158 static int
3159 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3160 {
3161         struct crypto_testsuite_params *ts_params = &testsuite_params;
3162         struct crypto_unittest_params *ut_params = &unittest_params;
3163
3164         int retval;
3165         unsigned plaintext_pad_len;
3166         unsigned plaintext_len;
3167         uint8_t *plaintext;
3168         struct rte_cryptodev_info dev_info;
3169
3170         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3171         uint64_t feat_flags = dev_info.feature_flags;
3172
3173         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3174                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3175                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3176                 return TEST_SKIPPED;
3177         }
3178
3179         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3180                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3181                 printf("Device doesn't support RAW data-path APIs.\n");
3182                 return TEST_SKIPPED;
3183         }
3184
3185         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3186                 return TEST_SKIPPED;
3187
3188         /* Verify the capabilities */
3189         struct rte_cryptodev_sym_capability_idx cap_idx;
3190         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3191         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3192         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3193                         &cap_idx) == NULL)
3194                 return TEST_SKIPPED;
3195
3196         /* Create SNOW 3G session */
3197         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3198                                 tdata->key.data, tdata->key.len,
3199                                 tdata->auth_iv.len, tdata->digest.len,
3200                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3201                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3202         if (retval < 0)
3203                 return retval;
3204         /* alloc mbuf and set payload */
3205         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3206
3207         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3208         rte_pktmbuf_tailroom(ut_params->ibuf));
3209
3210         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3211         /* Append data which is padded to a multiple of */
3212         /* the algorithms block size */
3213         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3214         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3215                                 plaintext_pad_len);
3216         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3217
3218         /* Create SNOW 3G operation */
3219         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3220                         tdata->digest.len,
3221                         tdata->auth_iv.data, tdata->auth_iv.len,
3222                         plaintext_pad_len,
3223                         RTE_CRYPTO_AUTH_OP_VERIFY,
3224                         tdata->validAuthLenInBits.len,
3225                         0);
3226         if (retval < 0)
3227                 return retval;
3228
3229         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3230                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3231                                 ut_params->op, 0, 1, 1, 0);
3232         else
3233                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3234                                 ut_params->op);
3235         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3236         ut_params->obuf = ut_params->op->sym->m_src;
3237         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3238                                 + plaintext_pad_len;
3239
3240         /* Validate obuf */
3241         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3242                 return 0;
3243         else
3244                 return -1;
3245
3246         return 0;
3247 }
3248
3249 static int
3250 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3251 {
3252         struct crypto_testsuite_params *ts_params = &testsuite_params;
3253         struct crypto_unittest_params *ut_params = &unittest_params;
3254
3255         int retval;
3256         unsigned plaintext_pad_len;
3257         unsigned plaintext_len;
3258         uint8_t *plaintext;
3259         struct rte_cryptodev_info dev_info;
3260
3261         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3262         uint64_t feat_flags = dev_info.feature_flags;
3263
3264         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3265                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3266                 printf("Device doesn't support RAW data-path APIs.\n");
3267                 return TEST_SKIPPED;
3268         }
3269
3270         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3271                 return TEST_SKIPPED;
3272
3273         /* Verify the capabilities */
3274         struct rte_cryptodev_sym_capability_idx cap_idx;
3275         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3276         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3277         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3278                         &cap_idx) == NULL)
3279                 return TEST_SKIPPED;
3280
3281         /* Create KASUMI session */
3282         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3283                         tdata->key.data, tdata->key.len,
3284                         0, tdata->digest.len,
3285                         RTE_CRYPTO_AUTH_OP_GENERATE,
3286                         RTE_CRYPTO_AUTH_KASUMI_F9);
3287         if (retval < 0)
3288                 return retval;
3289
3290         /* alloc mbuf and set payload */
3291         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3292
3293         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3294         rte_pktmbuf_tailroom(ut_params->ibuf));
3295
3296         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3297         /* Append data which is padded to a multiple of */
3298         /* the algorithms block size */
3299         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3300         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3301                                 plaintext_pad_len);
3302         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3303
3304         /* Create KASUMI operation */
3305         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3306                         NULL, 0,
3307                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3308                         tdata->plaintext.len,
3309                         0);
3310         if (retval < 0)
3311                 return retval;
3312
3313         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3314                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3315                         ut_params->op);
3316         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3317                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3318                                 ut_params->op, 0, 1, 1, 0);
3319         else
3320                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3321                         ut_params->op);
3322
3323         ut_params->obuf = ut_params->op->sym->m_src;
3324         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3325         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3326                         + plaintext_pad_len;
3327
3328         /* Validate obuf */
3329         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3330         ut_params->digest,
3331         tdata->digest.data,
3332         DIGEST_BYTE_LENGTH_KASUMI_F9,
3333         "KASUMI Generated auth tag not as expected");
3334
3335         return 0;
3336 }
3337
3338 static int
3339 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3340 {
3341         struct crypto_testsuite_params *ts_params = &testsuite_params;
3342         struct crypto_unittest_params *ut_params = &unittest_params;
3343
3344         int retval;
3345         unsigned plaintext_pad_len;
3346         unsigned plaintext_len;
3347         uint8_t *plaintext;
3348         struct rte_cryptodev_info dev_info;
3349
3350         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3351         uint64_t feat_flags = dev_info.feature_flags;
3352
3353         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3354                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3355                 printf("Device doesn't support RAW data-path APIs.\n");
3356                 return TEST_SKIPPED;
3357         }
3358
3359         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3360                 return TEST_SKIPPED;
3361
3362         /* Verify the capabilities */
3363         struct rte_cryptodev_sym_capability_idx cap_idx;
3364         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3365         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3366         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3367                         &cap_idx) == NULL)
3368                 return TEST_SKIPPED;
3369
3370         /* Create KASUMI session */
3371         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3372                                 tdata->key.data, tdata->key.len,
3373                                 0, tdata->digest.len,
3374                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3375                                 RTE_CRYPTO_AUTH_KASUMI_F9);
3376         if (retval < 0)
3377                 return retval;
3378         /* alloc mbuf and set payload */
3379         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3380
3381         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3382         rte_pktmbuf_tailroom(ut_params->ibuf));
3383
3384         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3385         /* Append data which is padded to a multiple */
3386         /* of the algorithms block size */
3387         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3388         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3389                                 plaintext_pad_len);
3390         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3391
3392         /* Create KASUMI operation */
3393         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3394                         tdata->digest.len,
3395                         NULL, 0,
3396                         plaintext_pad_len,
3397                         RTE_CRYPTO_AUTH_OP_VERIFY,
3398                         tdata->plaintext.len,
3399                         0);
3400         if (retval < 0)
3401                 return retval;
3402
3403         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3404                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3405                                 ut_params->op, 0, 1, 1, 0);
3406         else
3407                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3408                                 ut_params->op);
3409         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3410         ut_params->obuf = ut_params->op->sym->m_src;
3411         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3412                                 + plaintext_pad_len;
3413
3414         /* Validate obuf */
3415         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3416                 return 0;
3417         else
3418                 return -1;
3419
3420         return 0;
3421 }
3422
3423 static int
3424 test_snow3g_hash_generate_test_case_1(void)
3425 {
3426         return test_snow3g_authentication(&snow3g_hash_test_case_1);
3427 }
3428
3429 static int
3430 test_snow3g_hash_generate_test_case_2(void)
3431 {
3432         return test_snow3g_authentication(&snow3g_hash_test_case_2);
3433 }
3434
3435 static int
3436 test_snow3g_hash_generate_test_case_3(void)
3437 {
3438         return test_snow3g_authentication(&snow3g_hash_test_case_3);
3439 }
3440
3441 static int
3442 test_snow3g_hash_generate_test_case_4(void)
3443 {
3444         return test_snow3g_authentication(&snow3g_hash_test_case_4);
3445 }
3446
3447 static int
3448 test_snow3g_hash_generate_test_case_5(void)
3449 {
3450         return test_snow3g_authentication(&snow3g_hash_test_case_5);
3451 }
3452
3453 static int
3454 test_snow3g_hash_generate_test_case_6(void)
3455 {
3456         return test_snow3g_authentication(&snow3g_hash_test_case_6);
3457 }
3458
3459 static int
3460 test_snow3g_hash_verify_test_case_1(void)
3461 {
3462         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3463
3464 }
3465
3466 static int
3467 test_snow3g_hash_verify_test_case_2(void)
3468 {
3469         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3470 }
3471
3472 static int
3473 test_snow3g_hash_verify_test_case_3(void)
3474 {
3475         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3476 }
3477
3478 static int
3479 test_snow3g_hash_verify_test_case_4(void)
3480 {
3481         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3482 }
3483
3484 static int
3485 test_snow3g_hash_verify_test_case_5(void)
3486 {
3487         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3488 }
3489
3490 static int
3491 test_snow3g_hash_verify_test_case_6(void)
3492 {
3493         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3494 }
3495
3496 static int
3497 test_kasumi_hash_generate_test_case_1(void)
3498 {
3499         return test_kasumi_authentication(&kasumi_hash_test_case_1);
3500 }
3501
3502 static int
3503 test_kasumi_hash_generate_test_case_2(void)
3504 {
3505         return test_kasumi_authentication(&kasumi_hash_test_case_2);
3506 }
3507
3508 static int
3509 test_kasumi_hash_generate_test_case_3(void)
3510 {
3511         return test_kasumi_authentication(&kasumi_hash_test_case_3);
3512 }
3513
3514 static int
3515 test_kasumi_hash_generate_test_case_4(void)
3516 {
3517         return test_kasumi_authentication(&kasumi_hash_test_case_4);
3518 }
3519
3520 static int
3521 test_kasumi_hash_generate_test_case_5(void)
3522 {
3523         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3524 }
3525
3526 static int
3527 test_kasumi_hash_generate_test_case_6(void)
3528 {
3529         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3530 }
3531
3532 static int
3533 test_kasumi_hash_verify_test_case_1(void)
3534 {
3535         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3536 }
3537
3538 static int
3539 test_kasumi_hash_verify_test_case_2(void)
3540 {
3541         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3542 }
3543
3544 static int
3545 test_kasumi_hash_verify_test_case_3(void)
3546 {
3547         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3548 }
3549
3550 static int
3551 test_kasumi_hash_verify_test_case_4(void)
3552 {
3553         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3554 }
3555
3556 static int
3557 test_kasumi_hash_verify_test_case_5(void)
3558 {
3559         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3560 }
3561
3562 static int
3563 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3564 {
3565         struct crypto_testsuite_params *ts_params = &testsuite_params;
3566         struct crypto_unittest_params *ut_params = &unittest_params;
3567
3568         int retval;
3569         uint8_t *plaintext, *ciphertext;
3570         unsigned plaintext_pad_len;
3571         unsigned plaintext_len;
3572         struct rte_cryptodev_info dev_info;
3573
3574         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3575         uint64_t feat_flags = dev_info.feature_flags;
3576
3577         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3578                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3579                 printf("Device doesn't support RAW data-path APIs.\n");
3580                 return TEST_SKIPPED;
3581         }
3582
3583         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3584                 return TEST_SKIPPED;
3585
3586         /* Verify the capabilities */
3587         struct rte_cryptodev_sym_capability_idx cap_idx;
3588         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3589         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3590         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3591                         &cap_idx) == NULL)
3592                 return TEST_SKIPPED;
3593
3594         /* Create KASUMI session */
3595         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3596                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3597                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3598                                         tdata->key.data, tdata->key.len,
3599                                         tdata->cipher_iv.len);
3600         if (retval < 0)
3601                 return retval;
3602
3603         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3604
3605         /* Clear mbuf payload */
3606         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3607                rte_pktmbuf_tailroom(ut_params->ibuf));
3608
3609         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3610         /* Append data which is padded to a multiple */
3611         /* of the algorithms block size */
3612         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3613         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3614                                 plaintext_pad_len);
3615         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3616
3617         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3618
3619         /* Create KASUMI operation */
3620         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3621                                 tdata->cipher_iv.len,
3622                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3623                                 tdata->validCipherOffsetInBits.len);
3624         if (retval < 0)
3625                 return retval;
3626
3627         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3628                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3629                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3630         else
3631                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3632                                 ut_params->op);
3633         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3634
3635         ut_params->obuf = ut_params->op->sym->m_dst;
3636         if (ut_params->obuf)
3637                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3638         else
3639                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3640
3641         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3642
3643         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3644                                 (tdata->validCipherOffsetInBits.len >> 3);
3645         /* Validate obuf */
3646         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3647                 ciphertext,
3648                 reference_ciphertext,
3649                 tdata->validCipherLenInBits.len,
3650                 "KASUMI Ciphertext data not as expected");
3651         return 0;
3652 }
3653
3654 static int
3655 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3656 {
3657         struct crypto_testsuite_params *ts_params = &testsuite_params;
3658         struct crypto_unittest_params *ut_params = &unittest_params;
3659
3660         int retval;
3661
3662         unsigned int plaintext_pad_len;
3663         unsigned int plaintext_len;
3664
3665         uint8_t buffer[10000];
3666         const uint8_t *ciphertext;
3667
3668         struct rte_cryptodev_info dev_info;
3669
3670         /* Verify the capabilities */
3671         struct rte_cryptodev_sym_capability_idx cap_idx;
3672         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3673         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3674         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3675                         &cap_idx) == NULL)
3676                 return TEST_SKIPPED;
3677
3678         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3679
3680         uint64_t feat_flags = dev_info.feature_flags;
3681
3682         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3683                 printf("Device doesn't support in-place scatter-gather. "
3684                                 "Test Skipped.\n");
3685                 return TEST_SKIPPED;
3686         }
3687
3688         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3689                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3690                 printf("Device doesn't support RAW data-path APIs.\n");
3691                 return TEST_SKIPPED;
3692         }
3693
3694         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3695                 return TEST_SKIPPED;
3696
3697         /* Create KASUMI session */
3698         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3699                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3700                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3701                                         tdata->key.data, tdata->key.len,
3702                                         tdata->cipher_iv.len);
3703         if (retval < 0)
3704                 return retval;
3705
3706         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3707
3708
3709         /* Append data which is padded to a multiple */
3710         /* of the algorithms block size */
3711         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3712
3713         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3714                         plaintext_pad_len, 10, 0);
3715
3716         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3717
3718         /* Create KASUMI operation */
3719         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3720                                 tdata->cipher_iv.len,
3721                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3722                                 tdata->validCipherOffsetInBits.len);
3723         if (retval < 0)
3724                 return retval;
3725
3726         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3727                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3728                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3729         else
3730                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3731                                                 ut_params->op);
3732         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3733
3734         ut_params->obuf = ut_params->op->sym->m_dst;
3735
3736         if (ut_params->obuf)
3737                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3738                                 plaintext_len, buffer);
3739         else
3740                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3741                                 tdata->validCipherOffsetInBits.len >> 3,
3742                                 plaintext_len, buffer);
3743
3744         /* Validate obuf */
3745         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3746
3747         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3748                                 (tdata->validCipherOffsetInBits.len >> 3);
3749         /* Validate obuf */
3750         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3751                 ciphertext,
3752                 reference_ciphertext,
3753                 tdata->validCipherLenInBits.len,
3754                 "KASUMI Ciphertext data not as expected");
3755         return 0;
3756 }
3757
3758 static int
3759 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3760 {
3761         struct crypto_testsuite_params *ts_params = &testsuite_params;
3762         struct crypto_unittest_params *ut_params = &unittest_params;
3763
3764         int retval;
3765         uint8_t *plaintext, *ciphertext;
3766         unsigned plaintext_pad_len;
3767         unsigned plaintext_len;
3768
3769         /* Verify the capabilities */
3770         struct rte_cryptodev_sym_capability_idx cap_idx;
3771         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3772         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3773         /* Data-path service does not support OOP */
3774         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3775                         &cap_idx) == NULL)
3776                 return TEST_SKIPPED;
3777
3778         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3779                 return TEST_SKIPPED;
3780
3781         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3782                 return TEST_SKIPPED;
3783
3784         /* Create KASUMI session */
3785         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3786                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3787                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3788                                         tdata->key.data, tdata->key.len,
3789                                         tdata->cipher_iv.len);
3790         if (retval < 0)
3791                 return retval;
3792
3793         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3794         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3795
3796         /* Clear mbuf payload */
3797         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3798                rte_pktmbuf_tailroom(ut_params->ibuf));
3799
3800         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3801         /* Append data which is padded to a multiple */
3802         /* of the algorithms block size */
3803         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3804         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3805                                 plaintext_pad_len);
3806         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3807         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3808
3809         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3810
3811         /* Create KASUMI operation */
3812         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3813                                 tdata->cipher_iv.len,
3814                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3815                                 tdata->validCipherOffsetInBits.len);
3816         if (retval < 0)
3817                 return retval;
3818
3819         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3820                                                 ut_params->op);
3821         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3822
3823         ut_params->obuf = ut_params->op->sym->m_dst;
3824         if (ut_params->obuf)
3825                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3826         else
3827                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3828
3829         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3830
3831         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3832                                 (tdata->validCipherOffsetInBits.len >> 3);
3833         /* Validate obuf */
3834         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3835                 ciphertext,
3836                 reference_ciphertext,
3837                 tdata->validCipherLenInBits.len,
3838                 "KASUMI Ciphertext data not as expected");
3839         return 0;
3840 }
3841
3842 static int
3843 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3844 {
3845         struct crypto_testsuite_params *ts_params = &testsuite_params;
3846         struct crypto_unittest_params *ut_params = &unittest_params;
3847
3848         int retval;
3849         unsigned int plaintext_pad_len;
3850         unsigned int plaintext_len;
3851
3852         const uint8_t *ciphertext;
3853         uint8_t buffer[2048];
3854
3855         struct rte_cryptodev_info dev_info;
3856
3857         /* Verify the capabilities */
3858         struct rte_cryptodev_sym_capability_idx cap_idx;
3859         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3860         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3861         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3862                         &cap_idx) == NULL)
3863                 return TEST_SKIPPED;
3864
3865         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3866                 return TEST_SKIPPED;
3867
3868         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3869                 return TEST_SKIPPED;
3870
3871         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3872
3873         uint64_t feat_flags = dev_info.feature_flags;
3874         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3875                 printf("Device doesn't support out-of-place scatter-gather "
3876                                 "in both input and output mbufs. "
3877                                 "Test Skipped.\n");
3878                 return TEST_SKIPPED;
3879         }
3880
3881         /* Create KASUMI session */
3882         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3883                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3884                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3885                                         tdata->key.data, tdata->key.len,
3886                                         tdata->cipher_iv.len);
3887         if (retval < 0)
3888                 return retval;
3889
3890         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3891         /* Append data which is padded to a multiple */
3892         /* of the algorithms block size */
3893         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3894
3895         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3896                         plaintext_pad_len, 10, 0);
3897         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3898                         plaintext_pad_len, 3, 0);
3899
3900         /* Append data which is padded to a multiple */
3901         /* of the algorithms block size */
3902         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3903
3904         /* Create KASUMI operation */
3905         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3906                                 tdata->cipher_iv.len,
3907                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3908                                 tdata->validCipherOffsetInBits.len);
3909         if (retval < 0)
3910                 return retval;
3911
3912         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3913                                                 ut_params->op);
3914         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3915
3916         ut_params->obuf = ut_params->op->sym->m_dst;
3917         if (ut_params->obuf)
3918                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3919                                 plaintext_pad_len, buffer);
3920         else
3921                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3922                                 tdata->validCipherOffsetInBits.len >> 3,
3923                                 plaintext_pad_len, buffer);
3924
3925         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3926                                 (tdata->validCipherOffsetInBits.len >> 3);
3927         /* Validate obuf */
3928         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3929                 ciphertext,
3930                 reference_ciphertext,
3931                 tdata->validCipherLenInBits.len,
3932                 "KASUMI Ciphertext data not as expected");
3933         return 0;
3934 }
3935
3936
3937 static int
3938 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3939 {
3940         struct crypto_testsuite_params *ts_params = &testsuite_params;
3941         struct crypto_unittest_params *ut_params = &unittest_params;
3942
3943         int retval;
3944         uint8_t *ciphertext, *plaintext;
3945         unsigned ciphertext_pad_len;
3946         unsigned ciphertext_len;
3947
3948         /* Verify the capabilities */
3949         struct rte_cryptodev_sym_capability_idx cap_idx;
3950         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3951         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3952         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3953                         &cap_idx) == NULL)
3954                 return TEST_SKIPPED;
3955
3956         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3957                 return TEST_SKIPPED;
3958
3959         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3960                 return TEST_SKIPPED;
3961
3962         /* Create KASUMI session */
3963         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3964                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3965                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3966                                         tdata->key.data, tdata->key.len,
3967                                         tdata->cipher_iv.len);
3968         if (retval < 0)
3969                 return retval;
3970
3971         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3972         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3973
3974         /* Clear mbuf payload */
3975         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3976                rte_pktmbuf_tailroom(ut_params->ibuf));
3977
3978         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3979         /* Append data which is padded to a multiple */
3980         /* of the algorithms block size */
3981         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3982         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3983                                 ciphertext_pad_len);
3984         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3985         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3986
3987         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3988
3989         /* Create KASUMI operation */
3990         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3991                                 tdata->cipher_iv.len,
3992                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3993                                 tdata->validCipherOffsetInBits.len);
3994         if (retval < 0)
3995                 return retval;
3996
3997         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3998                                                 ut_params->op);
3999         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4000
4001         ut_params->obuf = ut_params->op->sym->m_dst;
4002         if (ut_params->obuf)
4003                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4004         else
4005                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4006
4007         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4008
4009         const uint8_t *reference_plaintext = tdata->plaintext.data +
4010                                 (tdata->validCipherOffsetInBits.len >> 3);
4011         /* Validate obuf */
4012         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4013                 plaintext,
4014                 reference_plaintext,
4015                 tdata->validCipherLenInBits.len,
4016                 "KASUMI Plaintext data not as expected");
4017         return 0;
4018 }
4019
4020 static int
4021 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4022 {
4023         struct crypto_testsuite_params *ts_params = &testsuite_params;
4024         struct crypto_unittest_params *ut_params = &unittest_params;
4025
4026         int retval;
4027         uint8_t *ciphertext, *plaintext;
4028         unsigned ciphertext_pad_len;
4029         unsigned ciphertext_len;
4030         struct rte_cryptodev_info dev_info;
4031
4032         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4033         uint64_t feat_flags = dev_info.feature_flags;
4034
4035         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4036                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4037                 printf("Device doesn't support RAW data-path APIs.\n");
4038                 return TEST_SKIPPED;
4039         }
4040
4041         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4042                 return TEST_SKIPPED;
4043
4044         /* Verify the capabilities */
4045         struct rte_cryptodev_sym_capability_idx cap_idx;
4046         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4047         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4048         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4049                         &cap_idx) == NULL)
4050                 return TEST_SKIPPED;
4051
4052         /* Create KASUMI session */
4053         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4054                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4055                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4056                                         tdata->key.data, tdata->key.len,
4057                                         tdata->cipher_iv.len);
4058         if (retval < 0)
4059                 return retval;
4060
4061         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4062
4063         /* Clear mbuf payload */
4064         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4065                rte_pktmbuf_tailroom(ut_params->ibuf));
4066
4067         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4068         /* Append data which is padded to a multiple */
4069         /* of the algorithms block size */
4070         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4071         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4072                                 ciphertext_pad_len);
4073         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4074
4075         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4076
4077         /* Create KASUMI operation */
4078         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4079                                         tdata->cipher_iv.len,
4080                                         tdata->ciphertext.len,
4081                                         tdata->validCipherOffsetInBits.len);
4082         if (retval < 0)
4083                 return retval;
4084
4085         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4086                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4087                                 ut_params->op, 1, 0, 1, 0);
4088         else
4089                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4090                                                 ut_params->op);
4091         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4092
4093         ut_params->obuf = ut_params->op->sym->m_dst;
4094         if (ut_params->obuf)
4095                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4096         else
4097                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4098
4099         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4100
4101         const uint8_t *reference_plaintext = tdata->plaintext.data +
4102                                 (tdata->validCipherOffsetInBits.len >> 3);
4103         /* Validate obuf */
4104         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4105                 plaintext,
4106                 reference_plaintext,
4107                 tdata->validCipherLenInBits.len,
4108                 "KASUMI Plaintext data not as expected");
4109         return 0;
4110 }
4111
4112 static int
4113 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4114 {
4115         struct crypto_testsuite_params *ts_params = &testsuite_params;
4116         struct crypto_unittest_params *ut_params = &unittest_params;
4117
4118         int retval;
4119         uint8_t *plaintext, *ciphertext;
4120         unsigned plaintext_pad_len;
4121         unsigned plaintext_len;
4122         struct rte_cryptodev_info dev_info;
4123
4124         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4125         uint64_t feat_flags = dev_info.feature_flags;
4126
4127         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4128                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4129                 printf("Device doesn't support RAW data-path APIs.\n");
4130                 return TEST_SKIPPED;
4131         }
4132
4133         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4134                 return TEST_SKIPPED;
4135
4136         /* Verify the capabilities */
4137         struct rte_cryptodev_sym_capability_idx cap_idx;
4138         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4139         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4140         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4141                         &cap_idx) == NULL)
4142                 return TEST_SKIPPED;
4143
4144         /* Create SNOW 3G session */
4145         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4146                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4147                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4148                                         tdata->key.data, tdata->key.len,
4149                                         tdata->cipher_iv.len);
4150         if (retval < 0)
4151                 return retval;
4152
4153         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4154
4155         /* Clear mbuf payload */
4156         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4157                rte_pktmbuf_tailroom(ut_params->ibuf));
4158
4159         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4160         /* Append data which is padded to a multiple of */
4161         /* the algorithms block size */
4162         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4163         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4164                                 plaintext_pad_len);
4165         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4166
4167         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4168
4169         /* Create SNOW 3G operation */
4170         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4171                                         tdata->cipher_iv.len,
4172                                         tdata->validCipherLenInBits.len,
4173                                         0);
4174         if (retval < 0)
4175                 return retval;
4176
4177         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4178                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4179                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4180         else
4181                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4182                                                 ut_params->op);
4183         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4184
4185         ut_params->obuf = ut_params->op->sym->m_dst;
4186         if (ut_params->obuf)
4187                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4188         else
4189                 ciphertext = plaintext;
4190
4191         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4192
4193         /* Validate obuf */
4194         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4195                 ciphertext,
4196                 tdata->ciphertext.data,
4197                 tdata->validDataLenInBits.len,
4198                 "SNOW 3G Ciphertext data not as expected");
4199         return 0;
4200 }
4201
4202
4203 static int
4204 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4205 {
4206         struct crypto_testsuite_params *ts_params = &testsuite_params;
4207         struct crypto_unittest_params *ut_params = &unittest_params;
4208         uint8_t *plaintext, *ciphertext;
4209
4210         int retval;
4211         unsigned plaintext_pad_len;
4212         unsigned plaintext_len;
4213
4214         /* Verify the capabilities */
4215         struct rte_cryptodev_sym_capability_idx cap_idx;
4216         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4217         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4218         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4219                         &cap_idx) == NULL)
4220                 return TEST_SKIPPED;
4221
4222         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4223                 return TEST_SKIPPED;
4224
4225         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4226                 return TEST_SKIPPED;
4227
4228         /* Create SNOW 3G session */
4229         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4230                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4231                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4232                                         tdata->key.data, tdata->key.len,
4233                                         tdata->cipher_iv.len);
4234         if (retval < 0)
4235                 return retval;
4236
4237         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4238         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4239
4240         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4241                         "Failed to allocate input buffer in mempool");
4242         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4243                         "Failed to allocate output buffer in mempool");
4244
4245         /* Clear mbuf payload */
4246         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4247                rte_pktmbuf_tailroom(ut_params->ibuf));
4248
4249         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4250         /* Append data which is padded to a multiple of */
4251         /* the algorithms block size */
4252         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4253         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4254                                 plaintext_pad_len);
4255         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4256         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4257
4258         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4259
4260         /* Create SNOW 3G operation */
4261         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4262                                         tdata->cipher_iv.len,
4263                                         tdata->validCipherLenInBits.len,
4264                                         0);
4265         if (retval < 0)
4266                 return retval;
4267
4268         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4269                                                 ut_params->op);
4270         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4271
4272         ut_params->obuf = ut_params->op->sym->m_dst;
4273         if (ut_params->obuf)
4274                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4275         else
4276                 ciphertext = plaintext;
4277
4278         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4279
4280         /* Validate obuf */
4281         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4282                 ciphertext,
4283                 tdata->ciphertext.data,
4284                 tdata->validDataLenInBits.len,
4285                 "SNOW 3G Ciphertext data not as expected");
4286         return 0;
4287 }
4288
4289 static int
4290 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4291 {
4292         struct crypto_testsuite_params *ts_params = &testsuite_params;
4293         struct crypto_unittest_params *ut_params = &unittest_params;
4294
4295         int retval;
4296         unsigned int plaintext_pad_len;
4297         unsigned int plaintext_len;
4298         uint8_t buffer[10000];
4299         const uint8_t *ciphertext;
4300
4301         struct rte_cryptodev_info dev_info;
4302
4303         /* Verify the capabilities */
4304         struct rte_cryptodev_sym_capability_idx cap_idx;
4305         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4306         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4307         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4308                         &cap_idx) == NULL)
4309                 return TEST_SKIPPED;
4310
4311         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4312                 return TEST_SKIPPED;
4313
4314         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4315                 return TEST_SKIPPED;
4316
4317         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4318
4319         uint64_t feat_flags = dev_info.feature_flags;
4320
4321         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4322                 printf("Device doesn't support out-of-place scatter-gather "
4323                                 "in both input and output mbufs. "
4324                                 "Test Skipped.\n");
4325                 return TEST_SKIPPED;
4326         }
4327
4328         /* Create SNOW 3G session */
4329         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4330                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4331                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4332                                         tdata->key.data, tdata->key.len,
4333                                         tdata->cipher_iv.len);
4334         if (retval < 0)
4335                 return retval;
4336
4337         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4338         /* Append data which is padded to a multiple of */
4339         /* the algorithms block size */
4340         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4341
4342         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4343                         plaintext_pad_len, 10, 0);
4344         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4345                         plaintext_pad_len, 3, 0);
4346
4347         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4348                         "Failed to allocate input buffer in mempool");
4349         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4350                         "Failed to allocate output buffer in mempool");
4351
4352         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4353
4354         /* Create SNOW 3G operation */
4355         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4356                                         tdata->cipher_iv.len,
4357                                         tdata->validCipherLenInBits.len,
4358                                         0);
4359         if (retval < 0)
4360                 return retval;
4361
4362         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4363                                                 ut_params->op);
4364         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4365
4366         ut_params->obuf = ut_params->op->sym->m_dst;
4367         if (ut_params->obuf)
4368                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4369                                 plaintext_len, buffer);
4370         else
4371                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4372                                 plaintext_len, buffer);
4373
4374         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4375
4376         /* Validate obuf */
4377         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4378                 ciphertext,
4379                 tdata->ciphertext.data,
4380                 tdata->validDataLenInBits.len,
4381                 "SNOW 3G Ciphertext data not as expected");
4382
4383         return 0;
4384 }
4385
4386 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4387 static void
4388 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4389 {
4390         uint8_t curr_byte, prev_byte;
4391         uint32_t length_in_bytes = ceil_byte_length(length + offset);
4392         uint8_t lower_byte_mask = (1 << offset) - 1;
4393         unsigned i;
4394
4395         prev_byte = buffer[0];
4396         buffer[0] >>= offset;
4397
4398         for (i = 1; i < length_in_bytes; i++) {
4399                 curr_byte = buffer[i];
4400                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4401                                 (curr_byte >> offset);
4402                 prev_byte = curr_byte;
4403         }
4404 }
4405
4406 static int
4407 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4408 {
4409         struct crypto_testsuite_params *ts_params = &testsuite_params;
4410         struct crypto_unittest_params *ut_params = &unittest_params;
4411         uint8_t *plaintext, *ciphertext;
4412         int retval;
4413         uint32_t plaintext_len;
4414         uint32_t plaintext_pad_len;
4415         uint8_t extra_offset = 4;
4416         uint8_t *expected_ciphertext_shifted;
4417         struct rte_cryptodev_info dev_info;
4418
4419         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4420         uint64_t feat_flags = dev_info.feature_flags;
4421
4422         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4423                         ((tdata->validDataLenInBits.len % 8) != 0)) {
4424                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4425                 return TEST_SKIPPED;
4426         }
4427
4428         /* Verify the capabilities */
4429         struct rte_cryptodev_sym_capability_idx cap_idx;
4430         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4431         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4432         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4433                         &cap_idx) == NULL)
4434                 return TEST_SKIPPED;
4435
4436         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4437                 return TEST_SKIPPED;
4438
4439         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4440                 return TEST_SKIPPED;
4441
4442         /* Create SNOW 3G session */
4443         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4444                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4445                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4446                                         tdata->key.data, tdata->key.len,
4447                                         tdata->cipher_iv.len);
4448         if (retval < 0)
4449                 return retval;
4450
4451         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4452         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4453
4454         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4455                         "Failed to allocate input buffer in mempool");
4456         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4457                         "Failed to allocate output buffer in mempool");
4458
4459         /* Clear mbuf payload */
4460         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4461                rte_pktmbuf_tailroom(ut_params->ibuf));
4462
4463         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4464         /*
4465          * Append data which is padded to a
4466          * multiple of the algorithms block size
4467          */
4468         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4469
4470         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4471                                                 plaintext_pad_len);
4472
4473         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4474
4475         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4476         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4477
4478 #ifdef RTE_APP_TEST_DEBUG
4479         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4480 #endif
4481         /* Create SNOW 3G operation */
4482         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4483                                         tdata->cipher_iv.len,
4484                                         tdata->validCipherLenInBits.len,
4485                                         extra_offset);
4486         if (retval < 0)
4487                 return retval;
4488
4489         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4490                                                 ut_params->op);
4491         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4492
4493         ut_params->obuf = ut_params->op->sym->m_dst;
4494         if (ut_params->obuf)
4495                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4496         else
4497                 ciphertext = plaintext;
4498
4499 #ifdef RTE_APP_TEST_DEBUG
4500         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4501 #endif
4502
4503         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4504
4505         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4506                         "failed to reserve memory for ciphertext shifted\n");
4507
4508         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4509                         ceil_byte_length(tdata->ciphertext.len));
4510         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4511                         extra_offset);
4512         /* Validate obuf */
4513         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4514                 ciphertext,
4515                 expected_ciphertext_shifted,
4516                 tdata->validDataLenInBits.len,
4517                 extra_offset,
4518                 "SNOW 3G Ciphertext data not as expected");
4519         return 0;
4520 }
4521
4522 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4523 {
4524         struct crypto_testsuite_params *ts_params = &testsuite_params;
4525         struct crypto_unittest_params *ut_params = &unittest_params;
4526
4527         int retval;
4528
4529         uint8_t *plaintext, *ciphertext;
4530         unsigned ciphertext_pad_len;
4531         unsigned ciphertext_len;
4532         struct rte_cryptodev_info dev_info;
4533
4534         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4535         uint64_t feat_flags = dev_info.feature_flags;
4536
4537         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4538                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4539                 printf("Device doesn't support RAW data-path APIs.\n");
4540                 return TEST_SKIPPED;
4541         }
4542
4543         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4544                 return TEST_SKIPPED;
4545
4546         /* Verify the capabilities */
4547         struct rte_cryptodev_sym_capability_idx cap_idx;
4548         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4549         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4550         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4551                         &cap_idx) == NULL)
4552                 return TEST_SKIPPED;
4553
4554         /* Create SNOW 3G session */
4555         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4556                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4557                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4558                                         tdata->key.data, tdata->key.len,
4559                                         tdata->cipher_iv.len);
4560         if (retval < 0)
4561                 return retval;
4562
4563         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4564
4565         /* Clear mbuf payload */
4566         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4567                rte_pktmbuf_tailroom(ut_params->ibuf));
4568
4569         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4570         /* Append data which is padded to a multiple of */
4571         /* the algorithms block size */
4572         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4573         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4574                                 ciphertext_pad_len);
4575         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4576
4577         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4578
4579         /* Create SNOW 3G operation */
4580         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4581                                         tdata->cipher_iv.len,
4582                                         tdata->validCipherLenInBits.len,
4583                                         tdata->cipher.offset_bits);
4584         if (retval < 0)
4585                 return retval;
4586
4587         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4588                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4589                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4590         else
4591                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4592                                                 ut_params->op);
4593         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4594         ut_params->obuf = ut_params->op->sym->m_dst;
4595         if (ut_params->obuf)
4596                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4597         else
4598                 plaintext = ciphertext;
4599
4600         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4601
4602         /* Validate obuf */
4603         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4604                                 tdata->plaintext.data,
4605                                 tdata->validDataLenInBits.len,
4606                                 "SNOW 3G Plaintext data not as expected");
4607         return 0;
4608 }
4609
4610 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4611 {
4612         struct crypto_testsuite_params *ts_params = &testsuite_params;
4613         struct crypto_unittest_params *ut_params = &unittest_params;
4614
4615         int retval;
4616
4617         uint8_t *plaintext, *ciphertext;
4618         unsigned ciphertext_pad_len;
4619         unsigned ciphertext_len;
4620
4621         /* Verify the capabilities */
4622         struct rte_cryptodev_sym_capability_idx cap_idx;
4623         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4624         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4625         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4626                         &cap_idx) == NULL)
4627                 return TEST_SKIPPED;
4628
4629         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4630                 return TEST_SKIPPED;
4631
4632         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4633                 return TEST_SKIPPED;
4634
4635         /* Create SNOW 3G session */
4636         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4637                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4638                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4639                                         tdata->key.data, tdata->key.len,
4640                                         tdata->cipher_iv.len);
4641         if (retval < 0)
4642                 return retval;
4643
4644         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4645         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4646
4647         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4648                         "Failed to allocate input buffer");
4649         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4650                         "Failed to allocate output buffer");
4651
4652         /* Clear mbuf payload */
4653         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4654                rte_pktmbuf_tailroom(ut_params->ibuf));
4655
4656         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4657                        rte_pktmbuf_tailroom(ut_params->obuf));
4658
4659         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4660         /* Append data which is padded to a multiple of */
4661         /* the algorithms block size */
4662         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4663         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4664                                 ciphertext_pad_len);
4665         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4666         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4667
4668         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4669
4670         /* Create SNOW 3G operation */
4671         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4672                                         tdata->cipher_iv.len,
4673                                         tdata->validCipherLenInBits.len,
4674                                         0);
4675         if (retval < 0)
4676                 return retval;
4677
4678         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4679                                                 ut_params->op);
4680         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4681         ut_params->obuf = ut_params->op->sym->m_dst;
4682         if (ut_params->obuf)
4683                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4684         else
4685                 plaintext = ciphertext;
4686
4687         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4688
4689         /* Validate obuf */
4690         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4691                                 tdata->plaintext.data,
4692                                 tdata->validDataLenInBits.len,
4693                                 "SNOW 3G Plaintext data not as expected");
4694         return 0;
4695 }
4696
4697 static int
4698 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4699 {
4700         struct crypto_testsuite_params *ts_params = &testsuite_params;
4701         struct crypto_unittest_params *ut_params = &unittest_params;
4702
4703         int retval;
4704
4705         uint8_t *plaintext, *ciphertext;
4706         unsigned int plaintext_pad_len;
4707         unsigned int plaintext_len;
4708
4709         struct rte_cryptodev_info dev_info;
4710         struct rte_cryptodev_sym_capability_idx cap_idx;
4711
4712         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4713         uint64_t feat_flags = dev_info.feature_flags;
4714
4715         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4716                         ((tdata->validAuthLenInBits.len % 8 != 0) ||
4717                         (tdata->validDataLenInBits.len % 8 != 0))) {
4718                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4719                 return TEST_SKIPPED;
4720         }
4721
4722         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4723                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4724                 printf("Device doesn't support RAW data-path APIs.\n");
4725                 return TEST_SKIPPED;
4726         }
4727
4728         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4729                 return TEST_SKIPPED;
4730
4731         /* Check if device supports ZUC EEA3 */
4732         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4733         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4734
4735         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4736                         &cap_idx) == NULL)
4737                 return TEST_SKIPPED;
4738
4739         /* Check if device supports ZUC EIA3 */
4740         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4741         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4742
4743         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4744                         &cap_idx) == NULL)
4745                 return TEST_SKIPPED;
4746
4747         /* Create ZUC session */
4748         retval = create_zuc_cipher_auth_encrypt_generate_session(
4749                         ts_params->valid_devs[0],
4750                         tdata);
4751         if (retval != 0)
4752                 return retval;
4753         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4754
4755         /* clear mbuf payload */
4756         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4757                         rte_pktmbuf_tailroom(ut_params->ibuf));
4758
4759         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4760         /* Append data which is padded to a multiple of */
4761         /* the algorithms block size */
4762         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4763         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4764                                 plaintext_pad_len);
4765         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4766
4767         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4768
4769         /* Create ZUC operation */
4770         retval = create_zuc_cipher_hash_generate_operation(tdata);
4771         if (retval < 0)
4772                 return retval;
4773
4774         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4775                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4776                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4777         else
4778                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4779                         ut_params->op);
4780         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4781         ut_params->obuf = ut_params->op->sym->m_src;
4782         if (ut_params->obuf)
4783                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4784         else
4785                 ciphertext = plaintext;
4786
4787         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4788         /* Validate obuf */
4789         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4790                         ciphertext,
4791                         tdata->ciphertext.data,
4792                         tdata->validDataLenInBits.len,
4793                         "ZUC Ciphertext data not as expected");
4794
4795         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4796             + plaintext_pad_len;
4797
4798         /* Validate obuf */
4799         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4800                         ut_params->digest,
4801                         tdata->digest.data,
4802                         4,
4803                         "ZUC Generated auth tag not as expected");
4804         return 0;
4805 }
4806
4807 static int
4808 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4809 {
4810         struct crypto_testsuite_params *ts_params = &testsuite_params;
4811         struct crypto_unittest_params *ut_params = &unittest_params;
4812
4813         int retval;
4814
4815         uint8_t *plaintext, *ciphertext;
4816         unsigned plaintext_pad_len;
4817         unsigned plaintext_len;
4818         struct rte_cryptodev_info dev_info;
4819
4820         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4821         uint64_t feat_flags = dev_info.feature_flags;
4822
4823         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4824                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4825                 printf("Device doesn't support RAW data-path APIs.\n");
4826                 return TEST_SKIPPED;
4827         }
4828
4829         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4830                 return TEST_SKIPPED;
4831
4832         /* Verify the capabilities */
4833         struct rte_cryptodev_sym_capability_idx cap_idx;
4834         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4835         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4836         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4837                         &cap_idx) == NULL)
4838                 return TEST_SKIPPED;
4839         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4840         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4841         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4842                         &cap_idx) == NULL)
4843                 return TEST_SKIPPED;
4844
4845         /* Create SNOW 3G session */
4846         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4847                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4848                         RTE_CRYPTO_AUTH_OP_GENERATE,
4849                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4850                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4851                         tdata->key.data, tdata->key.len,
4852                         tdata->auth_iv.len, tdata->digest.len,
4853                         tdata->cipher_iv.len);
4854         if (retval != 0)
4855                 return retval;
4856         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4857
4858         /* clear mbuf payload */
4859         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4860                         rte_pktmbuf_tailroom(ut_params->ibuf));
4861
4862         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4863         /* Append data which is padded to a multiple of */
4864         /* the algorithms block size */
4865         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4866         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4867                                 plaintext_pad_len);
4868         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4869
4870         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4871
4872         /* Create SNOW 3G operation */
4873         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4874                         tdata->digest.len, tdata->auth_iv.data,
4875                         tdata->auth_iv.len,
4876                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4877                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4878                         tdata->validCipherLenInBits.len,
4879                         0,
4880                         tdata->validAuthLenInBits.len,
4881                         0
4882                         );
4883         if (retval < 0)
4884                 return retval;
4885
4886         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4887                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4888                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4889         else
4890                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4891                         ut_params->op);
4892         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4893         ut_params->obuf = ut_params->op->sym->m_src;
4894         if (ut_params->obuf)
4895                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4896         else
4897                 ciphertext = plaintext;
4898
4899         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4900         /* Validate obuf */
4901         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4902                         ciphertext,
4903                         tdata->ciphertext.data,
4904                         tdata->validDataLenInBits.len,
4905                         "SNOW 3G Ciphertext data not as expected");
4906
4907         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4908             + plaintext_pad_len;
4909
4910         /* Validate obuf */
4911         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4912                         ut_params->digest,
4913                         tdata->digest.data,
4914                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4915                         "SNOW 3G Generated auth tag not as expected");
4916         return 0;
4917 }
4918
4919 static int
4920 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4921         uint8_t op_mode, uint8_t verify)
4922 {
4923         struct crypto_testsuite_params *ts_params = &testsuite_params;
4924         struct crypto_unittest_params *ut_params = &unittest_params;
4925
4926         int retval;
4927
4928         uint8_t *plaintext = NULL, *ciphertext = NULL;
4929         unsigned int plaintext_pad_len;
4930         unsigned int plaintext_len;
4931         unsigned int ciphertext_pad_len;
4932         unsigned int ciphertext_len;
4933
4934         struct rte_cryptodev_info dev_info;
4935
4936         /* Verify the capabilities */
4937         struct rte_cryptodev_sym_capability_idx cap_idx;
4938         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4939         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4940         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4941                         &cap_idx) == NULL)
4942                 return TEST_SKIPPED;
4943         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4944         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4945         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4946                         &cap_idx) == NULL)
4947                 return TEST_SKIPPED;
4948
4949         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4950                 return TEST_SKIPPED;
4951
4952         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4953
4954         uint64_t feat_flags = dev_info.feature_flags;
4955
4956         if (op_mode == OUT_OF_PLACE) {
4957                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4958                         printf("Device doesn't support digest encrypted.\n");
4959                         return TEST_SKIPPED;
4960                 }
4961                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4962                         return TEST_SKIPPED;
4963         }
4964
4965         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4966                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4967                 printf("Device doesn't support RAW data-path APIs.\n");
4968                 return TEST_SKIPPED;
4969         }
4970
4971         /* Create SNOW 3G session */
4972         retval = create_wireless_algo_auth_cipher_session(
4973                         ts_params->valid_devs[0],
4974                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4975                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4976                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4977                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4978                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4979                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4980                         tdata->key.data, tdata->key.len,
4981                         tdata->auth_iv.len, tdata->digest.len,
4982                         tdata->cipher_iv.len);
4983         if (retval != 0)
4984                 return retval;
4985
4986         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4987         if (op_mode == OUT_OF_PLACE)
4988                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4989
4990         /* clear mbuf payload */
4991         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4992                 rte_pktmbuf_tailroom(ut_params->ibuf));
4993         if (op_mode == OUT_OF_PLACE)
4994                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4995                         rte_pktmbuf_tailroom(ut_params->obuf));
4996
4997         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4998         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4999         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5000         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5001
5002         if (verify) {
5003                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5004                                         ciphertext_pad_len);
5005                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5006                 if (op_mode == OUT_OF_PLACE)
5007                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5008                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5009                         ciphertext_len);
5010         } else {
5011                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5012                                         plaintext_pad_len);
5013                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5014                 if (op_mode == OUT_OF_PLACE)
5015                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5016                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5017         }
5018
5019         /* Create SNOW 3G operation */
5020         retval = create_wireless_algo_auth_cipher_operation(
5021                 tdata->digest.data, tdata->digest.len,
5022                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5023                 tdata->auth_iv.data, tdata->auth_iv.len,
5024                 (tdata->digest.offset_bytes == 0 ?
5025                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5026                         : tdata->digest.offset_bytes),
5027                 tdata->validCipherLenInBits.len,
5028                 tdata->cipher.offset_bits,
5029                 tdata->validAuthLenInBits.len,
5030                 tdata->auth.offset_bits,
5031                 op_mode, 0, verify);
5032
5033         if (retval < 0)
5034                 return retval;
5035
5036         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5037                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5038                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5039         else
5040                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5041                         ut_params->op);
5042
5043         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5044
5045         ut_params->obuf = (op_mode == IN_PLACE ?
5046                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5047
5048         if (verify) {
5049                 if (ut_params->obuf)
5050                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5051                                                         uint8_t *);
5052                 else
5053                         plaintext = ciphertext +
5054                                 (tdata->cipher.offset_bits >> 3);
5055
5056                 debug_hexdump(stdout, "plaintext:", plaintext,
5057                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5058                 debug_hexdump(stdout, "plaintext expected:",
5059                         tdata->plaintext.data,
5060                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5061         } else {
5062                 if (ut_params->obuf)
5063                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5064                                                         uint8_t *);
5065                 else
5066                         ciphertext = plaintext;
5067
5068                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5069                         ciphertext_len);
5070                 debug_hexdump(stdout, "ciphertext expected:",
5071                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5072
5073                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5074                         + (tdata->digest.offset_bytes == 0 ?
5075                 plaintext_pad_len : tdata->digest.offset_bytes);
5076
5077                 debug_hexdump(stdout, "digest:", ut_params->digest,
5078                         tdata->digest.len);
5079                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5080                                 tdata->digest.len);
5081         }
5082
5083         /* Validate obuf */
5084         if (verify) {
5085                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5086                         plaintext,
5087                         tdata->plaintext.data,
5088                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5089                          (tdata->digest.len << 3)),
5090                         tdata->cipher.offset_bits,
5091                         "SNOW 3G Plaintext data not as expected");
5092         } else {
5093                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5094                         ciphertext,
5095                         tdata->ciphertext.data,
5096                         (tdata->validDataLenInBits.len -
5097                          tdata->cipher.offset_bits),
5098                         tdata->cipher.offset_bits,
5099                         "SNOW 3G Ciphertext data not as expected");
5100
5101                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5102                         ut_params->digest,
5103                         tdata->digest.data,
5104                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5105                         "SNOW 3G Generated auth tag not as expected");
5106         }
5107         return 0;
5108 }
5109
5110 static int
5111 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5112         uint8_t op_mode, uint8_t verify)
5113 {
5114         struct crypto_testsuite_params *ts_params = &testsuite_params;
5115         struct crypto_unittest_params *ut_params = &unittest_params;
5116
5117         int retval;
5118
5119         const uint8_t *plaintext = NULL;
5120         const uint8_t *ciphertext = NULL;
5121         const uint8_t *digest = NULL;
5122         unsigned int plaintext_pad_len;
5123         unsigned int plaintext_len;
5124         unsigned int ciphertext_pad_len;
5125         unsigned int ciphertext_len;
5126         uint8_t buffer[10000];
5127         uint8_t digest_buffer[10000];
5128
5129         struct rte_cryptodev_info dev_info;
5130
5131         /* Verify the capabilities */
5132         struct rte_cryptodev_sym_capability_idx cap_idx;
5133         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5134         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5135         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5136                         &cap_idx) == NULL)
5137                 return TEST_SKIPPED;
5138         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5139         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5140         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5141                         &cap_idx) == NULL)
5142                 return TEST_SKIPPED;
5143
5144         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5145                 return TEST_SKIPPED;
5146
5147         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5148
5149         uint64_t feat_flags = dev_info.feature_flags;
5150
5151         if (op_mode == IN_PLACE) {
5152                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5153                         printf("Device doesn't support in-place scatter-gather "
5154                                         "in both input and output mbufs.\n");
5155                         return TEST_SKIPPED;
5156                 }
5157                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5158                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5159                         printf("Device doesn't support RAW data-path APIs.\n");
5160                         return TEST_SKIPPED;
5161                 }
5162         } else {
5163                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5164                         return TEST_SKIPPED;
5165                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5166                         printf("Device doesn't support out-of-place scatter-gather "
5167                                         "in both input and output mbufs.\n");
5168                         return TEST_SKIPPED;
5169                 }
5170                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5171                         printf("Device doesn't support digest encrypted.\n");
5172                         return TEST_SKIPPED;
5173                 }
5174         }
5175
5176         /* Create SNOW 3G session */
5177         retval = create_wireless_algo_auth_cipher_session(
5178                         ts_params->valid_devs[0],
5179                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5180                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5181                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5182                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5183                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5184                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5185                         tdata->key.data, tdata->key.len,
5186                         tdata->auth_iv.len, tdata->digest.len,
5187                         tdata->cipher_iv.len);
5188
5189         if (retval != 0)
5190                 return retval;
5191
5192         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5193         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5194         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5195         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5196
5197         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5198                         plaintext_pad_len, 15, 0);
5199         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5200                         "Failed to allocate input buffer in mempool");
5201
5202         if (op_mode == OUT_OF_PLACE) {
5203                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5204                                 plaintext_pad_len, 15, 0);
5205                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5206                                 "Failed to allocate output buffer in mempool");
5207         }
5208
5209         if (verify) {
5210                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5211                         tdata->ciphertext.data);
5212                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5213                                         ciphertext_len, buffer);
5214                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5215                         ciphertext_len);
5216         } else {
5217                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5218                         tdata->plaintext.data);
5219                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5220                                         plaintext_len, buffer);
5221                 debug_hexdump(stdout, "plaintext:", plaintext,
5222                         plaintext_len);
5223         }
5224         memset(buffer, 0, sizeof(buffer));
5225
5226         /* Create SNOW 3G operation */
5227         retval = create_wireless_algo_auth_cipher_operation(
5228                 tdata->digest.data, tdata->digest.len,
5229                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5230                 tdata->auth_iv.data, tdata->auth_iv.len,
5231                 (tdata->digest.offset_bytes == 0 ?
5232                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5233                         : tdata->digest.offset_bytes),
5234                 tdata->validCipherLenInBits.len,
5235                 tdata->cipher.offset_bits,
5236                 tdata->validAuthLenInBits.len,
5237                 tdata->auth.offset_bits,
5238                 op_mode, 1, verify);
5239
5240         if (retval < 0)
5241                 return retval;
5242
5243         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5244                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5245                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5246         else
5247                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5248                         ut_params->op);
5249
5250         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5251
5252         ut_params->obuf = (op_mode == IN_PLACE ?
5253                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5254
5255         if (verify) {
5256                 if (ut_params->obuf)
5257                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5258                                         plaintext_len, buffer);
5259                 else
5260                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5261                                         plaintext_len, buffer);
5262
5263                 debug_hexdump(stdout, "plaintext:", plaintext,
5264                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5265                 debug_hexdump(stdout, "plaintext expected:",
5266                         tdata->plaintext.data,
5267                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5268         } else {
5269                 if (ut_params->obuf)
5270                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5271                                         ciphertext_len, buffer);
5272                 else
5273                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5274                                         ciphertext_len, buffer);
5275
5276                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5277                         ciphertext_len);
5278                 debug_hexdump(stdout, "ciphertext expected:",
5279                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5280
5281                 if (ut_params->obuf)
5282                         digest = rte_pktmbuf_read(ut_params->obuf,
5283                                 (tdata->digest.offset_bytes == 0 ?
5284                                 plaintext_pad_len : tdata->digest.offset_bytes),
5285                                 tdata->digest.len, digest_buffer);
5286                 else
5287                         digest = rte_pktmbuf_read(ut_params->ibuf,
5288                                 (tdata->digest.offset_bytes == 0 ?
5289                                 plaintext_pad_len : tdata->digest.offset_bytes),
5290                                 tdata->digest.len, digest_buffer);
5291
5292                 debug_hexdump(stdout, "digest:", digest,
5293                         tdata->digest.len);
5294                 debug_hexdump(stdout, "digest expected:",
5295                         tdata->digest.data, tdata->digest.len);
5296         }
5297
5298         /* Validate obuf */
5299         if (verify) {
5300                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5301                         plaintext,
5302                         tdata->plaintext.data,
5303                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5304                          (tdata->digest.len << 3)),
5305                         tdata->cipher.offset_bits,
5306                         "SNOW 3G Plaintext data not as expected");
5307         } else {
5308                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5309                         ciphertext,
5310                         tdata->ciphertext.data,
5311                         (tdata->validDataLenInBits.len -
5312                          tdata->cipher.offset_bits),
5313                         tdata->cipher.offset_bits,
5314                         "SNOW 3G Ciphertext data not as expected");
5315
5316                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5317                         digest,
5318                         tdata->digest.data,
5319                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5320                         "SNOW 3G Generated auth tag not as expected");
5321         }
5322         return 0;
5323 }
5324
5325 static int
5326 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5327         uint8_t op_mode, uint8_t verify)
5328 {
5329         struct crypto_testsuite_params *ts_params = &testsuite_params;
5330         struct crypto_unittest_params *ut_params = &unittest_params;
5331
5332         int retval;
5333
5334         uint8_t *plaintext = NULL, *ciphertext = NULL;
5335         unsigned int plaintext_pad_len;
5336         unsigned int plaintext_len;
5337         unsigned int ciphertext_pad_len;
5338         unsigned int ciphertext_len;
5339
5340         struct rte_cryptodev_info dev_info;
5341
5342         /* Verify the capabilities */
5343         struct rte_cryptodev_sym_capability_idx cap_idx;
5344         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5345         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5346         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5347                         &cap_idx) == NULL)
5348                 return TEST_SKIPPED;
5349         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5350         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5351         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5352                         &cap_idx) == NULL)
5353                 return TEST_SKIPPED;
5354
5355         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5356
5357         uint64_t feat_flags = dev_info.feature_flags;
5358
5359         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5360                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5361                 printf("Device doesn't support RAW data-path APIs.\n");
5362                 return TEST_SKIPPED;
5363         }
5364
5365         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5366                 return TEST_SKIPPED;
5367
5368         if (op_mode == OUT_OF_PLACE) {
5369                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5370                         return TEST_SKIPPED;
5371                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5372                         printf("Device doesn't support digest encrypted.\n");
5373                         return TEST_SKIPPED;
5374                 }
5375         }
5376
5377         /* Create KASUMI session */
5378         retval = create_wireless_algo_auth_cipher_session(
5379                         ts_params->valid_devs[0],
5380                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5381                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5382                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5383                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5384                         RTE_CRYPTO_AUTH_KASUMI_F9,
5385                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5386                         tdata->key.data, tdata->key.len,
5387                         0, tdata->digest.len,
5388                         tdata->cipher_iv.len);
5389
5390         if (retval != 0)
5391                 return retval;
5392
5393         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5394         if (op_mode == OUT_OF_PLACE)
5395                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5396
5397         /* clear mbuf payload */
5398         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5399                 rte_pktmbuf_tailroom(ut_params->ibuf));
5400         if (op_mode == OUT_OF_PLACE)
5401                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5402                         rte_pktmbuf_tailroom(ut_params->obuf));
5403
5404         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5405         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5406         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5407         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5408
5409         if (verify) {
5410                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5411                                         ciphertext_pad_len);
5412                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5413                 if (op_mode == OUT_OF_PLACE)
5414                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5415                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5416                         ciphertext_len);
5417         } else {
5418                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5419                                         plaintext_pad_len);
5420                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5421                 if (op_mode == OUT_OF_PLACE)
5422                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5423                 debug_hexdump(stdout, "plaintext:", plaintext,
5424                         plaintext_len);
5425         }
5426
5427         /* Create KASUMI operation */
5428         retval = create_wireless_algo_auth_cipher_operation(
5429                 tdata->digest.data, tdata->digest.len,
5430                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5431                 NULL, 0,
5432                 (tdata->digest.offset_bytes == 0 ?
5433                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5434                         : tdata->digest.offset_bytes),
5435                 tdata->validCipherLenInBits.len,
5436                 tdata->validCipherOffsetInBits.len,
5437                 tdata->validAuthLenInBits.len,
5438                 0,
5439                 op_mode, 0, verify);
5440
5441         if (retval < 0)
5442                 return retval;
5443
5444         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5445                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5446                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5447         else
5448                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5449                         ut_params->op);
5450
5451         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5452
5453         ut_params->obuf = (op_mode == IN_PLACE ?
5454                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5455
5456
5457         if (verify) {
5458                 if (ut_params->obuf)
5459                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5460                                                         uint8_t *);
5461                 else
5462                         plaintext = ciphertext;
5463
5464                 debug_hexdump(stdout, "plaintext:", plaintext,
5465                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5466                 debug_hexdump(stdout, "plaintext expected:",
5467                         tdata->plaintext.data,
5468                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5469         } else {
5470                 if (ut_params->obuf)
5471                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5472                                                         uint8_t *);
5473                 else
5474                         ciphertext = plaintext;
5475
5476                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5477                         ciphertext_len);
5478                 debug_hexdump(stdout, "ciphertext expected:",
5479                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5480
5481                 ut_params->digest = rte_pktmbuf_mtod(
5482                         ut_params->obuf, uint8_t *) +
5483                         (tdata->digest.offset_bytes == 0 ?
5484                         plaintext_pad_len : tdata->digest.offset_bytes);
5485
5486                 debug_hexdump(stdout, "digest:", ut_params->digest,
5487                         tdata->digest.len);
5488                 debug_hexdump(stdout, "digest expected:",
5489                         tdata->digest.data, tdata->digest.len);
5490         }
5491
5492         /* Validate obuf */
5493         if (verify) {
5494                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5495                         plaintext,
5496                         tdata->plaintext.data,
5497                         tdata->plaintext.len >> 3,
5498                         "KASUMI Plaintext data not as expected");
5499         } else {
5500                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5501                         ciphertext,
5502                         tdata->ciphertext.data,
5503                         tdata->ciphertext.len >> 3,
5504                         "KASUMI Ciphertext data not as expected");
5505
5506                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5507                         ut_params->digest,
5508                         tdata->digest.data,
5509                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5510                         "KASUMI Generated auth tag not as expected");
5511         }
5512         return 0;
5513 }
5514
5515 static int
5516 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5517         uint8_t op_mode, uint8_t verify)
5518 {
5519         struct crypto_testsuite_params *ts_params = &testsuite_params;
5520         struct crypto_unittest_params *ut_params = &unittest_params;
5521
5522         int retval;
5523
5524         const uint8_t *plaintext = NULL;
5525         const uint8_t *ciphertext = NULL;
5526         const uint8_t *digest = NULL;
5527         unsigned int plaintext_pad_len;
5528         unsigned int plaintext_len;
5529         unsigned int ciphertext_pad_len;
5530         unsigned int ciphertext_len;
5531         uint8_t buffer[10000];
5532         uint8_t digest_buffer[10000];
5533
5534         struct rte_cryptodev_info dev_info;
5535
5536         /* Verify the capabilities */
5537         struct rte_cryptodev_sym_capability_idx cap_idx;
5538         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5539         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5540         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5541                         &cap_idx) == NULL)
5542                 return TEST_SKIPPED;
5543         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5544         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5545         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5546                         &cap_idx) == NULL)
5547                 return TEST_SKIPPED;
5548
5549         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5550                 return TEST_SKIPPED;
5551
5552         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5553
5554         uint64_t feat_flags = dev_info.feature_flags;
5555
5556         if (op_mode == IN_PLACE) {
5557                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5558                         printf("Device doesn't support in-place scatter-gather "
5559                                         "in both input and output mbufs.\n");
5560                         return TEST_SKIPPED;
5561                 }
5562                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5563                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5564                         printf("Device doesn't support RAW data-path APIs.\n");
5565                         return TEST_SKIPPED;
5566                 }
5567         } else {
5568                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5569                         return TEST_SKIPPED;
5570                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5571                         printf("Device doesn't support out-of-place scatter-gather "
5572                                         "in both input and output mbufs.\n");
5573                         return TEST_SKIPPED;
5574                 }
5575                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5576                         printf("Device doesn't support digest encrypted.\n");
5577                         return TEST_SKIPPED;
5578                 }
5579         }
5580
5581         /* Create KASUMI session */
5582         retval = create_wireless_algo_auth_cipher_session(
5583                         ts_params->valid_devs[0],
5584                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5585                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5586                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5587                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5588                         RTE_CRYPTO_AUTH_KASUMI_F9,
5589                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5590                         tdata->key.data, tdata->key.len,
5591                         0, tdata->digest.len,
5592                         tdata->cipher_iv.len);
5593
5594         if (retval != 0)
5595                 return retval;
5596
5597         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5598         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5599         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5600         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5601
5602         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5603                         plaintext_pad_len, 15, 0);
5604         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5605                         "Failed to allocate input buffer in mempool");
5606
5607         if (op_mode == OUT_OF_PLACE) {
5608                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5609                                 plaintext_pad_len, 15, 0);
5610                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5611                                 "Failed to allocate output buffer in mempool");
5612         }
5613
5614         if (verify) {
5615                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5616                         tdata->ciphertext.data);
5617                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5618                                         ciphertext_len, buffer);
5619                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5620                         ciphertext_len);
5621         } else {
5622                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5623                         tdata->plaintext.data);
5624                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5625                                         plaintext_len, buffer);
5626                 debug_hexdump(stdout, "plaintext:", plaintext,
5627                         plaintext_len);
5628         }
5629         memset(buffer, 0, sizeof(buffer));
5630
5631         /* Create KASUMI operation */
5632         retval = create_wireless_algo_auth_cipher_operation(
5633                 tdata->digest.data, tdata->digest.len,
5634                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5635                 NULL, 0,
5636                 (tdata->digest.offset_bytes == 0 ?
5637                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5638                         : tdata->digest.offset_bytes),
5639                 tdata->validCipherLenInBits.len,
5640                 tdata->validCipherOffsetInBits.len,
5641                 tdata->validAuthLenInBits.len,
5642                 0,
5643                 op_mode, 1, verify);
5644
5645         if (retval < 0)
5646                 return retval;
5647
5648         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5649                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5650                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5651         else
5652                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5653                         ut_params->op);
5654
5655         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5656
5657         ut_params->obuf = (op_mode == IN_PLACE ?
5658                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5659
5660         if (verify) {
5661                 if (ut_params->obuf)
5662                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5663                                         plaintext_len, buffer);
5664                 else
5665                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5666                                         plaintext_len, buffer);
5667
5668                 debug_hexdump(stdout, "plaintext:", plaintext,
5669                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5670                 debug_hexdump(stdout, "plaintext expected:",
5671                         tdata->plaintext.data,
5672                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5673         } else {
5674                 if (ut_params->obuf)
5675                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5676                                         ciphertext_len, buffer);
5677                 else
5678                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5679                                         ciphertext_len, buffer);
5680
5681                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5682                         ciphertext_len);
5683                 debug_hexdump(stdout, "ciphertext expected:",
5684                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5685
5686                 if (ut_params->obuf)
5687                         digest = rte_pktmbuf_read(ut_params->obuf,
5688                                 (tdata->digest.offset_bytes == 0 ?
5689                                 plaintext_pad_len : tdata->digest.offset_bytes),
5690                                 tdata->digest.len, digest_buffer);
5691                 else
5692                         digest = rte_pktmbuf_read(ut_params->ibuf,
5693                                 (tdata->digest.offset_bytes == 0 ?
5694                                 plaintext_pad_len : tdata->digest.offset_bytes),
5695                                 tdata->digest.len, digest_buffer);
5696
5697                 debug_hexdump(stdout, "digest:", digest,
5698                         tdata->digest.len);
5699                 debug_hexdump(stdout, "digest expected:",
5700                         tdata->digest.data, tdata->digest.len);
5701         }
5702
5703         /* Validate obuf */
5704         if (verify) {
5705                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5706                         plaintext,
5707                         tdata->plaintext.data,
5708                         tdata->plaintext.len >> 3,
5709                         "KASUMI Plaintext data not as expected");
5710         } else {
5711                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5712                         ciphertext,
5713                         tdata->ciphertext.data,
5714                         tdata->validDataLenInBits.len,
5715                         "KASUMI Ciphertext data not as expected");
5716
5717                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5718                         digest,
5719                         tdata->digest.data,
5720                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5721                         "KASUMI Generated auth tag not as expected");
5722         }
5723         return 0;
5724 }
5725
5726 static int
5727 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5728 {
5729         struct crypto_testsuite_params *ts_params = &testsuite_params;
5730         struct crypto_unittest_params *ut_params = &unittest_params;
5731
5732         int retval;
5733
5734         uint8_t *plaintext, *ciphertext;
5735         unsigned plaintext_pad_len;
5736         unsigned plaintext_len;
5737         struct rte_cryptodev_info dev_info;
5738
5739         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5740         uint64_t feat_flags = dev_info.feature_flags;
5741
5742         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5743                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5744                 printf("Device doesn't support RAW data-path APIs.\n");
5745                 return TEST_SKIPPED;
5746         }
5747
5748         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5749                 return TEST_SKIPPED;
5750
5751         /* Verify the capabilities */
5752         struct rte_cryptodev_sym_capability_idx cap_idx;
5753         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5754         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5755         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5756                         &cap_idx) == NULL)
5757                 return TEST_SKIPPED;
5758         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5759         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5760         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5761                         &cap_idx) == NULL)
5762                 return TEST_SKIPPED;
5763
5764         /* Create KASUMI session */
5765         retval = create_wireless_algo_cipher_auth_session(
5766                         ts_params->valid_devs[0],
5767                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5768                         RTE_CRYPTO_AUTH_OP_GENERATE,
5769                         RTE_CRYPTO_AUTH_KASUMI_F9,
5770                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5771                         tdata->key.data, tdata->key.len,
5772                         0, tdata->digest.len,
5773                         tdata->cipher_iv.len);
5774         if (retval != 0)
5775                 return retval;
5776
5777         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5778
5779         /* clear mbuf payload */
5780         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5781                         rte_pktmbuf_tailroom(ut_params->ibuf));
5782
5783         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5784         /* Append data which is padded to a multiple of */
5785         /* the algorithms block size */
5786         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5787         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5788                                 plaintext_pad_len);
5789         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5790
5791         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5792
5793         /* Create KASUMI operation */
5794         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5795                                 tdata->digest.len, NULL, 0,
5796                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5797                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5798                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5799                                 tdata->validCipherOffsetInBits.len,
5800                                 tdata->validAuthLenInBits.len,
5801                                 0
5802                                 );
5803         if (retval < 0)
5804                 return retval;
5805
5806         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5807                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5808                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5809         else
5810                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5811                         ut_params->op);
5812         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5813
5814         if (ut_params->op->sym->m_dst)
5815                 ut_params->obuf = ut_params->op->sym->m_dst;
5816         else
5817                 ut_params->obuf = ut_params->op->sym->m_src;
5818
5819         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5820                                 tdata->validCipherOffsetInBits.len >> 3);
5821
5822         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5823                         + plaintext_pad_len;
5824
5825         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5826                                 (tdata->validCipherOffsetInBits.len >> 3);
5827         /* Validate obuf */
5828         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5829                 ciphertext,
5830                 reference_ciphertext,
5831                 tdata->validCipherLenInBits.len,
5832                 "KASUMI Ciphertext data not as expected");
5833
5834         /* Validate obuf */
5835         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5836                 ut_params->digest,
5837                 tdata->digest.data,
5838                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5839                 "KASUMI Generated auth tag not as expected");
5840         return 0;
5841 }
5842
5843 static int
5844 test_zuc_encryption(const struct wireless_test_data *tdata)
5845 {
5846         struct crypto_testsuite_params *ts_params = &testsuite_params;
5847         struct crypto_unittest_params *ut_params = &unittest_params;
5848
5849         int retval;
5850         uint8_t *plaintext, *ciphertext;
5851         unsigned plaintext_pad_len;
5852         unsigned plaintext_len;
5853         struct rte_cryptodev_info dev_info;
5854
5855         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5856         uint64_t feat_flags = dev_info.feature_flags;
5857
5858         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5859                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5860                 printf("Device doesn't support RAW data-path APIs.\n");
5861                 return TEST_SKIPPED;
5862         }
5863
5864         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5865                 return TEST_SKIPPED;
5866
5867         struct rte_cryptodev_sym_capability_idx cap_idx;
5868
5869         /* Check if device supports ZUC EEA3 */
5870         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5871         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5872
5873         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5874                         &cap_idx) == NULL)
5875                 return TEST_SKIPPED;
5876
5877         /* Create ZUC session */
5878         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5879                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5880                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5881                                         tdata->key.data, tdata->key.len,
5882                                         tdata->cipher_iv.len);
5883         if (retval != 0)
5884                 return retval;
5885
5886         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5887
5888         /* Clear mbuf payload */
5889         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5890                rte_pktmbuf_tailroom(ut_params->ibuf));
5891
5892         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5893         /* Append data which is padded to a multiple */
5894         /* of the algorithms block size */
5895         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5896         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5897                                 plaintext_pad_len);
5898         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5899
5900         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5901
5902         /* Create ZUC operation */
5903         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5904                                         tdata->cipher_iv.len,
5905                                         tdata->plaintext.len,
5906                                         0);
5907         if (retval < 0)
5908                 return retval;
5909
5910         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5911                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5912                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5913         else
5914                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5915                                                 ut_params->op);
5916         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5917
5918         ut_params->obuf = ut_params->op->sym->m_dst;
5919         if (ut_params->obuf)
5920                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5921         else
5922                 ciphertext = plaintext;
5923
5924         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5925
5926         /* Validate obuf */
5927         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5928                 ciphertext,
5929                 tdata->ciphertext.data,
5930                 tdata->validCipherLenInBits.len,
5931                 "ZUC Ciphertext data not as expected");
5932         return 0;
5933 }
5934
5935 static int
5936 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5937 {
5938         struct crypto_testsuite_params *ts_params = &testsuite_params;
5939         struct crypto_unittest_params *ut_params = &unittest_params;
5940
5941         int retval;
5942
5943         unsigned int plaintext_pad_len;
5944         unsigned int plaintext_len;
5945         const uint8_t *ciphertext;
5946         uint8_t ciphertext_buffer[2048];
5947         struct rte_cryptodev_info dev_info;
5948
5949         struct rte_cryptodev_sym_capability_idx cap_idx;
5950
5951         /* Check if device supports ZUC EEA3 */
5952         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5953         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5954
5955         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5956                         &cap_idx) == NULL)
5957                 return TEST_SKIPPED;
5958
5959         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5960                 return TEST_SKIPPED;
5961
5962         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5963
5964         uint64_t feat_flags = dev_info.feature_flags;
5965
5966         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5967                 printf("Device doesn't support in-place scatter-gather. "
5968                                 "Test Skipped.\n");
5969                 return TEST_SKIPPED;
5970         }
5971
5972         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5973                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5974                 printf("Device doesn't support RAW data-path APIs.\n");
5975                 return TEST_SKIPPED;
5976         }
5977
5978         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5979
5980         /* Append data which is padded to a multiple */
5981         /* of the algorithms block size */
5982         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5983
5984         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5985                         plaintext_pad_len, 10, 0);
5986
5987         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5988                         tdata->plaintext.data);
5989
5990         /* Create ZUC session */
5991         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5992                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5993                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5994                         tdata->key.data, tdata->key.len,
5995                         tdata->cipher_iv.len);
5996         if (retval < 0)
5997                 return retval;
5998
5999         /* Clear mbuf payload */
6000
6001         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
6002
6003         /* Create ZUC operation */
6004         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6005                         tdata->cipher_iv.len, tdata->plaintext.len,
6006                         0);
6007         if (retval < 0)
6008                 return retval;
6009
6010         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6011                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6012                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6013         else
6014                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6015                                                 ut_params->op);
6016         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6017
6018         ut_params->obuf = ut_params->op->sym->m_dst;
6019         if (ut_params->obuf)
6020                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
6021                         0, plaintext_len, ciphertext_buffer);
6022         else
6023                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6024                         0, plaintext_len, ciphertext_buffer);
6025
6026         /* Validate obuf */
6027         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6028
6029         /* Validate obuf */
6030         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6031                 ciphertext,
6032                 tdata->ciphertext.data,
6033                 tdata->validCipherLenInBits.len,
6034                 "ZUC Ciphertext data not as expected");
6035
6036         return 0;
6037 }
6038
6039 static int
6040 test_zuc_authentication(const struct wireless_test_data *tdata)
6041 {
6042         struct crypto_testsuite_params *ts_params = &testsuite_params;
6043         struct crypto_unittest_params *ut_params = &unittest_params;
6044
6045         int retval;
6046         unsigned plaintext_pad_len;
6047         unsigned plaintext_len;
6048         uint8_t *plaintext;
6049
6050         struct rte_cryptodev_sym_capability_idx cap_idx;
6051         struct rte_cryptodev_info dev_info;
6052
6053         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6054         uint64_t feat_flags = dev_info.feature_flags;
6055
6056         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6057                         (tdata->validAuthLenInBits.len % 8 != 0)) {
6058                 printf("Device doesn't support NON-Byte Aligned Data.\n");
6059                 return TEST_SKIPPED;
6060         }
6061
6062         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6063                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6064                 printf("Device doesn't support RAW data-path APIs.\n");
6065                 return TEST_SKIPPED;
6066         }
6067
6068         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6069                 return TEST_SKIPPED;
6070
6071         /* Check if device supports ZUC EIA3 */
6072         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6073         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6074
6075         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6076                         &cap_idx) == NULL)
6077                 return TEST_SKIPPED;
6078
6079         /* Create ZUC session */
6080         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6081                         tdata->key.data, tdata->key.len,
6082                         tdata->auth_iv.len, tdata->digest.len,
6083                         RTE_CRYPTO_AUTH_OP_GENERATE,
6084                         RTE_CRYPTO_AUTH_ZUC_EIA3);
6085         if (retval != 0)
6086                 return retval;
6087
6088         /* alloc mbuf and set payload */
6089         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6090
6091         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6092         rte_pktmbuf_tailroom(ut_params->ibuf));
6093
6094         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6095         /* Append data which is padded to a multiple of */
6096         /* the algorithms block size */
6097         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6098         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6099                                 plaintext_pad_len);
6100         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6101
6102         /* Create ZUC operation */
6103         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6104                         tdata->auth_iv.data, tdata->auth_iv.len,
6105                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6106                         tdata->validAuthLenInBits.len,
6107                         0);
6108         if (retval < 0)
6109                 return retval;
6110
6111         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6112                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6113                                 ut_params->op, 0, 1, 1, 0);
6114         else
6115                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6116                                 ut_params->op);
6117         ut_params->obuf = ut_params->op->sym->m_src;
6118         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6119         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6120                         + plaintext_pad_len;
6121
6122         /* Validate obuf */
6123         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6124         ut_params->digest,
6125         tdata->digest.data,
6126         tdata->digest.len,
6127         "ZUC Generated auth tag not as expected");
6128
6129         return 0;
6130 }
6131
6132 static int
6133 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6134         uint8_t op_mode, uint8_t verify)
6135 {
6136         struct crypto_testsuite_params *ts_params = &testsuite_params;
6137         struct crypto_unittest_params *ut_params = &unittest_params;
6138
6139         int retval;
6140
6141         uint8_t *plaintext = NULL, *ciphertext = NULL;
6142         unsigned int plaintext_pad_len;
6143         unsigned int plaintext_len;
6144         unsigned int ciphertext_pad_len;
6145         unsigned int ciphertext_len;
6146
6147         struct rte_cryptodev_info dev_info;
6148         struct rte_cryptodev_sym_capability_idx cap_idx;
6149
6150         /* Check if device supports ZUC EIA3 */
6151         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6152         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6153
6154         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6155                         &cap_idx) == NULL)
6156                 return TEST_SKIPPED;
6157
6158         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6159
6160         uint64_t feat_flags = dev_info.feature_flags;
6161
6162         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6163                 printf("Device doesn't support digest encrypted.\n");
6164                 return TEST_SKIPPED;
6165         }
6166         if (op_mode == IN_PLACE) {
6167                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6168                         printf("Device doesn't support in-place scatter-gather "
6169                                         "in both input and output mbufs.\n");
6170                         return TEST_SKIPPED;
6171                 }
6172
6173                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6174                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6175                         printf("Device doesn't support RAW data-path APIs.\n");
6176                         return TEST_SKIPPED;
6177                 }
6178         } else {
6179                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6180                         return TEST_SKIPPED;
6181                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6182                         printf("Device doesn't support out-of-place scatter-gather "
6183                                         "in both input and output mbufs.\n");
6184                         return TEST_SKIPPED;
6185                 }
6186         }
6187
6188         /* Create ZUC session */
6189         retval = create_wireless_algo_auth_cipher_session(
6190                         ts_params->valid_devs[0],
6191                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6192                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6193                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6194                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6195                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6196                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6197                         tdata->key.data, tdata->key.len,
6198                         tdata->auth_iv.len, tdata->digest.len,
6199                         tdata->cipher_iv.len);
6200
6201         if (retval != 0)
6202                 return retval;
6203
6204         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6205         if (op_mode == OUT_OF_PLACE)
6206                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6207
6208         /* clear mbuf payload */
6209         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6210                 rte_pktmbuf_tailroom(ut_params->ibuf));
6211         if (op_mode == OUT_OF_PLACE)
6212                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6213                         rte_pktmbuf_tailroom(ut_params->obuf));
6214
6215         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6216         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6217         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6218         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6219
6220         if (verify) {
6221                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6222                                         ciphertext_pad_len);
6223                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6224                 if (op_mode == OUT_OF_PLACE)
6225                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6226                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6227                         ciphertext_len);
6228         } else {
6229                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6230                                         plaintext_pad_len);
6231                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6232                 if (op_mode == OUT_OF_PLACE)
6233                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6234                 debug_hexdump(stdout, "plaintext:", plaintext,
6235                         plaintext_len);
6236         }
6237
6238         /* Create ZUC operation */
6239         retval = create_wireless_algo_auth_cipher_operation(
6240                 tdata->digest.data, tdata->digest.len,
6241                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6242                 tdata->auth_iv.data, tdata->auth_iv.len,
6243                 (tdata->digest.offset_bytes == 0 ?
6244                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6245                         : tdata->digest.offset_bytes),
6246                 tdata->validCipherLenInBits.len,
6247                 tdata->validCipherOffsetInBits.len,
6248                 tdata->validAuthLenInBits.len,
6249                 0,
6250                 op_mode, 0, verify);
6251
6252         if (retval < 0)
6253                 return retval;
6254
6255         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6256                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6257                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6258         else
6259                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6260                         ut_params->op);
6261
6262         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6263
6264         ut_params->obuf = (op_mode == IN_PLACE ?
6265                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6266
6267
6268         if (verify) {
6269                 if (ut_params->obuf)
6270                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6271                                                         uint8_t *);
6272                 else
6273                         plaintext = ciphertext;
6274
6275                 debug_hexdump(stdout, "plaintext:", plaintext,
6276                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6277                 debug_hexdump(stdout, "plaintext expected:",
6278                         tdata->plaintext.data,
6279                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6280         } else {
6281                 if (ut_params->obuf)
6282                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6283                                                         uint8_t *);
6284                 else
6285                         ciphertext = plaintext;
6286
6287                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6288                         ciphertext_len);
6289                 debug_hexdump(stdout, "ciphertext expected:",
6290                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6291
6292                 ut_params->digest = rte_pktmbuf_mtod(
6293                         ut_params->obuf, uint8_t *) +
6294                         (tdata->digest.offset_bytes == 0 ?
6295                         plaintext_pad_len : tdata->digest.offset_bytes);
6296
6297                 debug_hexdump(stdout, "digest:", ut_params->digest,
6298                         tdata->digest.len);
6299                 debug_hexdump(stdout, "digest expected:",
6300                         tdata->digest.data, tdata->digest.len);
6301         }
6302
6303         /* Validate obuf */
6304         if (verify) {
6305                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6306                         plaintext,
6307                         tdata->plaintext.data,
6308                         tdata->plaintext.len >> 3,
6309                         "ZUC Plaintext data not as expected");
6310         } else {
6311                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6312                         ciphertext,
6313                         tdata->ciphertext.data,
6314                         tdata->ciphertext.len >> 3,
6315                         "ZUC Ciphertext data not as expected");
6316
6317                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6318                         ut_params->digest,
6319                         tdata->digest.data,
6320                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6321                         "ZUC Generated auth tag not as expected");
6322         }
6323         return 0;
6324 }
6325
6326 static int
6327 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6328         uint8_t op_mode, uint8_t verify)
6329 {
6330         struct crypto_testsuite_params *ts_params = &testsuite_params;
6331         struct crypto_unittest_params *ut_params = &unittest_params;
6332
6333         int retval;
6334
6335         const uint8_t *plaintext = NULL;
6336         const uint8_t *ciphertext = NULL;
6337         const uint8_t *digest = NULL;
6338         unsigned int plaintext_pad_len;
6339         unsigned int plaintext_len;
6340         unsigned int ciphertext_pad_len;
6341         unsigned int ciphertext_len;
6342         uint8_t buffer[10000];
6343         uint8_t digest_buffer[10000];
6344
6345         struct rte_cryptodev_info dev_info;
6346         struct rte_cryptodev_sym_capability_idx cap_idx;
6347
6348         /* Check if device supports ZUC EIA3 */
6349         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6350         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6351
6352         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6353                         &cap_idx) == NULL)
6354                 return TEST_SKIPPED;
6355
6356         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6357
6358         uint64_t feat_flags = dev_info.feature_flags;
6359
6360         if (op_mode == IN_PLACE) {
6361                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6362                         printf("Device doesn't support in-place scatter-gather "
6363                                         "in both input and output mbufs.\n");
6364                         return TEST_SKIPPED;
6365                 }
6366
6367                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6368                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6369                         printf("Device doesn't support RAW data-path APIs.\n");
6370                         return TEST_SKIPPED;
6371                 }
6372         } else {
6373                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6374                         return TEST_SKIPPED;
6375                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6376                         printf("Device doesn't support out-of-place scatter-gather "
6377                                         "in both input and output mbufs.\n");
6378                         return TEST_SKIPPED;
6379                 }
6380                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6381                         printf("Device doesn't support digest encrypted.\n");
6382                         return TEST_SKIPPED;
6383                 }
6384         }
6385
6386         /* Create ZUC session */
6387         retval = create_wireless_algo_auth_cipher_session(
6388                         ts_params->valid_devs[0],
6389                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6390                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6391                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6392                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6393                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6394                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6395                         tdata->key.data, tdata->key.len,
6396                         tdata->auth_iv.len, tdata->digest.len,
6397                         tdata->cipher_iv.len);
6398
6399         if (retval != 0)
6400                 return retval;
6401
6402         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6403         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6404         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6405         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6406
6407         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6408                         plaintext_pad_len, 15, 0);
6409         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6410                         "Failed to allocate input buffer in mempool");
6411
6412         if (op_mode == OUT_OF_PLACE) {
6413                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6414                                 plaintext_pad_len, 15, 0);
6415                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6416                                 "Failed to allocate output buffer in mempool");
6417         }
6418
6419         if (verify) {
6420                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6421                         tdata->ciphertext.data);
6422                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6423                                         ciphertext_len, buffer);
6424                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6425                         ciphertext_len);
6426         } else {
6427                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6428                         tdata->plaintext.data);
6429                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6430                                         plaintext_len, buffer);
6431                 debug_hexdump(stdout, "plaintext:", plaintext,
6432                         plaintext_len);
6433         }
6434         memset(buffer, 0, sizeof(buffer));
6435
6436         /* Create ZUC operation */
6437         retval = create_wireless_algo_auth_cipher_operation(
6438                 tdata->digest.data, tdata->digest.len,
6439                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6440                 NULL, 0,
6441                 (tdata->digest.offset_bytes == 0 ?
6442                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6443                         : tdata->digest.offset_bytes),
6444                 tdata->validCipherLenInBits.len,
6445                 tdata->validCipherOffsetInBits.len,
6446                 tdata->validAuthLenInBits.len,
6447                 0,
6448                 op_mode, 1, verify);
6449
6450         if (retval < 0)
6451                 return retval;
6452
6453         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6454                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6455                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6456         else
6457                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6458                         ut_params->op);
6459
6460         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6461
6462         ut_params->obuf = (op_mode == IN_PLACE ?
6463                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6464
6465         if (verify) {
6466                 if (ut_params->obuf)
6467                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6468                                         plaintext_len, buffer);
6469                 else
6470                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6471                                         plaintext_len, buffer);
6472
6473                 debug_hexdump(stdout, "plaintext:", plaintext,
6474                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6475                 debug_hexdump(stdout, "plaintext expected:",
6476                         tdata->plaintext.data,
6477                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6478         } else {
6479                 if (ut_params->obuf)
6480                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6481                                         ciphertext_len, buffer);
6482                 else
6483                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6484                                         ciphertext_len, buffer);
6485
6486                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6487                         ciphertext_len);
6488                 debug_hexdump(stdout, "ciphertext expected:",
6489                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6490
6491                 if (ut_params->obuf)
6492                         digest = rte_pktmbuf_read(ut_params->obuf,
6493                                 (tdata->digest.offset_bytes == 0 ?
6494                                 plaintext_pad_len : tdata->digest.offset_bytes),
6495                                 tdata->digest.len, digest_buffer);
6496                 else
6497                         digest = rte_pktmbuf_read(ut_params->ibuf,
6498                                 (tdata->digest.offset_bytes == 0 ?
6499                                 plaintext_pad_len : tdata->digest.offset_bytes),
6500                                 tdata->digest.len, digest_buffer);
6501
6502                 debug_hexdump(stdout, "digest:", digest,
6503                         tdata->digest.len);
6504                 debug_hexdump(stdout, "digest expected:",
6505                         tdata->digest.data, tdata->digest.len);
6506         }
6507
6508         /* Validate obuf */
6509         if (verify) {
6510                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6511                         plaintext,
6512                         tdata->plaintext.data,
6513                         tdata->plaintext.len >> 3,
6514                         "ZUC Plaintext data not as expected");
6515         } else {
6516                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6517                         ciphertext,
6518                         tdata->ciphertext.data,
6519                         tdata->validDataLenInBits.len,
6520                         "ZUC Ciphertext data not as expected");
6521
6522                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6523                         digest,
6524                         tdata->digest.data,
6525                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6526                         "ZUC Generated auth tag not as expected");
6527         }
6528         return 0;
6529 }
6530
6531 static int
6532 test_kasumi_encryption_test_case_1(void)
6533 {
6534         return test_kasumi_encryption(&kasumi_test_case_1);
6535 }
6536
6537 static int
6538 test_kasumi_encryption_test_case_1_sgl(void)
6539 {
6540         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6541 }
6542
6543 static int
6544 test_kasumi_encryption_test_case_1_oop(void)
6545 {
6546         return test_kasumi_encryption_oop(&kasumi_test_case_1);
6547 }
6548
6549 static int
6550 test_kasumi_encryption_test_case_1_oop_sgl(void)
6551 {
6552         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6553 }
6554
6555 static int
6556 test_kasumi_encryption_test_case_2(void)
6557 {
6558         return test_kasumi_encryption(&kasumi_test_case_2);
6559 }
6560
6561 static int
6562 test_kasumi_encryption_test_case_3(void)
6563 {
6564         return test_kasumi_encryption(&kasumi_test_case_3);
6565 }
6566
6567 static int
6568 test_kasumi_encryption_test_case_4(void)
6569 {
6570         return test_kasumi_encryption(&kasumi_test_case_4);
6571 }
6572
6573 static int
6574 test_kasumi_encryption_test_case_5(void)
6575 {
6576         return test_kasumi_encryption(&kasumi_test_case_5);
6577 }
6578
6579 static int
6580 test_kasumi_decryption_test_case_1(void)
6581 {
6582         return test_kasumi_decryption(&kasumi_test_case_1);
6583 }
6584
6585 static int
6586 test_kasumi_decryption_test_case_1_oop(void)
6587 {
6588         return test_kasumi_decryption_oop(&kasumi_test_case_1);
6589 }
6590
6591 static int
6592 test_kasumi_decryption_test_case_2(void)
6593 {
6594         return test_kasumi_decryption(&kasumi_test_case_2);
6595 }
6596
6597 static int
6598 test_kasumi_decryption_test_case_3(void)
6599 {
6600         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6601         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6602                 return TEST_SKIPPED;
6603         return test_kasumi_decryption(&kasumi_test_case_3);
6604 }
6605
6606 static int
6607 test_kasumi_decryption_test_case_4(void)
6608 {
6609         return test_kasumi_decryption(&kasumi_test_case_4);
6610 }
6611
6612 static int
6613 test_kasumi_decryption_test_case_5(void)
6614 {
6615         return test_kasumi_decryption(&kasumi_test_case_5);
6616 }
6617 static int
6618 test_snow3g_encryption_test_case_1(void)
6619 {
6620         return test_snow3g_encryption(&snow3g_test_case_1);
6621 }
6622
6623 static int
6624 test_snow3g_encryption_test_case_1_oop(void)
6625 {
6626         return test_snow3g_encryption_oop(&snow3g_test_case_1);
6627 }
6628
6629 static int
6630 test_snow3g_encryption_test_case_1_oop_sgl(void)
6631 {
6632         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6633 }
6634
6635
6636 static int
6637 test_snow3g_encryption_test_case_1_offset_oop(void)
6638 {
6639         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6640 }
6641
6642 static int
6643 test_snow3g_encryption_test_case_2(void)
6644 {
6645         return test_snow3g_encryption(&snow3g_test_case_2);
6646 }
6647
6648 static int
6649 test_snow3g_encryption_test_case_3(void)
6650 {
6651         return test_snow3g_encryption(&snow3g_test_case_3);
6652 }
6653
6654 static int
6655 test_snow3g_encryption_test_case_4(void)
6656 {
6657         return test_snow3g_encryption(&snow3g_test_case_4);
6658 }
6659
6660 static int
6661 test_snow3g_encryption_test_case_5(void)
6662 {
6663         return test_snow3g_encryption(&snow3g_test_case_5);
6664 }
6665
6666 static int
6667 test_snow3g_decryption_test_case_1(void)
6668 {
6669         return test_snow3g_decryption(&snow3g_test_case_1);
6670 }
6671
6672 static int
6673 test_snow3g_decryption_test_case_1_oop(void)
6674 {
6675         return test_snow3g_decryption_oop(&snow3g_test_case_1);
6676 }
6677
6678 static int
6679 test_snow3g_decryption_test_case_2(void)
6680 {
6681         return test_snow3g_decryption(&snow3g_test_case_2);
6682 }
6683
6684 static int
6685 test_snow3g_decryption_test_case_3(void)
6686 {
6687         return test_snow3g_decryption(&snow3g_test_case_3);
6688 }
6689
6690 static int
6691 test_snow3g_decryption_test_case_4(void)
6692 {
6693         return test_snow3g_decryption(&snow3g_test_case_4);
6694 }
6695
6696 static int
6697 test_snow3g_decryption_test_case_5(void)
6698 {
6699         return test_snow3g_decryption(&snow3g_test_case_5);
6700 }
6701
6702 /*
6703  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6704  * Pattern digest from snow3g_test_data must be allocated as
6705  * 4 last bytes in plaintext.
6706  */
6707 static void
6708 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6709                 struct snow3g_hash_test_data *output)
6710 {
6711         if ((pattern != NULL) && (output != NULL)) {
6712                 output->key.len = pattern->key.len;
6713
6714                 memcpy(output->key.data,
6715                 pattern->key.data, pattern->key.len);
6716
6717                 output->auth_iv.len = pattern->auth_iv.len;
6718
6719                 memcpy(output->auth_iv.data,
6720                 pattern->auth_iv.data, pattern->auth_iv.len);
6721
6722                 output->plaintext.len = pattern->plaintext.len;
6723
6724                 memcpy(output->plaintext.data,
6725                 pattern->plaintext.data, pattern->plaintext.len >> 3);
6726
6727                 output->digest.len = pattern->digest.len;
6728
6729                 memcpy(output->digest.data,
6730                 &pattern->plaintext.data[pattern->digest.offset_bytes],
6731                 pattern->digest.len);
6732
6733                 output->validAuthLenInBits.len =
6734                 pattern->validAuthLenInBits.len;
6735         }
6736 }
6737
6738 /*
6739  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6740  */
6741 static int
6742 test_snow3g_decryption_with_digest_test_case_1(void)
6743 {
6744         struct snow3g_hash_test_data snow3g_hash_data;
6745         struct rte_cryptodev_info dev_info;
6746         struct crypto_testsuite_params *ts_params = &testsuite_params;
6747
6748         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6749         uint64_t feat_flags = dev_info.feature_flags;
6750
6751         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6752                 printf("Device doesn't support encrypted digest operations.\n");
6753                 return TEST_SKIPPED;
6754         }
6755
6756         /*
6757          * Function prepare data for hash veryfication test case.
6758          * Digest is allocated in 4 last bytes in plaintext, pattern.
6759          */
6760         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6761
6762         return test_snow3g_decryption(&snow3g_test_case_7) &
6763                         test_snow3g_authentication_verify(&snow3g_hash_data);
6764 }
6765
6766 static int
6767 test_snow3g_cipher_auth_test_case_1(void)
6768 {
6769         return test_snow3g_cipher_auth(&snow3g_test_case_3);
6770 }
6771
6772 static int
6773 test_snow3g_auth_cipher_test_case_1(void)
6774 {
6775         return test_snow3g_auth_cipher(
6776                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6777 }
6778
6779 static int
6780 test_snow3g_auth_cipher_test_case_2(void)
6781 {
6782         return test_snow3g_auth_cipher(
6783                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6784 }
6785
6786 static int
6787 test_snow3g_auth_cipher_test_case_2_oop(void)
6788 {
6789         return test_snow3g_auth_cipher(
6790                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6791 }
6792
6793 static int
6794 test_snow3g_auth_cipher_part_digest_enc(void)
6795 {
6796         return test_snow3g_auth_cipher(
6797                 &snow3g_auth_cipher_partial_digest_encryption,
6798                         IN_PLACE, 0);
6799 }
6800
6801 static int
6802 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6803 {
6804         return test_snow3g_auth_cipher(
6805                 &snow3g_auth_cipher_partial_digest_encryption,
6806                         OUT_OF_PLACE, 0);
6807 }
6808
6809 static int
6810 test_snow3g_auth_cipher_test_case_3_sgl(void)
6811 {
6812         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6813         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6814                 return TEST_SKIPPED;
6815         return test_snow3g_auth_cipher_sgl(
6816                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6817 }
6818
6819 static int
6820 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6821 {
6822         return test_snow3g_auth_cipher_sgl(
6823                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6824 }
6825
6826 static int
6827 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6828 {
6829         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6830         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6831                 return TEST_SKIPPED;
6832         return test_snow3g_auth_cipher_sgl(
6833                 &snow3g_auth_cipher_partial_digest_encryption,
6834                         IN_PLACE, 0);
6835 }
6836
6837 static int
6838 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6839 {
6840         return test_snow3g_auth_cipher_sgl(
6841                 &snow3g_auth_cipher_partial_digest_encryption,
6842                         OUT_OF_PLACE, 0);
6843 }
6844
6845 static int
6846 test_snow3g_auth_cipher_verify_test_case_1(void)
6847 {
6848         return test_snow3g_auth_cipher(
6849                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6850 }
6851
6852 static int
6853 test_snow3g_auth_cipher_verify_test_case_2(void)
6854 {
6855         return test_snow3g_auth_cipher(
6856                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6857 }
6858
6859 static int
6860 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6861 {
6862         return test_snow3g_auth_cipher(
6863                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6864 }
6865
6866 static int
6867 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6868 {
6869         return test_snow3g_auth_cipher(
6870                 &snow3g_auth_cipher_partial_digest_encryption,
6871                         IN_PLACE, 1);
6872 }
6873
6874 static int
6875 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6876 {
6877         return test_snow3g_auth_cipher(
6878                 &snow3g_auth_cipher_partial_digest_encryption,
6879                         OUT_OF_PLACE, 1);
6880 }
6881
6882 static int
6883 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6884 {
6885         return test_snow3g_auth_cipher_sgl(
6886                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6887 }
6888
6889 static int
6890 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6891 {
6892         return test_snow3g_auth_cipher_sgl(
6893                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6894 }
6895
6896 static int
6897 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6898 {
6899         return test_snow3g_auth_cipher_sgl(
6900                 &snow3g_auth_cipher_partial_digest_encryption,
6901                         IN_PLACE, 1);
6902 }
6903
6904 static int
6905 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6906 {
6907         return test_snow3g_auth_cipher_sgl(
6908                 &snow3g_auth_cipher_partial_digest_encryption,
6909                         OUT_OF_PLACE, 1);
6910 }
6911
6912 static int
6913 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6914 {
6915         return test_snow3g_auth_cipher(
6916                 &snow3g_test_case_7, IN_PLACE, 0);
6917 }
6918
6919 static int
6920 test_kasumi_auth_cipher_test_case_1(void)
6921 {
6922         return test_kasumi_auth_cipher(
6923                 &kasumi_test_case_3, IN_PLACE, 0);
6924 }
6925
6926 static int
6927 test_kasumi_auth_cipher_test_case_2(void)
6928 {
6929         return test_kasumi_auth_cipher(
6930                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6931 }
6932
6933 static int
6934 test_kasumi_auth_cipher_test_case_2_oop(void)
6935 {
6936         return test_kasumi_auth_cipher(
6937                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6938 }
6939
6940 static int
6941 test_kasumi_auth_cipher_test_case_2_sgl(void)
6942 {
6943         return test_kasumi_auth_cipher_sgl(
6944                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6945 }
6946
6947 static int
6948 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6949 {
6950         return test_kasumi_auth_cipher_sgl(
6951                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6952 }
6953
6954 static int
6955 test_kasumi_auth_cipher_verify_test_case_1(void)
6956 {
6957         return test_kasumi_auth_cipher(
6958                 &kasumi_test_case_3, IN_PLACE, 1);
6959 }
6960
6961 static int
6962 test_kasumi_auth_cipher_verify_test_case_2(void)
6963 {
6964         return test_kasumi_auth_cipher(
6965                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6966 }
6967
6968 static int
6969 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6970 {
6971         return test_kasumi_auth_cipher(
6972                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6973 }
6974
6975 static int
6976 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6977 {
6978         return test_kasumi_auth_cipher_sgl(
6979                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6980 }
6981
6982 static int
6983 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6984 {
6985         return test_kasumi_auth_cipher_sgl(
6986                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6987 }
6988
6989 static int
6990 test_kasumi_cipher_auth_test_case_1(void)
6991 {
6992         return test_kasumi_cipher_auth(&kasumi_test_case_6);
6993 }
6994
6995 static int
6996 test_zuc_encryption_test_case_1(void)
6997 {
6998         return test_zuc_encryption(&zuc_test_case_cipher_193b);
6999 }
7000
7001 static int
7002 test_zuc_encryption_test_case_2(void)
7003 {
7004         return test_zuc_encryption(&zuc_test_case_cipher_800b);
7005 }
7006
7007 static int
7008 test_zuc_encryption_test_case_3(void)
7009 {
7010         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
7011 }
7012
7013 static int
7014 test_zuc_encryption_test_case_4(void)
7015 {
7016         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
7017 }
7018
7019 static int
7020 test_zuc_encryption_test_case_5(void)
7021 {
7022         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7023 }
7024
7025 static int
7026 test_zuc_encryption_test_case_6_sgl(void)
7027 {
7028         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7029 }
7030
7031 static int
7032 test_zuc_encryption_test_case_7(void)
7033 {
7034         return test_zuc_encryption(&zuc_test_case_cipher_800b_key_256b);
7035 }
7036
7037 static int
7038 test_zuc_hash_generate_test_case_1(void)
7039 {
7040         return test_zuc_authentication(&zuc_test_case_auth_1b);
7041 }
7042
7043 static int
7044 test_zuc_hash_generate_test_case_2(void)
7045 {
7046         return test_zuc_authentication(&zuc_test_case_auth_90b);
7047 }
7048
7049 static int
7050 test_zuc_hash_generate_test_case_3(void)
7051 {
7052         return test_zuc_authentication(&zuc_test_case_auth_577b);
7053 }
7054
7055 static int
7056 test_zuc_hash_generate_test_case_4(void)
7057 {
7058         return test_zuc_authentication(&zuc_test_case_auth_2079b);
7059 }
7060
7061 static int
7062 test_zuc_hash_generate_test_case_5(void)
7063 {
7064         return test_zuc_authentication(&zuc_test_auth_5670b);
7065 }
7066
7067 static int
7068 test_zuc_hash_generate_test_case_6(void)
7069 {
7070         return test_zuc_authentication(&zuc_test_case_auth_128b);
7071 }
7072
7073 static int
7074 test_zuc_hash_generate_test_case_7(void)
7075 {
7076         return test_zuc_authentication(&zuc_test_case_auth_2080b);
7077 }
7078
7079 static int
7080 test_zuc_hash_generate_test_case_8(void)
7081 {
7082         return test_zuc_authentication(&zuc_test_case_auth_584b);
7083 }
7084
7085 static int
7086 test_zuc_hash_generate_test_case_9(void)
7087 {
7088         return test_zuc_authentication(&zuc_test_case_auth_584b_mac_64b);
7089 }
7090
7091 static int
7092 test_zuc_hash_generate_test_case_10(void)
7093 {
7094         return test_zuc_authentication(&zuc_test_case_auth_2080b_mac_128b);
7095 }
7096
7097 static int
7098 test_zuc_cipher_auth_test_case_1(void)
7099 {
7100         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7101 }
7102
7103 static int
7104 test_zuc_cipher_auth_test_case_2(void)
7105 {
7106         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7107 }
7108
7109 static int
7110 test_zuc_auth_cipher_test_case_1(void)
7111 {
7112         return test_zuc_auth_cipher(
7113                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7114 }
7115
7116 static int
7117 test_zuc_auth_cipher_test_case_1_oop(void)
7118 {
7119         return test_zuc_auth_cipher(
7120                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7121 }
7122
7123 static int
7124 test_zuc_auth_cipher_test_case_1_sgl(void)
7125 {
7126         return test_zuc_auth_cipher_sgl(
7127                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7128 }
7129
7130 static int
7131 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7132 {
7133         return test_zuc_auth_cipher_sgl(
7134                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7135 }
7136
7137 static int
7138 test_zuc_auth_cipher_verify_test_case_1(void)
7139 {
7140         return test_zuc_auth_cipher(
7141                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7142 }
7143
7144 static int
7145 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7146 {
7147         return test_zuc_auth_cipher(
7148                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7149 }
7150
7151 static int
7152 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7153 {
7154         return test_zuc_auth_cipher_sgl(
7155                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7156 }
7157
7158 static int
7159 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7160 {
7161         return test_zuc_auth_cipher_sgl(
7162                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7163 }
7164
7165 static int
7166 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7167 {
7168         uint8_t dev_id = testsuite_params.valid_devs[0];
7169
7170         struct rte_cryptodev_sym_capability_idx cap_idx;
7171
7172         /* Check if device supports particular cipher algorithm */
7173         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7174         cap_idx.algo.cipher = tdata->cipher_algo;
7175         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7176                 return TEST_SKIPPED;
7177
7178         /* Check if device supports particular hash algorithm */
7179         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7180         cap_idx.algo.auth = tdata->auth_algo;
7181         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7182                 return TEST_SKIPPED;
7183
7184         return 0;
7185 }
7186
7187 static int
7188 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7189         uint8_t op_mode, uint8_t verify)
7190 {
7191         struct crypto_testsuite_params *ts_params = &testsuite_params;
7192         struct crypto_unittest_params *ut_params = &unittest_params;
7193
7194         int retval;
7195
7196         uint8_t *plaintext = NULL, *ciphertext = NULL;
7197         unsigned int plaintext_pad_len;
7198         unsigned int plaintext_len;
7199         unsigned int ciphertext_pad_len;
7200         unsigned int ciphertext_len;
7201
7202         struct rte_cryptodev_info dev_info;
7203         struct rte_crypto_op *op;
7204
7205         /* Check if device supports particular algorithms separately */
7206         if (test_mixed_check_if_unsupported(tdata))
7207                 return TEST_SKIPPED;
7208         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7209                 return TEST_SKIPPED;
7210
7211         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7212
7213         uint64_t feat_flags = dev_info.feature_flags;
7214
7215         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7216                 printf("Device doesn't support digest encrypted.\n");
7217                 return TEST_SKIPPED;
7218         }
7219
7220         /* Create the session */
7221         if (verify)
7222                 retval = create_wireless_algo_cipher_auth_session(
7223                                 ts_params->valid_devs[0],
7224                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7225                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7226                                 tdata->auth_algo,
7227                                 tdata->cipher_algo,
7228                                 tdata->auth_key.data, tdata->auth_key.len,
7229                                 tdata->auth_iv.len, tdata->digest_enc.len,
7230                                 tdata->cipher_iv.len);
7231         else
7232                 retval = create_wireless_algo_auth_cipher_session(
7233                                 ts_params->valid_devs[0],
7234                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7235                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7236                                 tdata->auth_algo,
7237                                 tdata->cipher_algo,
7238                                 tdata->auth_key.data, tdata->auth_key.len,
7239                                 tdata->auth_iv.len, tdata->digest_enc.len,
7240                                 tdata->cipher_iv.len);
7241         if (retval != 0)
7242                 return retval;
7243
7244         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7245         if (op_mode == OUT_OF_PLACE)
7246                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7247
7248         /* clear mbuf payload */
7249         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7250                 rte_pktmbuf_tailroom(ut_params->ibuf));
7251         if (op_mode == OUT_OF_PLACE) {
7252
7253                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7254                                 rte_pktmbuf_tailroom(ut_params->obuf));
7255         }
7256
7257         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7258         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7259         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7260         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7261
7262         if (verify) {
7263                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7264                                 ciphertext_pad_len);
7265                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7266                 if (op_mode == OUT_OF_PLACE)
7267                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7268                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7269                                 ciphertext_len);
7270         } else {
7271                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7272                                 plaintext_pad_len);
7273                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7274                 if (op_mode == OUT_OF_PLACE)
7275                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7276                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7277         }
7278
7279         /* Create the operation */
7280         retval = create_wireless_algo_auth_cipher_operation(
7281                         tdata->digest_enc.data, tdata->digest_enc.len,
7282                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7283                         tdata->auth_iv.data, tdata->auth_iv.len,
7284                         (tdata->digest_enc.offset == 0 ?
7285                                 plaintext_pad_len
7286                                 : tdata->digest_enc.offset),
7287                         tdata->validCipherLen.len_bits,
7288                         tdata->cipher.offset_bits,
7289                         tdata->validAuthLen.len_bits,
7290                         tdata->auth.offset_bits,
7291                         op_mode, 0, verify);
7292
7293         if (retval < 0)
7294                 return retval;
7295
7296         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7297
7298         /* Check if the op failed because the device doesn't */
7299         /* support this particular combination of algorithms */
7300         if (op == NULL && ut_params->op->status ==
7301                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7302                 printf("Device doesn't support this mixed combination. "
7303                                 "Test Skipped.\n");
7304                 return TEST_SKIPPED;
7305         }
7306         ut_params->op = op;
7307
7308         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7309
7310         ut_params->obuf = (op_mode == IN_PLACE ?
7311                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7312
7313         if (verify) {
7314                 if (ut_params->obuf)
7315                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7316                                                         uint8_t *);
7317                 else
7318                         plaintext = ciphertext +
7319                                         (tdata->cipher.offset_bits >> 3);
7320
7321                 debug_hexdump(stdout, "plaintext:", plaintext,
7322                                 tdata->plaintext.len_bits >> 3);
7323                 debug_hexdump(stdout, "plaintext expected:",
7324                                 tdata->plaintext.data,
7325                                 tdata->plaintext.len_bits >> 3);
7326         } else {
7327                 if (ut_params->obuf)
7328                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7329                                         uint8_t *);
7330                 else
7331                         ciphertext = plaintext;
7332
7333                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7334                                 ciphertext_len);
7335                 debug_hexdump(stdout, "ciphertext expected:",
7336                                 tdata->ciphertext.data,
7337                                 tdata->ciphertext.len_bits >> 3);
7338
7339                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7340                                 + (tdata->digest_enc.offset == 0 ?
7341                 plaintext_pad_len : tdata->digest_enc.offset);
7342
7343                 debug_hexdump(stdout, "digest:", ut_params->digest,
7344                                 tdata->digest_enc.len);
7345                 debug_hexdump(stdout, "digest expected:",
7346                                 tdata->digest_enc.data,
7347                                 tdata->digest_enc.len);
7348         }
7349
7350         /* Validate obuf */
7351         if (verify) {
7352                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7353                                 plaintext,
7354                                 tdata->plaintext.data,
7355                                 tdata->plaintext.len_bits >> 3,
7356                                 "Plaintext data not as expected");
7357         } else {
7358                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7359                                 ciphertext,
7360                                 tdata->ciphertext.data,
7361                                 tdata->validDataLen.len_bits,
7362                                 "Ciphertext data not as expected");
7363
7364                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7365                                 ut_params->digest,
7366                                 tdata->digest_enc.data,
7367                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7368                                 "Generated auth tag not as expected");
7369         }
7370
7371         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7372                         "crypto op processing failed");
7373
7374         return 0;
7375 }
7376
7377 static int
7378 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7379         uint8_t op_mode, uint8_t verify)
7380 {
7381         struct crypto_testsuite_params *ts_params = &testsuite_params;
7382         struct crypto_unittest_params *ut_params = &unittest_params;
7383
7384         int retval;
7385
7386         const uint8_t *plaintext = NULL;
7387         const uint8_t *ciphertext = NULL;
7388         const uint8_t *digest = NULL;
7389         unsigned int plaintext_pad_len;
7390         unsigned int plaintext_len;
7391         unsigned int ciphertext_pad_len;
7392         unsigned int ciphertext_len;
7393         uint8_t buffer[10000];
7394         uint8_t digest_buffer[10000];
7395
7396         struct rte_cryptodev_info dev_info;
7397         struct rte_crypto_op *op;
7398
7399         /* Check if device supports particular algorithms */
7400         if (test_mixed_check_if_unsupported(tdata))
7401                 return TEST_SKIPPED;
7402         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7403                 return TEST_SKIPPED;
7404
7405         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7406
7407         uint64_t feat_flags = dev_info.feature_flags;
7408
7409         if (op_mode == IN_PLACE) {
7410                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7411                         printf("Device doesn't support in-place scatter-gather "
7412                                         "in both input and output mbufs.\n");
7413                         return TEST_SKIPPED;
7414                 }
7415         } else {
7416                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7417                         printf("Device doesn't support out-of-place scatter-gather "
7418                                         "in both input and output mbufs.\n");
7419                         return TEST_SKIPPED;
7420                 }
7421                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7422                         printf("Device doesn't support digest encrypted.\n");
7423                         return TEST_SKIPPED;
7424                 }
7425         }
7426
7427         /* Create the session */
7428         if (verify)
7429                 retval = create_wireless_algo_cipher_auth_session(
7430                                 ts_params->valid_devs[0],
7431                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7432                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7433                                 tdata->auth_algo,
7434                                 tdata->cipher_algo,
7435                                 tdata->auth_key.data, tdata->auth_key.len,
7436                                 tdata->auth_iv.len, tdata->digest_enc.len,
7437                                 tdata->cipher_iv.len);
7438         else
7439                 retval = create_wireless_algo_auth_cipher_session(
7440                                 ts_params->valid_devs[0],
7441                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7442                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7443                                 tdata->auth_algo,
7444                                 tdata->cipher_algo,
7445                                 tdata->auth_key.data, tdata->auth_key.len,
7446                                 tdata->auth_iv.len, tdata->digest_enc.len,
7447                                 tdata->cipher_iv.len);
7448         if (retval != 0)
7449                 return retval;
7450
7451         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7452         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7453         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7454         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7455
7456         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7457                         ciphertext_pad_len, 15, 0);
7458         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7459                         "Failed to allocate input buffer in mempool");
7460
7461         if (op_mode == OUT_OF_PLACE) {
7462                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7463                                 plaintext_pad_len, 15, 0);
7464                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
7465                                 "Failed to allocate output buffer in mempool");
7466         }
7467
7468         if (verify) {
7469                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7470                         tdata->ciphertext.data);
7471                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7472                                         ciphertext_len, buffer);
7473                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7474                         ciphertext_len);
7475         } else {
7476                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7477                         tdata->plaintext.data);
7478                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7479                                         plaintext_len, buffer);
7480                 debug_hexdump(stdout, "plaintext:", plaintext,
7481                         plaintext_len);
7482         }
7483         memset(buffer, 0, sizeof(buffer));
7484
7485         /* Create the operation */
7486         retval = create_wireless_algo_auth_cipher_operation(
7487                         tdata->digest_enc.data, tdata->digest_enc.len,
7488                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7489                         tdata->auth_iv.data, tdata->auth_iv.len,
7490                         (tdata->digest_enc.offset == 0 ?
7491                                 plaintext_pad_len
7492                                 : tdata->digest_enc.offset),
7493                         tdata->validCipherLen.len_bits,
7494                         tdata->cipher.offset_bits,
7495                         tdata->validAuthLen.len_bits,
7496                         tdata->auth.offset_bits,
7497                         op_mode, 1, verify);
7498
7499         if (retval < 0)
7500                 return retval;
7501
7502         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7503
7504         /* Check if the op failed because the device doesn't */
7505         /* support this particular combination of algorithms */
7506         if (op == NULL && ut_params->op->status ==
7507                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7508                 printf("Device doesn't support this mixed combination. "
7509                                 "Test Skipped.\n");
7510                 return TEST_SKIPPED;
7511         }
7512         ut_params->op = op;
7513
7514         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7515
7516         ut_params->obuf = (op_mode == IN_PLACE ?
7517                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7518
7519         if (verify) {
7520                 if (ut_params->obuf)
7521                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7522                                         plaintext_len, buffer);
7523                 else
7524                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7525                                         plaintext_len, buffer);
7526
7527                 debug_hexdump(stdout, "plaintext:", plaintext,
7528                                 (tdata->plaintext.len_bits >> 3) -
7529                                 tdata->digest_enc.len);
7530                 debug_hexdump(stdout, "plaintext expected:",
7531                                 tdata->plaintext.data,
7532                                 (tdata->plaintext.len_bits >> 3) -
7533                                 tdata->digest_enc.len);
7534         } else {
7535                 if (ut_params->obuf)
7536                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7537                                         ciphertext_len, buffer);
7538                 else
7539                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7540                                         ciphertext_len, buffer);
7541
7542                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7543                         ciphertext_len);
7544                 debug_hexdump(stdout, "ciphertext expected:",
7545                         tdata->ciphertext.data,
7546                         tdata->ciphertext.len_bits >> 3);
7547
7548                 if (ut_params->obuf)
7549                         digest = rte_pktmbuf_read(ut_params->obuf,
7550                                         (tdata->digest_enc.offset == 0 ?
7551                                                 plaintext_pad_len :
7552                                                 tdata->digest_enc.offset),
7553                                         tdata->digest_enc.len, digest_buffer);
7554                 else
7555                         digest = rte_pktmbuf_read(ut_params->ibuf,
7556                                         (tdata->digest_enc.offset == 0 ?
7557                                                 plaintext_pad_len :
7558                                                 tdata->digest_enc.offset),
7559                                         tdata->digest_enc.len, digest_buffer);
7560
7561                 debug_hexdump(stdout, "digest:", digest,
7562                                 tdata->digest_enc.len);
7563                 debug_hexdump(stdout, "digest expected:",
7564                                 tdata->digest_enc.data, tdata->digest_enc.len);
7565         }
7566
7567         /* Validate obuf */
7568         if (verify) {
7569                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7570                                 plaintext,
7571                                 tdata->plaintext.data,
7572                                 tdata->plaintext.len_bits >> 3,
7573                                 "Plaintext data not as expected");
7574         } else {
7575                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7576                                 ciphertext,
7577                                 tdata->ciphertext.data,
7578                                 tdata->validDataLen.len_bits,
7579                                 "Ciphertext data not as expected");
7580                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7581                                 digest,
7582                                 tdata->digest_enc.data,
7583                                 tdata->digest_enc.len,
7584                                 "Generated auth tag not as expected");
7585         }
7586
7587         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7588                         "crypto op processing failed");
7589
7590         return 0;
7591 }
7592
7593 /** AUTH AES CMAC + CIPHER AES CTR */
7594
7595 static int
7596 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7597 {
7598         return test_mixed_auth_cipher(
7599                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7600 }
7601
7602 static int
7603 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7604 {
7605         return test_mixed_auth_cipher(
7606                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7607 }
7608
7609 static int
7610 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7611 {
7612         return test_mixed_auth_cipher_sgl(
7613                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7614 }
7615
7616 static int
7617 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7618 {
7619         return test_mixed_auth_cipher_sgl(
7620                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7621 }
7622
7623 static int
7624 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7625 {
7626         return test_mixed_auth_cipher(
7627                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7628 }
7629
7630 static int
7631 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7632 {
7633         return test_mixed_auth_cipher(
7634                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7635 }
7636
7637 static int
7638 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7639 {
7640         return test_mixed_auth_cipher_sgl(
7641                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7642 }
7643
7644 static int
7645 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7646 {
7647         return test_mixed_auth_cipher_sgl(
7648                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7649 }
7650
7651 /** MIXED AUTH + CIPHER */
7652
7653 static int
7654 test_auth_zuc_cipher_snow_test_case_1(void)
7655 {
7656         return test_mixed_auth_cipher(
7657                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7658 }
7659
7660 static int
7661 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7662 {
7663         return test_mixed_auth_cipher(
7664                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7665 }
7666
7667 static int
7668 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7669 {
7670         return test_mixed_auth_cipher(
7671                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7672 }
7673
7674 static int
7675 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7676 {
7677         return test_mixed_auth_cipher(
7678                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7679 }
7680
7681 static int
7682 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7683 {
7684         return test_mixed_auth_cipher(
7685                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7686 }
7687
7688 static int
7689 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7690 {
7691         return test_mixed_auth_cipher(
7692                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7693 }
7694
7695 static int
7696 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7697 {
7698         return test_mixed_auth_cipher(
7699                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7700 }
7701
7702 static int
7703 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7704 {
7705         return test_mixed_auth_cipher(
7706                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7707 }
7708
7709 static int
7710 test_auth_snow_cipher_zuc_test_case_1(void)
7711 {
7712         return test_mixed_auth_cipher(
7713                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7714 }
7715
7716 static int
7717 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7718 {
7719         return test_mixed_auth_cipher(
7720                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7721 }
7722
7723 static int
7724 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7725 {
7726         return test_mixed_auth_cipher(
7727                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7728 }
7729
7730 static int
7731 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7732 {
7733         return test_mixed_auth_cipher(
7734                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7735 }
7736
7737 static int
7738 test_auth_null_cipher_snow_test_case_1(void)
7739 {
7740         return test_mixed_auth_cipher(
7741                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7742 }
7743
7744 static int
7745 test_verify_auth_null_cipher_snow_test_case_1(void)
7746 {
7747         return test_mixed_auth_cipher(
7748                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7749 }
7750
7751 static int
7752 test_auth_null_cipher_zuc_test_case_1(void)
7753 {
7754         return test_mixed_auth_cipher(
7755                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7756 }
7757
7758 static int
7759 test_verify_auth_null_cipher_zuc_test_case_1(void)
7760 {
7761         return test_mixed_auth_cipher(
7762                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7763 }
7764
7765 static int
7766 test_auth_snow_cipher_null_test_case_1(void)
7767 {
7768         return test_mixed_auth_cipher(
7769                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7770 }
7771
7772 static int
7773 test_verify_auth_snow_cipher_null_test_case_1(void)
7774 {
7775         return test_mixed_auth_cipher(
7776                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7777 }
7778
7779 static int
7780 test_auth_zuc_cipher_null_test_case_1(void)
7781 {
7782         return test_mixed_auth_cipher(
7783                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7784 }
7785
7786 static int
7787 test_verify_auth_zuc_cipher_null_test_case_1(void)
7788 {
7789         return test_mixed_auth_cipher(
7790                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7791 }
7792
7793 static int
7794 test_auth_null_cipher_aes_ctr_test_case_1(void)
7795 {
7796         return test_mixed_auth_cipher(
7797                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7798 }
7799
7800 static int
7801 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7802 {
7803         return test_mixed_auth_cipher(
7804                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7805 }
7806
7807 static int
7808 test_auth_aes_cmac_cipher_null_test_case_1(void)
7809 {
7810         return test_mixed_auth_cipher(
7811                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7812 }
7813
7814 static int
7815 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7816 {
7817         return test_mixed_auth_cipher(
7818                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7819 }
7820
7821 /* ***** AEAD algorithm Tests ***** */
7822
7823 static int
7824 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7825                 enum rte_crypto_aead_operation op,
7826                 const uint8_t *key, const uint8_t key_len,
7827                 const uint16_t aad_len, const uint8_t auth_len,
7828                 uint8_t iv_len)
7829 {
7830         uint8_t aead_key[key_len];
7831
7832         struct crypto_testsuite_params *ts_params = &testsuite_params;
7833         struct crypto_unittest_params *ut_params = &unittest_params;
7834
7835         memcpy(aead_key, key, key_len);
7836
7837         /* Setup AEAD Parameters */
7838         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7839         ut_params->aead_xform.next = NULL;
7840         ut_params->aead_xform.aead.algo = algo;
7841         ut_params->aead_xform.aead.op = op;
7842         ut_params->aead_xform.aead.key.data = aead_key;
7843         ut_params->aead_xform.aead.key.length = key_len;
7844         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7845         ut_params->aead_xform.aead.iv.length = iv_len;
7846         ut_params->aead_xform.aead.digest_length = auth_len;
7847         ut_params->aead_xform.aead.aad_length = aad_len;
7848
7849         debug_hexdump(stdout, "key:", key, key_len);
7850
7851         /* Create Crypto session*/
7852         ut_params->sess = rte_cryptodev_sym_session_create(
7853                         ts_params->session_mpool);
7854
7855         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7856                         &ut_params->aead_xform,
7857                         ts_params->session_priv_mpool);
7858
7859         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7860
7861         return 0;
7862 }
7863
7864 static int
7865 create_aead_xform(struct rte_crypto_op *op,
7866                 enum rte_crypto_aead_algorithm algo,
7867                 enum rte_crypto_aead_operation aead_op,
7868                 uint8_t *key, const uint8_t key_len,
7869                 const uint8_t aad_len, const uint8_t auth_len,
7870                 uint8_t iv_len)
7871 {
7872         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7873                         "failed to allocate space for crypto transform");
7874
7875         struct rte_crypto_sym_op *sym_op = op->sym;
7876
7877         /* Setup AEAD Parameters */
7878         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7879         sym_op->xform->next = NULL;
7880         sym_op->xform->aead.algo = algo;
7881         sym_op->xform->aead.op = aead_op;
7882         sym_op->xform->aead.key.data = key;
7883         sym_op->xform->aead.key.length = key_len;
7884         sym_op->xform->aead.iv.offset = IV_OFFSET;
7885         sym_op->xform->aead.iv.length = iv_len;
7886         sym_op->xform->aead.digest_length = auth_len;
7887         sym_op->xform->aead.aad_length = aad_len;
7888
7889         debug_hexdump(stdout, "key:", key, key_len);
7890
7891         return 0;
7892 }
7893
7894 static int
7895 create_aead_operation(enum rte_crypto_aead_operation op,
7896                 const struct aead_test_data *tdata)
7897 {
7898         struct crypto_testsuite_params *ts_params = &testsuite_params;
7899         struct crypto_unittest_params *ut_params = &unittest_params;
7900
7901         uint8_t *plaintext, *ciphertext;
7902         unsigned int aad_pad_len, plaintext_pad_len;
7903
7904         /* Generate Crypto op data structure */
7905         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7906                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7907         TEST_ASSERT_NOT_NULL(ut_params->op,
7908                         "Failed to allocate symmetric crypto operation struct");
7909
7910         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7911
7912         /* Append aad data */
7913         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7914                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7915                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7916                                 aad_pad_len);
7917                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7918                                 "no room to append aad");
7919
7920                 sym_op->aead.aad.phys_addr =
7921                                 rte_pktmbuf_iova(ut_params->ibuf);
7922                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
7923                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7924                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7925                         tdata->aad.len);
7926
7927                 /* Append IV at the end of the crypto operation*/
7928                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7929                                 uint8_t *, IV_OFFSET);
7930
7931                 /* Copy IV 1 byte after the IV pointer, according to the API */
7932                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7933                 debug_hexdump(stdout, "iv:", iv_ptr,
7934                         tdata->iv.len);
7935         } else {
7936                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7937                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7938                                 aad_pad_len);
7939                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7940                                 "no room to append aad");
7941
7942                 sym_op->aead.aad.phys_addr =
7943                                 rte_pktmbuf_iova(ut_params->ibuf);
7944                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7945                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7946                         tdata->aad.len);
7947
7948                 /* Append IV at the end of the crypto operation*/
7949                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7950                                 uint8_t *, IV_OFFSET);
7951
7952                 if (tdata->iv.len == 0) {
7953                         rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7954                         debug_hexdump(stdout, "iv:", iv_ptr,
7955                                 AES_GCM_J0_LENGTH);
7956                 } else {
7957                         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7958                         debug_hexdump(stdout, "iv:", iv_ptr,
7959                                 tdata->iv.len);
7960                 }
7961         }
7962
7963         /* Append plaintext/ciphertext */
7964         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7965                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7966                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7967                                 plaintext_pad_len);
7968                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7969
7970                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7971                 debug_hexdump(stdout, "plaintext:", plaintext,
7972                                 tdata->plaintext.len);
7973
7974                 if (ut_params->obuf) {
7975                         ciphertext = (uint8_t *)rte_pktmbuf_append(
7976                                         ut_params->obuf,
7977                                         plaintext_pad_len + aad_pad_len);
7978                         TEST_ASSERT_NOT_NULL(ciphertext,
7979                                         "no room to append ciphertext");
7980
7981                         memset(ciphertext + aad_pad_len, 0,
7982                                         tdata->ciphertext.len);
7983                 }
7984         } else {
7985                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7986                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7987                                 plaintext_pad_len);
7988                 TEST_ASSERT_NOT_NULL(ciphertext,
7989                                 "no room to append ciphertext");
7990
7991                 memcpy(ciphertext, tdata->ciphertext.data,
7992                                 tdata->ciphertext.len);
7993                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7994                                 tdata->ciphertext.len);
7995
7996                 if (ut_params->obuf) {
7997                         plaintext = (uint8_t *)rte_pktmbuf_append(
7998                                         ut_params->obuf,
7999                                         plaintext_pad_len + aad_pad_len);
8000                         TEST_ASSERT_NOT_NULL(plaintext,
8001                                         "no room to append plaintext");
8002
8003                         memset(plaintext + aad_pad_len, 0,
8004                                         tdata->plaintext.len);
8005                 }
8006         }
8007
8008         /* Append digest data */
8009         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8010                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8011                                 ut_params->obuf ? ut_params->obuf :
8012                                                 ut_params->ibuf,
8013                                                 tdata->auth_tag.len);
8014                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8015                                 "no room to append digest");
8016                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
8017                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8018                                 ut_params->obuf ? ut_params->obuf :
8019                                                 ut_params->ibuf,
8020                                                 plaintext_pad_len +
8021                                                 aad_pad_len);
8022         } else {
8023                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8024                                 ut_params->ibuf, tdata->auth_tag.len);
8025                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8026                                 "no room to append digest");
8027                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8028                                 ut_params->ibuf,
8029                                 plaintext_pad_len + aad_pad_len);
8030
8031                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8032                         tdata->auth_tag.len);
8033                 debug_hexdump(stdout, "digest:",
8034                         sym_op->aead.digest.data,
8035                         tdata->auth_tag.len);
8036         }
8037
8038         sym_op->aead.data.length = tdata->plaintext.len;
8039         sym_op->aead.data.offset = aad_pad_len;
8040
8041         return 0;
8042 }
8043
8044 static int
8045 test_authenticated_encryption(const struct aead_test_data *tdata)
8046 {
8047         struct crypto_testsuite_params *ts_params = &testsuite_params;
8048         struct crypto_unittest_params *ut_params = &unittest_params;
8049
8050         int retval;
8051         uint8_t *ciphertext, *auth_tag;
8052         uint16_t plaintext_pad_len;
8053         uint32_t i;
8054         struct rte_cryptodev_info dev_info;
8055
8056         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8057         uint64_t feat_flags = dev_info.feature_flags;
8058
8059         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8060                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8061                 printf("Device doesn't support RAW data-path APIs.\n");
8062                 return TEST_SKIPPED;
8063         }
8064
8065         /* Verify the capabilities */
8066         struct rte_cryptodev_sym_capability_idx cap_idx;
8067         const struct rte_cryptodev_symmetric_capability *capability;
8068         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8069         cap_idx.algo.aead = tdata->algo;
8070         capability = rte_cryptodev_sym_capability_get(
8071                         ts_params->valid_devs[0], &cap_idx);
8072         if (capability == NULL)
8073                 return TEST_SKIPPED;
8074         if (rte_cryptodev_sym_capability_check_aead(
8075                         capability, tdata->key.len, tdata->auth_tag.len,
8076                         tdata->aad.len, tdata->iv.len))
8077                 return TEST_SKIPPED;
8078
8079         /* Create AEAD session */
8080         retval = create_aead_session(ts_params->valid_devs[0],
8081                         tdata->algo,
8082                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8083                         tdata->key.data, tdata->key.len,
8084                         tdata->aad.len, tdata->auth_tag.len,
8085                         tdata->iv.len);
8086         if (retval < 0)
8087                 return retval;
8088
8089         if (tdata->aad.len > MBUF_SIZE) {
8090                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8091                 /* Populate full size of add data */
8092                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8093                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8094         } else
8095                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8096
8097         /* clear mbuf payload */
8098         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8099                         rte_pktmbuf_tailroom(ut_params->ibuf));
8100
8101         /* Create AEAD operation */
8102         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8103         if (retval < 0)
8104                 return retval;
8105
8106         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8107
8108         ut_params->op->sym->m_src = ut_params->ibuf;
8109
8110         /* Process crypto operation */
8111         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8112                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8113         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8114                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8115                                 ut_params->op, 0, 0, 0, 0);
8116         else
8117                 TEST_ASSERT_NOT_NULL(
8118                         process_crypto_request(ts_params->valid_devs[0],
8119                         ut_params->op), "failed to process sym crypto op");
8120
8121         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8122                         "crypto op processing failed");
8123
8124         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8125
8126         if (ut_params->op->sym->m_dst) {
8127                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8128                                 uint8_t *);
8129                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8130                                 uint8_t *, plaintext_pad_len);
8131         } else {
8132                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8133                                 uint8_t *,
8134                                 ut_params->op->sym->cipher.data.offset);
8135                 auth_tag = ciphertext + plaintext_pad_len;
8136         }
8137
8138         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8139         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8140
8141         /* Validate obuf */
8142         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8143                         ciphertext,
8144                         tdata->ciphertext.data,
8145                         tdata->ciphertext.len,
8146                         "Ciphertext data not as expected");
8147
8148         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8149                         auth_tag,
8150                         tdata->auth_tag.data,
8151                         tdata->auth_tag.len,
8152                         "Generated auth tag not as expected");
8153
8154         return 0;
8155
8156 }
8157
8158 #ifdef RTE_LIB_SECURITY
8159 static int
8160 security_proto_supported(enum rte_security_session_action_type action,
8161         enum rte_security_session_protocol proto)
8162 {
8163         struct crypto_testsuite_params *ts_params = &testsuite_params;
8164
8165         const struct rte_security_capability *capabilities;
8166         const struct rte_security_capability *capability;
8167         uint16_t i = 0;
8168
8169         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8170                                 rte_cryptodev_get_sec_ctx(
8171                                 ts_params->valid_devs[0]);
8172
8173
8174         capabilities = rte_security_capabilities_get(ctx);
8175
8176         if (capabilities == NULL)
8177                 return -ENOTSUP;
8178
8179         while ((capability = &capabilities[i++])->action !=
8180                         RTE_SECURITY_ACTION_TYPE_NONE) {
8181                 if (capability->action == action &&
8182                                 capability->protocol == proto)
8183                         return 0;
8184         }
8185
8186         return -ENOTSUP;
8187 }
8188
8189 /* Basic algorithm run function for async inplace mode.
8190  * Creates a session from input parameters and runs one operation
8191  * on input_vec. Checks the output of the crypto operation against
8192  * output_vec.
8193  */
8194 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8195                            enum rte_crypto_auth_operation opa,
8196                            const uint8_t *input_vec, unsigned int input_vec_len,
8197                            const uint8_t *output_vec,
8198                            unsigned int output_vec_len,
8199                            enum rte_crypto_cipher_algorithm cipher_alg,
8200                            const uint8_t *cipher_key, uint32_t cipher_key_len,
8201                            enum rte_crypto_auth_algorithm auth_alg,
8202                            const uint8_t *auth_key, uint32_t auth_key_len,
8203                            uint8_t bearer, enum rte_security_pdcp_domain domain,
8204                            uint8_t packet_direction, uint8_t sn_size,
8205                            uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8206 {
8207         struct crypto_testsuite_params *ts_params = &testsuite_params;
8208         struct crypto_unittest_params *ut_params = &unittest_params;
8209         uint8_t *plaintext;
8210         int ret = TEST_SUCCESS;
8211         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8212                                 rte_cryptodev_get_sec_ctx(
8213                                 ts_params->valid_devs[0]);
8214
8215         /* Verify the capabilities */
8216         struct rte_security_capability_idx sec_cap_idx;
8217
8218         sec_cap_idx.action = ut_params->type;
8219         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8220         sec_cap_idx.pdcp.domain = domain;
8221         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8222                 return TEST_SKIPPED;
8223
8224         /* Generate test mbuf data */
8225         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8226
8227         /* clear mbuf payload */
8228         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8229                         rte_pktmbuf_tailroom(ut_params->ibuf));
8230
8231         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8232                                                   input_vec_len);
8233         memcpy(plaintext, input_vec, input_vec_len);
8234
8235         /* Out of place support */
8236         if (oop) {
8237                 /*
8238                  * For out-op-place we need to alloc another mbuf
8239                  */
8240                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8241                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8242         }
8243
8244         /* Setup Cipher Parameters */
8245         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8246         ut_params->cipher_xform.cipher.algo = cipher_alg;
8247         ut_params->cipher_xform.cipher.op = opc;
8248         ut_params->cipher_xform.cipher.key.data = cipher_key;
8249         ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8250         ut_params->cipher_xform.cipher.iv.length =
8251                                 packet_direction ? 4 : 0;
8252         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8253
8254         /* Setup HMAC Parameters if ICV header is required */
8255         if (auth_alg != 0) {
8256                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8257                 ut_params->auth_xform.next = NULL;
8258                 ut_params->auth_xform.auth.algo = auth_alg;
8259                 ut_params->auth_xform.auth.op = opa;
8260                 ut_params->auth_xform.auth.key.data = auth_key;
8261                 ut_params->auth_xform.auth.key.length = auth_key_len;
8262
8263                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8264         } else {
8265                 ut_params->cipher_xform.next = NULL;
8266         }
8267
8268         struct rte_security_session_conf sess_conf = {
8269                 .action_type = ut_params->type,
8270                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8271                 {.pdcp = {
8272                         .bearer = bearer,
8273                         .domain = domain,
8274                         .pkt_dir = packet_direction,
8275                         .sn_size = sn_size,
8276                         .hfn = packet_direction ? 0 : hfn,
8277                         /**
8278                          * hfn can be set as pdcp_test_hfn[i]
8279                          * if hfn_ovrd is not set. Here, PDCP
8280                          * packet direction is just used to
8281                          * run half of the cases with session
8282                          * HFN and other half with per packet
8283                          * HFN.
8284                          */
8285                         .hfn_threshold = hfn_threshold,
8286                         .hfn_ovrd = packet_direction ? 1 : 0,
8287                         .sdap_enabled = sdap,
8288                 } },
8289                 .crypto_xform = &ut_params->cipher_xform
8290         };
8291
8292         /* Create security session */
8293         ut_params->sec_session = rte_security_session_create(ctx,
8294                                 &sess_conf, ts_params->session_mpool,
8295                                 ts_params->session_priv_mpool);
8296
8297         if (!ut_params->sec_session) {
8298                 printf("TestCase %s()-%d line %d failed %s: ",
8299                         __func__, i, __LINE__, "Failed to allocate session");
8300                 ret = TEST_FAILED;
8301                 goto on_err;
8302         }
8303
8304         /* Generate crypto op data structure */
8305         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8306                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8307         if (!ut_params->op) {
8308                 printf("TestCase %s()-%d line %d failed %s: ",
8309                         __func__, i, __LINE__,
8310                         "Failed to allocate symmetric crypto operation struct");
8311                 ret = TEST_FAILED;
8312                 goto on_err;
8313         }
8314
8315         uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8316                                         uint32_t *, IV_OFFSET);
8317         *per_pkt_hfn = packet_direction ? hfn : 0;
8318
8319         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8320
8321         /* set crypto operation source mbuf */
8322         ut_params->op->sym->m_src = ut_params->ibuf;
8323         if (oop)
8324                 ut_params->op->sym->m_dst = ut_params->obuf;
8325
8326         /* Process crypto operation */
8327         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8328                 == NULL) {
8329                 printf("TestCase %s()-%d line %d failed %s: ",
8330                         __func__, i, __LINE__,
8331                         "failed to process sym crypto op");
8332                 ret = TEST_FAILED;
8333                 goto on_err;
8334         }
8335
8336         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8337                 printf("TestCase %s()-%d line %d failed %s: ",
8338                         __func__, i, __LINE__, "crypto op processing failed");
8339                 ret = TEST_FAILED;
8340                 goto on_err;
8341         }
8342
8343         /* Validate obuf */
8344         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8345                         uint8_t *);
8346         if (oop) {
8347                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8348                                 uint8_t *);
8349         }
8350
8351         if (memcmp(ciphertext, output_vec, output_vec_len)) {
8352                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8353                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8354                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8355                 ret = TEST_FAILED;
8356                 goto on_err;
8357         }
8358
8359 on_err:
8360         rte_crypto_op_free(ut_params->op);
8361         ut_params->op = NULL;
8362
8363         if (ut_params->sec_session)
8364                 rte_security_session_destroy(ctx, ut_params->sec_session);
8365         ut_params->sec_session = NULL;
8366
8367         rte_pktmbuf_free(ut_params->ibuf);
8368         ut_params->ibuf = NULL;
8369         if (oop) {
8370                 rte_pktmbuf_free(ut_params->obuf);
8371                 ut_params->obuf = NULL;
8372         }
8373
8374         return ret;
8375 }
8376
8377 static int
8378 test_pdcp_proto_SGL(int i, int oop,
8379         enum rte_crypto_cipher_operation opc,
8380         enum rte_crypto_auth_operation opa,
8381         uint8_t *input_vec,
8382         unsigned int input_vec_len,
8383         uint8_t *output_vec,
8384         unsigned int output_vec_len,
8385         uint32_t fragsz,
8386         uint32_t fragsz_oop)
8387 {
8388         struct crypto_testsuite_params *ts_params = &testsuite_params;
8389         struct crypto_unittest_params *ut_params = &unittest_params;
8390         uint8_t *plaintext;
8391         struct rte_mbuf *buf, *buf_oop = NULL;
8392         int ret = TEST_SUCCESS;
8393         int to_trn = 0;
8394         int to_trn_tbl[16];
8395         int segs = 1;
8396         unsigned int trn_data = 0;
8397         struct rte_cryptodev_info dev_info;
8398         uint64_t feat_flags;
8399         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8400                                 rte_cryptodev_get_sec_ctx(
8401                                 ts_params->valid_devs[0]);
8402         struct rte_mbuf *temp_mbuf;
8403
8404         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8405         feat_flags = dev_info.feature_flags;
8406
8407         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8408                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8409                 printf("Device does not support RAW data-path APIs.\n");
8410                 return -ENOTSUP;
8411         }
8412         /* Verify the capabilities */
8413         struct rte_security_capability_idx sec_cap_idx;
8414
8415         sec_cap_idx.action = ut_params->type;
8416         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8417         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8418         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8419                 return TEST_SKIPPED;
8420
8421         if (fragsz > input_vec_len)
8422                 fragsz = input_vec_len;
8423
8424         uint16_t plaintext_len = fragsz;
8425         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8426
8427         if (fragsz_oop > output_vec_len)
8428                 frag_size_oop = output_vec_len;
8429
8430         int ecx = 0;
8431         if (input_vec_len % fragsz != 0) {
8432                 if (input_vec_len / fragsz + 1 > 16)
8433                         return 1;
8434         } else if (input_vec_len / fragsz > 16)
8435                 return 1;
8436
8437         /* Out of place support */
8438         if (oop) {
8439                 /*
8440                  * For out-op-place we need to alloc another mbuf
8441                  */
8442                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8443                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8444                 buf_oop = ut_params->obuf;
8445         }
8446
8447         /* Generate test mbuf data */
8448         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8449
8450         /* clear mbuf payload */
8451         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8452                         rte_pktmbuf_tailroom(ut_params->ibuf));
8453
8454         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8455                                                   plaintext_len);
8456         memcpy(plaintext, input_vec, plaintext_len);
8457         trn_data += plaintext_len;
8458
8459         buf = ut_params->ibuf;
8460
8461         /*
8462          * Loop until no more fragments
8463          */
8464
8465         while (trn_data < input_vec_len) {
8466                 ++segs;
8467                 to_trn = (input_vec_len - trn_data < fragsz) ?
8468                                 (input_vec_len - trn_data) : fragsz;
8469
8470                 to_trn_tbl[ecx++] = to_trn;
8471
8472                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8473                 buf = buf->next;
8474
8475                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8476                                 rte_pktmbuf_tailroom(buf));
8477
8478                 /* OOP */
8479                 if (oop && !fragsz_oop) {
8480                         buf_oop->next =
8481                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8482                         buf_oop = buf_oop->next;
8483                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8484                                         0, rte_pktmbuf_tailroom(buf_oop));
8485                         rte_pktmbuf_append(buf_oop, to_trn);
8486                 }
8487
8488                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8489                                 to_trn);
8490
8491                 memcpy(plaintext, input_vec + trn_data, to_trn);
8492                 trn_data += to_trn;
8493         }
8494
8495         ut_params->ibuf->nb_segs = segs;
8496
8497         segs = 1;
8498         if (fragsz_oop && oop) {
8499                 to_trn = 0;
8500                 ecx = 0;
8501
8502                 trn_data = frag_size_oop;
8503                 while (trn_data < output_vec_len) {
8504                         ++segs;
8505                         to_trn =
8506                                 (output_vec_len - trn_data <
8507                                                 frag_size_oop) ?
8508                                 (output_vec_len - trn_data) :
8509                                                 frag_size_oop;
8510
8511                         to_trn_tbl[ecx++] = to_trn;
8512
8513                         buf_oop->next =
8514                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
8515                         buf_oop = buf_oop->next;
8516                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8517                                         0, rte_pktmbuf_tailroom(buf_oop));
8518                         rte_pktmbuf_append(buf_oop, to_trn);
8519
8520                         trn_data += to_trn;
8521                 }
8522                 ut_params->obuf->nb_segs = segs;
8523         }
8524
8525         /* Setup Cipher Parameters */
8526         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8527         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8528         ut_params->cipher_xform.cipher.op = opc;
8529         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8530         ut_params->cipher_xform.cipher.key.length =
8531                                         pdcp_test_params[i].cipher_key_len;
8532         ut_params->cipher_xform.cipher.iv.length = 0;
8533
8534         /* Setup HMAC Parameters if ICV header is required */
8535         if (pdcp_test_params[i].auth_alg != 0) {
8536                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8537                 ut_params->auth_xform.next = NULL;
8538                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8539                 ut_params->auth_xform.auth.op = opa;
8540                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8541                 ut_params->auth_xform.auth.key.length =
8542                                         pdcp_test_params[i].auth_key_len;
8543
8544                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8545         } else {
8546                 ut_params->cipher_xform.next = NULL;
8547         }
8548
8549         struct rte_security_session_conf sess_conf = {
8550                 .action_type = ut_params->type,
8551                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8552                 {.pdcp = {
8553                         .bearer = pdcp_test_bearer[i],
8554                         .domain = pdcp_test_params[i].domain,
8555                         .pkt_dir = pdcp_test_packet_direction[i],
8556                         .sn_size = pdcp_test_data_sn_size[i],
8557                         .hfn = pdcp_test_hfn[i],
8558                         .hfn_threshold = pdcp_test_hfn_threshold[i],
8559                         .hfn_ovrd = 0,
8560                 } },
8561                 .crypto_xform = &ut_params->cipher_xform
8562         };
8563
8564         /* Create security session */
8565         ut_params->sec_session = rte_security_session_create(ctx,
8566                                 &sess_conf, ts_params->session_mpool,
8567                                 ts_params->session_priv_mpool);
8568
8569         if (!ut_params->sec_session) {
8570                 printf("TestCase %s()-%d line %d failed %s: ",
8571                         __func__, i, __LINE__, "Failed to allocate session");
8572                 ret = TEST_FAILED;
8573                 goto on_err;
8574         }
8575
8576         /* Generate crypto op data structure */
8577         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8578                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8579         if (!ut_params->op) {
8580                 printf("TestCase %s()-%d line %d failed %s: ",
8581                         __func__, i, __LINE__,
8582                         "Failed to allocate symmetric crypto operation struct");
8583                 ret = TEST_FAILED;
8584                 goto on_err;
8585         }
8586
8587         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8588
8589         /* set crypto operation source mbuf */
8590         ut_params->op->sym->m_src = ut_params->ibuf;
8591         if (oop)
8592                 ut_params->op->sym->m_dst = ut_params->obuf;
8593
8594         /* Process crypto operation */
8595         temp_mbuf = ut_params->op->sym->m_src;
8596         if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
8597                 /* filling lengths */
8598                 while (temp_mbuf) {
8599                         ut_params->op->sym->cipher.data.length
8600                                 += temp_mbuf->pkt_len;
8601                         ut_params->op->sym->auth.data.length
8602                                 += temp_mbuf->pkt_len;
8603                         temp_mbuf = temp_mbuf->next;
8604                 }
8605                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8606                         ut_params->op, 1, 1, 0, 0);
8607         } else {
8608                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8609                                                         ut_params->op);
8610         }
8611         if (ut_params->op == NULL) {
8612                 printf("TestCase %s()-%d line %d failed %s: ",
8613                         __func__, i, __LINE__,
8614                         "failed to process sym crypto op");
8615                 ret = TEST_FAILED;
8616                 goto on_err;
8617         }
8618
8619         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8620                 printf("TestCase %s()-%d line %d failed %s: ",
8621                         __func__, i, __LINE__, "crypto op processing failed");
8622                 ret = TEST_FAILED;
8623                 goto on_err;
8624         }
8625
8626         /* Validate obuf */
8627         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8628                         uint8_t *);
8629         if (oop) {
8630                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8631                                 uint8_t *);
8632         }
8633         if (fragsz_oop)
8634                 fragsz = frag_size_oop;
8635         if (memcmp(ciphertext, output_vec, fragsz)) {
8636                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8637                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8638                 rte_hexdump(stdout, "reference", output_vec, fragsz);
8639                 ret = TEST_FAILED;
8640                 goto on_err;
8641         }
8642
8643         buf = ut_params->op->sym->m_src->next;
8644         if (oop)
8645                 buf = ut_params->op->sym->m_dst->next;
8646
8647         unsigned int off = fragsz;
8648
8649         ecx = 0;
8650         while (buf) {
8651                 ciphertext = rte_pktmbuf_mtod(buf,
8652                                 uint8_t *);
8653                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8654                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8655                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8656                         rte_hexdump(stdout, "reference", output_vec + off,
8657                                         to_trn_tbl[ecx]);
8658                         ret = TEST_FAILED;
8659                         goto on_err;
8660                 }
8661                 off += to_trn_tbl[ecx++];
8662                 buf = buf->next;
8663         }
8664 on_err:
8665         rte_crypto_op_free(ut_params->op);
8666         ut_params->op = NULL;
8667
8668         if (ut_params->sec_session)
8669                 rte_security_session_destroy(ctx, ut_params->sec_session);
8670         ut_params->sec_session = NULL;
8671
8672         rte_pktmbuf_free(ut_params->ibuf);
8673         ut_params->ibuf = NULL;
8674         if (oop) {
8675                 rte_pktmbuf_free(ut_params->obuf);
8676                 ut_params->obuf = NULL;
8677         }
8678
8679         return ret;
8680 }
8681
8682 int
8683 test_pdcp_proto_cplane_encap(int i)
8684 {
8685         return test_pdcp_proto(
8686                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8687                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8688                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8689                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8690                 pdcp_test_params[i].cipher_key_len,
8691                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8692                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8693                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8694                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8695                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8696 }
8697
8698 int
8699 test_pdcp_proto_uplane_encap(int i)
8700 {
8701         return test_pdcp_proto(
8702                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8703                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8704                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8705                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8706                 pdcp_test_params[i].cipher_key_len,
8707                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8708                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8709                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8710                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8711                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8712 }
8713
8714 int
8715 test_pdcp_proto_uplane_encap_with_int(int i)
8716 {
8717         return test_pdcp_proto(
8718                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8719                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8720                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8721                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8722                 pdcp_test_params[i].cipher_key_len,
8723                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8724                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8725                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8726                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8727                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8728 }
8729
8730 int
8731 test_pdcp_proto_cplane_decap(int i)
8732 {
8733         return test_pdcp_proto(
8734                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8735                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8736                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8737                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8738                 pdcp_test_params[i].cipher_key_len,
8739                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8740                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8741                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8742                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8743                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8744 }
8745
8746 int
8747 test_pdcp_proto_uplane_decap(int i)
8748 {
8749         return test_pdcp_proto(
8750                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8751                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8752                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8753                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8754                 pdcp_test_params[i].cipher_key_len,
8755                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8756                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8757                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8758                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8759                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8760 }
8761
8762 int
8763 test_pdcp_proto_uplane_decap_with_int(int i)
8764 {
8765         return test_pdcp_proto(
8766                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8767                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8768                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8769                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8770                 pdcp_test_params[i].cipher_key_len,
8771                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8772                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8773                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8774                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8775                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8776 }
8777
8778 static int
8779 test_PDCP_PROTO_SGL_in_place_32B(void)
8780 {
8781         /* i can be used for running any PDCP case
8782          * In this case it is uplane 12-bit AES-SNOW DL encap
8783          */
8784         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8785         return test_pdcp_proto_SGL(i, IN_PLACE,
8786                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8787                         RTE_CRYPTO_AUTH_OP_GENERATE,
8788                         pdcp_test_data_in[i],
8789                         pdcp_test_data_in_len[i],
8790                         pdcp_test_data_out[i],
8791                         pdcp_test_data_in_len[i]+4,
8792                         32, 0);
8793 }
8794 static int
8795 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8796 {
8797         /* i can be used for running any PDCP case
8798          * In this case it is uplane 18-bit NULL-NULL DL encap
8799          */
8800         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8801         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8802                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8803                         RTE_CRYPTO_AUTH_OP_GENERATE,
8804                         pdcp_test_data_in[i],
8805                         pdcp_test_data_in_len[i],
8806                         pdcp_test_data_out[i],
8807                         pdcp_test_data_in_len[i]+4,
8808                         32, 128);
8809 }
8810 static int
8811 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8812 {
8813         /* i can be used for running any PDCP case
8814          * In this case it is uplane 18-bit AES DL encap
8815          */
8816         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8817                         + DOWNLINK;
8818         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8819                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8820                         RTE_CRYPTO_AUTH_OP_GENERATE,
8821                         pdcp_test_data_in[i],
8822                         pdcp_test_data_in_len[i],
8823                         pdcp_test_data_out[i],
8824                         pdcp_test_data_in_len[i],
8825                         32, 40);
8826 }
8827 static int
8828 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8829 {
8830         /* i can be used for running any PDCP case
8831          * In this case it is cplane 12-bit AES-ZUC DL encap
8832          */
8833         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8834         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8835                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8836                         RTE_CRYPTO_AUTH_OP_GENERATE,
8837                         pdcp_test_data_in[i],
8838                         pdcp_test_data_in_len[i],
8839                         pdcp_test_data_out[i],
8840                         pdcp_test_data_in_len[i]+4,
8841                         128, 32);
8842 }
8843
8844 static int
8845 test_PDCP_SDAP_PROTO_encap_all(void)
8846 {
8847         int i = 0, size = 0;
8848         int err, all_err = TEST_SUCCESS;
8849         const struct pdcp_sdap_test *cur_test;
8850
8851         size = RTE_DIM(list_pdcp_sdap_tests);
8852
8853         for (i = 0; i < size; i++) {
8854                 cur_test = &list_pdcp_sdap_tests[i];
8855                 err = test_pdcp_proto(
8856                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8857                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8858                         cur_test->in_len, cur_test->data_out,
8859                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8860                         cur_test->param.cipher_alg, cur_test->cipher_key,
8861                         cur_test->param.cipher_key_len,
8862                         cur_test->param.auth_alg,
8863                         cur_test->auth_key, cur_test->param.auth_key_len,
8864                         cur_test->bearer, cur_test->param.domain,
8865                         cur_test->packet_direction, cur_test->sn_size,
8866                         cur_test->hfn,
8867                         cur_test->hfn_threshold, SDAP_ENABLED);
8868                 if (err) {
8869                         printf("\t%d) %s: Encapsulation failed\n",
8870                                         cur_test->test_idx,
8871                                         cur_test->param.name);
8872                         err = TEST_FAILED;
8873                 } else {
8874                         printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8875                                         cur_test->param.name);
8876                         err = TEST_SUCCESS;
8877                 }
8878                 all_err += err;
8879         }
8880
8881         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8882
8883         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8884 }
8885
8886 static int
8887 test_PDCP_PROTO_short_mac(void)
8888 {
8889         int i = 0, size = 0;
8890         int err, all_err = TEST_SUCCESS;
8891         const struct pdcp_short_mac_test *cur_test;
8892
8893         size = RTE_DIM(list_pdcp_smac_tests);
8894
8895         for (i = 0; i < size; i++) {
8896                 cur_test = &list_pdcp_smac_tests[i];
8897                 err = test_pdcp_proto(
8898                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8899                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8900                         cur_test->in_len, cur_test->data_out,
8901                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8902                         RTE_CRYPTO_CIPHER_NULL, NULL,
8903                         0, cur_test->param.auth_alg,
8904                         cur_test->auth_key, cur_test->param.auth_key_len,
8905                         0, cur_test->param.domain, 0, 0,
8906                         0, 0, 0);
8907                 if (err) {
8908                         printf("\t%d) %s: Short MAC test failed\n",
8909                                         cur_test->test_idx,
8910                                         cur_test->param.name);
8911                         err = TEST_FAILED;
8912                 } else {
8913                         printf("\t%d) %s: Short MAC test PASS\n",
8914                                         cur_test->test_idx,
8915                                         cur_test->param.name);
8916                         rte_hexdump(stdout, "MAC I",
8917                                     cur_test->data_out + cur_test->in_len + 2,
8918                                     2);
8919                         err = TEST_SUCCESS;
8920                 }
8921                 all_err += err;
8922         }
8923
8924         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8925
8926         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8927
8928 }
8929
8930 static int
8931 test_PDCP_SDAP_PROTO_decap_all(void)
8932 {
8933         int i = 0, size = 0;
8934         int err, all_err = TEST_SUCCESS;
8935         const struct pdcp_sdap_test *cur_test;
8936
8937         size = RTE_DIM(list_pdcp_sdap_tests);
8938
8939         for (i = 0; i < size; i++) {
8940                 cur_test = &list_pdcp_sdap_tests[i];
8941                 err = test_pdcp_proto(
8942                         i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8943                         RTE_CRYPTO_AUTH_OP_VERIFY,
8944                         cur_test->data_out,
8945                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8946                         cur_test->data_in, cur_test->in_len,
8947                         cur_test->param.cipher_alg,
8948                         cur_test->cipher_key, cur_test->param.cipher_key_len,
8949                         cur_test->param.auth_alg, cur_test->auth_key,
8950                         cur_test->param.auth_key_len, cur_test->bearer,
8951                         cur_test->param.domain, cur_test->packet_direction,
8952                         cur_test->sn_size, cur_test->hfn,
8953                         cur_test->hfn_threshold, SDAP_ENABLED);
8954                 if (err) {
8955                         printf("\t%d) %s: Decapsulation failed\n",
8956                                         cur_test->test_idx,
8957                                         cur_test->param.name);
8958                         err = TEST_FAILED;
8959                 } else {
8960                         printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8961                                         cur_test->param.name);
8962                         err = TEST_SUCCESS;
8963                 }
8964                 all_err += err;
8965         }
8966
8967         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8968
8969         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8970 }
8971
8972 static int
8973 test_ipsec_proto_process(const struct ipsec_test_data td[],
8974                          struct ipsec_test_data res_d[],
8975                          int nb_td,
8976                          bool silent,
8977                          const struct ipsec_test_flags *flags)
8978 {
8979         struct crypto_testsuite_params *ts_params = &testsuite_params;
8980         struct crypto_unittest_params *ut_params = &unittest_params;
8981         struct rte_security_capability_idx sec_cap_idx;
8982         const struct rte_security_capability *sec_cap;
8983         struct rte_security_ipsec_xform ipsec_xform;
8984         uint8_t dev_id = ts_params->valid_devs[0];
8985         enum rte_security_ipsec_sa_direction dir;
8986         struct ipsec_test_data *res_d_tmp = NULL;
8987         uint32_t src = RTE_IPV4(192, 168, 1, 0);
8988         uint32_t dst = RTE_IPV4(192, 168, 1, 1);
8989         int salt_len, i, ret = TEST_SUCCESS;
8990         struct rte_security_ctx *ctx;
8991         uint8_t *input_text;
8992         uint32_t verify;
8993
8994         ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
8995         gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
8996
8997         /* Use first test data to create session */
8998
8999         /* Copy IPsec xform */
9000         memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
9001
9002         dir = ipsec_xform.direction;
9003         verify = flags->tunnel_hdr_verify;
9004
9005         if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
9006                 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
9007                         src += 1;
9008                 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
9009                         dst += 1;
9010         }
9011
9012         memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src));
9013         memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst));
9014
9015         ctx = rte_cryptodev_get_sec_ctx(dev_id);
9016
9017         sec_cap_idx.action = ut_params->type;
9018         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
9019         sec_cap_idx.ipsec.proto = ipsec_xform.proto;
9020         sec_cap_idx.ipsec.mode = ipsec_xform.mode;
9021         sec_cap_idx.ipsec.direction = ipsec_xform.direction;
9022
9023         if (flags->udp_encap)
9024                 ipsec_xform.options.udp_encap = 1;
9025
9026         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9027         if (sec_cap == NULL)
9028                 return TEST_SKIPPED;
9029
9030         /* Copy cipher session parameters */
9031         if (td[0].aead) {
9032                 memcpy(&ut_params->aead_xform, &td[0].xform.aead,
9033                        sizeof(ut_params->aead_xform));
9034                 ut_params->aead_xform.aead.key.data = td[0].key.data;
9035                 ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
9036
9037                 /* Verify crypto capabilities */
9038                 if (test_ipsec_crypto_caps_aead_verify(
9039                                 sec_cap,
9040                                 &ut_params->aead_xform) != 0) {
9041                         if (!silent)
9042                                 RTE_LOG(INFO, USER1,
9043                                         "Crypto capabilities not supported\n");
9044                         return TEST_SKIPPED;
9045                 }
9046         } else {
9047                 /* Only AEAD supported now */
9048                 return TEST_SKIPPED;
9049         }
9050
9051         if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
9052                 return TEST_SKIPPED;
9053
9054         salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
9055         memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
9056
9057         struct rte_security_session_conf sess_conf = {
9058                 .action_type = ut_params->type,
9059                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
9060                 .ipsec = ipsec_xform,
9061                 .crypto_xform = &ut_params->aead_xform,
9062         };
9063
9064         /* Create security session */
9065         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9066                                         ts_params->session_mpool,
9067                                         ts_params->session_priv_mpool);
9068
9069         if (ut_params->sec_session == NULL)
9070                 return TEST_SKIPPED;
9071
9072         for (i = 0; i < nb_td; i++) {
9073                 /* Setup source mbuf payload */
9074                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9075                 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9076                                 rte_pktmbuf_tailroom(ut_params->ibuf));
9077
9078                 input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9079                                 td[i].input_text.len);
9080
9081                 memcpy(input_text, td[i].input_text.data,
9082                        td[i].input_text.len);
9083
9084                 /* Generate crypto op data structure */
9085                 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9086                                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9087                 if (!ut_params->op) {
9088                         printf("TestCase %s line %d: %s\n",
9089                                 __func__, __LINE__,
9090                                 "failed to allocate crypto op");
9091                         ret = TEST_FAILED;
9092                         goto crypto_op_free;
9093                 }
9094
9095                 /* Attach session to operation */
9096                 rte_security_attach_session(ut_params->op,
9097                                             ut_params->sec_session);
9098
9099                 /* Set crypto operation mbufs */
9100                 ut_params->op->sym->m_src = ut_params->ibuf;
9101                 ut_params->op->sym->m_dst = NULL;
9102
9103                 /* Copy IV in crypto operation when IV generation is disabled */
9104                 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
9105                     ipsec_xform.options.iv_gen_disable == 1) {
9106                         uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
9107                                                                 uint8_t *,
9108                                                                 IV_OFFSET);
9109                         int len;
9110
9111                         if (td[i].aead)
9112                                 len = td[i].xform.aead.aead.iv.length;
9113                         else
9114                                 len = td[i].xform.chain.cipher.cipher.iv.length;
9115
9116                         memcpy(iv, td[i].iv.data, len);
9117                 }
9118
9119                 /* Process crypto operation */
9120                 process_crypto_request(dev_id, ut_params->op);
9121
9122                 ret = test_ipsec_status_check(ut_params->op, flags, dir, i + 1);
9123                 if (ret != TEST_SUCCESS)
9124                         goto crypto_op_free;
9125
9126                 if (res_d != NULL)
9127                         res_d_tmp = &res_d[i];
9128
9129                 ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
9130                                               res_d_tmp, silent, flags);
9131                 if (ret != TEST_SUCCESS)
9132                         goto crypto_op_free;
9133
9134                 rte_crypto_op_free(ut_params->op);
9135                 ut_params->op = NULL;
9136
9137                 rte_pktmbuf_free(ut_params->ibuf);
9138                 ut_params->ibuf = NULL;
9139         }
9140
9141 crypto_op_free:
9142         rte_crypto_op_free(ut_params->op);
9143         ut_params->op = NULL;
9144
9145         rte_pktmbuf_free(ut_params->ibuf);
9146         ut_params->ibuf = NULL;
9147
9148         if (ut_params->sec_session)
9149                 rte_security_session_destroy(ctx, ut_params->sec_session);
9150         ut_params->sec_session = NULL;
9151
9152         return ret;
9153 }
9154
9155 static int
9156 test_ipsec_proto_known_vec(const void *test_data)
9157 {
9158         struct ipsec_test_data td_outb;
9159         struct ipsec_test_flags flags;
9160
9161         memset(&flags, 0, sizeof(flags));
9162
9163         memcpy(&td_outb, test_data, sizeof(td_outb));
9164
9165         /* Disable IV gen to be able to test with known vectors */
9166         td_outb.ipsec_xform.options.iv_gen_disable = 1;
9167
9168         return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9169 }
9170
9171 static int
9172 test_ipsec_proto_known_vec_inb(const void *td_outb)
9173 {
9174         struct ipsec_test_flags flags;
9175         struct ipsec_test_data td_inb;
9176
9177         memset(&flags, 0, sizeof(flags));
9178
9179         test_ipsec_td_in_from_out(td_outb, &td_inb);
9180
9181         return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
9182 }
9183
9184 static int
9185 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
9186 {
9187         struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9188         struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9189         unsigned int i, nb_pkts = 1, pass_cnt = 0;
9190         int ret;
9191
9192         if (flags->iv_gen ||
9193             flags->sa_expiry_pkts_soft ||
9194             flags->sa_expiry_pkts_hard)
9195                 nb_pkts = IPSEC_TEST_PACKETS_MAX;
9196
9197         for (i = 0; i < RTE_DIM(aead_list); i++) {
9198                 test_ipsec_td_prepare(&aead_list[i],
9199                                       NULL,
9200                                       flags,
9201                                       td_outb,
9202                                       nb_pkts);
9203
9204                 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9205                                                flags);
9206                 if (ret == TEST_SKIPPED)
9207                         continue;
9208
9209                 if (ret == TEST_FAILED)
9210                         return TEST_FAILED;
9211
9212                 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9213
9214                 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9215                                                flags);
9216                 if (ret == TEST_SKIPPED)
9217                         continue;
9218
9219                 if (ret == TEST_FAILED)
9220                         return TEST_FAILED;
9221
9222                 if (flags->display_alg)
9223                         test_ipsec_display_alg(&aead_list[i], NULL);
9224
9225                 pass_cnt++;
9226         }
9227
9228         if (pass_cnt > 0)
9229                 return TEST_SUCCESS;
9230         else
9231                 return TEST_SKIPPED;
9232 }
9233
9234 static int
9235 test_ipsec_proto_display_list(const void *data __rte_unused)
9236 {
9237         struct ipsec_test_flags flags;
9238
9239         memset(&flags, 0, sizeof(flags));
9240
9241         flags.display_alg = true;
9242
9243         return test_ipsec_proto_all(&flags);
9244 }
9245
9246 static int
9247 test_ipsec_proto_iv_gen(const void *data __rte_unused)
9248 {
9249         struct ipsec_test_flags flags;
9250
9251         memset(&flags, 0, sizeof(flags));
9252
9253         flags.iv_gen = true;
9254
9255         return test_ipsec_proto_all(&flags);
9256 }
9257
9258 static int
9259 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused)
9260 {
9261         struct ipsec_test_flags flags;
9262
9263         memset(&flags, 0, sizeof(flags));
9264
9265         flags.sa_expiry_pkts_soft = true;
9266
9267         return test_ipsec_proto_all(&flags);
9268 }
9269
9270 static int
9271 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused)
9272 {
9273         struct ipsec_test_flags flags;
9274
9275         memset(&flags, 0, sizeof(flags));
9276
9277         flags.sa_expiry_pkts_hard = true;
9278
9279         return test_ipsec_proto_all(&flags);
9280 }
9281
9282 static int
9283 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused)
9284 {
9285         struct ipsec_test_flags flags;
9286
9287         memset(&flags, 0, sizeof(flags));
9288
9289         flags.icv_corrupt = true;
9290
9291         return test_ipsec_proto_all(&flags);
9292 }
9293
9294 static int
9295 test_ipsec_proto_udp_encap(const void *data __rte_unused)
9296 {
9297         struct ipsec_test_flags flags;
9298
9299         memset(&flags, 0, sizeof(flags));
9300
9301         flags.udp_encap = true;
9302
9303         return test_ipsec_proto_all(&flags);
9304 }
9305
9306 static int
9307 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
9308 {
9309         struct ipsec_test_flags flags;
9310
9311         memset(&flags, 0, sizeof(flags));
9312
9313         flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
9314
9315         return test_ipsec_proto_all(&flags);
9316 }
9317
9318 static int
9319 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
9320 {
9321         struct ipsec_test_flags flags;
9322
9323         memset(&flags, 0, sizeof(flags));
9324
9325         flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
9326
9327         return test_ipsec_proto_all(&flags);
9328 }
9329
9330 static int
9331 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused)
9332 {
9333         struct ipsec_test_flags flags;
9334
9335         memset(&flags, 0, sizeof(flags));
9336
9337         flags.udp_encap = true;
9338         flags.udp_ports_verify = true;
9339
9340         return test_ipsec_proto_all(&flags);
9341 }
9342
9343 static int
9344 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused)
9345 {
9346         struct ipsec_test_flags flags;
9347
9348         memset(&flags, 0, sizeof(flags));
9349
9350         flags.ip_csum = true;
9351
9352         return test_ipsec_proto_all(&flags);
9353 }
9354
9355 static int
9356 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused)
9357 {
9358         struct ipsec_test_flags flags;
9359
9360         memset(&flags, 0, sizeof(flags));
9361
9362         flags.l4_csum = true;
9363
9364         return test_ipsec_proto_all(&flags);
9365 }
9366
9367 static int
9368 test_PDCP_PROTO_all(void)
9369 {
9370         struct crypto_testsuite_params *ts_params = &testsuite_params;
9371         struct crypto_unittest_params *ut_params = &unittest_params;
9372         struct rte_cryptodev_info dev_info;
9373         int status;
9374
9375         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9376         uint64_t feat_flags = dev_info.feature_flags;
9377
9378         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9379                 return TEST_SKIPPED;
9380
9381         /* Set action type */
9382         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9383                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9384                 gbl_action_type;
9385
9386         if (security_proto_supported(ut_params->type,
9387                         RTE_SECURITY_PROTOCOL_PDCP) < 0)
9388                 return TEST_SKIPPED;
9389
9390         status = test_PDCP_PROTO_cplane_encap_all();
9391         status += test_PDCP_PROTO_cplane_decap_all();
9392         status += test_PDCP_PROTO_uplane_encap_all();
9393         status += test_PDCP_PROTO_uplane_decap_all();
9394         status += test_PDCP_PROTO_SGL_in_place_32B();
9395         status += test_PDCP_PROTO_SGL_oop_32B_128B();
9396         status += test_PDCP_PROTO_SGL_oop_32B_40B();
9397         status += test_PDCP_PROTO_SGL_oop_128B_32B();
9398         status += test_PDCP_SDAP_PROTO_encap_all();
9399         status += test_PDCP_SDAP_PROTO_decap_all();
9400         status += test_PDCP_PROTO_short_mac();
9401
9402         if (status)
9403                 return TEST_FAILED;
9404         else
9405                 return TEST_SUCCESS;
9406 }
9407
9408 static int
9409 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
9410 {
9411         struct crypto_testsuite_params *ts_params = &testsuite_params;
9412         struct crypto_unittest_params *ut_params = &unittest_params;
9413         uint8_t *plaintext, *ciphertext;
9414         uint8_t *iv_ptr;
9415         int32_t cipher_len, crc_len;
9416         uint32_t crc_data_len;
9417         int ret = TEST_SUCCESS;
9418
9419         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9420                                         rte_cryptodev_get_sec_ctx(
9421                                                 ts_params->valid_devs[0]);
9422
9423         /* Verify the capabilities */
9424         struct rte_security_capability_idx sec_cap_idx;
9425         const struct rte_security_capability *sec_cap;
9426         const struct rte_cryptodev_capabilities *crypto_cap;
9427         const struct rte_cryptodev_symmetric_capability *sym_cap;
9428         int j = 0;
9429
9430         sec_cap_idx.action = ut_params->type;
9431         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9432         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
9433
9434         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9435         if (sec_cap == NULL)
9436                 return TEST_SKIPPED;
9437
9438         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9439                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9440                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9441                                 crypto_cap->sym.xform_type ==
9442                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9443                                 crypto_cap->sym.cipher.algo ==
9444                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9445                         sym_cap = &crypto_cap->sym;
9446                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9447                                                 d_td->key.len,
9448                                                 d_td->iv.len) == 0)
9449                                 break;
9450                 }
9451         }
9452
9453         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9454                 return TEST_SKIPPED;
9455
9456         /* Setup source mbuf payload */
9457         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9458         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9459                         rte_pktmbuf_tailroom(ut_params->ibuf));
9460
9461         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9462                         d_td->ciphertext.len);
9463
9464         memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
9465
9466         /* Setup cipher session parameters */
9467         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9468         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9469         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
9470         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9471         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9472         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9473         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9474         ut_params->cipher_xform.next = NULL;
9475
9476         /* Setup DOCSIS session parameters */
9477         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
9478
9479         struct rte_security_session_conf sess_conf = {
9480                 .action_type = ut_params->type,
9481                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9482                 .docsis = ut_params->docsis_xform,
9483                 .crypto_xform = &ut_params->cipher_xform,
9484         };
9485
9486         /* Create security session */
9487         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9488                                         ts_params->session_mpool,
9489                                         ts_params->session_priv_mpool);
9490
9491         if (!ut_params->sec_session) {
9492                 printf("TestCase %s(%d) line %d: %s\n",
9493                         __func__, i, __LINE__, "failed to allocate session");
9494                 ret = TEST_FAILED;
9495                 goto on_err;
9496         }
9497
9498         /* Generate crypto op data structure */
9499         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9500                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9501         if (!ut_params->op) {
9502                 printf("TestCase %s(%d) line %d: %s\n",
9503                         __func__, i, __LINE__,
9504                         "failed to allocate symmetric crypto operation");
9505                 ret = TEST_FAILED;
9506                 goto on_err;
9507         }
9508
9509         /* Setup CRC operation parameters */
9510         crc_len = d_td->ciphertext.no_crc == false ?
9511                         (d_td->ciphertext.len -
9512                                 d_td->ciphertext.crc_offset -
9513                                 RTE_ETHER_CRC_LEN) :
9514                         0;
9515         crc_len = crc_len > 0 ? crc_len : 0;
9516         crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
9517         ut_params->op->sym->auth.data.length = crc_len;
9518         ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
9519
9520         /* Setup cipher operation parameters */
9521         cipher_len = d_td->ciphertext.no_cipher == false ?
9522                         (d_td->ciphertext.len -
9523                                 d_td->ciphertext.cipher_offset) :
9524                         0;
9525         cipher_len = cipher_len > 0 ? cipher_len : 0;
9526         ut_params->op->sym->cipher.data.length = cipher_len;
9527         ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
9528
9529         /* Setup cipher IV */
9530         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9531         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9532
9533         /* Attach session to operation */
9534         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9535
9536         /* Set crypto operation mbufs */
9537         ut_params->op->sym->m_src = ut_params->ibuf;
9538         ut_params->op->sym->m_dst = NULL;
9539
9540         /* Process crypto operation */
9541         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9542                         NULL) {
9543                 printf("TestCase %s(%d) line %d: %s\n",
9544                         __func__, i, __LINE__,
9545                         "failed to process security crypto op");
9546                 ret = TEST_FAILED;
9547                 goto on_err;
9548         }
9549
9550         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9551                 printf("TestCase %s(%d) line %d: %s\n",
9552                         __func__, i, __LINE__, "crypto op processing failed");
9553                 ret = TEST_FAILED;
9554                 goto on_err;
9555         }
9556
9557         /* Validate plaintext */
9558         plaintext = ciphertext;
9559
9560         if (memcmp(plaintext, d_td->plaintext.data,
9561                         d_td->plaintext.len - crc_data_len)) {
9562                 printf("TestCase %s(%d) line %d: %s\n",
9563                         __func__, i, __LINE__, "plaintext not as expected\n");
9564                 rte_hexdump(stdout, "expected", d_td->plaintext.data,
9565                                 d_td->plaintext.len);
9566                 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9567                 ret = TEST_FAILED;
9568                 goto on_err;
9569         }
9570
9571 on_err:
9572         rte_crypto_op_free(ut_params->op);
9573         ut_params->op = NULL;
9574
9575         if (ut_params->sec_session)
9576                 rte_security_session_destroy(ctx, ut_params->sec_session);
9577         ut_params->sec_session = NULL;
9578
9579         rte_pktmbuf_free(ut_params->ibuf);
9580         ut_params->ibuf = NULL;
9581
9582         return ret;
9583 }
9584
9585 static int
9586 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9587 {
9588         struct crypto_testsuite_params *ts_params = &testsuite_params;
9589         struct crypto_unittest_params *ut_params = &unittest_params;
9590         uint8_t *plaintext, *ciphertext;
9591         uint8_t *iv_ptr;
9592         int32_t cipher_len, crc_len;
9593         int ret = TEST_SUCCESS;
9594
9595         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9596                                         rte_cryptodev_get_sec_ctx(
9597                                                 ts_params->valid_devs[0]);
9598
9599         /* Verify the capabilities */
9600         struct rte_security_capability_idx sec_cap_idx;
9601         const struct rte_security_capability *sec_cap;
9602         const struct rte_cryptodev_capabilities *crypto_cap;
9603         const struct rte_cryptodev_symmetric_capability *sym_cap;
9604         int j = 0;
9605
9606         sec_cap_idx.action = ut_params->type;
9607         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9608         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9609
9610         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9611         if (sec_cap == NULL)
9612                 return TEST_SKIPPED;
9613
9614         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9615                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9616                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9617                                 crypto_cap->sym.xform_type ==
9618                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9619                                 crypto_cap->sym.cipher.algo ==
9620                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9621                         sym_cap = &crypto_cap->sym;
9622                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9623                                                 d_td->key.len,
9624                                                 d_td->iv.len) == 0)
9625                                 break;
9626                 }
9627         }
9628
9629         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9630                 return TEST_SKIPPED;
9631
9632         /* Setup source mbuf payload */
9633         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9634         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9635                         rte_pktmbuf_tailroom(ut_params->ibuf));
9636
9637         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9638                         d_td->plaintext.len);
9639
9640         memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9641
9642         /* Setup cipher session parameters */
9643         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9644         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9645         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9646         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9647         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9648         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9649         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9650         ut_params->cipher_xform.next = NULL;
9651
9652         /* Setup DOCSIS session parameters */
9653         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9654
9655         struct rte_security_session_conf sess_conf = {
9656                 .action_type = ut_params->type,
9657                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9658                 .docsis = ut_params->docsis_xform,
9659                 .crypto_xform = &ut_params->cipher_xform,
9660         };
9661
9662         /* Create security session */
9663         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9664                                         ts_params->session_mpool,
9665                                         ts_params->session_priv_mpool);
9666
9667         if (!ut_params->sec_session) {
9668                 printf("TestCase %s(%d) line %d: %s\n",
9669                         __func__, i, __LINE__, "failed to allocate session");
9670                 ret = TEST_FAILED;
9671                 goto on_err;
9672         }
9673
9674         /* Generate crypto op data structure */
9675         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9676                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9677         if (!ut_params->op) {
9678                 printf("TestCase %s(%d) line %d: %s\n",
9679                         __func__, i, __LINE__,
9680                         "failed to allocate security crypto operation");
9681                 ret = TEST_FAILED;
9682                 goto on_err;
9683         }
9684
9685         /* Setup CRC operation parameters */
9686         crc_len = d_td->plaintext.no_crc == false ?
9687                         (d_td->plaintext.len -
9688                                 d_td->plaintext.crc_offset -
9689                                 RTE_ETHER_CRC_LEN) :
9690                         0;
9691         crc_len = crc_len > 0 ? crc_len : 0;
9692         ut_params->op->sym->auth.data.length = crc_len;
9693         ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9694
9695         /* Setup cipher operation parameters */
9696         cipher_len = d_td->plaintext.no_cipher == false ?
9697                         (d_td->plaintext.len -
9698                                 d_td->plaintext.cipher_offset) :
9699                         0;
9700         cipher_len = cipher_len > 0 ? cipher_len : 0;
9701         ut_params->op->sym->cipher.data.length = cipher_len;
9702         ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9703
9704         /* Setup cipher IV */
9705         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9706         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9707
9708         /* Attach session to operation */
9709         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9710
9711         /* Set crypto operation mbufs */
9712         ut_params->op->sym->m_src = ut_params->ibuf;
9713         ut_params->op->sym->m_dst = NULL;
9714
9715         /* Process crypto operation */
9716         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9717                         NULL) {
9718                 printf("TestCase %s(%d) line %d: %s\n",
9719                         __func__, i, __LINE__,
9720                         "failed to process security crypto op");
9721                 ret = TEST_FAILED;
9722                 goto on_err;
9723         }
9724
9725         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9726                 printf("TestCase %s(%d) line %d: %s\n",
9727                         __func__, i, __LINE__, "crypto op processing failed");
9728                 ret = TEST_FAILED;
9729                 goto on_err;
9730         }
9731
9732         /* Validate ciphertext */
9733         ciphertext = plaintext;
9734
9735         if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9736                 printf("TestCase %s(%d) line %d: %s\n",
9737                         __func__, i, __LINE__, "ciphertext not as expected\n");
9738                 rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9739                                 d_td->ciphertext.len);
9740                 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9741                 ret = TEST_FAILED;
9742                 goto on_err;
9743         }
9744
9745 on_err:
9746         rte_crypto_op_free(ut_params->op);
9747         ut_params->op = NULL;
9748
9749         if (ut_params->sec_session)
9750                 rte_security_session_destroy(ctx, ut_params->sec_session);
9751         ut_params->sec_session = NULL;
9752
9753         rte_pktmbuf_free(ut_params->ibuf);
9754         ut_params->ibuf = NULL;
9755
9756         return ret;
9757 }
9758
9759 #define TEST_DOCSIS_COUNT(func) do {                    \
9760         int ret = func;                                 \
9761         if (ret == TEST_SUCCESS)  {                     \
9762                 printf("\t%2d)", n++);                  \
9763                 printf("+++++ PASSED:" #func"\n");      \
9764                 p++;                                    \
9765         } else if (ret == TEST_SKIPPED) {               \
9766                 printf("\t%2d)", n++);                  \
9767                 printf("~~~~~ SKIPPED:" #func"\n");     \
9768                 s++;                                    \
9769         } else {                                        \
9770                 printf("\t%2d)", n++);                  \
9771                 printf("----- FAILED:" #func"\n");      \
9772                 f++;                                    \
9773         }                                               \
9774 } while (0)
9775
9776 static int
9777 test_DOCSIS_PROTO_uplink_all(void)
9778 {
9779         int p = 0, s = 0, f = 0, n = 0;
9780
9781         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9782         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9783         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9784         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9785         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9786         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9787         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9788         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9789         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9790         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9791         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9792         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9793         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9794         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9795         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9796         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9797         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9798         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9799         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9800         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9801         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9802         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9803         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9804         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9805         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9806         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9807
9808         if (f)
9809                 printf("## %s: %d passed out of %d (%d skipped)\n",
9810                         __func__, p, n, s);
9811
9812         return f;
9813 };
9814
9815 static int
9816 test_DOCSIS_PROTO_downlink_all(void)
9817 {
9818         int p = 0, s = 0, f = 0, n = 0;
9819
9820         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9821         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9822         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9823         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9824         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9825         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9826         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9827         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9828         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9829         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9830         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9831         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9832         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9833         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9834         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9835         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9836         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9837         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9838         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9839         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9840         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9841         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9842         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9843         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9844         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9845         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9846
9847         if (f)
9848                 printf("## %s: %d passed out of %d (%d skipped)\n",
9849                         __func__, p, n, s);
9850
9851         return f;
9852 };
9853
9854 static int
9855 test_DOCSIS_PROTO_all(void)
9856 {
9857         struct crypto_testsuite_params *ts_params = &testsuite_params;
9858         struct crypto_unittest_params *ut_params = &unittest_params;
9859         struct rte_cryptodev_info dev_info;
9860         int status;
9861
9862         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9863         uint64_t feat_flags = dev_info.feature_flags;
9864
9865         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9866                 return TEST_SKIPPED;
9867
9868         /* Set action type */
9869         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9870                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9871                 gbl_action_type;
9872
9873         if (security_proto_supported(ut_params->type,
9874                         RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9875                 return TEST_SKIPPED;
9876
9877         status = test_DOCSIS_PROTO_uplink_all();
9878         status += test_DOCSIS_PROTO_downlink_all();
9879
9880         if (status)
9881                 return TEST_FAILED;
9882         else
9883                 return TEST_SUCCESS;
9884 }
9885 #endif
9886
9887 static int
9888 test_AES_GCM_authenticated_encryption_test_case_1(void)
9889 {
9890         return test_authenticated_encryption(&gcm_test_case_1);
9891 }
9892
9893 static int
9894 test_AES_GCM_authenticated_encryption_test_case_2(void)
9895 {
9896         return test_authenticated_encryption(&gcm_test_case_2);
9897 }
9898
9899 static int
9900 test_AES_GCM_authenticated_encryption_test_case_3(void)
9901 {
9902         return test_authenticated_encryption(&gcm_test_case_3);
9903 }
9904
9905 static int
9906 test_AES_GCM_authenticated_encryption_test_case_4(void)
9907 {
9908         return test_authenticated_encryption(&gcm_test_case_4);
9909 }
9910
9911 static int
9912 test_AES_GCM_authenticated_encryption_test_case_5(void)
9913 {
9914         return test_authenticated_encryption(&gcm_test_case_5);
9915 }
9916
9917 static int
9918 test_AES_GCM_authenticated_encryption_test_case_6(void)
9919 {
9920         return test_authenticated_encryption(&gcm_test_case_6);
9921 }
9922
9923 static int
9924 test_AES_GCM_authenticated_encryption_test_case_7(void)
9925 {
9926         return test_authenticated_encryption(&gcm_test_case_7);
9927 }
9928
9929 static int
9930 test_AES_GCM_authenticated_encryption_test_case_8(void)
9931 {
9932         return test_authenticated_encryption(&gcm_test_case_8);
9933 }
9934
9935 static int
9936 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9937 {
9938         return test_authenticated_encryption(&gcm_J0_test_case_1);
9939 }
9940
9941 static int
9942 test_AES_GCM_auth_encryption_test_case_192_1(void)
9943 {
9944         return test_authenticated_encryption(&gcm_test_case_192_1);
9945 }
9946
9947 static int
9948 test_AES_GCM_auth_encryption_test_case_192_2(void)
9949 {
9950         return test_authenticated_encryption(&gcm_test_case_192_2);
9951 }
9952
9953 static int
9954 test_AES_GCM_auth_encryption_test_case_192_3(void)
9955 {
9956         return test_authenticated_encryption(&gcm_test_case_192_3);
9957 }
9958
9959 static int
9960 test_AES_GCM_auth_encryption_test_case_192_4(void)
9961 {
9962         return test_authenticated_encryption(&gcm_test_case_192_4);
9963 }
9964
9965 static int
9966 test_AES_GCM_auth_encryption_test_case_192_5(void)
9967 {
9968         return test_authenticated_encryption(&gcm_test_case_192_5);
9969 }
9970
9971 static int
9972 test_AES_GCM_auth_encryption_test_case_192_6(void)
9973 {
9974         return test_authenticated_encryption(&gcm_test_case_192_6);
9975 }
9976
9977 static int
9978 test_AES_GCM_auth_encryption_test_case_192_7(void)
9979 {
9980         return test_authenticated_encryption(&gcm_test_case_192_7);
9981 }
9982
9983 static int
9984 test_AES_GCM_auth_encryption_test_case_256_1(void)
9985 {
9986         return test_authenticated_encryption(&gcm_test_case_256_1);
9987 }
9988
9989 static int
9990 test_AES_GCM_auth_encryption_test_case_256_2(void)
9991 {
9992         return test_authenticated_encryption(&gcm_test_case_256_2);
9993 }
9994
9995 static int
9996 test_AES_GCM_auth_encryption_test_case_256_3(void)
9997 {
9998         return test_authenticated_encryption(&gcm_test_case_256_3);
9999 }
10000
10001 static int
10002 test_AES_GCM_auth_encryption_test_case_256_4(void)
10003 {
10004         return test_authenticated_encryption(&gcm_test_case_256_4);
10005 }
10006
10007 static int
10008 test_AES_GCM_auth_encryption_test_case_256_5(void)
10009 {
10010         return test_authenticated_encryption(&gcm_test_case_256_5);
10011 }
10012
10013 static int
10014 test_AES_GCM_auth_encryption_test_case_256_6(void)
10015 {
10016         return test_authenticated_encryption(&gcm_test_case_256_6);
10017 }
10018
10019 static int
10020 test_AES_GCM_auth_encryption_test_case_256_7(void)
10021 {
10022         return test_authenticated_encryption(&gcm_test_case_256_7);
10023 }
10024
10025 static int
10026 test_AES_GCM_auth_encryption_test_case_aad_1(void)
10027 {
10028         return test_authenticated_encryption(&gcm_test_case_aad_1);
10029 }
10030
10031 static int
10032 test_AES_GCM_auth_encryption_test_case_aad_2(void)
10033 {
10034         return test_authenticated_encryption(&gcm_test_case_aad_2);
10035 }
10036
10037 static int
10038 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
10039 {
10040         struct aead_test_data tdata;
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         tdata.iv.data[0] += 1;
10046         res = test_authenticated_encryption(&tdata);
10047         if (res == TEST_SKIPPED)
10048                 return res;
10049         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10050         return TEST_SUCCESS;
10051 }
10052
10053 static int
10054 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
10055 {
10056         struct aead_test_data tdata;
10057         int res;
10058
10059         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10060         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10061         tdata.plaintext.data[0] += 1;
10062         res = test_authenticated_encryption(&tdata);
10063         if (res == TEST_SKIPPED)
10064                 return res;
10065         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10066         return TEST_SUCCESS;
10067 }
10068
10069 static int
10070 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
10071 {
10072         struct aead_test_data tdata;
10073         int res;
10074
10075         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10076         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10077         tdata.ciphertext.data[0] += 1;
10078         res = test_authenticated_encryption(&tdata);
10079         if (res == TEST_SKIPPED)
10080                 return res;
10081         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10082         return TEST_SUCCESS;
10083 }
10084
10085 static int
10086 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
10087 {
10088         struct aead_test_data tdata;
10089         int res;
10090
10091         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10092         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10093         tdata.aad.len += 1;
10094         res = test_authenticated_encryption(&tdata);
10095         if (res == TEST_SKIPPED)
10096                 return res;
10097         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10098         return TEST_SUCCESS;
10099 }
10100
10101 static int
10102 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
10103 {
10104         struct aead_test_data tdata;
10105         uint8_t aad[gcm_test_case_7.aad.len];
10106         int res;
10107
10108         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10109         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10110         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10111         aad[0] += 1;
10112         tdata.aad.data = aad;
10113         res = test_authenticated_encryption(&tdata);
10114         if (res == TEST_SKIPPED)
10115                 return res;
10116         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10117         return TEST_SUCCESS;
10118 }
10119
10120 static int
10121 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
10122 {
10123         struct aead_test_data tdata;
10124         int res;
10125
10126         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10127         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10128         tdata.auth_tag.data[0] += 1;
10129         res = test_authenticated_encryption(&tdata);
10130         if (res == TEST_SKIPPED)
10131                 return res;
10132         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10133         return TEST_SUCCESS;
10134 }
10135
10136 static int
10137 test_authenticated_decryption(const struct aead_test_data *tdata)
10138 {
10139         struct crypto_testsuite_params *ts_params = &testsuite_params;
10140         struct crypto_unittest_params *ut_params = &unittest_params;
10141
10142         int retval;
10143         uint8_t *plaintext;
10144         uint32_t i;
10145         struct rte_cryptodev_info dev_info;
10146
10147         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10148         uint64_t feat_flags = dev_info.feature_flags;
10149
10150         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10151                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10152                 printf("Device doesn't support RAW data-path APIs.\n");
10153                 return TEST_SKIPPED;
10154         }
10155
10156         /* Verify the capabilities */
10157         struct rte_cryptodev_sym_capability_idx cap_idx;
10158         const struct rte_cryptodev_symmetric_capability *capability;
10159         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10160         cap_idx.algo.aead = tdata->algo;
10161         capability = rte_cryptodev_sym_capability_get(
10162                         ts_params->valid_devs[0], &cap_idx);
10163         if (capability == NULL)
10164                 return TEST_SKIPPED;
10165         if (rte_cryptodev_sym_capability_check_aead(
10166                         capability, tdata->key.len, tdata->auth_tag.len,
10167                         tdata->aad.len, tdata->iv.len))
10168                 return TEST_SKIPPED;
10169
10170         /* Create AEAD session */
10171         retval = create_aead_session(ts_params->valid_devs[0],
10172                         tdata->algo,
10173                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10174                         tdata->key.data, tdata->key.len,
10175                         tdata->aad.len, tdata->auth_tag.len,
10176                         tdata->iv.len);
10177         if (retval < 0)
10178                 return retval;
10179
10180         /* alloc mbuf and set payload */
10181         if (tdata->aad.len > MBUF_SIZE) {
10182                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10183                 /* Populate full size of add data */
10184                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
10185                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
10186         } else
10187                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10188
10189         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10190                         rte_pktmbuf_tailroom(ut_params->ibuf));
10191
10192         /* Create AEAD operation */
10193         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10194         if (retval < 0)
10195                 return retval;
10196
10197         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10198
10199         ut_params->op->sym->m_src = ut_params->ibuf;
10200
10201         /* Process crypto operation */
10202         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10203                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
10204         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10205                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10206                                 ut_params->op, 0, 0, 0, 0);
10207         else
10208                 TEST_ASSERT_NOT_NULL(
10209                         process_crypto_request(ts_params->valid_devs[0],
10210                         ut_params->op), "failed to process sym crypto op");
10211
10212         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10213                         "crypto op processing failed");
10214
10215         if (ut_params->op->sym->m_dst)
10216                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
10217                                 uint8_t *);
10218         else
10219                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
10220                                 uint8_t *,
10221                                 ut_params->op->sym->cipher.data.offset);
10222
10223         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10224
10225         /* Validate obuf */
10226         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10227                         plaintext,
10228                         tdata->plaintext.data,
10229                         tdata->plaintext.len,
10230                         "Plaintext data not as expected");
10231
10232         TEST_ASSERT_EQUAL(ut_params->op->status,
10233                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10234                         "Authentication failed");
10235
10236         return 0;
10237 }
10238
10239 static int
10240 test_AES_GCM_authenticated_decryption_test_case_1(void)
10241 {
10242         return test_authenticated_decryption(&gcm_test_case_1);
10243 }
10244
10245 static int
10246 test_AES_GCM_authenticated_decryption_test_case_2(void)
10247 {
10248         return test_authenticated_decryption(&gcm_test_case_2);
10249 }
10250
10251 static int
10252 test_AES_GCM_authenticated_decryption_test_case_3(void)
10253 {
10254         return test_authenticated_decryption(&gcm_test_case_3);
10255 }
10256
10257 static int
10258 test_AES_GCM_authenticated_decryption_test_case_4(void)
10259 {
10260         return test_authenticated_decryption(&gcm_test_case_4);
10261 }
10262
10263 static int
10264 test_AES_GCM_authenticated_decryption_test_case_5(void)
10265 {
10266         return test_authenticated_decryption(&gcm_test_case_5);
10267 }
10268
10269 static int
10270 test_AES_GCM_authenticated_decryption_test_case_6(void)
10271 {
10272         return test_authenticated_decryption(&gcm_test_case_6);
10273 }
10274
10275 static int
10276 test_AES_GCM_authenticated_decryption_test_case_7(void)
10277 {
10278         return test_authenticated_decryption(&gcm_test_case_7);
10279 }
10280
10281 static int
10282 test_AES_GCM_authenticated_decryption_test_case_8(void)
10283 {
10284         return test_authenticated_decryption(&gcm_test_case_8);
10285 }
10286
10287 static int
10288 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
10289 {
10290         return test_authenticated_decryption(&gcm_J0_test_case_1);
10291 }
10292
10293 static int
10294 test_AES_GCM_auth_decryption_test_case_192_1(void)
10295 {
10296         return test_authenticated_decryption(&gcm_test_case_192_1);
10297 }
10298
10299 static int
10300 test_AES_GCM_auth_decryption_test_case_192_2(void)
10301 {
10302         return test_authenticated_decryption(&gcm_test_case_192_2);
10303 }
10304
10305 static int
10306 test_AES_GCM_auth_decryption_test_case_192_3(void)
10307 {
10308         return test_authenticated_decryption(&gcm_test_case_192_3);
10309 }
10310
10311 static int
10312 test_AES_GCM_auth_decryption_test_case_192_4(void)
10313 {
10314         return test_authenticated_decryption(&gcm_test_case_192_4);
10315 }
10316
10317 static int
10318 test_AES_GCM_auth_decryption_test_case_192_5(void)
10319 {
10320         return test_authenticated_decryption(&gcm_test_case_192_5);
10321 }
10322
10323 static int
10324 test_AES_GCM_auth_decryption_test_case_192_6(void)
10325 {
10326         return test_authenticated_decryption(&gcm_test_case_192_6);
10327 }
10328
10329 static int
10330 test_AES_GCM_auth_decryption_test_case_192_7(void)
10331 {
10332         return test_authenticated_decryption(&gcm_test_case_192_7);
10333 }
10334
10335 static int
10336 test_AES_GCM_auth_decryption_test_case_256_1(void)
10337 {
10338         return test_authenticated_decryption(&gcm_test_case_256_1);
10339 }
10340
10341 static int
10342 test_AES_GCM_auth_decryption_test_case_256_2(void)
10343 {
10344         return test_authenticated_decryption(&gcm_test_case_256_2);
10345 }
10346
10347 static int
10348 test_AES_GCM_auth_decryption_test_case_256_3(void)
10349 {
10350         return test_authenticated_decryption(&gcm_test_case_256_3);
10351 }
10352
10353 static int
10354 test_AES_GCM_auth_decryption_test_case_256_4(void)
10355 {
10356         return test_authenticated_decryption(&gcm_test_case_256_4);
10357 }
10358
10359 static int
10360 test_AES_GCM_auth_decryption_test_case_256_5(void)
10361 {
10362         return test_authenticated_decryption(&gcm_test_case_256_5);
10363 }
10364
10365 static int
10366 test_AES_GCM_auth_decryption_test_case_256_6(void)
10367 {
10368         return test_authenticated_decryption(&gcm_test_case_256_6);
10369 }
10370
10371 static int
10372 test_AES_GCM_auth_decryption_test_case_256_7(void)
10373 {
10374         return test_authenticated_decryption(&gcm_test_case_256_7);
10375 }
10376
10377 static int
10378 test_AES_GCM_auth_decryption_test_case_aad_1(void)
10379 {
10380         return test_authenticated_decryption(&gcm_test_case_aad_1);
10381 }
10382
10383 static int
10384 test_AES_GCM_auth_decryption_test_case_aad_2(void)
10385 {
10386         return test_authenticated_decryption(&gcm_test_case_aad_2);
10387 }
10388
10389 static int
10390 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
10391 {
10392         struct aead_test_data tdata;
10393         int res;
10394
10395         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10396         tdata.iv.data[0] += 1;
10397         res = test_authenticated_decryption(&tdata);
10398         if (res == TEST_SKIPPED)
10399                 return res;
10400         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10401         return TEST_SUCCESS;
10402 }
10403
10404 static int
10405 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
10406 {
10407         struct aead_test_data tdata;
10408         int res;
10409
10410         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10411         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10412         tdata.plaintext.data[0] += 1;
10413         res = test_authenticated_decryption(&tdata);
10414         if (res == TEST_SKIPPED)
10415                 return res;
10416         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10417         return TEST_SUCCESS;
10418 }
10419
10420 static int
10421 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
10422 {
10423         struct aead_test_data tdata;
10424         int res;
10425
10426         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10427         tdata.ciphertext.data[0] += 1;
10428         res = test_authenticated_decryption(&tdata);
10429         if (res == TEST_SKIPPED)
10430                 return res;
10431         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10432         return TEST_SUCCESS;
10433 }
10434
10435 static int
10436 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
10437 {
10438         struct aead_test_data tdata;
10439         int res;
10440
10441         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10442         tdata.aad.len += 1;
10443         res = test_authenticated_decryption(&tdata);
10444         if (res == TEST_SKIPPED)
10445                 return res;
10446         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10447         return TEST_SUCCESS;
10448 }
10449
10450 static int
10451 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
10452 {
10453         struct aead_test_data tdata;
10454         uint8_t aad[gcm_test_case_7.aad.len];
10455         int res;
10456
10457         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10458         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10459         aad[0] += 1;
10460         tdata.aad.data = aad;
10461         res = test_authenticated_decryption(&tdata);
10462         if (res == TEST_SKIPPED)
10463                 return res;
10464         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10465         return TEST_SUCCESS;
10466 }
10467
10468 static int
10469 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
10470 {
10471         struct aead_test_data tdata;
10472         int res;
10473
10474         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10475         tdata.auth_tag.data[0] += 1;
10476         res = test_authenticated_decryption(&tdata);
10477         if (res == TEST_SKIPPED)
10478                 return res;
10479         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
10480         return TEST_SUCCESS;
10481 }
10482
10483 static int
10484 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
10485 {
10486         struct crypto_testsuite_params *ts_params = &testsuite_params;
10487         struct crypto_unittest_params *ut_params = &unittest_params;
10488
10489         int retval;
10490         uint8_t *ciphertext, *auth_tag;
10491         uint16_t plaintext_pad_len;
10492         struct rte_cryptodev_info dev_info;
10493
10494         /* Verify the capabilities */
10495         struct rte_cryptodev_sym_capability_idx cap_idx;
10496         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10497         cap_idx.algo.aead = tdata->algo;
10498         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10499                         &cap_idx) == NULL)
10500                 return TEST_SKIPPED;
10501
10502         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10503         uint64_t feat_flags = dev_info.feature_flags;
10504
10505         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10506                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)))
10507                 return TEST_SKIPPED;
10508
10509         /* not supported with CPU crypto */
10510         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10511                 return TEST_SKIPPED;
10512
10513         /* Create AEAD session */
10514         retval = create_aead_session(ts_params->valid_devs[0],
10515                         tdata->algo,
10516                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10517                         tdata->key.data, tdata->key.len,
10518                         tdata->aad.len, tdata->auth_tag.len,
10519                         tdata->iv.len);
10520         if (retval < 0)
10521                 return retval;
10522
10523         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10524         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10525
10526         /* clear mbuf payload */
10527         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10528                         rte_pktmbuf_tailroom(ut_params->ibuf));
10529         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10530                         rte_pktmbuf_tailroom(ut_params->obuf));
10531
10532         /* Create AEAD operation */
10533         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10534         if (retval < 0)
10535                 return retval;
10536
10537         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10538
10539         ut_params->op->sym->m_src = ut_params->ibuf;
10540         ut_params->op->sym->m_dst = ut_params->obuf;
10541
10542         /* Process crypto operation */
10543         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10544                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10545                         ut_params->op, 0, 0, 0, 0);
10546         else
10547                 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10548                         ut_params->op), "failed to process sym crypto op");
10549
10550         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10551                         "crypto op processing failed");
10552
10553         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10554
10555         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10556                         ut_params->op->sym->cipher.data.offset);
10557         auth_tag = ciphertext + plaintext_pad_len;
10558
10559         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10560         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10561
10562         /* Validate obuf */
10563         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10564                         ciphertext,
10565                         tdata->ciphertext.data,
10566                         tdata->ciphertext.len,
10567                         "Ciphertext data not as expected");
10568
10569         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10570                         auth_tag,
10571                         tdata->auth_tag.data,
10572                         tdata->auth_tag.len,
10573                         "Generated auth tag not as expected");
10574
10575         return 0;
10576
10577 }
10578
10579 static int
10580 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10581 {
10582         return test_authenticated_encryption_oop(&gcm_test_case_5);
10583 }
10584
10585 static int
10586 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10587 {
10588         struct crypto_testsuite_params *ts_params = &testsuite_params;
10589         struct crypto_unittest_params *ut_params = &unittest_params;
10590
10591         int retval;
10592         uint8_t *plaintext;
10593         struct rte_cryptodev_info dev_info;
10594
10595         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10596         uint64_t feat_flags = dev_info.feature_flags;
10597
10598         /* Verify the capabilities */
10599         struct rte_cryptodev_sym_capability_idx cap_idx;
10600         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10601         cap_idx.algo.aead = tdata->algo;
10602         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10603                         &cap_idx) == NULL)
10604                 return TEST_SKIPPED;
10605
10606         /* not supported with CPU crypto and raw data-path APIs*/
10607         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10608                         global_api_test_type == CRYPTODEV_RAW_API_TEST)
10609                 return TEST_SKIPPED;
10610
10611         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10612                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10613                 printf("Device does not support RAW data-path APIs.\n");
10614                 return TEST_SKIPPED;
10615         }
10616
10617         /* Create AEAD session */
10618         retval = create_aead_session(ts_params->valid_devs[0],
10619                         tdata->algo,
10620                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10621                         tdata->key.data, tdata->key.len,
10622                         tdata->aad.len, tdata->auth_tag.len,
10623                         tdata->iv.len);
10624         if (retval < 0)
10625                 return retval;
10626
10627         /* alloc mbuf and set payload */
10628         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10629         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10630
10631         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10632                         rte_pktmbuf_tailroom(ut_params->ibuf));
10633         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10634                         rte_pktmbuf_tailroom(ut_params->obuf));
10635
10636         /* Create AEAD operation */
10637         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10638         if (retval < 0)
10639                 return retval;
10640
10641         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10642
10643         ut_params->op->sym->m_src = ut_params->ibuf;
10644         ut_params->op->sym->m_dst = ut_params->obuf;
10645
10646         /* Process crypto operation */
10647         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10648                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10649                                 ut_params->op, 0, 0, 0, 0);
10650         else
10651                 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10652                         ut_params->op), "failed to process sym crypto op");
10653
10654         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10655                         "crypto op processing failed");
10656
10657         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10658                         ut_params->op->sym->cipher.data.offset);
10659
10660         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10661
10662         /* Validate obuf */
10663         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10664                         plaintext,
10665                         tdata->plaintext.data,
10666                         tdata->plaintext.len,
10667                         "Plaintext data not as expected");
10668
10669         TEST_ASSERT_EQUAL(ut_params->op->status,
10670                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10671                         "Authentication failed");
10672         return 0;
10673 }
10674
10675 static int
10676 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10677 {
10678         return test_authenticated_decryption_oop(&gcm_test_case_5);
10679 }
10680
10681 static int
10682 test_authenticated_encryption_sessionless(
10683                 const struct aead_test_data *tdata)
10684 {
10685         struct crypto_testsuite_params *ts_params = &testsuite_params;
10686         struct crypto_unittest_params *ut_params = &unittest_params;
10687
10688         int retval;
10689         uint8_t *ciphertext, *auth_tag;
10690         uint16_t plaintext_pad_len;
10691         uint8_t key[tdata->key.len + 1];
10692         struct rte_cryptodev_info dev_info;
10693
10694         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10695         uint64_t feat_flags = dev_info.feature_flags;
10696
10697         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10698                 printf("Device doesn't support Sessionless ops.\n");
10699                 return TEST_SKIPPED;
10700         }
10701
10702         /* not supported with CPU crypto */
10703         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10704                 return TEST_SKIPPED;
10705
10706         /* Verify the capabilities */
10707         struct rte_cryptodev_sym_capability_idx cap_idx;
10708         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10709         cap_idx.algo.aead = tdata->algo;
10710         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10711                         &cap_idx) == NULL)
10712                 return TEST_SKIPPED;
10713
10714         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10715
10716         /* clear mbuf payload */
10717         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10718                         rte_pktmbuf_tailroom(ut_params->ibuf));
10719
10720         /* Create AEAD operation */
10721         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10722         if (retval < 0)
10723                 return retval;
10724
10725         /* Create GCM xform */
10726         memcpy(key, tdata->key.data, tdata->key.len);
10727         retval = create_aead_xform(ut_params->op,
10728                         tdata->algo,
10729                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10730                         key, tdata->key.len,
10731                         tdata->aad.len, tdata->auth_tag.len,
10732                         tdata->iv.len);
10733         if (retval < 0)
10734                 return retval;
10735
10736         ut_params->op->sym->m_src = ut_params->ibuf;
10737
10738         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10739                         RTE_CRYPTO_OP_SESSIONLESS,
10740                         "crypto op session type not sessionless");
10741
10742         /* Process crypto operation */
10743         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10744                         ut_params->op), "failed to process sym crypto op");
10745
10746         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10747
10748         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10749                         "crypto op status not success");
10750
10751         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10752
10753         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10754                         ut_params->op->sym->cipher.data.offset);
10755         auth_tag = ciphertext + plaintext_pad_len;
10756
10757         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10758         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10759
10760         /* Validate obuf */
10761         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10762                         ciphertext,
10763                         tdata->ciphertext.data,
10764                         tdata->ciphertext.len,
10765                         "Ciphertext data not as expected");
10766
10767         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10768                         auth_tag,
10769                         tdata->auth_tag.data,
10770                         tdata->auth_tag.len,
10771                         "Generated auth tag not as expected");
10772
10773         return 0;
10774
10775 }
10776
10777 static int
10778 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10779 {
10780         return test_authenticated_encryption_sessionless(
10781                         &gcm_test_case_5);
10782 }
10783
10784 static int
10785 test_authenticated_decryption_sessionless(
10786                 const struct aead_test_data *tdata)
10787 {
10788         struct crypto_testsuite_params *ts_params = &testsuite_params;
10789         struct crypto_unittest_params *ut_params = &unittest_params;
10790
10791         int retval;
10792         uint8_t *plaintext;
10793         uint8_t key[tdata->key.len + 1];
10794         struct rte_cryptodev_info dev_info;
10795
10796         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10797         uint64_t feat_flags = dev_info.feature_flags;
10798
10799         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10800                 printf("Device doesn't support Sessionless ops.\n");
10801                 return TEST_SKIPPED;
10802         }
10803
10804         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10805                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10806                 printf("Device doesn't support RAW data-path APIs.\n");
10807                 return TEST_SKIPPED;
10808         }
10809
10810         /* not supported with CPU crypto */
10811         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10812                 return TEST_SKIPPED;
10813
10814         /* Verify the capabilities */
10815         struct rte_cryptodev_sym_capability_idx cap_idx;
10816         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10817         cap_idx.algo.aead = tdata->algo;
10818         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10819                         &cap_idx) == NULL)
10820                 return TEST_SKIPPED;
10821
10822         /* alloc mbuf and set payload */
10823         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10824
10825         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10826                         rte_pktmbuf_tailroom(ut_params->ibuf));
10827
10828         /* Create AEAD operation */
10829         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10830         if (retval < 0)
10831                 return retval;
10832
10833         /* Create AEAD xform */
10834         memcpy(key, tdata->key.data, tdata->key.len);
10835         retval = create_aead_xform(ut_params->op,
10836                         tdata->algo,
10837                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10838                         key, tdata->key.len,
10839                         tdata->aad.len, tdata->auth_tag.len,
10840                         tdata->iv.len);
10841         if (retval < 0)
10842                 return retval;
10843
10844         ut_params->op->sym->m_src = ut_params->ibuf;
10845
10846         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10847                         RTE_CRYPTO_OP_SESSIONLESS,
10848                         "crypto op session type not sessionless");
10849
10850         /* Process crypto operation */
10851         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10852                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10853                                 ut_params->op, 0, 0, 0, 0);
10854         else
10855                 TEST_ASSERT_NOT_NULL(process_crypto_request(
10856                         ts_params->valid_devs[0], ut_params->op),
10857                                 "failed to process sym crypto op");
10858
10859         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10860
10861         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10862                         "crypto op status not success");
10863
10864         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10865                         ut_params->op->sym->cipher.data.offset);
10866
10867         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10868
10869         /* Validate obuf */
10870         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10871                         plaintext,
10872                         tdata->plaintext.data,
10873                         tdata->plaintext.len,
10874                         "Plaintext data not as expected");
10875
10876         TEST_ASSERT_EQUAL(ut_params->op->status,
10877                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10878                         "Authentication failed");
10879         return 0;
10880 }
10881
10882 static int
10883 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
10884 {
10885         return test_authenticated_decryption_sessionless(
10886                         &gcm_test_case_5);
10887 }
10888
10889 static int
10890 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
10891 {
10892         return test_authenticated_encryption(&ccm_test_case_128_1);
10893 }
10894
10895 static int
10896 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
10897 {
10898         return test_authenticated_encryption(&ccm_test_case_128_2);
10899 }
10900
10901 static int
10902 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
10903 {
10904         return test_authenticated_encryption(&ccm_test_case_128_3);
10905 }
10906
10907 static int
10908 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
10909 {
10910         return test_authenticated_decryption(&ccm_test_case_128_1);
10911 }
10912
10913 static int
10914 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
10915 {
10916         return test_authenticated_decryption(&ccm_test_case_128_2);
10917 }
10918
10919 static int
10920 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10921 {
10922         return test_authenticated_decryption(&ccm_test_case_128_3);
10923 }
10924
10925 static int
10926 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10927 {
10928         return test_authenticated_encryption(&ccm_test_case_192_1);
10929 }
10930
10931 static int
10932 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10933 {
10934         return test_authenticated_encryption(&ccm_test_case_192_2);
10935 }
10936
10937 static int
10938 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10939 {
10940         return test_authenticated_encryption(&ccm_test_case_192_3);
10941 }
10942
10943 static int
10944 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10945 {
10946         return test_authenticated_decryption(&ccm_test_case_192_1);
10947 }
10948
10949 static int
10950 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10951 {
10952         return test_authenticated_decryption(&ccm_test_case_192_2);
10953 }
10954
10955 static int
10956 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10957 {
10958         return test_authenticated_decryption(&ccm_test_case_192_3);
10959 }
10960
10961 static int
10962 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
10963 {
10964         return test_authenticated_encryption(&ccm_test_case_256_1);
10965 }
10966
10967 static int
10968 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
10969 {
10970         return test_authenticated_encryption(&ccm_test_case_256_2);
10971 }
10972
10973 static int
10974 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
10975 {
10976         return test_authenticated_encryption(&ccm_test_case_256_3);
10977 }
10978
10979 static int
10980 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
10981 {
10982         return test_authenticated_decryption(&ccm_test_case_256_1);
10983 }
10984
10985 static int
10986 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
10987 {
10988         return test_authenticated_decryption(&ccm_test_case_256_2);
10989 }
10990
10991 static int
10992 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
10993 {
10994         return test_authenticated_decryption(&ccm_test_case_256_3);
10995 }
10996
10997 static int
10998 test_stats(void)
10999 {
11000         struct crypto_testsuite_params *ts_params = &testsuite_params;
11001         struct rte_cryptodev_stats stats;
11002
11003         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11004                 return TEST_SKIPPED;
11005
11006         /* Verify the capabilities */
11007         struct rte_cryptodev_sym_capability_idx cap_idx;
11008         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11009         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
11010         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11011                         &cap_idx) == NULL)
11012                 return TEST_SKIPPED;
11013         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11014         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11015         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11016                         &cap_idx) == NULL)
11017                 return TEST_SKIPPED;
11018
11019         if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
11020                         == -ENOTSUP)
11021                 return TEST_SKIPPED;
11022
11023         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11024         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
11025                         &stats) == -ENODEV),
11026                 "rte_cryptodev_stats_get invalid dev failed");
11027         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
11028                 "rte_cryptodev_stats_get invalid Param failed");
11029
11030         /* Test expected values */
11031         test_AES_CBC_HMAC_SHA1_encrypt_digest();
11032         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11033                         &stats),
11034                 "rte_cryptodev_stats_get failed");
11035         TEST_ASSERT((stats.enqueued_count == 1),
11036                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11037         TEST_ASSERT((stats.dequeued_count == 1),
11038                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11039         TEST_ASSERT((stats.enqueue_err_count == 0),
11040                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11041         TEST_ASSERT((stats.dequeue_err_count == 0),
11042                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11043
11044         /* invalid device but should ignore and not reset device stats*/
11045         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
11046         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11047                         &stats),
11048                 "rte_cryptodev_stats_get failed");
11049         TEST_ASSERT((stats.enqueued_count == 1),
11050                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11051
11052         /* check that a valid reset clears stats */
11053         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11054         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11055                         &stats),
11056                                           "rte_cryptodev_stats_get failed");
11057         TEST_ASSERT((stats.enqueued_count == 0),
11058                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11059         TEST_ASSERT((stats.dequeued_count == 0),
11060                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11061
11062         return TEST_SUCCESS;
11063 }
11064
11065 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
11066                                    struct crypto_unittest_params *ut_params,
11067                                    enum rte_crypto_auth_operation op,
11068                                    const struct HMAC_MD5_vector *test_case)
11069 {
11070         uint8_t key[64];
11071
11072         memcpy(key, test_case->key.data, test_case->key.len);
11073
11074         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11075         ut_params->auth_xform.next = NULL;
11076         ut_params->auth_xform.auth.op = op;
11077
11078         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
11079
11080         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
11081         ut_params->auth_xform.auth.key.length = test_case->key.len;
11082         ut_params->auth_xform.auth.key.data = key;
11083
11084         ut_params->sess = rte_cryptodev_sym_session_create(
11085                         ts_params->session_mpool);
11086
11087         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11088                         ut_params->sess, &ut_params->auth_xform,
11089                         ts_params->session_priv_mpool);
11090
11091         if (ut_params->sess == NULL)
11092                 return TEST_FAILED;
11093
11094         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11095
11096         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11097                         rte_pktmbuf_tailroom(ut_params->ibuf));
11098
11099         return 0;
11100 }
11101
11102 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
11103                               const struct HMAC_MD5_vector *test_case,
11104                               uint8_t **plaintext)
11105 {
11106         uint16_t plaintext_pad_len;
11107
11108         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11109
11110         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11111                                 16);
11112
11113         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11114                         plaintext_pad_len);
11115         memcpy(*plaintext, test_case->plaintext.data,
11116                         test_case->plaintext.len);
11117
11118         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11119                         ut_params->ibuf, MD5_DIGEST_LEN);
11120         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11121                         "no room to append digest");
11122         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11123                         ut_params->ibuf, plaintext_pad_len);
11124
11125         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11126                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
11127                            test_case->auth_tag.len);
11128         }
11129
11130         sym_op->auth.data.offset = 0;
11131         sym_op->auth.data.length = test_case->plaintext.len;
11132
11133         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11134         ut_params->op->sym->m_src = ut_params->ibuf;
11135
11136         return 0;
11137 }
11138
11139 static int
11140 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
11141 {
11142         uint16_t plaintext_pad_len;
11143         uint8_t *plaintext, *auth_tag;
11144
11145         struct crypto_testsuite_params *ts_params = &testsuite_params;
11146         struct crypto_unittest_params *ut_params = &unittest_params;
11147         struct rte_cryptodev_info dev_info;
11148
11149         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11150         uint64_t feat_flags = dev_info.feature_flags;
11151
11152         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11153                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11154                 printf("Device doesn't support RAW data-path APIs.\n");
11155                 return TEST_SKIPPED;
11156         }
11157
11158         /* Verify the capabilities */
11159         struct rte_cryptodev_sym_capability_idx cap_idx;
11160         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11161         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11162         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11163                         &cap_idx) == NULL)
11164                 return TEST_SKIPPED;
11165
11166         if (MD5_HMAC_create_session(ts_params, ut_params,
11167                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
11168                 return TEST_FAILED;
11169
11170         /* Generate Crypto op data structure */
11171         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11172                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11173         TEST_ASSERT_NOT_NULL(ut_params->op,
11174                         "Failed to allocate symmetric crypto operation struct");
11175
11176         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11177                                 16);
11178
11179         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11180                 return TEST_FAILED;
11181
11182         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11183                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11184                         ut_params->op);
11185         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11186                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11187                                 ut_params->op, 0, 1, 0, 0);
11188         else
11189                 TEST_ASSERT_NOT_NULL(
11190                         process_crypto_request(ts_params->valid_devs[0],
11191                                 ut_params->op),
11192                                 "failed to process sym crypto op");
11193
11194         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11195                         "crypto op processing failed");
11196
11197         if (ut_params->op->sym->m_dst) {
11198                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11199                                 uint8_t *, plaintext_pad_len);
11200         } else {
11201                 auth_tag = plaintext + plaintext_pad_len;
11202         }
11203
11204         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11205                         auth_tag,
11206                         test_case->auth_tag.data,
11207                         test_case->auth_tag.len,
11208                         "HMAC_MD5 generated tag not as expected");
11209
11210         return TEST_SUCCESS;
11211 }
11212
11213 static int
11214 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
11215 {
11216         uint8_t *plaintext;
11217
11218         struct crypto_testsuite_params *ts_params = &testsuite_params;
11219         struct crypto_unittest_params *ut_params = &unittest_params;
11220         struct rte_cryptodev_info dev_info;
11221
11222         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11223         uint64_t feat_flags = dev_info.feature_flags;
11224
11225         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11226                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11227                 printf("Device doesn't support RAW data-path APIs.\n");
11228                 return TEST_SKIPPED;
11229         }
11230
11231         /* Verify the capabilities */
11232         struct rte_cryptodev_sym_capability_idx cap_idx;
11233         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11234         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11235         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11236                         &cap_idx) == NULL)
11237                 return TEST_SKIPPED;
11238
11239         if (MD5_HMAC_create_session(ts_params, ut_params,
11240                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
11241                 return TEST_FAILED;
11242         }
11243
11244         /* Generate Crypto op data structure */
11245         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11246                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11247         TEST_ASSERT_NOT_NULL(ut_params->op,
11248                         "Failed to allocate symmetric crypto operation struct");
11249
11250         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11251                 return TEST_FAILED;
11252
11253         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11254                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11255                         ut_params->op);
11256         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11257                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11258                                 ut_params->op, 0, 1, 0, 0);
11259         else
11260                 TEST_ASSERT_NOT_NULL(
11261                         process_crypto_request(ts_params->valid_devs[0],
11262                                 ut_params->op),
11263                                 "failed to process sym crypto op");
11264
11265         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11266                         "HMAC_MD5 crypto op processing failed");
11267
11268         return TEST_SUCCESS;
11269 }
11270
11271 static int
11272 test_MD5_HMAC_generate_case_1(void)
11273 {
11274         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
11275 }
11276
11277 static int
11278 test_MD5_HMAC_verify_case_1(void)
11279 {
11280         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
11281 }
11282
11283 static int
11284 test_MD5_HMAC_generate_case_2(void)
11285 {
11286         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
11287 }
11288
11289 static int
11290 test_MD5_HMAC_verify_case_2(void)
11291 {
11292         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
11293 }
11294
11295 static int
11296 test_multi_session(void)
11297 {
11298         struct crypto_testsuite_params *ts_params = &testsuite_params;
11299         struct crypto_unittest_params *ut_params = &unittest_params;
11300
11301         struct rte_cryptodev_info dev_info;
11302         struct rte_cryptodev_sym_session **sessions;
11303
11304         uint16_t i;
11305
11306         /* Verify the capabilities */
11307         struct rte_cryptodev_sym_capability_idx cap_idx;
11308         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11309         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11310         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11311                         &cap_idx) == NULL)
11312                 return TEST_SKIPPED;
11313         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11314         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11315         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11316                         &cap_idx) == NULL)
11317                 return TEST_SKIPPED;
11318
11319         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
11320                         aes_cbc_key, hmac_sha512_key);
11321
11322
11323         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11324
11325         sessions = rte_malloc(NULL,
11326                         sizeof(struct rte_cryptodev_sym_session *) *
11327                         (MAX_NB_SESSIONS + 1), 0);
11328
11329         /* Create multiple crypto sessions*/
11330         for (i = 0; i < MAX_NB_SESSIONS; i++) {
11331
11332                 sessions[i] = rte_cryptodev_sym_session_create(
11333                                 ts_params->session_mpool);
11334
11335                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11336                                 sessions[i], &ut_params->auth_xform,
11337                                 ts_params->session_priv_mpool);
11338                 TEST_ASSERT_NOT_NULL(sessions[i],
11339                                 "Session creation failed at session number %u",
11340                                 i);
11341
11342                 /* Attempt to send a request on each session */
11343                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
11344                         sessions[i],
11345                         ut_params,
11346                         ts_params,
11347                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
11348                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
11349                         aes_cbc_iv),
11350                         "Failed to perform decrypt on request number %u.", i);
11351                 /* free crypto operation structure */
11352                 if (ut_params->op)
11353                         rte_crypto_op_free(ut_params->op);
11354
11355                 /*
11356                  * free mbuf - both obuf and ibuf are usually the same,
11357                  * so check if they point at the same address is necessary,
11358                  * to avoid freeing the mbuf twice.
11359                  */
11360                 if (ut_params->obuf) {
11361                         rte_pktmbuf_free(ut_params->obuf);
11362                         if (ut_params->ibuf == ut_params->obuf)
11363                                 ut_params->ibuf = 0;
11364                         ut_params->obuf = 0;
11365                 }
11366                 if (ut_params->ibuf) {
11367                         rte_pktmbuf_free(ut_params->ibuf);
11368                         ut_params->ibuf = 0;
11369                 }
11370         }
11371
11372         sessions[i] = NULL;
11373         /* Next session create should fail */
11374         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11375                         sessions[i], &ut_params->auth_xform,
11376                         ts_params->session_priv_mpool);
11377         TEST_ASSERT_NULL(sessions[i],
11378                         "Session creation succeeded unexpectedly!");
11379
11380         for (i = 0; i < MAX_NB_SESSIONS; i++) {
11381                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11382                                 sessions[i]);
11383                 rte_cryptodev_sym_session_free(sessions[i]);
11384         }
11385
11386         rte_free(sessions);
11387
11388         return TEST_SUCCESS;
11389 }
11390
11391 struct multi_session_params {
11392         struct crypto_unittest_params ut_params;
11393         uint8_t *cipher_key;
11394         uint8_t *hmac_key;
11395         const uint8_t *cipher;
11396         const uint8_t *digest;
11397         uint8_t *iv;
11398 };
11399
11400 #define MB_SESSION_NUMBER 3
11401
11402 static int
11403 test_multi_session_random_usage(void)
11404 {
11405         struct crypto_testsuite_params *ts_params = &testsuite_params;
11406         struct rte_cryptodev_info dev_info;
11407         struct rte_cryptodev_sym_session **sessions;
11408         uint32_t i, j;
11409         struct multi_session_params ut_paramz[] = {
11410
11411                 {
11412                         .cipher_key = ms_aes_cbc_key0,
11413                         .hmac_key = ms_hmac_key0,
11414                         .cipher = ms_aes_cbc_cipher0,
11415                         .digest = ms_hmac_digest0,
11416                         .iv = ms_aes_cbc_iv0
11417                 },
11418                 {
11419                         .cipher_key = ms_aes_cbc_key1,
11420                         .hmac_key = ms_hmac_key1,
11421                         .cipher = ms_aes_cbc_cipher1,
11422                         .digest = ms_hmac_digest1,
11423                         .iv = ms_aes_cbc_iv1
11424                 },
11425                 {
11426                         .cipher_key = ms_aes_cbc_key2,
11427                         .hmac_key = ms_hmac_key2,
11428                         .cipher = ms_aes_cbc_cipher2,
11429                         .digest = ms_hmac_digest2,
11430                         .iv = ms_aes_cbc_iv2
11431                 },
11432
11433         };
11434
11435         /* Verify the capabilities */
11436         struct rte_cryptodev_sym_capability_idx cap_idx;
11437         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11438         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11439         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11440                         &cap_idx) == NULL)
11441                 return TEST_SKIPPED;
11442         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11443         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11444         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11445                         &cap_idx) == NULL)
11446                 return TEST_SKIPPED;
11447
11448         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11449
11450         sessions = rte_malloc(NULL,
11451                         (sizeof(struct rte_cryptodev_sym_session *)
11452                                         * MAX_NB_SESSIONS) + 1, 0);
11453
11454         for (i = 0; i < MB_SESSION_NUMBER; i++) {
11455                 sessions[i] = rte_cryptodev_sym_session_create(
11456                                 ts_params->session_mpool);
11457
11458                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
11459                                 sizeof(struct crypto_unittest_params));
11460
11461                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
11462                                 &ut_paramz[i].ut_params,
11463                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
11464
11465                 /* Create multiple crypto sessions*/
11466                 rte_cryptodev_sym_session_init(
11467                                 ts_params->valid_devs[0],
11468                                 sessions[i],
11469                                 &ut_paramz[i].ut_params.auth_xform,
11470                                 ts_params->session_priv_mpool);
11471
11472                 TEST_ASSERT_NOT_NULL(sessions[i],
11473                                 "Session creation failed at session number %u",
11474                                 i);
11475
11476         }
11477
11478         srand(time(NULL));
11479         for (i = 0; i < 40000; i++) {
11480
11481                 j = rand() % MB_SESSION_NUMBER;
11482
11483                 TEST_ASSERT_SUCCESS(
11484                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
11485                                         sessions[j],
11486                                         &ut_paramz[j].ut_params,
11487                                         ts_params, ut_paramz[j].cipher,
11488                                         ut_paramz[j].digest,
11489                                         ut_paramz[j].iv),
11490                         "Failed to perform decrypt on request number %u.", i);
11491
11492                 if (ut_paramz[j].ut_params.op)
11493                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
11494
11495                 /*
11496                  * free mbuf - both obuf and ibuf are usually the same,
11497                  * so check if they point at the same address is necessary,
11498                  * to avoid freeing the mbuf twice.
11499                  */
11500                 if (ut_paramz[j].ut_params.obuf) {
11501                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
11502                         if (ut_paramz[j].ut_params.ibuf
11503                                         == ut_paramz[j].ut_params.obuf)
11504                                 ut_paramz[j].ut_params.ibuf = 0;
11505                         ut_paramz[j].ut_params.obuf = 0;
11506                 }
11507                 if (ut_paramz[j].ut_params.ibuf) {
11508                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
11509                         ut_paramz[j].ut_params.ibuf = 0;
11510                 }
11511         }
11512
11513         for (i = 0; i < MB_SESSION_NUMBER; i++) {
11514                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11515                                 sessions[i]);
11516                 rte_cryptodev_sym_session_free(sessions[i]);
11517         }
11518
11519         rte_free(sessions);
11520
11521         return TEST_SUCCESS;
11522 }
11523
11524 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
11525                         0xab, 0xab, 0xab, 0xab,
11526                         0xab, 0xab, 0xab, 0xab,
11527                         0xab, 0xab, 0xab, 0xab};
11528
11529 static int
11530 test_null_invalid_operation(void)
11531 {
11532         struct crypto_testsuite_params *ts_params = &testsuite_params;
11533         struct crypto_unittest_params *ut_params = &unittest_params;
11534         int ret;
11535
11536         /* This test is for NULL PMD only */
11537         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11538                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11539                 return TEST_SKIPPED;
11540
11541         /* Setup Cipher Parameters */
11542         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11543         ut_params->cipher_xform.next = NULL;
11544
11545         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
11546         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11547
11548         ut_params->sess = rte_cryptodev_sym_session_create(
11549                         ts_params->session_mpool);
11550
11551         /* Create Crypto session*/
11552         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11553                         ut_params->sess, &ut_params->cipher_xform,
11554                         ts_params->session_priv_mpool);
11555         TEST_ASSERT(ret < 0,
11556                         "Session creation succeeded unexpectedly");
11557
11558
11559         /* Setup HMAC Parameters */
11560         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11561         ut_params->auth_xform.next = NULL;
11562
11563         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
11564         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11565
11566         ut_params->sess = rte_cryptodev_sym_session_create(
11567                         ts_params->session_mpool);
11568
11569         /* Create Crypto session*/
11570         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11571                         ut_params->sess, &ut_params->auth_xform,
11572                         ts_params->session_priv_mpool);
11573         TEST_ASSERT(ret < 0,
11574                         "Session creation succeeded unexpectedly");
11575
11576         return TEST_SUCCESS;
11577 }
11578
11579
11580 #define NULL_BURST_LENGTH (32)
11581
11582 static int
11583 test_null_burst_operation(void)
11584 {
11585         struct crypto_testsuite_params *ts_params = &testsuite_params;
11586         struct crypto_unittest_params *ut_params = &unittest_params;
11587
11588         unsigned i, burst_len = NULL_BURST_LENGTH;
11589
11590         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11591         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11592
11593         /* This test is for NULL PMD only */
11594         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11595                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11596                 return TEST_SKIPPED;
11597
11598         /* Setup Cipher Parameters */
11599         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11600         ut_params->cipher_xform.next = &ut_params->auth_xform;
11601
11602         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11603         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11604
11605         /* Setup HMAC Parameters */
11606         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11607         ut_params->auth_xform.next = NULL;
11608
11609         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11610         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11611
11612         ut_params->sess = rte_cryptodev_sym_session_create(
11613                         ts_params->session_mpool);
11614
11615         /* Create Crypto session*/
11616         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11617                         ut_params->sess, &ut_params->cipher_xform,
11618                         ts_params->session_priv_mpool);
11619         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11620
11621         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11622                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11623                         burst_len, "failed to generate burst of crypto ops");
11624
11625         /* Generate an operation for each mbuf in burst */
11626         for (i = 0; i < burst_len; i++) {
11627                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11628
11629                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11630
11631                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11632                                 sizeof(unsigned));
11633                 *data = i;
11634
11635                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11636
11637                 burst[i]->sym->m_src = m;
11638         }
11639
11640         /* Process crypto operation */
11641         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11642                         0, burst, burst_len),
11643                         burst_len,
11644                         "Error enqueuing burst");
11645
11646         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11647                         0, burst_dequeued, burst_len),
11648                         burst_len,
11649                         "Error dequeuing burst");
11650
11651
11652         for (i = 0; i < burst_len; i++) {
11653                 TEST_ASSERT_EQUAL(
11654                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11655                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11656                                         uint32_t *),
11657                         "data not as expected");
11658
11659                 rte_pktmbuf_free(burst[i]->sym->m_src);
11660                 rte_crypto_op_free(burst[i]);
11661         }
11662
11663         return TEST_SUCCESS;
11664 }
11665
11666 static uint16_t
11667 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11668                   uint16_t nb_ops, void *user_param)
11669 {
11670         RTE_SET_USED(dev_id);
11671         RTE_SET_USED(qp_id);
11672         RTE_SET_USED(ops);
11673         RTE_SET_USED(user_param);
11674
11675         printf("crypto enqueue callback called\n");
11676         return nb_ops;
11677 }
11678
11679 static uint16_t
11680 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11681                   uint16_t nb_ops, void *user_param)
11682 {
11683         RTE_SET_USED(dev_id);
11684         RTE_SET_USED(qp_id);
11685         RTE_SET_USED(ops);
11686         RTE_SET_USED(user_param);
11687
11688         printf("crypto dequeue callback called\n");
11689         return nb_ops;
11690 }
11691
11692 /*
11693  * Thread using enqueue/dequeue callback with RCU.
11694  */
11695 static int
11696 test_enqdeq_callback_thread(void *arg)
11697 {
11698         RTE_SET_USED(arg);
11699         /* DP thread calls rte_cryptodev_enqueue_burst()/
11700          * rte_cryptodev_dequeue_burst() and invokes callback.
11701          */
11702         test_null_burst_operation();
11703         return 0;
11704 }
11705
11706 static int
11707 test_enq_callback_setup(void)
11708 {
11709         struct crypto_testsuite_params *ts_params = &testsuite_params;
11710         struct rte_cryptodev_info dev_info;
11711         struct rte_cryptodev_qp_conf qp_conf = {
11712                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11713         };
11714
11715         struct rte_cryptodev_cb *cb;
11716         uint16_t qp_id = 0;
11717
11718         /* Stop the device in case it's started so it can be configured */
11719         rte_cryptodev_stop(ts_params->valid_devs[0]);
11720
11721         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11722
11723         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11724                         &ts_params->conf),
11725                         "Failed to configure cryptodev %u",
11726                         ts_params->valid_devs[0]);
11727
11728         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11729         qp_conf.mp_session = ts_params->session_mpool;
11730         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11731
11732         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11733                         ts_params->valid_devs[0], qp_id, &qp_conf,
11734                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11735                         "Failed test for "
11736                         "rte_cryptodev_queue_pair_setup: num_inflights "
11737                         "%u on qp %u on cryptodev %u",
11738                         qp_conf.nb_descriptors, qp_id,
11739                         ts_params->valid_devs[0]);
11740
11741         /* Test with invalid crypto device */
11742         cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11743                         qp_id, test_enq_callback, NULL);
11744         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11745                         "cryptodev %u did not fail",
11746                         qp_id, RTE_CRYPTO_MAX_DEVS);
11747
11748         /* Test with invalid queue pair */
11749         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11750                         dev_info.max_nb_queue_pairs + 1,
11751                         test_enq_callback, NULL);
11752         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11753                         "cryptodev %u did not fail",
11754                         dev_info.max_nb_queue_pairs + 1,
11755                         ts_params->valid_devs[0]);
11756
11757         /* Test with NULL callback */
11758         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11759                         qp_id, NULL, NULL);
11760         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11761                         "cryptodev %u did not fail",
11762                         qp_id, ts_params->valid_devs[0]);
11763
11764         /* Test with valid configuration */
11765         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11766                         qp_id, test_enq_callback, NULL);
11767         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11768                         "qp %u on cryptodev %u",
11769                         qp_id, ts_params->valid_devs[0]);
11770
11771         rte_cryptodev_start(ts_params->valid_devs[0]);
11772
11773         /* Launch a thread */
11774         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11775                                 rte_get_next_lcore(-1, 1, 0));
11776
11777         /* Wait until reader exited. */
11778         rte_eal_mp_wait_lcore();
11779
11780         /* Test with invalid crypto device */
11781         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11782                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11783                         "Expected call to fail as crypto device is invalid");
11784
11785         /* Test with invalid queue pair */
11786         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11787                         ts_params->valid_devs[0],
11788                         dev_info.max_nb_queue_pairs + 1, cb),
11789                         "Expected call to fail as queue pair is invalid");
11790
11791         /* Test with NULL callback */
11792         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11793                         ts_params->valid_devs[0], qp_id, NULL),
11794                         "Expected call to fail as callback is NULL");
11795
11796         /* Test with valid configuration */
11797         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11798                         ts_params->valid_devs[0], qp_id, cb),
11799                         "Failed test to remove callback on "
11800                         "qp %u on cryptodev %u",
11801                         qp_id, ts_params->valid_devs[0]);
11802
11803         return TEST_SUCCESS;
11804 }
11805
11806 static int
11807 test_deq_callback_setup(void)
11808 {
11809         struct crypto_testsuite_params *ts_params = &testsuite_params;
11810         struct rte_cryptodev_info dev_info;
11811         struct rte_cryptodev_qp_conf qp_conf = {
11812                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11813         };
11814
11815         struct rte_cryptodev_cb *cb;
11816         uint16_t qp_id = 0;
11817
11818         /* Stop the device in case it's started so it can be configured */
11819         rte_cryptodev_stop(ts_params->valid_devs[0]);
11820
11821         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11822
11823         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11824                         &ts_params->conf),
11825                         "Failed to configure cryptodev %u",
11826                         ts_params->valid_devs[0]);
11827
11828         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11829         qp_conf.mp_session = ts_params->session_mpool;
11830         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11831
11832         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11833                         ts_params->valid_devs[0], qp_id, &qp_conf,
11834                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11835                         "Failed test for "
11836                         "rte_cryptodev_queue_pair_setup: num_inflights "
11837                         "%u on qp %u on cryptodev %u",
11838                         qp_conf.nb_descriptors, qp_id,
11839                         ts_params->valid_devs[0]);
11840
11841         /* Test with invalid crypto device */
11842         cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11843                         qp_id, test_deq_callback, NULL);
11844         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11845                         "cryptodev %u did not fail",
11846                         qp_id, RTE_CRYPTO_MAX_DEVS);
11847
11848         /* Test with invalid queue pair */
11849         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11850                         dev_info.max_nb_queue_pairs + 1,
11851                         test_deq_callback, NULL);
11852         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11853                         "cryptodev %u did not fail",
11854                         dev_info.max_nb_queue_pairs + 1,
11855                         ts_params->valid_devs[0]);
11856
11857         /* Test with NULL callback */
11858         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11859                         qp_id, NULL, NULL);
11860         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11861                         "cryptodev %u did not fail",
11862                         qp_id, ts_params->valid_devs[0]);
11863
11864         /* Test with valid configuration */
11865         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11866                         qp_id, test_deq_callback, NULL);
11867         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11868                         "qp %u on cryptodev %u",
11869                         qp_id, ts_params->valid_devs[0]);
11870
11871         rte_cryptodev_start(ts_params->valid_devs[0]);
11872
11873         /* Launch a thread */
11874         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11875                                 rte_get_next_lcore(-1, 1, 0));
11876
11877         /* Wait until reader exited. */
11878         rte_eal_mp_wait_lcore();
11879
11880         /* Test with invalid crypto device */
11881         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11882                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11883                         "Expected call to fail as crypto device is invalid");
11884
11885         /* Test with invalid queue pair */
11886         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11887                         ts_params->valid_devs[0],
11888                         dev_info.max_nb_queue_pairs + 1, cb),
11889                         "Expected call to fail as queue pair is invalid");
11890
11891         /* Test with NULL callback */
11892         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11893                         ts_params->valid_devs[0], qp_id, NULL),
11894                         "Expected call to fail as callback is NULL");
11895
11896         /* Test with valid configuration */
11897         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
11898                         ts_params->valid_devs[0], qp_id, cb),
11899                         "Failed test to remove callback on "
11900                         "qp %u on cryptodev %u",
11901                         qp_id, ts_params->valid_devs[0]);
11902
11903         return TEST_SUCCESS;
11904 }
11905
11906 static void
11907 generate_gmac_large_plaintext(uint8_t *data)
11908 {
11909         uint16_t i;
11910
11911         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
11912                 memcpy(&data[i], &data[0], 32);
11913 }
11914
11915 static int
11916 create_gmac_operation(enum rte_crypto_auth_operation op,
11917                 const struct gmac_test_data *tdata)
11918 {
11919         struct crypto_testsuite_params *ts_params = &testsuite_params;
11920         struct crypto_unittest_params *ut_params = &unittest_params;
11921         struct rte_crypto_sym_op *sym_op;
11922
11923         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11924
11925         /* Generate Crypto op data structure */
11926         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11927                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11928         TEST_ASSERT_NOT_NULL(ut_params->op,
11929                         "Failed to allocate symmetric crypto operation struct");
11930
11931         sym_op = ut_params->op->sym;
11932
11933         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11934                         ut_params->ibuf, tdata->gmac_tag.len);
11935         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11936                         "no room to append digest");
11937
11938         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11939                         ut_params->ibuf, plaintext_pad_len);
11940
11941         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11942                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11943                                 tdata->gmac_tag.len);
11944                 debug_hexdump(stdout, "digest:",
11945                                 sym_op->auth.digest.data,
11946                                 tdata->gmac_tag.len);
11947         }
11948
11949         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11950                         uint8_t *, IV_OFFSET);
11951
11952         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11953
11954         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11955
11956         sym_op->cipher.data.length = 0;
11957         sym_op->cipher.data.offset = 0;
11958
11959         sym_op->auth.data.offset = 0;
11960         sym_op->auth.data.length = tdata->plaintext.len;
11961
11962         return 0;
11963 }
11964
11965 static int
11966 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
11967                 const struct gmac_test_data *tdata,
11968                 void *digest_mem, uint64_t digest_phys)
11969 {
11970         struct crypto_testsuite_params *ts_params = &testsuite_params;
11971         struct crypto_unittest_params *ut_params = &unittest_params;
11972         struct rte_crypto_sym_op *sym_op;
11973
11974         /* Generate Crypto op data structure */
11975         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11976                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11977         TEST_ASSERT_NOT_NULL(ut_params->op,
11978                         "Failed to allocate symmetric crypto operation struct");
11979
11980         sym_op = ut_params->op->sym;
11981
11982         sym_op->auth.digest.data = digest_mem;
11983         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11984                         "no room to append digest");
11985
11986         sym_op->auth.digest.phys_addr = digest_phys;
11987
11988         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11989                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11990                                 tdata->gmac_tag.len);
11991                 debug_hexdump(stdout, "digest:",
11992                                 sym_op->auth.digest.data,
11993                                 tdata->gmac_tag.len);
11994         }
11995
11996         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11997                         uint8_t *, IV_OFFSET);
11998
11999         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12000
12001         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12002
12003         sym_op->cipher.data.length = 0;
12004         sym_op->cipher.data.offset = 0;
12005
12006         sym_op->auth.data.offset = 0;
12007         sym_op->auth.data.length = tdata->plaintext.len;
12008
12009         return 0;
12010 }
12011
12012 static int create_gmac_session(uint8_t dev_id,
12013                 const struct gmac_test_data *tdata,
12014                 enum rte_crypto_auth_operation auth_op)
12015 {
12016         uint8_t auth_key[tdata->key.len];
12017
12018         struct crypto_testsuite_params *ts_params = &testsuite_params;
12019         struct crypto_unittest_params *ut_params = &unittest_params;
12020
12021         memcpy(auth_key, tdata->key.data, tdata->key.len);
12022
12023         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12024         ut_params->auth_xform.next = NULL;
12025
12026         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
12027         ut_params->auth_xform.auth.op = auth_op;
12028         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
12029         ut_params->auth_xform.auth.key.length = tdata->key.len;
12030         ut_params->auth_xform.auth.key.data = auth_key;
12031         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12032         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
12033
12034
12035         ut_params->sess = rte_cryptodev_sym_session_create(
12036                         ts_params->session_mpool);
12037
12038         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12039                         &ut_params->auth_xform,
12040                         ts_params->session_priv_mpool);
12041
12042         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12043
12044         return 0;
12045 }
12046
12047 static int
12048 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
12049 {
12050         struct crypto_testsuite_params *ts_params = &testsuite_params;
12051         struct crypto_unittest_params *ut_params = &unittest_params;
12052         struct rte_cryptodev_info dev_info;
12053
12054         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12055         uint64_t feat_flags = dev_info.feature_flags;
12056
12057         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12058                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12059                 printf("Device doesn't support RAW data-path APIs.\n");
12060                 return TEST_SKIPPED;
12061         }
12062
12063         int retval;
12064
12065         uint8_t *auth_tag, *plaintext;
12066         uint16_t plaintext_pad_len;
12067
12068         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12069                               "No GMAC length in the source data");
12070
12071         /* Verify the capabilities */
12072         struct rte_cryptodev_sym_capability_idx cap_idx;
12073         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12074         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12075         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12076                         &cap_idx) == NULL)
12077                 return TEST_SKIPPED;
12078
12079         retval = create_gmac_session(ts_params->valid_devs[0],
12080                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12081
12082         if (retval < 0)
12083                 return retval;
12084
12085         if (tdata->plaintext.len > MBUF_SIZE)
12086                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12087         else
12088                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12089         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12090                         "Failed to allocate input buffer in mempool");
12091
12092         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12093                         rte_pktmbuf_tailroom(ut_params->ibuf));
12094
12095         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12096         /*
12097          * Runtime generate the large plain text instead of use hard code
12098          * plain text vector. It is done to avoid create huge source file
12099          * with the test vector.
12100          */
12101         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12102                 generate_gmac_large_plaintext(tdata->plaintext.data);
12103
12104         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12105                                 plaintext_pad_len);
12106         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12107
12108         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12109         debug_hexdump(stdout, "plaintext:", plaintext,
12110                         tdata->plaintext.len);
12111
12112         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
12113                         tdata);
12114
12115         if (retval < 0)
12116                 return retval;
12117
12118         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12119
12120         ut_params->op->sym->m_src = ut_params->ibuf;
12121
12122         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12123                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12124                         ut_params->op);
12125         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12126                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12127                                 ut_params->op, 0, 1, 0, 0);
12128         else
12129                 TEST_ASSERT_NOT_NULL(
12130                         process_crypto_request(ts_params->valid_devs[0],
12131                         ut_params->op), "failed to process sym crypto op");
12132
12133         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12134                         "crypto op processing failed");
12135
12136         if (ut_params->op->sym->m_dst) {
12137                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12138                                 uint8_t *, plaintext_pad_len);
12139         } else {
12140                 auth_tag = plaintext + plaintext_pad_len;
12141         }
12142
12143         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12144
12145         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12146                         auth_tag,
12147                         tdata->gmac_tag.data,
12148                         tdata->gmac_tag.len,
12149                         "GMAC Generated auth tag not as expected");
12150
12151         return 0;
12152 }
12153
12154 static int
12155 test_AES_GMAC_authentication_test_case_1(void)
12156 {
12157         return test_AES_GMAC_authentication(&gmac_test_case_1);
12158 }
12159
12160 static int
12161 test_AES_GMAC_authentication_test_case_2(void)
12162 {
12163         return test_AES_GMAC_authentication(&gmac_test_case_2);
12164 }
12165
12166 static int
12167 test_AES_GMAC_authentication_test_case_3(void)
12168 {
12169         return test_AES_GMAC_authentication(&gmac_test_case_3);
12170 }
12171
12172 static int
12173 test_AES_GMAC_authentication_test_case_4(void)
12174 {
12175         return test_AES_GMAC_authentication(&gmac_test_case_4);
12176 }
12177
12178 static int
12179 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
12180 {
12181         struct crypto_testsuite_params *ts_params = &testsuite_params;
12182         struct crypto_unittest_params *ut_params = &unittest_params;
12183         int retval;
12184         uint32_t plaintext_pad_len;
12185         uint8_t *plaintext;
12186         struct rte_cryptodev_info dev_info;
12187
12188         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12189         uint64_t feat_flags = dev_info.feature_flags;
12190
12191         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12192                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12193                 printf("Device doesn't support RAW data-path APIs.\n");
12194                 return TEST_SKIPPED;
12195         }
12196
12197         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12198                               "No GMAC length in the source data");
12199
12200         /* Verify the capabilities */
12201         struct rte_cryptodev_sym_capability_idx cap_idx;
12202         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12203         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12204         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12205                         &cap_idx) == NULL)
12206                 return TEST_SKIPPED;
12207
12208         retval = create_gmac_session(ts_params->valid_devs[0],
12209                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
12210
12211         if (retval < 0)
12212                 return retval;
12213
12214         if (tdata->plaintext.len > MBUF_SIZE)
12215                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12216         else
12217                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12218         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12219                         "Failed to allocate input buffer in mempool");
12220
12221         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12222                         rte_pktmbuf_tailroom(ut_params->ibuf));
12223
12224         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12225
12226         /*
12227          * Runtime generate the large plain text instead of use hard code
12228          * plain text vector. It is done to avoid create huge source file
12229          * with the test vector.
12230          */
12231         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12232                 generate_gmac_large_plaintext(tdata->plaintext.data);
12233
12234         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12235                                 plaintext_pad_len);
12236         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12237
12238         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12239         debug_hexdump(stdout, "plaintext:", plaintext,
12240                         tdata->plaintext.len);
12241
12242         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
12243                         tdata);
12244
12245         if (retval < 0)
12246                 return retval;
12247
12248         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12249
12250         ut_params->op->sym->m_src = ut_params->ibuf;
12251
12252         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12253                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12254                         ut_params->op);
12255         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12256                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12257                                 ut_params->op, 0, 1, 0, 0);
12258         else
12259                 TEST_ASSERT_NOT_NULL(
12260                         process_crypto_request(ts_params->valid_devs[0],
12261                         ut_params->op), "failed to process sym crypto op");
12262
12263         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12264                         "crypto op processing failed");
12265
12266         return 0;
12267
12268 }
12269
12270 static int
12271 test_AES_GMAC_authentication_verify_test_case_1(void)
12272 {
12273         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
12274 }
12275
12276 static int
12277 test_AES_GMAC_authentication_verify_test_case_2(void)
12278 {
12279         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
12280 }
12281
12282 static int
12283 test_AES_GMAC_authentication_verify_test_case_3(void)
12284 {
12285         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
12286 }
12287
12288 static int
12289 test_AES_GMAC_authentication_verify_test_case_4(void)
12290 {
12291         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
12292 }
12293
12294 static int
12295 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
12296                                 uint32_t fragsz)
12297 {
12298         struct crypto_testsuite_params *ts_params = &testsuite_params;
12299         struct crypto_unittest_params *ut_params = &unittest_params;
12300         struct rte_cryptodev_info dev_info;
12301         uint64_t feature_flags;
12302         unsigned int trn_data = 0;
12303         void *digest_mem = NULL;
12304         uint32_t segs = 1;
12305         unsigned int to_trn = 0;
12306         struct rte_mbuf *buf = NULL;
12307         uint8_t *auth_tag, *plaintext;
12308         int retval;
12309
12310         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12311                               "No GMAC length in the source data");
12312
12313         /* Verify the capabilities */
12314         struct rte_cryptodev_sym_capability_idx cap_idx;
12315         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12316         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12317         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12318                         &cap_idx) == NULL)
12319                 return TEST_SKIPPED;
12320
12321         /* Check for any input SGL support */
12322         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12323         feature_flags = dev_info.feature_flags;
12324
12325         if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
12326                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
12327                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
12328                 return TEST_SKIPPED;
12329
12330         if (fragsz > tdata->plaintext.len)
12331                 fragsz = tdata->plaintext.len;
12332
12333         uint16_t plaintext_len = fragsz;
12334
12335         retval = create_gmac_session(ts_params->valid_devs[0],
12336                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12337
12338         if (retval < 0)
12339                 return retval;
12340
12341         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12342         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12343                         "Failed to allocate input buffer in mempool");
12344
12345         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12346                         rte_pktmbuf_tailroom(ut_params->ibuf));
12347
12348         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12349                                 plaintext_len);
12350         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12351
12352         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12353
12354         trn_data += plaintext_len;
12355
12356         buf = ut_params->ibuf;
12357
12358         /*
12359          * Loop until no more fragments
12360          */
12361
12362         while (trn_data < tdata->plaintext.len) {
12363                 ++segs;
12364                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
12365                                 (tdata->plaintext.len - trn_data) : fragsz;
12366
12367                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12368                 buf = buf->next;
12369
12370                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
12371                                 rte_pktmbuf_tailroom(buf));
12372
12373                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
12374                                 to_trn);
12375
12376                 memcpy(plaintext, tdata->plaintext.data + trn_data,
12377                                 to_trn);
12378                 trn_data += to_trn;
12379                 if (trn_data  == tdata->plaintext.len)
12380                         digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
12381                                         tdata->gmac_tag.len);
12382         }
12383         ut_params->ibuf->nb_segs = segs;
12384
12385         /*
12386          * Place digest at the end of the last buffer
12387          */
12388         uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
12389
12390         if (!digest_mem) {
12391                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12392                                 + tdata->gmac_tag.len);
12393                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
12394                                 tdata->plaintext.len);
12395         }
12396
12397         retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
12398                         tdata, digest_mem, digest_phys);
12399
12400         if (retval < 0)
12401                 return retval;
12402
12403         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12404
12405         ut_params->op->sym->m_src = ut_params->ibuf;
12406
12407         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12408                 return TEST_SKIPPED;
12409
12410         TEST_ASSERT_NOT_NULL(
12411                 process_crypto_request(ts_params->valid_devs[0],
12412                 ut_params->op), "failed to process sym crypto op");
12413
12414         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12415                         "crypto op processing failed");
12416
12417         auth_tag = digest_mem;
12418         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12419         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12420                         auth_tag,
12421                         tdata->gmac_tag.data,
12422                         tdata->gmac_tag.len,
12423                         "GMAC Generated auth tag not as expected");
12424
12425         return 0;
12426 }
12427
12428 /* Segment size not multiple of block size (16B) */
12429 static int
12430 test_AES_GMAC_authentication_SGL_40B(void)
12431 {
12432         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
12433 }
12434
12435 static int
12436 test_AES_GMAC_authentication_SGL_80B(void)
12437 {
12438         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
12439 }
12440
12441 static int
12442 test_AES_GMAC_authentication_SGL_2048B(void)
12443 {
12444         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
12445 }
12446
12447 /* Segment size not multiple of block size (16B) */
12448 static int
12449 test_AES_GMAC_authentication_SGL_2047B(void)
12450 {
12451         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
12452 }
12453
12454 struct test_crypto_vector {
12455         enum rte_crypto_cipher_algorithm crypto_algo;
12456         unsigned int cipher_offset;
12457         unsigned int cipher_len;
12458
12459         struct {
12460                 uint8_t data[64];
12461                 unsigned int len;
12462         } cipher_key;
12463
12464         struct {
12465                 uint8_t data[64];
12466                 unsigned int len;
12467         } iv;
12468
12469         struct {
12470                 const uint8_t *data;
12471                 unsigned int len;
12472         } plaintext;
12473
12474         struct {
12475                 const uint8_t *data;
12476                 unsigned int len;
12477         } ciphertext;
12478
12479         enum rte_crypto_auth_algorithm auth_algo;
12480         unsigned int auth_offset;
12481
12482         struct {
12483                 uint8_t data[128];
12484                 unsigned int len;
12485         } auth_key;
12486
12487         struct {
12488                 const uint8_t *data;
12489                 unsigned int len;
12490         } aad;
12491
12492         struct {
12493                 uint8_t data[128];
12494                 unsigned int len;
12495         } digest;
12496 };
12497
12498 static const struct test_crypto_vector
12499 hmac_sha1_test_crypto_vector = {
12500         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12501         .plaintext = {
12502                 .data = plaintext_hash,
12503                 .len = 512
12504         },
12505         .auth_key = {
12506                 .data = {
12507                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12508                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12509                         0xDE, 0xF4, 0xDE, 0xAD
12510                 },
12511                 .len = 20
12512         },
12513         .digest = {
12514                 .data = {
12515                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
12516                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
12517                         0x3F, 0x91, 0x64, 0x59
12518                 },
12519                 .len = 20
12520         }
12521 };
12522
12523 static const struct test_crypto_vector
12524 aes128_gmac_test_vector = {
12525         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
12526         .plaintext = {
12527                 .data = plaintext_hash,
12528                 .len = 512
12529         },
12530         .iv = {
12531                 .data = {
12532                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12533                         0x08, 0x09, 0x0A, 0x0B
12534                 },
12535                 .len = 12
12536         },
12537         .auth_key = {
12538                 .data = {
12539                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12540                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
12541                 },
12542                 .len = 16
12543         },
12544         .digest = {
12545                 .data = {
12546                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
12547                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
12548                 },
12549                 .len = 16
12550         }
12551 };
12552
12553 static const struct test_crypto_vector
12554 aes128cbc_hmac_sha1_test_vector = {
12555         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12556         .cipher_offset = 0,
12557         .cipher_len = 512,
12558         .cipher_key = {
12559                 .data = {
12560                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12561                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12562                 },
12563                 .len = 16
12564         },
12565         .iv = {
12566                 .data = {
12567                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12568                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12569                 },
12570                 .len = 16
12571         },
12572         .plaintext = {
12573                 .data = plaintext_hash,
12574                 .len = 512
12575         },
12576         .ciphertext = {
12577                 .data = ciphertext512_aes128cbc,
12578                 .len = 512
12579         },
12580         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12581         .auth_offset = 0,
12582         .auth_key = {
12583                 .data = {
12584                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12585                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12586                         0xDE, 0xF4, 0xDE, 0xAD
12587                 },
12588                 .len = 20
12589         },
12590         .digest = {
12591                 .data = {
12592                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12593                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12594                         0x18, 0x8C, 0x1D, 0x32
12595                 },
12596                 .len = 20
12597         }
12598 };
12599
12600 static const struct test_crypto_vector
12601 aes128cbc_hmac_sha1_aad_test_vector = {
12602         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12603         .cipher_offset = 8,
12604         .cipher_len = 496,
12605         .cipher_key = {
12606                 .data = {
12607                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12608                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12609                 },
12610                 .len = 16
12611         },
12612         .iv = {
12613                 .data = {
12614                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12615                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12616                 },
12617                 .len = 16
12618         },
12619         .plaintext = {
12620                 .data = plaintext_hash,
12621                 .len = 512
12622         },
12623         .ciphertext = {
12624                 .data = ciphertext512_aes128cbc_aad,
12625                 .len = 512
12626         },
12627         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12628         .auth_offset = 0,
12629         .auth_key = {
12630                 .data = {
12631                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12632                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12633                         0xDE, 0xF4, 0xDE, 0xAD
12634                 },
12635                 .len = 20
12636         },
12637         .digest = {
12638                 .data = {
12639                         0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12640                         0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12641                         0x62, 0x0F, 0xFB, 0x10
12642                 },
12643                 .len = 20
12644         }
12645 };
12646
12647 static void
12648 data_corruption(uint8_t *data)
12649 {
12650         data[0] += 1;
12651 }
12652
12653 static void
12654 tag_corruption(uint8_t *data, unsigned int tag_offset)
12655 {
12656         data[tag_offset] += 1;
12657 }
12658
12659 static int
12660 create_auth_session(struct crypto_unittest_params *ut_params,
12661                 uint8_t dev_id,
12662                 const struct test_crypto_vector *reference,
12663                 enum rte_crypto_auth_operation auth_op)
12664 {
12665         struct crypto_testsuite_params *ts_params = &testsuite_params;
12666         uint8_t auth_key[reference->auth_key.len + 1];
12667
12668         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12669
12670         /* Setup Authentication Parameters */
12671         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12672         ut_params->auth_xform.auth.op = auth_op;
12673         ut_params->auth_xform.next = NULL;
12674         ut_params->auth_xform.auth.algo = reference->auth_algo;
12675         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12676         ut_params->auth_xform.auth.key.data = auth_key;
12677         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12678
12679         /* Create Crypto session*/
12680         ut_params->sess = rte_cryptodev_sym_session_create(
12681                         ts_params->session_mpool);
12682
12683         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12684                                 &ut_params->auth_xform,
12685                                 ts_params->session_priv_mpool);
12686
12687         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12688
12689         return 0;
12690 }
12691
12692 static int
12693 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12694                 uint8_t dev_id,
12695                 const struct test_crypto_vector *reference,
12696                 enum rte_crypto_auth_operation auth_op,
12697                 enum rte_crypto_cipher_operation cipher_op)
12698 {
12699         struct crypto_testsuite_params *ts_params = &testsuite_params;
12700         uint8_t cipher_key[reference->cipher_key.len + 1];
12701         uint8_t auth_key[reference->auth_key.len + 1];
12702
12703         memcpy(cipher_key, reference->cipher_key.data,
12704                         reference->cipher_key.len);
12705         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12706
12707         /* Setup Authentication Parameters */
12708         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12709         ut_params->auth_xform.auth.op = auth_op;
12710         ut_params->auth_xform.auth.algo = reference->auth_algo;
12711         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12712         ut_params->auth_xform.auth.key.data = auth_key;
12713         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12714
12715         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12716                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12717                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
12718         } else {
12719                 ut_params->auth_xform.next = &ut_params->cipher_xform;
12720
12721                 /* Setup Cipher Parameters */
12722                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12723                 ut_params->cipher_xform.next = NULL;
12724                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12725                 ut_params->cipher_xform.cipher.op = cipher_op;
12726                 ut_params->cipher_xform.cipher.key.data = cipher_key;
12727                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12728                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12729                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12730         }
12731
12732         /* Create Crypto session*/
12733         ut_params->sess = rte_cryptodev_sym_session_create(
12734                         ts_params->session_mpool);
12735
12736         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12737                                 &ut_params->auth_xform,
12738                                 ts_params->session_priv_mpool);
12739
12740         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12741
12742         return 0;
12743 }
12744
12745 static int
12746 create_auth_operation(struct crypto_testsuite_params *ts_params,
12747                 struct crypto_unittest_params *ut_params,
12748                 const struct test_crypto_vector *reference,
12749                 unsigned int auth_generate)
12750 {
12751         /* Generate Crypto op data structure */
12752         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12753                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12754         TEST_ASSERT_NOT_NULL(ut_params->op,
12755                         "Failed to allocate pktmbuf offload");
12756
12757         /* Set crypto operation data parameters */
12758         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12759
12760         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12761
12762         /* set crypto operation source mbuf */
12763         sym_op->m_src = ut_params->ibuf;
12764
12765         /* digest */
12766         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12767                         ut_params->ibuf, reference->digest.len);
12768
12769         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12770                         "no room to append auth tag");
12771
12772         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12773                         ut_params->ibuf, reference->plaintext.len);
12774
12775         if (auth_generate)
12776                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12777         else
12778                 memcpy(sym_op->auth.digest.data,
12779                                 reference->digest.data,
12780                                 reference->digest.len);
12781
12782         debug_hexdump(stdout, "digest:",
12783                         sym_op->auth.digest.data,
12784                         reference->digest.len);
12785
12786         sym_op->auth.data.length = reference->plaintext.len;
12787         sym_op->auth.data.offset = 0;
12788
12789         return 0;
12790 }
12791
12792 static int
12793 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12794                 struct crypto_unittest_params *ut_params,
12795                 const struct test_crypto_vector *reference,
12796                 unsigned int auth_generate)
12797 {
12798         /* Generate Crypto op data structure */
12799         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12800                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12801         TEST_ASSERT_NOT_NULL(ut_params->op,
12802                         "Failed to allocate pktmbuf offload");
12803
12804         /* Set crypto operation data parameters */
12805         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12806
12807         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12808
12809         /* set crypto operation source mbuf */
12810         sym_op->m_src = ut_params->ibuf;
12811
12812         /* digest */
12813         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12814                         ut_params->ibuf, reference->digest.len);
12815
12816         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12817                         "no room to append auth tag");
12818
12819         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12820                         ut_params->ibuf, reference->ciphertext.len);
12821
12822         if (auth_generate)
12823                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12824         else
12825                 memcpy(sym_op->auth.digest.data,
12826                                 reference->digest.data,
12827                                 reference->digest.len);
12828
12829         debug_hexdump(stdout, "digest:",
12830                         sym_op->auth.digest.data,
12831                         reference->digest.len);
12832
12833         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12834                         reference->iv.data, reference->iv.len);
12835
12836         sym_op->cipher.data.length = 0;
12837         sym_op->cipher.data.offset = 0;
12838
12839         sym_op->auth.data.length = reference->plaintext.len;
12840         sym_op->auth.data.offset = 0;
12841
12842         return 0;
12843 }
12844
12845 static int
12846 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12847                 struct crypto_unittest_params *ut_params,
12848                 const struct test_crypto_vector *reference,
12849                 unsigned int auth_generate)
12850 {
12851         /* Generate Crypto op data structure */
12852         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12853                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12854         TEST_ASSERT_NOT_NULL(ut_params->op,
12855                         "Failed to allocate pktmbuf offload");
12856
12857         /* Set crypto operation data parameters */
12858         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12859
12860         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12861
12862         /* set crypto operation source mbuf */
12863         sym_op->m_src = ut_params->ibuf;
12864
12865         /* digest */
12866         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12867                         ut_params->ibuf, reference->digest.len);
12868
12869         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12870                         "no room to append auth tag");
12871
12872         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12873                         ut_params->ibuf, reference->ciphertext.len);
12874
12875         if (auth_generate)
12876                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12877         else
12878                 memcpy(sym_op->auth.digest.data,
12879                                 reference->digest.data,
12880                                 reference->digest.len);
12881
12882         debug_hexdump(stdout, "digest:",
12883                         sym_op->auth.digest.data,
12884                         reference->digest.len);
12885
12886         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12887                         reference->iv.data, reference->iv.len);
12888
12889         sym_op->cipher.data.length = reference->cipher_len;
12890         sym_op->cipher.data.offset = reference->cipher_offset;
12891
12892         sym_op->auth.data.length = reference->plaintext.len;
12893         sym_op->auth.data.offset = reference->auth_offset;
12894
12895         return 0;
12896 }
12897
12898 static int
12899 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12900                 struct crypto_unittest_params *ut_params,
12901                 const struct test_crypto_vector *reference)
12902 {
12903         return create_auth_operation(ts_params, ut_params, reference, 0);
12904 }
12905
12906 static int
12907 create_auth_verify_GMAC_operation(
12908                 struct crypto_testsuite_params *ts_params,
12909                 struct crypto_unittest_params *ut_params,
12910                 const struct test_crypto_vector *reference)
12911 {
12912         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
12913 }
12914
12915 static int
12916 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12917                 struct crypto_unittest_params *ut_params,
12918                 const struct test_crypto_vector *reference)
12919 {
12920         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12921 }
12922
12923 static int
12924 test_authentication_verify_fail_when_data_corruption(
12925                 struct crypto_testsuite_params *ts_params,
12926                 struct crypto_unittest_params *ut_params,
12927                 const struct test_crypto_vector *reference,
12928                 unsigned int data_corrupted)
12929 {
12930         int retval;
12931
12932         uint8_t *plaintext;
12933         struct rte_cryptodev_info dev_info;
12934
12935         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12936         uint64_t feat_flags = dev_info.feature_flags;
12937
12938         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12939                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12940                 printf("Device doesn't support RAW data-path APIs.\n");
12941                 return TEST_SKIPPED;
12942         }
12943
12944         /* Verify the capabilities */
12945         struct rte_cryptodev_sym_capability_idx cap_idx;
12946         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12947         cap_idx.algo.auth = reference->auth_algo;
12948         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12949                         &cap_idx) == NULL)
12950                 return TEST_SKIPPED;
12951
12952
12953         /* Create session */
12954         retval = create_auth_session(ut_params,
12955                         ts_params->valid_devs[0],
12956                         reference,
12957                         RTE_CRYPTO_AUTH_OP_VERIFY);
12958         if (retval < 0)
12959                 return retval;
12960
12961         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12962         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12963                         "Failed to allocate input buffer in mempool");
12964
12965         /* clear mbuf payload */
12966         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12967                         rte_pktmbuf_tailroom(ut_params->ibuf));
12968
12969         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12970                         reference->plaintext.len);
12971         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12972         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12973
12974         debug_hexdump(stdout, "plaintext:", plaintext,
12975                 reference->plaintext.len);
12976
12977         /* Create operation */
12978         retval = create_auth_verify_operation(ts_params, ut_params, reference);
12979
12980         if (retval < 0)
12981                 return retval;
12982
12983         if (data_corrupted)
12984                 data_corruption(plaintext);
12985         else
12986                 tag_corruption(plaintext, reference->plaintext.len);
12987
12988         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12989                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12990                         ut_params->op);
12991                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12992                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12993                         "authentication not failed");
12994         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12995                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12996                                 ut_params->op, 0, 1, 0, 0);
12997         else {
12998                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12999                         ut_params->op);
13000                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13001         }
13002
13003         return 0;
13004 }
13005
13006 static int
13007 test_authentication_verify_GMAC_fail_when_corruption(
13008                 struct crypto_testsuite_params *ts_params,
13009                 struct crypto_unittest_params *ut_params,
13010                 const struct test_crypto_vector *reference,
13011                 unsigned int data_corrupted)
13012 {
13013         int retval;
13014         uint8_t *plaintext;
13015         struct rte_cryptodev_info dev_info;
13016
13017         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13018         uint64_t feat_flags = dev_info.feature_flags;
13019
13020         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13021                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13022                 printf("Device doesn't support RAW data-path APIs.\n");
13023                 return TEST_SKIPPED;
13024         }
13025
13026         /* Verify the capabilities */
13027         struct rte_cryptodev_sym_capability_idx cap_idx;
13028         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13029         cap_idx.algo.auth = reference->auth_algo;
13030         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13031                         &cap_idx) == NULL)
13032                 return TEST_SKIPPED;
13033
13034         /* Create session */
13035         retval = create_auth_cipher_session(ut_params,
13036                         ts_params->valid_devs[0],
13037                         reference,
13038                         RTE_CRYPTO_AUTH_OP_VERIFY,
13039                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
13040         if (retval < 0)
13041                 return retval;
13042
13043         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13044         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13045                         "Failed to allocate input buffer in mempool");
13046
13047         /* clear mbuf payload */
13048         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13049                         rte_pktmbuf_tailroom(ut_params->ibuf));
13050
13051         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13052                         reference->plaintext.len);
13053         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13054         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13055
13056         debug_hexdump(stdout, "plaintext:", plaintext,
13057                 reference->plaintext.len);
13058
13059         /* Create operation */
13060         retval = create_auth_verify_GMAC_operation(ts_params,
13061                         ut_params,
13062                         reference);
13063
13064         if (retval < 0)
13065                 return retval;
13066
13067         if (data_corrupted)
13068                 data_corruption(plaintext);
13069         else
13070                 tag_corruption(plaintext, reference->aad.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, 0, 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_decryption_fail_when_corruption(
13092                 struct crypto_testsuite_params *ts_params,
13093                 struct crypto_unittest_params *ut_params,
13094                 const struct test_crypto_vector *reference,
13095                 unsigned int data_corrupted)
13096 {
13097         int retval;
13098
13099         uint8_t *ciphertext;
13100         struct rte_cryptodev_info dev_info;
13101
13102         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13103         uint64_t feat_flags = dev_info.feature_flags;
13104
13105         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13106                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13107                 printf("Device doesn't support RAW data-path APIs.\n");
13108                 return TEST_SKIPPED;
13109         }
13110
13111         /* Verify the capabilities */
13112         struct rte_cryptodev_sym_capability_idx cap_idx;
13113         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13114         cap_idx.algo.auth = reference->auth_algo;
13115         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13116                         &cap_idx) == NULL)
13117                 return TEST_SKIPPED;
13118         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13119         cap_idx.algo.cipher = reference->crypto_algo;
13120         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13121                         &cap_idx) == NULL)
13122                 return TEST_SKIPPED;
13123
13124         /* Create session */
13125         retval = create_auth_cipher_session(ut_params,
13126                         ts_params->valid_devs[0],
13127                         reference,
13128                         RTE_CRYPTO_AUTH_OP_VERIFY,
13129                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
13130         if (retval < 0)
13131                 return retval;
13132
13133         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13134         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13135                         "Failed to allocate input buffer in mempool");
13136
13137         /* clear mbuf payload */
13138         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13139                         rte_pktmbuf_tailroom(ut_params->ibuf));
13140
13141         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13142                         reference->ciphertext.len);
13143         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13144         memcpy(ciphertext, reference->ciphertext.data,
13145                         reference->ciphertext.len);
13146
13147         /* Create operation */
13148         retval = create_cipher_auth_verify_operation(ts_params,
13149                         ut_params,
13150                         reference);
13151
13152         if (retval < 0)
13153                 return retval;
13154
13155         if (data_corrupted)
13156                 data_corruption(ciphertext);
13157         else
13158                 tag_corruption(ciphertext, reference->ciphertext.len);
13159
13160         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13161                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13162                         ut_params->op);
13163                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13164                         RTE_CRYPTO_OP_STATUS_SUCCESS,
13165                         "authentication not failed");
13166         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13167                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13168                                 ut_params->op, 1, 1, 0, 0);
13169         else {
13170                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13171                         ut_params->op);
13172                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13173         }
13174
13175         return 0;
13176 }
13177
13178 static int
13179 test_authenticated_encrypt_with_esn(
13180                 struct crypto_testsuite_params *ts_params,
13181                 struct crypto_unittest_params *ut_params,
13182                 const struct test_crypto_vector *reference)
13183 {
13184         int retval;
13185
13186         uint8_t *authciphertext, *plaintext, *auth_tag;
13187         uint16_t plaintext_pad_len;
13188         uint8_t cipher_key[reference->cipher_key.len + 1];
13189         uint8_t auth_key[reference->auth_key.len + 1];
13190         struct rte_cryptodev_info dev_info;
13191
13192         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13193         uint64_t feat_flags = dev_info.feature_flags;
13194
13195         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13196                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13197                 printf("Device doesn't support RAW data-path APIs.\n");
13198                 return TEST_SKIPPED;
13199         }
13200
13201         /* Verify the capabilities */
13202         struct rte_cryptodev_sym_capability_idx cap_idx;
13203         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13204         cap_idx.algo.auth = reference->auth_algo;
13205         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13206                         &cap_idx) == NULL)
13207                 return TEST_SKIPPED;
13208         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13209         cap_idx.algo.cipher = reference->crypto_algo;
13210         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13211                         &cap_idx) == NULL)
13212                 return TEST_SKIPPED;
13213
13214         /* Create session */
13215         memcpy(cipher_key, reference->cipher_key.data,
13216                         reference->cipher_key.len);
13217         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13218
13219         /* Setup Cipher Parameters */
13220         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13221         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13222         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
13223         ut_params->cipher_xform.cipher.key.data = cipher_key;
13224         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13225         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13226         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13227
13228         ut_params->cipher_xform.next = &ut_params->auth_xform;
13229
13230         /* Setup Authentication Parameters */
13231         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13232         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
13233         ut_params->auth_xform.auth.algo = reference->auth_algo;
13234         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13235         ut_params->auth_xform.auth.key.data = auth_key;
13236         ut_params->auth_xform.auth.digest_length = reference->digest.len;
13237         ut_params->auth_xform.next = NULL;
13238
13239         /* Create Crypto session*/
13240         ut_params->sess = rte_cryptodev_sym_session_create(
13241                         ts_params->session_mpool);
13242
13243         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13244                                 ut_params->sess,
13245                                 &ut_params->cipher_xform,
13246                                 ts_params->session_priv_mpool);
13247
13248         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13249
13250         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13251         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13252                         "Failed to allocate input buffer in mempool");
13253
13254         /* clear mbuf payload */
13255         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13256                         rte_pktmbuf_tailroom(ut_params->ibuf));
13257
13258         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13259                         reference->plaintext.len);
13260         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13261         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13262
13263         /* Create operation */
13264         retval = create_cipher_auth_operation(ts_params,
13265                         ut_params,
13266                         reference, 0);
13267
13268         if (retval < 0)
13269                 return retval;
13270
13271         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13272                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13273                         ut_params->op);
13274         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13275                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13276                                 ut_params->op, 1, 1, 0, 0);
13277         else
13278                 ut_params->op = process_crypto_request(
13279                         ts_params->valid_devs[0], ut_params->op);
13280
13281         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
13282
13283         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13284                         "crypto op processing failed");
13285
13286         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
13287
13288         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
13289                         ut_params->op->sym->auth.data.offset);
13290         auth_tag = authciphertext + plaintext_pad_len;
13291         debug_hexdump(stdout, "ciphertext:", authciphertext,
13292                         reference->ciphertext.len);
13293         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
13294
13295         /* Validate obuf */
13296         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13297                         authciphertext,
13298                         reference->ciphertext.data,
13299                         reference->ciphertext.len,
13300                         "Ciphertext data not as expected");
13301
13302         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13303                         auth_tag,
13304                         reference->digest.data,
13305                         reference->digest.len,
13306                         "Generated digest not as expected");
13307
13308         return TEST_SUCCESS;
13309
13310 }
13311
13312 static int
13313 test_authenticated_decrypt_with_esn(
13314                 struct crypto_testsuite_params *ts_params,
13315                 struct crypto_unittest_params *ut_params,
13316                 const struct test_crypto_vector *reference)
13317 {
13318         int retval;
13319
13320         uint8_t *ciphertext;
13321         uint8_t cipher_key[reference->cipher_key.len + 1];
13322         uint8_t auth_key[reference->auth_key.len + 1];
13323         struct rte_cryptodev_info dev_info;
13324
13325         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13326         uint64_t feat_flags = dev_info.feature_flags;
13327
13328         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13329                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13330                 printf("Device doesn't support RAW data-path APIs.\n");
13331                 return TEST_SKIPPED;
13332         }
13333
13334         /* Verify the capabilities */
13335         struct rte_cryptodev_sym_capability_idx cap_idx;
13336         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13337         cap_idx.algo.auth = reference->auth_algo;
13338         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13339                         &cap_idx) == NULL)
13340                 return TEST_SKIPPED;
13341         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13342         cap_idx.algo.cipher = reference->crypto_algo;
13343         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13344                         &cap_idx) == NULL)
13345                 return TEST_SKIPPED;
13346
13347         /* Create session */
13348         memcpy(cipher_key, reference->cipher_key.data,
13349                         reference->cipher_key.len);
13350         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13351
13352         /* Setup Authentication Parameters */
13353         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13354         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
13355         ut_params->auth_xform.auth.algo = reference->auth_algo;
13356         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13357         ut_params->auth_xform.auth.key.data = auth_key;
13358         ut_params->auth_xform.auth.digest_length = reference->digest.len;
13359         ut_params->auth_xform.next = &ut_params->cipher_xform;
13360
13361         /* Setup Cipher Parameters */
13362         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13363         ut_params->cipher_xform.next = NULL;
13364         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13365         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
13366         ut_params->cipher_xform.cipher.key.data = cipher_key;
13367         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13368         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13369         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13370
13371         /* Create Crypto session*/
13372         ut_params->sess = rte_cryptodev_sym_session_create(
13373                         ts_params->session_mpool);
13374
13375         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13376                                 ut_params->sess,
13377                                 &ut_params->auth_xform,
13378                                 ts_params->session_priv_mpool);
13379
13380         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13381
13382         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13383         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13384                         "Failed to allocate input buffer in mempool");
13385
13386         /* clear mbuf payload */
13387         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13388                         rte_pktmbuf_tailroom(ut_params->ibuf));
13389
13390         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13391                         reference->ciphertext.len);
13392         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13393         memcpy(ciphertext, reference->ciphertext.data,
13394                         reference->ciphertext.len);
13395
13396         /* Create operation */
13397         retval = create_cipher_auth_verify_operation(ts_params,
13398                         ut_params,
13399                         reference);
13400
13401         if (retval < 0)
13402                 return retval;
13403
13404         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13405                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13406                         ut_params->op);
13407         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13408                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13409                                 ut_params->op, 1, 1, 0, 0);
13410         else
13411                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13412                         ut_params->op);
13413
13414         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
13415         TEST_ASSERT_EQUAL(ut_params->op->status,
13416                         RTE_CRYPTO_OP_STATUS_SUCCESS,
13417                         "crypto op processing passed");
13418
13419         ut_params->obuf = ut_params->op->sym->m_src;
13420         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
13421
13422         return 0;
13423 }
13424
13425 static int
13426 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
13427                 const struct aead_test_data *tdata,
13428                 void *digest_mem, uint64_t digest_phys)
13429 {
13430         struct crypto_testsuite_params *ts_params = &testsuite_params;
13431         struct crypto_unittest_params *ut_params = &unittest_params;
13432
13433         const unsigned int auth_tag_len = tdata->auth_tag.len;
13434         const unsigned int iv_len = tdata->iv.len;
13435         unsigned int aad_len = tdata->aad.len;
13436         unsigned int aad_len_pad = 0;
13437
13438         /* Generate Crypto op data structure */
13439         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13440                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13441         TEST_ASSERT_NOT_NULL(ut_params->op,
13442                 "Failed to allocate symmetric crypto operation struct");
13443
13444         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13445
13446         sym_op->aead.digest.data = digest_mem;
13447
13448         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
13449                         "no room to append digest");
13450
13451         sym_op->aead.digest.phys_addr = digest_phys;
13452
13453         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
13454                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
13455                                 auth_tag_len);
13456                 debug_hexdump(stdout, "digest:",
13457                                 sym_op->aead.digest.data,
13458                                 auth_tag_len);
13459         }
13460
13461         /* Append aad data */
13462         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
13463                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13464                                 uint8_t *, IV_OFFSET);
13465
13466                 /* Copy IV 1 byte after the IV pointer, according to the API */
13467                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
13468
13469                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
13470
13471                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13472                                 ut_params->ibuf, aad_len);
13473                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13474                                 "no room to prepend aad");
13475                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13476                                 ut_params->ibuf);
13477
13478                 memset(sym_op->aead.aad.data, 0, aad_len);
13479                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
13480                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13481
13482                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13483                 debug_hexdump(stdout, "aad:",
13484                                 sym_op->aead.aad.data, aad_len);
13485         } else {
13486                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13487                                 uint8_t *, IV_OFFSET);
13488
13489                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
13490
13491                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
13492
13493                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13494                                 ut_params->ibuf, aad_len_pad);
13495                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13496                                 "no room to prepend aad");
13497                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13498                                 ut_params->ibuf);
13499
13500                 memset(sym_op->aead.aad.data, 0, aad_len);
13501                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13502
13503                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13504                 debug_hexdump(stdout, "aad:",
13505                                 sym_op->aead.aad.data, aad_len);
13506         }
13507
13508         sym_op->aead.data.length = tdata->plaintext.len;
13509         sym_op->aead.data.offset = aad_len_pad;
13510
13511         return 0;
13512 }
13513
13514 #define SGL_MAX_NO      16
13515
13516 static int
13517 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
13518                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
13519 {
13520         struct crypto_testsuite_params *ts_params = &testsuite_params;
13521         struct crypto_unittest_params *ut_params = &unittest_params;
13522         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
13523         int retval;
13524         int to_trn = 0;
13525         int to_trn_tbl[SGL_MAX_NO];
13526         int segs = 1;
13527         unsigned int trn_data = 0;
13528         uint8_t *plaintext, *ciphertext, *auth_tag;
13529         struct rte_cryptodev_info dev_info;
13530
13531         /* Verify the capabilities */
13532         struct rte_cryptodev_sym_capability_idx cap_idx;
13533         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13534         cap_idx.algo.aead = tdata->algo;
13535         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13536                         &cap_idx) == NULL)
13537                 return TEST_SKIPPED;
13538
13539         /* OOP not supported with CPU crypto */
13540         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13541                 return TEST_SKIPPED;
13542
13543         /* Detailed check for the particular SGL support flag */
13544         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13545         if (!oop) {
13546                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
13547                 if (sgl_in && (!(dev_info.feature_flags &
13548                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
13549                         return TEST_SKIPPED;
13550
13551                 uint64_t feat_flags = dev_info.feature_flags;
13552
13553                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13554                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13555                         printf("Device doesn't support RAW data-path APIs.\n");
13556                         return TEST_SKIPPED;
13557                 }
13558         } else {
13559                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
13560                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
13561                                 tdata->plaintext.len;
13562                 /* Raw data path API does not support OOP */
13563                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13564                         return TEST_SKIPPED;
13565                 if (sgl_in && !sgl_out) {
13566                         if (!(dev_info.feature_flags &
13567                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
13568                                 return TEST_SKIPPED;
13569                 } else if (!sgl_in && sgl_out) {
13570                         if (!(dev_info.feature_flags &
13571                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
13572                                 return TEST_SKIPPED;
13573                 } else if (sgl_in && sgl_out) {
13574                         if (!(dev_info.feature_flags &
13575                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13576                                 return TEST_SKIPPED;
13577                 }
13578         }
13579
13580         if (fragsz > tdata->plaintext.len)
13581                 fragsz = tdata->plaintext.len;
13582
13583         uint16_t plaintext_len = fragsz;
13584         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13585
13586         if (fragsz_oop > tdata->plaintext.len)
13587                 frag_size_oop = tdata->plaintext.len;
13588
13589         int ecx = 0;
13590         void *digest_mem = NULL;
13591
13592         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13593
13594         if (tdata->plaintext.len % fragsz != 0) {
13595                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13596                         return 1;
13597         }       else {
13598                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13599                         return 1;
13600         }
13601
13602         /*
13603          * For out-op-place we need to alloc another mbuf
13604          */
13605         if (oop) {
13606                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13607                 rte_pktmbuf_append(ut_params->obuf,
13608                                 frag_size_oop + prepend_len);
13609                 buf_oop = ut_params->obuf;
13610         }
13611
13612         /* Create AEAD session */
13613         retval = create_aead_session(ts_params->valid_devs[0],
13614                         tdata->algo,
13615                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
13616                         tdata->key.data, tdata->key.len,
13617                         tdata->aad.len, tdata->auth_tag.len,
13618                         tdata->iv.len);
13619         if (retval < 0)
13620                 return retval;
13621
13622         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13623
13624         /* clear mbuf payload */
13625         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13626                         rte_pktmbuf_tailroom(ut_params->ibuf));
13627
13628         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13629                         plaintext_len);
13630
13631         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13632
13633         trn_data += plaintext_len;
13634
13635         buf = ut_params->ibuf;
13636
13637         /*
13638          * Loop until no more fragments
13639          */
13640
13641         while (trn_data < tdata->plaintext.len) {
13642                 ++segs;
13643                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13644                                 (tdata->plaintext.len - trn_data) : fragsz;
13645
13646                 to_trn_tbl[ecx++] = to_trn;
13647
13648                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13649                 buf = buf->next;
13650
13651                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13652                                 rte_pktmbuf_tailroom(buf));
13653
13654                 /* OOP */
13655                 if (oop && !fragsz_oop) {
13656                         buf_last_oop = buf_oop->next =
13657                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13658                         buf_oop = buf_oop->next;
13659                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13660                                         0, rte_pktmbuf_tailroom(buf_oop));
13661                         rte_pktmbuf_append(buf_oop, to_trn);
13662                 }
13663
13664                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13665                                 to_trn);
13666
13667                 memcpy(plaintext, tdata->plaintext.data + trn_data,
13668                                 to_trn);
13669                 trn_data += to_trn;
13670                 if (trn_data  == tdata->plaintext.len) {
13671                         if (oop) {
13672                                 if (!fragsz_oop)
13673                                         digest_mem = rte_pktmbuf_append(buf_oop,
13674                                                 tdata->auth_tag.len);
13675                         } else
13676                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13677                                         tdata->auth_tag.len);
13678                 }
13679         }
13680
13681         uint64_t digest_phys = 0;
13682
13683         ut_params->ibuf->nb_segs = segs;
13684
13685         segs = 1;
13686         if (fragsz_oop && oop) {
13687                 to_trn = 0;
13688                 ecx = 0;
13689
13690                 if (frag_size_oop == tdata->plaintext.len) {
13691                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
13692                                 tdata->auth_tag.len);
13693
13694                         digest_phys = rte_pktmbuf_iova_offset(
13695                                         ut_params->obuf,
13696                                         tdata->plaintext.len + prepend_len);
13697                 }
13698
13699                 trn_data = frag_size_oop;
13700                 while (trn_data < tdata->plaintext.len) {
13701                         ++segs;
13702                         to_trn =
13703                                 (tdata->plaintext.len - trn_data <
13704                                                 frag_size_oop) ?
13705                                 (tdata->plaintext.len - trn_data) :
13706                                                 frag_size_oop;
13707
13708                         to_trn_tbl[ecx++] = to_trn;
13709
13710                         buf_last_oop = buf_oop->next =
13711                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13712                         buf_oop = buf_oop->next;
13713                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13714                                         0, rte_pktmbuf_tailroom(buf_oop));
13715                         rte_pktmbuf_append(buf_oop, to_trn);
13716
13717                         trn_data += to_trn;
13718
13719                         if (trn_data  == tdata->plaintext.len) {
13720                                 digest_mem = rte_pktmbuf_append(buf_oop,
13721                                         tdata->auth_tag.len);
13722                         }
13723                 }
13724
13725                 ut_params->obuf->nb_segs = segs;
13726         }
13727
13728         /*
13729          * Place digest at the end of the last buffer
13730          */
13731         if (!digest_phys)
13732                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13733         if (oop && buf_last_oop)
13734                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13735
13736         if (!digest_mem && !oop) {
13737                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13738                                 + tdata->auth_tag.len);
13739                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13740                                 tdata->plaintext.len);
13741         }
13742
13743         /* Create AEAD operation */
13744         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13745                         tdata, digest_mem, digest_phys);
13746
13747         if (retval < 0)
13748                 return retval;
13749
13750         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13751
13752         ut_params->op->sym->m_src = ut_params->ibuf;
13753         if (oop)
13754                 ut_params->op->sym->m_dst = ut_params->obuf;
13755
13756         /* Process crypto operation */
13757         if (oop == IN_PLACE &&
13758                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13759                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13760         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13761                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13762                                 ut_params->op, 0, 0, 0, 0);
13763         else
13764                 TEST_ASSERT_NOT_NULL(
13765                         process_crypto_request(ts_params->valid_devs[0],
13766                         ut_params->op), "failed to process sym crypto op");
13767
13768         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13769                         "crypto op processing failed");
13770
13771
13772         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13773                         uint8_t *, prepend_len);
13774         if (oop) {
13775                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13776                                 uint8_t *, prepend_len);
13777         }
13778
13779         if (fragsz_oop)
13780                 fragsz = fragsz_oop;
13781
13782         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13783                         ciphertext,
13784                         tdata->ciphertext.data,
13785                         fragsz,
13786                         "Ciphertext data not as expected");
13787
13788         buf = ut_params->op->sym->m_src->next;
13789         if (oop)
13790                 buf = ut_params->op->sym->m_dst->next;
13791
13792         unsigned int off = fragsz;
13793
13794         ecx = 0;
13795         while (buf) {
13796                 ciphertext = rte_pktmbuf_mtod(buf,
13797                                 uint8_t *);
13798
13799                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
13800                                 ciphertext,
13801                                 tdata->ciphertext.data + off,
13802                                 to_trn_tbl[ecx],
13803                                 "Ciphertext data not as expected");
13804
13805                 off += to_trn_tbl[ecx++];
13806                 buf = buf->next;
13807         }
13808
13809         auth_tag = digest_mem;
13810         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13811                         auth_tag,
13812                         tdata->auth_tag.data,
13813                         tdata->auth_tag.len,
13814                         "Generated auth tag not as expected");
13815
13816         return 0;
13817 }
13818
13819 static int
13820 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13821 {
13822         return test_authenticated_encryption_SGL(
13823                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13824 }
13825
13826 static int
13827 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13828 {
13829         return test_authenticated_encryption_SGL(
13830                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13831 }
13832
13833 static int
13834 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13835 {
13836         return test_authenticated_encryption_SGL(
13837                         &gcm_test_case_8, OUT_OF_PLACE, 400,
13838                         gcm_test_case_8.plaintext.len);
13839 }
13840
13841 static int
13842 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13843 {
13844         /* This test is not for OPENSSL PMD */
13845         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13846                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13847                 return TEST_SKIPPED;
13848
13849         return test_authenticated_encryption_SGL(
13850                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13851 }
13852
13853 static int
13854 test_authentication_verify_fail_when_data_corrupted(
13855                 struct crypto_testsuite_params *ts_params,
13856                 struct crypto_unittest_params *ut_params,
13857                 const struct test_crypto_vector *reference)
13858 {
13859         return test_authentication_verify_fail_when_data_corruption(
13860                         ts_params, ut_params, reference, 1);
13861 }
13862
13863 static int
13864 test_authentication_verify_fail_when_tag_corrupted(
13865                 struct crypto_testsuite_params *ts_params,
13866                 struct crypto_unittest_params *ut_params,
13867                 const struct test_crypto_vector *reference)
13868 {
13869         return test_authentication_verify_fail_when_data_corruption(
13870                         ts_params, ut_params, reference, 0);
13871 }
13872
13873 static int
13874 test_authentication_verify_GMAC_fail_when_data_corrupted(
13875                 struct crypto_testsuite_params *ts_params,
13876                 struct crypto_unittest_params *ut_params,
13877                 const struct test_crypto_vector *reference)
13878 {
13879         return test_authentication_verify_GMAC_fail_when_corruption(
13880                         ts_params, ut_params, reference, 1);
13881 }
13882
13883 static int
13884 test_authentication_verify_GMAC_fail_when_tag_corrupted(
13885                 struct crypto_testsuite_params *ts_params,
13886                 struct crypto_unittest_params *ut_params,
13887                 const struct test_crypto_vector *reference)
13888 {
13889         return test_authentication_verify_GMAC_fail_when_corruption(
13890                         ts_params, ut_params, reference, 0);
13891 }
13892
13893 static int
13894 test_authenticated_decryption_fail_when_data_corrupted(
13895                 struct crypto_testsuite_params *ts_params,
13896                 struct crypto_unittest_params *ut_params,
13897                 const struct test_crypto_vector *reference)
13898 {
13899         return test_authenticated_decryption_fail_when_corruption(
13900                         ts_params, ut_params, reference, 1);
13901 }
13902
13903 static int
13904 test_authenticated_decryption_fail_when_tag_corrupted(
13905                 struct crypto_testsuite_params *ts_params,
13906                 struct crypto_unittest_params *ut_params,
13907                 const struct test_crypto_vector *reference)
13908 {
13909         return test_authenticated_decryption_fail_when_corruption(
13910                         ts_params, ut_params, reference, 0);
13911 }
13912
13913 static int
13914 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
13915 {
13916         return test_authentication_verify_fail_when_data_corrupted(
13917                         &testsuite_params, &unittest_params,
13918                         &hmac_sha1_test_crypto_vector);
13919 }
13920
13921 static int
13922 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13923 {
13924         return test_authentication_verify_fail_when_tag_corrupted(
13925                         &testsuite_params, &unittest_params,
13926                         &hmac_sha1_test_crypto_vector);
13927 }
13928
13929 static int
13930 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
13931 {
13932         return test_authentication_verify_GMAC_fail_when_data_corrupted(
13933                         &testsuite_params, &unittest_params,
13934                         &aes128_gmac_test_vector);
13935 }
13936
13937 static int
13938 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
13939 {
13940         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
13941                         &testsuite_params, &unittest_params,
13942                         &aes128_gmac_test_vector);
13943 }
13944
13945 static int
13946 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
13947 {
13948         return test_authenticated_decryption_fail_when_data_corrupted(
13949                         &testsuite_params,
13950                         &unittest_params,
13951                         &aes128cbc_hmac_sha1_test_vector);
13952 }
13953
13954 static int
13955 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
13956 {
13957         return test_authenticated_decryption_fail_when_tag_corrupted(
13958                         &testsuite_params,
13959                         &unittest_params,
13960                         &aes128cbc_hmac_sha1_test_vector);
13961 }
13962
13963 static int
13964 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13965 {
13966         return test_authenticated_encrypt_with_esn(
13967                         &testsuite_params,
13968                         &unittest_params,
13969                         &aes128cbc_hmac_sha1_aad_test_vector);
13970 }
13971
13972 static int
13973 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13974 {
13975         return test_authenticated_decrypt_with_esn(
13976                         &testsuite_params,
13977                         &unittest_params,
13978                         &aes128cbc_hmac_sha1_aad_test_vector);
13979 }
13980
13981 static int
13982 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
13983 {
13984         return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
13985 }
13986
13987 static int
13988 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
13989 {
13990         return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
13991 }
13992
13993 #ifdef RTE_CRYPTO_SCHEDULER
13994
13995 /* global AESNI worker IDs for the scheduler test */
13996 uint8_t aesni_ids[2];
13997
13998 static int
13999 scheduler_testsuite_setup(void)
14000 {
14001         uint32_t i = 0;
14002         int32_t nb_devs, ret;
14003         char vdev_args[VDEV_ARGS_SIZE] = {""};
14004         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
14005                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
14006         uint16_t worker_core_count = 0;
14007         uint16_t socket_id = 0;
14008
14009         if (gbl_driver_id == rte_cryptodev_driver_id_get(
14010                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
14011
14012                 /* Identify the Worker Cores
14013                  * Use 2 worker cores for the device args
14014                  */
14015                 RTE_LCORE_FOREACH_WORKER(i) {
14016                         if (worker_core_count > 1)
14017                                 break;
14018                         snprintf(vdev_args, sizeof(vdev_args),
14019                                         "%s%d", temp_str, i);
14020                         strcpy(temp_str, vdev_args);
14021                         strlcat(temp_str, ";", sizeof(temp_str));
14022                         worker_core_count++;
14023                         socket_id = rte_lcore_to_socket_id(i);
14024                 }
14025                 if (worker_core_count != 2) {
14026                         RTE_LOG(ERR, USER1,
14027                                 "Cryptodev scheduler test require at least "
14028                                 "two worker cores to run. "
14029                                 "Please use the correct coremask.\n");
14030                         return TEST_FAILED;
14031                 }
14032                 strcpy(temp_str, vdev_args);
14033                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
14034                                 temp_str, socket_id);
14035                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
14036                 nb_devs = rte_cryptodev_device_count_by_driver(
14037                                 rte_cryptodev_driver_id_get(
14038                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
14039                 if (nb_devs < 1) {
14040                         ret = rte_vdev_init(
14041                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
14042                                         vdev_args);
14043                         TEST_ASSERT(ret == 0,
14044                                 "Failed to create instance %u of pmd : %s",
14045                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14046                 }
14047         }
14048         return testsuite_setup();
14049 }
14050
14051 static int
14052 test_scheduler_attach_worker_op(void)
14053 {
14054         struct crypto_testsuite_params *ts_params = &testsuite_params;
14055         uint8_t sched_id = ts_params->valid_devs[0];
14056         uint32_t i, nb_devs_attached = 0;
14057         int ret;
14058         char vdev_name[32];
14059         unsigned int count = rte_cryptodev_count();
14060
14061         /* create 2 AESNI_MB vdevs on top of existing devices */
14062         for (i = count; i < count + 2; i++) {
14063                 snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
14064                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
14065                                 i);
14066                 ret = rte_vdev_init(vdev_name, NULL);
14067
14068                 TEST_ASSERT(ret == 0,
14069                         "Failed to create instance %u of"
14070                         " pmd : %s",
14071                         i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14072
14073                 if (ret < 0) {
14074                         RTE_LOG(ERR, USER1,
14075                                 "Failed to create 2 AESNI MB PMDs.\n");
14076                         return TEST_SKIPPED;
14077                 }
14078         }
14079
14080         /* attach 2 AESNI_MB cdevs */
14081         for (i = count; i < count + 2; i++) {
14082                 struct rte_cryptodev_info info;
14083                 unsigned int session_size;
14084
14085                 rte_cryptodev_info_get(i, &info);
14086                 if (info.driver_id != rte_cryptodev_driver_id_get(
14087                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
14088                         continue;
14089
14090                 session_size = rte_cryptodev_sym_get_private_session_size(i);
14091                 /*
14092                  * Create the session mempool again, since now there are new devices
14093                  * to use the mempool.
14094                  */
14095                 if (ts_params->session_mpool) {
14096                         rte_mempool_free(ts_params->session_mpool);
14097                         ts_params->session_mpool = NULL;
14098                 }
14099                 if (ts_params->session_priv_mpool) {
14100                         rte_mempool_free(ts_params->session_priv_mpool);
14101                         ts_params->session_priv_mpool = NULL;
14102                 }
14103
14104                 if (info.sym.max_nb_sessions != 0 &&
14105                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
14106                         RTE_LOG(ERR, USER1,
14107                                         "Device does not support "
14108                                         "at least %u sessions\n",
14109                                         MAX_NB_SESSIONS);
14110                         return TEST_FAILED;
14111                 }
14112                 /*
14113                  * Create mempool with maximum number of sessions,
14114                  * to include the session headers
14115                  */
14116                 if (ts_params->session_mpool == NULL) {
14117                         ts_params->session_mpool =
14118                                 rte_cryptodev_sym_session_pool_create(
14119                                                 "test_sess_mp",
14120                                                 MAX_NB_SESSIONS, 0, 0, 0,
14121                                                 SOCKET_ID_ANY);
14122                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
14123                                         "session mempool allocation failed");
14124                 }
14125
14126                 /*
14127                  * Create mempool with maximum number of sessions,
14128                  * to include device specific session private data
14129                  */
14130                 if (ts_params->session_priv_mpool == NULL) {
14131                         ts_params->session_priv_mpool = rte_mempool_create(
14132                                         "test_sess_mp_priv",
14133                                         MAX_NB_SESSIONS,
14134                                         session_size,
14135                                         0, 0, NULL, NULL, NULL,
14136                                         NULL, SOCKET_ID_ANY,
14137                                         0);
14138
14139                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
14140                                         "session mempool allocation failed");
14141                 }
14142
14143                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
14144                 ts_params->qp_conf.mp_session_private =
14145                                 ts_params->session_priv_mpool;
14146
14147                 ret = rte_cryptodev_scheduler_worker_attach(sched_id,
14148                                 (uint8_t)i);
14149
14150                 TEST_ASSERT(ret == 0,
14151                         "Failed to attach device %u of pmd : %s", i,
14152                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14153
14154                 aesni_ids[nb_devs_attached] = (uint8_t)i;
14155
14156                 nb_devs_attached++;
14157         }
14158
14159         return 0;
14160 }
14161
14162 static int
14163 test_scheduler_detach_worker_op(void)
14164 {
14165         struct crypto_testsuite_params *ts_params = &testsuite_params;
14166         uint8_t sched_id = ts_params->valid_devs[0];
14167         uint32_t i;
14168         int ret;
14169
14170         for (i = 0; i < 2; i++) {
14171                 ret = rte_cryptodev_scheduler_worker_detach(sched_id,
14172                                 aesni_ids[i]);
14173                 TEST_ASSERT(ret == 0,
14174                         "Failed to detach device %u", aesni_ids[i]);
14175         }
14176
14177         return 0;
14178 }
14179
14180 static int
14181 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
14182 {
14183         struct crypto_testsuite_params *ts_params = &testsuite_params;
14184         uint8_t sched_id = ts_params->valid_devs[0];
14185         /* set mode */
14186         return rte_cryptodev_scheduler_mode_set(sched_id,
14187                 scheduler_mode);
14188 }
14189
14190 static int
14191 test_scheduler_mode_roundrobin_op(void)
14192 {
14193         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
14194                         0, "Failed to set roundrobin mode");
14195         return 0;
14196
14197 }
14198
14199 static int
14200 test_scheduler_mode_multicore_op(void)
14201 {
14202         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
14203                         0, "Failed to set multicore mode");
14204
14205         return 0;
14206 }
14207
14208 static int
14209 test_scheduler_mode_failover_op(void)
14210 {
14211         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
14212                         0, "Failed to set failover mode");
14213
14214         return 0;
14215 }
14216
14217 static int
14218 test_scheduler_mode_pkt_size_distr_op(void)
14219 {
14220         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
14221                         0, "Failed to set pktsize mode");
14222
14223         return 0;
14224 }
14225
14226 static int
14227 scheduler_multicore_testsuite_setup(void)
14228 {
14229         if (test_scheduler_attach_worker_op() < 0)
14230                 return TEST_SKIPPED;
14231         if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
14232                 return TEST_SKIPPED;
14233         return 0;
14234 }
14235
14236 static int
14237 scheduler_roundrobin_testsuite_setup(void)
14238 {
14239         if (test_scheduler_attach_worker_op() < 0)
14240                 return TEST_SKIPPED;
14241         if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
14242                 return TEST_SKIPPED;
14243         return 0;
14244 }
14245
14246 static int
14247 scheduler_failover_testsuite_setup(void)
14248 {
14249         if (test_scheduler_attach_worker_op() < 0)
14250                 return TEST_SKIPPED;
14251         if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
14252                 return TEST_SKIPPED;
14253         return 0;
14254 }
14255
14256 static int
14257 scheduler_pkt_size_distr_testsuite_setup(void)
14258 {
14259         if (test_scheduler_attach_worker_op() < 0)
14260                 return TEST_SKIPPED;
14261         if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
14262                 return TEST_SKIPPED;
14263         return 0;
14264 }
14265
14266 static void
14267 scheduler_mode_testsuite_teardown(void)
14268 {
14269         test_scheduler_detach_worker_op();
14270 }
14271
14272 #endif /* RTE_CRYPTO_SCHEDULER */
14273
14274 static struct unit_test_suite end_testsuite = {
14275         .suite_name = NULL,
14276         .setup = NULL,
14277         .teardown = NULL,
14278         .unit_test_suites = NULL
14279 };
14280
14281 #ifdef RTE_LIB_SECURITY
14282 static struct unit_test_suite ipsec_proto_testsuite  = {
14283         .suite_name = "IPsec Proto Unit Test Suite",
14284         .setup = ipsec_proto_testsuite_setup,
14285         .unit_test_cases = {
14286                 TEST_CASE_NAMED_WITH_DATA(
14287                         "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14288                         ut_setup_security, ut_teardown,
14289                         test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
14290                 TEST_CASE_NAMED_WITH_DATA(
14291                         "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14292                         ut_setup_security, ut_teardown,
14293                         test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
14294                 TEST_CASE_NAMED_WITH_DATA(
14295                         "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14296                         ut_setup_security, ut_teardown,
14297                         test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
14298                 TEST_CASE_NAMED_WITH_DATA(
14299                         "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14300                         ut_setup_security, ut_teardown,
14301                         test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
14302                 TEST_CASE_NAMED_WITH_DATA(
14303                         "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14304                         ut_setup_security, ut_teardown,
14305                         test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
14306                 TEST_CASE_NAMED_WITH_DATA(
14307                         "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14308                         ut_setup_security, ut_teardown,
14309                         test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
14310                 TEST_CASE_NAMED_ST(
14311                         "Combined test alg list",
14312                         ut_setup_security, ut_teardown,
14313                         test_ipsec_proto_display_list),
14314                 TEST_CASE_NAMED_ST(
14315                         "IV generation",
14316                         ut_setup_security, ut_teardown,
14317                         test_ipsec_proto_iv_gen),
14318                 TEST_CASE_NAMED_ST(
14319                         "UDP encapsulation",
14320                         ut_setup_security, ut_teardown,
14321                         test_ipsec_proto_udp_encap),
14322                 TEST_CASE_NAMED_ST(
14323                         "UDP encapsulation ports verification test",
14324                         ut_setup_security, ut_teardown,
14325                         test_ipsec_proto_udp_ports_verify),
14326                 TEST_CASE_NAMED_ST(
14327                         "SA expiry packets soft",
14328                         ut_setup_security, ut_teardown,
14329                         test_ipsec_proto_sa_exp_pkts_soft),
14330                 TEST_CASE_NAMED_ST(
14331                         "SA expiry packets hard",
14332                         ut_setup_security, ut_teardown,
14333                         test_ipsec_proto_sa_exp_pkts_hard),
14334                 TEST_CASE_NAMED_ST(
14335                         "Negative test: ICV corruption",
14336                         ut_setup_security, ut_teardown,
14337                         test_ipsec_proto_err_icv_corrupt),
14338                 TEST_CASE_NAMED_ST(
14339                         "Tunnel dst addr verification",
14340                         ut_setup_security, ut_teardown,
14341                         test_ipsec_proto_tunnel_dst_addr_verify),
14342                 TEST_CASE_NAMED_ST(
14343                         "Tunnel src and dst addr verification",
14344                         ut_setup_security, ut_teardown,
14345                         test_ipsec_proto_tunnel_src_dst_addr_verify),
14346                 TEST_CASE_NAMED_ST(
14347                         "Inner IP checksum",
14348                         ut_setup_security, ut_teardown,
14349                         test_ipsec_proto_inner_ip_csum),
14350                 TEST_CASE_NAMED_ST(
14351                         "Inner L4 checksum",
14352                         ut_setup_security, ut_teardown,
14353                         test_ipsec_proto_inner_l4_csum),
14354                 TEST_CASES_END() /**< NULL terminate unit test array */
14355         }
14356 };
14357
14358 static struct unit_test_suite pdcp_proto_testsuite  = {
14359         .suite_name = "PDCP Proto Unit Test Suite",
14360         .setup = pdcp_proto_testsuite_setup,
14361         .unit_test_cases = {
14362                 TEST_CASE_ST(ut_setup_security, ut_teardown,
14363                         test_PDCP_PROTO_all),
14364                 TEST_CASES_END() /**< NULL terminate unit test array */
14365         }
14366 };
14367
14368 static struct unit_test_suite docsis_proto_testsuite  = {
14369         .suite_name = "Docsis Proto Unit Test Suite",
14370         .setup = docsis_proto_testsuite_setup,
14371         .unit_test_cases = {
14372                 TEST_CASE_ST(ut_setup_security, ut_teardown,
14373                         test_DOCSIS_PROTO_all),
14374                 TEST_CASES_END() /**< NULL terminate unit test array */
14375         }
14376 };
14377 #endif
14378
14379 static struct unit_test_suite cryptodev_gen_testsuite  = {
14380         .suite_name = "Crypto General Unit Test Suite",
14381         .setup = crypto_gen_testsuite_setup,
14382         .unit_test_cases = {
14383                 TEST_CASE_ST(ut_setup, ut_teardown,
14384                                 test_device_configure_invalid_dev_id),
14385                 TEST_CASE_ST(ut_setup, ut_teardown,
14386                                 test_queue_pair_descriptor_setup),
14387                 TEST_CASE_ST(ut_setup, ut_teardown,
14388                                 test_device_configure_invalid_queue_pair_ids),
14389                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
14390                 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
14391                 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
14392                 TEST_CASES_END() /**< NULL terminate unit test array */
14393         }
14394 };
14395
14396 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
14397         .suite_name = "Negative HMAC SHA1 Unit Test Suite",
14398         .setup = negative_hmac_sha1_testsuite_setup,
14399         .unit_test_cases = {
14400                 /** Negative tests */
14401                 TEST_CASE_ST(ut_setup, ut_teardown,
14402                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
14403                 TEST_CASE_ST(ut_setup, ut_teardown,
14404                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
14405                 TEST_CASE_ST(ut_setup, ut_teardown,
14406                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
14407                 TEST_CASE_ST(ut_setup, ut_teardown,
14408                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
14409
14410                 TEST_CASES_END() /**< NULL terminate unit test array */
14411         }
14412 };
14413
14414 static struct unit_test_suite cryptodev_multi_session_testsuite = {
14415         .suite_name = "Multi Session Unit Test Suite",
14416         .setup = multi_session_testsuite_setup,
14417         .unit_test_cases = {
14418                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
14419                 TEST_CASE_ST(ut_setup, ut_teardown,
14420                                 test_multi_session_random_usage),
14421
14422                 TEST_CASES_END() /**< NULL terminate unit test array */
14423         }
14424 };
14425
14426 static struct unit_test_suite cryptodev_null_testsuite  = {
14427         .suite_name = "NULL Test Suite",
14428         .setup = null_testsuite_setup,
14429         .unit_test_cases = {
14430                 TEST_CASE_ST(ut_setup, ut_teardown,
14431                         test_null_invalid_operation),
14432                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
14433                 TEST_CASES_END()
14434         }
14435 };
14436
14437 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
14438         .suite_name = "AES CCM Authenticated Test Suite",
14439         .setup = aes_ccm_auth_testsuite_setup,
14440         .unit_test_cases = {
14441                 /** AES CCM Authenticated Encryption 128 bits key*/
14442                 TEST_CASE_ST(ut_setup, ut_teardown,
14443                         test_AES_CCM_authenticated_encryption_test_case_128_1),
14444                 TEST_CASE_ST(ut_setup, ut_teardown,
14445                         test_AES_CCM_authenticated_encryption_test_case_128_2),
14446                 TEST_CASE_ST(ut_setup, ut_teardown,
14447                         test_AES_CCM_authenticated_encryption_test_case_128_3),
14448
14449                 /** AES CCM Authenticated Decryption 128 bits key*/
14450                 TEST_CASE_ST(ut_setup, ut_teardown,
14451                         test_AES_CCM_authenticated_decryption_test_case_128_1),
14452                 TEST_CASE_ST(ut_setup, ut_teardown,
14453                         test_AES_CCM_authenticated_decryption_test_case_128_2),
14454                 TEST_CASE_ST(ut_setup, ut_teardown,
14455                         test_AES_CCM_authenticated_decryption_test_case_128_3),
14456
14457                 /** AES CCM Authenticated Encryption 192 bits key */
14458                 TEST_CASE_ST(ut_setup, ut_teardown,
14459                         test_AES_CCM_authenticated_encryption_test_case_192_1),
14460                 TEST_CASE_ST(ut_setup, ut_teardown,
14461                         test_AES_CCM_authenticated_encryption_test_case_192_2),
14462                 TEST_CASE_ST(ut_setup, ut_teardown,
14463                         test_AES_CCM_authenticated_encryption_test_case_192_3),
14464
14465                 /** AES CCM Authenticated Decryption 192 bits key*/
14466                 TEST_CASE_ST(ut_setup, ut_teardown,
14467                         test_AES_CCM_authenticated_decryption_test_case_192_1),
14468                 TEST_CASE_ST(ut_setup, ut_teardown,
14469                         test_AES_CCM_authenticated_decryption_test_case_192_2),
14470                 TEST_CASE_ST(ut_setup, ut_teardown,
14471                         test_AES_CCM_authenticated_decryption_test_case_192_3),
14472
14473                 /** AES CCM Authenticated Encryption 256 bits key */
14474                 TEST_CASE_ST(ut_setup, ut_teardown,
14475                         test_AES_CCM_authenticated_encryption_test_case_256_1),
14476                 TEST_CASE_ST(ut_setup, ut_teardown,
14477                         test_AES_CCM_authenticated_encryption_test_case_256_2),
14478                 TEST_CASE_ST(ut_setup, ut_teardown,
14479                         test_AES_CCM_authenticated_encryption_test_case_256_3),
14480
14481                 /** AES CCM Authenticated Decryption 256 bits key*/
14482                 TEST_CASE_ST(ut_setup, ut_teardown,
14483                         test_AES_CCM_authenticated_decryption_test_case_256_1),
14484                 TEST_CASE_ST(ut_setup, ut_teardown,
14485                         test_AES_CCM_authenticated_decryption_test_case_256_2),
14486                 TEST_CASE_ST(ut_setup, ut_teardown,
14487                         test_AES_CCM_authenticated_decryption_test_case_256_3),
14488                 TEST_CASES_END()
14489         }
14490 };
14491
14492 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
14493         .suite_name = "AES GCM Authenticated Test Suite",
14494         .setup = aes_gcm_auth_testsuite_setup,
14495         .unit_test_cases = {
14496                 /** AES GCM Authenticated Encryption */
14497                 TEST_CASE_ST(ut_setup, ut_teardown,
14498                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
14499                 TEST_CASE_ST(ut_setup, ut_teardown,
14500                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
14501                 TEST_CASE_ST(ut_setup, ut_teardown,
14502                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
14503                 TEST_CASE_ST(ut_setup, ut_teardown,
14504                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
14505                 TEST_CASE_ST(ut_setup, ut_teardown,
14506                         test_AES_GCM_authenticated_encryption_test_case_1),
14507                 TEST_CASE_ST(ut_setup, ut_teardown,
14508                         test_AES_GCM_authenticated_encryption_test_case_2),
14509                 TEST_CASE_ST(ut_setup, ut_teardown,
14510                         test_AES_GCM_authenticated_encryption_test_case_3),
14511                 TEST_CASE_ST(ut_setup, ut_teardown,
14512                         test_AES_GCM_authenticated_encryption_test_case_4),
14513                 TEST_CASE_ST(ut_setup, ut_teardown,
14514                         test_AES_GCM_authenticated_encryption_test_case_5),
14515                 TEST_CASE_ST(ut_setup, ut_teardown,
14516                         test_AES_GCM_authenticated_encryption_test_case_6),
14517                 TEST_CASE_ST(ut_setup, ut_teardown,
14518                         test_AES_GCM_authenticated_encryption_test_case_7),
14519                 TEST_CASE_ST(ut_setup, ut_teardown,
14520                         test_AES_GCM_authenticated_encryption_test_case_8),
14521                 TEST_CASE_ST(ut_setup, ut_teardown,
14522                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
14523
14524                 /** AES GCM Authenticated Decryption */
14525                 TEST_CASE_ST(ut_setup, ut_teardown,
14526                         test_AES_GCM_authenticated_decryption_test_case_1),
14527                 TEST_CASE_ST(ut_setup, ut_teardown,
14528                         test_AES_GCM_authenticated_decryption_test_case_2),
14529                 TEST_CASE_ST(ut_setup, ut_teardown,
14530                         test_AES_GCM_authenticated_decryption_test_case_3),
14531                 TEST_CASE_ST(ut_setup, ut_teardown,
14532                         test_AES_GCM_authenticated_decryption_test_case_4),
14533                 TEST_CASE_ST(ut_setup, ut_teardown,
14534                         test_AES_GCM_authenticated_decryption_test_case_5),
14535                 TEST_CASE_ST(ut_setup, ut_teardown,
14536                         test_AES_GCM_authenticated_decryption_test_case_6),
14537                 TEST_CASE_ST(ut_setup, ut_teardown,
14538                         test_AES_GCM_authenticated_decryption_test_case_7),
14539                 TEST_CASE_ST(ut_setup, ut_teardown,
14540                         test_AES_GCM_authenticated_decryption_test_case_8),
14541                 TEST_CASE_ST(ut_setup, ut_teardown,
14542                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
14543
14544                 /** AES GCM Authenticated Encryption 192 bits key */
14545                 TEST_CASE_ST(ut_setup, ut_teardown,
14546                         test_AES_GCM_auth_encryption_test_case_192_1),
14547                 TEST_CASE_ST(ut_setup, ut_teardown,
14548                         test_AES_GCM_auth_encryption_test_case_192_2),
14549                 TEST_CASE_ST(ut_setup, ut_teardown,
14550                         test_AES_GCM_auth_encryption_test_case_192_3),
14551                 TEST_CASE_ST(ut_setup, ut_teardown,
14552                         test_AES_GCM_auth_encryption_test_case_192_4),
14553                 TEST_CASE_ST(ut_setup, ut_teardown,
14554                         test_AES_GCM_auth_encryption_test_case_192_5),
14555                 TEST_CASE_ST(ut_setup, ut_teardown,
14556                         test_AES_GCM_auth_encryption_test_case_192_6),
14557                 TEST_CASE_ST(ut_setup, ut_teardown,
14558                         test_AES_GCM_auth_encryption_test_case_192_7),
14559
14560                 /** AES GCM Authenticated Decryption 192 bits key */
14561                 TEST_CASE_ST(ut_setup, ut_teardown,
14562                         test_AES_GCM_auth_decryption_test_case_192_1),
14563                 TEST_CASE_ST(ut_setup, ut_teardown,
14564                         test_AES_GCM_auth_decryption_test_case_192_2),
14565                 TEST_CASE_ST(ut_setup, ut_teardown,
14566                         test_AES_GCM_auth_decryption_test_case_192_3),
14567                 TEST_CASE_ST(ut_setup, ut_teardown,
14568                         test_AES_GCM_auth_decryption_test_case_192_4),
14569                 TEST_CASE_ST(ut_setup, ut_teardown,
14570                         test_AES_GCM_auth_decryption_test_case_192_5),
14571                 TEST_CASE_ST(ut_setup, ut_teardown,
14572                         test_AES_GCM_auth_decryption_test_case_192_6),
14573                 TEST_CASE_ST(ut_setup, ut_teardown,
14574                         test_AES_GCM_auth_decryption_test_case_192_7),
14575
14576                 /** AES GCM Authenticated Encryption 256 bits key */
14577                 TEST_CASE_ST(ut_setup, ut_teardown,
14578                         test_AES_GCM_auth_encryption_test_case_256_1),
14579                 TEST_CASE_ST(ut_setup, ut_teardown,
14580                         test_AES_GCM_auth_encryption_test_case_256_2),
14581                 TEST_CASE_ST(ut_setup, ut_teardown,
14582                         test_AES_GCM_auth_encryption_test_case_256_3),
14583                 TEST_CASE_ST(ut_setup, ut_teardown,
14584                         test_AES_GCM_auth_encryption_test_case_256_4),
14585                 TEST_CASE_ST(ut_setup, ut_teardown,
14586                         test_AES_GCM_auth_encryption_test_case_256_5),
14587                 TEST_CASE_ST(ut_setup, ut_teardown,
14588                         test_AES_GCM_auth_encryption_test_case_256_6),
14589                 TEST_CASE_ST(ut_setup, ut_teardown,
14590                         test_AES_GCM_auth_encryption_test_case_256_7),
14591
14592                 /** AES GCM Authenticated Decryption 256 bits key */
14593                 TEST_CASE_ST(ut_setup, ut_teardown,
14594                         test_AES_GCM_auth_decryption_test_case_256_1),
14595                 TEST_CASE_ST(ut_setup, ut_teardown,
14596                         test_AES_GCM_auth_decryption_test_case_256_2),
14597                 TEST_CASE_ST(ut_setup, ut_teardown,
14598                         test_AES_GCM_auth_decryption_test_case_256_3),
14599                 TEST_CASE_ST(ut_setup, ut_teardown,
14600                         test_AES_GCM_auth_decryption_test_case_256_4),
14601                 TEST_CASE_ST(ut_setup, ut_teardown,
14602                         test_AES_GCM_auth_decryption_test_case_256_5),
14603                 TEST_CASE_ST(ut_setup, ut_teardown,
14604                         test_AES_GCM_auth_decryption_test_case_256_6),
14605                 TEST_CASE_ST(ut_setup, ut_teardown,
14606                         test_AES_GCM_auth_decryption_test_case_256_7),
14607
14608                 /** AES GCM Authenticated Encryption big aad size */
14609                 TEST_CASE_ST(ut_setup, ut_teardown,
14610                         test_AES_GCM_auth_encryption_test_case_aad_1),
14611                 TEST_CASE_ST(ut_setup, ut_teardown,
14612                         test_AES_GCM_auth_encryption_test_case_aad_2),
14613
14614                 /** AES GCM Authenticated Decryption big aad size */
14615                 TEST_CASE_ST(ut_setup, ut_teardown,
14616                         test_AES_GCM_auth_decryption_test_case_aad_1),
14617                 TEST_CASE_ST(ut_setup, ut_teardown,
14618                         test_AES_GCM_auth_decryption_test_case_aad_2),
14619
14620                 /** Out of place tests */
14621                 TEST_CASE_ST(ut_setup, ut_teardown,
14622                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
14623                 TEST_CASE_ST(ut_setup, ut_teardown,
14624                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
14625
14626                 /** Session-less tests */
14627                 TEST_CASE_ST(ut_setup, ut_teardown,
14628                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
14629                 TEST_CASE_ST(ut_setup, ut_teardown,
14630                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
14631
14632                 TEST_CASES_END()
14633         }
14634 };
14635
14636 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
14637         .suite_name = "AES GMAC Authentication Test Suite",
14638         .setup = aes_gmac_auth_testsuite_setup,
14639         .unit_test_cases = {
14640                 TEST_CASE_ST(ut_setup, ut_teardown,
14641                         test_AES_GMAC_authentication_test_case_1),
14642                 TEST_CASE_ST(ut_setup, ut_teardown,
14643                         test_AES_GMAC_authentication_verify_test_case_1),
14644                 TEST_CASE_ST(ut_setup, ut_teardown,
14645                         test_AES_GMAC_authentication_test_case_2),
14646                 TEST_CASE_ST(ut_setup, ut_teardown,
14647                         test_AES_GMAC_authentication_verify_test_case_2),
14648                 TEST_CASE_ST(ut_setup, ut_teardown,
14649                         test_AES_GMAC_authentication_test_case_3),
14650                 TEST_CASE_ST(ut_setup, ut_teardown,
14651                         test_AES_GMAC_authentication_verify_test_case_3),
14652                 TEST_CASE_ST(ut_setup, ut_teardown,
14653                         test_AES_GMAC_authentication_test_case_4),
14654                 TEST_CASE_ST(ut_setup, ut_teardown,
14655                         test_AES_GMAC_authentication_verify_test_case_4),
14656                 TEST_CASE_ST(ut_setup, ut_teardown,
14657                         test_AES_GMAC_authentication_SGL_40B),
14658                 TEST_CASE_ST(ut_setup, ut_teardown,
14659                         test_AES_GMAC_authentication_SGL_80B),
14660                 TEST_CASE_ST(ut_setup, ut_teardown,
14661                         test_AES_GMAC_authentication_SGL_2048B),
14662                 TEST_CASE_ST(ut_setup, ut_teardown,
14663                         test_AES_GMAC_authentication_SGL_2047B),
14664
14665                 TEST_CASES_END()
14666         }
14667 };
14668
14669 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14670         .suite_name = "Chacha20-Poly1305 Test Suite",
14671         .setup = chacha20_poly1305_testsuite_setup,
14672         .unit_test_cases = {
14673                 TEST_CASE_ST(ut_setup, ut_teardown,
14674                         test_chacha20_poly1305_encrypt_test_case_rfc8439),
14675                 TEST_CASE_ST(ut_setup, ut_teardown,
14676                         test_chacha20_poly1305_decrypt_test_case_rfc8439),
14677                 TEST_CASES_END()
14678         }
14679 };
14680
14681 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14682         .suite_name = "SNOW 3G Test Suite",
14683         .setup = snow3g_testsuite_setup,
14684         .unit_test_cases = {
14685                 /** SNOW 3G encrypt only (UEA2) */
14686                 TEST_CASE_ST(ut_setup, ut_teardown,
14687                         test_snow3g_encryption_test_case_1),
14688                 TEST_CASE_ST(ut_setup, ut_teardown,
14689                         test_snow3g_encryption_test_case_2),
14690                 TEST_CASE_ST(ut_setup, ut_teardown,
14691                         test_snow3g_encryption_test_case_3),
14692                 TEST_CASE_ST(ut_setup, ut_teardown,
14693                         test_snow3g_encryption_test_case_4),
14694                 TEST_CASE_ST(ut_setup, ut_teardown,
14695                         test_snow3g_encryption_test_case_5),
14696
14697                 TEST_CASE_ST(ut_setup, ut_teardown,
14698                         test_snow3g_encryption_test_case_1_oop),
14699                 TEST_CASE_ST(ut_setup, ut_teardown,
14700                         test_snow3g_encryption_test_case_1_oop_sgl),
14701                 TEST_CASE_ST(ut_setup, ut_teardown,
14702                         test_snow3g_encryption_test_case_1_offset_oop),
14703                 TEST_CASE_ST(ut_setup, ut_teardown,
14704                         test_snow3g_decryption_test_case_1_oop),
14705
14706                 /** SNOW 3G generate auth, then encrypt (UEA2) */
14707                 TEST_CASE_ST(ut_setup, ut_teardown,
14708                         test_snow3g_auth_cipher_test_case_1),
14709                 TEST_CASE_ST(ut_setup, ut_teardown,
14710                         test_snow3g_auth_cipher_test_case_2),
14711                 TEST_CASE_ST(ut_setup, ut_teardown,
14712                         test_snow3g_auth_cipher_test_case_2_oop),
14713                 TEST_CASE_ST(ut_setup, ut_teardown,
14714                         test_snow3g_auth_cipher_part_digest_enc),
14715                 TEST_CASE_ST(ut_setup, ut_teardown,
14716                         test_snow3g_auth_cipher_part_digest_enc_oop),
14717                 TEST_CASE_ST(ut_setup, ut_teardown,
14718                         test_snow3g_auth_cipher_test_case_3_sgl),
14719                 TEST_CASE_ST(ut_setup, ut_teardown,
14720                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
14721                 TEST_CASE_ST(ut_setup, ut_teardown,
14722                         test_snow3g_auth_cipher_part_digest_enc_sgl),
14723                 TEST_CASE_ST(ut_setup, ut_teardown,
14724                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14725
14726                 /** SNOW 3G decrypt (UEA2), then verify auth */
14727                 TEST_CASE_ST(ut_setup, ut_teardown,
14728                         test_snow3g_auth_cipher_verify_test_case_1),
14729                 TEST_CASE_ST(ut_setup, ut_teardown,
14730                         test_snow3g_auth_cipher_verify_test_case_2),
14731                 TEST_CASE_ST(ut_setup, ut_teardown,
14732                         test_snow3g_auth_cipher_verify_test_case_2_oop),
14733                 TEST_CASE_ST(ut_setup, ut_teardown,
14734                         test_snow3g_auth_cipher_verify_part_digest_enc),
14735                 TEST_CASE_ST(ut_setup, ut_teardown,
14736                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14737                 TEST_CASE_ST(ut_setup, ut_teardown,
14738                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
14739                 TEST_CASE_ST(ut_setup, ut_teardown,
14740                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14741                 TEST_CASE_ST(ut_setup, ut_teardown,
14742                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14743                 TEST_CASE_ST(ut_setup, ut_teardown,
14744                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14745
14746                 /** SNOW 3G decrypt only (UEA2) */
14747                 TEST_CASE_ST(ut_setup, ut_teardown,
14748                         test_snow3g_decryption_test_case_1),
14749                 TEST_CASE_ST(ut_setup, ut_teardown,
14750                         test_snow3g_decryption_test_case_2),
14751                 TEST_CASE_ST(ut_setup, ut_teardown,
14752                         test_snow3g_decryption_test_case_3),
14753                 TEST_CASE_ST(ut_setup, ut_teardown,
14754                         test_snow3g_decryption_test_case_4),
14755                 TEST_CASE_ST(ut_setup, ut_teardown,
14756                         test_snow3g_decryption_test_case_5),
14757                 TEST_CASE_ST(ut_setup, ut_teardown,
14758                         test_snow3g_decryption_with_digest_test_case_1),
14759                 TEST_CASE_ST(ut_setup, ut_teardown,
14760                         test_snow3g_hash_generate_test_case_1),
14761                 TEST_CASE_ST(ut_setup, ut_teardown,
14762                         test_snow3g_hash_generate_test_case_2),
14763                 TEST_CASE_ST(ut_setup, ut_teardown,
14764                         test_snow3g_hash_generate_test_case_3),
14765
14766                 /* Tests with buffers which length is not byte-aligned */
14767                 TEST_CASE_ST(ut_setup, ut_teardown,
14768                         test_snow3g_hash_generate_test_case_4),
14769                 TEST_CASE_ST(ut_setup, ut_teardown,
14770                         test_snow3g_hash_generate_test_case_5),
14771                 TEST_CASE_ST(ut_setup, ut_teardown,
14772                         test_snow3g_hash_generate_test_case_6),
14773                 TEST_CASE_ST(ut_setup, ut_teardown,
14774                         test_snow3g_hash_verify_test_case_1),
14775                 TEST_CASE_ST(ut_setup, ut_teardown,
14776                         test_snow3g_hash_verify_test_case_2),
14777                 TEST_CASE_ST(ut_setup, ut_teardown,
14778                         test_snow3g_hash_verify_test_case_3),
14779
14780                 /* Tests with buffers which length is not byte-aligned */
14781                 TEST_CASE_ST(ut_setup, ut_teardown,
14782                         test_snow3g_hash_verify_test_case_4),
14783                 TEST_CASE_ST(ut_setup, ut_teardown,
14784                         test_snow3g_hash_verify_test_case_5),
14785                 TEST_CASE_ST(ut_setup, ut_teardown,
14786                         test_snow3g_hash_verify_test_case_6),
14787                 TEST_CASE_ST(ut_setup, ut_teardown,
14788                         test_snow3g_cipher_auth_test_case_1),
14789                 TEST_CASE_ST(ut_setup, ut_teardown,
14790                         test_snow3g_auth_cipher_with_digest_test_case_1),
14791                 TEST_CASES_END()
14792         }
14793 };
14794
14795 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14796         .suite_name = "ZUC Test Suite",
14797         .setup = zuc_testsuite_setup,
14798         .unit_test_cases = {
14799                 /** ZUC encrypt only (EEA3) */
14800                 TEST_CASE_ST(ut_setup, ut_teardown,
14801                         test_zuc_encryption_test_case_1),
14802                 TEST_CASE_ST(ut_setup, ut_teardown,
14803                         test_zuc_encryption_test_case_2),
14804                 TEST_CASE_ST(ut_setup, ut_teardown,
14805                         test_zuc_encryption_test_case_3),
14806                 TEST_CASE_ST(ut_setup, ut_teardown,
14807                         test_zuc_encryption_test_case_4),
14808                 TEST_CASE_ST(ut_setup, ut_teardown,
14809                         test_zuc_encryption_test_case_5),
14810                 TEST_CASE_ST(ut_setup, ut_teardown,
14811                         test_zuc_encryption_test_case_6_sgl),
14812                 TEST_CASE_ST(ut_setup, ut_teardown,
14813                         test_zuc_encryption_test_case_7),
14814
14815                 /** ZUC authenticate (EIA3) */
14816                 TEST_CASE_ST(ut_setup, ut_teardown,
14817                         test_zuc_hash_generate_test_case_1),
14818                 TEST_CASE_ST(ut_setup, ut_teardown,
14819                         test_zuc_hash_generate_test_case_2),
14820                 TEST_CASE_ST(ut_setup, ut_teardown,
14821                         test_zuc_hash_generate_test_case_3),
14822                 TEST_CASE_ST(ut_setup, ut_teardown,
14823                         test_zuc_hash_generate_test_case_4),
14824                 TEST_CASE_ST(ut_setup, ut_teardown,
14825                         test_zuc_hash_generate_test_case_5),
14826                 TEST_CASE_ST(ut_setup, ut_teardown,
14827                         test_zuc_hash_generate_test_case_6),
14828                 TEST_CASE_ST(ut_setup, ut_teardown,
14829                         test_zuc_hash_generate_test_case_7),
14830                 TEST_CASE_ST(ut_setup, ut_teardown,
14831                         test_zuc_hash_generate_test_case_8),
14832                 TEST_CASE_ST(ut_setup, ut_teardown,
14833                         test_zuc_hash_generate_test_case_9),
14834                 TEST_CASE_ST(ut_setup, ut_teardown,
14835                         test_zuc_hash_generate_test_case_10),
14836
14837
14838                 /** ZUC alg-chain (EEA3/EIA3) */
14839                 TEST_CASE_ST(ut_setup, ut_teardown,
14840                         test_zuc_cipher_auth_test_case_1),
14841                 TEST_CASE_ST(ut_setup, ut_teardown,
14842                         test_zuc_cipher_auth_test_case_2),
14843
14844                 /** ZUC generate auth, then encrypt (EEA3) */
14845                 TEST_CASE_ST(ut_setup, ut_teardown,
14846                         test_zuc_auth_cipher_test_case_1),
14847                 TEST_CASE_ST(ut_setup, ut_teardown,
14848                         test_zuc_auth_cipher_test_case_1_oop),
14849                 TEST_CASE_ST(ut_setup, ut_teardown,
14850                         test_zuc_auth_cipher_test_case_1_sgl),
14851                 TEST_CASE_ST(ut_setup, ut_teardown,
14852                         test_zuc_auth_cipher_test_case_1_oop_sgl),
14853
14854                 /** ZUC decrypt (EEA3), then verify auth */
14855                 TEST_CASE_ST(ut_setup, ut_teardown,
14856                         test_zuc_auth_cipher_verify_test_case_1),
14857                 TEST_CASE_ST(ut_setup, ut_teardown,
14858                         test_zuc_auth_cipher_verify_test_case_1_oop),
14859                 TEST_CASE_ST(ut_setup, ut_teardown,
14860                         test_zuc_auth_cipher_verify_test_case_1_sgl),
14861                 TEST_CASE_ST(ut_setup, ut_teardown,
14862                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
14863                 TEST_CASES_END()
14864         }
14865 };
14866
14867 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
14868         .suite_name = "HMAC_MD5 Authentication Test Suite",
14869         .setup = hmac_md5_auth_testsuite_setup,
14870         .unit_test_cases = {
14871                 TEST_CASE_ST(ut_setup, ut_teardown,
14872                         test_MD5_HMAC_generate_case_1),
14873                 TEST_CASE_ST(ut_setup, ut_teardown,
14874                         test_MD5_HMAC_verify_case_1),
14875                 TEST_CASE_ST(ut_setup, ut_teardown,
14876                         test_MD5_HMAC_generate_case_2),
14877                 TEST_CASE_ST(ut_setup, ut_teardown,
14878                         test_MD5_HMAC_verify_case_2),
14879                 TEST_CASES_END()
14880         }
14881 };
14882
14883 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
14884         .suite_name = "Kasumi Test Suite",
14885         .setup = kasumi_testsuite_setup,
14886         .unit_test_cases = {
14887                 /** KASUMI hash only (UIA1) */
14888                 TEST_CASE_ST(ut_setup, ut_teardown,
14889                         test_kasumi_hash_generate_test_case_1),
14890                 TEST_CASE_ST(ut_setup, ut_teardown,
14891                         test_kasumi_hash_generate_test_case_2),
14892                 TEST_CASE_ST(ut_setup, ut_teardown,
14893                         test_kasumi_hash_generate_test_case_3),
14894                 TEST_CASE_ST(ut_setup, ut_teardown,
14895                         test_kasumi_hash_generate_test_case_4),
14896                 TEST_CASE_ST(ut_setup, ut_teardown,
14897                         test_kasumi_hash_generate_test_case_5),
14898                 TEST_CASE_ST(ut_setup, ut_teardown,
14899                         test_kasumi_hash_generate_test_case_6),
14900
14901                 TEST_CASE_ST(ut_setup, ut_teardown,
14902                         test_kasumi_hash_verify_test_case_1),
14903                 TEST_CASE_ST(ut_setup, ut_teardown,
14904                         test_kasumi_hash_verify_test_case_2),
14905                 TEST_CASE_ST(ut_setup, ut_teardown,
14906                         test_kasumi_hash_verify_test_case_3),
14907                 TEST_CASE_ST(ut_setup, ut_teardown,
14908                         test_kasumi_hash_verify_test_case_4),
14909                 TEST_CASE_ST(ut_setup, ut_teardown,
14910                         test_kasumi_hash_verify_test_case_5),
14911
14912                 /** KASUMI encrypt only (UEA1) */
14913                 TEST_CASE_ST(ut_setup, ut_teardown,
14914                         test_kasumi_encryption_test_case_1),
14915                 TEST_CASE_ST(ut_setup, ut_teardown,
14916                         test_kasumi_encryption_test_case_1_sgl),
14917                 TEST_CASE_ST(ut_setup, ut_teardown,
14918                         test_kasumi_encryption_test_case_1_oop),
14919                 TEST_CASE_ST(ut_setup, ut_teardown,
14920                         test_kasumi_encryption_test_case_1_oop_sgl),
14921                 TEST_CASE_ST(ut_setup, ut_teardown,
14922                         test_kasumi_encryption_test_case_2),
14923                 TEST_CASE_ST(ut_setup, ut_teardown,
14924                         test_kasumi_encryption_test_case_3),
14925                 TEST_CASE_ST(ut_setup, ut_teardown,
14926                         test_kasumi_encryption_test_case_4),
14927                 TEST_CASE_ST(ut_setup, ut_teardown,
14928                         test_kasumi_encryption_test_case_5),
14929
14930                 /** KASUMI decrypt only (UEA1) */
14931                 TEST_CASE_ST(ut_setup, ut_teardown,
14932                         test_kasumi_decryption_test_case_1),
14933                 TEST_CASE_ST(ut_setup, ut_teardown,
14934                         test_kasumi_decryption_test_case_2),
14935                 TEST_CASE_ST(ut_setup, ut_teardown,
14936                         test_kasumi_decryption_test_case_3),
14937                 TEST_CASE_ST(ut_setup, ut_teardown,
14938                         test_kasumi_decryption_test_case_4),
14939                 TEST_CASE_ST(ut_setup, ut_teardown,
14940                         test_kasumi_decryption_test_case_5),
14941                 TEST_CASE_ST(ut_setup, ut_teardown,
14942                         test_kasumi_decryption_test_case_1_oop),
14943                 TEST_CASE_ST(ut_setup, ut_teardown,
14944                         test_kasumi_cipher_auth_test_case_1),
14945
14946                 /** KASUMI generate auth, then encrypt (F8) */
14947                 TEST_CASE_ST(ut_setup, ut_teardown,
14948                         test_kasumi_auth_cipher_test_case_1),
14949                 TEST_CASE_ST(ut_setup, ut_teardown,
14950                         test_kasumi_auth_cipher_test_case_2),
14951                 TEST_CASE_ST(ut_setup, ut_teardown,
14952                         test_kasumi_auth_cipher_test_case_2_oop),
14953                 TEST_CASE_ST(ut_setup, ut_teardown,
14954                         test_kasumi_auth_cipher_test_case_2_sgl),
14955                 TEST_CASE_ST(ut_setup, ut_teardown,
14956                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
14957
14958                 /** KASUMI decrypt (F8), then verify auth */
14959                 TEST_CASE_ST(ut_setup, ut_teardown,
14960                         test_kasumi_auth_cipher_verify_test_case_1),
14961                 TEST_CASE_ST(ut_setup, ut_teardown,
14962                         test_kasumi_auth_cipher_verify_test_case_2),
14963                 TEST_CASE_ST(ut_setup, ut_teardown,
14964                         test_kasumi_auth_cipher_verify_test_case_2_oop),
14965                 TEST_CASE_ST(ut_setup, ut_teardown,
14966                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
14967                 TEST_CASE_ST(ut_setup, ut_teardown,
14968                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
14969
14970                 TEST_CASES_END()
14971         }
14972 };
14973
14974 static struct unit_test_suite cryptodev_esn_testsuite  = {
14975         .suite_name = "ESN Test Suite",
14976         .setup = esn_testsuite_setup,
14977         .unit_test_cases = {
14978                 TEST_CASE_ST(ut_setup, ut_teardown,
14979                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
14980                 TEST_CASE_ST(ut_setup, ut_teardown,
14981                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
14982                 TEST_CASES_END()
14983         }
14984 };
14985
14986 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
14987         .suite_name = "Negative AES GCM Test Suite",
14988         .setup = negative_aes_gcm_testsuite_setup,
14989         .unit_test_cases = {
14990                 TEST_CASE_ST(ut_setup, ut_teardown,
14991                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
14992                 TEST_CASE_ST(ut_setup, ut_teardown,
14993                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
14994                 TEST_CASE_ST(ut_setup, ut_teardown,
14995                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
14996                 TEST_CASE_ST(ut_setup, ut_teardown,
14997                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
14998                 TEST_CASE_ST(ut_setup, ut_teardown,
14999                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
15000                 TEST_CASE_ST(ut_setup, ut_teardown,
15001                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
15002                 TEST_CASE_ST(ut_setup, ut_teardown,
15003                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
15004                 TEST_CASE_ST(ut_setup, ut_teardown,
15005                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
15006                 TEST_CASE_ST(ut_setup, ut_teardown,
15007                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
15008                 TEST_CASE_ST(ut_setup, ut_teardown,
15009                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
15010                 TEST_CASE_ST(ut_setup, ut_teardown,
15011                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
15012                 TEST_CASE_ST(ut_setup, ut_teardown,
15013                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
15014
15015                 TEST_CASES_END()
15016         }
15017 };
15018
15019 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
15020         .suite_name = "Negative AES GMAC Test Suite",
15021         .setup = negative_aes_gmac_testsuite_setup,
15022         .unit_test_cases = {
15023                 TEST_CASE_ST(ut_setup, ut_teardown,
15024                         authentication_verify_AES128_GMAC_fail_data_corrupt),
15025                 TEST_CASE_ST(ut_setup, ut_teardown,
15026                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
15027
15028                 TEST_CASES_END()
15029         }
15030 };
15031
15032 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
15033         .suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
15034         .setup = mixed_cipher_hash_testsuite_setup,
15035         .unit_test_cases = {
15036                 /** AUTH AES CMAC + CIPHER AES CTR */
15037                 TEST_CASE_ST(ut_setup, ut_teardown,
15038                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
15039                 TEST_CASE_ST(ut_setup, ut_teardown,
15040                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
15041                 TEST_CASE_ST(ut_setup, ut_teardown,
15042                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
15043                 TEST_CASE_ST(ut_setup, ut_teardown,
15044                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
15045                 TEST_CASE_ST(ut_setup, ut_teardown,
15046                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
15047                 TEST_CASE_ST(ut_setup, ut_teardown,
15048                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
15049                 TEST_CASE_ST(ut_setup, ut_teardown,
15050                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
15051                 TEST_CASE_ST(ut_setup, ut_teardown,
15052                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
15053
15054                 /** AUTH ZUC + CIPHER SNOW3G */
15055                 TEST_CASE_ST(ut_setup, ut_teardown,
15056                         test_auth_zuc_cipher_snow_test_case_1),
15057                 TEST_CASE_ST(ut_setup, ut_teardown,
15058                         test_verify_auth_zuc_cipher_snow_test_case_1),
15059                 /** AUTH AES CMAC + CIPHER SNOW3G */
15060                 TEST_CASE_ST(ut_setup, ut_teardown,
15061                         test_auth_aes_cmac_cipher_snow_test_case_1),
15062                 TEST_CASE_ST(ut_setup, ut_teardown,
15063                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
15064                 /** AUTH ZUC + CIPHER AES CTR */
15065                 TEST_CASE_ST(ut_setup, ut_teardown,
15066                         test_auth_zuc_cipher_aes_ctr_test_case_1),
15067                 TEST_CASE_ST(ut_setup, ut_teardown,
15068                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
15069                 /** AUTH SNOW3G + CIPHER AES CTR */
15070                 TEST_CASE_ST(ut_setup, ut_teardown,
15071                         test_auth_snow_cipher_aes_ctr_test_case_1),
15072                 TEST_CASE_ST(ut_setup, ut_teardown,
15073                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
15074                 /** AUTH SNOW3G + CIPHER ZUC */
15075                 TEST_CASE_ST(ut_setup, ut_teardown,
15076                         test_auth_snow_cipher_zuc_test_case_1),
15077                 TEST_CASE_ST(ut_setup, ut_teardown,
15078                         test_verify_auth_snow_cipher_zuc_test_case_1),
15079                 /** AUTH AES CMAC + CIPHER ZUC */
15080                 TEST_CASE_ST(ut_setup, ut_teardown,
15081                         test_auth_aes_cmac_cipher_zuc_test_case_1),
15082                 TEST_CASE_ST(ut_setup, ut_teardown,
15083                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
15084
15085                 /** AUTH NULL + CIPHER SNOW3G */
15086                 TEST_CASE_ST(ut_setup, ut_teardown,
15087                         test_auth_null_cipher_snow_test_case_1),
15088                 TEST_CASE_ST(ut_setup, ut_teardown,
15089                         test_verify_auth_null_cipher_snow_test_case_1),
15090                 /** AUTH NULL + CIPHER ZUC */
15091                 TEST_CASE_ST(ut_setup, ut_teardown,
15092                         test_auth_null_cipher_zuc_test_case_1),
15093                 TEST_CASE_ST(ut_setup, ut_teardown,
15094                         test_verify_auth_null_cipher_zuc_test_case_1),
15095                 /** AUTH SNOW3G + CIPHER NULL */
15096                 TEST_CASE_ST(ut_setup, ut_teardown,
15097                         test_auth_snow_cipher_null_test_case_1),
15098                 TEST_CASE_ST(ut_setup, ut_teardown,
15099                         test_verify_auth_snow_cipher_null_test_case_1),
15100                 /** AUTH ZUC + CIPHER NULL */
15101                 TEST_CASE_ST(ut_setup, ut_teardown,
15102                         test_auth_zuc_cipher_null_test_case_1),
15103                 TEST_CASE_ST(ut_setup, ut_teardown,
15104                         test_verify_auth_zuc_cipher_null_test_case_1),
15105                 /** AUTH NULL + CIPHER AES CTR */
15106                 TEST_CASE_ST(ut_setup, ut_teardown,
15107                         test_auth_null_cipher_aes_ctr_test_case_1),
15108                 TEST_CASE_ST(ut_setup, ut_teardown,
15109                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
15110                 /** AUTH AES CMAC + CIPHER NULL */
15111                 TEST_CASE_ST(ut_setup, ut_teardown,
15112                         test_auth_aes_cmac_cipher_null_test_case_1),
15113                 TEST_CASE_ST(ut_setup, ut_teardown,
15114                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
15115                 TEST_CASES_END()
15116         }
15117 };
15118
15119 static int
15120 run_cryptodev_testsuite(const char *pmd_name)
15121 {
15122         uint8_t ret, j, i = 0, blk_start_idx = 0;
15123         const enum blockcipher_test_type blk_suites[] = {
15124                 BLKCIPHER_AES_CHAIN_TYPE,
15125                 BLKCIPHER_AES_CIPHERONLY_TYPE,
15126                 BLKCIPHER_AES_DOCSIS_TYPE,
15127                 BLKCIPHER_3DES_CHAIN_TYPE,
15128                 BLKCIPHER_3DES_CIPHERONLY_TYPE,
15129                 BLKCIPHER_DES_CIPHERONLY_TYPE,
15130                 BLKCIPHER_DES_DOCSIS_TYPE,
15131                 BLKCIPHER_AUTHONLY_TYPE};
15132         struct unit_test_suite *static_suites[] = {
15133                 &cryptodev_multi_session_testsuite,
15134                 &cryptodev_null_testsuite,
15135                 &cryptodev_aes_ccm_auth_testsuite,
15136                 &cryptodev_aes_gcm_auth_testsuite,
15137                 &cryptodev_aes_gmac_auth_testsuite,
15138                 &cryptodev_snow3g_testsuite,
15139                 &cryptodev_chacha20_poly1305_testsuite,
15140                 &cryptodev_zuc_testsuite,
15141                 &cryptodev_hmac_md5_auth_testsuite,
15142                 &cryptodev_kasumi_testsuite,
15143                 &cryptodev_esn_testsuite,
15144                 &cryptodev_negative_aes_gcm_testsuite,
15145                 &cryptodev_negative_aes_gmac_testsuite,
15146                 &cryptodev_mixed_cipher_hash_testsuite,
15147                 &cryptodev_negative_hmac_sha1_testsuite,
15148                 &cryptodev_gen_testsuite,
15149 #ifdef RTE_LIB_SECURITY
15150                 &ipsec_proto_testsuite,
15151                 &pdcp_proto_testsuite,
15152                 &docsis_proto_testsuite,
15153 #endif
15154                 &end_testsuite
15155         };
15156         static struct unit_test_suite ts = {
15157                 .suite_name = "Cryptodev Unit Test Suite",
15158                 .setup = testsuite_setup,
15159                 .teardown = testsuite_teardown,
15160                 .unit_test_cases = {TEST_CASES_END()}
15161         };
15162
15163         gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
15164
15165         if (gbl_driver_id == -1) {
15166                 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
15167                 return TEST_SKIPPED;
15168         }
15169
15170         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15171                         (RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
15172
15173         ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
15174         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15175         ret = unit_test_suite_runner(&ts);
15176
15177         FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
15178         free(ts.unit_test_suites);
15179         return ret;
15180 }
15181
15182 static int
15183 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
15184 {
15185         struct rte_cryptodev_info dev_info;
15186         uint8_t i, nb_devs;
15187         int driver_id;
15188
15189         driver_id = rte_cryptodev_driver_id_get(pmd_name);
15190         if (driver_id == -1) {
15191                 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
15192                 return TEST_SKIPPED;
15193         }
15194
15195         nb_devs = rte_cryptodev_count();
15196         if (nb_devs < 1) {
15197                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
15198                 return TEST_SKIPPED;
15199         }
15200
15201         for (i = 0; i < nb_devs; i++) {
15202                 rte_cryptodev_info_get(i, &dev_info);
15203                 if (dev_info.driver_id == driver_id) {
15204                         if (!(dev_info.feature_flags & flag)) {
15205                                 RTE_LOG(INFO, USER1, "%s not supported\n",
15206                                                 flag_name);
15207                                 return TEST_SKIPPED;
15208                         }
15209                         return 0; /* found */
15210                 }
15211         }
15212
15213         RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
15214         return TEST_SKIPPED;
15215 }
15216
15217 static int
15218 test_cryptodev_qat(void)
15219 {
15220         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
15221 }
15222
15223 static int
15224 test_cryptodev_virtio(void)
15225 {
15226         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
15227 }
15228
15229 static int
15230 test_cryptodev_aesni_mb(void)
15231 {
15232         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15233 }
15234
15235 static int
15236 test_cryptodev_cpu_aesni_mb(void)
15237 {
15238         int32_t rc;
15239         enum rte_security_session_action_type at = gbl_action_type;
15240         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15241         rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15242         gbl_action_type = at;
15243         return rc;
15244 }
15245
15246 static int
15247 test_cryptodev_openssl(void)
15248 {
15249         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
15250 }
15251
15252 static int
15253 test_cryptodev_aesni_gcm(void)
15254 {
15255         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15256 }
15257
15258 static int
15259 test_cryptodev_cpu_aesni_gcm(void)
15260 {
15261         int32_t rc;
15262         enum rte_security_session_action_type at = gbl_action_type;
15263         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15264         rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15265         gbl_action_type = at;
15266         return rc;
15267 }
15268
15269 static int
15270 test_cryptodev_mlx5(void)
15271 {
15272         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
15273 }
15274
15275 static int
15276 test_cryptodev_null(void)
15277 {
15278         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
15279 }
15280
15281 static int
15282 test_cryptodev_sw_snow3g(void)
15283 {
15284         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
15285 }
15286
15287 static int
15288 test_cryptodev_sw_kasumi(void)
15289 {
15290         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
15291 }
15292
15293 static int
15294 test_cryptodev_sw_zuc(void)
15295 {
15296         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
15297 }
15298
15299 static int
15300 test_cryptodev_armv8(void)
15301 {
15302         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
15303 }
15304
15305 static int
15306 test_cryptodev_mrvl(void)
15307 {
15308         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
15309 }
15310
15311 #ifdef RTE_CRYPTO_SCHEDULER
15312
15313 static int
15314 test_cryptodev_scheduler(void)
15315 {
15316         uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
15317         const enum blockcipher_test_type blk_suites[] = {
15318                 BLKCIPHER_AES_CHAIN_TYPE,
15319                 BLKCIPHER_AES_CIPHERONLY_TYPE,
15320                 BLKCIPHER_AUTHONLY_TYPE
15321         };
15322         static struct unit_test_suite scheduler_multicore = {
15323                 .suite_name = "Scheduler Multicore Unit Test Suite",
15324                 .setup = scheduler_multicore_testsuite_setup,
15325                 .teardown = scheduler_mode_testsuite_teardown,
15326                 .unit_test_cases = {TEST_CASES_END()}
15327         };
15328         static struct unit_test_suite scheduler_round_robin = {
15329                 .suite_name = "Scheduler Round Robin Unit Test Suite",
15330                 .setup = scheduler_roundrobin_testsuite_setup,
15331                 .teardown = scheduler_mode_testsuite_teardown,
15332                 .unit_test_cases = {TEST_CASES_END()}
15333         };
15334         static struct unit_test_suite scheduler_failover = {
15335                 .suite_name = "Scheduler Failover Unit Test Suite",
15336                 .setup = scheduler_failover_testsuite_setup,
15337                 .teardown = scheduler_mode_testsuite_teardown,
15338                 .unit_test_cases = {TEST_CASES_END()}
15339         };
15340         static struct unit_test_suite scheduler_pkt_size_distr = {
15341                 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
15342                 .setup = scheduler_pkt_size_distr_testsuite_setup,
15343                 .teardown = scheduler_mode_testsuite_teardown,
15344                 .unit_test_cases = {TEST_CASES_END()}
15345         };
15346         struct unit_test_suite *sched_mode_suites[] = {
15347                 &scheduler_multicore,
15348                 &scheduler_round_robin,
15349                 &scheduler_failover,
15350                 &scheduler_pkt_size_distr
15351         };
15352         static struct unit_test_suite scheduler_config = {
15353                 .suite_name = "Crypto Device Scheduler Config Unit Test Suite",
15354                 .unit_test_cases = {
15355                         TEST_CASE(test_scheduler_attach_worker_op),
15356                         TEST_CASE(test_scheduler_mode_multicore_op),
15357                         TEST_CASE(test_scheduler_mode_roundrobin_op),
15358                         TEST_CASE(test_scheduler_mode_failover_op),
15359                         TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
15360                         TEST_CASE(test_scheduler_detach_worker_op),
15361
15362                         TEST_CASES_END() /**< NULL terminate array */
15363                 }
15364         };
15365         struct unit_test_suite *static_suites[] = {
15366                 &scheduler_config,
15367                 &end_testsuite
15368         };
15369         static struct unit_test_suite ts = {
15370                 .suite_name = "Scheduler Unit Test Suite",
15371                 .setup = scheduler_testsuite_setup,
15372                 .teardown = testsuite_teardown,
15373                 .unit_test_cases = {TEST_CASES_END()}
15374         };
15375
15376         gbl_driver_id = rte_cryptodev_driver_id_get(
15377                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
15378
15379         if (gbl_driver_id == -1) {
15380                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
15381                 return TEST_SKIPPED;
15382         }
15383
15384         if (rte_cryptodev_driver_id_get(
15385                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
15386                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
15387                 return TEST_SKIPPED;
15388         }
15389
15390         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15391                 uint8_t blk_i = 0;
15392                 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
15393                                 (struct unit_test_suite *) *
15394                                 (RTE_DIM(blk_suites) + 1));
15395                 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
15396                                 blk_suites, RTE_DIM(blk_suites));
15397                 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
15398         }
15399
15400         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15401                         (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
15402         ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
15403                         RTE_DIM(sched_mode_suites));
15404         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15405         ret = unit_test_suite_runner(&ts);
15406
15407         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15408                 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
15409                                 (*sched_mode_suites[sched_i]),
15410                                 RTE_DIM(blk_suites));
15411                 free(sched_mode_suites[sched_i]->unit_test_suites);
15412         }
15413         free(ts.unit_test_suites);
15414         return ret;
15415 }
15416
15417 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
15418
15419 #endif
15420
15421 static int
15422 test_cryptodev_dpaa2_sec(void)
15423 {
15424         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
15425 }
15426
15427 static int
15428 test_cryptodev_dpaa_sec(void)
15429 {
15430         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
15431 }
15432
15433 static int
15434 test_cryptodev_ccp(void)
15435 {
15436         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
15437 }
15438
15439 static int
15440 test_cryptodev_octeontx(void)
15441 {
15442         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
15443 }
15444
15445 static int
15446 test_cryptodev_octeontx2(void)
15447 {
15448         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
15449 }
15450
15451 static int
15452 test_cryptodev_caam_jr(void)
15453 {
15454         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
15455 }
15456
15457 static int
15458 test_cryptodev_nitrox(void)
15459 {
15460         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
15461 }
15462
15463 static int
15464 test_cryptodev_bcmfs(void)
15465 {
15466         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
15467 }
15468
15469 static int
15470 test_cryptodev_qat_raw_api(void)
15471 {
15472         static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
15473         int ret;
15474
15475         ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15476                         "RAW API");
15477         if (ret)
15478                 return ret;
15479
15480         global_api_test_type = CRYPTODEV_RAW_API_TEST;
15481         ret = run_cryptodev_testsuite(pmd_name);
15482         global_api_test_type = CRYPTODEV_API_TEST;
15483
15484         return ret;
15485 }
15486
15487 static int
15488 test_cryptodev_cn9k(void)
15489 {
15490         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
15491 }
15492
15493 static int
15494 test_cryptodev_cn10k(void)
15495 {
15496         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
15497 }
15498
15499 static int
15500 test_cryptodev_dpaa2_sec_raw_api(void)
15501 {
15502         static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
15503         int ret;
15504
15505         ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15506                         "RAW API");
15507         if (ret)
15508                 return ret;
15509
15510         global_api_test_type = CRYPTODEV_RAW_API_TEST;
15511         ret = run_cryptodev_testsuite(pmd_name);
15512         global_api_test_type = CRYPTODEV_API_TEST;
15513
15514         return ret;
15515 }
15516
15517 static int
15518 test_cryptodev_dpaa_sec_raw_api(void)
15519 {
15520         static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
15521         int ret;
15522
15523         ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15524                         "RAW API");
15525         if (ret)
15526                 return ret;
15527
15528         global_api_test_type = CRYPTODEV_RAW_API_TEST;
15529         ret = run_cryptodev_testsuite(pmd_name);
15530         global_api_test_type = CRYPTODEV_API_TEST;
15531
15532         return ret;
15533 }
15534
15535 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest,
15536                 test_cryptodev_dpaa2_sec_raw_api);
15537 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest,
15538                 test_cryptodev_dpaa_sec_raw_api);
15539 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
15540                 test_cryptodev_qat_raw_api);
15541 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
15542 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
15543 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
15544         test_cryptodev_cpu_aesni_mb);
15545 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
15546 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
15547 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
15548         test_cryptodev_cpu_aesni_gcm);
15549 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
15550 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
15551 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
15552 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
15553 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
15554 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
15555 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
15556 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
15557 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
15558 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
15559 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
15560 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
15561 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
15562 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
15563 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
15564 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
15565 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
15566 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);