771a57445c2ed4ad64c4d09c8d1ee46a15a879a5
[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                         ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR ||
383                         n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
384                                         RTE_CRYPTO_OP_STATUS_SUCCESS;
385
386 exit:
387         free(ctx);
388 }
389
390 static void
391 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
392 {
393         int32_t n, st;
394         struct rte_crypto_sym_op *sop;
395         union rte_crypto_sym_ofs ofs;
396         struct rte_crypto_sgl sgl;
397         struct rte_crypto_sym_vec symvec;
398         struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
399         struct rte_crypto_vec vec[UINT8_MAX];
400
401         sop = op->sym;
402
403         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
404                 sop->aead.data.length, vec, RTE_DIM(vec));
405
406         if (n < 0 || n != sop->m_src->nb_segs) {
407                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
408                 return;
409         }
410
411         sgl.vec = vec;
412         sgl.num = n;
413         symvec.src_sgl = &sgl;
414         symvec.iv = &iv_ptr;
415         symvec.digest = &digest_ptr;
416         symvec.aad = &aad_ptr;
417         symvec.status = &st;
418         symvec.num = 1;
419
420         /* for CPU crypto the IOVA address is not required */
421         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
422         digest_ptr.va = (void *)sop->aead.digest.data;
423         aad_ptr.va = (void *)sop->aead.aad.data;
424
425         ofs.raw = 0;
426
427         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
428                 &symvec);
429
430         if (n != 1)
431                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
432         else
433                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
434 }
435
436 static void
437 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
438 {
439         int32_t n, st;
440         struct rte_crypto_sym_op *sop;
441         union rte_crypto_sym_ofs ofs;
442         struct rte_crypto_sgl sgl;
443         struct rte_crypto_sym_vec symvec;
444         struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
445         struct rte_crypto_vec vec[UINT8_MAX];
446
447         sop = op->sym;
448
449         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
450                 sop->auth.data.length, vec, RTE_DIM(vec));
451
452         if (n < 0 || n != sop->m_src->nb_segs) {
453                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
454                 return;
455         }
456
457         sgl.vec = vec;
458         sgl.num = n;
459         symvec.src_sgl = &sgl;
460         symvec.iv = &iv_ptr;
461         symvec.digest = &digest_ptr;
462         symvec.status = &st;
463         symvec.num = 1;
464
465         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
466         digest_ptr.va = (void *)sop->auth.digest.data;
467
468         ofs.raw = 0;
469         ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
470         ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
471                 (sop->cipher.data.offset + sop->cipher.data.length);
472
473         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
474                 &symvec);
475
476         if (n != 1)
477                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
478         else
479                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
480 }
481
482 static struct rte_crypto_op *
483 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
484 {
485
486         RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
487
488         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
489                 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
490                 return NULL;
491         }
492
493         op = NULL;
494
495         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
496                 rte_pause();
497
498         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
499                 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
500                 return NULL;
501         }
502
503         return op;
504 }
505
506 static struct crypto_testsuite_params testsuite_params = { NULL };
507 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
508 static struct crypto_unittest_params unittest_params;
509
510 static int
511 testsuite_setup(void)
512 {
513         struct crypto_testsuite_params *ts_params = &testsuite_params;
514         struct rte_cryptodev_info info;
515         uint32_t i = 0, nb_devs, dev_id;
516         uint16_t qp_id;
517
518         memset(ts_params, 0, sizeof(*ts_params));
519
520         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
521         if (ts_params->mbuf_pool == NULL) {
522                 /* Not already created so create */
523                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
524                                 "CRYPTO_MBUFPOOL",
525                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
526                                 rte_socket_id());
527                 if (ts_params->mbuf_pool == NULL) {
528                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
529                         return TEST_FAILED;
530                 }
531         }
532
533         ts_params->large_mbuf_pool = rte_mempool_lookup(
534                         "CRYPTO_LARGE_MBUFPOOL");
535         if (ts_params->large_mbuf_pool == NULL) {
536                 /* Not already created so create */
537                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
538                                 "CRYPTO_LARGE_MBUFPOOL",
539                                 1, 0, 0, UINT16_MAX,
540                                 rte_socket_id());
541                 if (ts_params->large_mbuf_pool == NULL) {
542                         RTE_LOG(ERR, USER1,
543                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
544                         return TEST_FAILED;
545                 }
546         }
547
548         ts_params->op_mpool = rte_crypto_op_pool_create(
549                         "MBUF_CRYPTO_SYM_OP_POOL",
550                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
551                         NUM_MBUFS, MBUF_CACHE_SIZE,
552                         DEFAULT_NUM_XFORMS *
553                         sizeof(struct rte_crypto_sym_xform) +
554                         MAXIMUM_IV_LENGTH,
555                         rte_socket_id());
556         if (ts_params->op_mpool == NULL) {
557                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
558                 return TEST_FAILED;
559         }
560
561         nb_devs = rte_cryptodev_count();
562         if (nb_devs < 1) {
563                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
564                 return TEST_SKIPPED;
565         }
566
567         if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
568                 RTE_LOG(WARNING, USER1, "No %s devices found?\n",
569                                 rte_cryptodev_driver_name_get(gbl_driver_id));
570                 return TEST_SKIPPED;
571         }
572
573         /* Create list of valid crypto devs */
574         for (i = 0; i < nb_devs; i++) {
575                 rte_cryptodev_info_get(i, &info);
576                 if (info.driver_id == gbl_driver_id)
577                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
578         }
579
580         if (ts_params->valid_dev_count < 1)
581                 return TEST_FAILED;
582
583         /* Set up all the qps on the first of the valid devices found */
584
585         dev_id = ts_params->valid_devs[0];
586
587         rte_cryptodev_info_get(dev_id, &info);
588
589         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
590         ts_params->conf.socket_id = SOCKET_ID_ANY;
591         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
592
593         unsigned int session_size =
594                 rte_cryptodev_sym_get_private_session_size(dev_id);
595
596 #ifdef RTE_LIB_SECURITY
597         unsigned int security_session_size = rte_security_session_get_size(
598                         rte_cryptodev_get_sec_ctx(dev_id));
599
600         if (session_size < security_session_size)
601                 session_size = security_session_size;
602 #endif
603         /*
604          * Create mempool with maximum number of sessions.
605          */
606         if (info.sym.max_nb_sessions != 0 &&
607                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
608                 RTE_LOG(ERR, USER1, "Device does not support "
609                                 "at least %u sessions\n",
610                                 MAX_NB_SESSIONS);
611                 return TEST_FAILED;
612         }
613
614         ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
615                         "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
616                         SOCKET_ID_ANY);
617         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
618                         "session mempool allocation failed");
619
620         ts_params->session_priv_mpool = rte_mempool_create(
621                         "test_sess_mp_priv",
622                         MAX_NB_SESSIONS,
623                         session_size,
624                         0, 0, NULL, NULL, NULL,
625                         NULL, SOCKET_ID_ANY,
626                         0);
627         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
628                         "session mempool allocation failed");
629
630
631
632         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
633                         &ts_params->conf),
634                         "Failed to configure cryptodev %u with %u qps",
635                         dev_id, ts_params->conf.nb_queue_pairs);
636
637         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
638         ts_params->qp_conf.mp_session = ts_params->session_mpool;
639         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
640
641         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
642                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
643                         dev_id, qp_id, &ts_params->qp_conf,
644                         rte_cryptodev_socket_id(dev_id)),
645                         "Failed to setup queue pair %u on cryptodev %u",
646                         qp_id, dev_id);
647         }
648
649         return TEST_SUCCESS;
650 }
651
652 static void
653 testsuite_teardown(void)
654 {
655         struct crypto_testsuite_params *ts_params = &testsuite_params;
656         int res;
657
658         if (ts_params->mbuf_pool != NULL) {
659                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
660                 rte_mempool_avail_count(ts_params->mbuf_pool));
661         }
662
663         if (ts_params->op_mpool != NULL) {
664                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
665                 rte_mempool_avail_count(ts_params->op_mpool));
666         }
667
668         /* Free session mempools */
669         if (ts_params->session_priv_mpool != NULL) {
670                 rte_mempool_free(ts_params->session_priv_mpool);
671                 ts_params->session_priv_mpool = NULL;
672         }
673
674         if (ts_params->session_mpool != NULL) {
675                 rte_mempool_free(ts_params->session_mpool);
676                 ts_params->session_mpool = NULL;
677         }
678
679         res = rte_cryptodev_close(ts_params->valid_devs[0]);
680         if (res)
681                 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
682 }
683
684 static int
685 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
686                 const int *algs, uint16_t num_algs)
687 {
688         uint8_t dev_id = testsuite_params.valid_devs[0];
689         bool some_alg_supported = FALSE;
690         uint16_t i;
691
692         for (i = 0; i < num_algs && !some_alg_supported; i++) {
693                 struct rte_cryptodev_sym_capability_idx alg = {
694                         type, {algs[i]}
695                 };
696                 if (rte_cryptodev_sym_capability_get(dev_id,
697                                 &alg) != NULL)
698                         some_alg_supported = TRUE;
699         }
700         if (!some_alg_supported)
701                 return TEST_SKIPPED;
702
703         return 0;
704 }
705
706 int
707 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
708                 uint16_t num_ciphers)
709 {
710         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
711                         (const int *) ciphers, num_ciphers);
712 }
713
714 int
715 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
716                 uint16_t num_auths)
717 {
718         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
719                         (const int *) auths, num_auths);
720 }
721
722 int
723 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
724                 uint16_t num_aeads)
725 {
726         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
727                         (const int *) aeads, num_aeads);
728 }
729
730 static int
731 null_testsuite_setup(void)
732 {
733         struct crypto_testsuite_params *ts_params = &testsuite_params;
734         uint8_t dev_id = ts_params->valid_devs[0];
735         struct rte_cryptodev_info dev_info;
736         const enum rte_crypto_cipher_algorithm ciphers[] = {
737                 RTE_CRYPTO_CIPHER_NULL
738         };
739         const enum rte_crypto_auth_algorithm auths[] = {
740                 RTE_CRYPTO_AUTH_NULL
741         };
742
743         rte_cryptodev_info_get(dev_id, &dev_info);
744
745         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
746                 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
747                                 "testsuite not met\n");
748                 return TEST_SKIPPED;
749         }
750
751         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
752                         && check_auth_capabilities_supported(auths,
753                         RTE_DIM(auths)) != 0) {
754                 RTE_LOG(INFO, USER1, "Capability requirements for NULL "
755                                 "testsuite not met\n");
756                 return TEST_SKIPPED;
757         }
758
759         return 0;
760 }
761
762 static int
763 crypto_gen_testsuite_setup(void)
764 {
765         struct crypto_testsuite_params *ts_params = &testsuite_params;
766         uint8_t dev_id = ts_params->valid_devs[0];
767         struct rte_cryptodev_info dev_info;
768
769         rte_cryptodev_info_get(dev_id, &dev_info);
770
771         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
772                 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
773                                 "testsuite not met\n");
774                 return TEST_SKIPPED;
775         }
776
777         return 0;
778 }
779
780 #ifdef RTE_LIB_SECURITY
781 static int
782 ipsec_proto_testsuite_setup(void)
783 {
784         struct crypto_testsuite_params *ts_params = &testsuite_params;
785         struct crypto_unittest_params *ut_params = &unittest_params;
786         struct rte_cryptodev_info dev_info;
787         int ret = 0;
788
789         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
790
791         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
792                 RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto "
793                                 "testsuite not met\n");
794                 return TEST_SKIPPED;
795         }
796
797         /* Reconfigure to enable security */
798         ret = dev_configure_and_start(0);
799         if (ret != TEST_SUCCESS)
800                 return ret;
801
802         /* Set action type */
803         ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
804
805         if (security_proto_supported(
806                         RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
807                         RTE_SECURITY_PROTOCOL_IPSEC) < 0) {
808                 RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto "
809                                 "test not met\n");
810                 ret = TEST_SKIPPED;
811         }
812
813         /*
814          * Stop the device. Device would be started again by individual test
815          * case setup routine.
816          */
817         rte_cryptodev_stop(ts_params->valid_devs[0]);
818
819         return ret;
820 }
821
822 static int
823 pdcp_proto_testsuite_setup(void)
824 {
825         struct crypto_testsuite_params *ts_params = &testsuite_params;
826         uint8_t dev_id = ts_params->valid_devs[0];
827         struct rte_cryptodev_info dev_info;
828         const enum rte_crypto_cipher_algorithm ciphers[] = {
829                 RTE_CRYPTO_CIPHER_NULL,
830                 RTE_CRYPTO_CIPHER_AES_CTR,
831                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
832                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
833         };
834         const enum rte_crypto_auth_algorithm auths[] = {
835                 RTE_CRYPTO_AUTH_NULL,
836                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
837                 RTE_CRYPTO_AUTH_AES_CMAC,
838                 RTE_CRYPTO_AUTH_ZUC_EIA3
839         };
840
841         rte_cryptodev_info_get(dev_id, &dev_info);
842
843         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
844                         !(dev_info.feature_flags &
845                         RTE_CRYPTODEV_FF_SECURITY)) {
846                 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
847                                 "testsuite not met\n");
848                 return TEST_SKIPPED;
849         }
850
851         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
852                         && check_auth_capabilities_supported(auths,
853                         RTE_DIM(auths)) != 0) {
854                 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
855                                 "testsuite not met\n");
856                 return TEST_SKIPPED;
857         }
858
859         return 0;
860 }
861
862 static int
863 docsis_proto_testsuite_setup(void)
864 {
865         struct crypto_testsuite_params *ts_params = &testsuite_params;
866         uint8_t dev_id = ts_params->valid_devs[0];
867         struct rte_cryptodev_info dev_info;
868         const enum rte_crypto_cipher_algorithm ciphers[] = {
869                 RTE_CRYPTO_CIPHER_AES_DOCSISBPI
870         };
871
872         rte_cryptodev_info_get(dev_id, &dev_info);
873
874         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
875                         !(dev_info.feature_flags &
876                         RTE_CRYPTODEV_FF_SECURITY)) {
877                 RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis "
878                                 "Proto testsuite not met\n");
879                 return TEST_SKIPPED;
880         }
881
882         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
883                 RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto "
884                                 "testsuite not met\n");
885                 return TEST_SKIPPED;
886         }
887
888         return 0;
889 }
890 #endif
891
892 static int
893 aes_ccm_auth_testsuite_setup(void)
894 {
895         struct crypto_testsuite_params *ts_params = &testsuite_params;
896         uint8_t dev_id = ts_params->valid_devs[0];
897         struct rte_cryptodev_info dev_info;
898         const enum rte_crypto_aead_algorithm aeads[] = {
899                 RTE_CRYPTO_AEAD_AES_CCM
900         };
901
902         rte_cryptodev_info_get(dev_id, &dev_info);
903
904         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
905                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
906                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
907                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
908                                 "testsuite not met\n");
909                 return TEST_SKIPPED;
910         }
911
912         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
913                 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
914                                 "testsuite not met\n");
915                 return TEST_SKIPPED;
916         }
917
918         return 0;
919 }
920
921 static int
922 aes_gcm_auth_testsuite_setup(void)
923 {
924         struct crypto_testsuite_params *ts_params = &testsuite_params;
925         uint8_t dev_id = ts_params->valid_devs[0];
926         struct rte_cryptodev_info dev_info;
927         const enum rte_crypto_aead_algorithm aeads[] = {
928                 RTE_CRYPTO_AEAD_AES_GCM
929         };
930
931         rte_cryptodev_info_get(dev_id, &dev_info);
932
933         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
934                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
935                                 "testsuite not met\n");
936                 return TEST_SKIPPED;
937         }
938
939         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
940                 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
941                                 "testsuite not met\n");
942                 return TEST_SKIPPED;
943         }
944
945         return 0;
946 }
947
948 static int
949 aes_gmac_auth_testsuite_setup(void)
950 {
951         struct crypto_testsuite_params *ts_params = &testsuite_params;
952         uint8_t dev_id = ts_params->valid_devs[0];
953         struct rte_cryptodev_info dev_info;
954         const enum rte_crypto_auth_algorithm auths[] = {
955                 RTE_CRYPTO_AUTH_AES_GMAC
956         };
957
958         rte_cryptodev_info_get(dev_id, &dev_info);
959
960         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
961                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
962                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
963                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
964                                 "testsuite not met\n");
965                 return TEST_SKIPPED;
966         }
967
968         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
969                 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
970                                 "testsuite not met\n");
971                 return TEST_SKIPPED;
972         }
973
974         return 0;
975 }
976
977 static int
978 chacha20_poly1305_testsuite_setup(void)
979 {
980         struct crypto_testsuite_params *ts_params = &testsuite_params;
981         uint8_t dev_id = ts_params->valid_devs[0];
982         struct rte_cryptodev_info dev_info;
983         const enum rte_crypto_aead_algorithm aeads[] = {
984                 RTE_CRYPTO_AEAD_CHACHA20_POLY1305
985         };
986
987         rte_cryptodev_info_get(dev_id, &dev_info);
988
989         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
990                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
991                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
992                 RTE_LOG(INFO, USER1, "Feature flag requirements for "
993                                 "Chacha20-Poly1305 testsuite not met\n");
994                 return TEST_SKIPPED;
995         }
996
997         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
998                 RTE_LOG(INFO, USER1, "Capability requirements for "
999                                 "Chacha20-Poly1305 testsuite not met\n");
1000                 return TEST_SKIPPED;
1001         }
1002
1003         return 0;
1004 }
1005
1006 static int
1007 snow3g_testsuite_setup(void)
1008 {
1009         struct crypto_testsuite_params *ts_params = &testsuite_params;
1010         uint8_t dev_id = ts_params->valid_devs[0];
1011         struct rte_cryptodev_info dev_info;
1012         const enum rte_crypto_cipher_algorithm ciphers[] = {
1013                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1014
1015         };
1016         const enum rte_crypto_auth_algorithm auths[] = {
1017                 RTE_CRYPTO_AUTH_SNOW3G_UIA2
1018         };
1019
1020         rte_cryptodev_info_get(dev_id, &dev_info);
1021
1022         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1023                 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
1024                                 "testsuite not met\n");
1025                 return TEST_SKIPPED;
1026         }
1027
1028         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1029                         && check_auth_capabilities_supported(auths,
1030                         RTE_DIM(auths)) != 0) {
1031                 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
1032                                 "testsuite not met\n");
1033                 return TEST_SKIPPED;
1034         }
1035
1036         return 0;
1037 }
1038
1039 static int
1040 zuc_testsuite_setup(void)
1041 {
1042         struct crypto_testsuite_params *ts_params = &testsuite_params;
1043         uint8_t dev_id = ts_params->valid_devs[0];
1044         struct rte_cryptodev_info dev_info;
1045         const enum rte_crypto_cipher_algorithm ciphers[] = {
1046                 RTE_CRYPTO_CIPHER_ZUC_EEA3
1047         };
1048         const enum rte_crypto_auth_algorithm auths[] = {
1049                 RTE_CRYPTO_AUTH_ZUC_EIA3
1050         };
1051
1052         rte_cryptodev_info_get(dev_id, &dev_info);
1053
1054         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1055                 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
1056                                 "testsuite not met\n");
1057                 return TEST_SKIPPED;
1058         }
1059
1060         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1061                         && check_auth_capabilities_supported(auths,
1062                         RTE_DIM(auths)) != 0) {
1063                 RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1064                                 "testsuite not met\n");
1065                 return TEST_SKIPPED;
1066         }
1067
1068         return 0;
1069 }
1070
1071 static int
1072 hmac_md5_auth_testsuite_setup(void)
1073 {
1074         struct crypto_testsuite_params *ts_params = &testsuite_params;
1075         uint8_t dev_id = ts_params->valid_devs[0];
1076         struct rte_cryptodev_info dev_info;
1077         const enum rte_crypto_auth_algorithm auths[] = {
1078                 RTE_CRYPTO_AUTH_MD5_HMAC
1079         };
1080
1081         rte_cryptodev_info_get(dev_id, &dev_info);
1082
1083         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1084                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1085                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1086                 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1087                                 "Auth testsuite not met\n");
1088                 return TEST_SKIPPED;
1089         }
1090
1091         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1092                 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1093                                 "testsuite not met\n");
1094                 return TEST_SKIPPED;
1095         }
1096
1097         return 0;
1098 }
1099
1100 static int
1101 kasumi_testsuite_setup(void)
1102 {
1103         struct crypto_testsuite_params *ts_params = &testsuite_params;
1104         uint8_t dev_id = ts_params->valid_devs[0];
1105         struct rte_cryptodev_info dev_info;
1106         const enum rte_crypto_cipher_algorithm ciphers[] = {
1107                 RTE_CRYPTO_CIPHER_KASUMI_F8
1108         };
1109         const enum rte_crypto_auth_algorithm auths[] = {
1110                 RTE_CRYPTO_AUTH_KASUMI_F9
1111         };
1112
1113         rte_cryptodev_info_get(dev_id, &dev_info);
1114
1115         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1116                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1117                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1118                 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1119                                 "testsuite not met\n");
1120                 return TEST_SKIPPED;
1121         }
1122
1123         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1124                         && check_auth_capabilities_supported(auths,
1125                         RTE_DIM(auths)) != 0) {
1126                 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1127                                 "testsuite not met\n");
1128                 return TEST_SKIPPED;
1129         }
1130
1131         return 0;
1132 }
1133
1134 static int
1135 negative_aes_gcm_testsuite_setup(void)
1136 {
1137         struct crypto_testsuite_params *ts_params = &testsuite_params;
1138         uint8_t dev_id = ts_params->valid_devs[0];
1139         struct rte_cryptodev_info dev_info;
1140         const enum rte_crypto_aead_algorithm aeads[] = {
1141                 RTE_CRYPTO_AEAD_AES_GCM
1142         };
1143
1144         rte_cryptodev_info_get(dev_id, &dev_info);
1145
1146         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1147                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1148                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1149                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1150                                 "AES GCM testsuite not met\n");
1151                 return TEST_SKIPPED;
1152         }
1153
1154         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1155                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1156                                 "AES GCM testsuite not met\n");
1157                 return TEST_SKIPPED;
1158         }
1159
1160         return 0;
1161 }
1162
1163 static int
1164 negative_aes_gmac_testsuite_setup(void)
1165 {
1166         struct crypto_testsuite_params *ts_params = &testsuite_params;
1167         uint8_t dev_id = ts_params->valid_devs[0];
1168         struct rte_cryptodev_info dev_info;
1169         const enum rte_crypto_auth_algorithm auths[] = {
1170                 RTE_CRYPTO_AUTH_AES_GMAC
1171         };
1172
1173         rte_cryptodev_info_get(dev_id, &dev_info);
1174
1175         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1176                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1177                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1178                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1179                                 "AES GMAC testsuite not met\n");
1180                 return TEST_SKIPPED;
1181         }
1182
1183         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1184                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1185                                 "AES GMAC testsuite not met\n");
1186                 return TEST_SKIPPED;
1187         }
1188
1189         return 0;
1190 }
1191
1192 static int
1193 mixed_cipher_hash_testsuite_setup(void)
1194 {
1195         struct crypto_testsuite_params *ts_params = &testsuite_params;
1196         uint8_t dev_id = ts_params->valid_devs[0];
1197         struct rte_cryptodev_info dev_info;
1198         uint64_t feat_flags;
1199         const enum rte_crypto_cipher_algorithm ciphers[] = {
1200                 RTE_CRYPTO_CIPHER_NULL,
1201                 RTE_CRYPTO_CIPHER_AES_CTR,
1202                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
1203                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1204         };
1205         const enum rte_crypto_auth_algorithm auths[] = {
1206                 RTE_CRYPTO_AUTH_NULL,
1207                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1208                 RTE_CRYPTO_AUTH_AES_CMAC,
1209                 RTE_CRYPTO_AUTH_ZUC_EIA3
1210         };
1211
1212         rte_cryptodev_info_get(dev_id, &dev_info);
1213         feat_flags = dev_info.feature_flags;
1214
1215         if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1216                         (global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1217                 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1218                                 "Cipher Hash testsuite not met\n");
1219                 return TEST_SKIPPED;
1220         }
1221
1222         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1223                         && check_auth_capabilities_supported(auths,
1224                         RTE_DIM(auths)) != 0) {
1225                 RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1226                                 "Cipher Hash testsuite not met\n");
1227                 return TEST_SKIPPED;
1228         }
1229
1230         return 0;
1231 }
1232
1233 static int
1234 esn_testsuite_setup(void)
1235 {
1236         struct crypto_testsuite_params *ts_params = &testsuite_params;
1237         uint8_t dev_id = ts_params->valid_devs[0];
1238         struct rte_cryptodev_info dev_info;
1239         const enum rte_crypto_cipher_algorithm ciphers[] = {
1240                 RTE_CRYPTO_CIPHER_AES_CBC
1241         };
1242         const enum rte_crypto_auth_algorithm auths[] = {
1243                 RTE_CRYPTO_AUTH_SHA1_HMAC
1244         };
1245
1246         rte_cryptodev_info_get(dev_id, &dev_info);
1247
1248         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1249                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1250                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1251                 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1252                                 "testsuite not met\n");
1253                 return TEST_SKIPPED;
1254         }
1255
1256         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1257                         && check_auth_capabilities_supported(auths,
1258                         RTE_DIM(auths)) != 0) {
1259                 RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1260                                 "testsuite not met\n");
1261                 return TEST_SKIPPED;
1262         }
1263
1264         return 0;
1265 }
1266
1267 static int
1268 multi_session_testsuite_setup(void)
1269 {
1270         struct crypto_testsuite_params *ts_params = &testsuite_params;
1271         uint8_t dev_id = ts_params->valid_devs[0];
1272         struct rte_cryptodev_info dev_info;
1273         const enum rte_crypto_cipher_algorithm ciphers[] = {
1274                 RTE_CRYPTO_CIPHER_AES_CBC
1275         };
1276         const enum rte_crypto_auth_algorithm auths[] = {
1277                 RTE_CRYPTO_AUTH_SHA512_HMAC
1278         };
1279
1280         rte_cryptodev_info_get(dev_id, &dev_info);
1281
1282         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1283                 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1284                                 "Session testsuite not met\n");
1285                 return TEST_SKIPPED;
1286         }
1287
1288         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1289                         && check_auth_capabilities_supported(auths,
1290                         RTE_DIM(auths)) != 0) {
1291                 RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1292                                 "Session testsuite not met\n");
1293                 return TEST_SKIPPED;
1294         }
1295
1296         return 0;
1297 }
1298
1299 static int
1300 negative_hmac_sha1_testsuite_setup(void)
1301 {
1302         struct crypto_testsuite_params *ts_params = &testsuite_params;
1303         uint8_t dev_id = ts_params->valid_devs[0];
1304         struct rte_cryptodev_info dev_info;
1305         const enum rte_crypto_cipher_algorithm ciphers[] = {
1306                 RTE_CRYPTO_CIPHER_AES_CBC
1307         };
1308         const enum rte_crypto_auth_algorithm auths[] = {
1309                 RTE_CRYPTO_AUTH_SHA1_HMAC
1310         };
1311
1312         rte_cryptodev_info_get(dev_id, &dev_info);
1313
1314         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1315                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1316                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1317                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1318                                 "HMAC SHA1 testsuite not met\n");
1319                 return TEST_SKIPPED;
1320         }
1321
1322         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1323                         && check_auth_capabilities_supported(auths,
1324                         RTE_DIM(auths)) != 0) {
1325                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1326                                 "HMAC SHA1 testsuite not met\n");
1327                 return TEST_SKIPPED;
1328         }
1329
1330         return 0;
1331 }
1332
1333 static int
1334 dev_configure_and_start(uint64_t ff_disable)
1335 {
1336         struct crypto_testsuite_params *ts_params = &testsuite_params;
1337         struct crypto_unittest_params *ut_params = &unittest_params;
1338
1339         uint16_t qp_id;
1340
1341         /* Clear unit test parameters before running test */
1342         memset(ut_params, 0, sizeof(*ut_params));
1343
1344         /* Reconfigure device to default parameters */
1345         ts_params->conf.socket_id = SOCKET_ID_ANY;
1346         ts_params->conf.ff_disable = ff_disable;
1347         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1348         ts_params->qp_conf.mp_session = ts_params->session_mpool;
1349         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1350
1351         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1352                         &ts_params->conf),
1353                         "Failed to configure cryptodev %u",
1354                         ts_params->valid_devs[0]);
1355
1356         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1357                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1358                         ts_params->valid_devs[0], qp_id,
1359                         &ts_params->qp_conf,
1360                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1361                         "Failed to setup queue pair %u on cryptodev %u",
1362                         qp_id, ts_params->valid_devs[0]);
1363         }
1364
1365
1366         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1367
1368         /* Start the device */
1369         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1370                         "Failed to start cryptodev %u",
1371                         ts_params->valid_devs[0]);
1372
1373         return TEST_SUCCESS;
1374 }
1375
1376 int
1377 ut_setup(void)
1378 {
1379         /* Configure and start the device with security feature disabled */
1380         return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1381 }
1382
1383 static int
1384 ut_setup_security(void)
1385 {
1386         /* Configure and start the device with no features disabled */
1387         return dev_configure_and_start(0);
1388 }
1389
1390 void
1391 ut_teardown(void)
1392 {
1393         struct crypto_testsuite_params *ts_params = &testsuite_params;
1394         struct crypto_unittest_params *ut_params = &unittest_params;
1395         struct rte_cryptodev_stats stats;
1396
1397         /* free crypto session structure */
1398 #ifdef RTE_LIB_SECURITY
1399         if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1400                 if (ut_params->sec_session) {
1401                         rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1402                                                 (ts_params->valid_devs[0]),
1403                                                 ut_params->sec_session);
1404                         ut_params->sec_session = NULL;
1405                 }
1406         } else
1407 #endif
1408         {
1409                 if (ut_params->sess) {
1410                         rte_cryptodev_sym_session_clear(
1411                                         ts_params->valid_devs[0],
1412                                         ut_params->sess);
1413                         rte_cryptodev_sym_session_free(ut_params->sess);
1414                         ut_params->sess = NULL;
1415                 }
1416         }
1417
1418         /* free crypto operation structure */
1419         if (ut_params->op)
1420                 rte_crypto_op_free(ut_params->op);
1421
1422         /*
1423          * free mbuf - both obuf and ibuf are usually the same,
1424          * so check if they point at the same address is necessary,
1425          * to avoid freeing the mbuf twice.
1426          */
1427         if (ut_params->obuf) {
1428                 rte_pktmbuf_free(ut_params->obuf);
1429                 if (ut_params->ibuf == ut_params->obuf)
1430                         ut_params->ibuf = 0;
1431                 ut_params->obuf = 0;
1432         }
1433         if (ut_params->ibuf) {
1434                 rte_pktmbuf_free(ut_params->ibuf);
1435                 ut_params->ibuf = 0;
1436         }
1437
1438         if (ts_params->mbuf_pool != NULL)
1439                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1440                         rte_mempool_avail_count(ts_params->mbuf_pool));
1441
1442         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1443
1444         /* Stop the device */
1445         rte_cryptodev_stop(ts_params->valid_devs[0]);
1446 }
1447
1448 static int
1449 test_device_configure_invalid_dev_id(void)
1450 {
1451         struct crypto_testsuite_params *ts_params = &testsuite_params;
1452         uint16_t dev_id, num_devs = 0;
1453
1454         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1455                         "Need at least %d devices for test", 1);
1456
1457         /* valid dev_id values */
1458         dev_id = ts_params->valid_devs[0];
1459
1460         /* Stop the device in case it's started so it can be configured */
1461         rte_cryptodev_stop(dev_id);
1462
1463         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1464                         "Failed test for rte_cryptodev_configure: "
1465                         "invalid dev_num %u", dev_id);
1466
1467         /* invalid dev_id values */
1468         dev_id = num_devs;
1469
1470         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1471                         "Failed test for rte_cryptodev_configure: "
1472                         "invalid dev_num %u", dev_id);
1473
1474         dev_id = 0xff;
1475
1476         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1477                         "Failed test for rte_cryptodev_configure:"
1478                         "invalid dev_num %u", dev_id);
1479
1480         return TEST_SUCCESS;
1481 }
1482
1483 static int
1484 test_device_configure_invalid_queue_pair_ids(void)
1485 {
1486         struct crypto_testsuite_params *ts_params = &testsuite_params;
1487         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1488
1489         /* Stop the device in case it's started so it can be configured */
1490         rte_cryptodev_stop(ts_params->valid_devs[0]);
1491
1492         /* valid - max value queue pairs */
1493         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1494
1495         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1496                         &ts_params->conf),
1497                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1498                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1499
1500         /* valid - one queue pairs */
1501         ts_params->conf.nb_queue_pairs = 1;
1502
1503         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1504                         &ts_params->conf),
1505                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1506                         ts_params->valid_devs[0],
1507                         ts_params->conf.nb_queue_pairs);
1508
1509
1510         /* invalid - zero queue pairs */
1511         ts_params->conf.nb_queue_pairs = 0;
1512
1513         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1514                         &ts_params->conf),
1515                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1516                         " invalid qps: %u",
1517                         ts_params->valid_devs[0],
1518                         ts_params->conf.nb_queue_pairs);
1519
1520
1521         /* invalid - max value supported by field queue pairs */
1522         ts_params->conf.nb_queue_pairs = UINT16_MAX;
1523
1524         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1525                         &ts_params->conf),
1526                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1527                         " invalid qps: %u",
1528                         ts_params->valid_devs[0],
1529                         ts_params->conf.nb_queue_pairs);
1530
1531
1532         /* invalid - max value + 1 queue pairs */
1533         ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1534
1535         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1536                         &ts_params->conf),
1537                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1538                         " invalid qps: %u",
1539                         ts_params->valid_devs[0],
1540                         ts_params->conf.nb_queue_pairs);
1541
1542         /* revert to original testsuite value */
1543         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1544
1545         return TEST_SUCCESS;
1546 }
1547
1548 static int
1549 test_queue_pair_descriptor_setup(void)
1550 {
1551         struct crypto_testsuite_params *ts_params = &testsuite_params;
1552         struct rte_cryptodev_qp_conf qp_conf = {
1553                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
1554         };
1555         uint16_t qp_id;
1556
1557         /* Stop the device in case it's started so it can be configured */
1558         rte_cryptodev_stop(ts_params->valid_devs[0]);
1559
1560         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1561                         &ts_params->conf),
1562                         "Failed to configure cryptodev %u",
1563                         ts_params->valid_devs[0]);
1564
1565         /*
1566          * Test various ring sizes on this device. memzones can't be
1567          * freed so are re-used if ring is released and re-created.
1568          */
1569         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1570         qp_conf.mp_session = ts_params->session_mpool;
1571         qp_conf.mp_session_private = ts_params->session_priv_mpool;
1572
1573         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1574                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1575                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1576                                 rte_cryptodev_socket_id(
1577                                                 ts_params->valid_devs[0])),
1578                                 "Failed test for "
1579                                 "rte_cryptodev_queue_pair_setup: num_inflights "
1580                                 "%u on qp %u on cryptodev %u",
1581                                 qp_conf.nb_descriptors, qp_id,
1582                                 ts_params->valid_devs[0]);
1583         }
1584
1585         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1586
1587         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1588                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1589                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1590                                 rte_cryptodev_socket_id(
1591                                                 ts_params->valid_devs[0])),
1592                                 "Failed test for"
1593                                 " rte_cryptodev_queue_pair_setup: num_inflights"
1594                                 " %u on qp %u on cryptodev %u",
1595                                 qp_conf.nb_descriptors, qp_id,
1596                                 ts_params->valid_devs[0]);
1597         }
1598
1599         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1600
1601         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1602                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1603                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1604                                 rte_cryptodev_socket_id(
1605                                                 ts_params->valid_devs[0])),
1606                                 "Failed test for "
1607                                 "rte_cryptodev_queue_pair_setup: num_inflights"
1608                                 " %u on qp %u on cryptodev %u",
1609                                 qp_conf.nb_descriptors, qp_id,
1610                                 ts_params->valid_devs[0]);
1611         }
1612
1613         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1614
1615         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1616                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1617                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1618                                 rte_cryptodev_socket_id(
1619                                                 ts_params->valid_devs[0])),
1620                                 "Failed test for"
1621                                 " rte_cryptodev_queue_pair_setup:"
1622                                 "num_inflights %u on qp %u on cryptodev %u",
1623                                 qp_conf.nb_descriptors, qp_id,
1624                                 ts_params->valid_devs[0]);
1625         }
1626
1627         /* test invalid queue pair id */
1628         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
1629
1630         qp_id = ts_params->conf.nb_queue_pairs;         /*invalid */
1631
1632         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1633                         ts_params->valid_devs[0],
1634                         qp_id, &qp_conf,
1635                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1636                         "Failed test for rte_cryptodev_queue_pair_setup:"
1637                         "invalid qp %u on cryptodev %u",
1638                         qp_id, ts_params->valid_devs[0]);
1639
1640         qp_id = 0xffff; /*invalid*/
1641
1642         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1643                         ts_params->valid_devs[0],
1644                         qp_id, &qp_conf,
1645                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1646                         "Failed test for rte_cryptodev_queue_pair_setup:"
1647                         "invalid qp %u on cryptodev %u",
1648                         qp_id, ts_params->valid_devs[0]);
1649
1650         return TEST_SUCCESS;
1651 }
1652
1653 /* ***** Plaintext data for tests ***** */
1654
1655 const char catch_22_quote_1[] =
1656                 "There was only one catch and that was Catch-22, which "
1657                 "specified that a concern for one's safety in the face of "
1658                 "dangers that were real and immediate was the process of a "
1659                 "rational mind. Orr was crazy and could be grounded. All he "
1660                 "had to do was ask; and as soon as he did, he would no longer "
1661                 "be crazy and would have to fly more missions. Orr would be "
1662                 "crazy to fly more missions and sane if he didn't, but if he "
1663                 "was sane he had to fly them. If he flew them he was crazy "
1664                 "and didn't have to; but if he didn't want to he was sane and "
1665                 "had to. Yossarian was moved very deeply by the absolute "
1666                 "simplicity of this clause of Catch-22 and let out a "
1667                 "respectful whistle. \"That's some catch, that Catch-22\", he "
1668                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
1669
1670 const char catch_22_quote[] =
1671                 "What a lousy earth! He wondered how many people were "
1672                 "destitute that same night even in his own prosperous country, "
1673                 "how many homes were shanties, how many husbands were drunk "
1674                 "and wives socked, and how many children were bullied, abused, "
1675                 "or abandoned. How many families hungered for food they could "
1676                 "not afford to buy? How many hearts were broken? How many "
1677                 "suicides would take place that same night, how many people "
1678                 "would go insane? How many cockroaches and landlords would "
1679                 "triumph? How many winners were losers, successes failures, "
1680                 "and rich men poor men? How many wise guys were stupid? How "
1681                 "many happy endings were unhappy endings? How many honest men "
1682                 "were liars, brave men cowards, loyal men traitors, how many "
1683                 "sainted men were corrupt, how many people in positions of "
1684                 "trust had sold their souls to bodyguards, how many had never "
1685                 "had souls? How many straight-and-narrow paths were crooked "
1686                 "paths? How many best families were worst families and how "
1687                 "many good people were bad people? When you added them all up "
1688                 "and then subtracted, you might be left with only the children, "
1689                 "and perhaps with Albert Einstein and an old violinist or "
1690                 "sculptor somewhere.";
1691
1692 #define QUOTE_480_BYTES         (480)
1693 #define QUOTE_512_BYTES         (512)
1694 #define QUOTE_768_BYTES         (768)
1695 #define QUOTE_1024_BYTES        (1024)
1696
1697
1698
1699 /* ***** SHA1 Hash Tests ***** */
1700
1701 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
1702
1703 static uint8_t hmac_sha1_key[] = {
1704         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1705         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1706         0xDE, 0xF4, 0xDE, 0xAD };
1707
1708 /* ***** SHA224 Hash Tests ***** */
1709
1710 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
1711
1712
1713 /* ***** AES-CBC Cipher Tests ***** */
1714
1715 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
1716 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
1717
1718 static uint8_t aes_cbc_key[] = {
1719         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1720         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1721
1722 static uint8_t aes_cbc_iv[] = {
1723         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1724         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1725
1726
1727 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1728
1729 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1730         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1731         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1732         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1733         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1734         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1735         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1736         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1737         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1738         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1739         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1740         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1741         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1742         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1743         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1744         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1745         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1746         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1747         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1748         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1749         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1750         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1751         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1752         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1753         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1754         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1755         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1756         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1757         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1758         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1759         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1760         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1761         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1762         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1763         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1764         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1765         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1766         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1767         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1768         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1769         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1770         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1771         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1772         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1773         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1774         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1775         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1776         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1777         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1778         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1779         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1780         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1781         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1782         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1783         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1784         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1785         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1786         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1787         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1788         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1789         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1790         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1791         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1792         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1793         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1794 };
1795
1796 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1797         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1798         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1799         0x18, 0x8c, 0x1d, 0x32
1800 };
1801
1802
1803 /* Multisession Vector context Test */
1804 /*Begin Session 0 */
1805 static uint8_t ms_aes_cbc_key0[] = {
1806         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1807         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1808 };
1809
1810 static uint8_t ms_aes_cbc_iv0[] = {
1811         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1812         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1813 };
1814
1815 static const uint8_t ms_aes_cbc_cipher0[] = {
1816                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1817                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1818                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1819                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1820                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1821                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1822                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1823                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1824                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1825                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1826                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1827                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1828                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1829                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1830                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1831                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1832                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1833                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1834                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1835                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1836                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1837                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1838                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1839                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1840                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1841                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1842                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1843                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1844                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1845                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1846                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1847                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1848                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1849                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1850                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1851                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1852                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1853                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1854                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1855                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1856                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1857                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1858                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1859                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1860                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1861                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1862                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1863                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1864                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1865                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1866                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1867                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1868                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1869                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1870                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1871                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1872                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1873                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1874                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1875                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1876                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1877                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1878                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1879                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1880 };
1881
1882
1883 static  uint8_t ms_hmac_key0[] = {
1884                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1885                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1886                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1887                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1888                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1889                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1890                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1891                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1892 };
1893
1894 static const uint8_t ms_hmac_digest0[] = {
1895                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1896                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1897                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1898                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1899                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1900                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1901                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1902                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1903                 };
1904
1905 /* End Session 0 */
1906 /* Begin session 1 */
1907
1908 static  uint8_t ms_aes_cbc_key1[] = {
1909                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1910                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1911 };
1912
1913 static  uint8_t ms_aes_cbc_iv1[] = {
1914         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1915         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1916 };
1917
1918 static const uint8_t ms_aes_cbc_cipher1[] = {
1919                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1920                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1921                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1922                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1923                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1924                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1925                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1926                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1927                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1928                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1929                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1930                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1931                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1932                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1933                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1934                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1935                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1936                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1937                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1938                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1939                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1940                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1941                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1942                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1943                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1944                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1945                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1946                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1947                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1948                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1949                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1950                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1951                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1952                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1953                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1954                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1955                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1956                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1957                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1958                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1959                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1960                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1961                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1962                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1963                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1964                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1965                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1966                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1967                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1968                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1969                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1970                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1971                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1972                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1973                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1974                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1975                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1976                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1977                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1978                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1979                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1980                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1981                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1982                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1983
1984 };
1985
1986 static uint8_t ms_hmac_key1[] = {
1987                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1988                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1989                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1990                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1991                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1992                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1993                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1994                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1995 };
1996
1997 static const uint8_t ms_hmac_digest1[] = {
1998                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1999                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
2000                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
2001                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
2002                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
2003                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
2004                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
2005                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
2006 };
2007 /* End Session 1  */
2008 /* Begin Session 2 */
2009 static  uint8_t ms_aes_cbc_key2[] = {
2010                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2011                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2012 };
2013
2014 static  uint8_t ms_aes_cbc_iv2[] = {
2015                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2016                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2017 };
2018
2019 static const uint8_t ms_aes_cbc_cipher2[] = {
2020                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
2021                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
2022                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
2023                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
2024                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
2025                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
2026                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
2027                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
2028                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
2029                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
2030                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
2031                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
2032                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
2033                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
2034                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
2035                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
2036                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
2037                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
2038                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
2039                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
2040                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
2041                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
2042                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
2043                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
2044                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
2045                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
2046                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
2047                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
2048                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
2049                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
2050                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
2051                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
2052                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
2053                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
2054                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
2055                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
2056                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
2057                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
2058                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
2059                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2060                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2061                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2062                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2063                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2064                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2065                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2066                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2067                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2068                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2069                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2070                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2071                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2072                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2073                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2074                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2075                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2076                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2077                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2078                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2079                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2080                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2081                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2082                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2083                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2084 };
2085
2086 static  uint8_t ms_hmac_key2[] = {
2087                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2088                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2089                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2090                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2091                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2092                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2093                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2094                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2095 };
2096
2097 static const uint8_t ms_hmac_digest2[] = {
2098                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2099                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2100                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2101                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2102                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2103                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2104                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2105                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2106 };
2107
2108 /* End Session 2 */
2109
2110
2111 static int
2112 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2113 {
2114         struct crypto_testsuite_params *ts_params = &testsuite_params;
2115         struct crypto_unittest_params *ut_params = &unittest_params;
2116
2117         /* Verify the capabilities */
2118         struct rte_cryptodev_sym_capability_idx cap_idx;
2119         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2120         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2121         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2122                         &cap_idx) == NULL)
2123                 return TEST_SKIPPED;
2124         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2125         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2126         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2127                         &cap_idx) == NULL)
2128                 return TEST_SKIPPED;
2129
2130         /* Generate test mbuf data and space for digest */
2131         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2132                         catch_22_quote, QUOTE_512_BYTES, 0);
2133
2134         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2135                         DIGEST_BYTE_LENGTH_SHA1);
2136         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2137
2138         /* Setup Cipher Parameters */
2139         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2140         ut_params->cipher_xform.next = &ut_params->auth_xform;
2141
2142         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2143         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2144         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2145         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2146         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2147         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2148
2149         /* Setup HMAC Parameters */
2150         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2151
2152         ut_params->auth_xform.next = NULL;
2153
2154         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2155         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2156         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2157         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2158         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2159
2160         ut_params->sess = rte_cryptodev_sym_session_create(
2161                         ts_params->session_mpool);
2162
2163         /* Create crypto session*/
2164         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2165                         ut_params->sess, &ut_params->cipher_xform,
2166                         ts_params->session_priv_mpool);
2167         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2168
2169         /* Generate crypto op data structure */
2170         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2171                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2172         TEST_ASSERT_NOT_NULL(ut_params->op,
2173                         "Failed to allocate symmetric crypto operation struct");
2174
2175         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2176
2177         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2178
2179         /* set crypto operation source mbuf */
2180         sym_op->m_src = ut_params->ibuf;
2181
2182         /* Set crypto operation authentication parameters */
2183         sym_op->auth.digest.data = ut_params->digest;
2184         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2185                         ut_params->ibuf, QUOTE_512_BYTES);
2186
2187         sym_op->auth.data.offset = 0;
2188         sym_op->auth.data.length = QUOTE_512_BYTES;
2189
2190         /* Copy IV at the end of the crypto operation */
2191         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2192                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2193
2194         /* Set crypto operation cipher parameters */
2195         sym_op->cipher.data.offset = 0;
2196         sym_op->cipher.data.length = QUOTE_512_BYTES;
2197
2198         /* Process crypto operation */
2199         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2200                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2201                         ut_params->op);
2202         else
2203                 TEST_ASSERT_NOT_NULL(
2204                         process_crypto_request(ts_params->valid_devs[0],
2205                                 ut_params->op),
2206                                 "failed to process sym crypto op");
2207
2208         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2209                         "crypto op processing failed");
2210
2211         /* Validate obuf */
2212         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2213                         uint8_t *);
2214
2215         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2216                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2217                         QUOTE_512_BYTES,
2218                         "ciphertext data not as expected");
2219
2220         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2221
2222         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2223                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2224                         gbl_driver_id == rte_cryptodev_driver_id_get(
2225                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2226                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2227                                         DIGEST_BYTE_LENGTH_SHA1,
2228                         "Generated digest data not as expected");
2229
2230         return TEST_SUCCESS;
2231 }
2232
2233 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2234
2235 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2236
2237 static uint8_t hmac_sha512_key[] = {
2238         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2239         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2240         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2241         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2242         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2243         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2244         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2245         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2246
2247 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2248         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2249         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2250         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2251         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2252         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2253         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2254         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2255         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2256
2257
2258
2259 static int
2260 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2261                 struct crypto_unittest_params *ut_params,
2262                 uint8_t *cipher_key,
2263                 uint8_t *hmac_key);
2264
2265 static int
2266 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2267                 struct crypto_unittest_params *ut_params,
2268                 struct crypto_testsuite_params *ts_params,
2269                 const uint8_t *cipher,
2270                 const uint8_t *digest,
2271                 const uint8_t *iv);
2272
2273
2274 static int
2275 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2276                 struct crypto_unittest_params *ut_params,
2277                 uint8_t *cipher_key,
2278                 uint8_t *hmac_key)
2279 {
2280
2281         /* Setup Cipher Parameters */
2282         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2283         ut_params->cipher_xform.next = NULL;
2284
2285         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2286         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2287         ut_params->cipher_xform.cipher.key.data = cipher_key;
2288         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2289         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2290         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2291
2292         /* Setup HMAC Parameters */
2293         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2294         ut_params->auth_xform.next = &ut_params->cipher_xform;
2295
2296         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2297         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2298         ut_params->auth_xform.auth.key.data = hmac_key;
2299         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2300         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2301
2302         return TEST_SUCCESS;
2303 }
2304
2305
2306 static int
2307 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2308                 struct crypto_unittest_params *ut_params,
2309                 struct crypto_testsuite_params *ts_params,
2310                 const uint8_t *cipher,
2311                 const uint8_t *digest,
2312                 const uint8_t *iv)
2313 {
2314         /* Generate test mbuf data and digest */
2315         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2316                         (const char *)
2317                         cipher,
2318                         QUOTE_512_BYTES, 0);
2319
2320         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2321                         DIGEST_BYTE_LENGTH_SHA512);
2322         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2323
2324         rte_memcpy(ut_params->digest,
2325                         digest,
2326                         DIGEST_BYTE_LENGTH_SHA512);
2327
2328         /* Generate Crypto op data structure */
2329         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2330                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2331         TEST_ASSERT_NOT_NULL(ut_params->op,
2332                         "Failed to allocate symmetric crypto operation struct");
2333
2334         rte_crypto_op_attach_sym_session(ut_params->op, sess);
2335
2336         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2337
2338         /* set crypto operation source mbuf */
2339         sym_op->m_src = ut_params->ibuf;
2340
2341         sym_op->auth.digest.data = ut_params->digest;
2342         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2343                         ut_params->ibuf, QUOTE_512_BYTES);
2344
2345         sym_op->auth.data.offset = 0;
2346         sym_op->auth.data.length = QUOTE_512_BYTES;
2347
2348         /* Copy IV at the end of the crypto operation */
2349         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2350                         iv, CIPHER_IV_LENGTH_AES_CBC);
2351
2352         sym_op->cipher.data.offset = 0;
2353         sym_op->cipher.data.length = QUOTE_512_BYTES;
2354
2355         /* Process crypto operation */
2356         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2357                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2358                         ut_params->op);
2359         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2360                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2361                                 ut_params->op, 1, 1, 0, 0);
2362         else
2363                 TEST_ASSERT_NOT_NULL(
2364                                 process_crypto_request(ts_params->valid_devs[0],
2365                                         ut_params->op),
2366                                         "failed to process sym crypto op");
2367
2368         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2369                         "crypto op processing failed");
2370
2371         ut_params->obuf = ut_params->op->sym->m_src;
2372
2373         /* Validate obuf */
2374         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2375                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2376                         catch_22_quote,
2377                         QUOTE_512_BYTES,
2378                         "Plaintext data not as expected");
2379
2380         /* Validate obuf */
2381         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2382                         "Digest verification failed");
2383
2384         return TEST_SUCCESS;
2385 }
2386
2387 /* ***** SNOW 3G Tests ***** */
2388 static int
2389 create_wireless_algo_hash_session(uint8_t dev_id,
2390         const uint8_t *key, const uint8_t key_len,
2391         const uint8_t iv_len, const uint8_t auth_len,
2392         enum rte_crypto_auth_operation op,
2393         enum rte_crypto_auth_algorithm algo)
2394 {
2395         uint8_t hash_key[key_len];
2396         int status;
2397
2398         struct crypto_testsuite_params *ts_params = &testsuite_params;
2399         struct crypto_unittest_params *ut_params = &unittest_params;
2400
2401         memcpy(hash_key, key, key_len);
2402
2403         debug_hexdump(stdout, "key:", key, key_len);
2404
2405         /* Setup Authentication Parameters */
2406         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2407         ut_params->auth_xform.next = NULL;
2408
2409         ut_params->auth_xform.auth.op = op;
2410         ut_params->auth_xform.auth.algo = algo;
2411         ut_params->auth_xform.auth.key.length = key_len;
2412         ut_params->auth_xform.auth.key.data = hash_key;
2413         ut_params->auth_xform.auth.digest_length = auth_len;
2414         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2415         ut_params->auth_xform.auth.iv.length = iv_len;
2416         ut_params->sess = rte_cryptodev_sym_session_create(
2417                         ts_params->session_mpool);
2418
2419         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2420                         &ut_params->auth_xform,
2421                         ts_params->session_priv_mpool);
2422         if (status == -ENOTSUP)
2423                 return TEST_SKIPPED;
2424
2425         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2426         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2427         return 0;
2428 }
2429
2430 static int
2431 create_wireless_algo_cipher_session(uint8_t dev_id,
2432                         enum rte_crypto_cipher_operation op,
2433                         enum rte_crypto_cipher_algorithm algo,
2434                         const uint8_t *key, const uint8_t key_len,
2435                         uint8_t iv_len)
2436 {
2437         uint8_t cipher_key[key_len];
2438         int status;
2439         struct crypto_testsuite_params *ts_params = &testsuite_params;
2440         struct crypto_unittest_params *ut_params = &unittest_params;
2441
2442         memcpy(cipher_key, key, key_len);
2443
2444         /* Setup Cipher Parameters */
2445         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2446         ut_params->cipher_xform.next = NULL;
2447
2448         ut_params->cipher_xform.cipher.algo = algo;
2449         ut_params->cipher_xform.cipher.op = op;
2450         ut_params->cipher_xform.cipher.key.data = cipher_key;
2451         ut_params->cipher_xform.cipher.key.length = key_len;
2452         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2453         ut_params->cipher_xform.cipher.iv.length = iv_len;
2454
2455         debug_hexdump(stdout, "key:", key, key_len);
2456
2457         /* Create Crypto session */
2458         ut_params->sess = rte_cryptodev_sym_session_create(
2459                         ts_params->session_mpool);
2460
2461         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2462                         &ut_params->cipher_xform,
2463                         ts_params->session_priv_mpool);
2464         if (status == -ENOTSUP)
2465                 return TEST_SKIPPED;
2466
2467         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2468         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2469         return 0;
2470 }
2471
2472 static int
2473 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2474                         unsigned int cipher_len,
2475                         unsigned int cipher_offset)
2476 {
2477         struct crypto_testsuite_params *ts_params = &testsuite_params;
2478         struct crypto_unittest_params *ut_params = &unittest_params;
2479
2480         /* Generate Crypto op data structure */
2481         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2482                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2483         TEST_ASSERT_NOT_NULL(ut_params->op,
2484                                 "Failed to allocate pktmbuf offload");
2485
2486         /* Set crypto operation data parameters */
2487         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2488
2489         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2490
2491         /* set crypto operation source mbuf */
2492         sym_op->m_src = ut_params->ibuf;
2493
2494         /* iv */
2495         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2496                         iv, iv_len);
2497         sym_op->cipher.data.length = cipher_len;
2498         sym_op->cipher.data.offset = cipher_offset;
2499         return 0;
2500 }
2501
2502 static int
2503 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2504                         unsigned int cipher_len,
2505                         unsigned int cipher_offset)
2506 {
2507         struct crypto_testsuite_params *ts_params = &testsuite_params;
2508         struct crypto_unittest_params *ut_params = &unittest_params;
2509
2510         /* Generate Crypto op data structure */
2511         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2512                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2513         TEST_ASSERT_NOT_NULL(ut_params->op,
2514                                 "Failed to allocate pktmbuf offload");
2515
2516         /* Set crypto operation data parameters */
2517         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2518
2519         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2520
2521         /* set crypto operation source mbuf */
2522         sym_op->m_src = ut_params->ibuf;
2523         sym_op->m_dst = ut_params->obuf;
2524
2525         /* iv */
2526         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2527                         iv, iv_len);
2528         sym_op->cipher.data.length = cipher_len;
2529         sym_op->cipher.data.offset = cipher_offset;
2530         return 0;
2531 }
2532
2533 static int
2534 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2535                 enum rte_crypto_cipher_operation cipher_op,
2536                 enum rte_crypto_auth_operation auth_op,
2537                 enum rte_crypto_auth_algorithm auth_algo,
2538                 enum rte_crypto_cipher_algorithm cipher_algo,
2539                 const uint8_t *key, uint8_t key_len,
2540                 uint8_t auth_iv_len, uint8_t auth_len,
2541                 uint8_t cipher_iv_len)
2542
2543 {
2544         uint8_t cipher_auth_key[key_len];
2545         int status;
2546
2547         struct crypto_testsuite_params *ts_params = &testsuite_params;
2548         struct crypto_unittest_params *ut_params = &unittest_params;
2549
2550         memcpy(cipher_auth_key, key, key_len);
2551
2552         /* Setup Authentication Parameters */
2553         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2554         ut_params->auth_xform.next = NULL;
2555
2556         ut_params->auth_xform.auth.op = auth_op;
2557         ut_params->auth_xform.auth.algo = auth_algo;
2558         ut_params->auth_xform.auth.key.length = key_len;
2559         /* Hash key = cipher key */
2560         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2561         ut_params->auth_xform.auth.digest_length = auth_len;
2562         /* Auth IV will be after cipher IV */
2563         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2564         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2565
2566         /* Setup Cipher Parameters */
2567         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2568         ut_params->cipher_xform.next = &ut_params->auth_xform;
2569
2570         ut_params->cipher_xform.cipher.algo = cipher_algo;
2571         ut_params->cipher_xform.cipher.op = cipher_op;
2572         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2573         ut_params->cipher_xform.cipher.key.length = key_len;
2574         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2575         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2576
2577         debug_hexdump(stdout, "key:", key, key_len);
2578
2579         /* Create Crypto session*/
2580         ut_params->sess = rte_cryptodev_sym_session_create(
2581                         ts_params->session_mpool);
2582         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2583
2584         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2585                         &ut_params->cipher_xform,
2586                         ts_params->session_priv_mpool);
2587         if (status == -ENOTSUP)
2588                 return TEST_SKIPPED;
2589
2590         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2591         return 0;
2592 }
2593
2594 static int
2595 create_wireless_cipher_auth_session(uint8_t dev_id,
2596                 enum rte_crypto_cipher_operation cipher_op,
2597                 enum rte_crypto_auth_operation auth_op,
2598                 enum rte_crypto_auth_algorithm auth_algo,
2599                 enum rte_crypto_cipher_algorithm cipher_algo,
2600                 const struct wireless_test_data *tdata)
2601 {
2602         const uint8_t key_len = tdata->key.len;
2603         uint8_t cipher_auth_key[key_len];
2604         int status;
2605
2606         struct crypto_testsuite_params *ts_params = &testsuite_params;
2607         struct crypto_unittest_params *ut_params = &unittest_params;
2608         const uint8_t *key = tdata->key.data;
2609         const uint8_t auth_len = tdata->digest.len;
2610         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2611         uint8_t auth_iv_len = tdata->auth_iv.len;
2612
2613         memcpy(cipher_auth_key, key, key_len);
2614
2615         /* Setup Authentication Parameters */
2616         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2617         ut_params->auth_xform.next = NULL;
2618
2619         ut_params->auth_xform.auth.op = auth_op;
2620         ut_params->auth_xform.auth.algo = auth_algo;
2621         ut_params->auth_xform.auth.key.length = key_len;
2622         /* Hash key = cipher key */
2623         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2624         ut_params->auth_xform.auth.digest_length = auth_len;
2625         /* Auth IV will be after cipher IV */
2626         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2627         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2628
2629         /* Setup Cipher Parameters */
2630         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2631         ut_params->cipher_xform.next = &ut_params->auth_xform;
2632
2633         ut_params->cipher_xform.cipher.algo = cipher_algo;
2634         ut_params->cipher_xform.cipher.op = cipher_op;
2635         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2636         ut_params->cipher_xform.cipher.key.length = key_len;
2637         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2638         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2639
2640
2641         debug_hexdump(stdout, "key:", key, key_len);
2642
2643         /* Create Crypto session*/
2644         ut_params->sess = rte_cryptodev_sym_session_create(
2645                         ts_params->session_mpool);
2646
2647         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2648                         &ut_params->cipher_xform,
2649                         ts_params->session_priv_mpool);
2650         if (status == -ENOTSUP)
2651                 return TEST_SKIPPED;
2652
2653         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2654         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2655         return 0;
2656 }
2657
2658 static int
2659 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2660                 const struct wireless_test_data *tdata)
2661 {
2662         return create_wireless_cipher_auth_session(dev_id,
2663                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2664                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2665                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2666 }
2667
2668 static int
2669 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2670                 enum rte_crypto_cipher_operation cipher_op,
2671                 enum rte_crypto_auth_operation auth_op,
2672                 enum rte_crypto_auth_algorithm auth_algo,
2673                 enum rte_crypto_cipher_algorithm cipher_algo,
2674                 const uint8_t *key, const uint8_t key_len,
2675                 uint8_t auth_iv_len, uint8_t auth_len,
2676                 uint8_t cipher_iv_len)
2677 {
2678         uint8_t auth_cipher_key[key_len];
2679         int status;
2680         struct crypto_testsuite_params *ts_params = &testsuite_params;
2681         struct crypto_unittest_params *ut_params = &unittest_params;
2682
2683         memcpy(auth_cipher_key, key, key_len);
2684
2685         /* Setup Authentication Parameters */
2686         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2687         ut_params->auth_xform.auth.op = auth_op;
2688         ut_params->auth_xform.next = &ut_params->cipher_xform;
2689         ut_params->auth_xform.auth.algo = auth_algo;
2690         ut_params->auth_xform.auth.key.length = key_len;
2691         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2692         ut_params->auth_xform.auth.digest_length = auth_len;
2693         /* Auth IV will be after cipher IV */
2694         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2695         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2696
2697         /* Setup Cipher Parameters */
2698         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2699         ut_params->cipher_xform.next = NULL;
2700         ut_params->cipher_xform.cipher.algo = cipher_algo;
2701         ut_params->cipher_xform.cipher.op = cipher_op;
2702         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2703         ut_params->cipher_xform.cipher.key.length = key_len;
2704         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2705         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2706
2707         debug_hexdump(stdout, "key:", key, key_len);
2708
2709         /* Create Crypto session*/
2710         ut_params->sess = rte_cryptodev_sym_session_create(
2711                         ts_params->session_mpool);
2712         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2713
2714         if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2715                 ut_params->auth_xform.next = NULL;
2716                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2717                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2718                                 &ut_params->cipher_xform,
2719                                 ts_params->session_priv_mpool);
2720
2721         } else
2722                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2723                                 &ut_params->auth_xform,
2724                                 ts_params->session_priv_mpool);
2725
2726         if (status == -ENOTSUP)
2727                 return TEST_SKIPPED;
2728
2729         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2730
2731         return 0;
2732 }
2733
2734 static int
2735 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2736                 unsigned int auth_tag_len,
2737                 const uint8_t *iv, unsigned int iv_len,
2738                 unsigned int data_pad_len,
2739                 enum rte_crypto_auth_operation op,
2740                 unsigned int auth_len, unsigned int auth_offset)
2741 {
2742         struct crypto_testsuite_params *ts_params = &testsuite_params;
2743
2744         struct crypto_unittest_params *ut_params = &unittest_params;
2745
2746         /* Generate Crypto op data structure */
2747         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2748                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2749         TEST_ASSERT_NOT_NULL(ut_params->op,
2750                 "Failed to allocate pktmbuf offload");
2751
2752         /* Set crypto operation data parameters */
2753         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2754
2755         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2756
2757         /* set crypto operation source mbuf */
2758         sym_op->m_src = ut_params->ibuf;
2759
2760         /* iv */
2761         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2762                         iv, iv_len);
2763         /* digest */
2764         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2765                                         ut_params->ibuf, auth_tag_len);
2766
2767         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2768                                 "no room to append auth tag");
2769         ut_params->digest = sym_op->auth.digest.data;
2770         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2771                         ut_params->ibuf, data_pad_len);
2772         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2773                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2774         else
2775                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2776
2777         debug_hexdump(stdout, "digest:",
2778                 sym_op->auth.digest.data,
2779                 auth_tag_len);
2780
2781         sym_op->auth.data.length = auth_len;
2782         sym_op->auth.data.offset = auth_offset;
2783
2784         return 0;
2785 }
2786
2787 static int
2788 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2789         enum rte_crypto_auth_operation op)
2790 {
2791         struct crypto_testsuite_params *ts_params = &testsuite_params;
2792         struct crypto_unittest_params *ut_params = &unittest_params;
2793
2794         const uint8_t *auth_tag = tdata->digest.data;
2795         const unsigned int auth_tag_len = tdata->digest.len;
2796         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2797         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2798
2799         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2800         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2801         const uint8_t *auth_iv = tdata->auth_iv.data;
2802         const uint8_t auth_iv_len = tdata->auth_iv.len;
2803         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2804         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2805
2806         /* Generate Crypto op data structure */
2807         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2808                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2809         TEST_ASSERT_NOT_NULL(ut_params->op,
2810                         "Failed to allocate pktmbuf offload");
2811         /* Set crypto operation data parameters */
2812         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2813
2814         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2815
2816         /* set crypto operation source mbuf */
2817         sym_op->m_src = ut_params->ibuf;
2818
2819         /* digest */
2820         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2821                         ut_params->ibuf, auth_tag_len);
2822
2823         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2824                         "no room to append auth tag");
2825         ut_params->digest = sym_op->auth.digest.data;
2826         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2827                         ut_params->ibuf, data_pad_len);
2828         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2829                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2830         else
2831                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2832
2833         debug_hexdump(stdout, "digest:",
2834                 sym_op->auth.digest.data,
2835                 auth_tag_len);
2836
2837         /* Copy cipher and auth IVs at the end of the crypto operation */
2838         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2839                                                 IV_OFFSET);
2840         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2841         iv_ptr += cipher_iv_len;
2842         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2843
2844         sym_op->cipher.data.length = cipher_len;
2845         sym_op->cipher.data.offset = 0;
2846         sym_op->auth.data.length = auth_len;
2847         sym_op->auth.data.offset = 0;
2848
2849         return 0;
2850 }
2851
2852 static int
2853 create_zuc_cipher_hash_generate_operation(
2854                 const struct wireless_test_data *tdata)
2855 {
2856         return create_wireless_cipher_hash_operation(tdata,
2857                 RTE_CRYPTO_AUTH_OP_GENERATE);
2858 }
2859
2860 static int
2861 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2862                 const unsigned auth_tag_len,
2863                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2864                 unsigned data_pad_len,
2865                 enum rte_crypto_auth_operation op,
2866                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2867                 const unsigned cipher_len, const unsigned cipher_offset,
2868                 const unsigned auth_len, const unsigned auth_offset)
2869 {
2870         struct crypto_testsuite_params *ts_params = &testsuite_params;
2871         struct crypto_unittest_params *ut_params = &unittest_params;
2872
2873         enum rte_crypto_cipher_algorithm cipher_algo =
2874                         ut_params->cipher_xform.cipher.algo;
2875         enum rte_crypto_auth_algorithm auth_algo =
2876                         ut_params->auth_xform.auth.algo;
2877
2878         /* Generate Crypto op data structure */
2879         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2880                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2881         TEST_ASSERT_NOT_NULL(ut_params->op,
2882                         "Failed to allocate pktmbuf offload");
2883         /* Set crypto operation data parameters */
2884         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2885
2886         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2887
2888         /* set crypto operation source mbuf */
2889         sym_op->m_src = ut_params->ibuf;
2890
2891         /* digest */
2892         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2893                         ut_params->ibuf, auth_tag_len);
2894
2895         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2896                         "no room to append auth tag");
2897         ut_params->digest = sym_op->auth.digest.data;
2898
2899         if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2900                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2901                                 ut_params->ibuf, data_pad_len);
2902         } else {
2903                 struct rte_mbuf *m = ut_params->ibuf;
2904                 unsigned int offset = data_pad_len;
2905
2906                 while (offset > m->data_len && m->next != NULL) {
2907                         offset -= m->data_len;
2908                         m = m->next;
2909                 }
2910                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2911                         m, offset);
2912         }
2913
2914         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2915                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2916         else
2917                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2918
2919         debug_hexdump(stdout, "digest:",
2920                 sym_op->auth.digest.data,
2921                 auth_tag_len);
2922
2923         /* Copy cipher and auth IVs at the end of the crypto operation */
2924         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2925                                                 IV_OFFSET);
2926         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2927         iv_ptr += cipher_iv_len;
2928         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2929
2930         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2931                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2932                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2933                 sym_op->cipher.data.length = cipher_len;
2934                 sym_op->cipher.data.offset = cipher_offset;
2935         } else {
2936                 sym_op->cipher.data.length = cipher_len >> 3;
2937                 sym_op->cipher.data.offset = cipher_offset >> 3;
2938         }
2939
2940         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2941                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2942                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2943                 sym_op->auth.data.length = auth_len;
2944                 sym_op->auth.data.offset = auth_offset;
2945         } else {
2946                 sym_op->auth.data.length = auth_len >> 3;
2947                 sym_op->auth.data.offset = auth_offset >> 3;
2948         }
2949
2950         return 0;
2951 }
2952
2953 static int
2954 create_wireless_algo_auth_cipher_operation(
2955                 const uint8_t *auth_tag, unsigned int auth_tag_len,
2956                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2957                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2958                 unsigned int data_pad_len,
2959                 unsigned int cipher_len, unsigned int cipher_offset,
2960                 unsigned int auth_len, unsigned int auth_offset,
2961                 uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2962 {
2963         struct crypto_testsuite_params *ts_params = &testsuite_params;
2964         struct crypto_unittest_params *ut_params = &unittest_params;
2965
2966         enum rte_crypto_cipher_algorithm cipher_algo =
2967                         ut_params->cipher_xform.cipher.algo;
2968         enum rte_crypto_auth_algorithm auth_algo =
2969                         ut_params->auth_xform.auth.algo;
2970
2971         /* Generate Crypto op data structure */
2972         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2973                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2974         TEST_ASSERT_NOT_NULL(ut_params->op,
2975                         "Failed to allocate pktmbuf offload");
2976
2977         /* Set crypto operation data parameters */
2978         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2979
2980         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2981
2982         /* set crypto operation mbufs */
2983         sym_op->m_src = ut_params->ibuf;
2984         if (op_mode == OUT_OF_PLACE)
2985                 sym_op->m_dst = ut_params->obuf;
2986
2987         /* digest */
2988         if (!do_sgl) {
2989                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2990                         (op_mode == IN_PLACE ?
2991                                 ut_params->ibuf : ut_params->obuf),
2992                         uint8_t *, data_pad_len);
2993                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2994                         (op_mode == IN_PLACE ?
2995                                 ut_params->ibuf : ut_params->obuf),
2996                         data_pad_len);
2997                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2998         } else {
2999                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
3000                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
3001                                 sym_op->m_src : sym_op->m_dst);
3002                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
3003                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
3004                         sgl_buf = sgl_buf->next;
3005                 }
3006                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
3007                                 uint8_t *, remaining_off);
3008                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
3009                                 remaining_off);
3010                 memset(sym_op->auth.digest.data, 0, remaining_off);
3011                 while (sgl_buf->next != NULL) {
3012                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
3013                                 0, rte_pktmbuf_data_len(sgl_buf));
3014                         sgl_buf = sgl_buf->next;
3015                 }
3016         }
3017
3018         /* Copy digest for the verification */
3019         if (verify)
3020                 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3021
3022         /* Copy cipher and auth IVs at the end of the crypto operation */
3023         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3024                         ut_params->op, uint8_t *, IV_OFFSET);
3025
3026         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3027         iv_ptr += cipher_iv_len;
3028         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3029
3030         /* Only copy over the offset data needed from src to dst in OOP,
3031          * if the auth and cipher offsets are not aligned
3032          */
3033         if (op_mode == OUT_OF_PLACE) {
3034                 if (cipher_offset > auth_offset)
3035                         rte_memcpy(
3036                                 rte_pktmbuf_mtod_offset(
3037                                         sym_op->m_dst,
3038                                         uint8_t *, auth_offset >> 3),
3039                                 rte_pktmbuf_mtod_offset(
3040                                         sym_op->m_src,
3041                                         uint8_t *, auth_offset >> 3),
3042                                 ((cipher_offset >> 3) - (auth_offset >> 3)));
3043         }
3044
3045         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3046                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3047                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3048                 sym_op->cipher.data.length = cipher_len;
3049                 sym_op->cipher.data.offset = cipher_offset;
3050         } else {
3051                 sym_op->cipher.data.length = cipher_len >> 3;
3052                 sym_op->cipher.data.offset = cipher_offset >> 3;
3053         }
3054
3055         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3056                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3057                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3058                 sym_op->auth.data.length = auth_len;
3059                 sym_op->auth.data.offset = auth_offset;
3060         } else {
3061                 sym_op->auth.data.length = auth_len >> 3;
3062                 sym_op->auth.data.offset = auth_offset >> 3;
3063         }
3064
3065         return 0;
3066 }
3067
3068 static int
3069 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3070 {
3071         struct crypto_testsuite_params *ts_params = &testsuite_params;
3072         struct crypto_unittest_params *ut_params = &unittest_params;
3073
3074         int retval;
3075         unsigned plaintext_pad_len;
3076         unsigned plaintext_len;
3077         uint8_t *plaintext;
3078         struct rte_cryptodev_info dev_info;
3079
3080         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3081         uint64_t feat_flags = dev_info.feature_flags;
3082
3083         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3084                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3085                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3086                 return TEST_SKIPPED;
3087         }
3088
3089         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3090                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3091                 printf("Device doesn't support RAW data-path APIs.\n");
3092                 return TEST_SKIPPED;
3093         }
3094
3095         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3096                 return TEST_SKIPPED;
3097
3098         /* Verify the capabilities */
3099         struct rte_cryptodev_sym_capability_idx cap_idx;
3100         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3101         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3102         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3103                         &cap_idx) == NULL)
3104                 return TEST_SKIPPED;
3105
3106         /* Create SNOW 3G session */
3107         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3108                         tdata->key.data, tdata->key.len,
3109                         tdata->auth_iv.len, tdata->digest.len,
3110                         RTE_CRYPTO_AUTH_OP_GENERATE,
3111                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3112         if (retval < 0)
3113                 return retval;
3114
3115         /* alloc mbuf and set payload */
3116         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3117
3118         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3119         rte_pktmbuf_tailroom(ut_params->ibuf));
3120
3121         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3122         /* Append data which is padded to a multiple of */
3123         /* the algorithms block size */
3124         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3125         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3126                                 plaintext_pad_len);
3127         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3128
3129         /* Create SNOW 3G operation */
3130         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3131                         tdata->auth_iv.data, tdata->auth_iv.len,
3132                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3133                         tdata->validAuthLenInBits.len,
3134                         0);
3135         if (retval < 0)
3136                 return retval;
3137
3138         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3139                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3140                                 ut_params->op, 0, 1, 1, 0);
3141         else
3142                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3143                                 ut_params->op);
3144         ut_params->obuf = ut_params->op->sym->m_src;
3145         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3146         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3147                         + plaintext_pad_len;
3148
3149         /* Validate obuf */
3150         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3151         ut_params->digest,
3152         tdata->digest.data,
3153         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3154         "SNOW 3G Generated auth tag not as expected");
3155
3156         return 0;
3157 }
3158
3159 static int
3160 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3161 {
3162         struct crypto_testsuite_params *ts_params = &testsuite_params;
3163         struct crypto_unittest_params *ut_params = &unittest_params;
3164
3165         int retval;
3166         unsigned plaintext_pad_len;
3167         unsigned plaintext_len;
3168         uint8_t *plaintext;
3169         struct rte_cryptodev_info dev_info;
3170
3171         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3172         uint64_t feat_flags = dev_info.feature_flags;
3173
3174         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3175                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3176                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3177                 return TEST_SKIPPED;
3178         }
3179
3180         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3181                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3182                 printf("Device doesn't support RAW data-path APIs.\n");
3183                 return TEST_SKIPPED;
3184         }
3185
3186         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3187                 return TEST_SKIPPED;
3188
3189         /* Verify the capabilities */
3190         struct rte_cryptodev_sym_capability_idx cap_idx;
3191         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3192         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3193         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3194                         &cap_idx) == NULL)
3195                 return TEST_SKIPPED;
3196
3197         /* Create SNOW 3G session */
3198         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3199                                 tdata->key.data, tdata->key.len,
3200                                 tdata->auth_iv.len, tdata->digest.len,
3201                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3202                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3203         if (retval < 0)
3204                 return retval;
3205         /* alloc mbuf and set payload */
3206         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3207
3208         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3209         rte_pktmbuf_tailroom(ut_params->ibuf));
3210
3211         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3212         /* Append data which is padded to a multiple of */
3213         /* the algorithms block size */
3214         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3215         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3216                                 plaintext_pad_len);
3217         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3218
3219         /* Create SNOW 3G operation */
3220         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3221                         tdata->digest.len,
3222                         tdata->auth_iv.data, tdata->auth_iv.len,
3223                         plaintext_pad_len,
3224                         RTE_CRYPTO_AUTH_OP_VERIFY,
3225                         tdata->validAuthLenInBits.len,
3226                         0);
3227         if (retval < 0)
3228                 return retval;
3229
3230         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3231                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3232                                 ut_params->op, 0, 1, 1, 0);
3233         else
3234                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3235                                 ut_params->op);
3236         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3237         ut_params->obuf = ut_params->op->sym->m_src;
3238         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3239                                 + plaintext_pad_len;
3240
3241         /* Validate obuf */
3242         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3243                 return 0;
3244         else
3245                 return -1;
3246
3247         return 0;
3248 }
3249
3250 static int
3251 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3252 {
3253         struct crypto_testsuite_params *ts_params = &testsuite_params;
3254         struct crypto_unittest_params *ut_params = &unittest_params;
3255
3256         int retval;
3257         unsigned plaintext_pad_len;
3258         unsigned plaintext_len;
3259         uint8_t *plaintext;
3260         struct rte_cryptodev_info dev_info;
3261
3262         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3263         uint64_t feat_flags = dev_info.feature_flags;
3264
3265         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3266                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3267                 printf("Device doesn't support RAW data-path APIs.\n");
3268                 return TEST_SKIPPED;
3269         }
3270
3271         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3272                 return TEST_SKIPPED;
3273
3274         /* Verify the capabilities */
3275         struct rte_cryptodev_sym_capability_idx cap_idx;
3276         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3277         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3278         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3279                         &cap_idx) == NULL)
3280                 return TEST_SKIPPED;
3281
3282         /* Create KASUMI session */
3283         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3284                         tdata->key.data, tdata->key.len,
3285                         0, tdata->digest.len,
3286                         RTE_CRYPTO_AUTH_OP_GENERATE,
3287                         RTE_CRYPTO_AUTH_KASUMI_F9);
3288         if (retval < 0)
3289                 return retval;
3290
3291         /* alloc mbuf and set payload */
3292         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3293
3294         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3295         rte_pktmbuf_tailroom(ut_params->ibuf));
3296
3297         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3298         /* Append data which is padded to a multiple of */
3299         /* the algorithms block size */
3300         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3301         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3302                                 plaintext_pad_len);
3303         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3304
3305         /* Create KASUMI operation */
3306         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3307                         NULL, 0,
3308                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3309                         tdata->plaintext.len,
3310                         0);
3311         if (retval < 0)
3312                 return retval;
3313
3314         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3315                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3316                         ut_params->op);
3317         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3318                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3319                                 ut_params->op, 0, 1, 1, 0);
3320         else
3321                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3322                         ut_params->op);
3323
3324         ut_params->obuf = ut_params->op->sym->m_src;
3325         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3326         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3327                         + plaintext_pad_len;
3328
3329         /* Validate obuf */
3330         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3331         ut_params->digest,
3332         tdata->digest.data,
3333         DIGEST_BYTE_LENGTH_KASUMI_F9,
3334         "KASUMI Generated auth tag not as expected");
3335
3336         return 0;
3337 }
3338
3339 static int
3340 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3341 {
3342         struct crypto_testsuite_params *ts_params = &testsuite_params;
3343         struct crypto_unittest_params *ut_params = &unittest_params;
3344
3345         int retval;
3346         unsigned plaintext_pad_len;
3347         unsigned plaintext_len;
3348         uint8_t *plaintext;
3349         struct rte_cryptodev_info dev_info;
3350
3351         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3352         uint64_t feat_flags = dev_info.feature_flags;
3353
3354         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3355                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3356                 printf("Device doesn't support RAW data-path APIs.\n");
3357                 return TEST_SKIPPED;
3358         }
3359
3360         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3361                 return TEST_SKIPPED;
3362
3363         /* Verify the capabilities */
3364         struct rte_cryptodev_sym_capability_idx cap_idx;
3365         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3366         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3367         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3368                         &cap_idx) == NULL)
3369                 return TEST_SKIPPED;
3370
3371         /* Create KASUMI session */
3372         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3373                                 tdata->key.data, tdata->key.len,
3374                                 0, tdata->digest.len,
3375                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3376                                 RTE_CRYPTO_AUTH_KASUMI_F9);
3377         if (retval < 0)
3378                 return retval;
3379         /* alloc mbuf and set payload */
3380         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3381
3382         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3383         rte_pktmbuf_tailroom(ut_params->ibuf));
3384
3385         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3386         /* Append data which is padded to a multiple */
3387         /* of the algorithms block size */
3388         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3389         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3390                                 plaintext_pad_len);
3391         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3392
3393         /* Create KASUMI operation */
3394         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3395                         tdata->digest.len,
3396                         NULL, 0,
3397                         plaintext_pad_len,
3398                         RTE_CRYPTO_AUTH_OP_VERIFY,
3399                         tdata->plaintext.len,
3400                         0);
3401         if (retval < 0)
3402                 return retval;
3403
3404         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3405                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3406                                 ut_params->op, 0, 1, 1, 0);
3407         else
3408                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3409                                 ut_params->op);
3410         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3411         ut_params->obuf = ut_params->op->sym->m_src;
3412         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3413                                 + plaintext_pad_len;
3414
3415         /* Validate obuf */
3416         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3417                 return 0;
3418         else
3419                 return -1;
3420
3421         return 0;
3422 }
3423
3424 static int
3425 test_snow3g_hash_generate_test_case_1(void)
3426 {
3427         return test_snow3g_authentication(&snow3g_hash_test_case_1);
3428 }
3429
3430 static int
3431 test_snow3g_hash_generate_test_case_2(void)
3432 {
3433         return test_snow3g_authentication(&snow3g_hash_test_case_2);
3434 }
3435
3436 static int
3437 test_snow3g_hash_generate_test_case_3(void)
3438 {
3439         return test_snow3g_authentication(&snow3g_hash_test_case_3);
3440 }
3441
3442 static int
3443 test_snow3g_hash_generate_test_case_4(void)
3444 {
3445         return test_snow3g_authentication(&snow3g_hash_test_case_4);
3446 }
3447
3448 static int
3449 test_snow3g_hash_generate_test_case_5(void)
3450 {
3451         return test_snow3g_authentication(&snow3g_hash_test_case_5);
3452 }
3453
3454 static int
3455 test_snow3g_hash_generate_test_case_6(void)
3456 {
3457         return test_snow3g_authentication(&snow3g_hash_test_case_6);
3458 }
3459
3460 static int
3461 test_snow3g_hash_verify_test_case_1(void)
3462 {
3463         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3464
3465 }
3466
3467 static int
3468 test_snow3g_hash_verify_test_case_2(void)
3469 {
3470         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3471 }
3472
3473 static int
3474 test_snow3g_hash_verify_test_case_3(void)
3475 {
3476         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3477 }
3478
3479 static int
3480 test_snow3g_hash_verify_test_case_4(void)
3481 {
3482         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3483 }
3484
3485 static int
3486 test_snow3g_hash_verify_test_case_5(void)
3487 {
3488         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3489 }
3490
3491 static int
3492 test_snow3g_hash_verify_test_case_6(void)
3493 {
3494         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3495 }
3496
3497 static int
3498 test_kasumi_hash_generate_test_case_1(void)
3499 {
3500         return test_kasumi_authentication(&kasumi_hash_test_case_1);
3501 }
3502
3503 static int
3504 test_kasumi_hash_generate_test_case_2(void)
3505 {
3506         return test_kasumi_authentication(&kasumi_hash_test_case_2);
3507 }
3508
3509 static int
3510 test_kasumi_hash_generate_test_case_3(void)
3511 {
3512         return test_kasumi_authentication(&kasumi_hash_test_case_3);
3513 }
3514
3515 static int
3516 test_kasumi_hash_generate_test_case_4(void)
3517 {
3518         return test_kasumi_authentication(&kasumi_hash_test_case_4);
3519 }
3520
3521 static int
3522 test_kasumi_hash_generate_test_case_5(void)
3523 {
3524         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3525 }
3526
3527 static int
3528 test_kasumi_hash_generate_test_case_6(void)
3529 {
3530         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3531 }
3532
3533 static int
3534 test_kasumi_hash_verify_test_case_1(void)
3535 {
3536         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3537 }
3538
3539 static int
3540 test_kasumi_hash_verify_test_case_2(void)
3541 {
3542         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3543 }
3544
3545 static int
3546 test_kasumi_hash_verify_test_case_3(void)
3547 {
3548         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3549 }
3550
3551 static int
3552 test_kasumi_hash_verify_test_case_4(void)
3553 {
3554         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3555 }
3556
3557 static int
3558 test_kasumi_hash_verify_test_case_5(void)
3559 {
3560         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3561 }
3562
3563 static int
3564 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3565 {
3566         struct crypto_testsuite_params *ts_params = &testsuite_params;
3567         struct crypto_unittest_params *ut_params = &unittest_params;
3568
3569         int retval;
3570         uint8_t *plaintext, *ciphertext;
3571         unsigned plaintext_pad_len;
3572         unsigned plaintext_len;
3573         struct rte_cryptodev_info dev_info;
3574
3575         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3576         uint64_t feat_flags = dev_info.feature_flags;
3577
3578         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3579                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3580                 printf("Device doesn't support RAW data-path APIs.\n");
3581                 return TEST_SKIPPED;
3582         }
3583
3584         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3585                 return TEST_SKIPPED;
3586
3587         /* Verify the capabilities */
3588         struct rte_cryptodev_sym_capability_idx cap_idx;
3589         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3590         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3591         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3592                         &cap_idx) == NULL)
3593                 return TEST_SKIPPED;
3594
3595         /* Create KASUMI session */
3596         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3597                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3598                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3599                                         tdata->key.data, tdata->key.len,
3600                                         tdata->cipher_iv.len);
3601         if (retval < 0)
3602                 return retval;
3603
3604         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3605
3606         /* Clear mbuf payload */
3607         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3608                rte_pktmbuf_tailroom(ut_params->ibuf));
3609
3610         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3611         /* Append data which is padded to a multiple */
3612         /* of the algorithms block size */
3613         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3614         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3615                                 plaintext_pad_len);
3616         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3617
3618         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3619
3620         /* Create KASUMI operation */
3621         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3622                                 tdata->cipher_iv.len,
3623                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3624                                 tdata->validCipherOffsetInBits.len);
3625         if (retval < 0)
3626                 return retval;
3627
3628         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3629                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3630                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3631         else
3632                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3633                                 ut_params->op);
3634         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3635
3636         ut_params->obuf = ut_params->op->sym->m_dst;
3637         if (ut_params->obuf)
3638                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3639         else
3640                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3641
3642         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3643
3644         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3645                                 (tdata->validCipherOffsetInBits.len >> 3);
3646         /* Validate obuf */
3647         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3648                 ciphertext,
3649                 reference_ciphertext,
3650                 tdata->validCipherLenInBits.len,
3651                 "KASUMI Ciphertext data not as expected");
3652         return 0;
3653 }
3654
3655 static int
3656 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3657 {
3658         struct crypto_testsuite_params *ts_params = &testsuite_params;
3659         struct crypto_unittest_params *ut_params = &unittest_params;
3660
3661         int retval;
3662
3663         unsigned int plaintext_pad_len;
3664         unsigned int plaintext_len;
3665
3666         uint8_t buffer[10000];
3667         const uint8_t *ciphertext;
3668
3669         struct rte_cryptodev_info dev_info;
3670
3671         /* Verify the capabilities */
3672         struct rte_cryptodev_sym_capability_idx cap_idx;
3673         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3674         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3675         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3676                         &cap_idx) == NULL)
3677                 return TEST_SKIPPED;
3678
3679         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3680
3681         uint64_t feat_flags = dev_info.feature_flags;
3682
3683         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3684                 printf("Device doesn't support in-place scatter-gather. "
3685                                 "Test Skipped.\n");
3686                 return TEST_SKIPPED;
3687         }
3688
3689         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3690                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3691                 printf("Device doesn't support RAW data-path APIs.\n");
3692                 return TEST_SKIPPED;
3693         }
3694
3695         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3696                 return TEST_SKIPPED;
3697
3698         /* Create KASUMI session */
3699         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3700                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3701                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3702                                         tdata->key.data, tdata->key.len,
3703                                         tdata->cipher_iv.len);
3704         if (retval < 0)
3705                 return retval;
3706
3707         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3708
3709
3710         /* Append data which is padded to a multiple */
3711         /* of the algorithms block size */
3712         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3713
3714         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3715                         plaintext_pad_len, 10, 0);
3716
3717         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3718
3719         /* Create KASUMI operation */
3720         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3721                                 tdata->cipher_iv.len,
3722                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3723                                 tdata->validCipherOffsetInBits.len);
3724         if (retval < 0)
3725                 return retval;
3726
3727         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3728                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3729                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3730         else
3731                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3732                                                 ut_params->op);
3733         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3734
3735         ut_params->obuf = ut_params->op->sym->m_dst;
3736
3737         if (ut_params->obuf)
3738                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3739                                 plaintext_len, buffer);
3740         else
3741                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3742                                 tdata->validCipherOffsetInBits.len >> 3,
3743                                 plaintext_len, buffer);
3744
3745         /* Validate obuf */
3746         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3747
3748         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3749                                 (tdata->validCipherOffsetInBits.len >> 3);
3750         /* Validate obuf */
3751         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3752                 ciphertext,
3753                 reference_ciphertext,
3754                 tdata->validCipherLenInBits.len,
3755                 "KASUMI Ciphertext data not as expected");
3756         return 0;
3757 }
3758
3759 static int
3760 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3761 {
3762         struct crypto_testsuite_params *ts_params = &testsuite_params;
3763         struct crypto_unittest_params *ut_params = &unittest_params;
3764
3765         int retval;
3766         uint8_t *plaintext, *ciphertext;
3767         unsigned plaintext_pad_len;
3768         unsigned plaintext_len;
3769
3770         /* Verify the capabilities */
3771         struct rte_cryptodev_sym_capability_idx cap_idx;
3772         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3773         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3774         /* Data-path service does not support OOP */
3775         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3776                         &cap_idx) == NULL)
3777                 return TEST_SKIPPED;
3778
3779         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3780                 return TEST_SKIPPED;
3781
3782         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3783                 return TEST_SKIPPED;
3784
3785         /* Create KASUMI session */
3786         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3787                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3788                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3789                                         tdata->key.data, tdata->key.len,
3790                                         tdata->cipher_iv.len);
3791         if (retval < 0)
3792                 return retval;
3793
3794         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3795         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3796
3797         /* Clear mbuf payload */
3798         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3799                rte_pktmbuf_tailroom(ut_params->ibuf));
3800
3801         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3802         /* Append data which is padded to a multiple */
3803         /* of the algorithms block size */
3804         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3805         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3806                                 plaintext_pad_len);
3807         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3808         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3809
3810         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3811
3812         /* Create KASUMI operation */
3813         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3814                                 tdata->cipher_iv.len,
3815                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3816                                 tdata->validCipherOffsetInBits.len);
3817         if (retval < 0)
3818                 return retval;
3819
3820         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3821                                                 ut_params->op);
3822         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3823
3824         ut_params->obuf = ut_params->op->sym->m_dst;
3825         if (ut_params->obuf)
3826                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3827         else
3828                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3829
3830         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3831
3832         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3833                                 (tdata->validCipherOffsetInBits.len >> 3);
3834         /* Validate obuf */
3835         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3836                 ciphertext,
3837                 reference_ciphertext,
3838                 tdata->validCipherLenInBits.len,
3839                 "KASUMI Ciphertext data not as expected");
3840         return 0;
3841 }
3842
3843 static int
3844 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3845 {
3846         struct crypto_testsuite_params *ts_params = &testsuite_params;
3847         struct crypto_unittest_params *ut_params = &unittest_params;
3848
3849         int retval;
3850         unsigned int plaintext_pad_len;
3851         unsigned int plaintext_len;
3852
3853         const uint8_t *ciphertext;
3854         uint8_t buffer[2048];
3855
3856         struct rte_cryptodev_info dev_info;
3857
3858         /* Verify the capabilities */
3859         struct rte_cryptodev_sym_capability_idx cap_idx;
3860         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3861         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3862         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3863                         &cap_idx) == NULL)
3864                 return TEST_SKIPPED;
3865
3866         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3867                 return TEST_SKIPPED;
3868
3869         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3870                 return TEST_SKIPPED;
3871
3872         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3873
3874         uint64_t feat_flags = dev_info.feature_flags;
3875         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3876                 printf("Device doesn't support out-of-place scatter-gather "
3877                                 "in both input and output mbufs. "
3878                                 "Test Skipped.\n");
3879                 return TEST_SKIPPED;
3880         }
3881
3882         /* Create KASUMI session */
3883         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3884                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3885                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3886                                         tdata->key.data, tdata->key.len,
3887                                         tdata->cipher_iv.len);
3888         if (retval < 0)
3889                 return retval;
3890
3891         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3892         /* Append data which is padded to a multiple */
3893         /* of the algorithms block size */
3894         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3895
3896         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3897                         plaintext_pad_len, 10, 0);
3898         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3899                         plaintext_pad_len, 3, 0);
3900
3901         /* Append data which is padded to a multiple */
3902         /* of the algorithms block size */
3903         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3904
3905         /* Create KASUMI operation */
3906         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3907                                 tdata->cipher_iv.len,
3908                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3909                                 tdata->validCipherOffsetInBits.len);
3910         if (retval < 0)
3911                 return retval;
3912
3913         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3914                                                 ut_params->op);
3915         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3916
3917         ut_params->obuf = ut_params->op->sym->m_dst;
3918         if (ut_params->obuf)
3919                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3920                                 plaintext_pad_len, buffer);
3921         else
3922                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3923                                 tdata->validCipherOffsetInBits.len >> 3,
3924                                 plaintext_pad_len, buffer);
3925
3926         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3927                                 (tdata->validCipherOffsetInBits.len >> 3);
3928         /* Validate obuf */
3929         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3930                 ciphertext,
3931                 reference_ciphertext,
3932                 tdata->validCipherLenInBits.len,
3933                 "KASUMI Ciphertext data not as expected");
3934         return 0;
3935 }
3936
3937
3938 static int
3939 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3940 {
3941         struct crypto_testsuite_params *ts_params = &testsuite_params;
3942         struct crypto_unittest_params *ut_params = &unittest_params;
3943
3944         int retval;
3945         uint8_t *ciphertext, *plaintext;
3946         unsigned ciphertext_pad_len;
3947         unsigned ciphertext_len;
3948
3949         /* Verify the capabilities */
3950         struct rte_cryptodev_sym_capability_idx cap_idx;
3951         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3952         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3953         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3954                         &cap_idx) == NULL)
3955                 return TEST_SKIPPED;
3956
3957         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3958                 return TEST_SKIPPED;
3959
3960         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3961                 return TEST_SKIPPED;
3962
3963         /* Create KASUMI session */
3964         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3965                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3966                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3967                                         tdata->key.data, tdata->key.len,
3968                                         tdata->cipher_iv.len);
3969         if (retval < 0)
3970                 return retval;
3971
3972         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3973         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3974
3975         /* Clear mbuf payload */
3976         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3977                rte_pktmbuf_tailroom(ut_params->ibuf));
3978
3979         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3980         /* Append data which is padded to a multiple */
3981         /* of the algorithms block size */
3982         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3983         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3984                                 ciphertext_pad_len);
3985         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3986         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3987
3988         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3989
3990         /* Create KASUMI operation */
3991         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3992                                 tdata->cipher_iv.len,
3993                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3994                                 tdata->validCipherOffsetInBits.len);
3995         if (retval < 0)
3996                 return retval;
3997
3998         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3999                                                 ut_params->op);
4000         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4001
4002         ut_params->obuf = ut_params->op->sym->m_dst;
4003         if (ut_params->obuf)
4004                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4005         else
4006                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4007
4008         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4009
4010         const uint8_t *reference_plaintext = tdata->plaintext.data +
4011                                 (tdata->validCipherOffsetInBits.len >> 3);
4012         /* Validate obuf */
4013         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4014                 plaintext,
4015                 reference_plaintext,
4016                 tdata->validCipherLenInBits.len,
4017                 "KASUMI Plaintext data not as expected");
4018         return 0;
4019 }
4020
4021 static int
4022 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4023 {
4024         struct crypto_testsuite_params *ts_params = &testsuite_params;
4025         struct crypto_unittest_params *ut_params = &unittest_params;
4026
4027         int retval;
4028         uint8_t *ciphertext, *plaintext;
4029         unsigned ciphertext_pad_len;
4030         unsigned ciphertext_len;
4031         struct rte_cryptodev_info dev_info;
4032
4033         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4034         uint64_t feat_flags = dev_info.feature_flags;
4035
4036         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4037                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4038                 printf("Device doesn't support RAW data-path APIs.\n");
4039                 return TEST_SKIPPED;
4040         }
4041
4042         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4043                 return TEST_SKIPPED;
4044
4045         /* Verify the capabilities */
4046         struct rte_cryptodev_sym_capability_idx cap_idx;
4047         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4048         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4049         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4050                         &cap_idx) == NULL)
4051                 return TEST_SKIPPED;
4052
4053         /* Create KASUMI session */
4054         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4055                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4056                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4057                                         tdata->key.data, tdata->key.len,
4058                                         tdata->cipher_iv.len);
4059         if (retval < 0)
4060                 return retval;
4061
4062         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4063
4064         /* Clear mbuf payload */
4065         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4066                rte_pktmbuf_tailroom(ut_params->ibuf));
4067
4068         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4069         /* Append data which is padded to a multiple */
4070         /* of the algorithms block size */
4071         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4072         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4073                                 ciphertext_pad_len);
4074         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4075
4076         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4077
4078         /* Create KASUMI operation */
4079         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4080                                         tdata->cipher_iv.len,
4081                                         tdata->ciphertext.len,
4082                                         tdata->validCipherOffsetInBits.len);
4083         if (retval < 0)
4084                 return retval;
4085
4086         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4087                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4088                                 ut_params->op, 1, 0, 1, 0);
4089         else
4090                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4091                                                 ut_params->op);
4092         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4093
4094         ut_params->obuf = ut_params->op->sym->m_dst;
4095         if (ut_params->obuf)
4096                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4097         else
4098                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4099
4100         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4101
4102         const uint8_t *reference_plaintext = tdata->plaintext.data +
4103                                 (tdata->validCipherOffsetInBits.len >> 3);
4104         /* Validate obuf */
4105         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4106                 plaintext,
4107                 reference_plaintext,
4108                 tdata->validCipherLenInBits.len,
4109                 "KASUMI Plaintext data not as expected");
4110         return 0;
4111 }
4112
4113 static int
4114 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4115 {
4116         struct crypto_testsuite_params *ts_params = &testsuite_params;
4117         struct crypto_unittest_params *ut_params = &unittest_params;
4118
4119         int retval;
4120         uint8_t *plaintext, *ciphertext;
4121         unsigned plaintext_pad_len;
4122         unsigned plaintext_len;
4123         struct rte_cryptodev_info dev_info;
4124
4125         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4126         uint64_t feat_flags = dev_info.feature_flags;
4127
4128         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4129                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4130                 printf("Device doesn't support RAW data-path APIs.\n");
4131                 return TEST_SKIPPED;
4132         }
4133
4134         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4135                 return TEST_SKIPPED;
4136
4137         /* Verify the capabilities */
4138         struct rte_cryptodev_sym_capability_idx cap_idx;
4139         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4140         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4141         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4142                         &cap_idx) == NULL)
4143                 return TEST_SKIPPED;
4144
4145         /* Create SNOW 3G session */
4146         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4147                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4148                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4149                                         tdata->key.data, tdata->key.len,
4150                                         tdata->cipher_iv.len);
4151         if (retval < 0)
4152                 return retval;
4153
4154         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4155
4156         /* Clear mbuf payload */
4157         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4158                rte_pktmbuf_tailroom(ut_params->ibuf));
4159
4160         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4161         /* Append data which is padded to a multiple of */
4162         /* the algorithms block size */
4163         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4164         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4165                                 plaintext_pad_len);
4166         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4167
4168         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4169
4170         /* Create SNOW 3G operation */
4171         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4172                                         tdata->cipher_iv.len,
4173                                         tdata->validCipherLenInBits.len,
4174                                         0);
4175         if (retval < 0)
4176                 return retval;
4177
4178         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4179                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4180                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4181         else
4182                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4183                                                 ut_params->op);
4184         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4185
4186         ut_params->obuf = ut_params->op->sym->m_dst;
4187         if (ut_params->obuf)
4188                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4189         else
4190                 ciphertext = plaintext;
4191
4192         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4193
4194         /* Validate obuf */
4195         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4196                 ciphertext,
4197                 tdata->ciphertext.data,
4198                 tdata->validDataLenInBits.len,
4199                 "SNOW 3G Ciphertext data not as expected");
4200         return 0;
4201 }
4202
4203
4204 static int
4205 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4206 {
4207         struct crypto_testsuite_params *ts_params = &testsuite_params;
4208         struct crypto_unittest_params *ut_params = &unittest_params;
4209         uint8_t *plaintext, *ciphertext;
4210
4211         int retval;
4212         unsigned plaintext_pad_len;
4213         unsigned plaintext_len;
4214         struct rte_cryptodev_info dev_info;
4215
4216         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4217         uint64_t feat_flags = dev_info.feature_flags;
4218
4219         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4220                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4221                 printf("Device does not support RAW data-path APIs.\n");
4222                 return -ENOTSUP;
4223         }
4224
4225         /* Verify the capabilities */
4226         struct rte_cryptodev_sym_capability_idx cap_idx;
4227         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4228         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4229         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4230                         &cap_idx) == NULL)
4231                 return TEST_SKIPPED;
4232
4233         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4234                 return TEST_SKIPPED;
4235
4236         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4237                 return TEST_SKIPPED;
4238
4239         /* Create SNOW 3G session */
4240         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4241                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4242                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4243                                         tdata->key.data, tdata->key.len,
4244                                         tdata->cipher_iv.len);
4245         if (retval < 0)
4246                 return retval;
4247
4248         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4249         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4250
4251         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4252                         "Failed to allocate input buffer in mempool");
4253         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4254                         "Failed to allocate output buffer in mempool");
4255
4256         /* Clear mbuf payload */
4257         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4258                rte_pktmbuf_tailroom(ut_params->ibuf));
4259
4260         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4261         /* Append data which is padded to a multiple of */
4262         /* the algorithms block size */
4263         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4264         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4265                                 plaintext_pad_len);
4266         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4267         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4268
4269         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4270
4271         /* Create SNOW 3G operation */
4272         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4273                                         tdata->cipher_iv.len,
4274                                         tdata->validCipherLenInBits.len,
4275                                         0);
4276         if (retval < 0)
4277                 return retval;
4278
4279         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4280                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4281                         ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4282         else
4283                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4284                                                 ut_params->op);
4285         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4286
4287         ut_params->obuf = ut_params->op->sym->m_dst;
4288         if (ut_params->obuf)
4289                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4290         else
4291                 ciphertext = plaintext;
4292
4293         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4294
4295         /* Validate obuf */
4296         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4297                 ciphertext,
4298                 tdata->ciphertext.data,
4299                 tdata->validDataLenInBits.len,
4300                 "SNOW 3G Ciphertext data not as expected");
4301         return 0;
4302 }
4303
4304 static int
4305 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4306 {
4307         struct crypto_testsuite_params *ts_params = &testsuite_params;
4308         struct crypto_unittest_params *ut_params = &unittest_params;
4309
4310         int retval;
4311         unsigned int plaintext_pad_len;
4312         unsigned int plaintext_len;
4313         uint8_t buffer[10000];
4314         const uint8_t *ciphertext;
4315
4316         struct rte_cryptodev_info dev_info;
4317
4318         /* Verify the capabilities */
4319         struct rte_cryptodev_sym_capability_idx cap_idx;
4320         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4321         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4322         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4323                         &cap_idx) == NULL)
4324                 return TEST_SKIPPED;
4325
4326         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4327                 return TEST_SKIPPED;
4328
4329         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4330                 return TEST_SKIPPED;
4331
4332         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4333
4334         uint64_t feat_flags = dev_info.feature_flags;
4335
4336         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4337                 printf("Device doesn't support out-of-place scatter-gather "
4338                                 "in both input and output mbufs. "
4339                                 "Test Skipped.\n");
4340                 return TEST_SKIPPED;
4341         }
4342
4343         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4344                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4345                 printf("Device does not support RAW data-path APIs.\n");
4346                 return -ENOTSUP;
4347         }
4348
4349         /* Create SNOW 3G session */
4350         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4351                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4352                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4353                                         tdata->key.data, tdata->key.len,
4354                                         tdata->cipher_iv.len);
4355         if (retval < 0)
4356                 return retval;
4357
4358         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4359         /* Append data which is padded to a multiple of */
4360         /* the algorithms block size */
4361         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4362
4363         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4364                         plaintext_pad_len, 10, 0);
4365         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4366                         plaintext_pad_len, 3, 0);
4367
4368         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4369                         "Failed to allocate input buffer in mempool");
4370         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4371                         "Failed to allocate output buffer in mempool");
4372
4373         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4374
4375         /* Create SNOW 3G operation */
4376         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4377                                         tdata->cipher_iv.len,
4378                                         tdata->validCipherLenInBits.len,
4379                                         0);
4380         if (retval < 0)
4381                 return retval;
4382
4383         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4384                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4385                         ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4386         else
4387                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4388                                                 ut_params->op);
4389         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4390
4391         ut_params->obuf = ut_params->op->sym->m_dst;
4392         if (ut_params->obuf)
4393                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4394                                 plaintext_len, buffer);
4395         else
4396                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4397                                 plaintext_len, buffer);
4398
4399         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4400
4401         /* Validate obuf */
4402         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4403                 ciphertext,
4404                 tdata->ciphertext.data,
4405                 tdata->validDataLenInBits.len,
4406                 "SNOW 3G Ciphertext data not as expected");
4407
4408         return 0;
4409 }
4410
4411 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4412 static void
4413 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4414 {
4415         uint8_t curr_byte, prev_byte;
4416         uint32_t length_in_bytes = ceil_byte_length(length + offset);
4417         uint8_t lower_byte_mask = (1 << offset) - 1;
4418         unsigned i;
4419
4420         prev_byte = buffer[0];
4421         buffer[0] >>= offset;
4422
4423         for (i = 1; i < length_in_bytes; i++) {
4424                 curr_byte = buffer[i];
4425                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4426                                 (curr_byte >> offset);
4427                 prev_byte = curr_byte;
4428         }
4429 }
4430
4431 static int
4432 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4433 {
4434         struct crypto_testsuite_params *ts_params = &testsuite_params;
4435         struct crypto_unittest_params *ut_params = &unittest_params;
4436         uint8_t *plaintext, *ciphertext;
4437         int retval;
4438         uint32_t plaintext_len;
4439         uint32_t plaintext_pad_len;
4440         uint8_t extra_offset = 4;
4441         uint8_t *expected_ciphertext_shifted;
4442         struct rte_cryptodev_info dev_info;
4443
4444         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4445         uint64_t feat_flags = dev_info.feature_flags;
4446
4447         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4448                         ((tdata->validDataLenInBits.len % 8) != 0)) {
4449                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4450                 return TEST_SKIPPED;
4451         }
4452
4453         /* Verify the capabilities */
4454         struct rte_cryptodev_sym_capability_idx cap_idx;
4455         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4456         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4457         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4458                         &cap_idx) == NULL)
4459                 return TEST_SKIPPED;
4460
4461         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4462                 return TEST_SKIPPED;
4463
4464         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4465                 return TEST_SKIPPED;
4466
4467         /* Create SNOW 3G session */
4468         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4469                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4470                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4471                                         tdata->key.data, tdata->key.len,
4472                                         tdata->cipher_iv.len);
4473         if (retval < 0)
4474                 return retval;
4475
4476         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4477         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4478
4479         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4480                         "Failed to allocate input buffer in mempool");
4481         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4482                         "Failed to allocate output buffer in mempool");
4483
4484         /* Clear mbuf payload */
4485         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4486                rte_pktmbuf_tailroom(ut_params->ibuf));
4487
4488         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4489         /*
4490          * Append data which is padded to a
4491          * multiple of the algorithms block size
4492          */
4493         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4494
4495         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4496                                                 plaintext_pad_len);
4497
4498         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4499
4500         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4501         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4502
4503 #ifdef RTE_APP_TEST_DEBUG
4504         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4505 #endif
4506         /* Create SNOW 3G operation */
4507         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4508                                         tdata->cipher_iv.len,
4509                                         tdata->validCipherLenInBits.len,
4510                                         extra_offset);
4511         if (retval < 0)
4512                 return retval;
4513
4514         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4515                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4516                         ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4517         else
4518                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4519                                                 ut_params->op);
4520         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4521
4522         ut_params->obuf = ut_params->op->sym->m_dst;
4523         if (ut_params->obuf)
4524                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4525         else
4526                 ciphertext = plaintext;
4527
4528 #ifdef RTE_APP_TEST_DEBUG
4529         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4530 #endif
4531
4532         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4533
4534         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4535                         "failed to reserve memory for ciphertext shifted\n");
4536
4537         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4538                         ceil_byte_length(tdata->ciphertext.len));
4539         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4540                         extra_offset);
4541         /* Validate obuf */
4542         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4543                 ciphertext,
4544                 expected_ciphertext_shifted,
4545                 tdata->validDataLenInBits.len,
4546                 extra_offset,
4547                 "SNOW 3G Ciphertext data not as expected");
4548         return 0;
4549 }
4550
4551 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4552 {
4553         struct crypto_testsuite_params *ts_params = &testsuite_params;
4554         struct crypto_unittest_params *ut_params = &unittest_params;
4555
4556         int retval;
4557
4558         uint8_t *plaintext, *ciphertext;
4559         unsigned ciphertext_pad_len;
4560         unsigned ciphertext_len;
4561         struct rte_cryptodev_info dev_info;
4562
4563         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4564         uint64_t feat_flags = dev_info.feature_flags;
4565
4566         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4567                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4568                 printf("Device doesn't support RAW data-path APIs.\n");
4569                 return TEST_SKIPPED;
4570         }
4571
4572         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4573                 return TEST_SKIPPED;
4574
4575         /* Verify the capabilities */
4576         struct rte_cryptodev_sym_capability_idx cap_idx;
4577         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4578         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4579         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4580                         &cap_idx) == NULL)
4581                 return TEST_SKIPPED;
4582
4583         /* Create SNOW 3G session */
4584         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4585                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4586                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4587                                         tdata->key.data, tdata->key.len,
4588                                         tdata->cipher_iv.len);
4589         if (retval < 0)
4590                 return retval;
4591
4592         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4593
4594         /* Clear mbuf payload */
4595         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4596                rte_pktmbuf_tailroom(ut_params->ibuf));
4597
4598         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4599         /* Append data which is padded to a multiple of */
4600         /* the algorithms block size */
4601         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4602         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4603                                 ciphertext_pad_len);
4604         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4605
4606         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4607
4608         /* Create SNOW 3G operation */
4609         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4610                                         tdata->cipher_iv.len,
4611                                         tdata->validCipherLenInBits.len,
4612                                         tdata->cipher.offset_bits);
4613         if (retval < 0)
4614                 return retval;
4615
4616         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4617                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4618                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4619         else
4620                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4621                                                 ut_params->op);
4622         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4623         ut_params->obuf = ut_params->op->sym->m_dst;
4624         if (ut_params->obuf)
4625                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4626         else
4627                 plaintext = ciphertext;
4628
4629         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4630
4631         /* Validate obuf */
4632         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4633                                 tdata->plaintext.data,
4634                                 tdata->validDataLenInBits.len,
4635                                 "SNOW 3G Plaintext data not as expected");
4636         return 0;
4637 }
4638
4639 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4640 {
4641         struct crypto_testsuite_params *ts_params = &testsuite_params;
4642         struct crypto_unittest_params *ut_params = &unittest_params;
4643
4644         int retval;
4645
4646         uint8_t *plaintext, *ciphertext;
4647         unsigned ciphertext_pad_len;
4648         unsigned ciphertext_len;
4649         struct rte_cryptodev_info dev_info;
4650
4651         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4652         uint64_t feat_flags = dev_info.feature_flags;
4653
4654         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4655                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4656                 printf("Device does not support RAW data-path APIs.\n");
4657                 return -ENOTSUP;
4658         }
4659         /* Verify the capabilities */
4660         struct rte_cryptodev_sym_capability_idx cap_idx;
4661         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4662         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4663         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4664                         &cap_idx) == NULL)
4665                 return TEST_SKIPPED;
4666
4667         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4668                 return TEST_SKIPPED;
4669
4670         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4671                 return TEST_SKIPPED;
4672
4673         /* Create SNOW 3G session */
4674         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4675                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4676                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4677                                         tdata->key.data, tdata->key.len,
4678                                         tdata->cipher_iv.len);
4679         if (retval < 0)
4680                 return retval;
4681
4682         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4683         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4684
4685         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4686                         "Failed to allocate input buffer");
4687         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4688                         "Failed to allocate output buffer");
4689
4690         /* Clear mbuf payload */
4691         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4692                rte_pktmbuf_tailroom(ut_params->ibuf));
4693
4694         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4695                        rte_pktmbuf_tailroom(ut_params->obuf));
4696
4697         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4698         /* Append data which is padded to a multiple of */
4699         /* the algorithms block size */
4700         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4701         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4702                                 ciphertext_pad_len);
4703         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4704         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4705
4706         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4707
4708         /* Create SNOW 3G operation */
4709         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4710                                         tdata->cipher_iv.len,
4711                                         tdata->validCipherLenInBits.len,
4712                                         0);
4713         if (retval < 0)
4714                 return retval;
4715
4716         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4717                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4718                         ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4719         else
4720                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4721                                                 ut_params->op);
4722         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4723         ut_params->obuf = ut_params->op->sym->m_dst;
4724         if (ut_params->obuf)
4725                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4726         else
4727                 plaintext = ciphertext;
4728
4729         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4730
4731         /* Validate obuf */
4732         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4733                                 tdata->plaintext.data,
4734                                 tdata->validDataLenInBits.len,
4735                                 "SNOW 3G Plaintext data not as expected");
4736         return 0;
4737 }
4738
4739 static int
4740 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4741 {
4742         struct crypto_testsuite_params *ts_params = &testsuite_params;
4743         struct crypto_unittest_params *ut_params = &unittest_params;
4744
4745         int retval;
4746
4747         uint8_t *plaintext, *ciphertext;
4748         unsigned int plaintext_pad_len;
4749         unsigned int plaintext_len;
4750
4751         struct rte_cryptodev_info dev_info;
4752         struct rte_cryptodev_sym_capability_idx cap_idx;
4753
4754         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4755         uint64_t feat_flags = dev_info.feature_flags;
4756
4757         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4758                         ((tdata->validAuthLenInBits.len % 8 != 0) ||
4759                         (tdata->validDataLenInBits.len % 8 != 0))) {
4760                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4761                 return TEST_SKIPPED;
4762         }
4763
4764         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4765                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4766                 printf("Device doesn't support RAW data-path APIs.\n");
4767                 return TEST_SKIPPED;
4768         }
4769
4770         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4771                 return TEST_SKIPPED;
4772
4773         /* Check if device supports ZUC EEA3 */
4774         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4775         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4776
4777         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4778                         &cap_idx) == NULL)
4779                 return TEST_SKIPPED;
4780
4781         /* Check if device supports ZUC EIA3 */
4782         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4783         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4784
4785         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4786                         &cap_idx) == NULL)
4787                 return TEST_SKIPPED;
4788
4789         /* Create ZUC session */
4790         retval = create_zuc_cipher_auth_encrypt_generate_session(
4791                         ts_params->valid_devs[0],
4792                         tdata);
4793         if (retval != 0)
4794                 return retval;
4795         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4796
4797         /* clear mbuf payload */
4798         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4799                         rte_pktmbuf_tailroom(ut_params->ibuf));
4800
4801         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4802         /* Append data which is padded to a multiple of */
4803         /* the algorithms block size */
4804         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4805         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4806                                 plaintext_pad_len);
4807         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4808
4809         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4810
4811         /* Create ZUC operation */
4812         retval = create_zuc_cipher_hash_generate_operation(tdata);
4813         if (retval < 0)
4814                 return retval;
4815
4816         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4817                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4818                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4819         else
4820                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4821                         ut_params->op);
4822         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4823         ut_params->obuf = ut_params->op->sym->m_src;
4824         if (ut_params->obuf)
4825                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4826         else
4827                 ciphertext = plaintext;
4828
4829         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4830         /* Validate obuf */
4831         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4832                         ciphertext,
4833                         tdata->ciphertext.data,
4834                         tdata->validDataLenInBits.len,
4835                         "ZUC Ciphertext data not as expected");
4836
4837         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4838             + plaintext_pad_len;
4839
4840         /* Validate obuf */
4841         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4842                         ut_params->digest,
4843                         tdata->digest.data,
4844                         4,
4845                         "ZUC Generated auth tag not as expected");
4846         return 0;
4847 }
4848
4849 static int
4850 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4851 {
4852         struct crypto_testsuite_params *ts_params = &testsuite_params;
4853         struct crypto_unittest_params *ut_params = &unittest_params;
4854
4855         int retval;
4856
4857         uint8_t *plaintext, *ciphertext;
4858         unsigned plaintext_pad_len;
4859         unsigned plaintext_len;
4860         struct rte_cryptodev_info dev_info;
4861
4862         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4863         uint64_t feat_flags = dev_info.feature_flags;
4864
4865         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4866                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4867                 printf("Device doesn't support RAW data-path APIs.\n");
4868                 return TEST_SKIPPED;
4869         }
4870
4871         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4872                 return TEST_SKIPPED;
4873
4874         /* Verify the capabilities */
4875         struct rte_cryptodev_sym_capability_idx cap_idx;
4876         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4877         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4878         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4879                         &cap_idx) == NULL)
4880                 return TEST_SKIPPED;
4881         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4882         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4883         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4884                         &cap_idx) == NULL)
4885                 return TEST_SKIPPED;
4886
4887         /* Create SNOW 3G session */
4888         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4889                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4890                         RTE_CRYPTO_AUTH_OP_GENERATE,
4891                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4892                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4893                         tdata->key.data, tdata->key.len,
4894                         tdata->auth_iv.len, tdata->digest.len,
4895                         tdata->cipher_iv.len);
4896         if (retval != 0)
4897                 return retval;
4898         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4899
4900         /* clear mbuf payload */
4901         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4902                         rte_pktmbuf_tailroom(ut_params->ibuf));
4903
4904         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4905         /* Append data which is padded to a multiple of */
4906         /* the algorithms block size */
4907         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4908         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4909                                 plaintext_pad_len);
4910         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4911
4912         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4913
4914         /* Create SNOW 3G operation */
4915         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4916                         tdata->digest.len, tdata->auth_iv.data,
4917                         tdata->auth_iv.len,
4918                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4919                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4920                         tdata->validCipherLenInBits.len,
4921                         0,
4922                         tdata->validAuthLenInBits.len,
4923                         0
4924                         );
4925         if (retval < 0)
4926                 return retval;
4927
4928         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4929                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4930                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4931         else
4932                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4933                         ut_params->op);
4934         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4935         ut_params->obuf = ut_params->op->sym->m_src;
4936         if (ut_params->obuf)
4937                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4938         else
4939                 ciphertext = plaintext;
4940
4941         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4942         /* Validate obuf */
4943         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4944                         ciphertext,
4945                         tdata->ciphertext.data,
4946                         tdata->validDataLenInBits.len,
4947                         "SNOW 3G Ciphertext data not as expected");
4948
4949         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4950             + plaintext_pad_len;
4951
4952         /* Validate obuf */
4953         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4954                         ut_params->digest,
4955                         tdata->digest.data,
4956                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4957                         "SNOW 3G Generated auth tag not as expected");
4958         return 0;
4959 }
4960
4961 static int
4962 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4963         uint8_t op_mode, uint8_t verify)
4964 {
4965         struct crypto_testsuite_params *ts_params = &testsuite_params;
4966         struct crypto_unittest_params *ut_params = &unittest_params;
4967
4968         int retval;
4969
4970         uint8_t *plaintext = NULL, *ciphertext = NULL;
4971         unsigned int plaintext_pad_len;
4972         unsigned int plaintext_len;
4973         unsigned int ciphertext_pad_len;
4974         unsigned int ciphertext_len;
4975
4976         struct rte_cryptodev_info dev_info;
4977
4978         /* Verify the capabilities */
4979         struct rte_cryptodev_sym_capability_idx cap_idx;
4980         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4981         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4982         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4983                         &cap_idx) == NULL)
4984                 return TEST_SKIPPED;
4985         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4986         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4987         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4988                         &cap_idx) == NULL)
4989                 return TEST_SKIPPED;
4990
4991         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4992                 return TEST_SKIPPED;
4993
4994         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4995
4996         uint64_t feat_flags = dev_info.feature_flags;
4997
4998         if (op_mode == OUT_OF_PLACE) {
4999                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5000                         printf("Device doesn't support digest encrypted.\n");
5001                         return TEST_SKIPPED;
5002                 }
5003                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5004                         return TEST_SKIPPED;
5005         }
5006
5007         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5008                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5009                 printf("Device doesn't support RAW data-path APIs.\n");
5010                 return TEST_SKIPPED;
5011         }
5012
5013         /* Create SNOW 3G session */
5014         retval = create_wireless_algo_auth_cipher_session(
5015                         ts_params->valid_devs[0],
5016                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5017                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5018                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5019                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5020                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5021                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5022                         tdata->key.data, tdata->key.len,
5023                         tdata->auth_iv.len, tdata->digest.len,
5024                         tdata->cipher_iv.len);
5025         if (retval != 0)
5026                 return retval;
5027
5028         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5029         if (op_mode == OUT_OF_PLACE)
5030                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5031
5032         /* clear mbuf payload */
5033         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5034                 rte_pktmbuf_tailroom(ut_params->ibuf));
5035         if (op_mode == OUT_OF_PLACE)
5036                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5037                         rte_pktmbuf_tailroom(ut_params->obuf));
5038
5039         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5040         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5041         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5042         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5043
5044         if (verify) {
5045                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5046                                         ciphertext_pad_len);
5047                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5048                 if (op_mode == OUT_OF_PLACE)
5049                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5050                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5051                         ciphertext_len);
5052         } else {
5053                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5054                                         plaintext_pad_len);
5055                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5056                 if (op_mode == OUT_OF_PLACE)
5057                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5058                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5059         }
5060
5061         /* Create SNOW 3G operation */
5062         retval = create_wireless_algo_auth_cipher_operation(
5063                 tdata->digest.data, tdata->digest.len,
5064                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5065                 tdata->auth_iv.data, tdata->auth_iv.len,
5066                 (tdata->digest.offset_bytes == 0 ?
5067                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5068                         : tdata->digest.offset_bytes),
5069                 tdata->validCipherLenInBits.len,
5070                 tdata->cipher.offset_bits,
5071                 tdata->validAuthLenInBits.len,
5072                 tdata->auth.offset_bits,
5073                 op_mode, 0, verify);
5074
5075         if (retval < 0)
5076                 return retval;
5077
5078         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5079                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5080                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5081         else
5082                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5083                         ut_params->op);
5084
5085         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5086
5087         ut_params->obuf = (op_mode == IN_PLACE ?
5088                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5089
5090         if (verify) {
5091                 if (ut_params->obuf)
5092                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5093                                                         uint8_t *);
5094                 else
5095                         plaintext = ciphertext +
5096                                 (tdata->cipher.offset_bits >> 3);
5097
5098                 debug_hexdump(stdout, "plaintext:", plaintext,
5099                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5100                 debug_hexdump(stdout, "plaintext expected:",
5101                         tdata->plaintext.data,
5102                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5103         } else {
5104                 if (ut_params->obuf)
5105                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5106                                                         uint8_t *);
5107                 else
5108                         ciphertext = plaintext;
5109
5110                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5111                         ciphertext_len);
5112                 debug_hexdump(stdout, "ciphertext expected:",
5113                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5114
5115                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5116                         + (tdata->digest.offset_bytes == 0 ?
5117                 plaintext_pad_len : tdata->digest.offset_bytes);
5118
5119                 debug_hexdump(stdout, "digest:", ut_params->digest,
5120                         tdata->digest.len);
5121                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5122                                 tdata->digest.len);
5123         }
5124
5125         /* Validate obuf */
5126         if (verify) {
5127                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5128                         plaintext,
5129                         tdata->plaintext.data,
5130                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5131                          (tdata->digest.len << 3)),
5132                         tdata->cipher.offset_bits,
5133                         "SNOW 3G Plaintext data not as expected");
5134         } else {
5135                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5136                         ciphertext,
5137                         tdata->ciphertext.data,
5138                         (tdata->validDataLenInBits.len -
5139                          tdata->cipher.offset_bits),
5140                         tdata->cipher.offset_bits,
5141                         "SNOW 3G Ciphertext data not as expected");
5142
5143                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5144                         ut_params->digest,
5145                         tdata->digest.data,
5146                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5147                         "SNOW 3G Generated auth tag not as expected");
5148         }
5149         return 0;
5150 }
5151
5152 static int
5153 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5154         uint8_t op_mode, uint8_t verify)
5155 {
5156         struct crypto_testsuite_params *ts_params = &testsuite_params;
5157         struct crypto_unittest_params *ut_params = &unittest_params;
5158
5159         int retval;
5160
5161         const uint8_t *plaintext = NULL;
5162         const uint8_t *ciphertext = NULL;
5163         const uint8_t *digest = NULL;
5164         unsigned int plaintext_pad_len;
5165         unsigned int plaintext_len;
5166         unsigned int ciphertext_pad_len;
5167         unsigned int ciphertext_len;
5168         uint8_t buffer[10000];
5169         uint8_t digest_buffer[10000];
5170
5171         struct rte_cryptodev_info dev_info;
5172
5173         /* Verify the capabilities */
5174         struct rte_cryptodev_sym_capability_idx cap_idx;
5175         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5176         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5177         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5178                         &cap_idx) == NULL)
5179                 return TEST_SKIPPED;
5180         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5181         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5182         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5183                         &cap_idx) == NULL)
5184                 return TEST_SKIPPED;
5185
5186         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5187                 return TEST_SKIPPED;
5188
5189         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5190
5191         uint64_t feat_flags = dev_info.feature_flags;
5192
5193         if (op_mode == IN_PLACE) {
5194                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5195                         printf("Device doesn't support in-place scatter-gather "
5196                                         "in both input and output mbufs.\n");
5197                         return TEST_SKIPPED;
5198                 }
5199                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5200                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5201                         printf("Device doesn't support RAW data-path APIs.\n");
5202                         return TEST_SKIPPED;
5203                 }
5204         } else {
5205                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5206                         return TEST_SKIPPED;
5207                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5208                         printf("Device doesn't support out-of-place scatter-gather "
5209                                         "in both input and output mbufs.\n");
5210                         return TEST_SKIPPED;
5211                 }
5212                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5213                         printf("Device doesn't support digest encrypted.\n");
5214                         return TEST_SKIPPED;
5215                 }
5216         }
5217
5218         /* Create SNOW 3G session */
5219         retval = create_wireless_algo_auth_cipher_session(
5220                         ts_params->valid_devs[0],
5221                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5222                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5223                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5224                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5225                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5226                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5227                         tdata->key.data, tdata->key.len,
5228                         tdata->auth_iv.len, tdata->digest.len,
5229                         tdata->cipher_iv.len);
5230
5231         if (retval != 0)
5232                 return retval;
5233
5234         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5235         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5236         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5237         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5238
5239         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5240                         plaintext_pad_len, 15, 0);
5241         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5242                         "Failed to allocate input buffer in mempool");
5243
5244         if (op_mode == OUT_OF_PLACE) {
5245                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5246                                 plaintext_pad_len, 15, 0);
5247                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5248                                 "Failed to allocate output buffer in mempool");
5249         }
5250
5251         if (verify) {
5252                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5253                         tdata->ciphertext.data);
5254                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5255                                         ciphertext_len, buffer);
5256                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5257                         ciphertext_len);
5258         } else {
5259                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5260                         tdata->plaintext.data);
5261                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5262                                         plaintext_len, buffer);
5263                 debug_hexdump(stdout, "plaintext:", plaintext,
5264                         plaintext_len);
5265         }
5266         memset(buffer, 0, sizeof(buffer));
5267
5268         /* Create SNOW 3G operation */
5269         retval = create_wireless_algo_auth_cipher_operation(
5270                 tdata->digest.data, tdata->digest.len,
5271                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5272                 tdata->auth_iv.data, tdata->auth_iv.len,
5273                 (tdata->digest.offset_bytes == 0 ?
5274                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5275                         : tdata->digest.offset_bytes),
5276                 tdata->validCipherLenInBits.len,
5277                 tdata->cipher.offset_bits,
5278                 tdata->validAuthLenInBits.len,
5279                 tdata->auth.offset_bits,
5280                 op_mode, 1, verify);
5281
5282         if (retval < 0)
5283                 return retval;
5284
5285         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5286                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5287                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5288         else
5289                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5290                         ut_params->op);
5291
5292         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5293
5294         ut_params->obuf = (op_mode == IN_PLACE ?
5295                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5296
5297         if (verify) {
5298                 if (ut_params->obuf)
5299                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5300                                         plaintext_len, buffer);
5301                 else
5302                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5303                                         plaintext_len, buffer);
5304
5305                 debug_hexdump(stdout, "plaintext:", plaintext,
5306                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5307                 debug_hexdump(stdout, "plaintext expected:",
5308                         tdata->plaintext.data,
5309                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5310         } else {
5311                 if (ut_params->obuf)
5312                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5313                                         ciphertext_len, buffer);
5314                 else
5315                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5316                                         ciphertext_len, buffer);
5317
5318                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5319                         ciphertext_len);
5320                 debug_hexdump(stdout, "ciphertext expected:",
5321                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5322
5323                 if (ut_params->obuf)
5324                         digest = rte_pktmbuf_read(ut_params->obuf,
5325                                 (tdata->digest.offset_bytes == 0 ?
5326                                 plaintext_pad_len : tdata->digest.offset_bytes),
5327                                 tdata->digest.len, digest_buffer);
5328                 else
5329                         digest = rte_pktmbuf_read(ut_params->ibuf,
5330                                 (tdata->digest.offset_bytes == 0 ?
5331                                 plaintext_pad_len : tdata->digest.offset_bytes),
5332                                 tdata->digest.len, digest_buffer);
5333
5334                 debug_hexdump(stdout, "digest:", digest,
5335                         tdata->digest.len);
5336                 debug_hexdump(stdout, "digest expected:",
5337                         tdata->digest.data, tdata->digest.len);
5338         }
5339
5340         /* Validate obuf */
5341         if (verify) {
5342                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5343                         plaintext,
5344                         tdata->plaintext.data,
5345                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5346                          (tdata->digest.len << 3)),
5347                         tdata->cipher.offset_bits,
5348                         "SNOW 3G Plaintext data not as expected");
5349         } else {
5350                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5351                         ciphertext,
5352                         tdata->ciphertext.data,
5353                         (tdata->validDataLenInBits.len -
5354                          tdata->cipher.offset_bits),
5355                         tdata->cipher.offset_bits,
5356                         "SNOW 3G Ciphertext data not as expected");
5357
5358                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5359                         digest,
5360                         tdata->digest.data,
5361                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5362                         "SNOW 3G Generated auth tag not as expected");
5363         }
5364         return 0;
5365 }
5366
5367 static int
5368 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5369         uint8_t op_mode, uint8_t verify)
5370 {
5371         struct crypto_testsuite_params *ts_params = &testsuite_params;
5372         struct crypto_unittest_params *ut_params = &unittest_params;
5373
5374         int retval;
5375
5376         uint8_t *plaintext = NULL, *ciphertext = NULL;
5377         unsigned int plaintext_pad_len;
5378         unsigned int plaintext_len;
5379         unsigned int ciphertext_pad_len;
5380         unsigned int ciphertext_len;
5381
5382         struct rte_cryptodev_info dev_info;
5383
5384         /* Verify the capabilities */
5385         struct rte_cryptodev_sym_capability_idx cap_idx;
5386         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5387         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5388         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5389                         &cap_idx) == NULL)
5390                 return TEST_SKIPPED;
5391         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5392         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5393         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5394                         &cap_idx) == NULL)
5395                 return TEST_SKIPPED;
5396
5397         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5398
5399         uint64_t feat_flags = dev_info.feature_flags;
5400
5401         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5402                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5403                 printf("Device doesn't support RAW data-path APIs.\n");
5404                 return TEST_SKIPPED;
5405         }
5406
5407         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5408                 return TEST_SKIPPED;
5409
5410         if (op_mode == OUT_OF_PLACE) {
5411                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5412                         return TEST_SKIPPED;
5413                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5414                         printf("Device doesn't support digest encrypted.\n");
5415                         return TEST_SKIPPED;
5416                 }
5417         }
5418
5419         /* Create KASUMI session */
5420         retval = create_wireless_algo_auth_cipher_session(
5421                         ts_params->valid_devs[0],
5422                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5423                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5424                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5425                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5426                         RTE_CRYPTO_AUTH_KASUMI_F9,
5427                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5428                         tdata->key.data, tdata->key.len,
5429                         0, tdata->digest.len,
5430                         tdata->cipher_iv.len);
5431
5432         if (retval != 0)
5433                 return retval;
5434
5435         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5436         if (op_mode == OUT_OF_PLACE)
5437                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5438
5439         /* clear mbuf payload */
5440         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5441                 rte_pktmbuf_tailroom(ut_params->ibuf));
5442         if (op_mode == OUT_OF_PLACE)
5443                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5444                         rte_pktmbuf_tailroom(ut_params->obuf));
5445
5446         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5447         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5448         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5449         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5450
5451         if (verify) {
5452                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5453                                         ciphertext_pad_len);
5454                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5455                 if (op_mode == OUT_OF_PLACE)
5456                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5457                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5458                         ciphertext_len);
5459         } else {
5460                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5461                                         plaintext_pad_len);
5462                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5463                 if (op_mode == OUT_OF_PLACE)
5464                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5465                 debug_hexdump(stdout, "plaintext:", plaintext,
5466                         plaintext_len);
5467         }
5468
5469         /* Create KASUMI operation */
5470         retval = create_wireless_algo_auth_cipher_operation(
5471                 tdata->digest.data, tdata->digest.len,
5472                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5473                 NULL, 0,
5474                 (tdata->digest.offset_bytes == 0 ?
5475                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5476                         : tdata->digest.offset_bytes),
5477                 tdata->validCipherLenInBits.len,
5478                 tdata->validCipherOffsetInBits.len,
5479                 tdata->validAuthLenInBits.len,
5480                 0,
5481                 op_mode, 0, verify);
5482
5483         if (retval < 0)
5484                 return retval;
5485
5486         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5487                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5488                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5489         else
5490                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5491                         ut_params->op);
5492
5493         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5494
5495         ut_params->obuf = (op_mode == IN_PLACE ?
5496                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5497
5498
5499         if (verify) {
5500                 if (ut_params->obuf)
5501                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5502                                                         uint8_t *);
5503                 else
5504                         plaintext = ciphertext;
5505
5506                 debug_hexdump(stdout, "plaintext:", plaintext,
5507                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5508                 debug_hexdump(stdout, "plaintext expected:",
5509                         tdata->plaintext.data,
5510                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5511         } else {
5512                 if (ut_params->obuf)
5513                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5514                                                         uint8_t *);
5515                 else
5516                         ciphertext = plaintext;
5517
5518                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5519                         ciphertext_len);
5520                 debug_hexdump(stdout, "ciphertext expected:",
5521                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5522
5523                 ut_params->digest = rte_pktmbuf_mtod(
5524                         ut_params->obuf, uint8_t *) +
5525                         (tdata->digest.offset_bytes == 0 ?
5526                         plaintext_pad_len : tdata->digest.offset_bytes);
5527
5528                 debug_hexdump(stdout, "digest:", ut_params->digest,
5529                         tdata->digest.len);
5530                 debug_hexdump(stdout, "digest expected:",
5531                         tdata->digest.data, tdata->digest.len);
5532         }
5533
5534         /* Validate obuf */
5535         if (verify) {
5536                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5537                         plaintext,
5538                         tdata->plaintext.data,
5539                         tdata->plaintext.len >> 3,
5540                         "KASUMI Plaintext data not as expected");
5541         } else {
5542                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5543                         ciphertext,
5544                         tdata->ciphertext.data,
5545                         tdata->ciphertext.len >> 3,
5546                         "KASUMI Ciphertext data not as expected");
5547
5548                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5549                         ut_params->digest,
5550                         tdata->digest.data,
5551                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5552                         "KASUMI Generated auth tag not as expected");
5553         }
5554         return 0;
5555 }
5556
5557 static int
5558 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5559         uint8_t op_mode, uint8_t verify)
5560 {
5561         struct crypto_testsuite_params *ts_params = &testsuite_params;
5562         struct crypto_unittest_params *ut_params = &unittest_params;
5563
5564         int retval;
5565
5566         const uint8_t *plaintext = NULL;
5567         const uint8_t *ciphertext = NULL;
5568         const uint8_t *digest = NULL;
5569         unsigned int plaintext_pad_len;
5570         unsigned int plaintext_len;
5571         unsigned int ciphertext_pad_len;
5572         unsigned int ciphertext_len;
5573         uint8_t buffer[10000];
5574         uint8_t digest_buffer[10000];
5575
5576         struct rte_cryptodev_info dev_info;
5577
5578         /* Verify the capabilities */
5579         struct rte_cryptodev_sym_capability_idx cap_idx;
5580         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5581         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5582         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5583                         &cap_idx) == NULL)
5584                 return TEST_SKIPPED;
5585         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5586         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5587         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5588                         &cap_idx) == NULL)
5589                 return TEST_SKIPPED;
5590
5591         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5592                 return TEST_SKIPPED;
5593
5594         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5595
5596         uint64_t feat_flags = dev_info.feature_flags;
5597
5598         if (op_mode == IN_PLACE) {
5599                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5600                         printf("Device doesn't support in-place scatter-gather "
5601                                         "in both input and output mbufs.\n");
5602                         return TEST_SKIPPED;
5603                 }
5604                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5605                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5606                         printf("Device doesn't support RAW data-path APIs.\n");
5607                         return TEST_SKIPPED;
5608                 }
5609         } else {
5610                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5611                         return TEST_SKIPPED;
5612                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5613                         printf("Device doesn't support out-of-place scatter-gather "
5614                                         "in both input and output mbufs.\n");
5615                         return TEST_SKIPPED;
5616                 }
5617                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5618                         printf("Device doesn't support digest encrypted.\n");
5619                         return TEST_SKIPPED;
5620                 }
5621         }
5622
5623         /* Create KASUMI session */
5624         retval = create_wireless_algo_auth_cipher_session(
5625                         ts_params->valid_devs[0],
5626                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5627                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5628                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5629                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5630                         RTE_CRYPTO_AUTH_KASUMI_F9,
5631                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5632                         tdata->key.data, tdata->key.len,
5633                         0, tdata->digest.len,
5634                         tdata->cipher_iv.len);
5635
5636         if (retval != 0)
5637                 return retval;
5638
5639         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5640         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5641         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5642         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5643
5644         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5645                         plaintext_pad_len, 15, 0);
5646         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5647                         "Failed to allocate input buffer in mempool");
5648
5649         if (op_mode == OUT_OF_PLACE) {
5650                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5651                                 plaintext_pad_len, 15, 0);
5652                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5653                                 "Failed to allocate output buffer in mempool");
5654         }
5655
5656         if (verify) {
5657                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5658                         tdata->ciphertext.data);
5659                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5660                                         ciphertext_len, buffer);
5661                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5662                         ciphertext_len);
5663         } else {
5664                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5665                         tdata->plaintext.data);
5666                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5667                                         plaintext_len, buffer);
5668                 debug_hexdump(stdout, "plaintext:", plaintext,
5669                         plaintext_len);
5670         }
5671         memset(buffer, 0, sizeof(buffer));
5672
5673         /* Create KASUMI operation */
5674         retval = create_wireless_algo_auth_cipher_operation(
5675                 tdata->digest.data, tdata->digest.len,
5676                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5677                 NULL, 0,
5678                 (tdata->digest.offset_bytes == 0 ?
5679                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5680                         : tdata->digest.offset_bytes),
5681                 tdata->validCipherLenInBits.len,
5682                 tdata->validCipherOffsetInBits.len,
5683                 tdata->validAuthLenInBits.len,
5684                 0,
5685                 op_mode, 1, verify);
5686
5687         if (retval < 0)
5688                 return retval;
5689
5690         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5691                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5692                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5693         else
5694                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5695                         ut_params->op);
5696
5697         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5698
5699         ut_params->obuf = (op_mode == IN_PLACE ?
5700                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5701
5702         if (verify) {
5703                 if (ut_params->obuf)
5704                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5705                                         plaintext_len, buffer);
5706                 else
5707                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5708                                         plaintext_len, buffer);
5709
5710                 debug_hexdump(stdout, "plaintext:", plaintext,
5711                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5712                 debug_hexdump(stdout, "plaintext expected:",
5713                         tdata->plaintext.data,
5714                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5715         } else {
5716                 if (ut_params->obuf)
5717                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5718                                         ciphertext_len, buffer);
5719                 else
5720                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5721                                         ciphertext_len, buffer);
5722
5723                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5724                         ciphertext_len);
5725                 debug_hexdump(stdout, "ciphertext expected:",
5726                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5727
5728                 if (ut_params->obuf)
5729                         digest = rte_pktmbuf_read(ut_params->obuf,
5730                                 (tdata->digest.offset_bytes == 0 ?
5731                                 plaintext_pad_len : tdata->digest.offset_bytes),
5732                                 tdata->digest.len, digest_buffer);
5733                 else
5734                         digest = rte_pktmbuf_read(ut_params->ibuf,
5735                                 (tdata->digest.offset_bytes == 0 ?
5736                                 plaintext_pad_len : tdata->digest.offset_bytes),
5737                                 tdata->digest.len, digest_buffer);
5738
5739                 debug_hexdump(stdout, "digest:", digest,
5740                         tdata->digest.len);
5741                 debug_hexdump(stdout, "digest expected:",
5742                         tdata->digest.data, tdata->digest.len);
5743         }
5744
5745         /* Validate obuf */
5746         if (verify) {
5747                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5748                         plaintext,
5749                         tdata->plaintext.data,
5750                         tdata->plaintext.len >> 3,
5751                         "KASUMI Plaintext data not as expected");
5752         } else {
5753                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5754                         ciphertext,
5755                         tdata->ciphertext.data,
5756                         tdata->validDataLenInBits.len,
5757                         "KASUMI Ciphertext data not as expected");
5758
5759                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5760                         digest,
5761                         tdata->digest.data,
5762                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5763                         "KASUMI Generated auth tag not as expected");
5764         }
5765         return 0;
5766 }
5767
5768 static int
5769 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5770 {
5771         struct crypto_testsuite_params *ts_params = &testsuite_params;
5772         struct crypto_unittest_params *ut_params = &unittest_params;
5773
5774         int retval;
5775
5776         uint8_t *plaintext, *ciphertext;
5777         unsigned plaintext_pad_len;
5778         unsigned plaintext_len;
5779         struct rte_cryptodev_info dev_info;
5780
5781         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5782         uint64_t feat_flags = dev_info.feature_flags;
5783
5784         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5785                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5786                 printf("Device doesn't support RAW data-path APIs.\n");
5787                 return TEST_SKIPPED;
5788         }
5789
5790         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5791                 return TEST_SKIPPED;
5792
5793         /* Verify the capabilities */
5794         struct rte_cryptodev_sym_capability_idx cap_idx;
5795         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5796         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5797         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5798                         &cap_idx) == NULL)
5799                 return TEST_SKIPPED;
5800         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5801         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5802         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5803                         &cap_idx) == NULL)
5804                 return TEST_SKIPPED;
5805
5806         /* Create KASUMI session */
5807         retval = create_wireless_algo_cipher_auth_session(
5808                         ts_params->valid_devs[0],
5809                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5810                         RTE_CRYPTO_AUTH_OP_GENERATE,
5811                         RTE_CRYPTO_AUTH_KASUMI_F9,
5812                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5813                         tdata->key.data, tdata->key.len,
5814                         0, tdata->digest.len,
5815                         tdata->cipher_iv.len);
5816         if (retval != 0)
5817                 return retval;
5818
5819         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5820
5821         /* clear mbuf payload */
5822         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5823                         rte_pktmbuf_tailroom(ut_params->ibuf));
5824
5825         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5826         /* Append data which is padded to a multiple of */
5827         /* the algorithms block size */
5828         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5829         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5830                                 plaintext_pad_len);
5831         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5832
5833         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5834
5835         /* Create KASUMI operation */
5836         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5837                                 tdata->digest.len, NULL, 0,
5838                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5839                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5840                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5841                                 tdata->validCipherOffsetInBits.len,
5842                                 tdata->validAuthLenInBits.len,
5843                                 0
5844                                 );
5845         if (retval < 0)
5846                 return retval;
5847
5848         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5849                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5850                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5851         else
5852                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5853                         ut_params->op);
5854         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5855
5856         if (ut_params->op->sym->m_dst)
5857                 ut_params->obuf = ut_params->op->sym->m_dst;
5858         else
5859                 ut_params->obuf = ut_params->op->sym->m_src;
5860
5861         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5862                                 tdata->validCipherOffsetInBits.len >> 3);
5863
5864         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5865                         + plaintext_pad_len;
5866
5867         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5868                                 (tdata->validCipherOffsetInBits.len >> 3);
5869         /* Validate obuf */
5870         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5871                 ciphertext,
5872                 reference_ciphertext,
5873                 tdata->validCipherLenInBits.len,
5874                 "KASUMI Ciphertext data not as expected");
5875
5876         /* Validate obuf */
5877         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5878                 ut_params->digest,
5879                 tdata->digest.data,
5880                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5881                 "KASUMI Generated auth tag not as expected");
5882         return 0;
5883 }
5884
5885 static int
5886 check_cipher_capability(const struct crypto_testsuite_params *ts_params,
5887                         const enum rte_crypto_cipher_algorithm cipher_algo,
5888                         const uint16_t key_size, const uint16_t iv_size)
5889 {
5890         struct rte_cryptodev_sym_capability_idx cap_idx;
5891         const struct rte_cryptodev_symmetric_capability *cap;
5892
5893         /* Check if device supports the algorithm */
5894         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5895         cap_idx.algo.cipher = cipher_algo;
5896
5897         cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5898                         &cap_idx);
5899
5900         if (cap == NULL)
5901                 return -1;
5902
5903         /* Check if device supports key size and IV size */
5904         if (rte_cryptodev_sym_capability_check_cipher(cap, key_size,
5905                         iv_size) < 0) {
5906                 return -1;
5907         }
5908
5909         return 0;
5910 }
5911
5912 static int
5913 test_zuc_encryption(const struct wireless_test_data *tdata)
5914 {
5915         struct crypto_testsuite_params *ts_params = &testsuite_params;
5916         struct crypto_unittest_params *ut_params = &unittest_params;
5917
5918         int retval;
5919         uint8_t *plaintext, *ciphertext;
5920         unsigned plaintext_pad_len;
5921         unsigned plaintext_len;
5922         struct rte_cryptodev_info dev_info;
5923
5924         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5925         uint64_t feat_flags = dev_info.feature_flags;
5926
5927         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5928                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5929                 printf("Device doesn't support RAW data-path APIs.\n");
5930                 return TEST_SKIPPED;
5931         }
5932
5933         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5934                 return TEST_SKIPPED;
5935
5936         /* Check if device supports ZUC EEA3 */
5937         if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
5938                         tdata->key.len, tdata->cipher_iv.len) < 0)
5939                 return TEST_SKIPPED;
5940
5941         /* Create ZUC session */
5942         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5943                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5944                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5945                                         tdata->key.data, tdata->key.len,
5946                                         tdata->cipher_iv.len);
5947         if (retval != 0)
5948                 return retval;
5949
5950         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5951
5952         /* Clear mbuf payload */
5953         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5954                rte_pktmbuf_tailroom(ut_params->ibuf));
5955
5956         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5957         /* Append data which is padded to a multiple */
5958         /* of the algorithms block size */
5959         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5960         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5961                                 plaintext_pad_len);
5962         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5963
5964         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5965
5966         /* Create ZUC operation */
5967         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5968                                         tdata->cipher_iv.len,
5969                                         tdata->plaintext.len,
5970                                         0);
5971         if (retval < 0)
5972                 return retval;
5973
5974         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5975                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5976                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5977         else
5978                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5979                                                 ut_params->op);
5980         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5981
5982         ut_params->obuf = ut_params->op->sym->m_dst;
5983         if (ut_params->obuf)
5984                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5985         else
5986                 ciphertext = plaintext;
5987
5988         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5989
5990         /* Validate obuf */
5991         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5992                 ciphertext,
5993                 tdata->ciphertext.data,
5994                 tdata->validCipherLenInBits.len,
5995                 "ZUC Ciphertext data not as expected");
5996         return 0;
5997 }
5998
5999 static int
6000 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
6001 {
6002         struct crypto_testsuite_params *ts_params = &testsuite_params;
6003         struct crypto_unittest_params *ut_params = &unittest_params;
6004
6005         int retval;
6006
6007         unsigned int plaintext_pad_len;
6008         unsigned int plaintext_len;
6009         const uint8_t *ciphertext;
6010         uint8_t ciphertext_buffer[2048];
6011         struct rte_cryptodev_info dev_info;
6012
6013         /* Check if device supports ZUC EEA3 */
6014         if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6015                         tdata->key.len, tdata->cipher_iv.len) < 0)
6016                 return TEST_SKIPPED;
6017
6018         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6019                 return TEST_SKIPPED;
6020
6021         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6022
6023         uint64_t feat_flags = dev_info.feature_flags;
6024
6025         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6026                 printf("Device doesn't support in-place scatter-gather. "
6027                                 "Test Skipped.\n");
6028                 return TEST_SKIPPED;
6029         }
6030
6031         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6032                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6033                 printf("Device doesn't support RAW data-path APIs.\n");
6034                 return TEST_SKIPPED;
6035         }
6036
6037         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6038
6039         /* Append data which is padded to a multiple */
6040         /* of the algorithms block size */
6041         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6042
6043         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6044                         plaintext_pad_len, 10, 0);
6045
6046         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6047                         tdata->plaintext.data);
6048
6049         /* Create ZUC session */
6050         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6051                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6052                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6053                         tdata->key.data, tdata->key.len,
6054                         tdata->cipher_iv.len);
6055         if (retval < 0)
6056                 return retval;
6057
6058         /* Clear mbuf payload */
6059
6060         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
6061
6062         /* Create ZUC operation */
6063         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6064                         tdata->cipher_iv.len, tdata->plaintext.len,
6065                         0);
6066         if (retval < 0)
6067                 return retval;
6068
6069         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6070                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6071                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6072         else
6073                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6074                                                 ut_params->op);
6075         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6076
6077         ut_params->obuf = ut_params->op->sym->m_dst;
6078         if (ut_params->obuf)
6079                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
6080                         0, plaintext_len, ciphertext_buffer);
6081         else
6082                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6083                         0, plaintext_len, ciphertext_buffer);
6084
6085         /* Validate obuf */
6086         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6087
6088         /* Validate obuf */
6089         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6090                 ciphertext,
6091                 tdata->ciphertext.data,
6092                 tdata->validCipherLenInBits.len,
6093                 "ZUC Ciphertext data not as expected");
6094
6095         return 0;
6096 }
6097
6098 static int
6099 test_zuc_authentication(const struct wireless_test_data *tdata)
6100 {
6101         struct crypto_testsuite_params *ts_params = &testsuite_params;
6102         struct crypto_unittest_params *ut_params = &unittest_params;
6103
6104         int retval;
6105         unsigned plaintext_pad_len;
6106         unsigned plaintext_len;
6107         uint8_t *plaintext;
6108
6109         struct rte_cryptodev_sym_capability_idx cap_idx;
6110         struct rte_cryptodev_info dev_info;
6111
6112         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6113         uint64_t feat_flags = dev_info.feature_flags;
6114
6115         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6116                         (tdata->validAuthLenInBits.len % 8 != 0)) {
6117                 printf("Device doesn't support NON-Byte Aligned Data.\n");
6118                 return TEST_SKIPPED;
6119         }
6120
6121         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6122                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6123                 printf("Device doesn't support RAW data-path APIs.\n");
6124                 return TEST_SKIPPED;
6125         }
6126
6127         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6128                 return TEST_SKIPPED;
6129
6130         /* Check if device supports ZUC EIA3 */
6131         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6132         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6133
6134         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6135                         &cap_idx) == NULL)
6136                 return TEST_SKIPPED;
6137
6138         /* Create ZUC session */
6139         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6140                         tdata->key.data, tdata->key.len,
6141                         tdata->auth_iv.len, tdata->digest.len,
6142                         RTE_CRYPTO_AUTH_OP_GENERATE,
6143                         RTE_CRYPTO_AUTH_ZUC_EIA3);
6144         if (retval != 0)
6145                 return retval;
6146
6147         /* alloc mbuf and set payload */
6148         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6149
6150         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6151         rte_pktmbuf_tailroom(ut_params->ibuf));
6152
6153         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6154         /* Append data which is padded to a multiple of */
6155         /* the algorithms block size */
6156         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6157         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6158                                 plaintext_pad_len);
6159         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6160
6161         /* Create ZUC operation */
6162         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6163                         tdata->auth_iv.data, tdata->auth_iv.len,
6164                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6165                         tdata->validAuthLenInBits.len,
6166                         0);
6167         if (retval < 0)
6168                 return retval;
6169
6170         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6171                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6172                                 ut_params->op, 0, 1, 1, 0);
6173         else
6174                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6175                                 ut_params->op);
6176         ut_params->obuf = ut_params->op->sym->m_src;
6177         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6178         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6179                         + plaintext_pad_len;
6180
6181         /* Validate obuf */
6182         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6183         ut_params->digest,
6184         tdata->digest.data,
6185         tdata->digest.len,
6186         "ZUC Generated auth tag not as expected");
6187
6188         return 0;
6189 }
6190
6191 static int
6192 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6193         uint8_t op_mode, uint8_t verify)
6194 {
6195         struct crypto_testsuite_params *ts_params = &testsuite_params;
6196         struct crypto_unittest_params *ut_params = &unittest_params;
6197
6198         int retval;
6199
6200         uint8_t *plaintext = NULL, *ciphertext = NULL;
6201         unsigned int plaintext_pad_len;
6202         unsigned int plaintext_len;
6203         unsigned int ciphertext_pad_len;
6204         unsigned int ciphertext_len;
6205
6206         struct rte_cryptodev_info dev_info;
6207         struct rte_cryptodev_sym_capability_idx cap_idx;
6208
6209         /* Check if device supports ZUC EEA3 */
6210         if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6211                         tdata->key.len, tdata->cipher_iv.len) < 0)
6212                 return TEST_SKIPPED;
6213
6214         /* Check if device supports ZUC EIA3 */
6215         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6216         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6217
6218         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6219                         &cap_idx) == NULL)
6220                 return TEST_SKIPPED;
6221
6222         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6223
6224         uint64_t feat_flags = dev_info.feature_flags;
6225
6226         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6227                 printf("Device doesn't support digest encrypted.\n");
6228                 return TEST_SKIPPED;
6229         }
6230         if (op_mode == IN_PLACE) {
6231                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6232                         printf("Device doesn't support in-place scatter-gather "
6233                                         "in both input and output mbufs.\n");
6234                         return TEST_SKIPPED;
6235                 }
6236
6237                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6238                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6239                         printf("Device doesn't support RAW data-path APIs.\n");
6240                         return TEST_SKIPPED;
6241                 }
6242         } else {
6243                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6244                         return TEST_SKIPPED;
6245                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6246                         printf("Device doesn't support out-of-place scatter-gather "
6247                                         "in both input and output mbufs.\n");
6248                         return TEST_SKIPPED;
6249                 }
6250         }
6251
6252         /* Create ZUC session */
6253         retval = create_wireless_algo_auth_cipher_session(
6254                         ts_params->valid_devs[0],
6255                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6256                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6257                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6258                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6259                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6260                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6261                         tdata->key.data, tdata->key.len,
6262                         tdata->auth_iv.len, tdata->digest.len,
6263                         tdata->cipher_iv.len);
6264
6265         if (retval != 0)
6266                 return retval;
6267
6268         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6269         if (op_mode == OUT_OF_PLACE)
6270                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6271
6272         /* clear mbuf payload */
6273         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6274                 rte_pktmbuf_tailroom(ut_params->ibuf));
6275         if (op_mode == OUT_OF_PLACE)
6276                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6277                         rte_pktmbuf_tailroom(ut_params->obuf));
6278
6279         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6280         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6281         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6282         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6283
6284         if (verify) {
6285                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6286                                         ciphertext_pad_len);
6287                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6288                 if (op_mode == OUT_OF_PLACE)
6289                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6290                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6291                         ciphertext_len);
6292         } else {
6293                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6294                                         plaintext_pad_len);
6295                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6296                 if (op_mode == OUT_OF_PLACE)
6297                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6298                 debug_hexdump(stdout, "plaintext:", plaintext,
6299                         plaintext_len);
6300         }
6301
6302         /* Create ZUC operation */
6303         retval = create_wireless_algo_auth_cipher_operation(
6304                 tdata->digest.data, tdata->digest.len,
6305                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6306                 tdata->auth_iv.data, tdata->auth_iv.len,
6307                 (tdata->digest.offset_bytes == 0 ?
6308                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6309                         : tdata->digest.offset_bytes),
6310                 tdata->validCipherLenInBits.len,
6311                 tdata->validCipherOffsetInBits.len,
6312                 tdata->validAuthLenInBits.len,
6313                 0,
6314                 op_mode, 0, verify);
6315
6316         if (retval < 0)
6317                 return retval;
6318
6319         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6320                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6321                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6322         else
6323                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6324                         ut_params->op);
6325
6326         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6327
6328         ut_params->obuf = (op_mode == IN_PLACE ?
6329                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6330
6331
6332         if (verify) {
6333                 if (ut_params->obuf)
6334                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6335                                                         uint8_t *);
6336                 else
6337                         plaintext = ciphertext;
6338
6339                 debug_hexdump(stdout, "plaintext:", plaintext,
6340                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6341                 debug_hexdump(stdout, "plaintext expected:",
6342                         tdata->plaintext.data,
6343                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6344         } else {
6345                 if (ut_params->obuf)
6346                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6347                                                         uint8_t *);
6348                 else
6349                         ciphertext = plaintext;
6350
6351                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6352                         ciphertext_len);
6353                 debug_hexdump(stdout, "ciphertext expected:",
6354                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6355
6356                 ut_params->digest = rte_pktmbuf_mtod(
6357                         ut_params->obuf, uint8_t *) +
6358                         (tdata->digest.offset_bytes == 0 ?
6359                         plaintext_pad_len : tdata->digest.offset_bytes);
6360
6361                 debug_hexdump(stdout, "digest:", ut_params->digest,
6362                         tdata->digest.len);
6363                 debug_hexdump(stdout, "digest expected:",
6364                         tdata->digest.data, tdata->digest.len);
6365         }
6366
6367         /* Validate obuf */
6368         if (verify) {
6369                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6370                         plaintext,
6371                         tdata->plaintext.data,
6372                         tdata->plaintext.len >> 3,
6373                         "ZUC Plaintext data not as expected");
6374         } else {
6375                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6376                         ciphertext,
6377                         tdata->ciphertext.data,
6378                         tdata->ciphertext.len >> 3,
6379                         "ZUC Ciphertext data not as expected");
6380
6381                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6382                         ut_params->digest,
6383                         tdata->digest.data,
6384                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6385                         "ZUC Generated auth tag not as expected");
6386         }
6387         return 0;
6388 }
6389
6390 static int
6391 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6392         uint8_t op_mode, uint8_t verify)
6393 {
6394         struct crypto_testsuite_params *ts_params = &testsuite_params;
6395         struct crypto_unittest_params *ut_params = &unittest_params;
6396
6397         int retval;
6398
6399         const uint8_t *plaintext = NULL;
6400         const uint8_t *ciphertext = NULL;
6401         const uint8_t *digest = NULL;
6402         unsigned int plaintext_pad_len;
6403         unsigned int plaintext_len;
6404         unsigned int ciphertext_pad_len;
6405         unsigned int ciphertext_len;
6406         uint8_t buffer[10000];
6407         uint8_t digest_buffer[10000];
6408
6409         struct rte_cryptodev_info dev_info;
6410         struct rte_cryptodev_sym_capability_idx cap_idx;
6411
6412         /* Check if device supports ZUC EEA3 */
6413         if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6414                         tdata->key.len, tdata->cipher_iv.len) < 0)
6415                 return TEST_SKIPPED;
6416
6417         /* Check if device supports ZUC EIA3 */
6418         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6419         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6420
6421         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6422                         &cap_idx) == NULL)
6423                 return TEST_SKIPPED;
6424
6425         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6426
6427         uint64_t feat_flags = dev_info.feature_flags;
6428
6429         if (op_mode == IN_PLACE) {
6430                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6431                         printf("Device doesn't support in-place scatter-gather "
6432                                         "in both input and output mbufs.\n");
6433                         return TEST_SKIPPED;
6434                 }
6435
6436                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6437                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6438                         printf("Device doesn't support RAW data-path APIs.\n");
6439                         return TEST_SKIPPED;
6440                 }
6441         } else {
6442                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6443                         return TEST_SKIPPED;
6444                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6445                         printf("Device doesn't support out-of-place scatter-gather "
6446                                         "in both input and output mbufs.\n");
6447                         return TEST_SKIPPED;
6448                 }
6449                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6450                         printf("Device doesn't support digest encrypted.\n");
6451                         return TEST_SKIPPED;
6452                 }
6453         }
6454
6455         /* Create ZUC session */
6456         retval = create_wireless_algo_auth_cipher_session(
6457                         ts_params->valid_devs[0],
6458                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6459                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6460                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6461                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6462                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6463                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6464                         tdata->key.data, tdata->key.len,
6465                         tdata->auth_iv.len, tdata->digest.len,
6466                         tdata->cipher_iv.len);
6467
6468         if (retval != 0)
6469                 return retval;
6470
6471         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6472         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6473         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6474         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6475
6476         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6477                         plaintext_pad_len, 15, 0);
6478         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6479                         "Failed to allocate input buffer in mempool");
6480
6481         if (op_mode == OUT_OF_PLACE) {
6482                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6483                                 plaintext_pad_len, 15, 0);
6484                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6485                                 "Failed to allocate output buffer in mempool");
6486         }
6487
6488         if (verify) {
6489                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6490                         tdata->ciphertext.data);
6491                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6492                                         ciphertext_len, buffer);
6493                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6494                         ciphertext_len);
6495         } else {
6496                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6497                         tdata->plaintext.data);
6498                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6499                                         plaintext_len, buffer);
6500                 debug_hexdump(stdout, "plaintext:", plaintext,
6501                         plaintext_len);
6502         }
6503         memset(buffer, 0, sizeof(buffer));
6504
6505         /* Create ZUC operation */
6506         retval = create_wireless_algo_auth_cipher_operation(
6507                 tdata->digest.data, tdata->digest.len,
6508                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6509                 NULL, 0,
6510                 (tdata->digest.offset_bytes == 0 ?
6511                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6512                         : tdata->digest.offset_bytes),
6513                 tdata->validCipherLenInBits.len,
6514                 tdata->validCipherOffsetInBits.len,
6515                 tdata->validAuthLenInBits.len,
6516                 0,
6517                 op_mode, 1, verify);
6518
6519         if (retval < 0)
6520                 return retval;
6521
6522         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6523                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6524                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6525         else
6526                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6527                         ut_params->op);
6528
6529         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6530
6531         ut_params->obuf = (op_mode == IN_PLACE ?
6532                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6533
6534         if (verify) {
6535                 if (ut_params->obuf)
6536                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6537                                         plaintext_len, buffer);
6538                 else
6539                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6540                                         plaintext_len, buffer);
6541
6542                 debug_hexdump(stdout, "plaintext:", plaintext,
6543                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6544                 debug_hexdump(stdout, "plaintext expected:",
6545                         tdata->plaintext.data,
6546                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6547         } else {
6548                 if (ut_params->obuf)
6549                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6550                                         ciphertext_len, buffer);
6551                 else
6552                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6553                                         ciphertext_len, buffer);
6554
6555                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6556                         ciphertext_len);
6557                 debug_hexdump(stdout, "ciphertext expected:",
6558                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6559
6560                 if (ut_params->obuf)
6561                         digest = rte_pktmbuf_read(ut_params->obuf,
6562                                 (tdata->digest.offset_bytes == 0 ?
6563                                 plaintext_pad_len : tdata->digest.offset_bytes),
6564                                 tdata->digest.len, digest_buffer);
6565                 else
6566                         digest = rte_pktmbuf_read(ut_params->ibuf,
6567                                 (tdata->digest.offset_bytes == 0 ?
6568                                 plaintext_pad_len : tdata->digest.offset_bytes),
6569                                 tdata->digest.len, digest_buffer);
6570
6571                 debug_hexdump(stdout, "digest:", digest,
6572                         tdata->digest.len);
6573                 debug_hexdump(stdout, "digest expected:",
6574                         tdata->digest.data, tdata->digest.len);
6575         }
6576
6577         /* Validate obuf */
6578         if (verify) {
6579                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6580                         plaintext,
6581                         tdata->plaintext.data,
6582                         tdata->plaintext.len >> 3,
6583                         "ZUC Plaintext data not as expected");
6584         } else {
6585                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6586                         ciphertext,
6587                         tdata->ciphertext.data,
6588                         tdata->validDataLenInBits.len,
6589                         "ZUC Ciphertext data not as expected");
6590
6591                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6592                         digest,
6593                         tdata->digest.data,
6594                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6595                         "ZUC Generated auth tag not as expected");
6596         }
6597         return 0;
6598 }
6599
6600 static int
6601 test_kasumi_encryption_test_case_1(void)
6602 {
6603         return test_kasumi_encryption(&kasumi_test_case_1);
6604 }
6605
6606 static int
6607 test_kasumi_encryption_test_case_1_sgl(void)
6608 {
6609         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6610 }
6611
6612 static int
6613 test_kasumi_encryption_test_case_1_oop(void)
6614 {
6615         return test_kasumi_encryption_oop(&kasumi_test_case_1);
6616 }
6617
6618 static int
6619 test_kasumi_encryption_test_case_1_oop_sgl(void)
6620 {
6621         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6622 }
6623
6624 static int
6625 test_kasumi_encryption_test_case_2(void)
6626 {
6627         return test_kasumi_encryption(&kasumi_test_case_2);
6628 }
6629
6630 static int
6631 test_kasumi_encryption_test_case_3(void)
6632 {
6633         return test_kasumi_encryption(&kasumi_test_case_3);
6634 }
6635
6636 static int
6637 test_kasumi_encryption_test_case_4(void)
6638 {
6639         return test_kasumi_encryption(&kasumi_test_case_4);
6640 }
6641
6642 static int
6643 test_kasumi_encryption_test_case_5(void)
6644 {
6645         return test_kasumi_encryption(&kasumi_test_case_5);
6646 }
6647
6648 static int
6649 test_kasumi_decryption_test_case_1(void)
6650 {
6651         return test_kasumi_decryption(&kasumi_test_case_1);
6652 }
6653
6654 static int
6655 test_kasumi_decryption_test_case_1_oop(void)
6656 {
6657         return test_kasumi_decryption_oop(&kasumi_test_case_1);
6658 }
6659
6660 static int
6661 test_kasumi_decryption_test_case_2(void)
6662 {
6663         return test_kasumi_decryption(&kasumi_test_case_2);
6664 }
6665
6666 static int
6667 test_kasumi_decryption_test_case_3(void)
6668 {
6669         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6670         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6671                 return TEST_SKIPPED;
6672         return test_kasumi_decryption(&kasumi_test_case_3);
6673 }
6674
6675 static int
6676 test_kasumi_decryption_test_case_4(void)
6677 {
6678         return test_kasumi_decryption(&kasumi_test_case_4);
6679 }
6680
6681 static int
6682 test_kasumi_decryption_test_case_5(void)
6683 {
6684         return test_kasumi_decryption(&kasumi_test_case_5);
6685 }
6686 static int
6687 test_snow3g_encryption_test_case_1(void)
6688 {
6689         return test_snow3g_encryption(&snow3g_test_case_1);
6690 }
6691
6692 static int
6693 test_snow3g_encryption_test_case_1_oop(void)
6694 {
6695         return test_snow3g_encryption_oop(&snow3g_test_case_1);
6696 }
6697
6698 static int
6699 test_snow3g_encryption_test_case_1_oop_sgl(void)
6700 {
6701         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6702 }
6703
6704
6705 static int
6706 test_snow3g_encryption_test_case_1_offset_oop(void)
6707 {
6708         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6709 }
6710
6711 static int
6712 test_snow3g_encryption_test_case_2(void)
6713 {
6714         return test_snow3g_encryption(&snow3g_test_case_2);
6715 }
6716
6717 static int
6718 test_snow3g_encryption_test_case_3(void)
6719 {
6720         return test_snow3g_encryption(&snow3g_test_case_3);
6721 }
6722
6723 static int
6724 test_snow3g_encryption_test_case_4(void)
6725 {
6726         return test_snow3g_encryption(&snow3g_test_case_4);
6727 }
6728
6729 static int
6730 test_snow3g_encryption_test_case_5(void)
6731 {
6732         return test_snow3g_encryption(&snow3g_test_case_5);
6733 }
6734
6735 static int
6736 test_snow3g_decryption_test_case_1(void)
6737 {
6738         return test_snow3g_decryption(&snow3g_test_case_1);
6739 }
6740
6741 static int
6742 test_snow3g_decryption_test_case_1_oop(void)
6743 {
6744         return test_snow3g_decryption_oop(&snow3g_test_case_1);
6745 }
6746
6747 static int
6748 test_snow3g_decryption_test_case_2(void)
6749 {
6750         return test_snow3g_decryption(&snow3g_test_case_2);
6751 }
6752
6753 static int
6754 test_snow3g_decryption_test_case_3(void)
6755 {
6756         return test_snow3g_decryption(&snow3g_test_case_3);
6757 }
6758
6759 static int
6760 test_snow3g_decryption_test_case_4(void)
6761 {
6762         return test_snow3g_decryption(&snow3g_test_case_4);
6763 }
6764
6765 static int
6766 test_snow3g_decryption_test_case_5(void)
6767 {
6768         return test_snow3g_decryption(&snow3g_test_case_5);
6769 }
6770
6771 /*
6772  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6773  * Pattern digest from snow3g_test_data must be allocated as
6774  * 4 last bytes in plaintext.
6775  */
6776 static void
6777 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6778                 struct snow3g_hash_test_data *output)
6779 {
6780         if ((pattern != NULL) && (output != NULL)) {
6781                 output->key.len = pattern->key.len;
6782
6783                 memcpy(output->key.data,
6784                 pattern->key.data, pattern->key.len);
6785
6786                 output->auth_iv.len = pattern->auth_iv.len;
6787
6788                 memcpy(output->auth_iv.data,
6789                 pattern->auth_iv.data, pattern->auth_iv.len);
6790
6791                 output->plaintext.len = pattern->plaintext.len;
6792
6793                 memcpy(output->plaintext.data,
6794                 pattern->plaintext.data, pattern->plaintext.len >> 3);
6795
6796                 output->digest.len = pattern->digest.len;
6797
6798                 memcpy(output->digest.data,
6799                 &pattern->plaintext.data[pattern->digest.offset_bytes],
6800                 pattern->digest.len);
6801
6802                 output->validAuthLenInBits.len =
6803                 pattern->validAuthLenInBits.len;
6804         }
6805 }
6806
6807 /*
6808  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6809  */
6810 static int
6811 test_snow3g_decryption_with_digest_test_case_1(void)
6812 {
6813         struct snow3g_hash_test_data snow3g_hash_data;
6814         struct rte_cryptodev_info dev_info;
6815         struct crypto_testsuite_params *ts_params = &testsuite_params;
6816
6817         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6818         uint64_t feat_flags = dev_info.feature_flags;
6819
6820         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6821                 printf("Device doesn't support encrypted digest operations.\n");
6822                 return TEST_SKIPPED;
6823         }
6824
6825         /*
6826          * Function prepare data for hash veryfication test case.
6827          * Digest is allocated in 4 last bytes in plaintext, pattern.
6828          */
6829         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6830
6831         return test_snow3g_decryption(&snow3g_test_case_7) &
6832                         test_snow3g_authentication_verify(&snow3g_hash_data);
6833 }
6834
6835 static int
6836 test_snow3g_cipher_auth_test_case_1(void)
6837 {
6838         return test_snow3g_cipher_auth(&snow3g_test_case_3);
6839 }
6840
6841 static int
6842 test_snow3g_auth_cipher_test_case_1(void)
6843 {
6844         return test_snow3g_auth_cipher(
6845                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6846 }
6847
6848 static int
6849 test_snow3g_auth_cipher_test_case_2(void)
6850 {
6851         return test_snow3g_auth_cipher(
6852                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6853 }
6854
6855 static int
6856 test_snow3g_auth_cipher_test_case_2_oop(void)
6857 {
6858         return test_snow3g_auth_cipher(
6859                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6860 }
6861
6862 static int
6863 test_snow3g_auth_cipher_part_digest_enc(void)
6864 {
6865         return test_snow3g_auth_cipher(
6866                 &snow3g_auth_cipher_partial_digest_encryption,
6867                         IN_PLACE, 0);
6868 }
6869
6870 static int
6871 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6872 {
6873         return test_snow3g_auth_cipher(
6874                 &snow3g_auth_cipher_partial_digest_encryption,
6875                         OUT_OF_PLACE, 0);
6876 }
6877
6878 static int
6879 test_snow3g_auth_cipher_test_case_3_sgl(void)
6880 {
6881         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6882         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6883                 return TEST_SKIPPED;
6884         return test_snow3g_auth_cipher_sgl(
6885                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6886 }
6887
6888 static int
6889 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6890 {
6891         return test_snow3g_auth_cipher_sgl(
6892                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6893 }
6894
6895 static int
6896 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6897 {
6898         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6899         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6900                 return TEST_SKIPPED;
6901         return test_snow3g_auth_cipher_sgl(
6902                 &snow3g_auth_cipher_partial_digest_encryption,
6903                         IN_PLACE, 0);
6904 }
6905
6906 static int
6907 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6908 {
6909         return test_snow3g_auth_cipher_sgl(
6910                 &snow3g_auth_cipher_partial_digest_encryption,
6911                         OUT_OF_PLACE, 0);
6912 }
6913
6914 static int
6915 test_snow3g_auth_cipher_verify_test_case_1(void)
6916 {
6917         return test_snow3g_auth_cipher(
6918                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6919 }
6920
6921 static int
6922 test_snow3g_auth_cipher_verify_test_case_2(void)
6923 {
6924         return test_snow3g_auth_cipher(
6925                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6926 }
6927
6928 static int
6929 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6930 {
6931         return test_snow3g_auth_cipher(
6932                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6933 }
6934
6935 static int
6936 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6937 {
6938         return test_snow3g_auth_cipher(
6939                 &snow3g_auth_cipher_partial_digest_encryption,
6940                         IN_PLACE, 1);
6941 }
6942
6943 static int
6944 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6945 {
6946         return test_snow3g_auth_cipher(
6947                 &snow3g_auth_cipher_partial_digest_encryption,
6948                         OUT_OF_PLACE, 1);
6949 }
6950
6951 static int
6952 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6953 {
6954         return test_snow3g_auth_cipher_sgl(
6955                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6956 }
6957
6958 static int
6959 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6960 {
6961         return test_snow3g_auth_cipher_sgl(
6962                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6963 }
6964
6965 static int
6966 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6967 {
6968         return test_snow3g_auth_cipher_sgl(
6969                 &snow3g_auth_cipher_partial_digest_encryption,
6970                         IN_PLACE, 1);
6971 }
6972
6973 static int
6974 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6975 {
6976         return test_snow3g_auth_cipher_sgl(
6977                 &snow3g_auth_cipher_partial_digest_encryption,
6978                         OUT_OF_PLACE, 1);
6979 }
6980
6981 static int
6982 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6983 {
6984         return test_snow3g_auth_cipher(
6985                 &snow3g_test_case_7, IN_PLACE, 0);
6986 }
6987
6988 static int
6989 test_kasumi_auth_cipher_test_case_1(void)
6990 {
6991         return test_kasumi_auth_cipher(
6992                 &kasumi_test_case_3, IN_PLACE, 0);
6993 }
6994
6995 static int
6996 test_kasumi_auth_cipher_test_case_2(void)
6997 {
6998         return test_kasumi_auth_cipher(
6999                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7000 }
7001
7002 static int
7003 test_kasumi_auth_cipher_test_case_2_oop(void)
7004 {
7005         return test_kasumi_auth_cipher(
7006                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7007 }
7008
7009 static int
7010 test_kasumi_auth_cipher_test_case_2_sgl(void)
7011 {
7012         return test_kasumi_auth_cipher_sgl(
7013                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7014 }
7015
7016 static int
7017 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
7018 {
7019         return test_kasumi_auth_cipher_sgl(
7020                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7021 }
7022
7023 static int
7024 test_kasumi_auth_cipher_verify_test_case_1(void)
7025 {
7026         return test_kasumi_auth_cipher(
7027                 &kasumi_test_case_3, IN_PLACE, 1);
7028 }
7029
7030 static int
7031 test_kasumi_auth_cipher_verify_test_case_2(void)
7032 {
7033         return test_kasumi_auth_cipher(
7034                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7035 }
7036
7037 static int
7038 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
7039 {
7040         return test_kasumi_auth_cipher(
7041                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7042 }
7043
7044 static int
7045 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
7046 {
7047         return test_kasumi_auth_cipher_sgl(
7048                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7049 }
7050
7051 static int
7052 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
7053 {
7054         return test_kasumi_auth_cipher_sgl(
7055                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7056 }
7057
7058 static int
7059 test_kasumi_cipher_auth_test_case_1(void)
7060 {
7061         return test_kasumi_cipher_auth(&kasumi_test_case_6);
7062 }
7063
7064 static int
7065 test_zuc_encryption_test_case_1(void)
7066 {
7067         return test_zuc_encryption(&zuc_test_case_cipher_193b);
7068 }
7069
7070 static int
7071 test_zuc_encryption_test_case_2(void)
7072 {
7073         return test_zuc_encryption(&zuc_test_case_cipher_800b);
7074 }
7075
7076 static int
7077 test_zuc_encryption_test_case_3(void)
7078 {
7079         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
7080 }
7081
7082 static int
7083 test_zuc_encryption_test_case_4(void)
7084 {
7085         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
7086 }
7087
7088 static int
7089 test_zuc_encryption_test_case_5(void)
7090 {
7091         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7092 }
7093
7094 static int
7095 test_zuc_encryption_test_case_6_sgl(void)
7096 {
7097         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7098 }
7099
7100 static int
7101 test_zuc_encryption_test_case_7(void)
7102 {
7103         return test_zuc_encryption(&zuc_test_case_cipher_800b_key_256b);
7104 }
7105
7106 static int
7107 test_zuc_hash_generate_test_case_1(void)
7108 {
7109         return test_zuc_authentication(&zuc_test_case_auth_1b);
7110 }
7111
7112 static int
7113 test_zuc_hash_generate_test_case_2(void)
7114 {
7115         return test_zuc_authentication(&zuc_test_case_auth_90b);
7116 }
7117
7118 static int
7119 test_zuc_hash_generate_test_case_3(void)
7120 {
7121         return test_zuc_authentication(&zuc_test_case_auth_577b);
7122 }
7123
7124 static int
7125 test_zuc_hash_generate_test_case_4(void)
7126 {
7127         return test_zuc_authentication(&zuc_test_case_auth_2079b);
7128 }
7129
7130 static int
7131 test_zuc_hash_generate_test_case_5(void)
7132 {
7133         return test_zuc_authentication(&zuc_test_auth_5670b);
7134 }
7135
7136 static int
7137 test_zuc_hash_generate_test_case_6(void)
7138 {
7139         return test_zuc_authentication(&zuc_test_case_auth_128b);
7140 }
7141
7142 static int
7143 test_zuc_hash_generate_test_case_7(void)
7144 {
7145         return test_zuc_authentication(&zuc_test_case_auth_2080b);
7146 }
7147
7148 static int
7149 test_zuc_hash_generate_test_case_8(void)
7150 {
7151         return test_zuc_authentication(&zuc_test_case_auth_584b);
7152 }
7153
7154 static int
7155 test_zuc_hash_generate_test_case_9(void)
7156 {
7157         return test_zuc_authentication(&zuc_test_case_auth_584b_mac_64b);
7158 }
7159
7160 static int
7161 test_zuc_hash_generate_test_case_10(void)
7162 {
7163         return test_zuc_authentication(&zuc_test_case_auth_2080b_mac_128b);
7164 }
7165
7166 static int
7167 test_zuc_cipher_auth_test_case_1(void)
7168 {
7169         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7170 }
7171
7172 static int
7173 test_zuc_cipher_auth_test_case_2(void)
7174 {
7175         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7176 }
7177
7178 static int
7179 test_zuc_auth_cipher_test_case_1(void)
7180 {
7181         return test_zuc_auth_cipher(
7182                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7183 }
7184
7185 static int
7186 test_zuc_auth_cipher_test_case_1_oop(void)
7187 {
7188         return test_zuc_auth_cipher(
7189                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7190 }
7191
7192 static int
7193 test_zuc_auth_cipher_test_case_1_sgl(void)
7194 {
7195         return test_zuc_auth_cipher_sgl(
7196                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7197 }
7198
7199 static int
7200 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7201 {
7202         return test_zuc_auth_cipher_sgl(
7203                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7204 }
7205
7206 static int
7207 test_zuc_auth_cipher_verify_test_case_1(void)
7208 {
7209         return test_zuc_auth_cipher(
7210                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7211 }
7212
7213 static int
7214 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7215 {
7216         return test_zuc_auth_cipher(
7217                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7218 }
7219
7220 static int
7221 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7222 {
7223         return test_zuc_auth_cipher_sgl(
7224                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7225 }
7226
7227 static int
7228 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7229 {
7230         return test_zuc_auth_cipher_sgl(
7231                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7232 }
7233
7234 static int
7235 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7236 {
7237         uint8_t dev_id = testsuite_params.valid_devs[0];
7238
7239         struct rte_cryptodev_sym_capability_idx cap_idx;
7240
7241         /* Check if device supports particular cipher algorithm */
7242         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7243         cap_idx.algo.cipher = tdata->cipher_algo;
7244         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7245                 return TEST_SKIPPED;
7246
7247         /* Check if device supports particular hash algorithm */
7248         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7249         cap_idx.algo.auth = tdata->auth_algo;
7250         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7251                 return TEST_SKIPPED;
7252
7253         return 0;
7254 }
7255
7256 static int
7257 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7258         uint8_t op_mode, uint8_t verify)
7259 {
7260         struct crypto_testsuite_params *ts_params = &testsuite_params;
7261         struct crypto_unittest_params *ut_params = &unittest_params;
7262
7263         int retval;
7264
7265         uint8_t *plaintext = NULL, *ciphertext = NULL;
7266         unsigned int plaintext_pad_len;
7267         unsigned int plaintext_len;
7268         unsigned int ciphertext_pad_len;
7269         unsigned int ciphertext_len;
7270
7271         struct rte_cryptodev_info dev_info;
7272         struct rte_crypto_op *op;
7273
7274         /* Check if device supports particular algorithms separately */
7275         if (test_mixed_check_if_unsupported(tdata))
7276                 return TEST_SKIPPED;
7277         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7278                 return TEST_SKIPPED;
7279
7280         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7281
7282         uint64_t feat_flags = dev_info.feature_flags;
7283
7284         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7285                 printf("Device doesn't support digest encrypted.\n");
7286                 return TEST_SKIPPED;
7287         }
7288
7289         /* Create the session */
7290         if (verify)
7291                 retval = create_wireless_algo_cipher_auth_session(
7292                                 ts_params->valid_devs[0],
7293                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7294                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7295                                 tdata->auth_algo,
7296                                 tdata->cipher_algo,
7297                                 tdata->auth_key.data, tdata->auth_key.len,
7298                                 tdata->auth_iv.len, tdata->digest_enc.len,
7299                                 tdata->cipher_iv.len);
7300         else
7301                 retval = create_wireless_algo_auth_cipher_session(
7302                                 ts_params->valid_devs[0],
7303                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7304                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7305                                 tdata->auth_algo,
7306                                 tdata->cipher_algo,
7307                                 tdata->auth_key.data, tdata->auth_key.len,
7308                                 tdata->auth_iv.len, tdata->digest_enc.len,
7309                                 tdata->cipher_iv.len);
7310         if (retval != 0)
7311                 return retval;
7312
7313         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7314         if (op_mode == OUT_OF_PLACE)
7315                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7316
7317         /* clear mbuf payload */
7318         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7319                 rte_pktmbuf_tailroom(ut_params->ibuf));
7320         if (op_mode == OUT_OF_PLACE) {
7321
7322                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7323                                 rte_pktmbuf_tailroom(ut_params->obuf));
7324         }
7325
7326         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7327         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7328         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7329         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7330
7331         if (verify) {
7332                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7333                                 ciphertext_pad_len);
7334                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7335                 if (op_mode == OUT_OF_PLACE)
7336                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7337                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7338                                 ciphertext_len);
7339         } else {
7340                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7341                                 plaintext_pad_len);
7342                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7343                 if (op_mode == OUT_OF_PLACE)
7344                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7345                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7346         }
7347
7348         /* Create the operation */
7349         retval = create_wireless_algo_auth_cipher_operation(
7350                         tdata->digest_enc.data, tdata->digest_enc.len,
7351                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7352                         tdata->auth_iv.data, tdata->auth_iv.len,
7353                         (tdata->digest_enc.offset == 0 ?
7354                                 plaintext_pad_len
7355                                 : tdata->digest_enc.offset),
7356                         tdata->validCipherLen.len_bits,
7357                         tdata->cipher.offset_bits,
7358                         tdata->validAuthLen.len_bits,
7359                         tdata->auth.offset_bits,
7360                         op_mode, 0, verify);
7361
7362         if (retval < 0)
7363                 return retval;
7364
7365         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7366
7367         /* Check if the op failed because the device doesn't */
7368         /* support this particular combination of algorithms */
7369         if (op == NULL && ut_params->op->status ==
7370                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7371                 printf("Device doesn't support this mixed combination. "
7372                                 "Test Skipped.\n");
7373                 return TEST_SKIPPED;
7374         }
7375         ut_params->op = op;
7376
7377         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7378
7379         ut_params->obuf = (op_mode == IN_PLACE ?
7380                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7381
7382         if (verify) {
7383                 if (ut_params->obuf)
7384                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7385                                                         uint8_t *);
7386                 else
7387                         plaintext = ciphertext +
7388                                         (tdata->cipher.offset_bits >> 3);
7389
7390                 debug_hexdump(stdout, "plaintext:", plaintext,
7391                                 tdata->plaintext.len_bits >> 3);
7392                 debug_hexdump(stdout, "plaintext expected:",
7393                                 tdata->plaintext.data,
7394                                 tdata->plaintext.len_bits >> 3);
7395         } else {
7396                 if (ut_params->obuf)
7397                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7398                                         uint8_t *);
7399                 else
7400                         ciphertext = plaintext;
7401
7402                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7403                                 ciphertext_len);
7404                 debug_hexdump(stdout, "ciphertext expected:",
7405                                 tdata->ciphertext.data,
7406                                 tdata->ciphertext.len_bits >> 3);
7407
7408                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7409                                 + (tdata->digest_enc.offset == 0 ?
7410                 plaintext_pad_len : tdata->digest_enc.offset);
7411
7412                 debug_hexdump(stdout, "digest:", ut_params->digest,
7413                                 tdata->digest_enc.len);
7414                 debug_hexdump(stdout, "digest expected:",
7415                                 tdata->digest_enc.data,
7416                                 tdata->digest_enc.len);
7417         }
7418
7419         /* Validate obuf */
7420         if (verify) {
7421                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7422                                 plaintext,
7423                                 tdata->plaintext.data,
7424                                 tdata->plaintext.len_bits >> 3,
7425                                 "Plaintext data not as expected");
7426         } else {
7427                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7428                                 ciphertext,
7429                                 tdata->ciphertext.data,
7430                                 tdata->validDataLen.len_bits,
7431                                 "Ciphertext data not as expected");
7432
7433                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7434                                 ut_params->digest,
7435                                 tdata->digest_enc.data,
7436                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7437                                 "Generated auth tag not as expected");
7438         }
7439
7440         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7441                         "crypto op processing failed");
7442
7443         return 0;
7444 }
7445
7446 static int
7447 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7448         uint8_t op_mode, uint8_t verify)
7449 {
7450         struct crypto_testsuite_params *ts_params = &testsuite_params;
7451         struct crypto_unittest_params *ut_params = &unittest_params;
7452
7453         int retval;
7454
7455         const uint8_t *plaintext = NULL;
7456         const uint8_t *ciphertext = NULL;
7457         const uint8_t *digest = NULL;
7458         unsigned int plaintext_pad_len;
7459         unsigned int plaintext_len;
7460         unsigned int ciphertext_pad_len;
7461         unsigned int ciphertext_len;
7462         uint8_t buffer[10000];
7463         uint8_t digest_buffer[10000];
7464
7465         struct rte_cryptodev_info dev_info;
7466         struct rte_crypto_op *op;
7467
7468         /* Check if device supports particular algorithms */
7469         if (test_mixed_check_if_unsupported(tdata))
7470                 return TEST_SKIPPED;
7471         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7472                 return TEST_SKIPPED;
7473
7474         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7475
7476         uint64_t feat_flags = dev_info.feature_flags;
7477
7478         if (op_mode == IN_PLACE) {
7479                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7480                         printf("Device doesn't support in-place scatter-gather "
7481                                         "in both input and output mbufs.\n");
7482                         return TEST_SKIPPED;
7483                 }
7484         } else {
7485                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7486                         printf("Device doesn't support out-of-place scatter-gather "
7487                                         "in both input and output mbufs.\n");
7488                         return TEST_SKIPPED;
7489                 }
7490                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7491                         printf("Device doesn't support digest encrypted.\n");
7492                         return TEST_SKIPPED;
7493                 }
7494         }
7495
7496         /* Create the session */
7497         if (verify)
7498                 retval = create_wireless_algo_cipher_auth_session(
7499                                 ts_params->valid_devs[0],
7500                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7501                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7502                                 tdata->auth_algo,
7503                                 tdata->cipher_algo,
7504                                 tdata->auth_key.data, tdata->auth_key.len,
7505                                 tdata->auth_iv.len, tdata->digest_enc.len,
7506                                 tdata->cipher_iv.len);
7507         else
7508                 retval = create_wireless_algo_auth_cipher_session(
7509                                 ts_params->valid_devs[0],
7510                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7511                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7512                                 tdata->auth_algo,
7513                                 tdata->cipher_algo,
7514                                 tdata->auth_key.data, tdata->auth_key.len,
7515                                 tdata->auth_iv.len, tdata->digest_enc.len,
7516                                 tdata->cipher_iv.len);
7517         if (retval != 0)
7518                 return retval;
7519
7520         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7521         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7522         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7523         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7524
7525         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7526                         ciphertext_pad_len, 15, 0);
7527         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7528                         "Failed to allocate input buffer in mempool");
7529
7530         if (op_mode == OUT_OF_PLACE) {
7531                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7532                                 plaintext_pad_len, 15, 0);
7533                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
7534                                 "Failed to allocate output buffer in mempool");
7535         }
7536
7537         if (verify) {
7538                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7539                         tdata->ciphertext.data);
7540                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7541                                         ciphertext_len, buffer);
7542                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7543                         ciphertext_len);
7544         } else {
7545                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7546                         tdata->plaintext.data);
7547                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7548                                         plaintext_len, buffer);
7549                 debug_hexdump(stdout, "plaintext:", plaintext,
7550                         plaintext_len);
7551         }
7552         memset(buffer, 0, sizeof(buffer));
7553
7554         /* Create the operation */
7555         retval = create_wireless_algo_auth_cipher_operation(
7556                         tdata->digest_enc.data, tdata->digest_enc.len,
7557                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7558                         tdata->auth_iv.data, tdata->auth_iv.len,
7559                         (tdata->digest_enc.offset == 0 ?
7560                                 plaintext_pad_len
7561                                 : tdata->digest_enc.offset),
7562                         tdata->validCipherLen.len_bits,
7563                         tdata->cipher.offset_bits,
7564                         tdata->validAuthLen.len_bits,
7565                         tdata->auth.offset_bits,
7566                         op_mode, 1, verify);
7567
7568         if (retval < 0)
7569                 return retval;
7570
7571         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7572
7573         /* Check if the op failed because the device doesn't */
7574         /* support this particular combination of algorithms */
7575         if (op == NULL && ut_params->op->status ==
7576                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7577                 printf("Device doesn't support this mixed combination. "
7578                                 "Test Skipped.\n");
7579                 return TEST_SKIPPED;
7580         }
7581         ut_params->op = op;
7582
7583         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7584
7585         ut_params->obuf = (op_mode == IN_PLACE ?
7586                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7587
7588         if (verify) {
7589                 if (ut_params->obuf)
7590                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7591                                         plaintext_len, buffer);
7592                 else
7593                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7594                                         plaintext_len, buffer);
7595
7596                 debug_hexdump(stdout, "plaintext:", plaintext,
7597                                 (tdata->plaintext.len_bits >> 3) -
7598                                 tdata->digest_enc.len);
7599                 debug_hexdump(stdout, "plaintext expected:",
7600                                 tdata->plaintext.data,
7601                                 (tdata->plaintext.len_bits >> 3) -
7602                                 tdata->digest_enc.len);
7603         } else {
7604                 if (ut_params->obuf)
7605                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7606                                         ciphertext_len, buffer);
7607                 else
7608                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7609                                         ciphertext_len, buffer);
7610
7611                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7612                         ciphertext_len);
7613                 debug_hexdump(stdout, "ciphertext expected:",
7614                         tdata->ciphertext.data,
7615                         tdata->ciphertext.len_bits >> 3);
7616
7617                 if (ut_params->obuf)
7618                         digest = rte_pktmbuf_read(ut_params->obuf,
7619                                         (tdata->digest_enc.offset == 0 ?
7620                                                 plaintext_pad_len :
7621                                                 tdata->digest_enc.offset),
7622                                         tdata->digest_enc.len, digest_buffer);
7623                 else
7624                         digest = rte_pktmbuf_read(ut_params->ibuf,
7625                                         (tdata->digest_enc.offset == 0 ?
7626                                                 plaintext_pad_len :
7627                                                 tdata->digest_enc.offset),
7628                                         tdata->digest_enc.len, digest_buffer);
7629
7630                 debug_hexdump(stdout, "digest:", digest,
7631                                 tdata->digest_enc.len);
7632                 debug_hexdump(stdout, "digest expected:",
7633                                 tdata->digest_enc.data, tdata->digest_enc.len);
7634         }
7635
7636         /* Validate obuf */
7637         if (verify) {
7638                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7639                                 plaintext,
7640                                 tdata->plaintext.data,
7641                                 tdata->plaintext.len_bits >> 3,
7642                                 "Plaintext data not as expected");
7643         } else {
7644                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7645                                 ciphertext,
7646                                 tdata->ciphertext.data,
7647                                 tdata->validDataLen.len_bits,
7648                                 "Ciphertext data not as expected");
7649                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7650                                 digest,
7651                                 tdata->digest_enc.data,
7652                                 tdata->digest_enc.len,
7653                                 "Generated auth tag not as expected");
7654         }
7655
7656         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7657                         "crypto op processing failed");
7658
7659         return 0;
7660 }
7661
7662 /** AUTH AES CMAC + CIPHER AES CTR */
7663
7664 static int
7665 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7666 {
7667         return test_mixed_auth_cipher(
7668                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7669 }
7670
7671 static int
7672 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7673 {
7674         return test_mixed_auth_cipher(
7675                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7676 }
7677
7678 static int
7679 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7680 {
7681         return test_mixed_auth_cipher_sgl(
7682                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7683 }
7684
7685 static int
7686 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7687 {
7688         return test_mixed_auth_cipher_sgl(
7689                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7690 }
7691
7692 static int
7693 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7694 {
7695         return test_mixed_auth_cipher(
7696                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7697 }
7698
7699 static int
7700 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7701 {
7702         return test_mixed_auth_cipher(
7703                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7704 }
7705
7706 static int
7707 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7708 {
7709         return test_mixed_auth_cipher_sgl(
7710                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7711 }
7712
7713 static int
7714 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7715 {
7716         return test_mixed_auth_cipher_sgl(
7717                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7718 }
7719
7720 /** MIXED AUTH + CIPHER */
7721
7722 static int
7723 test_auth_zuc_cipher_snow_test_case_1(void)
7724 {
7725         return test_mixed_auth_cipher(
7726                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7727 }
7728
7729 static int
7730 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7731 {
7732         return test_mixed_auth_cipher(
7733                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7734 }
7735
7736 static int
7737 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7738 {
7739         return test_mixed_auth_cipher(
7740                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7741 }
7742
7743 static int
7744 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7745 {
7746         return test_mixed_auth_cipher(
7747                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7748 }
7749
7750 static int
7751 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7752 {
7753         return test_mixed_auth_cipher(
7754                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7755 }
7756
7757 static int
7758 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7759 {
7760         return test_mixed_auth_cipher(
7761                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7762 }
7763
7764 static int
7765 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7766 {
7767         return test_mixed_auth_cipher(
7768                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7769 }
7770
7771 static int
7772 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7773 {
7774         return test_mixed_auth_cipher(
7775                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7776 }
7777
7778 static int
7779 test_auth_snow_cipher_zuc_test_case_1(void)
7780 {
7781         return test_mixed_auth_cipher(
7782                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7783 }
7784
7785 static int
7786 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7787 {
7788         return test_mixed_auth_cipher(
7789                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7790 }
7791
7792 static int
7793 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7794 {
7795         return test_mixed_auth_cipher(
7796                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7797 }
7798
7799 static int
7800 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7801 {
7802         return test_mixed_auth_cipher(
7803                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7804 }
7805
7806 static int
7807 test_auth_null_cipher_snow_test_case_1(void)
7808 {
7809         return test_mixed_auth_cipher(
7810                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7811 }
7812
7813 static int
7814 test_verify_auth_null_cipher_snow_test_case_1(void)
7815 {
7816         return test_mixed_auth_cipher(
7817                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7818 }
7819
7820 static int
7821 test_auth_null_cipher_zuc_test_case_1(void)
7822 {
7823         return test_mixed_auth_cipher(
7824                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7825 }
7826
7827 static int
7828 test_verify_auth_null_cipher_zuc_test_case_1(void)
7829 {
7830         return test_mixed_auth_cipher(
7831                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7832 }
7833
7834 static int
7835 test_auth_snow_cipher_null_test_case_1(void)
7836 {
7837         return test_mixed_auth_cipher(
7838                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7839 }
7840
7841 static int
7842 test_verify_auth_snow_cipher_null_test_case_1(void)
7843 {
7844         return test_mixed_auth_cipher(
7845                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7846 }
7847
7848 static int
7849 test_auth_zuc_cipher_null_test_case_1(void)
7850 {
7851         return test_mixed_auth_cipher(
7852                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7853 }
7854
7855 static int
7856 test_verify_auth_zuc_cipher_null_test_case_1(void)
7857 {
7858         return test_mixed_auth_cipher(
7859                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7860 }
7861
7862 static int
7863 test_auth_null_cipher_aes_ctr_test_case_1(void)
7864 {
7865         return test_mixed_auth_cipher(
7866                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7867 }
7868
7869 static int
7870 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7871 {
7872         return test_mixed_auth_cipher(
7873                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7874 }
7875
7876 static int
7877 test_auth_aes_cmac_cipher_null_test_case_1(void)
7878 {
7879         return test_mixed_auth_cipher(
7880                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7881 }
7882
7883 static int
7884 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7885 {
7886         return test_mixed_auth_cipher(
7887                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7888 }
7889
7890 /* ***** AEAD algorithm Tests ***** */
7891
7892 static int
7893 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7894                 enum rte_crypto_aead_operation op,
7895                 const uint8_t *key, const uint8_t key_len,
7896                 const uint16_t aad_len, const uint8_t auth_len,
7897                 uint8_t iv_len)
7898 {
7899         uint8_t aead_key[key_len];
7900
7901         struct crypto_testsuite_params *ts_params = &testsuite_params;
7902         struct crypto_unittest_params *ut_params = &unittest_params;
7903
7904         memcpy(aead_key, key, key_len);
7905
7906         /* Setup AEAD Parameters */
7907         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7908         ut_params->aead_xform.next = NULL;
7909         ut_params->aead_xform.aead.algo = algo;
7910         ut_params->aead_xform.aead.op = op;
7911         ut_params->aead_xform.aead.key.data = aead_key;
7912         ut_params->aead_xform.aead.key.length = key_len;
7913         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7914         ut_params->aead_xform.aead.iv.length = iv_len;
7915         ut_params->aead_xform.aead.digest_length = auth_len;
7916         ut_params->aead_xform.aead.aad_length = aad_len;
7917
7918         debug_hexdump(stdout, "key:", key, key_len);
7919
7920         /* Create Crypto session*/
7921         ut_params->sess = rte_cryptodev_sym_session_create(
7922                         ts_params->session_mpool);
7923
7924         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7925                         &ut_params->aead_xform,
7926                         ts_params->session_priv_mpool);
7927
7928         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7929
7930         return 0;
7931 }
7932
7933 static int
7934 create_aead_xform(struct rte_crypto_op *op,
7935                 enum rte_crypto_aead_algorithm algo,
7936                 enum rte_crypto_aead_operation aead_op,
7937                 uint8_t *key, const uint8_t key_len,
7938                 const uint8_t aad_len, const uint8_t auth_len,
7939                 uint8_t iv_len)
7940 {
7941         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7942                         "failed to allocate space for crypto transform");
7943
7944         struct rte_crypto_sym_op *sym_op = op->sym;
7945
7946         /* Setup AEAD Parameters */
7947         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7948         sym_op->xform->next = NULL;
7949         sym_op->xform->aead.algo = algo;
7950         sym_op->xform->aead.op = aead_op;
7951         sym_op->xform->aead.key.data = key;
7952         sym_op->xform->aead.key.length = key_len;
7953         sym_op->xform->aead.iv.offset = IV_OFFSET;
7954         sym_op->xform->aead.iv.length = iv_len;
7955         sym_op->xform->aead.digest_length = auth_len;
7956         sym_op->xform->aead.aad_length = aad_len;
7957
7958         debug_hexdump(stdout, "key:", key, key_len);
7959
7960         return 0;
7961 }
7962
7963 static int
7964 create_aead_operation(enum rte_crypto_aead_operation op,
7965                 const struct aead_test_data *tdata)
7966 {
7967         struct crypto_testsuite_params *ts_params = &testsuite_params;
7968         struct crypto_unittest_params *ut_params = &unittest_params;
7969
7970         uint8_t *plaintext, *ciphertext;
7971         unsigned int aad_pad_len, plaintext_pad_len;
7972
7973         /* Generate Crypto op data structure */
7974         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7975                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7976         TEST_ASSERT_NOT_NULL(ut_params->op,
7977                         "Failed to allocate symmetric crypto operation struct");
7978
7979         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7980
7981         /* Append aad data */
7982         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7983                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7984                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7985                                 aad_pad_len);
7986                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7987                                 "no room to append aad");
7988
7989                 sym_op->aead.aad.phys_addr =
7990                                 rte_pktmbuf_iova(ut_params->ibuf);
7991                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
7992                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7993                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7994                         tdata->aad.len);
7995
7996                 /* Append IV at the end of the crypto operation*/
7997                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7998                                 uint8_t *, IV_OFFSET);
7999
8000                 /* Copy IV 1 byte after the IV pointer, according to the API */
8001                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
8002                 debug_hexdump(stdout, "iv:", iv_ptr,
8003                         tdata->iv.len);
8004         } else {
8005                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
8006                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8007                                 aad_pad_len);
8008                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8009                                 "no room to append aad");
8010
8011                 sym_op->aead.aad.phys_addr =
8012                                 rte_pktmbuf_iova(ut_params->ibuf);
8013                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
8014                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
8015                         tdata->aad.len);
8016
8017                 /* Append IV at the end of the crypto operation*/
8018                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8019                                 uint8_t *, IV_OFFSET);
8020
8021                 if (tdata->iv.len == 0) {
8022                         rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
8023                         debug_hexdump(stdout, "iv:", iv_ptr,
8024                                 AES_GCM_J0_LENGTH);
8025                 } else {
8026                         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
8027                         debug_hexdump(stdout, "iv:", iv_ptr,
8028                                 tdata->iv.len);
8029                 }
8030         }
8031
8032         /* Append plaintext/ciphertext */
8033         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8034                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8035                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8036                                 plaintext_pad_len);
8037                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
8038
8039                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
8040                 debug_hexdump(stdout, "plaintext:", plaintext,
8041                                 tdata->plaintext.len);
8042
8043                 if (ut_params->obuf) {
8044                         ciphertext = (uint8_t *)rte_pktmbuf_append(
8045                                         ut_params->obuf,
8046                                         plaintext_pad_len + aad_pad_len);
8047                         TEST_ASSERT_NOT_NULL(ciphertext,
8048                                         "no room to append ciphertext");
8049
8050                         memset(ciphertext + aad_pad_len, 0,
8051                                         tdata->ciphertext.len);
8052                 }
8053         } else {
8054                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
8055                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8056                                 plaintext_pad_len);
8057                 TEST_ASSERT_NOT_NULL(ciphertext,
8058                                 "no room to append ciphertext");
8059
8060                 memcpy(ciphertext, tdata->ciphertext.data,
8061                                 tdata->ciphertext.len);
8062                 debug_hexdump(stdout, "ciphertext:", ciphertext,
8063                                 tdata->ciphertext.len);
8064
8065                 if (ut_params->obuf) {
8066                         plaintext = (uint8_t *)rte_pktmbuf_append(
8067                                         ut_params->obuf,
8068                                         plaintext_pad_len + aad_pad_len);
8069                         TEST_ASSERT_NOT_NULL(plaintext,
8070                                         "no room to append plaintext");
8071
8072                         memset(plaintext + aad_pad_len, 0,
8073                                         tdata->plaintext.len);
8074                 }
8075         }
8076
8077         /* Append digest data */
8078         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8079                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8080                                 ut_params->obuf ? ut_params->obuf :
8081                                                 ut_params->ibuf,
8082                                                 tdata->auth_tag.len);
8083                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8084                                 "no room to append digest");
8085                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
8086                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8087                                 ut_params->obuf ? ut_params->obuf :
8088                                                 ut_params->ibuf,
8089                                                 plaintext_pad_len +
8090                                                 aad_pad_len);
8091         } else {
8092                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8093                                 ut_params->ibuf, tdata->auth_tag.len);
8094                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8095                                 "no room to append digest");
8096                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8097                                 ut_params->ibuf,
8098                                 plaintext_pad_len + aad_pad_len);
8099
8100                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8101                         tdata->auth_tag.len);
8102                 debug_hexdump(stdout, "digest:",
8103                         sym_op->aead.digest.data,
8104                         tdata->auth_tag.len);
8105         }
8106
8107         sym_op->aead.data.length = tdata->plaintext.len;
8108         sym_op->aead.data.offset = aad_pad_len;
8109
8110         return 0;
8111 }
8112
8113 static int
8114 test_authenticated_encryption(const struct aead_test_data *tdata)
8115 {
8116         struct crypto_testsuite_params *ts_params = &testsuite_params;
8117         struct crypto_unittest_params *ut_params = &unittest_params;
8118
8119         int retval;
8120         uint8_t *ciphertext, *auth_tag;
8121         uint16_t plaintext_pad_len;
8122         uint32_t i;
8123         struct rte_cryptodev_info dev_info;
8124
8125         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8126         uint64_t feat_flags = dev_info.feature_flags;
8127
8128         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8129                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8130                 printf("Device doesn't support RAW data-path APIs.\n");
8131                 return TEST_SKIPPED;
8132         }
8133
8134         /* Verify the capabilities */
8135         struct rte_cryptodev_sym_capability_idx cap_idx;
8136         const struct rte_cryptodev_symmetric_capability *capability;
8137         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8138         cap_idx.algo.aead = tdata->algo;
8139         capability = rte_cryptodev_sym_capability_get(
8140                         ts_params->valid_devs[0], &cap_idx);
8141         if (capability == NULL)
8142                 return TEST_SKIPPED;
8143         if (rte_cryptodev_sym_capability_check_aead(
8144                         capability, tdata->key.len, tdata->auth_tag.len,
8145                         tdata->aad.len, tdata->iv.len))
8146                 return TEST_SKIPPED;
8147
8148         /* Create AEAD session */
8149         retval = create_aead_session(ts_params->valid_devs[0],
8150                         tdata->algo,
8151                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8152                         tdata->key.data, tdata->key.len,
8153                         tdata->aad.len, tdata->auth_tag.len,
8154                         tdata->iv.len);
8155         if (retval < 0)
8156                 return retval;
8157
8158         if (tdata->aad.len > MBUF_SIZE) {
8159                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8160                 /* Populate full size of add data */
8161                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8162                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8163         } else
8164                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8165
8166         /* clear mbuf payload */
8167         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8168                         rte_pktmbuf_tailroom(ut_params->ibuf));
8169
8170         /* Create AEAD operation */
8171         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8172         if (retval < 0)
8173                 return retval;
8174
8175         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8176
8177         ut_params->op->sym->m_src = ut_params->ibuf;
8178
8179         /* Process crypto operation */
8180         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8181                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8182         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8183                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8184                                 ut_params->op, 0, 0, 0, 0);
8185         else
8186                 TEST_ASSERT_NOT_NULL(
8187                         process_crypto_request(ts_params->valid_devs[0],
8188                         ut_params->op), "failed to process sym crypto op");
8189
8190         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8191                         "crypto op processing failed");
8192
8193         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8194
8195         if (ut_params->op->sym->m_dst) {
8196                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8197                                 uint8_t *);
8198                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8199                                 uint8_t *, plaintext_pad_len);
8200         } else {
8201                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8202                                 uint8_t *,
8203                                 ut_params->op->sym->cipher.data.offset);
8204                 auth_tag = ciphertext + plaintext_pad_len;
8205         }
8206
8207         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8208         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8209
8210         /* Validate obuf */
8211         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8212                         ciphertext,
8213                         tdata->ciphertext.data,
8214                         tdata->ciphertext.len,
8215                         "Ciphertext data not as expected");
8216
8217         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8218                         auth_tag,
8219                         tdata->auth_tag.data,
8220                         tdata->auth_tag.len,
8221                         "Generated auth tag not as expected");
8222
8223         return 0;
8224
8225 }
8226
8227 #ifdef RTE_LIB_SECURITY
8228 static int
8229 security_proto_supported(enum rte_security_session_action_type action,
8230         enum rte_security_session_protocol proto)
8231 {
8232         struct crypto_testsuite_params *ts_params = &testsuite_params;
8233
8234         const struct rte_security_capability *capabilities;
8235         const struct rte_security_capability *capability;
8236         uint16_t i = 0;
8237
8238         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8239                                 rte_cryptodev_get_sec_ctx(
8240                                 ts_params->valid_devs[0]);
8241
8242
8243         capabilities = rte_security_capabilities_get(ctx);
8244
8245         if (capabilities == NULL)
8246                 return -ENOTSUP;
8247
8248         while ((capability = &capabilities[i++])->action !=
8249                         RTE_SECURITY_ACTION_TYPE_NONE) {
8250                 if (capability->action == action &&
8251                                 capability->protocol == proto)
8252                         return 0;
8253         }
8254
8255         return -ENOTSUP;
8256 }
8257
8258 /* Basic algorithm run function for async inplace mode.
8259  * Creates a session from input parameters and runs one operation
8260  * on input_vec. Checks the output of the crypto operation against
8261  * output_vec.
8262  */
8263 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8264                            enum rte_crypto_auth_operation opa,
8265                            const uint8_t *input_vec, unsigned int input_vec_len,
8266                            const uint8_t *output_vec,
8267                            unsigned int output_vec_len,
8268                            enum rte_crypto_cipher_algorithm cipher_alg,
8269                            const uint8_t *cipher_key, uint32_t cipher_key_len,
8270                            enum rte_crypto_auth_algorithm auth_alg,
8271                            const uint8_t *auth_key, uint32_t auth_key_len,
8272                            uint8_t bearer, enum rte_security_pdcp_domain domain,
8273                            uint8_t packet_direction, uint8_t sn_size,
8274                            uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8275 {
8276         struct crypto_testsuite_params *ts_params = &testsuite_params;
8277         struct crypto_unittest_params *ut_params = &unittest_params;
8278         uint8_t *plaintext;
8279         int ret = TEST_SUCCESS;
8280         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8281                                 rte_cryptodev_get_sec_ctx(
8282                                 ts_params->valid_devs[0]);
8283
8284         /* Verify the capabilities */
8285         struct rte_security_capability_idx sec_cap_idx;
8286
8287         sec_cap_idx.action = ut_params->type;
8288         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8289         sec_cap_idx.pdcp.domain = domain;
8290         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8291                 return TEST_SKIPPED;
8292
8293         /* Generate test mbuf data */
8294         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8295
8296         /* clear mbuf payload */
8297         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8298                         rte_pktmbuf_tailroom(ut_params->ibuf));
8299
8300         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8301                                                   input_vec_len);
8302         memcpy(plaintext, input_vec, input_vec_len);
8303
8304         /* Out of place support */
8305         if (oop) {
8306                 /*
8307                  * For out-op-place we need to alloc another mbuf
8308                  */
8309                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8310                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8311         }
8312
8313         /* Setup Cipher Parameters */
8314         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8315         ut_params->cipher_xform.cipher.algo = cipher_alg;
8316         ut_params->cipher_xform.cipher.op = opc;
8317         ut_params->cipher_xform.cipher.key.data = cipher_key;
8318         ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8319         ut_params->cipher_xform.cipher.iv.length =
8320                                 packet_direction ? 4 : 0;
8321         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8322
8323         /* Setup HMAC Parameters if ICV header is required */
8324         if (auth_alg != 0) {
8325                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8326                 ut_params->auth_xform.next = NULL;
8327                 ut_params->auth_xform.auth.algo = auth_alg;
8328                 ut_params->auth_xform.auth.op = opa;
8329                 ut_params->auth_xform.auth.key.data = auth_key;
8330                 ut_params->auth_xform.auth.key.length = auth_key_len;
8331
8332                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8333         } else {
8334                 ut_params->cipher_xform.next = NULL;
8335         }
8336
8337         struct rte_security_session_conf sess_conf = {
8338                 .action_type = ut_params->type,
8339                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8340                 {.pdcp = {
8341                         .bearer = bearer,
8342                         .domain = domain,
8343                         .pkt_dir = packet_direction,
8344                         .sn_size = sn_size,
8345                         .hfn = packet_direction ? 0 : hfn,
8346                         /**
8347                          * hfn can be set as pdcp_test_hfn[i]
8348                          * if hfn_ovrd is not set. Here, PDCP
8349                          * packet direction is just used to
8350                          * run half of the cases with session
8351                          * HFN and other half with per packet
8352                          * HFN.
8353                          */
8354                         .hfn_threshold = hfn_threshold,
8355                         .hfn_ovrd = packet_direction ? 1 : 0,
8356                         .sdap_enabled = sdap,
8357                 } },
8358                 .crypto_xform = &ut_params->cipher_xform
8359         };
8360
8361         /* Create security session */
8362         ut_params->sec_session = rte_security_session_create(ctx,
8363                                 &sess_conf, ts_params->session_mpool,
8364                                 ts_params->session_priv_mpool);
8365
8366         if (!ut_params->sec_session) {
8367                 printf("TestCase %s()-%d line %d failed %s: ",
8368                         __func__, i, __LINE__, "Failed to allocate session");
8369                 ret = TEST_FAILED;
8370                 goto on_err;
8371         }
8372
8373         /* Generate crypto op data structure */
8374         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8375                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8376         if (!ut_params->op) {
8377                 printf("TestCase %s()-%d line %d failed %s: ",
8378                         __func__, i, __LINE__,
8379                         "Failed to allocate symmetric crypto operation struct");
8380                 ret = TEST_FAILED;
8381                 goto on_err;
8382         }
8383
8384         uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8385                                         uint32_t *, IV_OFFSET);
8386         *per_pkt_hfn = packet_direction ? hfn : 0;
8387
8388         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8389
8390         /* set crypto operation source mbuf */
8391         ut_params->op->sym->m_src = ut_params->ibuf;
8392         if (oop)
8393                 ut_params->op->sym->m_dst = ut_params->obuf;
8394
8395         /* Process crypto operation */
8396         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8397                 == NULL) {
8398                 printf("TestCase %s()-%d line %d failed %s: ",
8399                         __func__, i, __LINE__,
8400                         "failed to process sym crypto op");
8401                 ret = TEST_FAILED;
8402                 goto on_err;
8403         }
8404
8405         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8406                 printf("TestCase %s()-%d line %d failed %s: ",
8407                         __func__, i, __LINE__, "crypto op processing failed");
8408                 ret = TEST_FAILED;
8409                 goto on_err;
8410         }
8411
8412         /* Validate obuf */
8413         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8414                         uint8_t *);
8415         if (oop) {
8416                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8417                                 uint8_t *);
8418         }
8419
8420         if (memcmp(ciphertext, output_vec, output_vec_len)) {
8421                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8422                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8423                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8424                 ret = TEST_FAILED;
8425                 goto on_err;
8426         }
8427
8428 on_err:
8429         rte_crypto_op_free(ut_params->op);
8430         ut_params->op = NULL;
8431
8432         if (ut_params->sec_session)
8433                 rte_security_session_destroy(ctx, ut_params->sec_session);
8434         ut_params->sec_session = NULL;
8435
8436         rte_pktmbuf_free(ut_params->ibuf);
8437         ut_params->ibuf = NULL;
8438         if (oop) {
8439                 rte_pktmbuf_free(ut_params->obuf);
8440                 ut_params->obuf = NULL;
8441         }
8442
8443         return ret;
8444 }
8445
8446 static int
8447 test_pdcp_proto_SGL(int i, int oop,
8448         enum rte_crypto_cipher_operation opc,
8449         enum rte_crypto_auth_operation opa,
8450         uint8_t *input_vec,
8451         unsigned int input_vec_len,
8452         uint8_t *output_vec,
8453         unsigned int output_vec_len,
8454         uint32_t fragsz,
8455         uint32_t fragsz_oop)
8456 {
8457         struct crypto_testsuite_params *ts_params = &testsuite_params;
8458         struct crypto_unittest_params *ut_params = &unittest_params;
8459         uint8_t *plaintext;
8460         struct rte_mbuf *buf, *buf_oop = NULL;
8461         int ret = TEST_SUCCESS;
8462         int to_trn = 0;
8463         int to_trn_tbl[16];
8464         int segs = 1;
8465         unsigned int trn_data = 0;
8466         struct rte_cryptodev_info dev_info;
8467         uint64_t feat_flags;
8468         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8469                                 rte_cryptodev_get_sec_ctx(
8470                                 ts_params->valid_devs[0]);
8471         struct rte_mbuf *temp_mbuf;
8472
8473         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8474         feat_flags = dev_info.feature_flags;
8475
8476         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8477                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8478                 printf("Device does not support RAW data-path APIs.\n");
8479                 return -ENOTSUP;
8480         }
8481         /* Verify the capabilities */
8482         struct rte_security_capability_idx sec_cap_idx;
8483
8484         sec_cap_idx.action = ut_params->type;
8485         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8486         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8487         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8488                 return TEST_SKIPPED;
8489
8490         if (fragsz > input_vec_len)
8491                 fragsz = input_vec_len;
8492
8493         uint16_t plaintext_len = fragsz;
8494         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8495
8496         if (fragsz_oop > output_vec_len)
8497                 frag_size_oop = output_vec_len;
8498
8499         int ecx = 0;
8500         if (input_vec_len % fragsz != 0) {
8501                 if (input_vec_len / fragsz + 1 > 16)
8502                         return 1;
8503         } else if (input_vec_len / fragsz > 16)
8504                 return 1;
8505
8506         /* Out of place support */
8507         if (oop) {
8508                 /*
8509                  * For out-op-place we need to alloc another mbuf
8510                  */
8511                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8512                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8513                 buf_oop = ut_params->obuf;
8514         }
8515
8516         /* Generate test mbuf data */
8517         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8518
8519         /* clear mbuf payload */
8520         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8521                         rte_pktmbuf_tailroom(ut_params->ibuf));
8522
8523         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8524                                                   plaintext_len);
8525         memcpy(plaintext, input_vec, plaintext_len);
8526         trn_data += plaintext_len;
8527
8528         buf = ut_params->ibuf;
8529
8530         /*
8531          * Loop until no more fragments
8532          */
8533
8534         while (trn_data < input_vec_len) {
8535                 ++segs;
8536                 to_trn = (input_vec_len - trn_data < fragsz) ?
8537                                 (input_vec_len - trn_data) : fragsz;
8538
8539                 to_trn_tbl[ecx++] = to_trn;
8540
8541                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8542                 buf = buf->next;
8543
8544                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8545                                 rte_pktmbuf_tailroom(buf));
8546
8547                 /* OOP */
8548                 if (oop && !fragsz_oop) {
8549                         buf_oop->next =
8550                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8551                         buf_oop = buf_oop->next;
8552                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8553                                         0, rte_pktmbuf_tailroom(buf_oop));
8554                         rte_pktmbuf_append(buf_oop, to_trn);
8555                 }
8556
8557                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8558                                 to_trn);
8559
8560                 memcpy(plaintext, input_vec + trn_data, to_trn);
8561                 trn_data += to_trn;
8562         }
8563
8564         ut_params->ibuf->nb_segs = segs;
8565
8566         segs = 1;
8567         if (fragsz_oop && oop) {
8568                 to_trn = 0;
8569                 ecx = 0;
8570
8571                 trn_data = frag_size_oop;
8572                 while (trn_data < output_vec_len) {
8573                         ++segs;
8574                         to_trn =
8575                                 (output_vec_len - trn_data <
8576                                                 frag_size_oop) ?
8577                                 (output_vec_len - trn_data) :
8578                                                 frag_size_oop;
8579
8580                         to_trn_tbl[ecx++] = to_trn;
8581
8582                         buf_oop->next =
8583                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
8584                         buf_oop = buf_oop->next;
8585                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8586                                         0, rte_pktmbuf_tailroom(buf_oop));
8587                         rte_pktmbuf_append(buf_oop, to_trn);
8588
8589                         trn_data += to_trn;
8590                 }
8591                 ut_params->obuf->nb_segs = segs;
8592         }
8593
8594         /* Setup Cipher Parameters */
8595         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8596         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8597         ut_params->cipher_xform.cipher.op = opc;
8598         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8599         ut_params->cipher_xform.cipher.key.length =
8600                                         pdcp_test_params[i].cipher_key_len;
8601         ut_params->cipher_xform.cipher.iv.length = 0;
8602
8603         /* Setup HMAC Parameters if ICV header is required */
8604         if (pdcp_test_params[i].auth_alg != 0) {
8605                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8606                 ut_params->auth_xform.next = NULL;
8607                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8608                 ut_params->auth_xform.auth.op = opa;
8609                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8610                 ut_params->auth_xform.auth.key.length =
8611                                         pdcp_test_params[i].auth_key_len;
8612
8613                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8614         } else {
8615                 ut_params->cipher_xform.next = NULL;
8616         }
8617
8618         struct rte_security_session_conf sess_conf = {
8619                 .action_type = ut_params->type,
8620                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8621                 {.pdcp = {
8622                         .bearer = pdcp_test_bearer[i],
8623                         .domain = pdcp_test_params[i].domain,
8624                         .pkt_dir = pdcp_test_packet_direction[i],
8625                         .sn_size = pdcp_test_data_sn_size[i],
8626                         .hfn = pdcp_test_hfn[i],
8627                         .hfn_threshold = pdcp_test_hfn_threshold[i],
8628                         .hfn_ovrd = 0,
8629                 } },
8630                 .crypto_xform = &ut_params->cipher_xform
8631         };
8632
8633         /* Create security session */
8634         ut_params->sec_session = rte_security_session_create(ctx,
8635                                 &sess_conf, ts_params->session_mpool,
8636                                 ts_params->session_priv_mpool);
8637
8638         if (!ut_params->sec_session) {
8639                 printf("TestCase %s()-%d line %d failed %s: ",
8640                         __func__, i, __LINE__, "Failed to allocate session");
8641                 ret = TEST_FAILED;
8642                 goto on_err;
8643         }
8644
8645         /* Generate crypto op data structure */
8646         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8647                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8648         if (!ut_params->op) {
8649                 printf("TestCase %s()-%d line %d failed %s: ",
8650                         __func__, i, __LINE__,
8651                         "Failed to allocate symmetric crypto operation struct");
8652                 ret = TEST_FAILED;
8653                 goto on_err;
8654         }
8655
8656         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8657
8658         /* set crypto operation source mbuf */
8659         ut_params->op->sym->m_src = ut_params->ibuf;
8660         if (oop)
8661                 ut_params->op->sym->m_dst = ut_params->obuf;
8662
8663         /* Process crypto operation */
8664         temp_mbuf = ut_params->op->sym->m_src;
8665         if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
8666                 /* filling lengths */
8667                 while (temp_mbuf) {
8668                         ut_params->op->sym->cipher.data.length
8669                                 += temp_mbuf->pkt_len;
8670                         ut_params->op->sym->auth.data.length
8671                                 += temp_mbuf->pkt_len;
8672                         temp_mbuf = temp_mbuf->next;
8673                 }
8674                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8675                         ut_params->op, 1, 1, 0, 0);
8676         } else {
8677                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8678                                                         ut_params->op);
8679         }
8680         if (ut_params->op == NULL) {
8681                 printf("TestCase %s()-%d line %d failed %s: ",
8682                         __func__, i, __LINE__,
8683                         "failed to process sym crypto op");
8684                 ret = TEST_FAILED;
8685                 goto on_err;
8686         }
8687
8688         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8689                 printf("TestCase %s()-%d line %d failed %s: ",
8690                         __func__, i, __LINE__, "crypto op processing failed");
8691                 ret = TEST_FAILED;
8692                 goto on_err;
8693         }
8694
8695         /* Validate obuf */
8696         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8697                         uint8_t *);
8698         if (oop) {
8699                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8700                                 uint8_t *);
8701         }
8702         if (fragsz_oop)
8703                 fragsz = frag_size_oop;
8704         if (memcmp(ciphertext, output_vec, fragsz)) {
8705                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8706                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8707                 rte_hexdump(stdout, "reference", output_vec, fragsz);
8708                 ret = TEST_FAILED;
8709                 goto on_err;
8710         }
8711
8712         buf = ut_params->op->sym->m_src->next;
8713         if (oop)
8714                 buf = ut_params->op->sym->m_dst->next;
8715
8716         unsigned int off = fragsz;
8717
8718         ecx = 0;
8719         while (buf) {
8720                 ciphertext = rte_pktmbuf_mtod(buf,
8721                                 uint8_t *);
8722                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8723                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8724                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8725                         rte_hexdump(stdout, "reference", output_vec + off,
8726                                         to_trn_tbl[ecx]);
8727                         ret = TEST_FAILED;
8728                         goto on_err;
8729                 }
8730                 off += to_trn_tbl[ecx++];
8731                 buf = buf->next;
8732         }
8733 on_err:
8734         rte_crypto_op_free(ut_params->op);
8735         ut_params->op = NULL;
8736
8737         if (ut_params->sec_session)
8738                 rte_security_session_destroy(ctx, ut_params->sec_session);
8739         ut_params->sec_session = NULL;
8740
8741         rte_pktmbuf_free(ut_params->ibuf);
8742         ut_params->ibuf = NULL;
8743         if (oop) {
8744                 rte_pktmbuf_free(ut_params->obuf);
8745                 ut_params->obuf = NULL;
8746         }
8747
8748         return ret;
8749 }
8750
8751 int
8752 test_pdcp_proto_cplane_encap(int i)
8753 {
8754         return test_pdcp_proto(
8755                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8756                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8757                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8758                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8759                 pdcp_test_params[i].cipher_key_len,
8760                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8761                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8762                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8763                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8764                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8765 }
8766
8767 int
8768 test_pdcp_proto_uplane_encap(int i)
8769 {
8770         return test_pdcp_proto(
8771                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8772                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8773                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8774                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8775                 pdcp_test_params[i].cipher_key_len,
8776                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8777                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8778                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8779                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8780                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8781 }
8782
8783 int
8784 test_pdcp_proto_uplane_encap_with_int(int i)
8785 {
8786         return test_pdcp_proto(
8787                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8788                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8789                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8790                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8791                 pdcp_test_params[i].cipher_key_len,
8792                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8793                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8794                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8795                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8796                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8797 }
8798
8799 int
8800 test_pdcp_proto_cplane_decap(int i)
8801 {
8802         return test_pdcp_proto(
8803                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8804                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8805                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8806                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8807                 pdcp_test_params[i].cipher_key_len,
8808                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8809                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8810                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8811                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8812                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8813 }
8814
8815 int
8816 test_pdcp_proto_uplane_decap(int i)
8817 {
8818         return test_pdcp_proto(
8819                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8820                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8821                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8822                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8823                 pdcp_test_params[i].cipher_key_len,
8824                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8825                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8826                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8827                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8828                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8829 }
8830
8831 int
8832 test_pdcp_proto_uplane_decap_with_int(int i)
8833 {
8834         return test_pdcp_proto(
8835                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8836                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8837                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8838                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8839                 pdcp_test_params[i].cipher_key_len,
8840                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8841                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8842                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8843                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8844                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8845 }
8846
8847 static int
8848 test_PDCP_PROTO_SGL_in_place_32B(void)
8849 {
8850         /* i can be used for running any PDCP case
8851          * In this case it is uplane 12-bit AES-SNOW DL encap
8852          */
8853         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8854         return test_pdcp_proto_SGL(i, IN_PLACE,
8855                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8856                         RTE_CRYPTO_AUTH_OP_GENERATE,
8857                         pdcp_test_data_in[i],
8858                         pdcp_test_data_in_len[i],
8859                         pdcp_test_data_out[i],
8860                         pdcp_test_data_in_len[i]+4,
8861                         32, 0);
8862 }
8863 static int
8864 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8865 {
8866         /* i can be used for running any PDCP case
8867          * In this case it is uplane 18-bit NULL-NULL DL encap
8868          */
8869         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8870         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8871                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8872                         RTE_CRYPTO_AUTH_OP_GENERATE,
8873                         pdcp_test_data_in[i],
8874                         pdcp_test_data_in_len[i],
8875                         pdcp_test_data_out[i],
8876                         pdcp_test_data_in_len[i]+4,
8877                         32, 128);
8878 }
8879 static int
8880 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8881 {
8882         /* i can be used for running any PDCP case
8883          * In this case it is uplane 18-bit AES DL encap
8884          */
8885         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8886                         + DOWNLINK;
8887         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8888                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8889                         RTE_CRYPTO_AUTH_OP_GENERATE,
8890                         pdcp_test_data_in[i],
8891                         pdcp_test_data_in_len[i],
8892                         pdcp_test_data_out[i],
8893                         pdcp_test_data_in_len[i],
8894                         32, 40);
8895 }
8896 static int
8897 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8898 {
8899         /* i can be used for running any PDCP case
8900          * In this case it is cplane 12-bit AES-ZUC DL encap
8901          */
8902         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8903         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8904                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8905                         RTE_CRYPTO_AUTH_OP_GENERATE,
8906                         pdcp_test_data_in[i],
8907                         pdcp_test_data_in_len[i],
8908                         pdcp_test_data_out[i],
8909                         pdcp_test_data_in_len[i]+4,
8910                         128, 32);
8911 }
8912
8913 static int
8914 test_PDCP_SDAP_PROTO_encap_all(void)
8915 {
8916         int i = 0, size = 0;
8917         int err, all_err = TEST_SUCCESS;
8918         const struct pdcp_sdap_test *cur_test;
8919
8920         size = RTE_DIM(list_pdcp_sdap_tests);
8921
8922         for (i = 0; i < size; i++) {
8923                 cur_test = &list_pdcp_sdap_tests[i];
8924                 err = test_pdcp_proto(
8925                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8926                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8927                         cur_test->in_len, cur_test->data_out,
8928                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8929                         cur_test->param.cipher_alg, cur_test->cipher_key,
8930                         cur_test->param.cipher_key_len,
8931                         cur_test->param.auth_alg,
8932                         cur_test->auth_key, cur_test->param.auth_key_len,
8933                         cur_test->bearer, cur_test->param.domain,
8934                         cur_test->packet_direction, cur_test->sn_size,
8935                         cur_test->hfn,
8936                         cur_test->hfn_threshold, SDAP_ENABLED);
8937                 if (err) {
8938                         printf("\t%d) %s: Encapsulation failed\n",
8939                                         cur_test->test_idx,
8940                                         cur_test->param.name);
8941                         err = TEST_FAILED;
8942                 } else {
8943                         printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8944                                         cur_test->param.name);
8945                         err = TEST_SUCCESS;
8946                 }
8947                 all_err += err;
8948         }
8949
8950         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8951
8952         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8953 }
8954
8955 static int
8956 test_PDCP_PROTO_short_mac(void)
8957 {
8958         int i = 0, size = 0;
8959         int err, all_err = TEST_SUCCESS;
8960         const struct pdcp_short_mac_test *cur_test;
8961
8962         size = RTE_DIM(list_pdcp_smac_tests);
8963
8964         for (i = 0; i < size; i++) {
8965                 cur_test = &list_pdcp_smac_tests[i];
8966                 err = test_pdcp_proto(
8967                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8968                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8969                         cur_test->in_len, cur_test->data_out,
8970                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8971                         RTE_CRYPTO_CIPHER_NULL, NULL,
8972                         0, cur_test->param.auth_alg,
8973                         cur_test->auth_key, cur_test->param.auth_key_len,
8974                         0, cur_test->param.domain, 0, 0,
8975                         0, 0, 0);
8976                 if (err) {
8977                         printf("\t%d) %s: Short MAC test failed\n",
8978                                         cur_test->test_idx,
8979                                         cur_test->param.name);
8980                         err = TEST_FAILED;
8981                 } else {
8982                         printf("\t%d) %s: Short MAC test PASS\n",
8983                                         cur_test->test_idx,
8984                                         cur_test->param.name);
8985                         rte_hexdump(stdout, "MAC I",
8986                                     cur_test->data_out + cur_test->in_len + 2,
8987                                     2);
8988                         err = TEST_SUCCESS;
8989                 }
8990                 all_err += err;
8991         }
8992
8993         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8994
8995         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8996
8997 }
8998
8999 static int
9000 test_PDCP_SDAP_PROTO_decap_all(void)
9001 {
9002         int i = 0, size = 0;
9003         int err, all_err = TEST_SUCCESS;
9004         const struct pdcp_sdap_test *cur_test;
9005
9006         size = RTE_DIM(list_pdcp_sdap_tests);
9007
9008         for (i = 0; i < size; i++) {
9009                 cur_test = &list_pdcp_sdap_tests[i];
9010                 err = test_pdcp_proto(
9011                         i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
9012                         RTE_CRYPTO_AUTH_OP_VERIFY,
9013                         cur_test->data_out,
9014                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9015                         cur_test->data_in, cur_test->in_len,
9016                         cur_test->param.cipher_alg,
9017                         cur_test->cipher_key, cur_test->param.cipher_key_len,
9018                         cur_test->param.auth_alg, cur_test->auth_key,
9019                         cur_test->param.auth_key_len, cur_test->bearer,
9020                         cur_test->param.domain, cur_test->packet_direction,
9021                         cur_test->sn_size, cur_test->hfn,
9022                         cur_test->hfn_threshold, SDAP_ENABLED);
9023                 if (err) {
9024                         printf("\t%d) %s: Decapsulation failed\n",
9025                                         cur_test->test_idx,
9026                                         cur_test->param.name);
9027                         err = TEST_FAILED;
9028                 } else {
9029                         printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
9030                                         cur_test->param.name);
9031                         err = TEST_SUCCESS;
9032                 }
9033                 all_err += err;
9034         }
9035
9036         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9037
9038         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9039 }
9040
9041 static int
9042 test_ipsec_proto_process(const struct ipsec_test_data td[],
9043                          struct ipsec_test_data res_d[],
9044                          int nb_td,
9045                          bool silent,
9046                          const struct ipsec_test_flags *flags)
9047 {
9048         struct crypto_testsuite_params *ts_params = &testsuite_params;
9049         struct crypto_unittest_params *ut_params = &unittest_params;
9050         struct rte_security_capability_idx sec_cap_idx;
9051         const struct rte_security_capability *sec_cap;
9052         struct rte_security_ipsec_xform ipsec_xform;
9053         uint8_t dev_id = ts_params->valid_devs[0];
9054         enum rte_security_ipsec_sa_direction dir;
9055         struct ipsec_test_data *res_d_tmp = NULL;
9056         uint32_t src = RTE_IPV4(192, 168, 1, 0);
9057         uint32_t dst = RTE_IPV4(192, 168, 1, 1);
9058         int salt_len, i, ret = TEST_SUCCESS;
9059         struct rte_security_ctx *ctx;
9060         uint8_t *input_text;
9061         uint32_t verify;
9062
9063         ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9064         gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9065
9066         /* Use first test data to create session */
9067
9068         /* Copy IPsec xform */
9069         memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
9070
9071         dir = ipsec_xform.direction;
9072         verify = flags->tunnel_hdr_verify;
9073
9074         if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
9075                 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
9076                         src += 1;
9077                 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
9078                         dst += 1;
9079         }
9080
9081         memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src));
9082         memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst));
9083
9084         ctx = rte_cryptodev_get_sec_ctx(dev_id);
9085
9086         sec_cap_idx.action = ut_params->type;
9087         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
9088         sec_cap_idx.ipsec.proto = ipsec_xform.proto;
9089         sec_cap_idx.ipsec.mode = ipsec_xform.mode;
9090         sec_cap_idx.ipsec.direction = ipsec_xform.direction;
9091
9092         if (flags->udp_encap)
9093                 ipsec_xform.options.udp_encap = 1;
9094
9095         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9096         if (sec_cap == NULL)
9097                 return TEST_SKIPPED;
9098
9099         /* Copy cipher session parameters */
9100         if (td[0].aead) {
9101                 memcpy(&ut_params->aead_xform, &td[0].xform.aead,
9102                        sizeof(ut_params->aead_xform));
9103                 ut_params->aead_xform.aead.key.data = td[0].key.data;
9104                 ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
9105
9106                 /* Verify crypto capabilities */
9107                 if (test_ipsec_crypto_caps_aead_verify(
9108                                 sec_cap,
9109                                 &ut_params->aead_xform) != 0) {
9110                         if (!silent)
9111                                 RTE_LOG(INFO, USER1,
9112                                         "Crypto capabilities not supported\n");
9113                         return TEST_SKIPPED;
9114                 }
9115         } else {
9116                 /* Only AEAD supported now */
9117                 return TEST_SKIPPED;
9118         }
9119
9120         if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
9121                 return TEST_SKIPPED;
9122
9123         salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
9124         memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
9125
9126         struct rte_security_session_conf sess_conf = {
9127                 .action_type = ut_params->type,
9128                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
9129                 .ipsec = ipsec_xform,
9130                 .crypto_xform = &ut_params->aead_xform,
9131         };
9132
9133         /* Create security session */
9134         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9135                                         ts_params->session_mpool,
9136                                         ts_params->session_priv_mpool);
9137
9138         if (ut_params->sec_session == NULL)
9139                 return TEST_SKIPPED;
9140
9141         for (i = 0; i < nb_td; i++) {
9142                 /* Setup source mbuf payload */
9143                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9144                 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9145                                 rte_pktmbuf_tailroom(ut_params->ibuf));
9146
9147                 input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9148                                 td[i].input_text.len);
9149
9150                 memcpy(input_text, td[i].input_text.data,
9151                        td[i].input_text.len);
9152
9153                 /* Generate crypto op data structure */
9154                 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9155                                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9156                 if (!ut_params->op) {
9157                         printf("TestCase %s line %d: %s\n",
9158                                 __func__, __LINE__,
9159                                 "failed to allocate crypto op");
9160                         ret = TEST_FAILED;
9161                         goto crypto_op_free;
9162                 }
9163
9164                 /* Attach session to operation */
9165                 rte_security_attach_session(ut_params->op,
9166                                             ut_params->sec_session);
9167
9168                 /* Set crypto operation mbufs */
9169                 ut_params->op->sym->m_src = ut_params->ibuf;
9170                 ut_params->op->sym->m_dst = NULL;
9171
9172                 /* Copy IV in crypto operation when IV generation is disabled */
9173                 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
9174                     ipsec_xform.options.iv_gen_disable == 1) {
9175                         uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
9176                                                                 uint8_t *,
9177                                                                 IV_OFFSET);
9178                         int len;
9179
9180                         if (td[i].aead)
9181                                 len = td[i].xform.aead.aead.iv.length;
9182                         else
9183                                 len = td[i].xform.chain.cipher.cipher.iv.length;
9184
9185                         memcpy(iv, td[i].iv.data, len);
9186                 }
9187
9188                 /* Process crypto operation */
9189                 process_crypto_request(dev_id, ut_params->op);
9190
9191                 ret = test_ipsec_status_check(ut_params->op, flags, dir, i + 1);
9192                 if (ret != TEST_SUCCESS)
9193                         goto crypto_op_free;
9194
9195                 if (res_d != NULL)
9196                         res_d_tmp = &res_d[i];
9197
9198                 ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
9199                                               res_d_tmp, silent, flags);
9200                 if (ret != TEST_SUCCESS)
9201                         goto crypto_op_free;
9202
9203                 rte_crypto_op_free(ut_params->op);
9204                 ut_params->op = NULL;
9205
9206                 rte_pktmbuf_free(ut_params->ibuf);
9207                 ut_params->ibuf = NULL;
9208         }
9209
9210 crypto_op_free:
9211         rte_crypto_op_free(ut_params->op);
9212         ut_params->op = NULL;
9213
9214         rte_pktmbuf_free(ut_params->ibuf);
9215         ut_params->ibuf = NULL;
9216
9217         if (ut_params->sec_session)
9218                 rte_security_session_destroy(ctx, ut_params->sec_session);
9219         ut_params->sec_session = NULL;
9220
9221         return ret;
9222 }
9223
9224 static int
9225 test_ipsec_proto_known_vec(const void *test_data)
9226 {
9227         struct ipsec_test_data td_outb;
9228         struct ipsec_test_flags flags;
9229
9230         memset(&flags, 0, sizeof(flags));
9231
9232         memcpy(&td_outb, test_data, sizeof(td_outb));
9233
9234         /* Disable IV gen to be able to test with known vectors */
9235         td_outb.ipsec_xform.options.iv_gen_disable = 1;
9236
9237         return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9238 }
9239
9240 static int
9241 test_ipsec_proto_known_vec_inb(const void *td_outb)
9242 {
9243         struct ipsec_test_flags flags;
9244         struct ipsec_test_data td_inb;
9245
9246         memset(&flags, 0, sizeof(flags));
9247
9248         test_ipsec_td_in_from_out(td_outb, &td_inb);
9249
9250         return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
9251 }
9252
9253 static int
9254 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
9255 {
9256         struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9257         struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9258         unsigned int i, nb_pkts = 1, pass_cnt = 0;
9259         int ret;
9260
9261         if (flags->iv_gen ||
9262             flags->sa_expiry_pkts_soft ||
9263             flags->sa_expiry_pkts_hard)
9264                 nb_pkts = IPSEC_TEST_PACKETS_MAX;
9265
9266         for (i = 0; i < RTE_DIM(aead_list); i++) {
9267                 test_ipsec_td_prepare(&aead_list[i],
9268                                       NULL,
9269                                       flags,
9270                                       td_outb,
9271                                       nb_pkts);
9272
9273                 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9274                                                flags);
9275                 if (ret == TEST_SKIPPED)
9276                         continue;
9277
9278                 if (ret == TEST_FAILED)
9279                         return TEST_FAILED;
9280
9281                 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9282
9283                 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9284                                                flags);
9285                 if (ret == TEST_SKIPPED)
9286                         continue;
9287
9288                 if (ret == TEST_FAILED)
9289                         return TEST_FAILED;
9290
9291                 if (flags->display_alg)
9292                         test_ipsec_display_alg(&aead_list[i], NULL);
9293
9294                 pass_cnt++;
9295         }
9296
9297         if (pass_cnt > 0)
9298                 return TEST_SUCCESS;
9299         else
9300                 return TEST_SKIPPED;
9301 }
9302
9303 static int
9304 test_ipsec_proto_display_list(const void *data __rte_unused)
9305 {
9306         struct ipsec_test_flags flags;
9307
9308         memset(&flags, 0, sizeof(flags));
9309
9310         flags.display_alg = true;
9311
9312         return test_ipsec_proto_all(&flags);
9313 }
9314
9315 static int
9316 test_ipsec_proto_iv_gen(const void *data __rte_unused)
9317 {
9318         struct ipsec_test_flags flags;
9319
9320         memset(&flags, 0, sizeof(flags));
9321
9322         flags.iv_gen = true;
9323
9324         return test_ipsec_proto_all(&flags);
9325 }
9326
9327 static int
9328 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused)
9329 {
9330         struct ipsec_test_flags flags;
9331
9332         memset(&flags, 0, sizeof(flags));
9333
9334         flags.sa_expiry_pkts_soft = true;
9335
9336         return test_ipsec_proto_all(&flags);
9337 }
9338
9339 static int
9340 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused)
9341 {
9342         struct ipsec_test_flags flags;
9343
9344         memset(&flags, 0, sizeof(flags));
9345
9346         flags.sa_expiry_pkts_hard = true;
9347
9348         return test_ipsec_proto_all(&flags);
9349 }
9350
9351 static int
9352 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused)
9353 {
9354         struct ipsec_test_flags flags;
9355
9356         memset(&flags, 0, sizeof(flags));
9357
9358         flags.icv_corrupt = true;
9359
9360         return test_ipsec_proto_all(&flags);
9361 }
9362
9363 static int
9364 test_ipsec_proto_udp_encap(const void *data __rte_unused)
9365 {
9366         struct ipsec_test_flags flags;
9367
9368         memset(&flags, 0, sizeof(flags));
9369
9370         flags.udp_encap = true;
9371
9372         return test_ipsec_proto_all(&flags);
9373 }
9374
9375 static int
9376 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
9377 {
9378         struct ipsec_test_flags flags;
9379
9380         memset(&flags, 0, sizeof(flags));
9381
9382         flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
9383
9384         return test_ipsec_proto_all(&flags);
9385 }
9386
9387 static int
9388 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
9389 {
9390         struct ipsec_test_flags flags;
9391
9392         memset(&flags, 0, sizeof(flags));
9393
9394         flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
9395
9396         return test_ipsec_proto_all(&flags);
9397 }
9398
9399 static int
9400 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused)
9401 {
9402         struct ipsec_test_flags flags;
9403
9404         memset(&flags, 0, sizeof(flags));
9405
9406         flags.udp_encap = true;
9407         flags.udp_ports_verify = true;
9408
9409         return test_ipsec_proto_all(&flags);
9410 }
9411
9412 static int
9413 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused)
9414 {
9415         struct ipsec_test_flags flags;
9416
9417         memset(&flags, 0, sizeof(flags));
9418
9419         flags.ip_csum = true;
9420
9421         return test_ipsec_proto_all(&flags);
9422 }
9423
9424 static int
9425 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused)
9426 {
9427         struct ipsec_test_flags flags;
9428
9429         memset(&flags, 0, sizeof(flags));
9430
9431         flags.l4_csum = true;
9432
9433         return test_ipsec_proto_all(&flags);
9434 }
9435
9436 static int
9437 test_PDCP_PROTO_all(void)
9438 {
9439         struct crypto_testsuite_params *ts_params = &testsuite_params;
9440         struct crypto_unittest_params *ut_params = &unittest_params;
9441         struct rte_cryptodev_info dev_info;
9442         int status;
9443
9444         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9445         uint64_t feat_flags = dev_info.feature_flags;
9446
9447         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9448                 return TEST_SKIPPED;
9449
9450         /* Set action type */
9451         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9452                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9453                 gbl_action_type;
9454
9455         if (security_proto_supported(ut_params->type,
9456                         RTE_SECURITY_PROTOCOL_PDCP) < 0)
9457                 return TEST_SKIPPED;
9458
9459         status = test_PDCP_PROTO_cplane_encap_all();
9460         status += test_PDCP_PROTO_cplane_decap_all();
9461         status += test_PDCP_PROTO_uplane_encap_all();
9462         status += test_PDCP_PROTO_uplane_decap_all();
9463         status += test_PDCP_PROTO_SGL_in_place_32B();
9464         status += test_PDCP_PROTO_SGL_oop_32B_128B();
9465         status += test_PDCP_PROTO_SGL_oop_32B_40B();
9466         status += test_PDCP_PROTO_SGL_oop_128B_32B();
9467         status += test_PDCP_SDAP_PROTO_encap_all();
9468         status += test_PDCP_SDAP_PROTO_decap_all();
9469         status += test_PDCP_PROTO_short_mac();
9470
9471         if (status)
9472                 return TEST_FAILED;
9473         else
9474                 return TEST_SUCCESS;
9475 }
9476
9477 static int
9478 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
9479 {
9480         struct crypto_testsuite_params *ts_params = &testsuite_params;
9481         struct crypto_unittest_params *ut_params = &unittest_params;
9482         uint8_t *plaintext, *ciphertext;
9483         uint8_t *iv_ptr;
9484         int32_t cipher_len, crc_len;
9485         uint32_t crc_data_len;
9486         int ret = TEST_SUCCESS;
9487
9488         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9489                                         rte_cryptodev_get_sec_ctx(
9490                                                 ts_params->valid_devs[0]);
9491
9492         /* Verify the capabilities */
9493         struct rte_security_capability_idx sec_cap_idx;
9494         const struct rte_security_capability *sec_cap;
9495         const struct rte_cryptodev_capabilities *crypto_cap;
9496         const struct rte_cryptodev_symmetric_capability *sym_cap;
9497         int j = 0;
9498
9499         sec_cap_idx.action = ut_params->type;
9500         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9501         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
9502
9503         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9504         if (sec_cap == NULL)
9505                 return TEST_SKIPPED;
9506
9507         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9508                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9509                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9510                                 crypto_cap->sym.xform_type ==
9511                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9512                                 crypto_cap->sym.cipher.algo ==
9513                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9514                         sym_cap = &crypto_cap->sym;
9515                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9516                                                 d_td->key.len,
9517                                                 d_td->iv.len) == 0)
9518                                 break;
9519                 }
9520         }
9521
9522         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9523                 return TEST_SKIPPED;
9524
9525         /* Setup source mbuf payload */
9526         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9527         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9528                         rte_pktmbuf_tailroom(ut_params->ibuf));
9529
9530         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9531                         d_td->ciphertext.len);
9532
9533         memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
9534
9535         /* Setup cipher session parameters */
9536         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9537         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9538         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
9539         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9540         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9541         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9542         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9543         ut_params->cipher_xform.next = NULL;
9544
9545         /* Setup DOCSIS session parameters */
9546         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
9547
9548         struct rte_security_session_conf sess_conf = {
9549                 .action_type = ut_params->type,
9550                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9551                 .docsis = ut_params->docsis_xform,
9552                 .crypto_xform = &ut_params->cipher_xform,
9553         };
9554
9555         /* Create security session */
9556         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9557                                         ts_params->session_mpool,
9558                                         ts_params->session_priv_mpool);
9559
9560         if (!ut_params->sec_session) {
9561                 printf("TestCase %s(%d) line %d: %s\n",
9562                         __func__, i, __LINE__, "failed to allocate session");
9563                 ret = TEST_FAILED;
9564                 goto on_err;
9565         }
9566
9567         /* Generate crypto op data structure */
9568         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9569                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9570         if (!ut_params->op) {
9571                 printf("TestCase %s(%d) line %d: %s\n",
9572                         __func__, i, __LINE__,
9573                         "failed to allocate symmetric crypto operation");
9574                 ret = TEST_FAILED;
9575                 goto on_err;
9576         }
9577
9578         /* Setup CRC operation parameters */
9579         crc_len = d_td->ciphertext.no_crc == false ?
9580                         (d_td->ciphertext.len -
9581                                 d_td->ciphertext.crc_offset -
9582                                 RTE_ETHER_CRC_LEN) :
9583                         0;
9584         crc_len = crc_len > 0 ? crc_len : 0;
9585         crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
9586         ut_params->op->sym->auth.data.length = crc_len;
9587         ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
9588
9589         /* Setup cipher operation parameters */
9590         cipher_len = d_td->ciphertext.no_cipher == false ?
9591                         (d_td->ciphertext.len -
9592                                 d_td->ciphertext.cipher_offset) :
9593                         0;
9594         cipher_len = cipher_len > 0 ? cipher_len : 0;
9595         ut_params->op->sym->cipher.data.length = cipher_len;
9596         ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
9597
9598         /* Setup cipher IV */
9599         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9600         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9601
9602         /* Attach session to operation */
9603         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9604
9605         /* Set crypto operation mbufs */
9606         ut_params->op->sym->m_src = ut_params->ibuf;
9607         ut_params->op->sym->m_dst = NULL;
9608
9609         /* Process crypto operation */
9610         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9611                         NULL) {
9612                 printf("TestCase %s(%d) line %d: %s\n",
9613                         __func__, i, __LINE__,
9614                         "failed to process security crypto op");
9615                 ret = TEST_FAILED;
9616                 goto on_err;
9617         }
9618
9619         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9620                 printf("TestCase %s(%d) line %d: %s\n",
9621                         __func__, i, __LINE__, "crypto op processing failed");
9622                 ret = TEST_FAILED;
9623                 goto on_err;
9624         }
9625
9626         /* Validate plaintext */
9627         plaintext = ciphertext;
9628
9629         if (memcmp(plaintext, d_td->plaintext.data,
9630                         d_td->plaintext.len - crc_data_len)) {
9631                 printf("TestCase %s(%d) line %d: %s\n",
9632                         __func__, i, __LINE__, "plaintext not as expected\n");
9633                 rte_hexdump(stdout, "expected", d_td->plaintext.data,
9634                                 d_td->plaintext.len);
9635                 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9636                 ret = TEST_FAILED;
9637                 goto on_err;
9638         }
9639
9640 on_err:
9641         rte_crypto_op_free(ut_params->op);
9642         ut_params->op = NULL;
9643
9644         if (ut_params->sec_session)
9645                 rte_security_session_destroy(ctx, ut_params->sec_session);
9646         ut_params->sec_session = NULL;
9647
9648         rte_pktmbuf_free(ut_params->ibuf);
9649         ut_params->ibuf = NULL;
9650
9651         return ret;
9652 }
9653
9654 static int
9655 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9656 {
9657         struct crypto_testsuite_params *ts_params = &testsuite_params;
9658         struct crypto_unittest_params *ut_params = &unittest_params;
9659         uint8_t *plaintext, *ciphertext;
9660         uint8_t *iv_ptr;
9661         int32_t cipher_len, crc_len;
9662         int ret = TEST_SUCCESS;
9663
9664         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9665                                         rte_cryptodev_get_sec_ctx(
9666                                                 ts_params->valid_devs[0]);
9667
9668         /* Verify the capabilities */
9669         struct rte_security_capability_idx sec_cap_idx;
9670         const struct rte_security_capability *sec_cap;
9671         const struct rte_cryptodev_capabilities *crypto_cap;
9672         const struct rte_cryptodev_symmetric_capability *sym_cap;
9673         int j = 0;
9674
9675         sec_cap_idx.action = ut_params->type;
9676         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9677         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9678
9679         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9680         if (sec_cap == NULL)
9681                 return TEST_SKIPPED;
9682
9683         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9684                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9685                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9686                                 crypto_cap->sym.xform_type ==
9687                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9688                                 crypto_cap->sym.cipher.algo ==
9689                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9690                         sym_cap = &crypto_cap->sym;
9691                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9692                                                 d_td->key.len,
9693                                                 d_td->iv.len) == 0)
9694                                 break;
9695                 }
9696         }
9697
9698         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9699                 return TEST_SKIPPED;
9700
9701         /* Setup source mbuf payload */
9702         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9703         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9704                         rte_pktmbuf_tailroom(ut_params->ibuf));
9705
9706         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9707                         d_td->plaintext.len);
9708
9709         memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9710
9711         /* Setup cipher session parameters */
9712         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9713         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9714         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9715         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9716         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9717         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9718         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9719         ut_params->cipher_xform.next = NULL;
9720
9721         /* Setup DOCSIS session parameters */
9722         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9723
9724         struct rte_security_session_conf sess_conf = {
9725                 .action_type = ut_params->type,
9726                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9727                 .docsis = ut_params->docsis_xform,
9728                 .crypto_xform = &ut_params->cipher_xform,
9729         };
9730
9731         /* Create security session */
9732         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9733                                         ts_params->session_mpool,
9734                                         ts_params->session_priv_mpool);
9735
9736         if (!ut_params->sec_session) {
9737                 printf("TestCase %s(%d) line %d: %s\n",
9738                         __func__, i, __LINE__, "failed to allocate session");
9739                 ret = TEST_FAILED;
9740                 goto on_err;
9741         }
9742
9743         /* Generate crypto op data structure */
9744         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9745                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9746         if (!ut_params->op) {
9747                 printf("TestCase %s(%d) line %d: %s\n",
9748                         __func__, i, __LINE__,
9749                         "failed to allocate security crypto operation");
9750                 ret = TEST_FAILED;
9751                 goto on_err;
9752         }
9753
9754         /* Setup CRC operation parameters */
9755         crc_len = d_td->plaintext.no_crc == false ?
9756                         (d_td->plaintext.len -
9757                                 d_td->plaintext.crc_offset -
9758                                 RTE_ETHER_CRC_LEN) :
9759                         0;
9760         crc_len = crc_len > 0 ? crc_len : 0;
9761         ut_params->op->sym->auth.data.length = crc_len;
9762         ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9763
9764         /* Setup cipher operation parameters */
9765         cipher_len = d_td->plaintext.no_cipher == false ?
9766                         (d_td->plaintext.len -
9767                                 d_td->plaintext.cipher_offset) :
9768                         0;
9769         cipher_len = cipher_len > 0 ? cipher_len : 0;
9770         ut_params->op->sym->cipher.data.length = cipher_len;
9771         ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9772
9773         /* Setup cipher IV */
9774         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9775         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9776
9777         /* Attach session to operation */
9778         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9779
9780         /* Set crypto operation mbufs */
9781         ut_params->op->sym->m_src = ut_params->ibuf;
9782         ut_params->op->sym->m_dst = NULL;
9783
9784         /* Process crypto operation */
9785         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9786                         NULL) {
9787                 printf("TestCase %s(%d) line %d: %s\n",
9788                         __func__, i, __LINE__,
9789                         "failed to process security crypto op");
9790                 ret = TEST_FAILED;
9791                 goto on_err;
9792         }
9793
9794         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9795                 printf("TestCase %s(%d) line %d: %s\n",
9796                         __func__, i, __LINE__, "crypto op processing failed");
9797                 ret = TEST_FAILED;
9798                 goto on_err;
9799         }
9800
9801         /* Validate ciphertext */
9802         ciphertext = plaintext;
9803
9804         if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9805                 printf("TestCase %s(%d) line %d: %s\n",
9806                         __func__, i, __LINE__, "ciphertext not as expected\n");
9807                 rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9808                                 d_td->ciphertext.len);
9809                 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9810                 ret = TEST_FAILED;
9811                 goto on_err;
9812         }
9813
9814 on_err:
9815         rte_crypto_op_free(ut_params->op);
9816         ut_params->op = NULL;
9817
9818         if (ut_params->sec_session)
9819                 rte_security_session_destroy(ctx, ut_params->sec_session);
9820         ut_params->sec_session = NULL;
9821
9822         rte_pktmbuf_free(ut_params->ibuf);
9823         ut_params->ibuf = NULL;
9824
9825         return ret;
9826 }
9827
9828 #define TEST_DOCSIS_COUNT(func) do {                    \
9829         int ret = func;                                 \
9830         if (ret == TEST_SUCCESS)  {                     \
9831                 printf("\t%2d)", n++);                  \
9832                 printf("+++++ PASSED:" #func"\n");      \
9833                 p++;                                    \
9834         } else if (ret == TEST_SKIPPED) {               \
9835                 printf("\t%2d)", n++);                  \
9836                 printf("~~~~~ SKIPPED:" #func"\n");     \
9837                 s++;                                    \
9838         } else {                                        \
9839                 printf("\t%2d)", n++);                  \
9840                 printf("----- FAILED:" #func"\n");      \
9841                 f++;                                    \
9842         }                                               \
9843 } while (0)
9844
9845 static int
9846 test_DOCSIS_PROTO_uplink_all(void)
9847 {
9848         int p = 0, s = 0, f = 0, n = 0;
9849
9850         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9851         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9852         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9853         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9854         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9855         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9856         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9857         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9858         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9859         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9860         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9861         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9862         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9863         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9864         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9865         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9866         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9867         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9868         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9869         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9870         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9871         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9872         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9873         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9874         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9875         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9876
9877         if (f)
9878                 printf("## %s: %d passed out of %d (%d skipped)\n",
9879                         __func__, p, n, s);
9880
9881         return f;
9882 };
9883
9884 static int
9885 test_DOCSIS_PROTO_downlink_all(void)
9886 {
9887         int p = 0, s = 0, f = 0, n = 0;
9888
9889         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9890         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9891         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9892         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9893         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9894         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9895         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9896         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9897         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9898         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9899         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9900         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9901         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9902         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9903         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9904         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9905         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9906         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9907         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9908         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9909         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9910         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9911         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9912         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9913         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9914         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9915
9916         if (f)
9917                 printf("## %s: %d passed out of %d (%d skipped)\n",
9918                         __func__, p, n, s);
9919
9920         return f;
9921 };
9922
9923 static int
9924 test_DOCSIS_PROTO_all(void)
9925 {
9926         struct crypto_testsuite_params *ts_params = &testsuite_params;
9927         struct crypto_unittest_params *ut_params = &unittest_params;
9928         struct rte_cryptodev_info dev_info;
9929         int status;
9930
9931         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9932         uint64_t feat_flags = dev_info.feature_flags;
9933
9934         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9935                 return TEST_SKIPPED;
9936
9937         /* Set action type */
9938         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9939                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9940                 gbl_action_type;
9941
9942         if (security_proto_supported(ut_params->type,
9943                         RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9944                 return TEST_SKIPPED;
9945
9946         status = test_DOCSIS_PROTO_uplink_all();
9947         status += test_DOCSIS_PROTO_downlink_all();
9948
9949         if (status)
9950                 return TEST_FAILED;
9951         else
9952                 return TEST_SUCCESS;
9953 }
9954 #endif
9955
9956 static int
9957 test_AES_GCM_authenticated_encryption_test_case_1(void)
9958 {
9959         return test_authenticated_encryption(&gcm_test_case_1);
9960 }
9961
9962 static int
9963 test_AES_GCM_authenticated_encryption_test_case_2(void)
9964 {
9965         return test_authenticated_encryption(&gcm_test_case_2);
9966 }
9967
9968 static int
9969 test_AES_GCM_authenticated_encryption_test_case_3(void)
9970 {
9971         return test_authenticated_encryption(&gcm_test_case_3);
9972 }
9973
9974 static int
9975 test_AES_GCM_authenticated_encryption_test_case_4(void)
9976 {
9977         return test_authenticated_encryption(&gcm_test_case_4);
9978 }
9979
9980 static int
9981 test_AES_GCM_authenticated_encryption_test_case_5(void)
9982 {
9983         return test_authenticated_encryption(&gcm_test_case_5);
9984 }
9985
9986 static int
9987 test_AES_GCM_authenticated_encryption_test_case_6(void)
9988 {
9989         return test_authenticated_encryption(&gcm_test_case_6);
9990 }
9991
9992 static int
9993 test_AES_GCM_authenticated_encryption_test_case_7(void)
9994 {
9995         return test_authenticated_encryption(&gcm_test_case_7);
9996 }
9997
9998 static int
9999 test_AES_GCM_authenticated_encryption_test_case_8(void)
10000 {
10001         return test_authenticated_encryption(&gcm_test_case_8);
10002 }
10003
10004 static int
10005 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
10006 {
10007         return test_authenticated_encryption(&gcm_J0_test_case_1);
10008 }
10009
10010 static int
10011 test_AES_GCM_auth_encryption_test_case_192_1(void)
10012 {
10013         return test_authenticated_encryption(&gcm_test_case_192_1);
10014 }
10015
10016 static int
10017 test_AES_GCM_auth_encryption_test_case_192_2(void)
10018 {
10019         return test_authenticated_encryption(&gcm_test_case_192_2);
10020 }
10021
10022 static int
10023 test_AES_GCM_auth_encryption_test_case_192_3(void)
10024 {
10025         return test_authenticated_encryption(&gcm_test_case_192_3);
10026 }
10027
10028 static int
10029 test_AES_GCM_auth_encryption_test_case_192_4(void)
10030 {
10031         return test_authenticated_encryption(&gcm_test_case_192_4);
10032 }
10033
10034 static int
10035 test_AES_GCM_auth_encryption_test_case_192_5(void)
10036 {
10037         return test_authenticated_encryption(&gcm_test_case_192_5);
10038 }
10039
10040 static int
10041 test_AES_GCM_auth_encryption_test_case_192_6(void)
10042 {
10043         return test_authenticated_encryption(&gcm_test_case_192_6);
10044 }
10045
10046 static int
10047 test_AES_GCM_auth_encryption_test_case_192_7(void)
10048 {
10049         return test_authenticated_encryption(&gcm_test_case_192_7);
10050 }
10051
10052 static int
10053 test_AES_GCM_auth_encryption_test_case_256_1(void)
10054 {
10055         return test_authenticated_encryption(&gcm_test_case_256_1);
10056 }
10057
10058 static int
10059 test_AES_GCM_auth_encryption_test_case_256_2(void)
10060 {
10061         return test_authenticated_encryption(&gcm_test_case_256_2);
10062 }
10063
10064 static int
10065 test_AES_GCM_auth_encryption_test_case_256_3(void)
10066 {
10067         return test_authenticated_encryption(&gcm_test_case_256_3);
10068 }
10069
10070 static int
10071 test_AES_GCM_auth_encryption_test_case_256_4(void)
10072 {
10073         return test_authenticated_encryption(&gcm_test_case_256_4);
10074 }
10075
10076 static int
10077 test_AES_GCM_auth_encryption_test_case_256_5(void)
10078 {
10079         return test_authenticated_encryption(&gcm_test_case_256_5);
10080 }
10081
10082 static int
10083 test_AES_GCM_auth_encryption_test_case_256_6(void)
10084 {
10085         return test_authenticated_encryption(&gcm_test_case_256_6);
10086 }
10087
10088 static int
10089 test_AES_GCM_auth_encryption_test_case_256_7(void)
10090 {
10091         return test_authenticated_encryption(&gcm_test_case_256_7);
10092 }
10093
10094 static int
10095 test_AES_GCM_auth_encryption_test_case_aad_1(void)
10096 {
10097         return test_authenticated_encryption(&gcm_test_case_aad_1);
10098 }
10099
10100 static int
10101 test_AES_GCM_auth_encryption_test_case_aad_2(void)
10102 {
10103         return test_authenticated_encryption(&gcm_test_case_aad_2);
10104 }
10105
10106 static int
10107 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
10108 {
10109         struct aead_test_data tdata;
10110         int res;
10111
10112         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10113         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10114         tdata.iv.data[0] += 1;
10115         res = test_authenticated_encryption(&tdata);
10116         if (res == TEST_SKIPPED)
10117                 return res;
10118         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10119         return TEST_SUCCESS;
10120 }
10121
10122 static int
10123 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
10124 {
10125         struct aead_test_data tdata;
10126         int res;
10127
10128         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10129         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10130         tdata.plaintext.data[0] += 1;
10131         res = test_authenticated_encryption(&tdata);
10132         if (res == TEST_SKIPPED)
10133                 return res;
10134         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10135         return TEST_SUCCESS;
10136 }
10137
10138 static int
10139 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
10140 {
10141         struct aead_test_data tdata;
10142         int res;
10143
10144         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10145         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10146         tdata.ciphertext.data[0] += 1;
10147         res = test_authenticated_encryption(&tdata);
10148         if (res == TEST_SKIPPED)
10149                 return res;
10150         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10151         return TEST_SUCCESS;
10152 }
10153
10154 static int
10155 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
10156 {
10157         struct aead_test_data tdata;
10158         int res;
10159
10160         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10161         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10162         tdata.aad.len += 1;
10163         res = test_authenticated_encryption(&tdata);
10164         if (res == TEST_SKIPPED)
10165                 return res;
10166         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10167         return TEST_SUCCESS;
10168 }
10169
10170 static int
10171 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
10172 {
10173         struct aead_test_data tdata;
10174         uint8_t aad[gcm_test_case_7.aad.len];
10175         int res;
10176
10177         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10178         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10179         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10180         aad[0] += 1;
10181         tdata.aad.data = aad;
10182         res = test_authenticated_encryption(&tdata);
10183         if (res == TEST_SKIPPED)
10184                 return res;
10185         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10186         return TEST_SUCCESS;
10187 }
10188
10189 static int
10190 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
10191 {
10192         struct aead_test_data tdata;
10193         int res;
10194
10195         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10196         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10197         tdata.auth_tag.data[0] += 1;
10198         res = test_authenticated_encryption(&tdata);
10199         if (res == TEST_SKIPPED)
10200                 return res;
10201         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10202         return TEST_SUCCESS;
10203 }
10204
10205 static int
10206 test_authenticated_decryption(const struct aead_test_data *tdata)
10207 {
10208         struct crypto_testsuite_params *ts_params = &testsuite_params;
10209         struct crypto_unittest_params *ut_params = &unittest_params;
10210
10211         int retval;
10212         uint8_t *plaintext;
10213         uint32_t i;
10214         struct rte_cryptodev_info dev_info;
10215
10216         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10217         uint64_t feat_flags = dev_info.feature_flags;
10218
10219         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10220                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10221                 printf("Device doesn't support RAW data-path APIs.\n");
10222                 return TEST_SKIPPED;
10223         }
10224
10225         /* Verify the capabilities */
10226         struct rte_cryptodev_sym_capability_idx cap_idx;
10227         const struct rte_cryptodev_symmetric_capability *capability;
10228         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10229         cap_idx.algo.aead = tdata->algo;
10230         capability = rte_cryptodev_sym_capability_get(
10231                         ts_params->valid_devs[0], &cap_idx);
10232         if (capability == NULL)
10233                 return TEST_SKIPPED;
10234         if (rte_cryptodev_sym_capability_check_aead(
10235                         capability, tdata->key.len, tdata->auth_tag.len,
10236                         tdata->aad.len, tdata->iv.len))
10237                 return TEST_SKIPPED;
10238
10239         /* Create AEAD session */
10240         retval = create_aead_session(ts_params->valid_devs[0],
10241                         tdata->algo,
10242                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10243                         tdata->key.data, tdata->key.len,
10244                         tdata->aad.len, tdata->auth_tag.len,
10245                         tdata->iv.len);
10246         if (retval < 0)
10247                 return retval;
10248
10249         /* alloc mbuf and set payload */
10250         if (tdata->aad.len > MBUF_SIZE) {
10251                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10252                 /* Populate full size of add data */
10253                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
10254                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
10255         } else
10256                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10257
10258         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10259                         rte_pktmbuf_tailroom(ut_params->ibuf));
10260
10261         /* Create AEAD operation */
10262         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10263         if (retval < 0)
10264                 return retval;
10265
10266         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10267
10268         ut_params->op->sym->m_src = ut_params->ibuf;
10269
10270         /* Process crypto operation */
10271         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10272                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
10273         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10274                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10275                                 ut_params->op, 0, 0, 0, 0);
10276         else
10277                 TEST_ASSERT_NOT_NULL(
10278                         process_crypto_request(ts_params->valid_devs[0],
10279                         ut_params->op), "failed to process sym crypto op");
10280
10281         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10282                         "crypto op processing failed");
10283
10284         if (ut_params->op->sym->m_dst)
10285                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
10286                                 uint8_t *);
10287         else
10288                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
10289                                 uint8_t *,
10290                                 ut_params->op->sym->cipher.data.offset);
10291
10292         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10293
10294         /* Validate obuf */
10295         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10296                         plaintext,
10297                         tdata->plaintext.data,
10298                         tdata->plaintext.len,
10299                         "Plaintext data not as expected");
10300
10301         TEST_ASSERT_EQUAL(ut_params->op->status,
10302                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10303                         "Authentication failed");
10304
10305         return 0;
10306 }
10307
10308 static int
10309 test_AES_GCM_authenticated_decryption_test_case_1(void)
10310 {
10311         return test_authenticated_decryption(&gcm_test_case_1);
10312 }
10313
10314 static int
10315 test_AES_GCM_authenticated_decryption_test_case_2(void)
10316 {
10317         return test_authenticated_decryption(&gcm_test_case_2);
10318 }
10319
10320 static int
10321 test_AES_GCM_authenticated_decryption_test_case_3(void)
10322 {
10323         return test_authenticated_decryption(&gcm_test_case_3);
10324 }
10325
10326 static int
10327 test_AES_GCM_authenticated_decryption_test_case_4(void)
10328 {
10329         return test_authenticated_decryption(&gcm_test_case_4);
10330 }
10331
10332 static int
10333 test_AES_GCM_authenticated_decryption_test_case_5(void)
10334 {
10335         return test_authenticated_decryption(&gcm_test_case_5);
10336 }
10337
10338 static int
10339 test_AES_GCM_authenticated_decryption_test_case_6(void)
10340 {
10341         return test_authenticated_decryption(&gcm_test_case_6);
10342 }
10343
10344 static int
10345 test_AES_GCM_authenticated_decryption_test_case_7(void)
10346 {
10347         return test_authenticated_decryption(&gcm_test_case_7);
10348 }
10349
10350 static int
10351 test_AES_GCM_authenticated_decryption_test_case_8(void)
10352 {
10353         return test_authenticated_decryption(&gcm_test_case_8);
10354 }
10355
10356 static int
10357 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
10358 {
10359         return test_authenticated_decryption(&gcm_J0_test_case_1);
10360 }
10361
10362 static int
10363 test_AES_GCM_auth_decryption_test_case_192_1(void)
10364 {
10365         return test_authenticated_decryption(&gcm_test_case_192_1);
10366 }
10367
10368 static int
10369 test_AES_GCM_auth_decryption_test_case_192_2(void)
10370 {
10371         return test_authenticated_decryption(&gcm_test_case_192_2);
10372 }
10373
10374 static int
10375 test_AES_GCM_auth_decryption_test_case_192_3(void)
10376 {
10377         return test_authenticated_decryption(&gcm_test_case_192_3);
10378 }
10379
10380 static int
10381 test_AES_GCM_auth_decryption_test_case_192_4(void)
10382 {
10383         return test_authenticated_decryption(&gcm_test_case_192_4);
10384 }
10385
10386 static int
10387 test_AES_GCM_auth_decryption_test_case_192_5(void)
10388 {
10389         return test_authenticated_decryption(&gcm_test_case_192_5);
10390 }
10391
10392 static int
10393 test_AES_GCM_auth_decryption_test_case_192_6(void)
10394 {
10395         return test_authenticated_decryption(&gcm_test_case_192_6);
10396 }
10397
10398 static int
10399 test_AES_GCM_auth_decryption_test_case_192_7(void)
10400 {
10401         return test_authenticated_decryption(&gcm_test_case_192_7);
10402 }
10403
10404 static int
10405 test_AES_GCM_auth_decryption_test_case_256_1(void)
10406 {
10407         return test_authenticated_decryption(&gcm_test_case_256_1);
10408 }
10409
10410 static int
10411 test_AES_GCM_auth_decryption_test_case_256_2(void)
10412 {
10413         return test_authenticated_decryption(&gcm_test_case_256_2);
10414 }
10415
10416 static int
10417 test_AES_GCM_auth_decryption_test_case_256_3(void)
10418 {
10419         return test_authenticated_decryption(&gcm_test_case_256_3);
10420 }
10421
10422 static int
10423 test_AES_GCM_auth_decryption_test_case_256_4(void)
10424 {
10425         return test_authenticated_decryption(&gcm_test_case_256_4);
10426 }
10427
10428 static int
10429 test_AES_GCM_auth_decryption_test_case_256_5(void)
10430 {
10431         return test_authenticated_decryption(&gcm_test_case_256_5);
10432 }
10433
10434 static int
10435 test_AES_GCM_auth_decryption_test_case_256_6(void)
10436 {
10437         return test_authenticated_decryption(&gcm_test_case_256_6);
10438 }
10439
10440 static int
10441 test_AES_GCM_auth_decryption_test_case_256_7(void)
10442 {
10443         return test_authenticated_decryption(&gcm_test_case_256_7);
10444 }
10445
10446 static int
10447 test_AES_GCM_auth_decryption_test_case_aad_1(void)
10448 {
10449         return test_authenticated_decryption(&gcm_test_case_aad_1);
10450 }
10451
10452 static int
10453 test_AES_GCM_auth_decryption_test_case_aad_2(void)
10454 {
10455         return test_authenticated_decryption(&gcm_test_case_aad_2);
10456 }
10457
10458 static int
10459 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
10460 {
10461         struct aead_test_data tdata;
10462         int res;
10463
10464         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10465         tdata.iv.data[0] += 1;
10466         res = test_authenticated_decryption(&tdata);
10467         if (res == TEST_SKIPPED)
10468                 return res;
10469         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10470         return TEST_SUCCESS;
10471 }
10472
10473 static int
10474 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
10475 {
10476         struct aead_test_data tdata;
10477         int res;
10478
10479         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10480         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10481         tdata.plaintext.data[0] += 1;
10482         res = test_authenticated_decryption(&tdata);
10483         if (res == TEST_SKIPPED)
10484                 return res;
10485         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10486         return TEST_SUCCESS;
10487 }
10488
10489 static int
10490 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
10491 {
10492         struct aead_test_data tdata;
10493         int res;
10494
10495         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10496         tdata.ciphertext.data[0] += 1;
10497         res = test_authenticated_decryption(&tdata);
10498         if (res == TEST_SKIPPED)
10499                 return res;
10500         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10501         return TEST_SUCCESS;
10502 }
10503
10504 static int
10505 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
10506 {
10507         struct aead_test_data tdata;
10508         int res;
10509
10510         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10511         tdata.aad.len += 1;
10512         res = test_authenticated_decryption(&tdata);
10513         if (res == TEST_SKIPPED)
10514                 return res;
10515         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10516         return TEST_SUCCESS;
10517 }
10518
10519 static int
10520 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
10521 {
10522         struct aead_test_data tdata;
10523         uint8_t aad[gcm_test_case_7.aad.len];
10524         int res;
10525
10526         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10527         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10528         aad[0] += 1;
10529         tdata.aad.data = aad;
10530         res = test_authenticated_decryption(&tdata);
10531         if (res == TEST_SKIPPED)
10532                 return res;
10533         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10534         return TEST_SUCCESS;
10535 }
10536
10537 static int
10538 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
10539 {
10540         struct aead_test_data tdata;
10541         int res;
10542
10543         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10544         tdata.auth_tag.data[0] += 1;
10545         res = test_authenticated_decryption(&tdata);
10546         if (res == TEST_SKIPPED)
10547                 return res;
10548         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
10549         return TEST_SUCCESS;
10550 }
10551
10552 static int
10553 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
10554 {
10555         struct crypto_testsuite_params *ts_params = &testsuite_params;
10556         struct crypto_unittest_params *ut_params = &unittest_params;
10557
10558         int retval;
10559         uint8_t *ciphertext, *auth_tag;
10560         uint16_t plaintext_pad_len;
10561         struct rte_cryptodev_info dev_info;
10562
10563         /* Verify the capabilities */
10564         struct rte_cryptodev_sym_capability_idx cap_idx;
10565         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10566         cap_idx.algo.aead = tdata->algo;
10567         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10568                         &cap_idx) == NULL)
10569                 return TEST_SKIPPED;
10570
10571         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10572         uint64_t feat_flags = dev_info.feature_flags;
10573
10574         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10575                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)))
10576                 return TEST_SKIPPED;
10577
10578         /* not supported with CPU crypto */
10579         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10580                 return TEST_SKIPPED;
10581
10582         /* Create AEAD session */
10583         retval = create_aead_session(ts_params->valid_devs[0],
10584                         tdata->algo,
10585                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10586                         tdata->key.data, tdata->key.len,
10587                         tdata->aad.len, tdata->auth_tag.len,
10588                         tdata->iv.len);
10589         if (retval < 0)
10590                 return retval;
10591
10592         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10593         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10594
10595         /* clear mbuf payload */
10596         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10597                         rte_pktmbuf_tailroom(ut_params->ibuf));
10598         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10599                         rte_pktmbuf_tailroom(ut_params->obuf));
10600
10601         /* Create AEAD operation */
10602         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10603         if (retval < 0)
10604                 return retval;
10605
10606         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10607
10608         ut_params->op->sym->m_src = ut_params->ibuf;
10609         ut_params->op->sym->m_dst = ut_params->obuf;
10610
10611         /* Process crypto operation */
10612         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10613                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10614                         ut_params->op, 0, 0, 0, 0);
10615         else
10616                 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10617                         ut_params->op), "failed to process sym crypto op");
10618
10619         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10620                         "crypto op processing failed");
10621
10622         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10623
10624         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10625                         ut_params->op->sym->cipher.data.offset);
10626         auth_tag = ciphertext + plaintext_pad_len;
10627
10628         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10629         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10630
10631         /* Validate obuf */
10632         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10633                         ciphertext,
10634                         tdata->ciphertext.data,
10635                         tdata->ciphertext.len,
10636                         "Ciphertext data not as expected");
10637
10638         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10639                         auth_tag,
10640                         tdata->auth_tag.data,
10641                         tdata->auth_tag.len,
10642                         "Generated auth tag not as expected");
10643
10644         return 0;
10645
10646 }
10647
10648 static int
10649 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10650 {
10651         return test_authenticated_encryption_oop(&gcm_test_case_5);
10652 }
10653
10654 static int
10655 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10656 {
10657         struct crypto_testsuite_params *ts_params = &testsuite_params;
10658         struct crypto_unittest_params *ut_params = &unittest_params;
10659
10660         int retval;
10661         uint8_t *plaintext;
10662         struct rte_cryptodev_info dev_info;
10663
10664         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10665         uint64_t feat_flags = dev_info.feature_flags;
10666
10667         /* Verify the capabilities */
10668         struct rte_cryptodev_sym_capability_idx cap_idx;
10669         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10670         cap_idx.algo.aead = tdata->algo;
10671         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10672                         &cap_idx) == NULL)
10673                 return TEST_SKIPPED;
10674
10675         /* not supported with CPU crypto and raw data-path APIs*/
10676         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10677                         global_api_test_type == CRYPTODEV_RAW_API_TEST)
10678                 return TEST_SKIPPED;
10679
10680         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10681                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10682                 printf("Device does not support RAW data-path APIs.\n");
10683                 return TEST_SKIPPED;
10684         }
10685
10686         /* Create AEAD session */
10687         retval = create_aead_session(ts_params->valid_devs[0],
10688                         tdata->algo,
10689                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10690                         tdata->key.data, tdata->key.len,
10691                         tdata->aad.len, tdata->auth_tag.len,
10692                         tdata->iv.len);
10693         if (retval < 0)
10694                 return retval;
10695
10696         /* alloc mbuf and set payload */
10697         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10698         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10699
10700         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10701                         rte_pktmbuf_tailroom(ut_params->ibuf));
10702         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10703                         rte_pktmbuf_tailroom(ut_params->obuf));
10704
10705         /* Create AEAD operation */
10706         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10707         if (retval < 0)
10708                 return retval;
10709
10710         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10711
10712         ut_params->op->sym->m_src = ut_params->ibuf;
10713         ut_params->op->sym->m_dst = ut_params->obuf;
10714
10715         /* Process crypto operation */
10716         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10717                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10718                                 ut_params->op, 0, 0, 0, 0);
10719         else
10720                 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10721                         ut_params->op), "failed to process sym crypto op");
10722
10723         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10724                         "crypto op processing failed");
10725
10726         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10727                         ut_params->op->sym->cipher.data.offset);
10728
10729         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10730
10731         /* Validate obuf */
10732         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10733                         plaintext,
10734                         tdata->plaintext.data,
10735                         tdata->plaintext.len,
10736                         "Plaintext data not as expected");
10737
10738         TEST_ASSERT_EQUAL(ut_params->op->status,
10739                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10740                         "Authentication failed");
10741         return 0;
10742 }
10743
10744 static int
10745 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10746 {
10747         return test_authenticated_decryption_oop(&gcm_test_case_5);
10748 }
10749
10750 static int
10751 test_authenticated_encryption_sessionless(
10752                 const struct aead_test_data *tdata)
10753 {
10754         struct crypto_testsuite_params *ts_params = &testsuite_params;
10755         struct crypto_unittest_params *ut_params = &unittest_params;
10756
10757         int retval;
10758         uint8_t *ciphertext, *auth_tag;
10759         uint16_t plaintext_pad_len;
10760         uint8_t key[tdata->key.len + 1];
10761         struct rte_cryptodev_info dev_info;
10762
10763         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10764         uint64_t feat_flags = dev_info.feature_flags;
10765
10766         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10767                 printf("Device doesn't support Sessionless ops.\n");
10768                 return TEST_SKIPPED;
10769         }
10770
10771         /* not supported with CPU crypto */
10772         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10773                 return TEST_SKIPPED;
10774
10775         /* Verify the capabilities */
10776         struct rte_cryptodev_sym_capability_idx cap_idx;
10777         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10778         cap_idx.algo.aead = tdata->algo;
10779         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10780                         &cap_idx) == NULL)
10781                 return TEST_SKIPPED;
10782
10783         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10784
10785         /* clear mbuf payload */
10786         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10787                         rte_pktmbuf_tailroom(ut_params->ibuf));
10788
10789         /* Create AEAD operation */
10790         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10791         if (retval < 0)
10792                 return retval;
10793
10794         /* Create GCM xform */
10795         memcpy(key, tdata->key.data, tdata->key.len);
10796         retval = create_aead_xform(ut_params->op,
10797                         tdata->algo,
10798                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10799                         key, tdata->key.len,
10800                         tdata->aad.len, tdata->auth_tag.len,
10801                         tdata->iv.len);
10802         if (retval < 0)
10803                 return retval;
10804
10805         ut_params->op->sym->m_src = ut_params->ibuf;
10806
10807         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10808                         RTE_CRYPTO_OP_SESSIONLESS,
10809                         "crypto op session type not sessionless");
10810
10811         /* Process crypto operation */
10812         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10813                         ut_params->op), "failed to process sym crypto op");
10814
10815         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10816
10817         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10818                         "crypto op status not success");
10819
10820         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10821
10822         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10823                         ut_params->op->sym->cipher.data.offset);
10824         auth_tag = ciphertext + plaintext_pad_len;
10825
10826         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10827         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10828
10829         /* Validate obuf */
10830         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10831                         ciphertext,
10832                         tdata->ciphertext.data,
10833                         tdata->ciphertext.len,
10834                         "Ciphertext data not as expected");
10835
10836         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10837                         auth_tag,
10838                         tdata->auth_tag.data,
10839                         tdata->auth_tag.len,
10840                         "Generated auth tag not as expected");
10841
10842         return 0;
10843
10844 }
10845
10846 static int
10847 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10848 {
10849         return test_authenticated_encryption_sessionless(
10850                         &gcm_test_case_5);
10851 }
10852
10853 static int
10854 test_authenticated_decryption_sessionless(
10855                 const struct aead_test_data *tdata)
10856 {
10857         struct crypto_testsuite_params *ts_params = &testsuite_params;
10858         struct crypto_unittest_params *ut_params = &unittest_params;
10859
10860         int retval;
10861         uint8_t *plaintext;
10862         uint8_t key[tdata->key.len + 1];
10863         struct rte_cryptodev_info dev_info;
10864
10865         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10866         uint64_t feat_flags = dev_info.feature_flags;
10867
10868         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10869                 printf("Device doesn't support Sessionless ops.\n");
10870                 return TEST_SKIPPED;
10871         }
10872
10873         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10874                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10875                 printf("Device doesn't support RAW data-path APIs.\n");
10876                 return TEST_SKIPPED;
10877         }
10878
10879         /* not supported with CPU crypto */
10880         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10881                 return TEST_SKIPPED;
10882
10883         /* Verify the capabilities */
10884         struct rte_cryptodev_sym_capability_idx cap_idx;
10885         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10886         cap_idx.algo.aead = tdata->algo;
10887         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10888                         &cap_idx) == NULL)
10889                 return TEST_SKIPPED;
10890
10891         /* alloc mbuf and set payload */
10892         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10893
10894         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10895                         rte_pktmbuf_tailroom(ut_params->ibuf));
10896
10897         /* Create AEAD operation */
10898         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10899         if (retval < 0)
10900                 return retval;
10901
10902         /* Create AEAD xform */
10903         memcpy(key, tdata->key.data, tdata->key.len);
10904         retval = create_aead_xform(ut_params->op,
10905                         tdata->algo,
10906                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10907                         key, tdata->key.len,
10908                         tdata->aad.len, tdata->auth_tag.len,
10909                         tdata->iv.len);
10910         if (retval < 0)
10911                 return retval;
10912
10913         ut_params->op->sym->m_src = ut_params->ibuf;
10914
10915         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10916                         RTE_CRYPTO_OP_SESSIONLESS,
10917                         "crypto op session type not sessionless");
10918
10919         /* Process crypto operation */
10920         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10921                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10922                                 ut_params->op, 0, 0, 0, 0);
10923         else
10924                 TEST_ASSERT_NOT_NULL(process_crypto_request(
10925                         ts_params->valid_devs[0], ut_params->op),
10926                                 "failed to process sym crypto op");
10927
10928         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10929
10930         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10931                         "crypto op status not success");
10932
10933         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10934                         ut_params->op->sym->cipher.data.offset);
10935
10936         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10937
10938         /* Validate obuf */
10939         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10940                         plaintext,
10941                         tdata->plaintext.data,
10942                         tdata->plaintext.len,
10943                         "Plaintext data not as expected");
10944
10945         TEST_ASSERT_EQUAL(ut_params->op->status,
10946                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10947                         "Authentication failed");
10948         return 0;
10949 }
10950
10951 static int
10952 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
10953 {
10954         return test_authenticated_decryption_sessionless(
10955                         &gcm_test_case_5);
10956 }
10957
10958 static int
10959 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
10960 {
10961         return test_authenticated_encryption(&ccm_test_case_128_1);
10962 }
10963
10964 static int
10965 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
10966 {
10967         return test_authenticated_encryption(&ccm_test_case_128_2);
10968 }
10969
10970 static int
10971 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
10972 {
10973         return test_authenticated_encryption(&ccm_test_case_128_3);
10974 }
10975
10976 static int
10977 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
10978 {
10979         return test_authenticated_decryption(&ccm_test_case_128_1);
10980 }
10981
10982 static int
10983 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
10984 {
10985         return test_authenticated_decryption(&ccm_test_case_128_2);
10986 }
10987
10988 static int
10989 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10990 {
10991         return test_authenticated_decryption(&ccm_test_case_128_3);
10992 }
10993
10994 static int
10995 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10996 {
10997         return test_authenticated_encryption(&ccm_test_case_192_1);
10998 }
10999
11000 static int
11001 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
11002 {
11003         return test_authenticated_encryption(&ccm_test_case_192_2);
11004 }
11005
11006 static int
11007 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
11008 {
11009         return test_authenticated_encryption(&ccm_test_case_192_3);
11010 }
11011
11012 static int
11013 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
11014 {
11015         return test_authenticated_decryption(&ccm_test_case_192_1);
11016 }
11017
11018 static int
11019 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
11020 {
11021         return test_authenticated_decryption(&ccm_test_case_192_2);
11022 }
11023
11024 static int
11025 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
11026 {
11027         return test_authenticated_decryption(&ccm_test_case_192_3);
11028 }
11029
11030 static int
11031 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
11032 {
11033         return test_authenticated_encryption(&ccm_test_case_256_1);
11034 }
11035
11036 static int
11037 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
11038 {
11039         return test_authenticated_encryption(&ccm_test_case_256_2);
11040 }
11041
11042 static int
11043 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
11044 {
11045         return test_authenticated_encryption(&ccm_test_case_256_3);
11046 }
11047
11048 static int
11049 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
11050 {
11051         return test_authenticated_decryption(&ccm_test_case_256_1);
11052 }
11053
11054 static int
11055 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
11056 {
11057         return test_authenticated_decryption(&ccm_test_case_256_2);
11058 }
11059
11060 static int
11061 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
11062 {
11063         return test_authenticated_decryption(&ccm_test_case_256_3);
11064 }
11065
11066 static int
11067 test_stats(void)
11068 {
11069         struct crypto_testsuite_params *ts_params = &testsuite_params;
11070         struct rte_cryptodev_stats stats;
11071
11072         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11073                 return TEST_SKIPPED;
11074
11075         /* Verify the capabilities */
11076         struct rte_cryptodev_sym_capability_idx cap_idx;
11077         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11078         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
11079         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11080                         &cap_idx) == NULL)
11081                 return TEST_SKIPPED;
11082         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11083         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11084         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11085                         &cap_idx) == NULL)
11086                 return TEST_SKIPPED;
11087
11088         if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
11089                         == -ENOTSUP)
11090                 return TEST_SKIPPED;
11091
11092         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11093         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
11094                         &stats) == -ENODEV),
11095                 "rte_cryptodev_stats_get invalid dev failed");
11096         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
11097                 "rte_cryptodev_stats_get invalid Param failed");
11098
11099         /* Test expected values */
11100         test_AES_CBC_HMAC_SHA1_encrypt_digest();
11101         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11102                         &stats),
11103                 "rte_cryptodev_stats_get failed");
11104         TEST_ASSERT((stats.enqueued_count == 1),
11105                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11106         TEST_ASSERT((stats.dequeued_count == 1),
11107                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11108         TEST_ASSERT((stats.enqueue_err_count == 0),
11109                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11110         TEST_ASSERT((stats.dequeue_err_count == 0),
11111                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11112
11113         /* invalid device but should ignore and not reset device stats*/
11114         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
11115         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11116                         &stats),
11117                 "rte_cryptodev_stats_get failed");
11118         TEST_ASSERT((stats.enqueued_count == 1),
11119                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11120
11121         /* check that a valid reset clears stats */
11122         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11123         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11124                         &stats),
11125                                           "rte_cryptodev_stats_get failed");
11126         TEST_ASSERT((stats.enqueued_count == 0),
11127                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11128         TEST_ASSERT((stats.dequeued_count == 0),
11129                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
11130
11131         return TEST_SUCCESS;
11132 }
11133
11134 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
11135                                    struct crypto_unittest_params *ut_params,
11136                                    enum rte_crypto_auth_operation op,
11137                                    const struct HMAC_MD5_vector *test_case)
11138 {
11139         uint8_t key[64];
11140
11141         memcpy(key, test_case->key.data, test_case->key.len);
11142
11143         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11144         ut_params->auth_xform.next = NULL;
11145         ut_params->auth_xform.auth.op = op;
11146
11147         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
11148
11149         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
11150         ut_params->auth_xform.auth.key.length = test_case->key.len;
11151         ut_params->auth_xform.auth.key.data = key;
11152
11153         ut_params->sess = rte_cryptodev_sym_session_create(
11154                         ts_params->session_mpool);
11155
11156         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11157                         ut_params->sess, &ut_params->auth_xform,
11158                         ts_params->session_priv_mpool);
11159
11160         if (ut_params->sess == NULL)
11161                 return TEST_FAILED;
11162
11163         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11164
11165         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11166                         rte_pktmbuf_tailroom(ut_params->ibuf));
11167
11168         return 0;
11169 }
11170
11171 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
11172                               const struct HMAC_MD5_vector *test_case,
11173                               uint8_t **plaintext)
11174 {
11175         uint16_t plaintext_pad_len;
11176
11177         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11178
11179         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11180                                 16);
11181
11182         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11183                         plaintext_pad_len);
11184         memcpy(*plaintext, test_case->plaintext.data,
11185                         test_case->plaintext.len);
11186
11187         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11188                         ut_params->ibuf, MD5_DIGEST_LEN);
11189         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11190                         "no room to append digest");
11191         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11192                         ut_params->ibuf, plaintext_pad_len);
11193
11194         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11195                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
11196                            test_case->auth_tag.len);
11197         }
11198
11199         sym_op->auth.data.offset = 0;
11200         sym_op->auth.data.length = test_case->plaintext.len;
11201
11202         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11203         ut_params->op->sym->m_src = ut_params->ibuf;
11204
11205         return 0;
11206 }
11207
11208 static int
11209 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
11210 {
11211         uint16_t plaintext_pad_len;
11212         uint8_t *plaintext, *auth_tag;
11213
11214         struct crypto_testsuite_params *ts_params = &testsuite_params;
11215         struct crypto_unittest_params *ut_params = &unittest_params;
11216         struct rte_cryptodev_info dev_info;
11217
11218         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11219         uint64_t feat_flags = dev_info.feature_flags;
11220
11221         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11222                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11223                 printf("Device doesn't support RAW data-path APIs.\n");
11224                 return TEST_SKIPPED;
11225         }
11226
11227         /* Verify the capabilities */
11228         struct rte_cryptodev_sym_capability_idx cap_idx;
11229         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11230         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11231         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11232                         &cap_idx) == NULL)
11233                 return TEST_SKIPPED;
11234
11235         if (MD5_HMAC_create_session(ts_params, ut_params,
11236                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
11237                 return TEST_FAILED;
11238
11239         /* Generate Crypto op data structure */
11240         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11241                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11242         TEST_ASSERT_NOT_NULL(ut_params->op,
11243                         "Failed to allocate symmetric crypto operation struct");
11244
11245         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11246                                 16);
11247
11248         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11249                 return TEST_FAILED;
11250
11251         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11252                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11253                         ut_params->op);
11254         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11255                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11256                                 ut_params->op, 0, 1, 0, 0);
11257         else
11258                 TEST_ASSERT_NOT_NULL(
11259                         process_crypto_request(ts_params->valid_devs[0],
11260                                 ut_params->op),
11261                                 "failed to process sym crypto op");
11262
11263         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11264                         "crypto op processing failed");
11265
11266         if (ut_params->op->sym->m_dst) {
11267                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11268                                 uint8_t *, plaintext_pad_len);
11269         } else {
11270                 auth_tag = plaintext + plaintext_pad_len;
11271         }
11272
11273         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11274                         auth_tag,
11275                         test_case->auth_tag.data,
11276                         test_case->auth_tag.len,
11277                         "HMAC_MD5 generated tag not as expected");
11278
11279         return TEST_SUCCESS;
11280 }
11281
11282 static int
11283 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
11284 {
11285         uint8_t *plaintext;
11286
11287         struct crypto_testsuite_params *ts_params = &testsuite_params;
11288         struct crypto_unittest_params *ut_params = &unittest_params;
11289         struct rte_cryptodev_info dev_info;
11290
11291         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11292         uint64_t feat_flags = dev_info.feature_flags;
11293
11294         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11295                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11296                 printf("Device doesn't support RAW data-path APIs.\n");
11297                 return TEST_SKIPPED;
11298         }
11299
11300         /* Verify the capabilities */
11301         struct rte_cryptodev_sym_capability_idx cap_idx;
11302         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11303         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11304         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11305                         &cap_idx) == NULL)
11306                 return TEST_SKIPPED;
11307
11308         if (MD5_HMAC_create_session(ts_params, ut_params,
11309                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
11310                 return TEST_FAILED;
11311         }
11312
11313         /* Generate Crypto op data structure */
11314         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11315                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11316         TEST_ASSERT_NOT_NULL(ut_params->op,
11317                         "Failed to allocate symmetric crypto operation struct");
11318
11319         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11320                 return TEST_FAILED;
11321
11322         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11323                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11324                         ut_params->op);
11325         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11326                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11327                                 ut_params->op, 0, 1, 0, 0);
11328         else
11329                 TEST_ASSERT_NOT_NULL(
11330                         process_crypto_request(ts_params->valid_devs[0],
11331                                 ut_params->op),
11332                                 "failed to process sym crypto op");
11333
11334         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11335                         "HMAC_MD5 crypto op processing failed");
11336
11337         return TEST_SUCCESS;
11338 }
11339
11340 static int
11341 test_MD5_HMAC_generate_case_1(void)
11342 {
11343         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
11344 }
11345
11346 static int
11347 test_MD5_HMAC_verify_case_1(void)
11348 {
11349         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
11350 }
11351
11352 static int
11353 test_MD5_HMAC_generate_case_2(void)
11354 {
11355         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
11356 }
11357
11358 static int
11359 test_MD5_HMAC_verify_case_2(void)
11360 {
11361         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
11362 }
11363
11364 static int
11365 test_multi_session(void)
11366 {
11367         struct crypto_testsuite_params *ts_params = &testsuite_params;
11368         struct crypto_unittest_params *ut_params = &unittest_params;
11369
11370         struct rte_cryptodev_info dev_info;
11371         struct rte_cryptodev_sym_session **sessions;
11372
11373         uint16_t i;
11374
11375         /* Verify the capabilities */
11376         struct rte_cryptodev_sym_capability_idx cap_idx;
11377         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11378         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11379         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11380                         &cap_idx) == NULL)
11381                 return TEST_SKIPPED;
11382         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11383         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11384         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11385                         &cap_idx) == NULL)
11386                 return TEST_SKIPPED;
11387
11388         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
11389                         aes_cbc_key, hmac_sha512_key);
11390
11391
11392         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11393
11394         sessions = rte_malloc(NULL,
11395                         sizeof(struct rte_cryptodev_sym_session *) *
11396                         (MAX_NB_SESSIONS + 1), 0);
11397
11398         /* Create multiple crypto sessions*/
11399         for (i = 0; i < MAX_NB_SESSIONS; i++) {
11400
11401                 sessions[i] = rte_cryptodev_sym_session_create(
11402                                 ts_params->session_mpool);
11403
11404                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11405                                 sessions[i], &ut_params->auth_xform,
11406                                 ts_params->session_priv_mpool);
11407                 TEST_ASSERT_NOT_NULL(sessions[i],
11408                                 "Session creation failed at session number %u",
11409                                 i);
11410
11411                 /* Attempt to send a request on each session */
11412                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
11413                         sessions[i],
11414                         ut_params,
11415                         ts_params,
11416                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
11417                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
11418                         aes_cbc_iv),
11419                         "Failed to perform decrypt on request number %u.", i);
11420                 /* free crypto operation structure */
11421                 if (ut_params->op)
11422                         rte_crypto_op_free(ut_params->op);
11423
11424                 /*
11425                  * free mbuf - both obuf and ibuf are usually the same,
11426                  * so check if they point at the same address is necessary,
11427                  * to avoid freeing the mbuf twice.
11428                  */
11429                 if (ut_params->obuf) {
11430                         rte_pktmbuf_free(ut_params->obuf);
11431                         if (ut_params->ibuf == ut_params->obuf)
11432                                 ut_params->ibuf = 0;
11433                         ut_params->obuf = 0;
11434                 }
11435                 if (ut_params->ibuf) {
11436                         rte_pktmbuf_free(ut_params->ibuf);
11437                         ut_params->ibuf = 0;
11438                 }
11439         }
11440
11441         sessions[i] = NULL;
11442         /* Next session create should fail */
11443         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11444                         sessions[i], &ut_params->auth_xform,
11445                         ts_params->session_priv_mpool);
11446         TEST_ASSERT_NULL(sessions[i],
11447                         "Session creation succeeded unexpectedly!");
11448
11449         for (i = 0; i < MAX_NB_SESSIONS; i++) {
11450                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11451                                 sessions[i]);
11452                 rte_cryptodev_sym_session_free(sessions[i]);
11453         }
11454
11455         rte_free(sessions);
11456
11457         return TEST_SUCCESS;
11458 }
11459
11460 struct multi_session_params {
11461         struct crypto_unittest_params ut_params;
11462         uint8_t *cipher_key;
11463         uint8_t *hmac_key;
11464         const uint8_t *cipher;
11465         const uint8_t *digest;
11466         uint8_t *iv;
11467 };
11468
11469 #define MB_SESSION_NUMBER 3
11470
11471 static int
11472 test_multi_session_random_usage(void)
11473 {
11474         struct crypto_testsuite_params *ts_params = &testsuite_params;
11475         struct rte_cryptodev_info dev_info;
11476         struct rte_cryptodev_sym_session **sessions;
11477         uint32_t i, j;
11478         struct multi_session_params ut_paramz[] = {
11479
11480                 {
11481                         .cipher_key = ms_aes_cbc_key0,
11482                         .hmac_key = ms_hmac_key0,
11483                         .cipher = ms_aes_cbc_cipher0,
11484                         .digest = ms_hmac_digest0,
11485                         .iv = ms_aes_cbc_iv0
11486                 },
11487                 {
11488                         .cipher_key = ms_aes_cbc_key1,
11489                         .hmac_key = ms_hmac_key1,
11490                         .cipher = ms_aes_cbc_cipher1,
11491                         .digest = ms_hmac_digest1,
11492                         .iv = ms_aes_cbc_iv1
11493                 },
11494                 {
11495                         .cipher_key = ms_aes_cbc_key2,
11496                         .hmac_key = ms_hmac_key2,
11497                         .cipher = ms_aes_cbc_cipher2,
11498                         .digest = ms_hmac_digest2,
11499                         .iv = ms_aes_cbc_iv2
11500                 },
11501
11502         };
11503
11504         /* Verify the capabilities */
11505         struct rte_cryptodev_sym_capability_idx cap_idx;
11506         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11507         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11508         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11509                         &cap_idx) == NULL)
11510                 return TEST_SKIPPED;
11511         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11512         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11513         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11514                         &cap_idx) == NULL)
11515                 return TEST_SKIPPED;
11516
11517         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11518
11519         sessions = rte_malloc(NULL,
11520                         (sizeof(struct rte_cryptodev_sym_session *)
11521                                         * MAX_NB_SESSIONS) + 1, 0);
11522
11523         for (i = 0; i < MB_SESSION_NUMBER; i++) {
11524                 sessions[i] = rte_cryptodev_sym_session_create(
11525                                 ts_params->session_mpool);
11526
11527                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
11528                                 sizeof(struct crypto_unittest_params));
11529
11530                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
11531                                 &ut_paramz[i].ut_params,
11532                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
11533
11534                 /* Create multiple crypto sessions*/
11535                 rte_cryptodev_sym_session_init(
11536                                 ts_params->valid_devs[0],
11537                                 sessions[i],
11538                                 &ut_paramz[i].ut_params.auth_xform,
11539                                 ts_params->session_priv_mpool);
11540
11541                 TEST_ASSERT_NOT_NULL(sessions[i],
11542                                 "Session creation failed at session number %u",
11543                                 i);
11544
11545         }
11546
11547         srand(time(NULL));
11548         for (i = 0; i < 40000; i++) {
11549
11550                 j = rand() % MB_SESSION_NUMBER;
11551
11552                 TEST_ASSERT_SUCCESS(
11553                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
11554                                         sessions[j],
11555                                         &ut_paramz[j].ut_params,
11556                                         ts_params, ut_paramz[j].cipher,
11557                                         ut_paramz[j].digest,
11558                                         ut_paramz[j].iv),
11559                         "Failed to perform decrypt on request number %u.", i);
11560
11561                 if (ut_paramz[j].ut_params.op)
11562                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
11563
11564                 /*
11565                  * free mbuf - both obuf and ibuf are usually the same,
11566                  * so check if they point at the same address is necessary,
11567                  * to avoid freeing the mbuf twice.
11568                  */
11569                 if (ut_paramz[j].ut_params.obuf) {
11570                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
11571                         if (ut_paramz[j].ut_params.ibuf
11572                                         == ut_paramz[j].ut_params.obuf)
11573                                 ut_paramz[j].ut_params.ibuf = 0;
11574                         ut_paramz[j].ut_params.obuf = 0;
11575                 }
11576                 if (ut_paramz[j].ut_params.ibuf) {
11577                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
11578                         ut_paramz[j].ut_params.ibuf = 0;
11579                 }
11580         }
11581
11582         for (i = 0; i < MB_SESSION_NUMBER; i++) {
11583                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11584                                 sessions[i]);
11585                 rte_cryptodev_sym_session_free(sessions[i]);
11586         }
11587
11588         rte_free(sessions);
11589
11590         return TEST_SUCCESS;
11591 }
11592
11593 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
11594                         0xab, 0xab, 0xab, 0xab,
11595                         0xab, 0xab, 0xab, 0xab,
11596                         0xab, 0xab, 0xab, 0xab};
11597
11598 static int
11599 test_null_invalid_operation(void)
11600 {
11601         struct crypto_testsuite_params *ts_params = &testsuite_params;
11602         struct crypto_unittest_params *ut_params = &unittest_params;
11603         int ret;
11604
11605         /* This test is for NULL PMD only */
11606         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11607                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11608                 return TEST_SKIPPED;
11609
11610         /* Setup Cipher Parameters */
11611         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11612         ut_params->cipher_xform.next = NULL;
11613
11614         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
11615         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11616
11617         ut_params->sess = rte_cryptodev_sym_session_create(
11618                         ts_params->session_mpool);
11619
11620         /* Create Crypto session*/
11621         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11622                         ut_params->sess, &ut_params->cipher_xform,
11623                         ts_params->session_priv_mpool);
11624         TEST_ASSERT(ret < 0,
11625                         "Session creation succeeded unexpectedly");
11626
11627
11628         /* Setup HMAC Parameters */
11629         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11630         ut_params->auth_xform.next = NULL;
11631
11632         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
11633         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11634
11635         ut_params->sess = rte_cryptodev_sym_session_create(
11636                         ts_params->session_mpool);
11637
11638         /* Create Crypto session*/
11639         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11640                         ut_params->sess, &ut_params->auth_xform,
11641                         ts_params->session_priv_mpool);
11642         TEST_ASSERT(ret < 0,
11643                         "Session creation succeeded unexpectedly");
11644
11645         return TEST_SUCCESS;
11646 }
11647
11648
11649 #define NULL_BURST_LENGTH (32)
11650
11651 static int
11652 test_null_burst_operation(void)
11653 {
11654         struct crypto_testsuite_params *ts_params = &testsuite_params;
11655         struct crypto_unittest_params *ut_params = &unittest_params;
11656
11657         unsigned i, burst_len = NULL_BURST_LENGTH;
11658
11659         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11660         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11661
11662         /* This test is for NULL PMD only */
11663         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11664                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11665                 return TEST_SKIPPED;
11666
11667         /* Setup Cipher Parameters */
11668         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11669         ut_params->cipher_xform.next = &ut_params->auth_xform;
11670
11671         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11672         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11673
11674         /* Setup HMAC Parameters */
11675         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11676         ut_params->auth_xform.next = NULL;
11677
11678         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11679         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11680
11681         ut_params->sess = rte_cryptodev_sym_session_create(
11682                         ts_params->session_mpool);
11683
11684         /* Create Crypto session*/
11685         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11686                         ut_params->sess, &ut_params->cipher_xform,
11687                         ts_params->session_priv_mpool);
11688         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11689
11690         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11691                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11692                         burst_len, "failed to generate burst of crypto ops");
11693
11694         /* Generate an operation for each mbuf in burst */
11695         for (i = 0; i < burst_len; i++) {
11696                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11697
11698                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11699
11700                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11701                                 sizeof(unsigned));
11702                 *data = i;
11703
11704                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11705
11706                 burst[i]->sym->m_src = m;
11707         }
11708
11709         /* Process crypto operation */
11710         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11711                         0, burst, burst_len),
11712                         burst_len,
11713                         "Error enqueuing burst");
11714
11715         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11716                         0, burst_dequeued, burst_len),
11717                         burst_len,
11718                         "Error dequeuing burst");
11719
11720
11721         for (i = 0; i < burst_len; i++) {
11722                 TEST_ASSERT_EQUAL(
11723                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11724                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11725                                         uint32_t *),
11726                         "data not as expected");
11727
11728                 rte_pktmbuf_free(burst[i]->sym->m_src);
11729                 rte_crypto_op_free(burst[i]);
11730         }
11731
11732         return TEST_SUCCESS;
11733 }
11734
11735 static uint16_t
11736 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11737                   uint16_t nb_ops, void *user_param)
11738 {
11739         RTE_SET_USED(dev_id);
11740         RTE_SET_USED(qp_id);
11741         RTE_SET_USED(ops);
11742         RTE_SET_USED(user_param);
11743
11744         printf("crypto enqueue callback called\n");
11745         return nb_ops;
11746 }
11747
11748 static uint16_t
11749 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11750                   uint16_t nb_ops, void *user_param)
11751 {
11752         RTE_SET_USED(dev_id);
11753         RTE_SET_USED(qp_id);
11754         RTE_SET_USED(ops);
11755         RTE_SET_USED(user_param);
11756
11757         printf("crypto dequeue callback called\n");
11758         return nb_ops;
11759 }
11760
11761 /*
11762  * Thread using enqueue/dequeue callback with RCU.
11763  */
11764 static int
11765 test_enqdeq_callback_thread(void *arg)
11766 {
11767         RTE_SET_USED(arg);
11768         /* DP thread calls rte_cryptodev_enqueue_burst()/
11769          * rte_cryptodev_dequeue_burst() and invokes callback.
11770          */
11771         test_null_burst_operation();
11772         return 0;
11773 }
11774
11775 static int
11776 test_enq_callback_setup(void)
11777 {
11778         struct crypto_testsuite_params *ts_params = &testsuite_params;
11779         struct rte_cryptodev_info dev_info;
11780         struct rte_cryptodev_qp_conf qp_conf = {
11781                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11782         };
11783
11784         struct rte_cryptodev_cb *cb;
11785         uint16_t qp_id = 0;
11786
11787         /* Stop the device in case it's started so it can be configured */
11788         rte_cryptodev_stop(ts_params->valid_devs[0]);
11789
11790         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11791
11792         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11793                         &ts_params->conf),
11794                         "Failed to configure cryptodev %u",
11795                         ts_params->valid_devs[0]);
11796
11797         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11798         qp_conf.mp_session = ts_params->session_mpool;
11799         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11800
11801         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11802                         ts_params->valid_devs[0], qp_id, &qp_conf,
11803                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11804                         "Failed test for "
11805                         "rte_cryptodev_queue_pair_setup: num_inflights "
11806                         "%u on qp %u on cryptodev %u",
11807                         qp_conf.nb_descriptors, qp_id,
11808                         ts_params->valid_devs[0]);
11809
11810         /* Test with invalid crypto device */
11811         cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11812                         qp_id, test_enq_callback, NULL);
11813         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11814                         "cryptodev %u did not fail",
11815                         qp_id, RTE_CRYPTO_MAX_DEVS);
11816
11817         /* Test with invalid queue pair */
11818         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11819                         dev_info.max_nb_queue_pairs + 1,
11820                         test_enq_callback, NULL);
11821         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11822                         "cryptodev %u did not fail",
11823                         dev_info.max_nb_queue_pairs + 1,
11824                         ts_params->valid_devs[0]);
11825
11826         /* Test with NULL callback */
11827         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11828                         qp_id, NULL, NULL);
11829         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11830                         "cryptodev %u did not fail",
11831                         qp_id, ts_params->valid_devs[0]);
11832
11833         /* Test with valid configuration */
11834         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11835                         qp_id, test_enq_callback, NULL);
11836         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11837                         "qp %u on cryptodev %u",
11838                         qp_id, ts_params->valid_devs[0]);
11839
11840         rte_cryptodev_start(ts_params->valid_devs[0]);
11841
11842         /* Launch a thread */
11843         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11844                                 rte_get_next_lcore(-1, 1, 0));
11845
11846         /* Wait until reader exited. */
11847         rte_eal_mp_wait_lcore();
11848
11849         /* Test with invalid crypto device */
11850         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11851                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11852                         "Expected call to fail as crypto device is invalid");
11853
11854         /* Test with invalid queue pair */
11855         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11856                         ts_params->valid_devs[0],
11857                         dev_info.max_nb_queue_pairs + 1, cb),
11858                         "Expected call to fail as queue pair is invalid");
11859
11860         /* Test with NULL callback */
11861         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11862                         ts_params->valid_devs[0], qp_id, NULL),
11863                         "Expected call to fail as callback is NULL");
11864
11865         /* Test with valid configuration */
11866         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11867                         ts_params->valid_devs[0], qp_id, cb),
11868                         "Failed test to remove callback on "
11869                         "qp %u on cryptodev %u",
11870                         qp_id, ts_params->valid_devs[0]);
11871
11872         return TEST_SUCCESS;
11873 }
11874
11875 static int
11876 test_deq_callback_setup(void)
11877 {
11878         struct crypto_testsuite_params *ts_params = &testsuite_params;
11879         struct rte_cryptodev_info dev_info;
11880         struct rte_cryptodev_qp_conf qp_conf = {
11881                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11882         };
11883
11884         struct rte_cryptodev_cb *cb;
11885         uint16_t qp_id = 0;
11886
11887         /* Stop the device in case it's started so it can be configured */
11888         rte_cryptodev_stop(ts_params->valid_devs[0]);
11889
11890         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11891
11892         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11893                         &ts_params->conf),
11894                         "Failed to configure cryptodev %u",
11895                         ts_params->valid_devs[0]);
11896
11897         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11898         qp_conf.mp_session = ts_params->session_mpool;
11899         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11900
11901         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11902                         ts_params->valid_devs[0], qp_id, &qp_conf,
11903                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11904                         "Failed test for "
11905                         "rte_cryptodev_queue_pair_setup: num_inflights "
11906                         "%u on qp %u on cryptodev %u",
11907                         qp_conf.nb_descriptors, qp_id,
11908                         ts_params->valid_devs[0]);
11909
11910         /* Test with invalid crypto device */
11911         cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11912                         qp_id, test_deq_callback, NULL);
11913         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11914                         "cryptodev %u did not fail",
11915                         qp_id, RTE_CRYPTO_MAX_DEVS);
11916
11917         /* Test with invalid queue pair */
11918         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11919                         dev_info.max_nb_queue_pairs + 1,
11920                         test_deq_callback, NULL);
11921         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11922                         "cryptodev %u did not fail",
11923                         dev_info.max_nb_queue_pairs + 1,
11924                         ts_params->valid_devs[0]);
11925
11926         /* Test with NULL callback */
11927         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11928                         qp_id, NULL, NULL);
11929         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11930                         "cryptodev %u did not fail",
11931                         qp_id, ts_params->valid_devs[0]);
11932
11933         /* Test with valid configuration */
11934         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11935                         qp_id, test_deq_callback, NULL);
11936         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11937                         "qp %u on cryptodev %u",
11938                         qp_id, ts_params->valid_devs[0]);
11939
11940         rte_cryptodev_start(ts_params->valid_devs[0]);
11941
11942         /* Launch a thread */
11943         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11944                                 rte_get_next_lcore(-1, 1, 0));
11945
11946         /* Wait until reader exited. */
11947         rte_eal_mp_wait_lcore();
11948
11949         /* Test with invalid crypto device */
11950         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11951                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11952                         "Expected call to fail as crypto device is invalid");
11953
11954         /* Test with invalid queue pair */
11955         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11956                         ts_params->valid_devs[0],
11957                         dev_info.max_nb_queue_pairs + 1, cb),
11958                         "Expected call to fail as queue pair is invalid");
11959
11960         /* Test with NULL callback */
11961         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11962                         ts_params->valid_devs[0], qp_id, NULL),
11963                         "Expected call to fail as callback is NULL");
11964
11965         /* Test with valid configuration */
11966         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
11967                         ts_params->valid_devs[0], qp_id, cb),
11968                         "Failed test to remove callback on "
11969                         "qp %u on cryptodev %u",
11970                         qp_id, ts_params->valid_devs[0]);
11971
11972         return TEST_SUCCESS;
11973 }
11974
11975 static void
11976 generate_gmac_large_plaintext(uint8_t *data)
11977 {
11978         uint16_t i;
11979
11980         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
11981                 memcpy(&data[i], &data[0], 32);
11982 }
11983
11984 static int
11985 create_gmac_operation(enum rte_crypto_auth_operation op,
11986                 const struct gmac_test_data *tdata)
11987 {
11988         struct crypto_testsuite_params *ts_params = &testsuite_params;
11989         struct crypto_unittest_params *ut_params = &unittest_params;
11990         struct rte_crypto_sym_op *sym_op;
11991
11992         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11993
11994         /* Generate Crypto op data structure */
11995         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11996                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11997         TEST_ASSERT_NOT_NULL(ut_params->op,
11998                         "Failed to allocate symmetric crypto operation struct");
11999
12000         sym_op = ut_params->op->sym;
12001
12002         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12003                         ut_params->ibuf, tdata->gmac_tag.len);
12004         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12005                         "no room to append digest");
12006
12007         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12008                         ut_params->ibuf, plaintext_pad_len);
12009
12010         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12011                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12012                                 tdata->gmac_tag.len);
12013                 debug_hexdump(stdout, "digest:",
12014                                 sym_op->auth.digest.data,
12015                                 tdata->gmac_tag.len);
12016         }
12017
12018         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12019                         uint8_t *, IV_OFFSET);
12020
12021         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12022
12023         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12024
12025         sym_op->cipher.data.length = 0;
12026         sym_op->cipher.data.offset = 0;
12027
12028         sym_op->auth.data.offset = 0;
12029         sym_op->auth.data.length = tdata->plaintext.len;
12030
12031         return 0;
12032 }
12033
12034 static int
12035 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
12036                 const struct gmac_test_data *tdata,
12037                 void *digest_mem, uint64_t digest_phys)
12038 {
12039         struct crypto_testsuite_params *ts_params = &testsuite_params;
12040         struct crypto_unittest_params *ut_params = &unittest_params;
12041         struct rte_crypto_sym_op *sym_op;
12042
12043         /* Generate Crypto op data structure */
12044         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12045                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12046         TEST_ASSERT_NOT_NULL(ut_params->op,
12047                         "Failed to allocate symmetric crypto operation struct");
12048
12049         sym_op = ut_params->op->sym;
12050
12051         sym_op->auth.digest.data = digest_mem;
12052         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12053                         "no room to append digest");
12054
12055         sym_op->auth.digest.phys_addr = digest_phys;
12056
12057         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12058                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12059                                 tdata->gmac_tag.len);
12060                 debug_hexdump(stdout, "digest:",
12061                                 sym_op->auth.digest.data,
12062                                 tdata->gmac_tag.len);
12063         }
12064
12065         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12066                         uint8_t *, IV_OFFSET);
12067
12068         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12069
12070         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12071
12072         sym_op->cipher.data.length = 0;
12073         sym_op->cipher.data.offset = 0;
12074
12075         sym_op->auth.data.offset = 0;
12076         sym_op->auth.data.length = tdata->plaintext.len;
12077
12078         return 0;
12079 }
12080
12081 static int create_gmac_session(uint8_t dev_id,
12082                 const struct gmac_test_data *tdata,
12083                 enum rte_crypto_auth_operation auth_op)
12084 {
12085         uint8_t auth_key[tdata->key.len];
12086
12087         struct crypto_testsuite_params *ts_params = &testsuite_params;
12088         struct crypto_unittest_params *ut_params = &unittest_params;
12089
12090         memcpy(auth_key, tdata->key.data, tdata->key.len);
12091
12092         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12093         ut_params->auth_xform.next = NULL;
12094
12095         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
12096         ut_params->auth_xform.auth.op = auth_op;
12097         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
12098         ut_params->auth_xform.auth.key.length = tdata->key.len;
12099         ut_params->auth_xform.auth.key.data = auth_key;
12100         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12101         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
12102
12103
12104         ut_params->sess = rte_cryptodev_sym_session_create(
12105                         ts_params->session_mpool);
12106
12107         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12108                         &ut_params->auth_xform,
12109                         ts_params->session_priv_mpool);
12110
12111         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12112
12113         return 0;
12114 }
12115
12116 static int
12117 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
12118 {
12119         struct crypto_testsuite_params *ts_params = &testsuite_params;
12120         struct crypto_unittest_params *ut_params = &unittest_params;
12121         struct rte_cryptodev_info dev_info;
12122
12123         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12124         uint64_t feat_flags = dev_info.feature_flags;
12125
12126         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12127                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12128                 printf("Device doesn't support RAW data-path APIs.\n");
12129                 return TEST_SKIPPED;
12130         }
12131
12132         int retval;
12133
12134         uint8_t *auth_tag, *plaintext;
12135         uint16_t plaintext_pad_len;
12136
12137         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12138                               "No GMAC length in the source data");
12139
12140         /* Verify the capabilities */
12141         struct rte_cryptodev_sym_capability_idx cap_idx;
12142         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12143         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12144         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12145                         &cap_idx) == NULL)
12146                 return TEST_SKIPPED;
12147
12148         retval = create_gmac_session(ts_params->valid_devs[0],
12149                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12150
12151         if (retval < 0)
12152                 return retval;
12153
12154         if (tdata->plaintext.len > MBUF_SIZE)
12155                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12156         else
12157                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12158         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12159                         "Failed to allocate input buffer in mempool");
12160
12161         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12162                         rte_pktmbuf_tailroom(ut_params->ibuf));
12163
12164         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12165         /*
12166          * Runtime generate the large plain text instead of use hard code
12167          * plain text vector. It is done to avoid create huge source file
12168          * with the test vector.
12169          */
12170         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12171                 generate_gmac_large_plaintext(tdata->plaintext.data);
12172
12173         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12174                                 plaintext_pad_len);
12175         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12176
12177         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12178         debug_hexdump(stdout, "plaintext:", plaintext,
12179                         tdata->plaintext.len);
12180
12181         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
12182                         tdata);
12183
12184         if (retval < 0)
12185                 return retval;
12186
12187         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12188
12189         ut_params->op->sym->m_src = ut_params->ibuf;
12190
12191         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12192                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12193                         ut_params->op);
12194         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12195                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12196                                 ut_params->op, 0, 1, 0, 0);
12197         else
12198                 TEST_ASSERT_NOT_NULL(
12199                         process_crypto_request(ts_params->valid_devs[0],
12200                         ut_params->op), "failed to process sym crypto op");
12201
12202         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12203                         "crypto op processing failed");
12204
12205         if (ut_params->op->sym->m_dst) {
12206                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12207                                 uint8_t *, plaintext_pad_len);
12208         } else {
12209                 auth_tag = plaintext + plaintext_pad_len;
12210         }
12211
12212         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12213
12214         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12215                         auth_tag,
12216                         tdata->gmac_tag.data,
12217                         tdata->gmac_tag.len,
12218                         "GMAC Generated auth tag not as expected");
12219
12220         return 0;
12221 }
12222
12223 static int
12224 test_AES_GMAC_authentication_test_case_1(void)
12225 {
12226         return test_AES_GMAC_authentication(&gmac_test_case_1);
12227 }
12228
12229 static int
12230 test_AES_GMAC_authentication_test_case_2(void)
12231 {
12232         return test_AES_GMAC_authentication(&gmac_test_case_2);
12233 }
12234
12235 static int
12236 test_AES_GMAC_authentication_test_case_3(void)
12237 {
12238         return test_AES_GMAC_authentication(&gmac_test_case_3);
12239 }
12240
12241 static int
12242 test_AES_GMAC_authentication_test_case_4(void)
12243 {
12244         return test_AES_GMAC_authentication(&gmac_test_case_4);
12245 }
12246
12247 static int
12248 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
12249 {
12250         struct crypto_testsuite_params *ts_params = &testsuite_params;
12251         struct crypto_unittest_params *ut_params = &unittest_params;
12252         int retval;
12253         uint32_t plaintext_pad_len;
12254         uint8_t *plaintext;
12255         struct rte_cryptodev_info dev_info;
12256
12257         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12258         uint64_t feat_flags = dev_info.feature_flags;
12259
12260         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12261                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12262                 printf("Device doesn't support RAW data-path APIs.\n");
12263                 return TEST_SKIPPED;
12264         }
12265
12266         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12267                               "No GMAC length in the source data");
12268
12269         /* Verify the capabilities */
12270         struct rte_cryptodev_sym_capability_idx cap_idx;
12271         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12272         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12273         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12274                         &cap_idx) == NULL)
12275                 return TEST_SKIPPED;
12276
12277         retval = create_gmac_session(ts_params->valid_devs[0],
12278                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
12279
12280         if (retval < 0)
12281                 return retval;
12282
12283         if (tdata->plaintext.len > MBUF_SIZE)
12284                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12285         else
12286                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12287         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12288                         "Failed to allocate input buffer in mempool");
12289
12290         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12291                         rte_pktmbuf_tailroom(ut_params->ibuf));
12292
12293         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12294
12295         /*
12296          * Runtime generate the large plain text instead of use hard code
12297          * plain text vector. It is done to avoid create huge source file
12298          * with the test vector.
12299          */
12300         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12301                 generate_gmac_large_plaintext(tdata->plaintext.data);
12302
12303         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12304                                 plaintext_pad_len);
12305         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12306
12307         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12308         debug_hexdump(stdout, "plaintext:", plaintext,
12309                         tdata->plaintext.len);
12310
12311         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
12312                         tdata);
12313
12314         if (retval < 0)
12315                 return retval;
12316
12317         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12318
12319         ut_params->op->sym->m_src = ut_params->ibuf;
12320
12321         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12322                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12323                         ut_params->op);
12324         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12325                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12326                                 ut_params->op, 0, 1, 0, 0);
12327         else
12328                 TEST_ASSERT_NOT_NULL(
12329                         process_crypto_request(ts_params->valid_devs[0],
12330                         ut_params->op), "failed to process sym crypto op");
12331
12332         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12333                         "crypto op processing failed");
12334
12335         return 0;
12336
12337 }
12338
12339 static int
12340 test_AES_GMAC_authentication_verify_test_case_1(void)
12341 {
12342         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
12343 }
12344
12345 static int
12346 test_AES_GMAC_authentication_verify_test_case_2(void)
12347 {
12348         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
12349 }
12350
12351 static int
12352 test_AES_GMAC_authentication_verify_test_case_3(void)
12353 {
12354         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
12355 }
12356
12357 static int
12358 test_AES_GMAC_authentication_verify_test_case_4(void)
12359 {
12360         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
12361 }
12362
12363 static int
12364 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
12365                                 uint32_t fragsz)
12366 {
12367         struct crypto_testsuite_params *ts_params = &testsuite_params;
12368         struct crypto_unittest_params *ut_params = &unittest_params;
12369         struct rte_cryptodev_info dev_info;
12370         uint64_t feature_flags;
12371         unsigned int trn_data = 0;
12372         void *digest_mem = NULL;
12373         uint32_t segs = 1;
12374         unsigned int to_trn = 0;
12375         struct rte_mbuf *buf = NULL;
12376         uint8_t *auth_tag, *plaintext;
12377         int retval;
12378
12379         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12380                               "No GMAC length in the source data");
12381
12382         /* Verify the capabilities */
12383         struct rte_cryptodev_sym_capability_idx cap_idx;
12384         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12385         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12386         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12387                         &cap_idx) == NULL)
12388                 return TEST_SKIPPED;
12389
12390         /* Check for any input SGL support */
12391         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12392         feature_flags = dev_info.feature_flags;
12393
12394         if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
12395                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
12396                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
12397                 return TEST_SKIPPED;
12398
12399         if (fragsz > tdata->plaintext.len)
12400                 fragsz = tdata->plaintext.len;
12401
12402         uint16_t plaintext_len = fragsz;
12403
12404         retval = create_gmac_session(ts_params->valid_devs[0],
12405                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12406
12407         if (retval < 0)
12408                 return retval;
12409
12410         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12411         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12412                         "Failed to allocate input buffer in mempool");
12413
12414         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12415                         rte_pktmbuf_tailroom(ut_params->ibuf));
12416
12417         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12418                                 plaintext_len);
12419         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12420
12421         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12422
12423         trn_data += plaintext_len;
12424
12425         buf = ut_params->ibuf;
12426
12427         /*
12428          * Loop until no more fragments
12429          */
12430
12431         while (trn_data < tdata->plaintext.len) {
12432                 ++segs;
12433                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
12434                                 (tdata->plaintext.len - trn_data) : fragsz;
12435
12436                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12437                 buf = buf->next;
12438
12439                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
12440                                 rte_pktmbuf_tailroom(buf));
12441
12442                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
12443                                 to_trn);
12444
12445                 memcpy(plaintext, tdata->plaintext.data + trn_data,
12446                                 to_trn);
12447                 trn_data += to_trn;
12448                 if (trn_data  == tdata->plaintext.len)
12449                         digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
12450                                         tdata->gmac_tag.len);
12451         }
12452         ut_params->ibuf->nb_segs = segs;
12453
12454         /*
12455          * Place digest at the end of the last buffer
12456          */
12457         uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
12458
12459         if (!digest_mem) {
12460                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12461                                 + tdata->gmac_tag.len);
12462                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
12463                                 tdata->plaintext.len);
12464         }
12465
12466         retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
12467                         tdata, digest_mem, digest_phys);
12468
12469         if (retval < 0)
12470                 return retval;
12471
12472         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12473
12474         ut_params->op->sym->m_src = ut_params->ibuf;
12475
12476         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12477                 return TEST_SKIPPED;
12478
12479         TEST_ASSERT_NOT_NULL(
12480                 process_crypto_request(ts_params->valid_devs[0],
12481                 ut_params->op), "failed to process sym crypto op");
12482
12483         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12484                         "crypto op processing failed");
12485
12486         auth_tag = digest_mem;
12487         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12488         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12489                         auth_tag,
12490                         tdata->gmac_tag.data,
12491                         tdata->gmac_tag.len,
12492                         "GMAC Generated auth tag not as expected");
12493
12494         return 0;
12495 }
12496
12497 /* Segment size not multiple of block size (16B) */
12498 static int
12499 test_AES_GMAC_authentication_SGL_40B(void)
12500 {
12501         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
12502 }
12503
12504 static int
12505 test_AES_GMAC_authentication_SGL_80B(void)
12506 {
12507         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
12508 }
12509
12510 static int
12511 test_AES_GMAC_authentication_SGL_2048B(void)
12512 {
12513         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
12514 }
12515
12516 /* Segment size not multiple of block size (16B) */
12517 static int
12518 test_AES_GMAC_authentication_SGL_2047B(void)
12519 {
12520         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
12521 }
12522
12523 struct test_crypto_vector {
12524         enum rte_crypto_cipher_algorithm crypto_algo;
12525         unsigned int cipher_offset;
12526         unsigned int cipher_len;
12527
12528         struct {
12529                 uint8_t data[64];
12530                 unsigned int len;
12531         } cipher_key;
12532
12533         struct {
12534                 uint8_t data[64];
12535                 unsigned int len;
12536         } iv;
12537
12538         struct {
12539                 const uint8_t *data;
12540                 unsigned int len;
12541         } plaintext;
12542
12543         struct {
12544                 const uint8_t *data;
12545                 unsigned int len;
12546         } ciphertext;
12547
12548         enum rte_crypto_auth_algorithm auth_algo;
12549         unsigned int auth_offset;
12550
12551         struct {
12552                 uint8_t data[128];
12553                 unsigned int len;
12554         } auth_key;
12555
12556         struct {
12557                 const uint8_t *data;
12558                 unsigned int len;
12559         } aad;
12560
12561         struct {
12562                 uint8_t data[128];
12563                 unsigned int len;
12564         } digest;
12565 };
12566
12567 static const struct test_crypto_vector
12568 hmac_sha1_test_crypto_vector = {
12569         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12570         .plaintext = {
12571                 .data = plaintext_hash,
12572                 .len = 512
12573         },
12574         .auth_key = {
12575                 .data = {
12576                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12577                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12578                         0xDE, 0xF4, 0xDE, 0xAD
12579                 },
12580                 .len = 20
12581         },
12582         .digest = {
12583                 .data = {
12584                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
12585                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
12586                         0x3F, 0x91, 0x64, 0x59
12587                 },
12588                 .len = 20
12589         }
12590 };
12591
12592 static const struct test_crypto_vector
12593 aes128_gmac_test_vector = {
12594         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
12595         .plaintext = {
12596                 .data = plaintext_hash,
12597                 .len = 512
12598         },
12599         .iv = {
12600                 .data = {
12601                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12602                         0x08, 0x09, 0x0A, 0x0B
12603                 },
12604                 .len = 12
12605         },
12606         .auth_key = {
12607                 .data = {
12608                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12609                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
12610                 },
12611                 .len = 16
12612         },
12613         .digest = {
12614                 .data = {
12615                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
12616                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
12617                 },
12618                 .len = 16
12619         }
12620 };
12621
12622 static const struct test_crypto_vector
12623 aes128cbc_hmac_sha1_test_vector = {
12624         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12625         .cipher_offset = 0,
12626         .cipher_len = 512,
12627         .cipher_key = {
12628                 .data = {
12629                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12630                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12631                 },
12632                 .len = 16
12633         },
12634         .iv = {
12635                 .data = {
12636                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12637                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12638                 },
12639                 .len = 16
12640         },
12641         .plaintext = {
12642                 .data = plaintext_hash,
12643                 .len = 512
12644         },
12645         .ciphertext = {
12646                 .data = ciphertext512_aes128cbc,
12647                 .len = 512
12648         },
12649         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12650         .auth_offset = 0,
12651         .auth_key = {
12652                 .data = {
12653                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12654                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12655                         0xDE, 0xF4, 0xDE, 0xAD
12656                 },
12657                 .len = 20
12658         },
12659         .digest = {
12660                 .data = {
12661                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12662                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12663                         0x18, 0x8C, 0x1D, 0x32
12664                 },
12665                 .len = 20
12666         }
12667 };
12668
12669 static const struct test_crypto_vector
12670 aes128cbc_hmac_sha1_aad_test_vector = {
12671         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12672         .cipher_offset = 8,
12673         .cipher_len = 496,
12674         .cipher_key = {
12675                 .data = {
12676                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12677                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12678                 },
12679                 .len = 16
12680         },
12681         .iv = {
12682                 .data = {
12683                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12684                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12685                 },
12686                 .len = 16
12687         },
12688         .plaintext = {
12689                 .data = plaintext_hash,
12690                 .len = 512
12691         },
12692         .ciphertext = {
12693                 .data = ciphertext512_aes128cbc_aad,
12694                 .len = 512
12695         },
12696         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12697         .auth_offset = 0,
12698         .auth_key = {
12699                 .data = {
12700                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12701                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12702                         0xDE, 0xF4, 0xDE, 0xAD
12703                 },
12704                 .len = 20
12705         },
12706         .digest = {
12707                 .data = {
12708                         0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12709                         0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12710                         0x62, 0x0F, 0xFB, 0x10
12711                 },
12712                 .len = 20
12713         }
12714 };
12715
12716 static void
12717 data_corruption(uint8_t *data)
12718 {
12719         data[0] += 1;
12720 }
12721
12722 static void
12723 tag_corruption(uint8_t *data, unsigned int tag_offset)
12724 {
12725         data[tag_offset] += 1;
12726 }
12727
12728 static int
12729 create_auth_session(struct crypto_unittest_params *ut_params,
12730                 uint8_t dev_id,
12731                 const struct test_crypto_vector *reference,
12732                 enum rte_crypto_auth_operation auth_op)
12733 {
12734         struct crypto_testsuite_params *ts_params = &testsuite_params;
12735         uint8_t auth_key[reference->auth_key.len + 1];
12736
12737         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12738
12739         /* Setup Authentication Parameters */
12740         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12741         ut_params->auth_xform.auth.op = auth_op;
12742         ut_params->auth_xform.next = NULL;
12743         ut_params->auth_xform.auth.algo = reference->auth_algo;
12744         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12745         ut_params->auth_xform.auth.key.data = auth_key;
12746         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12747
12748         /* Create Crypto session*/
12749         ut_params->sess = rte_cryptodev_sym_session_create(
12750                         ts_params->session_mpool);
12751
12752         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12753                                 &ut_params->auth_xform,
12754                                 ts_params->session_priv_mpool);
12755
12756         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12757
12758         return 0;
12759 }
12760
12761 static int
12762 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12763                 uint8_t dev_id,
12764                 const struct test_crypto_vector *reference,
12765                 enum rte_crypto_auth_operation auth_op,
12766                 enum rte_crypto_cipher_operation cipher_op)
12767 {
12768         struct crypto_testsuite_params *ts_params = &testsuite_params;
12769         uint8_t cipher_key[reference->cipher_key.len + 1];
12770         uint8_t auth_key[reference->auth_key.len + 1];
12771
12772         memcpy(cipher_key, reference->cipher_key.data,
12773                         reference->cipher_key.len);
12774         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12775
12776         /* Setup Authentication Parameters */
12777         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12778         ut_params->auth_xform.auth.op = auth_op;
12779         ut_params->auth_xform.auth.algo = reference->auth_algo;
12780         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12781         ut_params->auth_xform.auth.key.data = auth_key;
12782         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12783
12784         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12785                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12786                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
12787         } else {
12788                 ut_params->auth_xform.next = &ut_params->cipher_xform;
12789
12790                 /* Setup Cipher Parameters */
12791                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12792                 ut_params->cipher_xform.next = NULL;
12793                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12794                 ut_params->cipher_xform.cipher.op = cipher_op;
12795                 ut_params->cipher_xform.cipher.key.data = cipher_key;
12796                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12797                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12798                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12799         }
12800
12801         /* Create Crypto session*/
12802         ut_params->sess = rte_cryptodev_sym_session_create(
12803                         ts_params->session_mpool);
12804
12805         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12806                                 &ut_params->auth_xform,
12807                                 ts_params->session_priv_mpool);
12808
12809         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12810
12811         return 0;
12812 }
12813
12814 static int
12815 create_auth_operation(struct crypto_testsuite_params *ts_params,
12816                 struct crypto_unittest_params *ut_params,
12817                 const struct test_crypto_vector *reference,
12818                 unsigned int auth_generate)
12819 {
12820         /* Generate Crypto op data structure */
12821         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12822                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12823         TEST_ASSERT_NOT_NULL(ut_params->op,
12824                         "Failed to allocate pktmbuf offload");
12825
12826         /* Set crypto operation data parameters */
12827         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12828
12829         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12830
12831         /* set crypto operation source mbuf */
12832         sym_op->m_src = ut_params->ibuf;
12833
12834         /* digest */
12835         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12836                         ut_params->ibuf, reference->digest.len);
12837
12838         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12839                         "no room to append auth tag");
12840
12841         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12842                         ut_params->ibuf, reference->plaintext.len);
12843
12844         if (auth_generate)
12845                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12846         else
12847                 memcpy(sym_op->auth.digest.data,
12848                                 reference->digest.data,
12849                                 reference->digest.len);
12850
12851         debug_hexdump(stdout, "digest:",
12852                         sym_op->auth.digest.data,
12853                         reference->digest.len);
12854
12855         sym_op->auth.data.length = reference->plaintext.len;
12856         sym_op->auth.data.offset = 0;
12857
12858         return 0;
12859 }
12860
12861 static int
12862 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12863                 struct crypto_unittest_params *ut_params,
12864                 const struct test_crypto_vector *reference,
12865                 unsigned int auth_generate)
12866 {
12867         /* Generate Crypto op data structure */
12868         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12869                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12870         TEST_ASSERT_NOT_NULL(ut_params->op,
12871                         "Failed to allocate pktmbuf offload");
12872
12873         /* Set crypto operation data parameters */
12874         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12875
12876         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12877
12878         /* set crypto operation source mbuf */
12879         sym_op->m_src = ut_params->ibuf;
12880
12881         /* digest */
12882         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12883                         ut_params->ibuf, reference->digest.len);
12884
12885         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12886                         "no room to append auth tag");
12887
12888         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12889                         ut_params->ibuf, reference->ciphertext.len);
12890
12891         if (auth_generate)
12892                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12893         else
12894                 memcpy(sym_op->auth.digest.data,
12895                                 reference->digest.data,
12896                                 reference->digest.len);
12897
12898         debug_hexdump(stdout, "digest:",
12899                         sym_op->auth.digest.data,
12900                         reference->digest.len);
12901
12902         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12903                         reference->iv.data, reference->iv.len);
12904
12905         sym_op->cipher.data.length = 0;
12906         sym_op->cipher.data.offset = 0;
12907
12908         sym_op->auth.data.length = reference->plaintext.len;
12909         sym_op->auth.data.offset = 0;
12910
12911         return 0;
12912 }
12913
12914 static int
12915 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12916                 struct crypto_unittest_params *ut_params,
12917                 const struct test_crypto_vector *reference,
12918                 unsigned int auth_generate)
12919 {
12920         /* Generate Crypto op data structure */
12921         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12922                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12923         TEST_ASSERT_NOT_NULL(ut_params->op,
12924                         "Failed to allocate pktmbuf offload");
12925
12926         /* Set crypto operation data parameters */
12927         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12928
12929         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12930
12931         /* set crypto operation source mbuf */
12932         sym_op->m_src = ut_params->ibuf;
12933
12934         /* digest */
12935         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12936                         ut_params->ibuf, reference->digest.len);
12937
12938         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12939                         "no room to append auth tag");
12940
12941         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12942                         ut_params->ibuf, reference->ciphertext.len);
12943
12944         if (auth_generate)
12945                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12946         else
12947                 memcpy(sym_op->auth.digest.data,
12948                                 reference->digest.data,
12949                                 reference->digest.len);
12950
12951         debug_hexdump(stdout, "digest:",
12952                         sym_op->auth.digest.data,
12953                         reference->digest.len);
12954
12955         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12956                         reference->iv.data, reference->iv.len);
12957
12958         sym_op->cipher.data.length = reference->cipher_len;
12959         sym_op->cipher.data.offset = reference->cipher_offset;
12960
12961         sym_op->auth.data.length = reference->plaintext.len;
12962         sym_op->auth.data.offset = reference->auth_offset;
12963
12964         return 0;
12965 }
12966
12967 static int
12968 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12969                 struct crypto_unittest_params *ut_params,
12970                 const struct test_crypto_vector *reference)
12971 {
12972         return create_auth_operation(ts_params, ut_params, reference, 0);
12973 }
12974
12975 static int
12976 create_auth_verify_GMAC_operation(
12977                 struct crypto_testsuite_params *ts_params,
12978                 struct crypto_unittest_params *ut_params,
12979                 const struct test_crypto_vector *reference)
12980 {
12981         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
12982 }
12983
12984 static int
12985 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12986                 struct crypto_unittest_params *ut_params,
12987                 const struct test_crypto_vector *reference)
12988 {
12989         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12990 }
12991
12992 static int
12993 test_authentication_verify_fail_when_data_corruption(
12994                 struct crypto_testsuite_params *ts_params,
12995                 struct crypto_unittest_params *ut_params,
12996                 const struct test_crypto_vector *reference,
12997                 unsigned int data_corrupted)
12998 {
12999         int retval;
13000
13001         uint8_t *plaintext;
13002         struct rte_cryptodev_info dev_info;
13003
13004         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13005         uint64_t feat_flags = dev_info.feature_flags;
13006
13007         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13008                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13009                 printf("Device doesn't support RAW data-path APIs.\n");
13010                 return TEST_SKIPPED;
13011         }
13012
13013         /* Verify the capabilities */
13014         struct rte_cryptodev_sym_capability_idx cap_idx;
13015         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13016         cap_idx.algo.auth = reference->auth_algo;
13017         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13018                         &cap_idx) == NULL)
13019                 return TEST_SKIPPED;
13020
13021
13022         /* Create session */
13023         retval = create_auth_session(ut_params,
13024                         ts_params->valid_devs[0],
13025                         reference,
13026                         RTE_CRYPTO_AUTH_OP_VERIFY);
13027         if (retval < 0)
13028                 return retval;
13029
13030         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13031         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13032                         "Failed to allocate input buffer in mempool");
13033
13034         /* clear mbuf payload */
13035         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13036                         rte_pktmbuf_tailroom(ut_params->ibuf));
13037
13038         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13039                         reference->plaintext.len);
13040         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13041         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13042
13043         debug_hexdump(stdout, "plaintext:", plaintext,
13044                 reference->plaintext.len);
13045
13046         /* Create operation */
13047         retval = create_auth_verify_operation(ts_params, ut_params, reference);
13048
13049         if (retval < 0)
13050                 return retval;
13051
13052         if (data_corrupted)
13053                 data_corruption(plaintext);
13054         else
13055                 tag_corruption(plaintext, reference->plaintext.len);
13056
13057         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13058                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13059                         ut_params->op);
13060                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13061                         RTE_CRYPTO_OP_STATUS_SUCCESS,
13062                         "authentication not failed");
13063         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13064                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13065                                 ut_params->op, 0, 1, 0, 0);
13066         else {
13067                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13068                         ut_params->op);
13069         }
13070         if (ut_params->op == NULL)
13071                 return 0;
13072         else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
13073                 return 0;
13074
13075         return -1;
13076 }
13077
13078 static int
13079 test_authentication_verify_GMAC_fail_when_corruption(
13080                 struct crypto_testsuite_params *ts_params,
13081                 struct crypto_unittest_params *ut_params,
13082                 const struct test_crypto_vector *reference,
13083                 unsigned int data_corrupted)
13084 {
13085         int retval;
13086         uint8_t *plaintext;
13087         struct rte_cryptodev_info dev_info;
13088
13089         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13090         uint64_t feat_flags = dev_info.feature_flags;
13091
13092         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13093                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13094                 printf("Device doesn't support RAW data-path APIs.\n");
13095                 return TEST_SKIPPED;
13096         }
13097
13098         /* Verify the capabilities */
13099         struct rte_cryptodev_sym_capability_idx cap_idx;
13100         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13101         cap_idx.algo.auth = reference->auth_algo;
13102         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13103                         &cap_idx) == NULL)
13104                 return TEST_SKIPPED;
13105
13106         /* Create session */
13107         retval = create_auth_cipher_session(ut_params,
13108                         ts_params->valid_devs[0],
13109                         reference,
13110                         RTE_CRYPTO_AUTH_OP_VERIFY,
13111                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
13112         if (retval < 0)
13113                 return retval;
13114
13115         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13116         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13117                         "Failed to allocate input buffer in mempool");
13118
13119         /* clear mbuf payload */
13120         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13121                         rte_pktmbuf_tailroom(ut_params->ibuf));
13122
13123         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13124                         reference->plaintext.len);
13125         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13126         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13127
13128         debug_hexdump(stdout, "plaintext:", plaintext,
13129                 reference->plaintext.len);
13130
13131         /* Create operation */
13132         retval = create_auth_verify_GMAC_operation(ts_params,
13133                         ut_params,
13134                         reference);
13135
13136         if (retval < 0)
13137                 return retval;
13138
13139         if (data_corrupted)
13140                 data_corruption(plaintext);
13141         else
13142                 tag_corruption(plaintext, reference->aad.len);
13143
13144         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13145                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13146                         ut_params->op);
13147                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13148                         RTE_CRYPTO_OP_STATUS_SUCCESS,
13149                         "authentication not failed");
13150         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13151                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13152                                 ut_params->op, 0, 1, 0, 0);
13153         else {
13154                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13155                         ut_params->op);
13156                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13157         }
13158
13159         return 0;
13160 }
13161
13162 static int
13163 test_authenticated_decryption_fail_when_corruption(
13164                 struct crypto_testsuite_params *ts_params,
13165                 struct crypto_unittest_params *ut_params,
13166                 const struct test_crypto_vector *reference,
13167                 unsigned int data_corrupted)
13168 {
13169         int retval;
13170
13171         uint8_t *ciphertext;
13172         struct rte_cryptodev_info dev_info;
13173
13174         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13175         uint64_t feat_flags = dev_info.feature_flags;
13176
13177         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13178                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13179                 printf("Device doesn't support RAW data-path APIs.\n");
13180                 return TEST_SKIPPED;
13181         }
13182
13183         /* Verify the capabilities */
13184         struct rte_cryptodev_sym_capability_idx cap_idx;
13185         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13186         cap_idx.algo.auth = reference->auth_algo;
13187         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13188                         &cap_idx) == NULL)
13189                 return TEST_SKIPPED;
13190         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13191         cap_idx.algo.cipher = reference->crypto_algo;
13192         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13193                         &cap_idx) == NULL)
13194                 return TEST_SKIPPED;
13195
13196         /* Create session */
13197         retval = create_auth_cipher_session(ut_params,
13198                         ts_params->valid_devs[0],
13199                         reference,
13200                         RTE_CRYPTO_AUTH_OP_VERIFY,
13201                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
13202         if (retval < 0)
13203                 return retval;
13204
13205         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13206         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13207                         "Failed to allocate input buffer in mempool");
13208
13209         /* clear mbuf payload */
13210         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13211                         rte_pktmbuf_tailroom(ut_params->ibuf));
13212
13213         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13214                         reference->ciphertext.len);
13215         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13216         memcpy(ciphertext, reference->ciphertext.data,
13217                         reference->ciphertext.len);
13218
13219         /* Create operation */
13220         retval = create_cipher_auth_verify_operation(ts_params,
13221                         ut_params,
13222                         reference);
13223
13224         if (retval < 0)
13225                 return retval;
13226
13227         if (data_corrupted)
13228                 data_corruption(ciphertext);
13229         else
13230                 tag_corruption(ciphertext, reference->ciphertext.len);
13231
13232         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13233                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13234                         ut_params->op);
13235                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13236                         RTE_CRYPTO_OP_STATUS_SUCCESS,
13237                         "authentication not failed");
13238         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13239                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13240                                 ut_params->op, 1, 1, 0, 0);
13241         else {
13242                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13243                         ut_params->op);
13244                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13245         }
13246
13247         return 0;
13248 }
13249
13250 static int
13251 test_authenticated_encrypt_with_esn(
13252                 struct crypto_testsuite_params *ts_params,
13253                 struct crypto_unittest_params *ut_params,
13254                 const struct test_crypto_vector *reference)
13255 {
13256         int retval;
13257
13258         uint8_t *authciphertext, *plaintext, *auth_tag;
13259         uint16_t plaintext_pad_len;
13260         uint8_t cipher_key[reference->cipher_key.len + 1];
13261         uint8_t auth_key[reference->auth_key.len + 1];
13262         struct rte_cryptodev_info dev_info;
13263
13264         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13265         uint64_t feat_flags = dev_info.feature_flags;
13266
13267         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13268                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13269                 printf("Device doesn't support RAW data-path APIs.\n");
13270                 return TEST_SKIPPED;
13271         }
13272
13273         /* Verify the capabilities */
13274         struct rte_cryptodev_sym_capability_idx cap_idx;
13275         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13276         cap_idx.algo.auth = reference->auth_algo;
13277         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13278                         &cap_idx) == NULL)
13279                 return TEST_SKIPPED;
13280         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13281         cap_idx.algo.cipher = reference->crypto_algo;
13282         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13283                         &cap_idx) == NULL)
13284                 return TEST_SKIPPED;
13285
13286         /* Create session */
13287         memcpy(cipher_key, reference->cipher_key.data,
13288                         reference->cipher_key.len);
13289         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13290
13291         /* Setup Cipher Parameters */
13292         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13293         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13294         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
13295         ut_params->cipher_xform.cipher.key.data = cipher_key;
13296         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13297         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13298         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13299
13300         ut_params->cipher_xform.next = &ut_params->auth_xform;
13301
13302         /* Setup Authentication Parameters */
13303         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13304         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
13305         ut_params->auth_xform.auth.algo = reference->auth_algo;
13306         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13307         ut_params->auth_xform.auth.key.data = auth_key;
13308         ut_params->auth_xform.auth.digest_length = reference->digest.len;
13309         ut_params->auth_xform.next = NULL;
13310
13311         /* Create Crypto session*/
13312         ut_params->sess = rte_cryptodev_sym_session_create(
13313                         ts_params->session_mpool);
13314
13315         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13316                                 ut_params->sess,
13317                                 &ut_params->cipher_xform,
13318                                 ts_params->session_priv_mpool);
13319
13320         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13321
13322         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13323         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13324                         "Failed to allocate input buffer in mempool");
13325
13326         /* clear mbuf payload */
13327         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13328                         rte_pktmbuf_tailroom(ut_params->ibuf));
13329
13330         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13331                         reference->plaintext.len);
13332         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13333         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13334
13335         /* Create operation */
13336         retval = create_cipher_auth_operation(ts_params,
13337                         ut_params,
13338                         reference, 0);
13339
13340         if (retval < 0)
13341                 return retval;
13342
13343         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13344                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13345                         ut_params->op);
13346         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13347                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13348                                 ut_params->op, 1, 1, 0, 0);
13349         else
13350                 ut_params->op = process_crypto_request(
13351                         ts_params->valid_devs[0], ut_params->op);
13352
13353         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
13354
13355         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13356                         "crypto op processing failed");
13357
13358         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
13359
13360         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
13361                         ut_params->op->sym->auth.data.offset);
13362         auth_tag = authciphertext + plaintext_pad_len;
13363         debug_hexdump(stdout, "ciphertext:", authciphertext,
13364                         reference->ciphertext.len);
13365         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
13366
13367         /* Validate obuf */
13368         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13369                         authciphertext,
13370                         reference->ciphertext.data,
13371                         reference->ciphertext.len,
13372                         "Ciphertext data not as expected");
13373
13374         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13375                         auth_tag,
13376                         reference->digest.data,
13377                         reference->digest.len,
13378                         "Generated digest not as expected");
13379
13380         return TEST_SUCCESS;
13381
13382 }
13383
13384 static int
13385 test_authenticated_decrypt_with_esn(
13386                 struct crypto_testsuite_params *ts_params,
13387                 struct crypto_unittest_params *ut_params,
13388                 const struct test_crypto_vector *reference)
13389 {
13390         int retval;
13391
13392         uint8_t *ciphertext;
13393         uint8_t cipher_key[reference->cipher_key.len + 1];
13394         uint8_t auth_key[reference->auth_key.len + 1];
13395         struct rte_cryptodev_info dev_info;
13396
13397         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13398         uint64_t feat_flags = dev_info.feature_flags;
13399
13400         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13401                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13402                 printf("Device doesn't support RAW data-path APIs.\n");
13403                 return TEST_SKIPPED;
13404         }
13405
13406         /* Verify the capabilities */
13407         struct rte_cryptodev_sym_capability_idx cap_idx;
13408         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13409         cap_idx.algo.auth = reference->auth_algo;
13410         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13411                         &cap_idx) == NULL)
13412                 return TEST_SKIPPED;
13413         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13414         cap_idx.algo.cipher = reference->crypto_algo;
13415         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13416                         &cap_idx) == NULL)
13417                 return TEST_SKIPPED;
13418
13419         /* Create session */
13420         memcpy(cipher_key, reference->cipher_key.data,
13421                         reference->cipher_key.len);
13422         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13423
13424         /* Setup Authentication Parameters */
13425         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13426         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
13427         ut_params->auth_xform.auth.algo = reference->auth_algo;
13428         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13429         ut_params->auth_xform.auth.key.data = auth_key;
13430         ut_params->auth_xform.auth.digest_length = reference->digest.len;
13431         ut_params->auth_xform.next = &ut_params->cipher_xform;
13432
13433         /* Setup Cipher Parameters */
13434         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13435         ut_params->cipher_xform.next = NULL;
13436         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13437         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
13438         ut_params->cipher_xform.cipher.key.data = cipher_key;
13439         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13440         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13441         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13442
13443         /* Create Crypto session*/
13444         ut_params->sess = rte_cryptodev_sym_session_create(
13445                         ts_params->session_mpool);
13446
13447         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13448                                 ut_params->sess,
13449                                 &ut_params->auth_xform,
13450                                 ts_params->session_priv_mpool);
13451
13452         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13453
13454         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13455         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13456                         "Failed to allocate input buffer in mempool");
13457
13458         /* clear mbuf payload */
13459         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13460                         rte_pktmbuf_tailroom(ut_params->ibuf));
13461
13462         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13463                         reference->ciphertext.len);
13464         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13465         memcpy(ciphertext, reference->ciphertext.data,
13466                         reference->ciphertext.len);
13467
13468         /* Create operation */
13469         retval = create_cipher_auth_verify_operation(ts_params,
13470                         ut_params,
13471                         reference);
13472
13473         if (retval < 0)
13474                 return retval;
13475
13476         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13477                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13478                         ut_params->op);
13479         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13480                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13481                                 ut_params->op, 1, 1, 0, 0);
13482         else
13483                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13484                         ut_params->op);
13485
13486         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
13487         TEST_ASSERT_EQUAL(ut_params->op->status,
13488                         RTE_CRYPTO_OP_STATUS_SUCCESS,
13489                         "crypto op processing passed");
13490
13491         ut_params->obuf = ut_params->op->sym->m_src;
13492         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
13493
13494         return 0;
13495 }
13496
13497 static int
13498 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
13499                 const struct aead_test_data *tdata,
13500                 void *digest_mem, uint64_t digest_phys)
13501 {
13502         struct crypto_testsuite_params *ts_params = &testsuite_params;
13503         struct crypto_unittest_params *ut_params = &unittest_params;
13504
13505         const unsigned int auth_tag_len = tdata->auth_tag.len;
13506         const unsigned int iv_len = tdata->iv.len;
13507         unsigned int aad_len = tdata->aad.len;
13508         unsigned int aad_len_pad = 0;
13509
13510         /* Generate Crypto op data structure */
13511         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13512                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13513         TEST_ASSERT_NOT_NULL(ut_params->op,
13514                 "Failed to allocate symmetric crypto operation struct");
13515
13516         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13517
13518         sym_op->aead.digest.data = digest_mem;
13519
13520         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
13521                         "no room to append digest");
13522
13523         sym_op->aead.digest.phys_addr = digest_phys;
13524
13525         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
13526                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
13527                                 auth_tag_len);
13528                 debug_hexdump(stdout, "digest:",
13529                                 sym_op->aead.digest.data,
13530                                 auth_tag_len);
13531         }
13532
13533         /* Append aad data */
13534         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
13535                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13536                                 uint8_t *, IV_OFFSET);
13537
13538                 /* Copy IV 1 byte after the IV pointer, according to the API */
13539                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
13540
13541                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
13542
13543                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13544                                 ut_params->ibuf, aad_len);
13545                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13546                                 "no room to prepend aad");
13547                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13548                                 ut_params->ibuf);
13549
13550                 memset(sym_op->aead.aad.data, 0, aad_len);
13551                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
13552                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13553
13554                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13555                 debug_hexdump(stdout, "aad:",
13556                                 sym_op->aead.aad.data, aad_len);
13557         } else {
13558                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13559                                 uint8_t *, IV_OFFSET);
13560
13561                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
13562
13563                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
13564
13565                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13566                                 ut_params->ibuf, aad_len_pad);
13567                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13568                                 "no room to prepend aad");
13569                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13570                                 ut_params->ibuf);
13571
13572                 memset(sym_op->aead.aad.data, 0, aad_len);
13573                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13574
13575                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13576                 debug_hexdump(stdout, "aad:",
13577                                 sym_op->aead.aad.data, aad_len);
13578         }
13579
13580         sym_op->aead.data.length = tdata->plaintext.len;
13581         sym_op->aead.data.offset = aad_len_pad;
13582
13583         return 0;
13584 }
13585
13586 #define SGL_MAX_NO      16
13587
13588 static int
13589 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
13590                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
13591 {
13592         struct crypto_testsuite_params *ts_params = &testsuite_params;
13593         struct crypto_unittest_params *ut_params = &unittest_params;
13594         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
13595         int retval;
13596         int to_trn = 0;
13597         int to_trn_tbl[SGL_MAX_NO];
13598         int segs = 1;
13599         unsigned int trn_data = 0;
13600         uint8_t *plaintext, *ciphertext, *auth_tag;
13601         struct rte_cryptodev_info dev_info;
13602
13603         /* Verify the capabilities */
13604         struct rte_cryptodev_sym_capability_idx cap_idx;
13605         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13606         cap_idx.algo.aead = tdata->algo;
13607         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13608                         &cap_idx) == NULL)
13609                 return TEST_SKIPPED;
13610
13611         /* OOP not supported with CPU crypto */
13612         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13613                 return TEST_SKIPPED;
13614
13615         /* Detailed check for the particular SGL support flag */
13616         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13617         if (!oop) {
13618                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
13619                 if (sgl_in && (!(dev_info.feature_flags &
13620                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
13621                         return TEST_SKIPPED;
13622
13623                 uint64_t feat_flags = dev_info.feature_flags;
13624
13625                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13626                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13627                         printf("Device doesn't support RAW data-path APIs.\n");
13628                         return TEST_SKIPPED;
13629                 }
13630         } else {
13631                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
13632                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
13633                                 tdata->plaintext.len;
13634                 /* Raw data path API does not support OOP */
13635                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13636                         return TEST_SKIPPED;
13637                 if (sgl_in && !sgl_out) {
13638                         if (!(dev_info.feature_flags &
13639                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
13640                                 return TEST_SKIPPED;
13641                 } else if (!sgl_in && sgl_out) {
13642                         if (!(dev_info.feature_flags &
13643                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
13644                                 return TEST_SKIPPED;
13645                 } else if (sgl_in && sgl_out) {
13646                         if (!(dev_info.feature_flags &
13647                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13648                                 return TEST_SKIPPED;
13649                 }
13650         }
13651
13652         if (fragsz > tdata->plaintext.len)
13653                 fragsz = tdata->plaintext.len;
13654
13655         uint16_t plaintext_len = fragsz;
13656         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13657
13658         if (fragsz_oop > tdata->plaintext.len)
13659                 frag_size_oop = tdata->plaintext.len;
13660
13661         int ecx = 0;
13662         void *digest_mem = NULL;
13663
13664         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13665
13666         if (tdata->plaintext.len % fragsz != 0) {
13667                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13668                         return 1;
13669         }       else {
13670                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13671                         return 1;
13672         }
13673
13674         /*
13675          * For out-op-place we need to alloc another mbuf
13676          */
13677         if (oop) {
13678                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13679                 rte_pktmbuf_append(ut_params->obuf,
13680                                 frag_size_oop + prepend_len);
13681                 buf_oop = ut_params->obuf;
13682         }
13683
13684         /* Create AEAD session */
13685         retval = create_aead_session(ts_params->valid_devs[0],
13686                         tdata->algo,
13687                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
13688                         tdata->key.data, tdata->key.len,
13689                         tdata->aad.len, tdata->auth_tag.len,
13690                         tdata->iv.len);
13691         if (retval < 0)
13692                 return retval;
13693
13694         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13695
13696         /* clear mbuf payload */
13697         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13698                         rte_pktmbuf_tailroom(ut_params->ibuf));
13699
13700         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13701                         plaintext_len);
13702
13703         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13704
13705         trn_data += plaintext_len;
13706
13707         buf = ut_params->ibuf;
13708
13709         /*
13710          * Loop until no more fragments
13711          */
13712
13713         while (trn_data < tdata->plaintext.len) {
13714                 ++segs;
13715                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13716                                 (tdata->plaintext.len - trn_data) : fragsz;
13717
13718                 to_trn_tbl[ecx++] = to_trn;
13719
13720                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13721                 buf = buf->next;
13722
13723                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13724                                 rte_pktmbuf_tailroom(buf));
13725
13726                 /* OOP */
13727                 if (oop && !fragsz_oop) {
13728                         buf_last_oop = buf_oop->next =
13729                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13730                         buf_oop = buf_oop->next;
13731                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13732                                         0, rte_pktmbuf_tailroom(buf_oop));
13733                         rte_pktmbuf_append(buf_oop, to_trn);
13734                 }
13735
13736                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13737                                 to_trn);
13738
13739                 memcpy(plaintext, tdata->plaintext.data + trn_data,
13740                                 to_trn);
13741                 trn_data += to_trn;
13742                 if (trn_data  == tdata->plaintext.len) {
13743                         if (oop) {
13744                                 if (!fragsz_oop)
13745                                         digest_mem = rte_pktmbuf_append(buf_oop,
13746                                                 tdata->auth_tag.len);
13747                         } else
13748                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13749                                         tdata->auth_tag.len);
13750                 }
13751         }
13752
13753         uint64_t digest_phys = 0;
13754
13755         ut_params->ibuf->nb_segs = segs;
13756
13757         segs = 1;
13758         if (fragsz_oop && oop) {
13759                 to_trn = 0;
13760                 ecx = 0;
13761
13762                 if (frag_size_oop == tdata->plaintext.len) {
13763                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
13764                                 tdata->auth_tag.len);
13765
13766                         digest_phys = rte_pktmbuf_iova_offset(
13767                                         ut_params->obuf,
13768                                         tdata->plaintext.len + prepend_len);
13769                 }
13770
13771                 trn_data = frag_size_oop;
13772                 while (trn_data < tdata->plaintext.len) {
13773                         ++segs;
13774                         to_trn =
13775                                 (tdata->plaintext.len - trn_data <
13776                                                 frag_size_oop) ?
13777                                 (tdata->plaintext.len - trn_data) :
13778                                                 frag_size_oop;
13779
13780                         to_trn_tbl[ecx++] = to_trn;
13781
13782                         buf_last_oop = buf_oop->next =
13783                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13784                         buf_oop = buf_oop->next;
13785                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13786                                         0, rte_pktmbuf_tailroom(buf_oop));
13787                         rte_pktmbuf_append(buf_oop, to_trn);
13788
13789                         trn_data += to_trn;
13790
13791                         if (trn_data  == tdata->plaintext.len) {
13792                                 digest_mem = rte_pktmbuf_append(buf_oop,
13793                                         tdata->auth_tag.len);
13794                         }
13795                 }
13796
13797                 ut_params->obuf->nb_segs = segs;
13798         }
13799
13800         /*
13801          * Place digest at the end of the last buffer
13802          */
13803         if (!digest_phys)
13804                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13805         if (oop && buf_last_oop)
13806                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13807
13808         if (!digest_mem && !oop) {
13809                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13810                                 + tdata->auth_tag.len);
13811                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13812                                 tdata->plaintext.len);
13813         }
13814
13815         /* Create AEAD operation */
13816         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13817                         tdata, digest_mem, digest_phys);
13818
13819         if (retval < 0)
13820                 return retval;
13821
13822         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13823
13824         ut_params->op->sym->m_src = ut_params->ibuf;
13825         if (oop)
13826                 ut_params->op->sym->m_dst = ut_params->obuf;
13827
13828         /* Process crypto operation */
13829         if (oop == IN_PLACE &&
13830                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13831                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13832         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13833                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13834                                 ut_params->op, 0, 0, 0, 0);
13835         else
13836                 TEST_ASSERT_NOT_NULL(
13837                         process_crypto_request(ts_params->valid_devs[0],
13838                         ut_params->op), "failed to process sym crypto op");
13839
13840         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13841                         "crypto op processing failed");
13842
13843
13844         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13845                         uint8_t *, prepend_len);
13846         if (oop) {
13847                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13848                                 uint8_t *, prepend_len);
13849         }
13850
13851         if (fragsz_oop)
13852                 fragsz = fragsz_oop;
13853
13854         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13855                         ciphertext,
13856                         tdata->ciphertext.data,
13857                         fragsz,
13858                         "Ciphertext data not as expected");
13859
13860         buf = ut_params->op->sym->m_src->next;
13861         if (oop)
13862                 buf = ut_params->op->sym->m_dst->next;
13863
13864         unsigned int off = fragsz;
13865
13866         ecx = 0;
13867         while (buf) {
13868                 ciphertext = rte_pktmbuf_mtod(buf,
13869                                 uint8_t *);
13870
13871                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
13872                                 ciphertext,
13873                                 tdata->ciphertext.data + off,
13874                                 to_trn_tbl[ecx],
13875                                 "Ciphertext data not as expected");
13876
13877                 off += to_trn_tbl[ecx++];
13878                 buf = buf->next;
13879         }
13880
13881         auth_tag = digest_mem;
13882         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13883                         auth_tag,
13884                         tdata->auth_tag.data,
13885                         tdata->auth_tag.len,
13886                         "Generated auth tag not as expected");
13887
13888         return 0;
13889 }
13890
13891 static int
13892 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13893 {
13894         return test_authenticated_encryption_SGL(
13895                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13896 }
13897
13898 static int
13899 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13900 {
13901         return test_authenticated_encryption_SGL(
13902                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13903 }
13904
13905 static int
13906 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13907 {
13908         return test_authenticated_encryption_SGL(
13909                         &gcm_test_case_8, OUT_OF_PLACE, 400,
13910                         gcm_test_case_8.plaintext.len);
13911 }
13912
13913 static int
13914 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13915 {
13916         /* This test is not for OPENSSL PMD */
13917         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13918                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13919                 return TEST_SKIPPED;
13920
13921         return test_authenticated_encryption_SGL(
13922                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13923 }
13924
13925 static int
13926 test_authentication_verify_fail_when_data_corrupted(
13927                 struct crypto_testsuite_params *ts_params,
13928                 struct crypto_unittest_params *ut_params,
13929                 const struct test_crypto_vector *reference)
13930 {
13931         return test_authentication_verify_fail_when_data_corruption(
13932                         ts_params, ut_params, reference, 1);
13933 }
13934
13935 static int
13936 test_authentication_verify_fail_when_tag_corrupted(
13937                 struct crypto_testsuite_params *ts_params,
13938                 struct crypto_unittest_params *ut_params,
13939                 const struct test_crypto_vector *reference)
13940 {
13941         return test_authentication_verify_fail_when_data_corruption(
13942                         ts_params, ut_params, reference, 0);
13943 }
13944
13945 static int
13946 test_authentication_verify_GMAC_fail_when_data_corrupted(
13947                 struct crypto_testsuite_params *ts_params,
13948                 struct crypto_unittest_params *ut_params,
13949                 const struct test_crypto_vector *reference)
13950 {
13951         return test_authentication_verify_GMAC_fail_when_corruption(
13952                         ts_params, ut_params, reference, 1);
13953 }
13954
13955 static int
13956 test_authentication_verify_GMAC_fail_when_tag_corrupted(
13957                 struct crypto_testsuite_params *ts_params,
13958                 struct crypto_unittest_params *ut_params,
13959                 const struct test_crypto_vector *reference)
13960 {
13961         return test_authentication_verify_GMAC_fail_when_corruption(
13962                         ts_params, ut_params, reference, 0);
13963 }
13964
13965 static int
13966 test_authenticated_decryption_fail_when_data_corrupted(
13967                 struct crypto_testsuite_params *ts_params,
13968                 struct crypto_unittest_params *ut_params,
13969                 const struct test_crypto_vector *reference)
13970 {
13971         return test_authenticated_decryption_fail_when_corruption(
13972                         ts_params, ut_params, reference, 1);
13973 }
13974
13975 static int
13976 test_authenticated_decryption_fail_when_tag_corrupted(
13977                 struct crypto_testsuite_params *ts_params,
13978                 struct crypto_unittest_params *ut_params,
13979                 const struct test_crypto_vector *reference)
13980 {
13981         return test_authenticated_decryption_fail_when_corruption(
13982                         ts_params, ut_params, reference, 0);
13983 }
13984
13985 static int
13986 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
13987 {
13988         return test_authentication_verify_fail_when_data_corrupted(
13989                         &testsuite_params, &unittest_params,
13990                         &hmac_sha1_test_crypto_vector);
13991 }
13992
13993 static int
13994 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13995 {
13996         return test_authentication_verify_fail_when_tag_corrupted(
13997                         &testsuite_params, &unittest_params,
13998                         &hmac_sha1_test_crypto_vector);
13999 }
14000
14001 static int
14002 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
14003 {
14004         return test_authentication_verify_GMAC_fail_when_data_corrupted(
14005                         &testsuite_params, &unittest_params,
14006                         &aes128_gmac_test_vector);
14007 }
14008
14009 static int
14010 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
14011 {
14012         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
14013                         &testsuite_params, &unittest_params,
14014                         &aes128_gmac_test_vector);
14015 }
14016
14017 static int
14018 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
14019 {
14020         return test_authenticated_decryption_fail_when_data_corrupted(
14021                         &testsuite_params,
14022                         &unittest_params,
14023                         &aes128cbc_hmac_sha1_test_vector);
14024 }
14025
14026 static int
14027 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
14028 {
14029         return test_authenticated_decryption_fail_when_tag_corrupted(
14030                         &testsuite_params,
14031                         &unittest_params,
14032                         &aes128cbc_hmac_sha1_test_vector);
14033 }
14034
14035 static int
14036 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14037 {
14038         return test_authenticated_encrypt_with_esn(
14039                         &testsuite_params,
14040                         &unittest_params,
14041                         &aes128cbc_hmac_sha1_aad_test_vector);
14042 }
14043
14044 static int
14045 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14046 {
14047         return test_authenticated_decrypt_with_esn(
14048                         &testsuite_params,
14049                         &unittest_params,
14050                         &aes128cbc_hmac_sha1_aad_test_vector);
14051 }
14052
14053 static int
14054 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
14055 {
14056         return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
14057 }
14058
14059 static int
14060 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
14061 {
14062         return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
14063 }
14064
14065 #ifdef RTE_CRYPTO_SCHEDULER
14066
14067 /* global AESNI worker IDs for the scheduler test */
14068 uint8_t aesni_ids[2];
14069
14070 static int
14071 scheduler_testsuite_setup(void)
14072 {
14073         uint32_t i = 0;
14074         int32_t nb_devs, ret;
14075         char vdev_args[VDEV_ARGS_SIZE] = {""};
14076         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
14077                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
14078         uint16_t worker_core_count = 0;
14079         uint16_t socket_id = 0;
14080
14081         if (gbl_driver_id == rte_cryptodev_driver_id_get(
14082                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
14083
14084                 /* Identify the Worker Cores
14085                  * Use 2 worker cores for the device args
14086                  */
14087                 RTE_LCORE_FOREACH_WORKER(i) {
14088                         if (worker_core_count > 1)
14089                                 break;
14090                         snprintf(vdev_args, sizeof(vdev_args),
14091                                         "%s%d", temp_str, i);
14092                         strcpy(temp_str, vdev_args);
14093                         strlcat(temp_str, ";", sizeof(temp_str));
14094                         worker_core_count++;
14095                         socket_id = rte_lcore_to_socket_id(i);
14096                 }
14097                 if (worker_core_count != 2) {
14098                         RTE_LOG(ERR, USER1,
14099                                 "Cryptodev scheduler test require at least "
14100                                 "two worker cores to run. "
14101                                 "Please use the correct coremask.\n");
14102                         return TEST_FAILED;
14103                 }
14104                 strcpy(temp_str, vdev_args);
14105                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
14106                                 temp_str, socket_id);
14107                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
14108                 nb_devs = rte_cryptodev_device_count_by_driver(
14109                                 rte_cryptodev_driver_id_get(
14110                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
14111                 if (nb_devs < 1) {
14112                         ret = rte_vdev_init(
14113                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
14114                                         vdev_args);
14115                         TEST_ASSERT(ret == 0,
14116                                 "Failed to create instance %u of pmd : %s",
14117                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14118                 }
14119         }
14120         return testsuite_setup();
14121 }
14122
14123 static int
14124 test_scheduler_attach_worker_op(void)
14125 {
14126         struct crypto_testsuite_params *ts_params = &testsuite_params;
14127         uint8_t sched_id = ts_params->valid_devs[0];
14128         uint32_t i, nb_devs_attached = 0;
14129         int ret;
14130         char vdev_name[32];
14131         unsigned int count = rte_cryptodev_count();
14132
14133         /* create 2 AESNI_MB vdevs on top of existing devices */
14134         for (i = count; i < count + 2; i++) {
14135                 snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
14136                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
14137                                 i);
14138                 ret = rte_vdev_init(vdev_name, NULL);
14139
14140                 TEST_ASSERT(ret == 0,
14141                         "Failed to create instance %u of"
14142                         " pmd : %s",
14143                         i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14144
14145                 if (ret < 0) {
14146                         RTE_LOG(ERR, USER1,
14147                                 "Failed to create 2 AESNI MB PMDs.\n");
14148                         return TEST_SKIPPED;
14149                 }
14150         }
14151
14152         /* attach 2 AESNI_MB cdevs */
14153         for (i = count; i < count + 2; i++) {
14154                 struct rte_cryptodev_info info;
14155                 unsigned int session_size;
14156
14157                 rte_cryptodev_info_get(i, &info);
14158                 if (info.driver_id != rte_cryptodev_driver_id_get(
14159                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
14160                         continue;
14161
14162                 session_size = rte_cryptodev_sym_get_private_session_size(i);
14163                 /*
14164                  * Create the session mempool again, since now there are new devices
14165                  * to use the mempool.
14166                  */
14167                 if (ts_params->session_mpool) {
14168                         rte_mempool_free(ts_params->session_mpool);
14169                         ts_params->session_mpool = NULL;
14170                 }
14171                 if (ts_params->session_priv_mpool) {
14172                         rte_mempool_free(ts_params->session_priv_mpool);
14173                         ts_params->session_priv_mpool = NULL;
14174                 }
14175
14176                 if (info.sym.max_nb_sessions != 0 &&
14177                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
14178                         RTE_LOG(ERR, USER1,
14179                                         "Device does not support "
14180                                         "at least %u sessions\n",
14181                                         MAX_NB_SESSIONS);
14182                         return TEST_FAILED;
14183                 }
14184                 /*
14185                  * Create mempool with maximum number of sessions,
14186                  * to include the session headers
14187                  */
14188                 if (ts_params->session_mpool == NULL) {
14189                         ts_params->session_mpool =
14190                                 rte_cryptodev_sym_session_pool_create(
14191                                                 "test_sess_mp",
14192                                                 MAX_NB_SESSIONS, 0, 0, 0,
14193                                                 SOCKET_ID_ANY);
14194                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
14195                                         "session mempool allocation failed");
14196                 }
14197
14198                 /*
14199                  * Create mempool with maximum number of sessions,
14200                  * to include device specific session private data
14201                  */
14202                 if (ts_params->session_priv_mpool == NULL) {
14203                         ts_params->session_priv_mpool = rte_mempool_create(
14204                                         "test_sess_mp_priv",
14205                                         MAX_NB_SESSIONS,
14206                                         session_size,
14207                                         0, 0, NULL, NULL, NULL,
14208                                         NULL, SOCKET_ID_ANY,
14209                                         0);
14210
14211                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
14212                                         "session mempool allocation failed");
14213                 }
14214
14215                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
14216                 ts_params->qp_conf.mp_session_private =
14217                                 ts_params->session_priv_mpool;
14218
14219                 ret = rte_cryptodev_scheduler_worker_attach(sched_id,
14220                                 (uint8_t)i);
14221
14222                 TEST_ASSERT(ret == 0,
14223                         "Failed to attach device %u of pmd : %s", i,
14224                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14225
14226                 aesni_ids[nb_devs_attached] = (uint8_t)i;
14227
14228                 nb_devs_attached++;
14229         }
14230
14231         return 0;
14232 }
14233
14234 static int
14235 test_scheduler_detach_worker_op(void)
14236 {
14237         struct crypto_testsuite_params *ts_params = &testsuite_params;
14238         uint8_t sched_id = ts_params->valid_devs[0];
14239         uint32_t i;
14240         int ret;
14241
14242         for (i = 0; i < 2; i++) {
14243                 ret = rte_cryptodev_scheduler_worker_detach(sched_id,
14244                                 aesni_ids[i]);
14245                 TEST_ASSERT(ret == 0,
14246                         "Failed to detach device %u", aesni_ids[i]);
14247         }
14248
14249         return 0;
14250 }
14251
14252 static int
14253 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
14254 {
14255         struct crypto_testsuite_params *ts_params = &testsuite_params;
14256         uint8_t sched_id = ts_params->valid_devs[0];
14257         /* set mode */
14258         return rte_cryptodev_scheduler_mode_set(sched_id,
14259                 scheduler_mode);
14260 }
14261
14262 static int
14263 test_scheduler_mode_roundrobin_op(void)
14264 {
14265         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
14266                         0, "Failed to set roundrobin mode");
14267         return 0;
14268
14269 }
14270
14271 static int
14272 test_scheduler_mode_multicore_op(void)
14273 {
14274         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
14275                         0, "Failed to set multicore mode");
14276
14277         return 0;
14278 }
14279
14280 static int
14281 test_scheduler_mode_failover_op(void)
14282 {
14283         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
14284                         0, "Failed to set failover mode");
14285
14286         return 0;
14287 }
14288
14289 static int
14290 test_scheduler_mode_pkt_size_distr_op(void)
14291 {
14292         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
14293                         0, "Failed to set pktsize mode");
14294
14295         return 0;
14296 }
14297
14298 static int
14299 scheduler_multicore_testsuite_setup(void)
14300 {
14301         if (test_scheduler_attach_worker_op() < 0)
14302                 return TEST_SKIPPED;
14303         if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
14304                 return TEST_SKIPPED;
14305         return 0;
14306 }
14307
14308 static int
14309 scheduler_roundrobin_testsuite_setup(void)
14310 {
14311         if (test_scheduler_attach_worker_op() < 0)
14312                 return TEST_SKIPPED;
14313         if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
14314                 return TEST_SKIPPED;
14315         return 0;
14316 }
14317
14318 static int
14319 scheduler_failover_testsuite_setup(void)
14320 {
14321         if (test_scheduler_attach_worker_op() < 0)
14322                 return TEST_SKIPPED;
14323         if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
14324                 return TEST_SKIPPED;
14325         return 0;
14326 }
14327
14328 static int
14329 scheduler_pkt_size_distr_testsuite_setup(void)
14330 {
14331         if (test_scheduler_attach_worker_op() < 0)
14332                 return TEST_SKIPPED;
14333         if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
14334                 return TEST_SKIPPED;
14335         return 0;
14336 }
14337
14338 static void
14339 scheduler_mode_testsuite_teardown(void)
14340 {
14341         test_scheduler_detach_worker_op();
14342 }
14343
14344 #endif /* RTE_CRYPTO_SCHEDULER */
14345
14346 static struct unit_test_suite end_testsuite = {
14347         .suite_name = NULL,
14348         .setup = NULL,
14349         .teardown = NULL,
14350         .unit_test_suites = NULL
14351 };
14352
14353 #ifdef RTE_LIB_SECURITY
14354 static struct unit_test_suite ipsec_proto_testsuite  = {
14355         .suite_name = "IPsec Proto Unit Test Suite",
14356         .setup = ipsec_proto_testsuite_setup,
14357         .unit_test_cases = {
14358                 TEST_CASE_NAMED_WITH_DATA(
14359                         "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14360                         ut_setup_security, ut_teardown,
14361                         test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
14362                 TEST_CASE_NAMED_WITH_DATA(
14363                         "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14364                         ut_setup_security, ut_teardown,
14365                         test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
14366                 TEST_CASE_NAMED_WITH_DATA(
14367                         "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14368                         ut_setup_security, ut_teardown,
14369                         test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
14370                 TEST_CASE_NAMED_WITH_DATA(
14371                         "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14372                         ut_setup_security, ut_teardown,
14373                         test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
14374                 TEST_CASE_NAMED_WITH_DATA(
14375                         "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14376                         ut_setup_security, ut_teardown,
14377                         test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
14378                 TEST_CASE_NAMED_WITH_DATA(
14379                         "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14380                         ut_setup_security, ut_teardown,
14381                         test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
14382                 TEST_CASE_NAMED_ST(
14383                         "Combined test alg list",
14384                         ut_setup_security, ut_teardown,
14385                         test_ipsec_proto_display_list),
14386                 TEST_CASE_NAMED_ST(
14387                         "IV generation",
14388                         ut_setup_security, ut_teardown,
14389                         test_ipsec_proto_iv_gen),
14390                 TEST_CASE_NAMED_ST(
14391                         "UDP encapsulation",
14392                         ut_setup_security, ut_teardown,
14393                         test_ipsec_proto_udp_encap),
14394                 TEST_CASE_NAMED_ST(
14395                         "UDP encapsulation ports verification test",
14396                         ut_setup_security, ut_teardown,
14397                         test_ipsec_proto_udp_ports_verify),
14398                 TEST_CASE_NAMED_ST(
14399                         "SA expiry packets soft",
14400                         ut_setup_security, ut_teardown,
14401                         test_ipsec_proto_sa_exp_pkts_soft),
14402                 TEST_CASE_NAMED_ST(
14403                         "SA expiry packets hard",
14404                         ut_setup_security, ut_teardown,
14405                         test_ipsec_proto_sa_exp_pkts_hard),
14406                 TEST_CASE_NAMED_ST(
14407                         "Negative test: ICV corruption",
14408                         ut_setup_security, ut_teardown,
14409                         test_ipsec_proto_err_icv_corrupt),
14410                 TEST_CASE_NAMED_ST(
14411                         "Tunnel dst addr verification",
14412                         ut_setup_security, ut_teardown,
14413                         test_ipsec_proto_tunnel_dst_addr_verify),
14414                 TEST_CASE_NAMED_ST(
14415                         "Tunnel src and dst addr verification",
14416                         ut_setup_security, ut_teardown,
14417                         test_ipsec_proto_tunnel_src_dst_addr_verify),
14418                 TEST_CASE_NAMED_ST(
14419                         "Inner IP checksum",
14420                         ut_setup_security, ut_teardown,
14421                         test_ipsec_proto_inner_ip_csum),
14422                 TEST_CASE_NAMED_ST(
14423                         "Inner L4 checksum",
14424                         ut_setup_security, ut_teardown,
14425                         test_ipsec_proto_inner_l4_csum),
14426                 TEST_CASES_END() /**< NULL terminate unit test array */
14427         }
14428 };
14429
14430 static struct unit_test_suite pdcp_proto_testsuite  = {
14431         .suite_name = "PDCP Proto Unit Test Suite",
14432         .setup = pdcp_proto_testsuite_setup,
14433         .unit_test_cases = {
14434                 TEST_CASE_ST(ut_setup_security, ut_teardown,
14435                         test_PDCP_PROTO_all),
14436                 TEST_CASES_END() /**< NULL terminate unit test array */
14437         }
14438 };
14439
14440 static struct unit_test_suite docsis_proto_testsuite  = {
14441         .suite_name = "Docsis Proto Unit Test Suite",
14442         .setup = docsis_proto_testsuite_setup,
14443         .unit_test_cases = {
14444                 TEST_CASE_ST(ut_setup_security, ut_teardown,
14445                         test_DOCSIS_PROTO_all),
14446                 TEST_CASES_END() /**< NULL terminate unit test array */
14447         }
14448 };
14449 #endif
14450
14451 static struct unit_test_suite cryptodev_gen_testsuite  = {
14452         .suite_name = "Crypto General Unit Test Suite",
14453         .setup = crypto_gen_testsuite_setup,
14454         .unit_test_cases = {
14455                 TEST_CASE_ST(ut_setup, ut_teardown,
14456                                 test_device_configure_invalid_dev_id),
14457                 TEST_CASE_ST(ut_setup, ut_teardown,
14458                                 test_queue_pair_descriptor_setup),
14459                 TEST_CASE_ST(ut_setup, ut_teardown,
14460                                 test_device_configure_invalid_queue_pair_ids),
14461                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
14462                 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
14463                 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
14464                 TEST_CASES_END() /**< NULL terminate unit test array */
14465         }
14466 };
14467
14468 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
14469         .suite_name = "Negative HMAC SHA1 Unit Test Suite",
14470         .setup = negative_hmac_sha1_testsuite_setup,
14471         .unit_test_cases = {
14472                 /** Negative tests */
14473                 TEST_CASE_ST(ut_setup, ut_teardown,
14474                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
14475                 TEST_CASE_ST(ut_setup, ut_teardown,
14476                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
14477                 TEST_CASE_ST(ut_setup, ut_teardown,
14478                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
14479                 TEST_CASE_ST(ut_setup, ut_teardown,
14480                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
14481
14482                 TEST_CASES_END() /**< NULL terminate unit test array */
14483         }
14484 };
14485
14486 static struct unit_test_suite cryptodev_multi_session_testsuite = {
14487         .suite_name = "Multi Session Unit Test Suite",
14488         .setup = multi_session_testsuite_setup,
14489         .unit_test_cases = {
14490                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
14491                 TEST_CASE_ST(ut_setup, ut_teardown,
14492                                 test_multi_session_random_usage),
14493
14494                 TEST_CASES_END() /**< NULL terminate unit test array */
14495         }
14496 };
14497
14498 static struct unit_test_suite cryptodev_null_testsuite  = {
14499         .suite_name = "NULL Test Suite",
14500         .setup = null_testsuite_setup,
14501         .unit_test_cases = {
14502                 TEST_CASE_ST(ut_setup, ut_teardown,
14503                         test_null_invalid_operation),
14504                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
14505                 TEST_CASES_END()
14506         }
14507 };
14508
14509 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
14510         .suite_name = "AES CCM Authenticated Test Suite",
14511         .setup = aes_ccm_auth_testsuite_setup,
14512         .unit_test_cases = {
14513                 /** AES CCM Authenticated Encryption 128 bits key*/
14514                 TEST_CASE_ST(ut_setup, ut_teardown,
14515                         test_AES_CCM_authenticated_encryption_test_case_128_1),
14516                 TEST_CASE_ST(ut_setup, ut_teardown,
14517                         test_AES_CCM_authenticated_encryption_test_case_128_2),
14518                 TEST_CASE_ST(ut_setup, ut_teardown,
14519                         test_AES_CCM_authenticated_encryption_test_case_128_3),
14520
14521                 /** AES CCM Authenticated Decryption 128 bits key*/
14522                 TEST_CASE_ST(ut_setup, ut_teardown,
14523                         test_AES_CCM_authenticated_decryption_test_case_128_1),
14524                 TEST_CASE_ST(ut_setup, ut_teardown,
14525                         test_AES_CCM_authenticated_decryption_test_case_128_2),
14526                 TEST_CASE_ST(ut_setup, ut_teardown,
14527                         test_AES_CCM_authenticated_decryption_test_case_128_3),
14528
14529                 /** AES CCM Authenticated Encryption 192 bits key */
14530                 TEST_CASE_ST(ut_setup, ut_teardown,
14531                         test_AES_CCM_authenticated_encryption_test_case_192_1),
14532                 TEST_CASE_ST(ut_setup, ut_teardown,
14533                         test_AES_CCM_authenticated_encryption_test_case_192_2),
14534                 TEST_CASE_ST(ut_setup, ut_teardown,
14535                         test_AES_CCM_authenticated_encryption_test_case_192_3),
14536
14537                 /** AES CCM Authenticated Decryption 192 bits key*/
14538                 TEST_CASE_ST(ut_setup, ut_teardown,
14539                         test_AES_CCM_authenticated_decryption_test_case_192_1),
14540                 TEST_CASE_ST(ut_setup, ut_teardown,
14541                         test_AES_CCM_authenticated_decryption_test_case_192_2),
14542                 TEST_CASE_ST(ut_setup, ut_teardown,
14543                         test_AES_CCM_authenticated_decryption_test_case_192_3),
14544
14545                 /** AES CCM Authenticated Encryption 256 bits key */
14546                 TEST_CASE_ST(ut_setup, ut_teardown,
14547                         test_AES_CCM_authenticated_encryption_test_case_256_1),
14548                 TEST_CASE_ST(ut_setup, ut_teardown,
14549                         test_AES_CCM_authenticated_encryption_test_case_256_2),
14550                 TEST_CASE_ST(ut_setup, ut_teardown,
14551                         test_AES_CCM_authenticated_encryption_test_case_256_3),
14552
14553                 /** AES CCM Authenticated Decryption 256 bits key*/
14554                 TEST_CASE_ST(ut_setup, ut_teardown,
14555                         test_AES_CCM_authenticated_decryption_test_case_256_1),
14556                 TEST_CASE_ST(ut_setup, ut_teardown,
14557                         test_AES_CCM_authenticated_decryption_test_case_256_2),
14558                 TEST_CASE_ST(ut_setup, ut_teardown,
14559                         test_AES_CCM_authenticated_decryption_test_case_256_3),
14560                 TEST_CASES_END()
14561         }
14562 };
14563
14564 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
14565         .suite_name = "AES GCM Authenticated Test Suite",
14566         .setup = aes_gcm_auth_testsuite_setup,
14567         .unit_test_cases = {
14568                 /** AES GCM Authenticated Encryption */
14569                 TEST_CASE_ST(ut_setup, ut_teardown,
14570                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
14571                 TEST_CASE_ST(ut_setup, ut_teardown,
14572                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
14573                 TEST_CASE_ST(ut_setup, ut_teardown,
14574                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
14575                 TEST_CASE_ST(ut_setup, ut_teardown,
14576                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
14577                 TEST_CASE_ST(ut_setup, ut_teardown,
14578                         test_AES_GCM_authenticated_encryption_test_case_1),
14579                 TEST_CASE_ST(ut_setup, ut_teardown,
14580                         test_AES_GCM_authenticated_encryption_test_case_2),
14581                 TEST_CASE_ST(ut_setup, ut_teardown,
14582                         test_AES_GCM_authenticated_encryption_test_case_3),
14583                 TEST_CASE_ST(ut_setup, ut_teardown,
14584                         test_AES_GCM_authenticated_encryption_test_case_4),
14585                 TEST_CASE_ST(ut_setup, ut_teardown,
14586                         test_AES_GCM_authenticated_encryption_test_case_5),
14587                 TEST_CASE_ST(ut_setup, ut_teardown,
14588                         test_AES_GCM_authenticated_encryption_test_case_6),
14589                 TEST_CASE_ST(ut_setup, ut_teardown,
14590                         test_AES_GCM_authenticated_encryption_test_case_7),
14591                 TEST_CASE_ST(ut_setup, ut_teardown,
14592                         test_AES_GCM_authenticated_encryption_test_case_8),
14593                 TEST_CASE_ST(ut_setup, ut_teardown,
14594                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
14595
14596                 /** AES GCM Authenticated Decryption */
14597                 TEST_CASE_ST(ut_setup, ut_teardown,
14598                         test_AES_GCM_authenticated_decryption_test_case_1),
14599                 TEST_CASE_ST(ut_setup, ut_teardown,
14600                         test_AES_GCM_authenticated_decryption_test_case_2),
14601                 TEST_CASE_ST(ut_setup, ut_teardown,
14602                         test_AES_GCM_authenticated_decryption_test_case_3),
14603                 TEST_CASE_ST(ut_setup, ut_teardown,
14604                         test_AES_GCM_authenticated_decryption_test_case_4),
14605                 TEST_CASE_ST(ut_setup, ut_teardown,
14606                         test_AES_GCM_authenticated_decryption_test_case_5),
14607                 TEST_CASE_ST(ut_setup, ut_teardown,
14608                         test_AES_GCM_authenticated_decryption_test_case_6),
14609                 TEST_CASE_ST(ut_setup, ut_teardown,
14610                         test_AES_GCM_authenticated_decryption_test_case_7),
14611                 TEST_CASE_ST(ut_setup, ut_teardown,
14612                         test_AES_GCM_authenticated_decryption_test_case_8),
14613                 TEST_CASE_ST(ut_setup, ut_teardown,
14614                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
14615
14616                 /** AES GCM Authenticated Encryption 192 bits key */
14617                 TEST_CASE_ST(ut_setup, ut_teardown,
14618                         test_AES_GCM_auth_encryption_test_case_192_1),
14619                 TEST_CASE_ST(ut_setup, ut_teardown,
14620                         test_AES_GCM_auth_encryption_test_case_192_2),
14621                 TEST_CASE_ST(ut_setup, ut_teardown,
14622                         test_AES_GCM_auth_encryption_test_case_192_3),
14623                 TEST_CASE_ST(ut_setup, ut_teardown,
14624                         test_AES_GCM_auth_encryption_test_case_192_4),
14625                 TEST_CASE_ST(ut_setup, ut_teardown,
14626                         test_AES_GCM_auth_encryption_test_case_192_5),
14627                 TEST_CASE_ST(ut_setup, ut_teardown,
14628                         test_AES_GCM_auth_encryption_test_case_192_6),
14629                 TEST_CASE_ST(ut_setup, ut_teardown,
14630                         test_AES_GCM_auth_encryption_test_case_192_7),
14631
14632                 /** AES GCM Authenticated Decryption 192 bits key */
14633                 TEST_CASE_ST(ut_setup, ut_teardown,
14634                         test_AES_GCM_auth_decryption_test_case_192_1),
14635                 TEST_CASE_ST(ut_setup, ut_teardown,
14636                         test_AES_GCM_auth_decryption_test_case_192_2),
14637                 TEST_CASE_ST(ut_setup, ut_teardown,
14638                         test_AES_GCM_auth_decryption_test_case_192_3),
14639                 TEST_CASE_ST(ut_setup, ut_teardown,
14640                         test_AES_GCM_auth_decryption_test_case_192_4),
14641                 TEST_CASE_ST(ut_setup, ut_teardown,
14642                         test_AES_GCM_auth_decryption_test_case_192_5),
14643                 TEST_CASE_ST(ut_setup, ut_teardown,
14644                         test_AES_GCM_auth_decryption_test_case_192_6),
14645                 TEST_CASE_ST(ut_setup, ut_teardown,
14646                         test_AES_GCM_auth_decryption_test_case_192_7),
14647
14648                 /** AES GCM Authenticated Encryption 256 bits key */
14649                 TEST_CASE_ST(ut_setup, ut_teardown,
14650                         test_AES_GCM_auth_encryption_test_case_256_1),
14651                 TEST_CASE_ST(ut_setup, ut_teardown,
14652                         test_AES_GCM_auth_encryption_test_case_256_2),
14653                 TEST_CASE_ST(ut_setup, ut_teardown,
14654                         test_AES_GCM_auth_encryption_test_case_256_3),
14655                 TEST_CASE_ST(ut_setup, ut_teardown,
14656                         test_AES_GCM_auth_encryption_test_case_256_4),
14657                 TEST_CASE_ST(ut_setup, ut_teardown,
14658                         test_AES_GCM_auth_encryption_test_case_256_5),
14659                 TEST_CASE_ST(ut_setup, ut_teardown,
14660                         test_AES_GCM_auth_encryption_test_case_256_6),
14661                 TEST_CASE_ST(ut_setup, ut_teardown,
14662                         test_AES_GCM_auth_encryption_test_case_256_7),
14663
14664                 /** AES GCM Authenticated Decryption 256 bits key */
14665                 TEST_CASE_ST(ut_setup, ut_teardown,
14666                         test_AES_GCM_auth_decryption_test_case_256_1),
14667                 TEST_CASE_ST(ut_setup, ut_teardown,
14668                         test_AES_GCM_auth_decryption_test_case_256_2),
14669                 TEST_CASE_ST(ut_setup, ut_teardown,
14670                         test_AES_GCM_auth_decryption_test_case_256_3),
14671                 TEST_CASE_ST(ut_setup, ut_teardown,
14672                         test_AES_GCM_auth_decryption_test_case_256_4),
14673                 TEST_CASE_ST(ut_setup, ut_teardown,
14674                         test_AES_GCM_auth_decryption_test_case_256_5),
14675                 TEST_CASE_ST(ut_setup, ut_teardown,
14676                         test_AES_GCM_auth_decryption_test_case_256_6),
14677                 TEST_CASE_ST(ut_setup, ut_teardown,
14678                         test_AES_GCM_auth_decryption_test_case_256_7),
14679
14680                 /** AES GCM Authenticated Encryption big aad size */
14681                 TEST_CASE_ST(ut_setup, ut_teardown,
14682                         test_AES_GCM_auth_encryption_test_case_aad_1),
14683                 TEST_CASE_ST(ut_setup, ut_teardown,
14684                         test_AES_GCM_auth_encryption_test_case_aad_2),
14685
14686                 /** AES GCM Authenticated Decryption big aad size */
14687                 TEST_CASE_ST(ut_setup, ut_teardown,
14688                         test_AES_GCM_auth_decryption_test_case_aad_1),
14689                 TEST_CASE_ST(ut_setup, ut_teardown,
14690                         test_AES_GCM_auth_decryption_test_case_aad_2),
14691
14692                 /** Out of place tests */
14693                 TEST_CASE_ST(ut_setup, ut_teardown,
14694                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
14695                 TEST_CASE_ST(ut_setup, ut_teardown,
14696                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
14697
14698                 /** Session-less tests */
14699                 TEST_CASE_ST(ut_setup, ut_teardown,
14700                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
14701                 TEST_CASE_ST(ut_setup, ut_teardown,
14702                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
14703
14704                 TEST_CASES_END()
14705         }
14706 };
14707
14708 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
14709         .suite_name = "AES GMAC Authentication Test Suite",
14710         .setup = aes_gmac_auth_testsuite_setup,
14711         .unit_test_cases = {
14712                 TEST_CASE_ST(ut_setup, ut_teardown,
14713                         test_AES_GMAC_authentication_test_case_1),
14714                 TEST_CASE_ST(ut_setup, ut_teardown,
14715                         test_AES_GMAC_authentication_verify_test_case_1),
14716                 TEST_CASE_ST(ut_setup, ut_teardown,
14717                         test_AES_GMAC_authentication_test_case_2),
14718                 TEST_CASE_ST(ut_setup, ut_teardown,
14719                         test_AES_GMAC_authentication_verify_test_case_2),
14720                 TEST_CASE_ST(ut_setup, ut_teardown,
14721                         test_AES_GMAC_authentication_test_case_3),
14722                 TEST_CASE_ST(ut_setup, ut_teardown,
14723                         test_AES_GMAC_authentication_verify_test_case_3),
14724                 TEST_CASE_ST(ut_setup, ut_teardown,
14725                         test_AES_GMAC_authentication_test_case_4),
14726                 TEST_CASE_ST(ut_setup, ut_teardown,
14727                         test_AES_GMAC_authentication_verify_test_case_4),
14728                 TEST_CASE_ST(ut_setup, ut_teardown,
14729                         test_AES_GMAC_authentication_SGL_40B),
14730                 TEST_CASE_ST(ut_setup, ut_teardown,
14731                         test_AES_GMAC_authentication_SGL_80B),
14732                 TEST_CASE_ST(ut_setup, ut_teardown,
14733                         test_AES_GMAC_authentication_SGL_2048B),
14734                 TEST_CASE_ST(ut_setup, ut_teardown,
14735                         test_AES_GMAC_authentication_SGL_2047B),
14736
14737                 TEST_CASES_END()
14738         }
14739 };
14740
14741 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14742         .suite_name = "Chacha20-Poly1305 Test Suite",
14743         .setup = chacha20_poly1305_testsuite_setup,
14744         .unit_test_cases = {
14745                 TEST_CASE_ST(ut_setup, ut_teardown,
14746                         test_chacha20_poly1305_encrypt_test_case_rfc8439),
14747                 TEST_CASE_ST(ut_setup, ut_teardown,
14748                         test_chacha20_poly1305_decrypt_test_case_rfc8439),
14749                 TEST_CASES_END()
14750         }
14751 };
14752
14753 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14754         .suite_name = "SNOW 3G Test Suite",
14755         .setup = snow3g_testsuite_setup,
14756         .unit_test_cases = {
14757                 /** SNOW 3G encrypt only (UEA2) */
14758                 TEST_CASE_ST(ut_setup, ut_teardown,
14759                         test_snow3g_encryption_test_case_1),
14760                 TEST_CASE_ST(ut_setup, ut_teardown,
14761                         test_snow3g_encryption_test_case_2),
14762                 TEST_CASE_ST(ut_setup, ut_teardown,
14763                         test_snow3g_encryption_test_case_3),
14764                 TEST_CASE_ST(ut_setup, ut_teardown,
14765                         test_snow3g_encryption_test_case_4),
14766                 TEST_CASE_ST(ut_setup, ut_teardown,
14767                         test_snow3g_encryption_test_case_5),
14768
14769                 TEST_CASE_ST(ut_setup, ut_teardown,
14770                         test_snow3g_encryption_test_case_1_oop),
14771                 TEST_CASE_ST(ut_setup, ut_teardown,
14772                         test_snow3g_encryption_test_case_1_oop_sgl),
14773                 TEST_CASE_ST(ut_setup, ut_teardown,
14774                         test_snow3g_encryption_test_case_1_offset_oop),
14775                 TEST_CASE_ST(ut_setup, ut_teardown,
14776                         test_snow3g_decryption_test_case_1_oop),
14777
14778                 /** SNOW 3G generate auth, then encrypt (UEA2) */
14779                 TEST_CASE_ST(ut_setup, ut_teardown,
14780                         test_snow3g_auth_cipher_test_case_1),
14781                 TEST_CASE_ST(ut_setup, ut_teardown,
14782                         test_snow3g_auth_cipher_test_case_2),
14783                 TEST_CASE_ST(ut_setup, ut_teardown,
14784                         test_snow3g_auth_cipher_test_case_2_oop),
14785                 TEST_CASE_ST(ut_setup, ut_teardown,
14786                         test_snow3g_auth_cipher_part_digest_enc),
14787                 TEST_CASE_ST(ut_setup, ut_teardown,
14788                         test_snow3g_auth_cipher_part_digest_enc_oop),
14789                 TEST_CASE_ST(ut_setup, ut_teardown,
14790                         test_snow3g_auth_cipher_test_case_3_sgl),
14791                 TEST_CASE_ST(ut_setup, ut_teardown,
14792                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
14793                 TEST_CASE_ST(ut_setup, ut_teardown,
14794                         test_snow3g_auth_cipher_part_digest_enc_sgl),
14795                 TEST_CASE_ST(ut_setup, ut_teardown,
14796                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14797
14798                 /** SNOW 3G decrypt (UEA2), then verify auth */
14799                 TEST_CASE_ST(ut_setup, ut_teardown,
14800                         test_snow3g_auth_cipher_verify_test_case_1),
14801                 TEST_CASE_ST(ut_setup, ut_teardown,
14802                         test_snow3g_auth_cipher_verify_test_case_2),
14803                 TEST_CASE_ST(ut_setup, ut_teardown,
14804                         test_snow3g_auth_cipher_verify_test_case_2_oop),
14805                 TEST_CASE_ST(ut_setup, ut_teardown,
14806                         test_snow3g_auth_cipher_verify_part_digest_enc),
14807                 TEST_CASE_ST(ut_setup, ut_teardown,
14808                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14809                 TEST_CASE_ST(ut_setup, ut_teardown,
14810                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
14811                 TEST_CASE_ST(ut_setup, ut_teardown,
14812                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14813                 TEST_CASE_ST(ut_setup, ut_teardown,
14814                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14815                 TEST_CASE_ST(ut_setup, ut_teardown,
14816                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14817
14818                 /** SNOW 3G decrypt only (UEA2) */
14819                 TEST_CASE_ST(ut_setup, ut_teardown,
14820                         test_snow3g_decryption_test_case_1),
14821                 TEST_CASE_ST(ut_setup, ut_teardown,
14822                         test_snow3g_decryption_test_case_2),
14823                 TEST_CASE_ST(ut_setup, ut_teardown,
14824                         test_snow3g_decryption_test_case_3),
14825                 TEST_CASE_ST(ut_setup, ut_teardown,
14826                         test_snow3g_decryption_test_case_4),
14827                 TEST_CASE_ST(ut_setup, ut_teardown,
14828                         test_snow3g_decryption_test_case_5),
14829                 TEST_CASE_ST(ut_setup, ut_teardown,
14830                         test_snow3g_decryption_with_digest_test_case_1),
14831                 TEST_CASE_ST(ut_setup, ut_teardown,
14832                         test_snow3g_hash_generate_test_case_1),
14833                 TEST_CASE_ST(ut_setup, ut_teardown,
14834                         test_snow3g_hash_generate_test_case_2),
14835                 TEST_CASE_ST(ut_setup, ut_teardown,
14836                         test_snow3g_hash_generate_test_case_3),
14837
14838                 /* Tests with buffers which length is not byte-aligned */
14839                 TEST_CASE_ST(ut_setup, ut_teardown,
14840                         test_snow3g_hash_generate_test_case_4),
14841                 TEST_CASE_ST(ut_setup, ut_teardown,
14842                         test_snow3g_hash_generate_test_case_5),
14843                 TEST_CASE_ST(ut_setup, ut_teardown,
14844                         test_snow3g_hash_generate_test_case_6),
14845                 TEST_CASE_ST(ut_setup, ut_teardown,
14846                         test_snow3g_hash_verify_test_case_1),
14847                 TEST_CASE_ST(ut_setup, ut_teardown,
14848                         test_snow3g_hash_verify_test_case_2),
14849                 TEST_CASE_ST(ut_setup, ut_teardown,
14850                         test_snow3g_hash_verify_test_case_3),
14851
14852                 /* Tests with buffers which length is not byte-aligned */
14853                 TEST_CASE_ST(ut_setup, ut_teardown,
14854                         test_snow3g_hash_verify_test_case_4),
14855                 TEST_CASE_ST(ut_setup, ut_teardown,
14856                         test_snow3g_hash_verify_test_case_5),
14857                 TEST_CASE_ST(ut_setup, ut_teardown,
14858                         test_snow3g_hash_verify_test_case_6),
14859                 TEST_CASE_ST(ut_setup, ut_teardown,
14860                         test_snow3g_cipher_auth_test_case_1),
14861                 TEST_CASE_ST(ut_setup, ut_teardown,
14862                         test_snow3g_auth_cipher_with_digest_test_case_1),
14863                 TEST_CASES_END()
14864         }
14865 };
14866
14867 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14868         .suite_name = "ZUC Test Suite",
14869         .setup = zuc_testsuite_setup,
14870         .unit_test_cases = {
14871                 /** ZUC encrypt only (EEA3) */
14872                 TEST_CASE_ST(ut_setup, ut_teardown,
14873                         test_zuc_encryption_test_case_1),
14874                 TEST_CASE_ST(ut_setup, ut_teardown,
14875                         test_zuc_encryption_test_case_2),
14876                 TEST_CASE_ST(ut_setup, ut_teardown,
14877                         test_zuc_encryption_test_case_3),
14878                 TEST_CASE_ST(ut_setup, ut_teardown,
14879                         test_zuc_encryption_test_case_4),
14880                 TEST_CASE_ST(ut_setup, ut_teardown,
14881                         test_zuc_encryption_test_case_5),
14882                 TEST_CASE_ST(ut_setup, ut_teardown,
14883                         test_zuc_encryption_test_case_6_sgl),
14884                 TEST_CASE_ST(ut_setup, ut_teardown,
14885                         test_zuc_encryption_test_case_7),
14886
14887                 /** ZUC authenticate (EIA3) */
14888                 TEST_CASE_ST(ut_setup, ut_teardown,
14889                         test_zuc_hash_generate_test_case_1),
14890                 TEST_CASE_ST(ut_setup, ut_teardown,
14891                         test_zuc_hash_generate_test_case_2),
14892                 TEST_CASE_ST(ut_setup, ut_teardown,
14893                         test_zuc_hash_generate_test_case_3),
14894                 TEST_CASE_ST(ut_setup, ut_teardown,
14895                         test_zuc_hash_generate_test_case_4),
14896                 TEST_CASE_ST(ut_setup, ut_teardown,
14897                         test_zuc_hash_generate_test_case_5),
14898                 TEST_CASE_ST(ut_setup, ut_teardown,
14899                         test_zuc_hash_generate_test_case_6),
14900                 TEST_CASE_ST(ut_setup, ut_teardown,
14901                         test_zuc_hash_generate_test_case_7),
14902                 TEST_CASE_ST(ut_setup, ut_teardown,
14903                         test_zuc_hash_generate_test_case_8),
14904                 TEST_CASE_ST(ut_setup, ut_teardown,
14905                         test_zuc_hash_generate_test_case_9),
14906                 TEST_CASE_ST(ut_setup, ut_teardown,
14907                         test_zuc_hash_generate_test_case_10),
14908
14909
14910                 /** ZUC alg-chain (EEA3/EIA3) */
14911                 TEST_CASE_ST(ut_setup, ut_teardown,
14912                         test_zuc_cipher_auth_test_case_1),
14913                 TEST_CASE_ST(ut_setup, ut_teardown,
14914                         test_zuc_cipher_auth_test_case_2),
14915
14916                 /** ZUC generate auth, then encrypt (EEA3) */
14917                 TEST_CASE_ST(ut_setup, ut_teardown,
14918                         test_zuc_auth_cipher_test_case_1),
14919                 TEST_CASE_ST(ut_setup, ut_teardown,
14920                         test_zuc_auth_cipher_test_case_1_oop),
14921                 TEST_CASE_ST(ut_setup, ut_teardown,
14922                         test_zuc_auth_cipher_test_case_1_sgl),
14923                 TEST_CASE_ST(ut_setup, ut_teardown,
14924                         test_zuc_auth_cipher_test_case_1_oop_sgl),
14925
14926                 /** ZUC decrypt (EEA3), then verify auth */
14927                 TEST_CASE_ST(ut_setup, ut_teardown,
14928                         test_zuc_auth_cipher_verify_test_case_1),
14929                 TEST_CASE_ST(ut_setup, ut_teardown,
14930                         test_zuc_auth_cipher_verify_test_case_1_oop),
14931                 TEST_CASE_ST(ut_setup, ut_teardown,
14932                         test_zuc_auth_cipher_verify_test_case_1_sgl),
14933                 TEST_CASE_ST(ut_setup, ut_teardown,
14934                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
14935                 TEST_CASES_END()
14936         }
14937 };
14938
14939 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
14940         .suite_name = "HMAC_MD5 Authentication Test Suite",
14941         .setup = hmac_md5_auth_testsuite_setup,
14942         .unit_test_cases = {
14943                 TEST_CASE_ST(ut_setup, ut_teardown,
14944                         test_MD5_HMAC_generate_case_1),
14945                 TEST_CASE_ST(ut_setup, ut_teardown,
14946                         test_MD5_HMAC_verify_case_1),
14947                 TEST_CASE_ST(ut_setup, ut_teardown,
14948                         test_MD5_HMAC_generate_case_2),
14949                 TEST_CASE_ST(ut_setup, ut_teardown,
14950                         test_MD5_HMAC_verify_case_2),
14951                 TEST_CASES_END()
14952         }
14953 };
14954
14955 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
14956         .suite_name = "Kasumi Test Suite",
14957         .setup = kasumi_testsuite_setup,
14958         .unit_test_cases = {
14959                 /** KASUMI hash only (UIA1) */
14960                 TEST_CASE_ST(ut_setup, ut_teardown,
14961                         test_kasumi_hash_generate_test_case_1),
14962                 TEST_CASE_ST(ut_setup, ut_teardown,
14963                         test_kasumi_hash_generate_test_case_2),
14964                 TEST_CASE_ST(ut_setup, ut_teardown,
14965                         test_kasumi_hash_generate_test_case_3),
14966                 TEST_CASE_ST(ut_setup, ut_teardown,
14967                         test_kasumi_hash_generate_test_case_4),
14968                 TEST_CASE_ST(ut_setup, ut_teardown,
14969                         test_kasumi_hash_generate_test_case_5),
14970                 TEST_CASE_ST(ut_setup, ut_teardown,
14971                         test_kasumi_hash_generate_test_case_6),
14972
14973                 TEST_CASE_ST(ut_setup, ut_teardown,
14974                         test_kasumi_hash_verify_test_case_1),
14975                 TEST_CASE_ST(ut_setup, ut_teardown,
14976                         test_kasumi_hash_verify_test_case_2),
14977                 TEST_CASE_ST(ut_setup, ut_teardown,
14978                         test_kasumi_hash_verify_test_case_3),
14979                 TEST_CASE_ST(ut_setup, ut_teardown,
14980                         test_kasumi_hash_verify_test_case_4),
14981                 TEST_CASE_ST(ut_setup, ut_teardown,
14982                         test_kasumi_hash_verify_test_case_5),
14983
14984                 /** KASUMI encrypt only (UEA1) */
14985                 TEST_CASE_ST(ut_setup, ut_teardown,
14986                         test_kasumi_encryption_test_case_1),
14987                 TEST_CASE_ST(ut_setup, ut_teardown,
14988                         test_kasumi_encryption_test_case_1_sgl),
14989                 TEST_CASE_ST(ut_setup, ut_teardown,
14990                         test_kasumi_encryption_test_case_1_oop),
14991                 TEST_CASE_ST(ut_setup, ut_teardown,
14992                         test_kasumi_encryption_test_case_1_oop_sgl),
14993                 TEST_CASE_ST(ut_setup, ut_teardown,
14994                         test_kasumi_encryption_test_case_2),
14995                 TEST_CASE_ST(ut_setup, ut_teardown,
14996                         test_kasumi_encryption_test_case_3),
14997                 TEST_CASE_ST(ut_setup, ut_teardown,
14998                         test_kasumi_encryption_test_case_4),
14999                 TEST_CASE_ST(ut_setup, ut_teardown,
15000                         test_kasumi_encryption_test_case_5),
15001
15002                 /** KASUMI decrypt only (UEA1) */
15003                 TEST_CASE_ST(ut_setup, ut_teardown,
15004                         test_kasumi_decryption_test_case_1),
15005                 TEST_CASE_ST(ut_setup, ut_teardown,
15006                         test_kasumi_decryption_test_case_2),
15007                 TEST_CASE_ST(ut_setup, ut_teardown,
15008                         test_kasumi_decryption_test_case_3),
15009                 TEST_CASE_ST(ut_setup, ut_teardown,
15010                         test_kasumi_decryption_test_case_4),
15011                 TEST_CASE_ST(ut_setup, ut_teardown,
15012                         test_kasumi_decryption_test_case_5),
15013                 TEST_CASE_ST(ut_setup, ut_teardown,
15014                         test_kasumi_decryption_test_case_1_oop),
15015                 TEST_CASE_ST(ut_setup, ut_teardown,
15016                         test_kasumi_cipher_auth_test_case_1),
15017
15018                 /** KASUMI generate auth, then encrypt (F8) */
15019                 TEST_CASE_ST(ut_setup, ut_teardown,
15020                         test_kasumi_auth_cipher_test_case_1),
15021                 TEST_CASE_ST(ut_setup, ut_teardown,
15022                         test_kasumi_auth_cipher_test_case_2),
15023                 TEST_CASE_ST(ut_setup, ut_teardown,
15024                         test_kasumi_auth_cipher_test_case_2_oop),
15025                 TEST_CASE_ST(ut_setup, ut_teardown,
15026                         test_kasumi_auth_cipher_test_case_2_sgl),
15027                 TEST_CASE_ST(ut_setup, ut_teardown,
15028                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
15029
15030                 /** KASUMI decrypt (F8), then verify auth */
15031                 TEST_CASE_ST(ut_setup, ut_teardown,
15032                         test_kasumi_auth_cipher_verify_test_case_1),
15033                 TEST_CASE_ST(ut_setup, ut_teardown,
15034                         test_kasumi_auth_cipher_verify_test_case_2),
15035                 TEST_CASE_ST(ut_setup, ut_teardown,
15036                         test_kasumi_auth_cipher_verify_test_case_2_oop),
15037                 TEST_CASE_ST(ut_setup, ut_teardown,
15038                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
15039                 TEST_CASE_ST(ut_setup, ut_teardown,
15040                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
15041
15042                 TEST_CASES_END()
15043         }
15044 };
15045
15046 static struct unit_test_suite cryptodev_esn_testsuite  = {
15047         .suite_name = "ESN Test Suite",
15048         .setup = esn_testsuite_setup,
15049         .unit_test_cases = {
15050                 TEST_CASE_ST(ut_setup, ut_teardown,
15051                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
15052                 TEST_CASE_ST(ut_setup, ut_teardown,
15053                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
15054                 TEST_CASES_END()
15055         }
15056 };
15057
15058 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
15059         .suite_name = "Negative AES GCM Test Suite",
15060         .setup = negative_aes_gcm_testsuite_setup,
15061         .unit_test_cases = {
15062                 TEST_CASE_ST(ut_setup, ut_teardown,
15063                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
15064                 TEST_CASE_ST(ut_setup, ut_teardown,
15065                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
15066                 TEST_CASE_ST(ut_setup, ut_teardown,
15067                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
15068                 TEST_CASE_ST(ut_setup, ut_teardown,
15069                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
15070                 TEST_CASE_ST(ut_setup, ut_teardown,
15071                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
15072                 TEST_CASE_ST(ut_setup, ut_teardown,
15073                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
15074                 TEST_CASE_ST(ut_setup, ut_teardown,
15075                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
15076                 TEST_CASE_ST(ut_setup, ut_teardown,
15077                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
15078                 TEST_CASE_ST(ut_setup, ut_teardown,
15079                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
15080                 TEST_CASE_ST(ut_setup, ut_teardown,
15081                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
15082                 TEST_CASE_ST(ut_setup, ut_teardown,
15083                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
15084                 TEST_CASE_ST(ut_setup, ut_teardown,
15085                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
15086
15087                 TEST_CASES_END()
15088         }
15089 };
15090
15091 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
15092         .suite_name = "Negative AES GMAC Test Suite",
15093         .setup = negative_aes_gmac_testsuite_setup,
15094         .unit_test_cases = {
15095                 TEST_CASE_ST(ut_setup, ut_teardown,
15096                         authentication_verify_AES128_GMAC_fail_data_corrupt),
15097                 TEST_CASE_ST(ut_setup, ut_teardown,
15098                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
15099
15100                 TEST_CASES_END()
15101         }
15102 };
15103
15104 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
15105         .suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
15106         .setup = mixed_cipher_hash_testsuite_setup,
15107         .unit_test_cases = {
15108                 /** AUTH AES CMAC + CIPHER AES CTR */
15109                 TEST_CASE_ST(ut_setup, ut_teardown,
15110                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
15111                 TEST_CASE_ST(ut_setup, ut_teardown,
15112                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
15113                 TEST_CASE_ST(ut_setup, ut_teardown,
15114                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
15115                 TEST_CASE_ST(ut_setup, ut_teardown,
15116                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
15117                 TEST_CASE_ST(ut_setup, ut_teardown,
15118                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
15119                 TEST_CASE_ST(ut_setup, ut_teardown,
15120                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
15121                 TEST_CASE_ST(ut_setup, ut_teardown,
15122                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
15123                 TEST_CASE_ST(ut_setup, ut_teardown,
15124                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
15125
15126                 /** AUTH ZUC + CIPHER SNOW3G */
15127                 TEST_CASE_ST(ut_setup, ut_teardown,
15128                         test_auth_zuc_cipher_snow_test_case_1),
15129                 TEST_CASE_ST(ut_setup, ut_teardown,
15130                         test_verify_auth_zuc_cipher_snow_test_case_1),
15131                 /** AUTH AES CMAC + CIPHER SNOW3G */
15132                 TEST_CASE_ST(ut_setup, ut_teardown,
15133                         test_auth_aes_cmac_cipher_snow_test_case_1),
15134                 TEST_CASE_ST(ut_setup, ut_teardown,
15135                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
15136                 /** AUTH ZUC + CIPHER AES CTR */
15137                 TEST_CASE_ST(ut_setup, ut_teardown,
15138                         test_auth_zuc_cipher_aes_ctr_test_case_1),
15139                 TEST_CASE_ST(ut_setup, ut_teardown,
15140                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
15141                 /** AUTH SNOW3G + CIPHER AES CTR */
15142                 TEST_CASE_ST(ut_setup, ut_teardown,
15143                         test_auth_snow_cipher_aes_ctr_test_case_1),
15144                 TEST_CASE_ST(ut_setup, ut_teardown,
15145                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
15146                 /** AUTH SNOW3G + CIPHER ZUC */
15147                 TEST_CASE_ST(ut_setup, ut_teardown,
15148                         test_auth_snow_cipher_zuc_test_case_1),
15149                 TEST_CASE_ST(ut_setup, ut_teardown,
15150                         test_verify_auth_snow_cipher_zuc_test_case_1),
15151                 /** AUTH AES CMAC + CIPHER ZUC */
15152                 TEST_CASE_ST(ut_setup, ut_teardown,
15153                         test_auth_aes_cmac_cipher_zuc_test_case_1),
15154                 TEST_CASE_ST(ut_setup, ut_teardown,
15155                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
15156
15157                 /** AUTH NULL + CIPHER SNOW3G */
15158                 TEST_CASE_ST(ut_setup, ut_teardown,
15159                         test_auth_null_cipher_snow_test_case_1),
15160                 TEST_CASE_ST(ut_setup, ut_teardown,
15161                         test_verify_auth_null_cipher_snow_test_case_1),
15162                 /** AUTH NULL + CIPHER ZUC */
15163                 TEST_CASE_ST(ut_setup, ut_teardown,
15164                         test_auth_null_cipher_zuc_test_case_1),
15165                 TEST_CASE_ST(ut_setup, ut_teardown,
15166                         test_verify_auth_null_cipher_zuc_test_case_1),
15167                 /** AUTH SNOW3G + CIPHER NULL */
15168                 TEST_CASE_ST(ut_setup, ut_teardown,
15169                         test_auth_snow_cipher_null_test_case_1),
15170                 TEST_CASE_ST(ut_setup, ut_teardown,
15171                         test_verify_auth_snow_cipher_null_test_case_1),
15172                 /** AUTH ZUC + CIPHER NULL */
15173                 TEST_CASE_ST(ut_setup, ut_teardown,
15174                         test_auth_zuc_cipher_null_test_case_1),
15175                 TEST_CASE_ST(ut_setup, ut_teardown,
15176                         test_verify_auth_zuc_cipher_null_test_case_1),
15177                 /** AUTH NULL + CIPHER AES CTR */
15178                 TEST_CASE_ST(ut_setup, ut_teardown,
15179                         test_auth_null_cipher_aes_ctr_test_case_1),
15180                 TEST_CASE_ST(ut_setup, ut_teardown,
15181                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
15182                 /** AUTH AES CMAC + CIPHER NULL */
15183                 TEST_CASE_ST(ut_setup, ut_teardown,
15184                         test_auth_aes_cmac_cipher_null_test_case_1),
15185                 TEST_CASE_ST(ut_setup, ut_teardown,
15186                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
15187                 TEST_CASES_END()
15188         }
15189 };
15190
15191 static int
15192 run_cryptodev_testsuite(const char *pmd_name)
15193 {
15194         uint8_t ret, j, i = 0, blk_start_idx = 0;
15195         const enum blockcipher_test_type blk_suites[] = {
15196                 BLKCIPHER_AES_CHAIN_TYPE,
15197                 BLKCIPHER_AES_CIPHERONLY_TYPE,
15198                 BLKCIPHER_AES_DOCSIS_TYPE,
15199                 BLKCIPHER_3DES_CHAIN_TYPE,
15200                 BLKCIPHER_3DES_CIPHERONLY_TYPE,
15201                 BLKCIPHER_DES_CIPHERONLY_TYPE,
15202                 BLKCIPHER_DES_DOCSIS_TYPE,
15203                 BLKCIPHER_AUTHONLY_TYPE};
15204         struct unit_test_suite *static_suites[] = {
15205                 &cryptodev_multi_session_testsuite,
15206                 &cryptodev_null_testsuite,
15207                 &cryptodev_aes_ccm_auth_testsuite,
15208                 &cryptodev_aes_gcm_auth_testsuite,
15209                 &cryptodev_aes_gmac_auth_testsuite,
15210                 &cryptodev_snow3g_testsuite,
15211                 &cryptodev_chacha20_poly1305_testsuite,
15212                 &cryptodev_zuc_testsuite,
15213                 &cryptodev_hmac_md5_auth_testsuite,
15214                 &cryptodev_kasumi_testsuite,
15215                 &cryptodev_esn_testsuite,
15216                 &cryptodev_negative_aes_gcm_testsuite,
15217                 &cryptodev_negative_aes_gmac_testsuite,
15218                 &cryptodev_mixed_cipher_hash_testsuite,
15219                 &cryptodev_negative_hmac_sha1_testsuite,
15220                 &cryptodev_gen_testsuite,
15221 #ifdef RTE_LIB_SECURITY
15222                 &ipsec_proto_testsuite,
15223                 &pdcp_proto_testsuite,
15224                 &docsis_proto_testsuite,
15225 #endif
15226                 &end_testsuite
15227         };
15228         static struct unit_test_suite ts = {
15229                 .suite_name = "Cryptodev Unit Test Suite",
15230                 .setup = testsuite_setup,
15231                 .teardown = testsuite_teardown,
15232                 .unit_test_cases = {TEST_CASES_END()}
15233         };
15234
15235         gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
15236
15237         if (gbl_driver_id == -1) {
15238                 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
15239                 return TEST_SKIPPED;
15240         }
15241
15242         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15243                         (RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
15244
15245         ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
15246         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15247         ret = unit_test_suite_runner(&ts);
15248
15249         FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
15250         free(ts.unit_test_suites);
15251         return ret;
15252 }
15253
15254 static int
15255 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
15256 {
15257         struct rte_cryptodev_info dev_info;
15258         uint8_t i, nb_devs;
15259         int driver_id;
15260
15261         driver_id = rte_cryptodev_driver_id_get(pmd_name);
15262         if (driver_id == -1) {
15263                 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
15264                 return TEST_SKIPPED;
15265         }
15266
15267         nb_devs = rte_cryptodev_count();
15268         if (nb_devs < 1) {
15269                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
15270                 return TEST_SKIPPED;
15271         }
15272
15273         for (i = 0; i < nb_devs; i++) {
15274                 rte_cryptodev_info_get(i, &dev_info);
15275                 if (dev_info.driver_id == driver_id) {
15276                         if (!(dev_info.feature_flags & flag)) {
15277                                 RTE_LOG(INFO, USER1, "%s not supported\n",
15278                                                 flag_name);
15279                                 return TEST_SKIPPED;
15280                         }
15281                         return 0; /* found */
15282                 }
15283         }
15284
15285         RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
15286         return TEST_SKIPPED;
15287 }
15288
15289 static int
15290 test_cryptodev_qat(void)
15291 {
15292         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
15293 }
15294
15295 static int
15296 test_cryptodev_virtio(void)
15297 {
15298         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
15299 }
15300
15301 static int
15302 test_cryptodev_aesni_mb(void)
15303 {
15304         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15305 }
15306
15307 static int
15308 test_cryptodev_cpu_aesni_mb(void)
15309 {
15310         int32_t rc;
15311         enum rte_security_session_action_type at = gbl_action_type;
15312         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15313         rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15314         gbl_action_type = at;
15315         return rc;
15316 }
15317
15318 static int
15319 test_cryptodev_openssl(void)
15320 {
15321         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
15322 }
15323
15324 static int
15325 test_cryptodev_aesni_gcm(void)
15326 {
15327         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15328 }
15329
15330 static int
15331 test_cryptodev_cpu_aesni_gcm(void)
15332 {
15333         int32_t rc;
15334         enum rte_security_session_action_type at = gbl_action_type;
15335         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15336         rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15337         gbl_action_type = at;
15338         return rc;
15339 }
15340
15341 static int
15342 test_cryptodev_mlx5(void)
15343 {
15344         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
15345 }
15346
15347 static int
15348 test_cryptodev_null(void)
15349 {
15350         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
15351 }
15352
15353 static int
15354 test_cryptodev_sw_snow3g(void)
15355 {
15356         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
15357 }
15358
15359 static int
15360 test_cryptodev_sw_kasumi(void)
15361 {
15362         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
15363 }
15364
15365 static int
15366 test_cryptodev_sw_zuc(void)
15367 {
15368         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
15369 }
15370
15371 static int
15372 test_cryptodev_armv8(void)
15373 {
15374         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
15375 }
15376
15377 static int
15378 test_cryptodev_mrvl(void)
15379 {
15380         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
15381 }
15382
15383 #ifdef RTE_CRYPTO_SCHEDULER
15384
15385 static int
15386 test_cryptodev_scheduler(void)
15387 {
15388         uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
15389         const enum blockcipher_test_type blk_suites[] = {
15390                 BLKCIPHER_AES_CHAIN_TYPE,
15391                 BLKCIPHER_AES_CIPHERONLY_TYPE,
15392                 BLKCIPHER_AUTHONLY_TYPE
15393         };
15394         static struct unit_test_suite scheduler_multicore = {
15395                 .suite_name = "Scheduler Multicore Unit Test Suite",
15396                 .setup = scheduler_multicore_testsuite_setup,
15397                 .teardown = scheduler_mode_testsuite_teardown,
15398                 .unit_test_cases = {TEST_CASES_END()}
15399         };
15400         static struct unit_test_suite scheduler_round_robin = {
15401                 .suite_name = "Scheduler Round Robin Unit Test Suite",
15402                 .setup = scheduler_roundrobin_testsuite_setup,
15403                 .teardown = scheduler_mode_testsuite_teardown,
15404                 .unit_test_cases = {TEST_CASES_END()}
15405         };
15406         static struct unit_test_suite scheduler_failover = {
15407                 .suite_name = "Scheduler Failover Unit Test Suite",
15408                 .setup = scheduler_failover_testsuite_setup,
15409                 .teardown = scheduler_mode_testsuite_teardown,
15410                 .unit_test_cases = {TEST_CASES_END()}
15411         };
15412         static struct unit_test_suite scheduler_pkt_size_distr = {
15413                 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
15414                 .setup = scheduler_pkt_size_distr_testsuite_setup,
15415                 .teardown = scheduler_mode_testsuite_teardown,
15416                 .unit_test_cases = {TEST_CASES_END()}
15417         };
15418         struct unit_test_suite *sched_mode_suites[] = {
15419                 &scheduler_multicore,
15420                 &scheduler_round_robin,
15421                 &scheduler_failover,
15422                 &scheduler_pkt_size_distr
15423         };
15424         static struct unit_test_suite scheduler_config = {
15425                 .suite_name = "Crypto Device Scheduler Config Unit Test Suite",
15426                 .unit_test_cases = {
15427                         TEST_CASE(test_scheduler_attach_worker_op),
15428                         TEST_CASE(test_scheduler_mode_multicore_op),
15429                         TEST_CASE(test_scheduler_mode_roundrobin_op),
15430                         TEST_CASE(test_scheduler_mode_failover_op),
15431                         TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
15432                         TEST_CASE(test_scheduler_detach_worker_op),
15433
15434                         TEST_CASES_END() /**< NULL terminate array */
15435                 }
15436         };
15437         struct unit_test_suite *static_suites[] = {
15438                 &scheduler_config,
15439                 &end_testsuite
15440         };
15441         static struct unit_test_suite ts = {
15442                 .suite_name = "Scheduler Unit Test Suite",
15443                 .setup = scheduler_testsuite_setup,
15444                 .teardown = testsuite_teardown,
15445                 .unit_test_cases = {TEST_CASES_END()}
15446         };
15447
15448         gbl_driver_id = rte_cryptodev_driver_id_get(
15449                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
15450
15451         if (gbl_driver_id == -1) {
15452                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
15453                 return TEST_SKIPPED;
15454         }
15455
15456         if (rte_cryptodev_driver_id_get(
15457                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
15458                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
15459                 return TEST_SKIPPED;
15460         }
15461
15462         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15463                 uint8_t blk_i = 0;
15464                 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
15465                                 (struct unit_test_suite *) *
15466                                 (RTE_DIM(blk_suites) + 1));
15467                 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
15468                                 blk_suites, RTE_DIM(blk_suites));
15469                 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
15470         }
15471
15472         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15473                         (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
15474         ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
15475                         RTE_DIM(sched_mode_suites));
15476         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15477         ret = unit_test_suite_runner(&ts);
15478
15479         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15480                 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
15481                                 (*sched_mode_suites[sched_i]),
15482                                 RTE_DIM(blk_suites));
15483                 free(sched_mode_suites[sched_i]->unit_test_suites);
15484         }
15485         free(ts.unit_test_suites);
15486         return ret;
15487 }
15488
15489 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
15490
15491 #endif
15492
15493 static int
15494 test_cryptodev_dpaa2_sec(void)
15495 {
15496         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
15497 }
15498
15499 static int
15500 test_cryptodev_dpaa_sec(void)
15501 {
15502         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
15503 }
15504
15505 static int
15506 test_cryptodev_ccp(void)
15507 {
15508         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
15509 }
15510
15511 static int
15512 test_cryptodev_octeontx(void)
15513 {
15514         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
15515 }
15516
15517 static int
15518 test_cryptodev_octeontx2(void)
15519 {
15520         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
15521 }
15522
15523 static int
15524 test_cryptodev_caam_jr(void)
15525 {
15526         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
15527 }
15528
15529 static int
15530 test_cryptodev_nitrox(void)
15531 {
15532         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
15533 }
15534
15535 static int
15536 test_cryptodev_bcmfs(void)
15537 {
15538         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
15539 }
15540
15541 static int
15542 test_cryptodev_qat_raw_api(void)
15543 {
15544         static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
15545         int ret;
15546
15547         ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15548                         "RAW API");
15549         if (ret)
15550                 return ret;
15551
15552         global_api_test_type = CRYPTODEV_RAW_API_TEST;
15553         ret = run_cryptodev_testsuite(pmd_name);
15554         global_api_test_type = CRYPTODEV_API_TEST;
15555
15556         return ret;
15557 }
15558
15559 static int
15560 test_cryptodev_cn9k(void)
15561 {
15562         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
15563 }
15564
15565 static int
15566 test_cryptodev_cn10k(void)
15567 {
15568         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
15569 }
15570
15571 static int
15572 test_cryptodev_dpaa2_sec_raw_api(void)
15573 {
15574         static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
15575         int ret;
15576
15577         ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15578                         "RAW API");
15579         if (ret)
15580                 return ret;
15581
15582         global_api_test_type = CRYPTODEV_RAW_API_TEST;
15583         ret = run_cryptodev_testsuite(pmd_name);
15584         global_api_test_type = CRYPTODEV_API_TEST;
15585
15586         return ret;
15587 }
15588
15589 static int
15590 test_cryptodev_dpaa_sec_raw_api(void)
15591 {
15592         static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
15593         int ret;
15594
15595         ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15596                         "RAW API");
15597         if (ret)
15598                 return ret;
15599
15600         global_api_test_type = CRYPTODEV_RAW_API_TEST;
15601         ret = run_cryptodev_testsuite(pmd_name);
15602         global_api_test_type = CRYPTODEV_API_TEST;
15603
15604         return ret;
15605 }
15606
15607 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest,
15608                 test_cryptodev_dpaa2_sec_raw_api);
15609 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest,
15610                 test_cryptodev_dpaa_sec_raw_api);
15611 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
15612                 test_cryptodev_qat_raw_api);
15613 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
15614 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
15615 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
15616         test_cryptodev_cpu_aesni_mb);
15617 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
15618 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
15619 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
15620         test_cryptodev_cpu_aesni_gcm);
15621 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
15622 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
15623 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
15624 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
15625 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
15626 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
15627 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
15628 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
15629 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
15630 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
15631 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
15632 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
15633 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
15634 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
15635 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
15636 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
15637 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
15638 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);