c7975ed01c4c2a8fd9254f6d630357771497db1b
[dpdk.git] / app / test / test_cryptodev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation
3  */
4
5 #include <time.h>
6
7 #include <rte_common.h>
8 #include <rte_hexdump.h>
9 #include <rte_mbuf.h>
10 #include <rte_malloc.h>
11 #include <rte_memcpy.h>
12 #include <rte_pause.h>
13 #include <rte_bus_vdev.h>
14 #include <rte_ether.h>
15
16 #include <rte_crypto.h>
17 #include <rte_cryptodev.h>
18 #include <rte_cryptodev_pmd.h>
19 #include <rte_string_fns.h>
20
21 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
22 #include <rte_cryptodev_scheduler.h>
23 #include <rte_cryptodev_scheduler_operations.h>
24 #endif
25
26 #include <rte_lcore.h>
27
28 #include "test.h"
29 #include "test_cryptodev.h"
30
31 #include "test_cryptodev_blockcipher.h"
32 #include "test_cryptodev_aes_test_vectors.h"
33 #include "test_cryptodev_des_test_vectors.h"
34 #include "test_cryptodev_hash_test_vectors.h"
35 #include "test_cryptodev_kasumi_test_vectors.h"
36 #include "test_cryptodev_kasumi_hash_test_vectors.h"
37 #include "test_cryptodev_snow3g_test_vectors.h"
38 #include "test_cryptodev_snow3g_hash_test_vectors.h"
39 #include "test_cryptodev_zuc_test_vectors.h"
40 #include "test_cryptodev_aead_test_vectors.h"
41 #include "test_cryptodev_hmac_test_vectors.h"
42 #include "test_cryptodev_mixed_test_vectors.h"
43 #ifdef RTE_LIBRTE_SECURITY
44 #include "test_cryptodev_security_pdcp_test_vectors.h"
45 #include "test_cryptodev_security_pdcp_test_func.h"
46 #include "test_cryptodev_security_docsis_test_vectors.h"
47 #endif
48
49 #define VDEV_ARGS_SIZE 100
50 #define MAX_NB_SESSIONS 4
51
52 #define MAX_DRV_SERVICE_CTX_SIZE 256
53
54 #define MAX_RAW_DEQUEUE_COUNT   65535
55
56 #define IN_PLACE 0
57 #define OUT_OF_PLACE 1
58
59 static int gbl_driver_id;
60
61 static enum rte_security_session_action_type gbl_action_type =
62         RTE_SECURITY_ACTION_TYPE_NONE;
63
64 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
65
66 struct crypto_testsuite_params {
67         struct rte_mempool *mbuf_pool;
68         struct rte_mempool *large_mbuf_pool;
69         struct rte_mempool *op_mpool;
70         struct rte_mempool *session_mpool;
71         struct rte_mempool *session_priv_mpool;
72         struct rte_cryptodev_config conf;
73         struct rte_cryptodev_qp_conf qp_conf;
74
75         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
76         uint8_t valid_dev_count;
77 };
78
79 struct crypto_unittest_params {
80         struct rte_crypto_sym_xform cipher_xform;
81         struct rte_crypto_sym_xform auth_xform;
82         struct rte_crypto_sym_xform aead_xform;
83 #ifdef RTE_LIBRTE_SECURITY
84         struct rte_security_docsis_xform docsis_xform;
85 #endif
86
87         union {
88                 struct rte_cryptodev_sym_session *sess;
89 #ifdef RTE_LIBRTE_SECURITY
90                 struct rte_security_session *sec_session;
91 #endif
92         };
93 #ifdef RTE_LIBRTE_SECURITY
94         enum rte_security_session_action_type type;
95 #endif
96         struct rte_crypto_op *op;
97
98         struct rte_mbuf *obuf, *ibuf;
99
100         uint8_t *digest;
101 };
102
103 #define ALIGN_POW2_ROUNDUP(num, align) \
104         (((num) + (align) - 1) & ~((align) - 1))
105
106 /*
107  * Forward declarations.
108  */
109 static int
110 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
111                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
112                 uint8_t *hmac_key);
113
114 static int
115 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
116                 struct crypto_unittest_params *ut_params,
117                 struct crypto_testsuite_params *ts_param,
118                 const uint8_t *cipher,
119                 const uint8_t *digest,
120                 const uint8_t *iv);
121
122 static struct rte_mbuf *
123 setup_test_string(struct rte_mempool *mpool,
124                 const char *string, size_t len, uint8_t blocksize)
125 {
126         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
127         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
128
129         memset(m->buf_addr, 0, m->buf_len);
130         if (m) {
131                 char *dst = rte_pktmbuf_append(m, t_len);
132
133                 if (!dst) {
134                         rte_pktmbuf_free(m);
135                         return NULL;
136                 }
137                 if (string != NULL)
138                         rte_memcpy(dst, string, t_len);
139                 else
140                         memset(dst, 0, t_len);
141         }
142
143         return m;
144 }
145
146 /* Get number of bytes in X bits (rounding up) */
147 static uint32_t
148 ceil_byte_length(uint32_t num_bits)
149 {
150         if (num_bits % 8)
151                 return ((num_bits >> 3) + 1);
152         else
153                 return (num_bits >> 3);
154 }
155
156 static uint32_t
157 get_raw_dp_dequeue_count(void *user_data __rte_unused)
158 {
159         return 1;
160 }
161
162 static void
163 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused,
164                 uint8_t is_op_success)
165 {
166         struct rte_crypto_op *op = user_data;
167         op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
168                         RTE_CRYPTO_OP_STATUS_ERROR;
169 }
170
171 void
172 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
173                 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
174                 uint8_t len_in_bits, uint8_t cipher_iv_len)
175 {
176         struct rte_crypto_sym_op *sop = op->sym;
177         struct rte_crypto_op *ret_op = NULL;
178         struct rte_crypto_vec data_vec[UINT8_MAX];
179         struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
180         union rte_crypto_sym_ofs ofs;
181         struct rte_crypto_sym_vec vec;
182         struct rte_crypto_sgl sgl;
183         uint32_t max_len;
184         union rte_cryptodev_session_ctx sess;
185         uint32_t count = 0;
186         struct rte_crypto_raw_dp_ctx *ctx;
187         uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
188                         auth_len = 0;
189         int32_t n;
190         uint32_t n_success;
191         int ctx_service_size;
192         int32_t status = 0;
193         int enqueue_status, dequeue_status;
194
195         ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
196         if (ctx_service_size < 0) {
197                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
198                 return;
199         }
200
201         ctx = malloc(ctx_service_size);
202         if (!ctx) {
203                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
204                 return;
205         }
206
207         /* Both are enums, setting crypto_sess will suit any session type */
208         sess.crypto_sess = op->sym->session;
209
210         if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
211                         op->sess_type, sess, 0) < 0) {
212                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
213                 goto exit;
214         }
215
216         cipher_iv.iova = 0;
217         cipher_iv.va = NULL;
218         aad_auth_iv.iova = 0;
219         aad_auth_iv.va = NULL;
220         digest.iova = 0;
221         digest.va = NULL;
222         sgl.vec = data_vec;
223         vec.num = 1;
224         vec.sgl = &sgl;
225         vec.iv = &cipher_iv;
226         vec.digest = &digest;
227         vec.aad = &aad_auth_iv;
228         vec.status = &status;
229
230         ofs.raw = 0;
231
232         if (is_cipher && is_auth) {
233                 cipher_offset = sop->cipher.data.offset;
234                 cipher_len = sop->cipher.data.length;
235                 auth_offset = sop->auth.data.offset;
236                 auth_len = sop->auth.data.length;
237                 max_len = RTE_MAX(cipher_offset + cipher_len,
238                                 auth_offset + auth_len);
239                 if (len_in_bits) {
240                         max_len = max_len >> 3;
241                         cipher_offset = cipher_offset >> 3;
242                         auth_offset = auth_offset >> 3;
243                         cipher_len = cipher_len >> 3;
244                         auth_len = auth_len >> 3;
245                 }
246                 ofs.ofs.cipher.head = cipher_offset;
247                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
248                 ofs.ofs.auth.head = auth_offset;
249                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
250                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
251                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
252                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
253                                 op, void *, IV_OFFSET + cipher_iv_len);
254                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
255                                 cipher_iv_len);
256                 digest.va = (void *)sop->auth.digest.data;
257                 digest.iova = sop->auth.digest.phys_addr;
258
259         } else if (is_cipher) {
260                 cipher_offset = sop->cipher.data.offset;
261                 cipher_len = sop->cipher.data.length;
262                 max_len = cipher_len + cipher_offset;
263                 if (len_in_bits) {
264                         max_len = max_len >> 3;
265                         cipher_offset = cipher_offset >> 3;
266                         cipher_len = cipher_len >> 3;
267                 }
268                 ofs.ofs.cipher.head = cipher_offset;
269                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
270                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
271                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
272
273         } else if (is_auth) {
274                 auth_offset = sop->auth.data.offset;
275                 auth_len = sop->auth.data.length;
276                 max_len = auth_len + auth_offset;
277                 if (len_in_bits) {
278                         max_len = max_len >> 3;
279                         auth_offset = auth_offset >> 3;
280                         auth_len = auth_len >> 3;
281                 }
282                 ofs.ofs.auth.head = auth_offset;
283                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
284                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
285                                 op, void *, IV_OFFSET + cipher_iv_len);
286                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
287                                 cipher_iv_len);
288                 digest.va = (void *)sop->auth.digest.data;
289                 digest.iova = sop->auth.digest.phys_addr;
290
291         } else { /* aead */
292                 cipher_offset = sop->aead.data.offset;
293                 cipher_len = sop->aead.data.length;
294                 max_len = cipher_len + cipher_offset;
295                 if (len_in_bits) {
296                         max_len = max_len >> 3;
297                         cipher_offset = cipher_offset >> 3;
298                         cipher_len = cipher_len >> 3;
299                 }
300                 ofs.ofs.cipher.head = cipher_offset;
301                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
302                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
303                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
304                 aad_auth_iv.va = (void *)sop->aead.aad.data;
305                 aad_auth_iv.iova = sop->aead.aad.phys_addr;
306                 digest.va = (void *)sop->aead.digest.data;
307                 digest.iova = sop->aead.digest.phys_addr;
308         }
309
310         n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
311                         data_vec, RTE_DIM(data_vec));
312         if (n < 0 || n > sop->m_src->nb_segs) {
313                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
314                 goto exit;
315         }
316
317         sgl.num = n;
318
319         if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
320                         &enqueue_status) < 1) {
321                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
322                 goto exit;
323         }
324
325         if (enqueue_status == 0) {
326                 status = rte_cryptodev_raw_enqueue_done(ctx, 1);
327                 if (status < 0) {
328                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
329                         goto exit;
330                 }
331         } else if (enqueue_status < 0) {
332                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
333                 goto exit;
334         }
335
336         n = n_success = 0;
337         while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
338                 n = rte_cryptodev_raw_dequeue_burst(ctx,
339                         get_raw_dp_dequeue_count, post_process_raw_dp_op,
340                                 (void **)&ret_op, 0, &n_success,
341                                 &dequeue_status);
342                 if (dequeue_status < 0) {
343                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
344                         goto exit;
345                 }
346                 if (n == 0)
347                         rte_pause();
348         }
349
350         if (n == 1 && dequeue_status == 0) {
351                 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
352                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
353                         goto exit;
354                 }
355         }
356
357         op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
358                         n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
359                                         RTE_CRYPTO_OP_STATUS_SUCCESS;
360
361 exit:
362         free(ctx);
363 }
364
365 static void
366 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
367 {
368         int32_t n, st;
369         struct rte_crypto_sym_op *sop;
370         union rte_crypto_sym_ofs ofs;
371         struct rte_crypto_sgl sgl;
372         struct rte_crypto_sym_vec symvec;
373         struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
374         struct rte_crypto_vec vec[UINT8_MAX];
375
376         sop = op->sym;
377
378         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
379                 sop->aead.data.length, vec, RTE_DIM(vec));
380
381         if (n < 0 || n != sop->m_src->nb_segs) {
382                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
383                 return;
384         }
385
386         sgl.vec = vec;
387         sgl.num = n;
388         symvec.sgl = &sgl;
389         symvec.iv = &iv_ptr;
390         symvec.digest = &digest_ptr;
391         symvec.aad = &aad_ptr;
392         symvec.status = &st;
393         symvec.num = 1;
394
395         /* for CPU crypto the IOVA address is not required */
396         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
397         digest_ptr.va = (void *)sop->aead.digest.data;
398         aad_ptr.va = (void *)sop->aead.aad.data;
399
400         ofs.raw = 0;
401
402         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
403                 &symvec);
404
405         if (n != 1)
406                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
407         else
408                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
409 }
410
411 static void
412 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
413 {
414         int32_t n, st;
415         struct rte_crypto_sym_op *sop;
416         union rte_crypto_sym_ofs ofs;
417         struct rte_crypto_sgl sgl;
418         struct rte_crypto_sym_vec symvec;
419         struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
420         struct rte_crypto_vec vec[UINT8_MAX];
421
422         sop = op->sym;
423
424         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
425                 sop->auth.data.length, vec, RTE_DIM(vec));
426
427         if (n < 0 || n != sop->m_src->nb_segs) {
428                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
429                 return;
430         }
431
432         sgl.vec = vec;
433         sgl.num = n;
434         symvec.sgl = &sgl;
435         symvec.iv = &iv_ptr;
436         symvec.digest = &digest_ptr;
437         symvec.status = &st;
438         symvec.num = 1;
439
440         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
441         digest_ptr.va = (void *)sop->auth.digest.data;
442
443         ofs.raw = 0;
444         ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
445         ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
446                 (sop->cipher.data.offset + sop->cipher.data.length);
447
448         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
449                 &symvec);
450
451         if (n != 1)
452                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
453         else
454                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
455 }
456
457 static struct rte_crypto_op *
458 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
459 {
460
461         RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
462
463         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
464                 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
465                 return NULL;
466         }
467
468         op = NULL;
469
470         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
471                 rte_pause();
472
473         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
474                 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
475                 return NULL;
476         }
477
478         return op;
479 }
480
481 static struct crypto_testsuite_params testsuite_params = { NULL };
482 static struct crypto_unittest_params unittest_params;
483
484 static int
485 testsuite_setup(void)
486 {
487         struct crypto_testsuite_params *ts_params = &testsuite_params;
488         struct rte_cryptodev_info info;
489         uint32_t i = 0, nb_devs, dev_id;
490         int ret;
491         uint16_t qp_id;
492
493         memset(ts_params, 0, sizeof(*ts_params));
494
495         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
496         if (ts_params->mbuf_pool == NULL) {
497                 /* Not already created so create */
498                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
499                                 "CRYPTO_MBUFPOOL",
500                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
501                                 rte_socket_id());
502                 if (ts_params->mbuf_pool == NULL) {
503                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
504                         return TEST_FAILED;
505                 }
506         }
507
508         ts_params->large_mbuf_pool = rte_mempool_lookup(
509                         "CRYPTO_LARGE_MBUFPOOL");
510         if (ts_params->large_mbuf_pool == NULL) {
511                 /* Not already created so create */
512                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
513                                 "CRYPTO_LARGE_MBUFPOOL",
514                                 1, 0, 0, UINT16_MAX,
515                                 rte_socket_id());
516                 if (ts_params->large_mbuf_pool == NULL) {
517                         RTE_LOG(ERR, USER1,
518                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
519                         return TEST_FAILED;
520                 }
521         }
522
523         ts_params->op_mpool = rte_crypto_op_pool_create(
524                         "MBUF_CRYPTO_SYM_OP_POOL",
525                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
526                         NUM_MBUFS, MBUF_CACHE_SIZE,
527                         DEFAULT_NUM_XFORMS *
528                         sizeof(struct rte_crypto_sym_xform) +
529                         MAXIMUM_IV_LENGTH,
530                         rte_socket_id());
531         if (ts_params->op_mpool == NULL) {
532                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
533                 return TEST_FAILED;
534         }
535
536         /* Create an AESNI MB device if required */
537         if (gbl_driver_id == rte_cryptodev_driver_id_get(
538                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) {
539                 nb_devs = rte_cryptodev_device_count_by_driver(
540                                 rte_cryptodev_driver_id_get(
541                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
542                 if (nb_devs < 1) {
543                         ret = rte_vdev_init(
544                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
545
546                         TEST_ASSERT(ret == 0,
547                                 "Failed to create instance of"
548                                 " pmd : %s",
549                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
550                 }
551         }
552
553         /* Create an AESNI GCM device if required */
554         if (gbl_driver_id == rte_cryptodev_driver_id_get(
555                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))) {
556                 nb_devs = rte_cryptodev_device_count_by_driver(
557                                 rte_cryptodev_driver_id_get(
558                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)));
559                 if (nb_devs < 1) {
560                         TEST_ASSERT_SUCCESS(rte_vdev_init(
561                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
562                                 "Failed to create instance of"
563                                 " pmd : %s",
564                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
565                 }
566         }
567
568         /* Create a SNOW 3G device if required */
569         if (gbl_driver_id == rte_cryptodev_driver_id_get(
570                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))) {
571                 nb_devs = rte_cryptodev_device_count_by_driver(
572                                 rte_cryptodev_driver_id_get(
573                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)));
574                 if (nb_devs < 1) {
575                         TEST_ASSERT_SUCCESS(rte_vdev_init(
576                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
577                                 "Failed to create instance of"
578                                 " pmd : %s",
579                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
580                 }
581         }
582
583         /* Create a KASUMI device if required */
584         if (gbl_driver_id == rte_cryptodev_driver_id_get(
585                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))) {
586                 nb_devs = rte_cryptodev_device_count_by_driver(
587                                 rte_cryptodev_driver_id_get(
588                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)));
589                 if (nb_devs < 1) {
590                         TEST_ASSERT_SUCCESS(rte_vdev_init(
591                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
592                                 "Failed to create instance of"
593                                 " pmd : %s",
594                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
595                 }
596         }
597
598         /* Create a ZUC device if required */
599         if (gbl_driver_id == rte_cryptodev_driver_id_get(
600                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) {
601                 nb_devs = rte_cryptodev_device_count_by_driver(
602                                 rte_cryptodev_driver_id_get(
603                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)));
604                 if (nb_devs < 1) {
605                         TEST_ASSERT_SUCCESS(rte_vdev_init(
606                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL),
607                                 "Failed to create instance of"
608                                 " pmd : %s",
609                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
610                 }
611         }
612
613         /* Create a NULL device if required */
614         if (gbl_driver_id == rte_cryptodev_driver_id_get(
615                         RTE_STR(CRYPTODEV_NAME_NULL_PMD))) {
616                 nb_devs = rte_cryptodev_device_count_by_driver(
617                                 rte_cryptodev_driver_id_get(
618                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD)));
619                 if (nb_devs < 1) {
620                         ret = rte_vdev_init(
621                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
622
623                         TEST_ASSERT(ret == 0,
624                                 "Failed to create instance of"
625                                 " pmd : %s",
626                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD));
627                 }
628         }
629
630         /* Create an OPENSSL device if required */
631         if (gbl_driver_id == rte_cryptodev_driver_id_get(
632                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
633                 nb_devs = rte_cryptodev_device_count_by_driver(
634                                 rte_cryptodev_driver_id_get(
635                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
636                 if (nb_devs < 1) {
637                         ret = rte_vdev_init(
638                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
639                                 NULL);
640
641                         TEST_ASSERT(ret == 0, "Failed to create "
642                                 "instance of pmd : %s",
643                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
644                 }
645         }
646
647         /* Create a ARMv8 device if required */
648         if (gbl_driver_id == rte_cryptodev_driver_id_get(
649                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))) {
650                 nb_devs = rte_cryptodev_device_count_by_driver(
651                                 rte_cryptodev_driver_id_get(
652                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)));
653                 if (nb_devs < 1) {
654                         ret = rte_vdev_init(
655                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD),
656                                 NULL);
657
658                         TEST_ASSERT(ret == 0, "Failed to create "
659                                 "instance of pmd : %s",
660                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
661                 }
662         }
663
664         /* Create a MVSAM device if required */
665         if (gbl_driver_id == rte_cryptodev_driver_id_get(
666                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))) {
667                 nb_devs = rte_cryptodev_device_count_by_driver(
668                                 rte_cryptodev_driver_id_get(
669                                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)));
670                 if (nb_devs < 1) {
671                         ret = rte_vdev_init(
672                                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD),
673                                 NULL);
674
675                         TEST_ASSERT(ret == 0, "Failed to create "
676                                 "instance of pmd : %s",
677                                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
678                 }
679         }
680
681         /* Create an CCP device if required */
682         if (gbl_driver_id == rte_cryptodev_driver_id_get(
683                         RTE_STR(CRYPTODEV_NAME_CCP_PMD))) {
684                 nb_devs = rte_cryptodev_device_count_by_driver(
685                                 rte_cryptodev_driver_id_get(
686                                 RTE_STR(CRYPTODEV_NAME_CCP_PMD)));
687                 if (nb_devs < 1) {
688                         ret = rte_vdev_init(
689                                 RTE_STR(CRYPTODEV_NAME_CCP_PMD),
690                                 NULL);
691
692                         TEST_ASSERT(ret == 0, "Failed to create "
693                                 "instance of pmd : %s",
694                                 RTE_STR(CRYPTODEV_NAME_CCP_PMD));
695                 }
696         }
697
698 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
699         char vdev_args[VDEV_ARGS_SIZE] = {""};
700         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
701                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
702         uint16_t worker_core_count = 0;
703         uint16_t socket_id = 0;
704
705         if (gbl_driver_id == rte_cryptodev_driver_id_get(
706                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
707
708                 /* Identify the Worker Cores
709                  * Use 2 worker cores for the device args
710                  */
711                 RTE_LCORE_FOREACH_SLAVE(i) {
712                         if (worker_core_count > 1)
713                                 break;
714                         snprintf(vdev_args, sizeof(vdev_args),
715                                         "%s%d", temp_str, i);
716                         strcpy(temp_str, vdev_args);
717                         strlcat(temp_str, ";", sizeof(temp_str));
718                         worker_core_count++;
719                         socket_id = rte_lcore_to_socket_id(i);
720                 }
721                 if (worker_core_count != 2) {
722                         RTE_LOG(ERR, USER1,
723                                 "Cryptodev scheduler test require at least "
724                                 "two worker cores to run. "
725                                 "Please use the correct coremask.\n");
726                         return TEST_FAILED;
727                 }
728                 strcpy(temp_str, vdev_args);
729                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
730                                 temp_str, socket_id);
731                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
732                 nb_devs = rte_cryptodev_device_count_by_driver(
733                                 rte_cryptodev_driver_id_get(
734                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
735                 if (nb_devs < 1) {
736                         ret = rte_vdev_init(
737                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
738                                         vdev_args);
739                         TEST_ASSERT(ret == 0,
740                                 "Failed to create instance %u of"
741                                 " pmd : %s",
742                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
743                 }
744         }
745 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
746
747         nb_devs = rte_cryptodev_count();
748         if (nb_devs < 1) {
749                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
750                 return TEST_SKIPPED;
751         }
752
753         /* Create list of valid crypto devs */
754         for (i = 0; i < nb_devs; i++) {
755                 rte_cryptodev_info_get(i, &info);
756                 if (info.driver_id == gbl_driver_id)
757                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
758         }
759
760         if (ts_params->valid_dev_count < 1)
761                 return TEST_FAILED;
762
763         /* Set up all the qps on the first of the valid devices found */
764
765         dev_id = ts_params->valid_devs[0];
766
767         rte_cryptodev_info_get(dev_id, &info);
768
769         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
770         ts_params->conf.socket_id = SOCKET_ID_ANY;
771         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
772
773         unsigned int session_size =
774                 rte_cryptodev_sym_get_private_session_size(dev_id);
775
776         /*
777          * Create mempool with maximum number of sessions * 2,
778          * to include the session headers
779          */
780         if (info.sym.max_nb_sessions != 0 &&
781                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
782                 RTE_LOG(ERR, USER1, "Device does not support "
783                                 "at least %u sessions\n",
784                                 MAX_NB_SESSIONS);
785                 return TEST_FAILED;
786         }
787
788         ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
789                         "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
790                         SOCKET_ID_ANY);
791         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
792                         "session mempool allocation failed");
793
794         ts_params->session_priv_mpool = rte_mempool_create(
795                         "test_sess_mp_priv",
796                         MAX_NB_SESSIONS,
797                         session_size,
798                         0, 0, NULL, NULL, NULL,
799                         NULL, SOCKET_ID_ANY,
800                         0);
801         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
802                         "session mempool allocation failed");
803
804
805
806         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
807                         &ts_params->conf),
808                         "Failed to configure cryptodev %u with %u qps",
809                         dev_id, ts_params->conf.nb_queue_pairs);
810
811         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
812         ts_params->qp_conf.mp_session = ts_params->session_mpool;
813         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
814
815         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
816                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
817                         dev_id, qp_id, &ts_params->qp_conf,
818                         rte_cryptodev_socket_id(dev_id)),
819                         "Failed to setup queue pair %u on cryptodev %u",
820                         qp_id, dev_id);
821         }
822
823         return TEST_SUCCESS;
824 }
825
826 static void
827 testsuite_teardown(void)
828 {
829         struct crypto_testsuite_params *ts_params = &testsuite_params;
830
831         if (ts_params->mbuf_pool != NULL) {
832                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
833                 rte_mempool_avail_count(ts_params->mbuf_pool));
834         }
835
836         if (ts_params->op_mpool != NULL) {
837                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
838                 rte_mempool_avail_count(ts_params->op_mpool));
839         }
840
841         /* Free session mempools */
842         if (ts_params->session_priv_mpool != NULL) {
843                 rte_mempool_free(ts_params->session_priv_mpool);
844                 ts_params->session_priv_mpool = NULL;
845         }
846
847         if (ts_params->session_mpool != NULL) {
848                 rte_mempool_free(ts_params->session_mpool);
849                 ts_params->session_mpool = NULL;
850         }
851 }
852
853 static int
854 dev_configure_and_start(uint64_t ff_disable)
855 {
856         struct crypto_testsuite_params *ts_params = &testsuite_params;
857         struct crypto_unittest_params *ut_params = &unittest_params;
858
859         uint16_t qp_id;
860
861         /* Clear unit test parameters before running test */
862         memset(ut_params, 0, sizeof(*ut_params));
863
864         /* Reconfigure device to default parameters */
865         ts_params->conf.socket_id = SOCKET_ID_ANY;
866         ts_params->conf.ff_disable = ff_disable;
867         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
868         ts_params->qp_conf.mp_session = ts_params->session_mpool;
869         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
870
871         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
872                         &ts_params->conf),
873                         "Failed to configure cryptodev %u",
874                         ts_params->valid_devs[0]);
875
876         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
877                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
878                         ts_params->valid_devs[0], qp_id,
879                         &ts_params->qp_conf,
880                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
881                         "Failed to setup queue pair %u on cryptodev %u",
882                         qp_id, ts_params->valid_devs[0]);
883         }
884
885
886         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
887
888         /* Start the device */
889         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
890                         "Failed to start cryptodev %u",
891                         ts_params->valid_devs[0]);
892
893         return TEST_SUCCESS;
894 }
895
896 static int
897 ut_setup(void)
898 {
899         /* Configure and start the device with security feature disabled */
900         return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
901 }
902
903 static int
904 ut_setup_security(void)
905 {
906         /* Configure and start the device with no features disabled */
907         return dev_configure_and_start(0);
908 }
909
910 static void
911 ut_teardown(void)
912 {
913         struct crypto_testsuite_params *ts_params = &testsuite_params;
914         struct crypto_unittest_params *ut_params = &unittest_params;
915         struct rte_cryptodev_stats stats;
916
917         /* free crypto session structure */
918 #ifdef RTE_LIBRTE_SECURITY
919         if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
920                 if (ut_params->sec_session) {
921                         rte_security_session_destroy(rte_cryptodev_get_sec_ctx
922                                                 (ts_params->valid_devs[0]),
923                                                 ut_params->sec_session);
924                         ut_params->sec_session = NULL;
925                 }
926         } else
927 #endif
928         {
929                 if (ut_params->sess) {
930                         rte_cryptodev_sym_session_clear(
931                                         ts_params->valid_devs[0],
932                                         ut_params->sess);
933                         rte_cryptodev_sym_session_free(ut_params->sess);
934                         ut_params->sess = NULL;
935                 }
936         }
937
938         /* free crypto operation structure */
939         if (ut_params->op)
940                 rte_crypto_op_free(ut_params->op);
941
942         /*
943          * free mbuf - both obuf and ibuf are usually the same,
944          * so check if they point at the same address is necessary,
945          * to avoid freeing the mbuf twice.
946          */
947         if (ut_params->obuf) {
948                 rte_pktmbuf_free(ut_params->obuf);
949                 if (ut_params->ibuf == ut_params->obuf)
950                         ut_params->ibuf = 0;
951                 ut_params->obuf = 0;
952         }
953         if (ut_params->ibuf) {
954                 rte_pktmbuf_free(ut_params->ibuf);
955                 ut_params->ibuf = 0;
956         }
957
958         if (ts_params->mbuf_pool != NULL)
959                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
960                         rte_mempool_avail_count(ts_params->mbuf_pool));
961
962         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
963
964         /* Stop the device */
965         rte_cryptodev_stop(ts_params->valid_devs[0]);
966 }
967
968 static int
969 test_device_configure_invalid_dev_id(void)
970 {
971         struct crypto_testsuite_params *ts_params = &testsuite_params;
972         uint16_t dev_id, num_devs = 0;
973
974         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
975                         "Need at least %d devices for test", 1);
976
977         /* valid dev_id values */
978         dev_id = ts_params->valid_devs[0];
979
980         /* Stop the device in case it's started so it can be configured */
981         rte_cryptodev_stop(dev_id);
982
983         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
984                         "Failed test for rte_cryptodev_configure: "
985                         "invalid dev_num %u", dev_id);
986
987         /* invalid dev_id values */
988         dev_id = num_devs;
989
990         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
991                         "Failed test for rte_cryptodev_configure: "
992                         "invalid dev_num %u", dev_id);
993
994         dev_id = 0xff;
995
996         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
997                         "Failed test for rte_cryptodev_configure:"
998                         "invalid dev_num %u", dev_id);
999
1000         return TEST_SUCCESS;
1001 }
1002
1003 static int
1004 test_device_configure_invalid_queue_pair_ids(void)
1005 {
1006         struct crypto_testsuite_params *ts_params = &testsuite_params;
1007         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1008
1009         /* Stop the device in case it's started so it can be configured */
1010         rte_cryptodev_stop(ts_params->valid_devs[0]);
1011
1012         /* valid - max value queue pairs */
1013         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1014
1015         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1016                         &ts_params->conf),
1017                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1018                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1019
1020         /* valid - one queue pairs */
1021         ts_params->conf.nb_queue_pairs = 1;
1022
1023         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1024                         &ts_params->conf),
1025                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1026                         ts_params->valid_devs[0],
1027                         ts_params->conf.nb_queue_pairs);
1028
1029
1030         /* invalid - zero queue pairs */
1031         ts_params->conf.nb_queue_pairs = 0;
1032
1033         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1034                         &ts_params->conf),
1035                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1036                         " invalid qps: %u",
1037                         ts_params->valid_devs[0],
1038                         ts_params->conf.nb_queue_pairs);
1039
1040
1041         /* invalid - max value supported by field queue pairs */
1042         ts_params->conf.nb_queue_pairs = UINT16_MAX;
1043
1044         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1045                         &ts_params->conf),
1046                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1047                         " invalid qps: %u",
1048                         ts_params->valid_devs[0],
1049                         ts_params->conf.nb_queue_pairs);
1050
1051
1052         /* invalid - max value + 1 queue pairs */
1053         ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1054
1055         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1056                         &ts_params->conf),
1057                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1058                         " invalid qps: %u",
1059                         ts_params->valid_devs[0],
1060                         ts_params->conf.nb_queue_pairs);
1061
1062         /* revert to original testsuite value */
1063         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1064
1065         return TEST_SUCCESS;
1066 }
1067
1068 static int
1069 test_queue_pair_descriptor_setup(void)
1070 {
1071         struct crypto_testsuite_params *ts_params = &testsuite_params;
1072         struct rte_cryptodev_qp_conf qp_conf = {
1073                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
1074         };
1075         uint16_t qp_id;
1076
1077         /* Stop the device in case it's started so it can be configured */
1078         rte_cryptodev_stop(ts_params->valid_devs[0]);
1079
1080         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1081                         &ts_params->conf),
1082                         "Failed to configure cryptodev %u",
1083                         ts_params->valid_devs[0]);
1084
1085         /*
1086          * Test various ring sizes on this device. memzones can't be
1087          * freed so are re-used if ring is released and re-created.
1088          */
1089         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1090         qp_conf.mp_session = ts_params->session_mpool;
1091         qp_conf.mp_session_private = ts_params->session_priv_mpool;
1092
1093         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1094                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1095                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1096                                 rte_cryptodev_socket_id(
1097                                                 ts_params->valid_devs[0])),
1098                                 "Failed test for "
1099                                 "rte_cryptodev_queue_pair_setup: num_inflights "
1100                                 "%u on qp %u on cryptodev %u",
1101                                 qp_conf.nb_descriptors, qp_id,
1102                                 ts_params->valid_devs[0]);
1103         }
1104
1105         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1106
1107         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1108                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1109                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1110                                 rte_cryptodev_socket_id(
1111                                                 ts_params->valid_devs[0])),
1112                                 "Failed test for"
1113                                 " rte_cryptodev_queue_pair_setup: num_inflights"
1114                                 " %u on qp %u on cryptodev %u",
1115                                 qp_conf.nb_descriptors, qp_id,
1116                                 ts_params->valid_devs[0]);
1117         }
1118
1119         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1120
1121         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1122                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1123                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1124                                 rte_cryptodev_socket_id(
1125                                                 ts_params->valid_devs[0])),
1126                                 "Failed test for "
1127                                 "rte_cryptodev_queue_pair_setup: num_inflights"
1128                                 " %u on qp %u on cryptodev %u",
1129                                 qp_conf.nb_descriptors, qp_id,
1130                                 ts_params->valid_devs[0]);
1131         }
1132
1133         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1134
1135         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1136                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1137                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1138                                 rte_cryptodev_socket_id(
1139                                                 ts_params->valid_devs[0])),
1140                                 "Failed test for"
1141                                 " rte_cryptodev_queue_pair_setup:"
1142                                 "num_inflights %u on qp %u on cryptodev %u",
1143                                 qp_conf.nb_descriptors, qp_id,
1144                                 ts_params->valid_devs[0]);
1145         }
1146
1147         /* test invalid queue pair id */
1148         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
1149
1150         qp_id = ts_params->conf.nb_queue_pairs;         /*invalid */
1151
1152         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1153                         ts_params->valid_devs[0],
1154                         qp_id, &qp_conf,
1155                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1156                         "Failed test for rte_cryptodev_queue_pair_setup:"
1157                         "invalid qp %u on cryptodev %u",
1158                         qp_id, ts_params->valid_devs[0]);
1159
1160         qp_id = 0xffff; /*invalid*/
1161
1162         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1163                         ts_params->valid_devs[0],
1164                         qp_id, &qp_conf,
1165                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1166                         "Failed test for rte_cryptodev_queue_pair_setup:"
1167                         "invalid qp %u on cryptodev %u",
1168                         qp_id, ts_params->valid_devs[0]);
1169
1170         return TEST_SUCCESS;
1171 }
1172
1173 /* ***** Plaintext data for tests ***** */
1174
1175 const char catch_22_quote_1[] =
1176                 "There was only one catch and that was Catch-22, which "
1177                 "specified that a concern for one's safety in the face of "
1178                 "dangers that were real and immediate was the process of a "
1179                 "rational mind. Orr was crazy and could be grounded. All he "
1180                 "had to do was ask; and as soon as he did, he would no longer "
1181                 "be crazy and would have to fly more missions. Orr would be "
1182                 "crazy to fly more missions and sane if he didn't, but if he "
1183                 "was sane he had to fly them. If he flew them he was crazy "
1184                 "and didn't have to; but if he didn't want to he was sane and "
1185                 "had to. Yossarian was moved very deeply by the absolute "
1186                 "simplicity of this clause of Catch-22 and let out a "
1187                 "respectful whistle. \"That's some catch, that Catch-22\", he "
1188                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
1189
1190 const char catch_22_quote[] =
1191                 "What a lousy earth! He wondered how many people were "
1192                 "destitute that same night even in his own prosperous country, "
1193                 "how many homes were shanties, how many husbands were drunk "
1194                 "and wives socked, and how many children were bullied, abused, "
1195                 "or abandoned. How many families hungered for food they could "
1196                 "not afford to buy? How many hearts were broken? How many "
1197                 "suicides would take place that same night, how many people "
1198                 "would go insane? How many cockroaches and landlords would "
1199                 "triumph? How many winners were losers, successes failures, "
1200                 "and rich men poor men? How many wise guys were stupid? How "
1201                 "many happy endings were unhappy endings? How many honest men "
1202                 "were liars, brave men cowards, loyal men traitors, how many "
1203                 "sainted men were corrupt, how many people in positions of "
1204                 "trust had sold their souls to bodyguards, how many had never "
1205                 "had souls? How many straight-and-narrow paths were crooked "
1206                 "paths? How many best families were worst families and how "
1207                 "many good people were bad people? When you added them all up "
1208                 "and then subtracted, you might be left with only the children, "
1209                 "and perhaps with Albert Einstein and an old violinist or "
1210                 "sculptor somewhere.";
1211
1212 #define QUOTE_480_BYTES         (480)
1213 #define QUOTE_512_BYTES         (512)
1214 #define QUOTE_768_BYTES         (768)
1215 #define QUOTE_1024_BYTES        (1024)
1216
1217
1218
1219 /* ***** SHA1 Hash Tests ***** */
1220
1221 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
1222
1223 static uint8_t hmac_sha1_key[] = {
1224         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1225         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1226         0xDE, 0xF4, 0xDE, 0xAD };
1227
1228 /* ***** SHA224 Hash Tests ***** */
1229
1230 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
1231
1232
1233 /* ***** AES-CBC Cipher Tests ***** */
1234
1235 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
1236 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
1237
1238 static uint8_t aes_cbc_key[] = {
1239         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1240         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1241
1242 static uint8_t aes_cbc_iv[] = {
1243         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1244         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1245
1246
1247 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1248
1249 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1250         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1251         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1252         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1253         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1254         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1255         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1256         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1257         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1258         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1259         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1260         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1261         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1262         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1263         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1264         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1265         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1266         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1267         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1268         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1269         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1270         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1271         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1272         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1273         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1274         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1275         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1276         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1277         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1278         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1279         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1280         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1281         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1282         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1283         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1284         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1285         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1286         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1287         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1288         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1289         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1290         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1291         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1292         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1293         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1294         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1295         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1296         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1297         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1298         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1299         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1300         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1301         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1302         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1303         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1304         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1305         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1306         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1307         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1308         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1309         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1310         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1311         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1312         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1313         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1314 };
1315
1316 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1317         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1318         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1319         0x18, 0x8c, 0x1d, 0x32
1320 };
1321
1322
1323 /* Multisession Vector context Test */
1324 /*Begin Session 0 */
1325 static uint8_t ms_aes_cbc_key0[] = {
1326         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1327         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1328 };
1329
1330 static uint8_t ms_aes_cbc_iv0[] = {
1331         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1332         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1333 };
1334
1335 static const uint8_t ms_aes_cbc_cipher0[] = {
1336                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1337                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1338                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1339                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1340                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1341                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1342                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1343                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1344                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1345                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1346                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1347                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1348                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1349                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1350                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1351                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1352                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1353                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1354                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1355                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1356                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1357                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1358                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1359                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1360                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1361                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1362                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1363                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1364                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1365                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1366                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1367                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1368                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1369                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1370                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1371                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1372                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1373                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1374                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1375                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1376                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1377                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1378                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1379                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1380                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1381                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1382                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1383                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1384                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1385                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1386                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1387                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1388                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1389                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1390                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1391                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1392                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1393                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1394                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1395                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1396                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1397                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1398                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1399                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1400 };
1401
1402
1403 static  uint8_t ms_hmac_key0[] = {
1404                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1405                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1406                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1407                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1408                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1409                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1410                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1411                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1412 };
1413
1414 static const uint8_t ms_hmac_digest0[] = {
1415                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1416                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1417                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1418                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1419                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1420                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1421                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1422                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1423                 };
1424
1425 /* End Session 0 */
1426 /* Begin session 1 */
1427
1428 static  uint8_t ms_aes_cbc_key1[] = {
1429                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1430                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1431 };
1432
1433 static  uint8_t ms_aes_cbc_iv1[] = {
1434         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1435         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1436 };
1437
1438 static const uint8_t ms_aes_cbc_cipher1[] = {
1439                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1440                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1441                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1442                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1443                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1444                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1445                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1446                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1447                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1448                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1449                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1450                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1451                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1452                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1453                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1454                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1455                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1456                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1457                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1458                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1459                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1460                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1461                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1462                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1463                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1464                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1465                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1466                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1467                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1468                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1469                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1470                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1471                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1472                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1473                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1474                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1475                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1476                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1477                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1478                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1479                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1480                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1481                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1482                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1483                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1484                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1485                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1486                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1487                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1488                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1489                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1490                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1491                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1492                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1493                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1494                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1495                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1496                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1497                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1498                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1499                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1500                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1501                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1502                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1503
1504 };
1505
1506 static uint8_t ms_hmac_key1[] = {
1507                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1508                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1509                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1510                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1511                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1512                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1513                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1514                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1515 };
1516
1517 static const uint8_t ms_hmac_digest1[] = {
1518                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1519                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1520                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1521                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1522                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1523                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1524                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1525                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1526 };
1527 /* End Session 1  */
1528 /* Begin Session 2 */
1529 static  uint8_t ms_aes_cbc_key2[] = {
1530                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1531                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1532 };
1533
1534 static  uint8_t ms_aes_cbc_iv2[] = {
1535                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1536                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1537 };
1538
1539 static const uint8_t ms_aes_cbc_cipher2[] = {
1540                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1541                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1542                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1543                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1544                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1545                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1546                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1547                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1548                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1549                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1550                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1551                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1552                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1553                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1554                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1555                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1556                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1557                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1558                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1559                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1560                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1561                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1562                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1563                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1564                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1565                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1566                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1567                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1568                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1569                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1570                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1571                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1572                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1573                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1574                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1575                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1576                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1577                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1578                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1579                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1580                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1581                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1582                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1583                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1584                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1585                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
1586                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
1587                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
1588                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
1589                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
1590                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
1591                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
1592                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
1593                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
1594                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
1595                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
1596                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
1597                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
1598                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
1599                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
1600                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
1601                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
1602                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
1603                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
1604 };
1605
1606 static  uint8_t ms_hmac_key2[] = {
1607                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1608                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1609                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1610                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1611                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1612                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1613                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1614                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1615 };
1616
1617 static const uint8_t ms_hmac_digest2[] = {
1618                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
1619                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
1620                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
1621                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
1622                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
1623                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
1624                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
1625                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
1626 };
1627
1628 /* End Session 2 */
1629
1630
1631 static int
1632 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
1633 {
1634         struct crypto_testsuite_params *ts_params = &testsuite_params;
1635         struct crypto_unittest_params *ut_params = &unittest_params;
1636
1637         /* Verify the capabilities */
1638         struct rte_cryptodev_sym_capability_idx cap_idx;
1639         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1640         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
1641         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
1642                         &cap_idx) == NULL)
1643                 return -ENOTSUP;
1644         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1645         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
1646         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
1647                         &cap_idx) == NULL)
1648                 return -ENOTSUP;
1649
1650         /* Generate test mbuf data and space for digest */
1651         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1652                         catch_22_quote, QUOTE_512_BYTES, 0);
1653
1654         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1655                         DIGEST_BYTE_LENGTH_SHA1);
1656         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1657
1658         /* Setup Cipher Parameters */
1659         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1660         ut_params->cipher_xform.next = &ut_params->auth_xform;
1661
1662         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1663         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1664         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1665         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1666         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1667         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1668
1669         /* Setup HMAC Parameters */
1670         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1671
1672         ut_params->auth_xform.next = NULL;
1673
1674         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1675         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1676         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1677         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1678         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1679
1680         ut_params->sess = rte_cryptodev_sym_session_create(
1681                         ts_params->session_mpool);
1682
1683         /* Create crypto session*/
1684         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
1685                         ut_params->sess, &ut_params->cipher_xform,
1686                         ts_params->session_priv_mpool);
1687         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1688
1689         /* Generate crypto op data structure */
1690         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1691                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1692         TEST_ASSERT_NOT_NULL(ut_params->op,
1693                         "Failed to allocate symmetric crypto operation struct");
1694
1695         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1696
1697         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1698
1699         /* set crypto operation source mbuf */
1700         sym_op->m_src = ut_params->ibuf;
1701
1702         /* Set crypto operation authentication parameters */
1703         sym_op->auth.digest.data = ut_params->digest;
1704         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
1705                         ut_params->ibuf, QUOTE_512_BYTES);
1706
1707         sym_op->auth.data.offset = 0;
1708         sym_op->auth.data.length = QUOTE_512_BYTES;
1709
1710         /* Copy IV at the end of the crypto operation */
1711         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1712                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
1713
1714         /* Set crypto operation cipher parameters */
1715         sym_op->cipher.data.offset = 0;
1716         sym_op->cipher.data.length = QUOTE_512_BYTES;
1717
1718         /* Process crypto operation */
1719         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
1720                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
1721                         ut_params->op);
1722         else
1723                 TEST_ASSERT_NOT_NULL(
1724                         process_crypto_request(ts_params->valid_devs[0],
1725                                 ut_params->op),
1726                                 "failed to process sym crypto op");
1727
1728         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1729                         "crypto op processing failed");
1730
1731         /* Validate obuf */
1732         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
1733                         uint8_t *);
1734
1735         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1736                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1737                         QUOTE_512_BYTES,
1738                         "ciphertext data not as expected");
1739
1740         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1741
1742         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1743                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1744                         gbl_driver_id == rte_cryptodev_driver_id_get(
1745                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
1746                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1747                                         DIGEST_BYTE_LENGTH_SHA1,
1748                         "Generated digest data not as expected");
1749
1750         return TEST_SUCCESS;
1751 }
1752
1753 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1754
1755 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
1756
1757 static uint8_t hmac_sha512_key[] = {
1758         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1759         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1760         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1761         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1762         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1763         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1764         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1765         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1766
1767 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1768         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1769         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1770         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1771         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1772         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1773         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1774         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1775         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1776
1777
1778
1779 static int
1780 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1781                 struct crypto_unittest_params *ut_params,
1782                 uint8_t *cipher_key,
1783                 uint8_t *hmac_key);
1784
1785 static int
1786 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1787                 struct crypto_unittest_params *ut_params,
1788                 struct crypto_testsuite_params *ts_params,
1789                 const uint8_t *cipher,
1790                 const uint8_t *digest,
1791                 const uint8_t *iv);
1792
1793
1794 static int
1795 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1796                 struct crypto_unittest_params *ut_params,
1797                 uint8_t *cipher_key,
1798                 uint8_t *hmac_key)
1799 {
1800
1801         /* Setup Cipher Parameters */
1802         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1803         ut_params->cipher_xform.next = NULL;
1804
1805         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1806         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1807         ut_params->cipher_xform.cipher.key.data = cipher_key;
1808         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1809         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1810         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1811
1812         /* Setup HMAC Parameters */
1813         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1814         ut_params->auth_xform.next = &ut_params->cipher_xform;
1815
1816         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1817         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1818         ut_params->auth_xform.auth.key.data = hmac_key;
1819         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1820         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1821
1822         return TEST_SUCCESS;
1823 }
1824
1825
1826 static int
1827 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1828                 struct crypto_unittest_params *ut_params,
1829                 struct crypto_testsuite_params *ts_params,
1830                 const uint8_t *cipher,
1831                 const uint8_t *digest,
1832                 const uint8_t *iv)
1833 {
1834         /* Generate test mbuf data and digest */
1835         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1836                         (const char *)
1837                         cipher,
1838                         QUOTE_512_BYTES, 0);
1839
1840         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1841                         DIGEST_BYTE_LENGTH_SHA512);
1842         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1843
1844         rte_memcpy(ut_params->digest,
1845                         digest,
1846                         DIGEST_BYTE_LENGTH_SHA512);
1847
1848         /* Generate Crypto op data structure */
1849         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1850                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1851         TEST_ASSERT_NOT_NULL(ut_params->op,
1852                         "Failed to allocate symmetric crypto operation struct");
1853
1854         rte_crypto_op_attach_sym_session(ut_params->op, sess);
1855
1856         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1857
1858         /* set crypto operation source mbuf */
1859         sym_op->m_src = ut_params->ibuf;
1860
1861         sym_op->auth.digest.data = ut_params->digest;
1862         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
1863                         ut_params->ibuf, QUOTE_512_BYTES);
1864
1865         sym_op->auth.data.offset = 0;
1866         sym_op->auth.data.length = QUOTE_512_BYTES;
1867
1868         /* Copy IV at the end of the crypto operation */
1869         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1870                         iv, CIPHER_IV_LENGTH_AES_CBC);
1871
1872         sym_op->cipher.data.offset = 0;
1873         sym_op->cipher.data.length = QUOTE_512_BYTES;
1874
1875         /* Process crypto operation */
1876         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
1877                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
1878                         ut_params->op);
1879         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
1880                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
1881                                 ut_params->op, 1, 1, 0, 0);
1882         else
1883                 TEST_ASSERT_NOT_NULL(
1884                                 process_crypto_request(ts_params->valid_devs[0],
1885                                         ut_params->op),
1886                                         "failed to process sym crypto op");
1887
1888         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1889                         "crypto op processing failed");
1890
1891         ut_params->obuf = ut_params->op->sym->m_src;
1892
1893         /* Validate obuf */
1894         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1895                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
1896                         catch_22_quote,
1897                         QUOTE_512_BYTES,
1898                         "Plaintext data not as expected");
1899
1900         /* Validate obuf */
1901         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1902                         "Digest verification failed");
1903
1904         return TEST_SUCCESS;
1905 }
1906
1907 static int
1908 test_blockcipher(enum blockcipher_test_type test_type)
1909 {
1910         struct crypto_testsuite_params *ts_params = &testsuite_params;
1911         int status;
1912
1913         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1914                 ts_params->op_mpool,
1915                 ts_params->session_mpool, ts_params->session_priv_mpool,
1916                 ts_params->valid_devs[0],
1917                 test_type);
1918
1919         if (status == -ENOTSUP)
1920                 return status;
1921
1922         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1923
1924         return TEST_SUCCESS;
1925 }
1926
1927 static int
1928 test_AES_cipheronly_all(void)
1929 {
1930         return test_blockcipher(BLKCIPHER_AES_CIPHERONLY_TYPE);
1931 }
1932
1933 static int
1934 test_AES_docsis_all(void)
1935 {
1936         /* Data-path service does not support DOCSIS yet */
1937         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
1938                 return -ENOTSUP;
1939         return test_blockcipher(BLKCIPHER_AES_DOCSIS_TYPE);
1940 }
1941
1942 static int
1943 test_DES_docsis_all(void)
1944 {
1945         /* Data-path service does not support DOCSIS yet */
1946         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
1947                 return -ENOTSUP;
1948         return test_blockcipher(BLKCIPHER_DES_DOCSIS_TYPE);
1949 }
1950
1951 static int
1952 test_DES_cipheronly_all(void)
1953 {
1954         return test_blockcipher(BLKCIPHER_DES_CIPHERONLY_TYPE);
1955 }
1956
1957 static int
1958 test_authonly_all(void)
1959 {
1960         return test_blockcipher(BLKCIPHER_AUTHONLY_TYPE);
1961 }
1962
1963 static int
1964 test_AES_chain_all(void)
1965 {
1966         return test_blockcipher(BLKCIPHER_AES_CHAIN_TYPE);
1967 }
1968
1969 static int
1970 test_3DES_chain_all(void)
1971 {
1972         return test_blockcipher(BLKCIPHER_3DES_CHAIN_TYPE);
1973 }
1974
1975 static int
1976 test_3DES_cipheronly_all(void)
1977 {
1978         return test_blockcipher(BLKCIPHER_3DES_CIPHERONLY_TYPE);
1979 }
1980
1981 /* ***** SNOW 3G Tests ***** */
1982 static int
1983 create_wireless_algo_hash_session(uint8_t dev_id,
1984         const uint8_t *key, const uint8_t key_len,
1985         const uint8_t iv_len, const uint8_t auth_len,
1986         enum rte_crypto_auth_operation op,
1987         enum rte_crypto_auth_algorithm algo)
1988 {
1989         uint8_t hash_key[key_len];
1990         int status;
1991
1992         struct crypto_testsuite_params *ts_params = &testsuite_params;
1993         struct crypto_unittest_params *ut_params = &unittest_params;
1994
1995         memcpy(hash_key, key, key_len);
1996
1997         debug_hexdump(stdout, "key:", key, key_len);
1998
1999         /* Setup Authentication Parameters */
2000         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2001         ut_params->auth_xform.next = NULL;
2002
2003         ut_params->auth_xform.auth.op = op;
2004         ut_params->auth_xform.auth.algo = algo;
2005         ut_params->auth_xform.auth.key.length = key_len;
2006         ut_params->auth_xform.auth.key.data = hash_key;
2007         ut_params->auth_xform.auth.digest_length = auth_len;
2008         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2009         ut_params->auth_xform.auth.iv.length = iv_len;
2010         ut_params->sess = rte_cryptodev_sym_session_create(
2011                         ts_params->session_mpool);
2012
2013         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2014                         &ut_params->auth_xform,
2015                         ts_params->session_priv_mpool);
2016         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2017         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2018         return 0;
2019 }
2020
2021 static int
2022 create_wireless_algo_cipher_session(uint8_t dev_id,
2023                         enum rte_crypto_cipher_operation op,
2024                         enum rte_crypto_cipher_algorithm algo,
2025                         const uint8_t *key, const uint8_t key_len,
2026                         uint8_t iv_len)
2027 {
2028         uint8_t cipher_key[key_len];
2029         int status;
2030         struct crypto_testsuite_params *ts_params = &testsuite_params;
2031         struct crypto_unittest_params *ut_params = &unittest_params;
2032
2033         memcpy(cipher_key, key, key_len);
2034
2035         /* Setup Cipher Parameters */
2036         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2037         ut_params->cipher_xform.next = NULL;
2038
2039         ut_params->cipher_xform.cipher.algo = algo;
2040         ut_params->cipher_xform.cipher.op = op;
2041         ut_params->cipher_xform.cipher.key.data = cipher_key;
2042         ut_params->cipher_xform.cipher.key.length = key_len;
2043         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2044         ut_params->cipher_xform.cipher.iv.length = iv_len;
2045
2046         debug_hexdump(stdout, "key:", key, key_len);
2047
2048         /* Create Crypto session */
2049         ut_params->sess = rte_cryptodev_sym_session_create(
2050                         ts_params->session_mpool);
2051
2052         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2053                         &ut_params->cipher_xform,
2054                         ts_params->session_priv_mpool);
2055         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2056         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2057         return 0;
2058 }
2059
2060 static int
2061 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2062                         unsigned int cipher_len,
2063                         unsigned int cipher_offset)
2064 {
2065         struct crypto_testsuite_params *ts_params = &testsuite_params;
2066         struct crypto_unittest_params *ut_params = &unittest_params;
2067
2068         /* Generate Crypto op data structure */
2069         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2070                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2071         TEST_ASSERT_NOT_NULL(ut_params->op,
2072                                 "Failed to allocate pktmbuf offload");
2073
2074         /* Set crypto operation data parameters */
2075         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2076
2077         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2078
2079         /* set crypto operation source mbuf */
2080         sym_op->m_src = ut_params->ibuf;
2081
2082         /* iv */
2083         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2084                         iv, iv_len);
2085         sym_op->cipher.data.length = cipher_len;
2086         sym_op->cipher.data.offset = cipher_offset;
2087         return 0;
2088 }
2089
2090 static int
2091 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2092                         unsigned int cipher_len,
2093                         unsigned int cipher_offset)
2094 {
2095         struct crypto_testsuite_params *ts_params = &testsuite_params;
2096         struct crypto_unittest_params *ut_params = &unittest_params;
2097
2098         /* Generate Crypto op data structure */
2099         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2100                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2101         TEST_ASSERT_NOT_NULL(ut_params->op,
2102                                 "Failed to allocate pktmbuf offload");
2103
2104         /* Set crypto operation data parameters */
2105         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2106
2107         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2108
2109         /* set crypto operation source mbuf */
2110         sym_op->m_src = ut_params->ibuf;
2111         sym_op->m_dst = ut_params->obuf;
2112
2113         /* iv */
2114         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2115                         iv, iv_len);
2116         sym_op->cipher.data.length = cipher_len;
2117         sym_op->cipher.data.offset = cipher_offset;
2118         return 0;
2119 }
2120
2121 static int
2122 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2123                 enum rte_crypto_cipher_operation cipher_op,
2124                 enum rte_crypto_auth_operation auth_op,
2125                 enum rte_crypto_auth_algorithm auth_algo,
2126                 enum rte_crypto_cipher_algorithm cipher_algo,
2127                 const uint8_t *key, uint8_t key_len,
2128                 uint8_t auth_iv_len, uint8_t auth_len,
2129                 uint8_t cipher_iv_len)
2130
2131 {
2132         uint8_t cipher_auth_key[key_len];
2133         int status;
2134
2135         struct crypto_testsuite_params *ts_params = &testsuite_params;
2136         struct crypto_unittest_params *ut_params = &unittest_params;
2137
2138         memcpy(cipher_auth_key, key, key_len);
2139
2140         /* Setup Authentication Parameters */
2141         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2142         ut_params->auth_xform.next = NULL;
2143
2144         ut_params->auth_xform.auth.op = auth_op;
2145         ut_params->auth_xform.auth.algo = auth_algo;
2146         ut_params->auth_xform.auth.key.length = key_len;
2147         /* Hash key = cipher key */
2148         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2149         ut_params->auth_xform.auth.digest_length = auth_len;
2150         /* Auth IV will be after cipher IV */
2151         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2152         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2153
2154         /* Setup Cipher Parameters */
2155         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2156         ut_params->cipher_xform.next = &ut_params->auth_xform;
2157
2158         ut_params->cipher_xform.cipher.algo = cipher_algo;
2159         ut_params->cipher_xform.cipher.op = cipher_op;
2160         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2161         ut_params->cipher_xform.cipher.key.length = key_len;
2162         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2163         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2164
2165         debug_hexdump(stdout, "key:", key, key_len);
2166
2167         /* Create Crypto session*/
2168         ut_params->sess = rte_cryptodev_sym_session_create(
2169                         ts_params->session_mpool);
2170         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2171
2172         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2173                         &ut_params->cipher_xform,
2174                         ts_params->session_priv_mpool);
2175         if (status == -ENOTSUP)
2176                 return status;
2177
2178         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2179         return 0;
2180 }
2181
2182 static int
2183 create_wireless_cipher_auth_session(uint8_t dev_id,
2184                 enum rte_crypto_cipher_operation cipher_op,
2185                 enum rte_crypto_auth_operation auth_op,
2186                 enum rte_crypto_auth_algorithm auth_algo,
2187                 enum rte_crypto_cipher_algorithm cipher_algo,
2188                 const struct wireless_test_data *tdata)
2189 {
2190         const uint8_t key_len = tdata->key.len;
2191         uint8_t cipher_auth_key[key_len];
2192         int status;
2193
2194         struct crypto_testsuite_params *ts_params = &testsuite_params;
2195         struct crypto_unittest_params *ut_params = &unittest_params;
2196         const uint8_t *key = tdata->key.data;
2197         const uint8_t auth_len = tdata->digest.len;
2198         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2199         uint8_t auth_iv_len = tdata->auth_iv.len;
2200
2201         memcpy(cipher_auth_key, key, key_len);
2202
2203         /* Setup Authentication Parameters */
2204         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2205         ut_params->auth_xform.next = NULL;
2206
2207         ut_params->auth_xform.auth.op = auth_op;
2208         ut_params->auth_xform.auth.algo = auth_algo;
2209         ut_params->auth_xform.auth.key.length = key_len;
2210         /* Hash key = cipher key */
2211         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2212         ut_params->auth_xform.auth.digest_length = auth_len;
2213         /* Auth IV will be after cipher IV */
2214         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2215         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2216
2217         /* Setup Cipher Parameters */
2218         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2219         ut_params->cipher_xform.next = &ut_params->auth_xform;
2220
2221         ut_params->cipher_xform.cipher.algo = cipher_algo;
2222         ut_params->cipher_xform.cipher.op = cipher_op;
2223         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2224         ut_params->cipher_xform.cipher.key.length = key_len;
2225         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2226         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2227
2228
2229         debug_hexdump(stdout, "key:", key, key_len);
2230
2231         /* Create Crypto session*/
2232         ut_params->sess = rte_cryptodev_sym_session_create(
2233                         ts_params->session_mpool);
2234
2235         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2236                         &ut_params->cipher_xform,
2237                         ts_params->session_priv_mpool);
2238         if (status == -ENOTSUP)
2239                 return status;
2240
2241         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2242         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2243         return 0;
2244 }
2245
2246 static int
2247 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2248                 const struct wireless_test_data *tdata)
2249 {
2250         return create_wireless_cipher_auth_session(dev_id,
2251                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2252                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2253                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2254 }
2255
2256 static int
2257 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2258                 enum rte_crypto_cipher_operation cipher_op,
2259                 enum rte_crypto_auth_operation auth_op,
2260                 enum rte_crypto_auth_algorithm auth_algo,
2261                 enum rte_crypto_cipher_algorithm cipher_algo,
2262                 const uint8_t *key, const uint8_t key_len,
2263                 uint8_t auth_iv_len, uint8_t auth_len,
2264                 uint8_t cipher_iv_len)
2265 {
2266         uint8_t auth_cipher_key[key_len];
2267         int status;
2268         struct crypto_testsuite_params *ts_params = &testsuite_params;
2269         struct crypto_unittest_params *ut_params = &unittest_params;
2270
2271         memcpy(auth_cipher_key, key, key_len);
2272
2273         /* Setup Authentication Parameters */
2274         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2275         ut_params->auth_xform.auth.op = auth_op;
2276         ut_params->auth_xform.next = &ut_params->cipher_xform;
2277         ut_params->auth_xform.auth.algo = auth_algo;
2278         ut_params->auth_xform.auth.key.length = key_len;
2279         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2280         ut_params->auth_xform.auth.digest_length = auth_len;
2281         /* Auth IV will be after cipher IV */
2282         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2283         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2284
2285         /* Setup Cipher Parameters */
2286         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2287         ut_params->cipher_xform.next = NULL;
2288         ut_params->cipher_xform.cipher.algo = cipher_algo;
2289         ut_params->cipher_xform.cipher.op = cipher_op;
2290         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2291         ut_params->cipher_xform.cipher.key.length = key_len;
2292         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2293         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2294
2295         debug_hexdump(stdout, "key:", key, key_len);
2296
2297         /* Create Crypto session*/
2298         ut_params->sess = rte_cryptodev_sym_session_create(
2299                         ts_params->session_mpool);
2300         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2301
2302         if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2303                 ut_params->auth_xform.next = NULL;
2304                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2305                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2306                                 &ut_params->cipher_xform,
2307                                 ts_params->session_priv_mpool);
2308
2309         } else
2310                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2311                                 &ut_params->auth_xform,
2312                                 ts_params->session_priv_mpool);
2313
2314         if (status == -ENOTSUP)
2315                 return status;
2316
2317         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2318
2319         return 0;
2320 }
2321
2322 static int
2323 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2324                 unsigned int auth_tag_len,
2325                 const uint8_t *iv, unsigned int iv_len,
2326                 unsigned int data_pad_len,
2327                 enum rte_crypto_auth_operation op,
2328                 unsigned int auth_len, unsigned int auth_offset)
2329 {
2330         struct crypto_testsuite_params *ts_params = &testsuite_params;
2331
2332         struct crypto_unittest_params *ut_params = &unittest_params;
2333
2334         /* Generate Crypto op data structure */
2335         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2336                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2337         TEST_ASSERT_NOT_NULL(ut_params->op,
2338                 "Failed to allocate pktmbuf offload");
2339
2340         /* Set crypto operation data parameters */
2341         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2342
2343         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2344
2345         /* set crypto operation source mbuf */
2346         sym_op->m_src = ut_params->ibuf;
2347
2348         /* iv */
2349         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2350                         iv, iv_len);
2351         /* digest */
2352         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2353                                         ut_params->ibuf, auth_tag_len);
2354
2355         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2356                                 "no room to append auth tag");
2357         ut_params->digest = sym_op->auth.digest.data;
2358         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2359                         ut_params->ibuf, data_pad_len);
2360         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2361                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2362         else
2363                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2364
2365         debug_hexdump(stdout, "digest:",
2366                 sym_op->auth.digest.data,
2367                 auth_tag_len);
2368
2369         sym_op->auth.data.length = auth_len;
2370         sym_op->auth.data.offset = auth_offset;
2371
2372         return 0;
2373 }
2374
2375 static int
2376 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2377         enum rte_crypto_auth_operation op)
2378 {
2379         struct crypto_testsuite_params *ts_params = &testsuite_params;
2380         struct crypto_unittest_params *ut_params = &unittest_params;
2381
2382         const uint8_t *auth_tag = tdata->digest.data;
2383         const unsigned int auth_tag_len = tdata->digest.len;
2384         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2385         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2386
2387         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2388         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2389         const uint8_t *auth_iv = tdata->auth_iv.data;
2390         const uint8_t auth_iv_len = tdata->auth_iv.len;
2391         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2392         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2393
2394         /* Generate Crypto op data structure */
2395         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2396                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2397         TEST_ASSERT_NOT_NULL(ut_params->op,
2398                         "Failed to allocate pktmbuf offload");
2399         /* Set crypto operation data parameters */
2400         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2401
2402         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2403
2404         /* set crypto operation source mbuf */
2405         sym_op->m_src = ut_params->ibuf;
2406
2407         /* digest */
2408         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2409                         ut_params->ibuf, auth_tag_len);
2410
2411         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2412                         "no room to append auth tag");
2413         ut_params->digest = sym_op->auth.digest.data;
2414         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2415                         ut_params->ibuf, data_pad_len);
2416         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2417                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2418         else
2419                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2420
2421         debug_hexdump(stdout, "digest:",
2422                 sym_op->auth.digest.data,
2423                 auth_tag_len);
2424
2425         /* Copy cipher and auth IVs at the end of the crypto operation */
2426         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2427                                                 IV_OFFSET);
2428         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2429         iv_ptr += cipher_iv_len;
2430         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2431
2432         sym_op->cipher.data.length = cipher_len;
2433         sym_op->cipher.data.offset = 0;
2434         sym_op->auth.data.length = auth_len;
2435         sym_op->auth.data.offset = 0;
2436
2437         return 0;
2438 }
2439
2440 static int
2441 create_zuc_cipher_hash_generate_operation(
2442                 const struct wireless_test_data *tdata)
2443 {
2444         return create_wireless_cipher_hash_operation(tdata,
2445                 RTE_CRYPTO_AUTH_OP_GENERATE);
2446 }
2447
2448 static int
2449 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2450                 const unsigned auth_tag_len,
2451                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2452                 unsigned data_pad_len,
2453                 enum rte_crypto_auth_operation op,
2454                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2455                 const unsigned cipher_len, const unsigned cipher_offset,
2456                 const unsigned auth_len, const unsigned auth_offset)
2457 {
2458         struct crypto_testsuite_params *ts_params = &testsuite_params;
2459         struct crypto_unittest_params *ut_params = &unittest_params;
2460
2461         enum rte_crypto_cipher_algorithm cipher_algo =
2462                         ut_params->cipher_xform.cipher.algo;
2463         enum rte_crypto_auth_algorithm auth_algo =
2464                         ut_params->auth_xform.auth.algo;
2465
2466         /* Generate Crypto op data structure */
2467         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2468                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2469         TEST_ASSERT_NOT_NULL(ut_params->op,
2470                         "Failed to allocate pktmbuf offload");
2471         /* Set crypto operation data parameters */
2472         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2473
2474         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2475
2476         /* set crypto operation source mbuf */
2477         sym_op->m_src = ut_params->ibuf;
2478
2479         /* digest */
2480         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2481                         ut_params->ibuf, auth_tag_len);
2482
2483         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2484                         "no room to append auth tag");
2485         ut_params->digest = sym_op->auth.digest.data;
2486
2487         if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2488                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2489                                 ut_params->ibuf, data_pad_len);
2490         } else {
2491                 struct rte_mbuf *m = ut_params->ibuf;
2492                 unsigned int offset = data_pad_len;
2493
2494                 while (offset > m->data_len && m->next != NULL) {
2495                         offset -= m->data_len;
2496                         m = m->next;
2497                 }
2498                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2499                         m, offset);
2500         }
2501
2502         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2503                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2504         else
2505                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2506
2507         debug_hexdump(stdout, "digest:",
2508                 sym_op->auth.digest.data,
2509                 auth_tag_len);
2510
2511         /* Copy cipher and auth IVs at the end of the crypto operation */
2512         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2513                                                 IV_OFFSET);
2514         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2515         iv_ptr += cipher_iv_len;
2516         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2517
2518         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2519                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2520                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2521                 sym_op->cipher.data.length = cipher_len;
2522                 sym_op->cipher.data.offset = cipher_offset;
2523         } else {
2524                 sym_op->cipher.data.length = cipher_len >> 3;
2525                 sym_op->cipher.data.offset = cipher_offset >> 3;
2526         }
2527
2528         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2529                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2530                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2531                 sym_op->auth.data.length = auth_len;
2532                 sym_op->auth.data.offset = auth_offset;
2533         } else {
2534                 sym_op->auth.data.length = auth_len >> 3;
2535                 sym_op->auth.data.offset = auth_offset >> 3;
2536         }
2537
2538         return 0;
2539 }
2540
2541 static int
2542 create_wireless_algo_auth_cipher_operation(
2543                 const uint8_t *auth_tag, unsigned int auth_tag_len,
2544                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2545                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2546                 unsigned int data_pad_len,
2547                 unsigned int cipher_len, unsigned int cipher_offset,
2548                 unsigned int auth_len, unsigned int auth_offset,
2549                 uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2550 {
2551         struct crypto_testsuite_params *ts_params = &testsuite_params;
2552         struct crypto_unittest_params *ut_params = &unittest_params;
2553
2554         enum rte_crypto_cipher_algorithm cipher_algo =
2555                         ut_params->cipher_xform.cipher.algo;
2556         enum rte_crypto_auth_algorithm auth_algo =
2557                         ut_params->auth_xform.auth.algo;
2558
2559         /* Generate Crypto op data structure */
2560         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2561                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2562         TEST_ASSERT_NOT_NULL(ut_params->op,
2563                         "Failed to allocate pktmbuf offload");
2564
2565         /* Set crypto operation data parameters */
2566         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2567
2568         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2569
2570         /* set crypto operation mbufs */
2571         sym_op->m_src = ut_params->ibuf;
2572         if (op_mode == OUT_OF_PLACE)
2573                 sym_op->m_dst = ut_params->obuf;
2574
2575         /* digest */
2576         if (!do_sgl) {
2577                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2578                         (op_mode == IN_PLACE ?
2579                                 ut_params->ibuf : ut_params->obuf),
2580                         uint8_t *, data_pad_len);
2581                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2582                         (op_mode == IN_PLACE ?
2583                                 ut_params->ibuf : ut_params->obuf),
2584                         data_pad_len);
2585                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2586         } else {
2587                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2588                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2589                                 sym_op->m_src : sym_op->m_dst);
2590                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2591                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2592                         sgl_buf = sgl_buf->next;
2593                 }
2594                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2595                                 uint8_t *, remaining_off);
2596                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2597                                 remaining_off);
2598                 memset(sym_op->auth.digest.data, 0, remaining_off);
2599                 while (sgl_buf->next != NULL) {
2600                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2601                                 0, rte_pktmbuf_data_len(sgl_buf));
2602                         sgl_buf = sgl_buf->next;
2603                 }
2604         }
2605
2606         /* Copy digest for the verification */
2607         if (verify)
2608                 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2609
2610         /* Copy cipher and auth IVs at the end of the crypto operation */
2611         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
2612                         ut_params->op, uint8_t *, IV_OFFSET);
2613
2614         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2615         iv_ptr += cipher_iv_len;
2616         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2617
2618         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2619                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2620                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2621                 sym_op->cipher.data.length = cipher_len;
2622                 sym_op->cipher.data.offset = cipher_offset;
2623         } else {
2624                 sym_op->cipher.data.length = cipher_len >> 3;
2625                 sym_op->cipher.data.offset = cipher_offset >> 3;
2626         }
2627
2628         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2629                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2630                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2631                 sym_op->auth.data.length = auth_len;
2632                 sym_op->auth.data.offset = auth_offset;
2633         } else {
2634                 sym_op->auth.data.length = auth_len >> 3;
2635                 sym_op->auth.data.offset = auth_offset >> 3;
2636         }
2637
2638         return 0;
2639 }
2640
2641 static int
2642 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2643 {
2644         struct crypto_testsuite_params *ts_params = &testsuite_params;
2645         struct crypto_unittest_params *ut_params = &unittest_params;
2646
2647         int retval;
2648         unsigned plaintext_pad_len;
2649         unsigned plaintext_len;
2650         uint8_t *plaintext;
2651         struct rte_cryptodev_info dev_info;
2652
2653         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2654         uint64_t feat_flags = dev_info.feature_flags;
2655
2656         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
2657                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
2658                 printf("Device doesn't support NON-Byte Aligned Data.\n");
2659                 return -ENOTSUP;
2660         }
2661
2662         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2663                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2664                 printf("Device doesn't support RAW data-path APIs.\n");
2665                 return -ENOTSUP;
2666         }
2667
2668         /* Verify the capabilities */
2669         struct rte_cryptodev_sym_capability_idx cap_idx;
2670         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2671         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2672         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2673                         &cap_idx) == NULL)
2674                 return -ENOTSUP;
2675
2676         /* Create SNOW 3G session */
2677         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2678                         tdata->key.data, tdata->key.len,
2679                         tdata->auth_iv.len, tdata->digest.len,
2680                         RTE_CRYPTO_AUTH_OP_GENERATE,
2681                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2682         if (retval < 0)
2683                 return retval;
2684
2685         /* alloc mbuf and set payload */
2686         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2687
2688         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2689         rte_pktmbuf_tailroom(ut_params->ibuf));
2690
2691         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2692         /* Append data which is padded to a multiple of */
2693         /* the algorithms block size */
2694         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2695         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2696                                 plaintext_pad_len);
2697         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2698
2699         /* Create SNOW 3G operation */
2700         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2701                         tdata->auth_iv.data, tdata->auth_iv.len,
2702                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2703                         tdata->validAuthLenInBits.len,
2704                         0);
2705         if (retval < 0)
2706                 return retval;
2707
2708         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2709                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2710                                 ut_params->op, 0, 1, 1, 0);
2711         else
2712                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2713                                 ut_params->op);
2714         ut_params->obuf = ut_params->op->sym->m_src;
2715         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2716         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2717                         + plaintext_pad_len;
2718
2719         /* Validate obuf */
2720         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2721         ut_params->digest,
2722         tdata->digest.data,
2723         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2724         "SNOW 3G Generated auth tag not as expected");
2725
2726         return 0;
2727 }
2728
2729 static int
2730 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2731 {
2732         struct crypto_testsuite_params *ts_params = &testsuite_params;
2733         struct crypto_unittest_params *ut_params = &unittest_params;
2734
2735         int retval;
2736         unsigned plaintext_pad_len;
2737         unsigned plaintext_len;
2738         uint8_t *plaintext;
2739         struct rte_cryptodev_info dev_info;
2740
2741         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2742         uint64_t feat_flags = dev_info.feature_flags;
2743
2744         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
2745                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
2746                 printf("Device doesn't support NON-Byte Aligned Data.\n");
2747                 return -ENOTSUP;
2748         }
2749
2750         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2751                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2752                 printf("Device doesn't support RAW data-path APIs.\n");
2753                 return -ENOTSUP;
2754         }
2755
2756         /* Verify the capabilities */
2757         struct rte_cryptodev_sym_capability_idx cap_idx;
2758         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2759         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2760         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2761                         &cap_idx) == NULL)
2762                 return -ENOTSUP;
2763
2764         /* Create SNOW 3G session */
2765         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2766                                 tdata->key.data, tdata->key.len,
2767                                 tdata->auth_iv.len, tdata->digest.len,
2768                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2769                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2770         if (retval < 0)
2771                 return retval;
2772         /* alloc mbuf and set payload */
2773         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2774
2775         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2776         rte_pktmbuf_tailroom(ut_params->ibuf));
2777
2778         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2779         /* Append data which is padded to a multiple of */
2780         /* the algorithms block size */
2781         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2782         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2783                                 plaintext_pad_len);
2784         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2785
2786         /* Create SNOW 3G operation */
2787         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2788                         tdata->digest.len,
2789                         tdata->auth_iv.data, tdata->auth_iv.len,
2790                         plaintext_pad_len,
2791                         RTE_CRYPTO_AUTH_OP_VERIFY,
2792                         tdata->validAuthLenInBits.len,
2793                         0);
2794         if (retval < 0)
2795                 return retval;
2796
2797         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2798                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2799                                 ut_params->op, 0, 1, 1, 0);
2800         else
2801                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2802                                 ut_params->op);
2803         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2804         ut_params->obuf = ut_params->op->sym->m_src;
2805         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2806                                 + plaintext_pad_len;
2807
2808         /* Validate obuf */
2809         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2810                 return 0;
2811         else
2812                 return -1;
2813
2814         return 0;
2815 }
2816
2817 static int
2818 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
2819 {
2820         struct crypto_testsuite_params *ts_params = &testsuite_params;
2821         struct crypto_unittest_params *ut_params = &unittest_params;
2822
2823         int retval;
2824         unsigned plaintext_pad_len;
2825         unsigned plaintext_len;
2826         uint8_t *plaintext;
2827         struct rte_cryptodev_info dev_info;
2828
2829         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2830         uint64_t feat_flags = dev_info.feature_flags;
2831
2832         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2833                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2834                 printf("Device doesn't support RAW data-path APIs.\n");
2835                 return -ENOTSUP;
2836         }
2837
2838         /* Verify the capabilities */
2839         struct rte_cryptodev_sym_capability_idx cap_idx;
2840         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2841         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
2842         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2843                         &cap_idx) == NULL)
2844                 return -ENOTSUP;
2845
2846         /* Create KASUMI session */
2847         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2848                         tdata->key.data, tdata->key.len,
2849                         0, tdata->digest.len,
2850                         RTE_CRYPTO_AUTH_OP_GENERATE,
2851                         RTE_CRYPTO_AUTH_KASUMI_F9);
2852         if (retval < 0)
2853                 return retval;
2854
2855         /* alloc mbuf and set payload */
2856         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2857
2858         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2859         rte_pktmbuf_tailroom(ut_params->ibuf));
2860
2861         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2862         /* Append data which is padded to a multiple of */
2863         /* the algorithms block size */
2864         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2865         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2866                                 plaintext_pad_len);
2867         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2868
2869         /* Create KASUMI operation */
2870         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2871                         NULL, 0,
2872                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2873                         tdata->plaintext.len,
2874                         0);
2875         if (retval < 0)
2876                 return retval;
2877
2878         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2879                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2880                         ut_params->op);
2881         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2882                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2883                                 ut_params->op, 0, 1, 1, 0);
2884         else
2885                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2886                         ut_params->op);
2887
2888         ut_params->obuf = ut_params->op->sym->m_src;
2889         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2890         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2891                         + plaintext_pad_len;
2892
2893         /* Validate obuf */
2894         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2895         ut_params->digest,
2896         tdata->digest.data,
2897         DIGEST_BYTE_LENGTH_KASUMI_F9,
2898         "KASUMI Generated auth tag not as expected");
2899
2900         return 0;
2901 }
2902
2903 static int
2904 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
2905 {
2906         struct crypto_testsuite_params *ts_params = &testsuite_params;
2907         struct crypto_unittest_params *ut_params = &unittest_params;
2908
2909         int retval;
2910         unsigned plaintext_pad_len;
2911         unsigned plaintext_len;
2912         uint8_t *plaintext;
2913         struct rte_cryptodev_info dev_info;
2914
2915         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2916         uint64_t feat_flags = dev_info.feature_flags;
2917
2918         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2919                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2920                 printf("Device doesn't support RAW data-path APIs.\n");
2921                 return -ENOTSUP;
2922         }
2923
2924         /* Verify the capabilities */
2925         struct rte_cryptodev_sym_capability_idx cap_idx;
2926         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2927         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
2928         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2929                         &cap_idx) == NULL)
2930                 return -ENOTSUP;
2931
2932         /* Create KASUMI session */
2933         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2934                                 tdata->key.data, tdata->key.len,
2935                                 0, tdata->digest.len,
2936                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2937                                 RTE_CRYPTO_AUTH_KASUMI_F9);
2938         if (retval < 0)
2939                 return retval;
2940         /* alloc mbuf and set payload */
2941         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2942
2943         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2944         rte_pktmbuf_tailroom(ut_params->ibuf));
2945
2946         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2947         /* Append data which is padded to a multiple */
2948         /* of the algorithms block size */
2949         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2950         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2951                                 plaintext_pad_len);
2952         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2953
2954         /* Create KASUMI operation */
2955         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2956                         tdata->digest.len,
2957                         NULL, 0,
2958                         plaintext_pad_len,
2959                         RTE_CRYPTO_AUTH_OP_VERIFY,
2960                         tdata->plaintext.len,
2961                         0);
2962         if (retval < 0)
2963                 return retval;
2964
2965         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2966                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2967                                 ut_params->op, 0, 1, 1, 0);
2968         else
2969                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2970                                 ut_params->op);
2971         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2972         ut_params->obuf = ut_params->op->sym->m_src;
2973         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2974                                 + plaintext_pad_len;
2975
2976         /* Validate obuf */
2977         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2978                 return 0;
2979         else
2980                 return -1;
2981
2982         return 0;
2983 }
2984
2985 static int
2986 test_snow3g_hash_generate_test_case_1(void)
2987 {
2988         return test_snow3g_authentication(&snow3g_hash_test_case_1);
2989 }
2990
2991 static int
2992 test_snow3g_hash_generate_test_case_2(void)
2993 {
2994         return test_snow3g_authentication(&snow3g_hash_test_case_2);
2995 }
2996
2997 static int
2998 test_snow3g_hash_generate_test_case_3(void)
2999 {
3000         return test_snow3g_authentication(&snow3g_hash_test_case_3);
3001 }
3002
3003 static int
3004 test_snow3g_hash_generate_test_case_4(void)
3005 {
3006         return test_snow3g_authentication(&snow3g_hash_test_case_4);
3007 }
3008
3009 static int
3010 test_snow3g_hash_generate_test_case_5(void)
3011 {
3012         return test_snow3g_authentication(&snow3g_hash_test_case_5);
3013 }
3014
3015 static int
3016 test_snow3g_hash_generate_test_case_6(void)
3017 {
3018         return test_snow3g_authentication(&snow3g_hash_test_case_6);
3019 }
3020
3021 static int
3022 test_snow3g_hash_verify_test_case_1(void)
3023 {
3024         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3025
3026 }
3027
3028 static int
3029 test_snow3g_hash_verify_test_case_2(void)
3030 {
3031         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3032 }
3033
3034 static int
3035 test_snow3g_hash_verify_test_case_3(void)
3036 {
3037         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3038 }
3039
3040 static int
3041 test_snow3g_hash_verify_test_case_4(void)
3042 {
3043         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3044 }
3045
3046 static int
3047 test_snow3g_hash_verify_test_case_5(void)
3048 {
3049         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3050 }
3051
3052 static int
3053 test_snow3g_hash_verify_test_case_6(void)
3054 {
3055         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3056 }
3057
3058 static int
3059 test_kasumi_hash_generate_test_case_1(void)
3060 {
3061         return test_kasumi_authentication(&kasumi_hash_test_case_1);
3062 }
3063
3064 static int
3065 test_kasumi_hash_generate_test_case_2(void)
3066 {
3067         return test_kasumi_authentication(&kasumi_hash_test_case_2);
3068 }
3069
3070 static int
3071 test_kasumi_hash_generate_test_case_3(void)
3072 {
3073         return test_kasumi_authentication(&kasumi_hash_test_case_3);
3074 }
3075
3076 static int
3077 test_kasumi_hash_generate_test_case_4(void)
3078 {
3079         return test_kasumi_authentication(&kasumi_hash_test_case_4);
3080 }
3081
3082 static int
3083 test_kasumi_hash_generate_test_case_5(void)
3084 {
3085         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3086 }
3087
3088 static int
3089 test_kasumi_hash_generate_test_case_6(void)
3090 {
3091         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3092 }
3093
3094 static int
3095 test_kasumi_hash_verify_test_case_1(void)
3096 {
3097         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3098 }
3099
3100 static int
3101 test_kasumi_hash_verify_test_case_2(void)
3102 {
3103         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3104 }
3105
3106 static int
3107 test_kasumi_hash_verify_test_case_3(void)
3108 {
3109         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3110 }
3111
3112 static int
3113 test_kasumi_hash_verify_test_case_4(void)
3114 {
3115         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3116 }
3117
3118 static int
3119 test_kasumi_hash_verify_test_case_5(void)
3120 {
3121         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3122 }
3123
3124 static int
3125 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3126 {
3127         struct crypto_testsuite_params *ts_params = &testsuite_params;
3128         struct crypto_unittest_params *ut_params = &unittest_params;
3129
3130         int retval;
3131         uint8_t *plaintext, *ciphertext;
3132         unsigned plaintext_pad_len;
3133         unsigned plaintext_len;
3134         struct rte_cryptodev_info dev_info;
3135
3136         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3137         uint64_t feat_flags = dev_info.feature_flags;
3138
3139         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3140                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3141                 printf("Device doesn't support RAW data-path APIs.\n");
3142                 return -ENOTSUP;
3143         }
3144
3145         /* Verify the capabilities */
3146         struct rte_cryptodev_sym_capability_idx cap_idx;
3147         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3148         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3149         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3150                         &cap_idx) == NULL)
3151                 return -ENOTSUP;
3152
3153         /* Create KASUMI session */
3154         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3155                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3156                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3157                                         tdata->key.data, tdata->key.len,
3158                                         tdata->cipher_iv.len);
3159         if (retval < 0)
3160                 return retval;
3161
3162         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3163
3164         /* Clear mbuf payload */
3165         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3166                rte_pktmbuf_tailroom(ut_params->ibuf));
3167
3168         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3169         /* Append data which is padded to a multiple */
3170         /* of the algorithms block size */
3171         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3172         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3173                                 plaintext_pad_len);
3174         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3175
3176         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3177
3178         /* Create KASUMI operation */
3179         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3180                                 tdata->cipher_iv.len,
3181                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3182                                 tdata->validCipherOffsetInBits.len);
3183         if (retval < 0)
3184                 return retval;
3185
3186         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3187                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3188                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3189         else
3190                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3191                                 ut_params->op);
3192         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3193
3194         ut_params->obuf = ut_params->op->sym->m_dst;
3195         if (ut_params->obuf)
3196                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3197         else
3198                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3199
3200         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3201
3202         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3203                                 (tdata->validCipherOffsetInBits.len >> 3);
3204         /* Validate obuf */
3205         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3206                 ciphertext,
3207                 reference_ciphertext,
3208                 tdata->validCipherLenInBits.len,
3209                 "KASUMI Ciphertext data not as expected");
3210         return 0;
3211 }
3212
3213 static int
3214 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3215 {
3216         struct crypto_testsuite_params *ts_params = &testsuite_params;
3217         struct crypto_unittest_params *ut_params = &unittest_params;
3218
3219         int retval;
3220
3221         unsigned int plaintext_pad_len;
3222         unsigned int plaintext_len;
3223
3224         uint8_t buffer[10000];
3225         const uint8_t *ciphertext;
3226
3227         struct rte_cryptodev_info dev_info;
3228
3229         /* Verify the capabilities */
3230         struct rte_cryptodev_sym_capability_idx cap_idx;
3231         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3232         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3233         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3234                         &cap_idx) == NULL)
3235                 return -ENOTSUP;
3236
3237         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3238
3239         uint64_t feat_flags = dev_info.feature_flags;
3240
3241         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3242                 printf("Device doesn't support in-place scatter-gather. "
3243                                 "Test Skipped.\n");
3244                 return -ENOTSUP;
3245         }
3246
3247         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3248                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3249                 printf("Device doesn't support RAW data-path APIs.\n");
3250                 return -ENOTSUP;
3251         }
3252
3253         /* Create KASUMI session */
3254         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3255                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3256                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3257                                         tdata->key.data, tdata->key.len,
3258                                         tdata->cipher_iv.len);
3259         if (retval < 0)
3260                 return retval;
3261
3262         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3263
3264
3265         /* Append data which is padded to a multiple */
3266         /* of the algorithms block size */
3267         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3268
3269         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3270                         plaintext_pad_len, 10, 0);
3271
3272         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3273
3274         /* Create KASUMI operation */
3275         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3276                                 tdata->cipher_iv.len,
3277                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3278                                 tdata->validCipherOffsetInBits.len);
3279         if (retval < 0)
3280                 return retval;
3281
3282         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3283                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3284                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3285         else
3286                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3287                                                 ut_params->op);
3288         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3289
3290         ut_params->obuf = ut_params->op->sym->m_dst;
3291
3292         if (ut_params->obuf)
3293                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3294                                 plaintext_len, buffer);
3295         else
3296                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3297                                 tdata->validCipherOffsetInBits.len >> 3,
3298                                 plaintext_len, buffer);
3299
3300         /* Validate obuf */
3301         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3302
3303         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3304                                 (tdata->validCipherOffsetInBits.len >> 3);
3305         /* Validate obuf */
3306         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3307                 ciphertext,
3308                 reference_ciphertext,
3309                 tdata->validCipherLenInBits.len,
3310                 "KASUMI Ciphertext data not as expected");
3311         return 0;
3312 }
3313
3314 static int
3315 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3316 {
3317         struct crypto_testsuite_params *ts_params = &testsuite_params;
3318         struct crypto_unittest_params *ut_params = &unittest_params;
3319
3320         int retval;
3321         uint8_t *plaintext, *ciphertext;
3322         unsigned plaintext_pad_len;
3323         unsigned plaintext_len;
3324
3325         /* Verify the capabilities */
3326         struct rte_cryptodev_sym_capability_idx cap_idx;
3327         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3328         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3329         /* Data-path service does not support OOP */
3330         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3331                         &cap_idx) == NULL)
3332                 return -ENOTSUP;
3333
3334         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3335                 return -ENOTSUP;
3336
3337         /* Create KASUMI session */
3338         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3339                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3340                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3341                                         tdata->key.data, tdata->key.len,
3342                                         tdata->cipher_iv.len);
3343         if (retval < 0)
3344                 return retval;
3345
3346         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3347         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3348
3349         /* Clear mbuf payload */
3350         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3351                rte_pktmbuf_tailroom(ut_params->ibuf));
3352
3353         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3354         /* Append data which is padded to a multiple */
3355         /* of the algorithms block size */
3356         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3357         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3358                                 plaintext_pad_len);
3359         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3360         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3361
3362         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3363
3364         /* Create KASUMI operation */
3365         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3366                                 tdata->cipher_iv.len,
3367                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3368                                 tdata->validCipherOffsetInBits.len);
3369         if (retval < 0)
3370                 return retval;
3371
3372         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3373                                                 ut_params->op);
3374         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3375
3376         ut_params->obuf = ut_params->op->sym->m_dst;
3377         if (ut_params->obuf)
3378                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3379         else
3380                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3381
3382         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3383
3384         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3385                                 (tdata->validCipherOffsetInBits.len >> 3);
3386         /* Validate obuf */
3387         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3388                 ciphertext,
3389                 reference_ciphertext,
3390                 tdata->validCipherLenInBits.len,
3391                 "KASUMI Ciphertext data not as expected");
3392         return 0;
3393 }
3394
3395 static int
3396 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3397 {
3398         struct crypto_testsuite_params *ts_params = &testsuite_params;
3399         struct crypto_unittest_params *ut_params = &unittest_params;
3400
3401         int retval;
3402         unsigned int plaintext_pad_len;
3403         unsigned int plaintext_len;
3404
3405         const uint8_t *ciphertext;
3406         uint8_t buffer[2048];
3407
3408         struct rte_cryptodev_info dev_info;
3409
3410         /* Verify the capabilities */
3411         struct rte_cryptodev_sym_capability_idx cap_idx;
3412         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3413         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3414         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3415                         &cap_idx) == NULL)
3416                 return -ENOTSUP;
3417
3418         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3419                 return -ENOTSUP;
3420
3421         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3422
3423         uint64_t feat_flags = dev_info.feature_flags;
3424         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3425                 printf("Device doesn't support out-of-place scatter-gather "
3426                                 "in both input and output mbufs. "
3427                                 "Test Skipped.\n");
3428                 return -ENOTSUP;
3429         }
3430
3431         /* Create KASUMI session */
3432         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3433                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3434                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3435                                         tdata->key.data, tdata->key.len,
3436                                         tdata->cipher_iv.len);
3437         if (retval < 0)
3438                 return retval;
3439
3440         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3441         /* Append data which is padded to a multiple */
3442         /* of the algorithms block size */
3443         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3444
3445         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3446                         plaintext_pad_len, 10, 0);
3447         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3448                         plaintext_pad_len, 3, 0);
3449
3450         /* Append data which is padded to a multiple */
3451         /* of the algorithms block size */
3452         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3453
3454         /* Create KASUMI operation */
3455         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3456                                 tdata->cipher_iv.len,
3457                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3458                                 tdata->validCipherOffsetInBits.len);
3459         if (retval < 0)
3460                 return retval;
3461
3462         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3463                                                 ut_params->op);
3464         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3465
3466         ut_params->obuf = ut_params->op->sym->m_dst;
3467         if (ut_params->obuf)
3468                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3469                                 plaintext_pad_len, buffer);
3470         else
3471                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3472                                 tdata->validCipherOffsetInBits.len >> 3,
3473                                 plaintext_pad_len, buffer);
3474
3475         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3476                                 (tdata->validCipherOffsetInBits.len >> 3);
3477         /* Validate obuf */
3478         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3479                 ciphertext,
3480                 reference_ciphertext,
3481                 tdata->validCipherLenInBits.len,
3482                 "KASUMI Ciphertext data not as expected");
3483         return 0;
3484 }
3485
3486
3487 static int
3488 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3489 {
3490         struct crypto_testsuite_params *ts_params = &testsuite_params;
3491         struct crypto_unittest_params *ut_params = &unittest_params;
3492
3493         int retval;
3494         uint8_t *ciphertext, *plaintext;
3495         unsigned ciphertext_pad_len;
3496         unsigned ciphertext_len;
3497
3498         /* Verify the capabilities */
3499         struct rte_cryptodev_sym_capability_idx cap_idx;
3500         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3501         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3502         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3503                         &cap_idx) == NULL)
3504                 return -ENOTSUP;
3505
3506         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3507                 return -ENOTSUP;
3508
3509         /* Create KASUMI session */
3510         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3511                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3512                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3513                                         tdata->key.data, tdata->key.len,
3514                                         tdata->cipher_iv.len);
3515         if (retval < 0)
3516                 return retval;
3517
3518         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3519         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3520
3521         /* Clear mbuf payload */
3522         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3523                rte_pktmbuf_tailroom(ut_params->ibuf));
3524
3525         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3526         /* Append data which is padded to a multiple */
3527         /* of the algorithms block size */
3528         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3529         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3530                                 ciphertext_pad_len);
3531         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3532         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3533
3534         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3535
3536         /* Create KASUMI operation */
3537         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3538                                 tdata->cipher_iv.len,
3539                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3540                                 tdata->validCipherOffsetInBits.len);
3541         if (retval < 0)
3542                 return retval;
3543
3544         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3545                                                 ut_params->op);
3546         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3547
3548         ut_params->obuf = ut_params->op->sym->m_dst;
3549         if (ut_params->obuf)
3550                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3551         else
3552                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3553
3554         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3555
3556         const uint8_t *reference_plaintext = tdata->plaintext.data +
3557                                 (tdata->validCipherOffsetInBits.len >> 3);
3558         /* Validate obuf */
3559         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3560                 plaintext,
3561                 reference_plaintext,
3562                 tdata->validCipherLenInBits.len,
3563                 "KASUMI Plaintext data not as expected");
3564         return 0;
3565 }
3566
3567 static int
3568 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3569 {
3570         struct crypto_testsuite_params *ts_params = &testsuite_params;
3571         struct crypto_unittest_params *ut_params = &unittest_params;
3572
3573         int retval;
3574         uint8_t *ciphertext, *plaintext;
3575         unsigned ciphertext_pad_len;
3576         unsigned ciphertext_len;
3577         struct rte_cryptodev_info dev_info;
3578
3579         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3580         uint64_t feat_flags = dev_info.feature_flags;
3581
3582         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3583                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3584                 printf("Device doesn't support RAW data-path APIs.\n");
3585                 return -ENOTSUP;
3586         }
3587
3588         /* Verify the capabilities */
3589         struct rte_cryptodev_sym_capability_idx cap_idx;
3590         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3591         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3592         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3593                         &cap_idx) == NULL)
3594                 return -ENOTSUP;
3595
3596         /* Create KASUMI session */
3597         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3598                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3599                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3600                                         tdata->key.data, tdata->key.len,
3601                                         tdata->cipher_iv.len);
3602         if (retval < 0)
3603                 return retval;
3604
3605         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3606
3607         /* Clear mbuf payload */
3608         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3609                rte_pktmbuf_tailroom(ut_params->ibuf));
3610
3611         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3612         /* Append data which is padded to a multiple */
3613         /* of the algorithms block size */
3614         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3615         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3616                                 ciphertext_pad_len);
3617         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3618
3619         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3620
3621         /* Create KASUMI operation */
3622         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3623                                         tdata->cipher_iv.len,
3624                                         tdata->ciphertext.len,
3625                                         tdata->validCipherOffsetInBits.len);
3626         if (retval < 0)
3627                 return retval;
3628
3629         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3630                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3631                                 ut_params->op, 1, 0, 1, 0);
3632         else
3633                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3634                                                 ut_params->op);
3635         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3636
3637         ut_params->obuf = ut_params->op->sym->m_dst;
3638         if (ut_params->obuf)
3639                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3640         else
3641                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3642
3643         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3644
3645         const uint8_t *reference_plaintext = tdata->plaintext.data +
3646                                 (tdata->validCipherOffsetInBits.len >> 3);
3647         /* Validate obuf */
3648         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3649                 plaintext,
3650                 reference_plaintext,
3651                 tdata->validCipherLenInBits.len,
3652                 "KASUMI Plaintext data not as expected");
3653         return 0;
3654 }
3655
3656 static int
3657 test_snow3g_encryption(const struct snow3g_test_data *tdata)
3658 {
3659         struct crypto_testsuite_params *ts_params = &testsuite_params;
3660         struct crypto_unittest_params *ut_params = &unittest_params;
3661
3662         int retval;
3663         uint8_t *plaintext, *ciphertext;
3664         unsigned plaintext_pad_len;
3665         unsigned plaintext_len;
3666         struct rte_cryptodev_info dev_info;
3667
3668         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3669         uint64_t feat_flags = dev_info.feature_flags;
3670
3671         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3672                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3673                 printf("Device doesn't support RAW data-path APIs.\n");
3674                 return -ENOTSUP;
3675         }
3676
3677         /* Verify the capabilities */
3678         struct rte_cryptodev_sym_capability_idx cap_idx;
3679         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3680         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3681         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3682                         &cap_idx) == NULL)
3683                 return -ENOTSUP;
3684
3685         /* Create SNOW 3G session */
3686         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3687                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3688                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3689                                         tdata->key.data, tdata->key.len,
3690                                         tdata->cipher_iv.len);
3691         if (retval < 0)
3692                 return retval;
3693
3694         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3695
3696         /* Clear mbuf payload */
3697         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3698                rte_pktmbuf_tailroom(ut_params->ibuf));
3699
3700         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3701         /* Append data which is padded to a multiple of */
3702         /* the algorithms block size */
3703         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3704         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3705                                 plaintext_pad_len);
3706         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3707
3708         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3709
3710         /* Create SNOW 3G operation */
3711         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3712                                         tdata->cipher_iv.len,
3713                                         tdata->validCipherLenInBits.len,
3714                                         0);
3715         if (retval < 0)
3716                 return retval;
3717
3718         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3719                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3720                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3721         else
3722                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3723                                                 ut_params->op);
3724         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3725
3726         ut_params->obuf = ut_params->op->sym->m_dst;
3727         if (ut_params->obuf)
3728                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3729         else
3730                 ciphertext = plaintext;
3731
3732         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3733
3734         /* Validate obuf */
3735         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3736                 ciphertext,
3737                 tdata->ciphertext.data,
3738                 tdata->validDataLenInBits.len,
3739                 "SNOW 3G Ciphertext data not as expected");
3740         return 0;
3741 }
3742
3743
3744 static int
3745 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
3746 {
3747         struct crypto_testsuite_params *ts_params = &testsuite_params;
3748         struct crypto_unittest_params *ut_params = &unittest_params;
3749         uint8_t *plaintext, *ciphertext;
3750
3751         int retval;
3752         unsigned plaintext_pad_len;
3753         unsigned plaintext_len;
3754
3755         /* Verify the capabilities */
3756         struct rte_cryptodev_sym_capability_idx cap_idx;
3757         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3758         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3759         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3760                         &cap_idx) == NULL)
3761                 return -ENOTSUP;
3762
3763         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3764                 return -ENOTSUP;
3765
3766         /* Create SNOW 3G session */
3767         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3768                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3769                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3770                                         tdata->key.data, tdata->key.len,
3771                                         tdata->cipher_iv.len);
3772         if (retval < 0)
3773                 return retval;
3774
3775         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3776         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3777
3778         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3779                         "Failed to allocate input buffer in mempool");
3780         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3781                         "Failed to allocate output buffer in mempool");
3782
3783         /* Clear mbuf payload */
3784         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3785                rte_pktmbuf_tailroom(ut_params->ibuf));
3786
3787         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3788         /* Append data which is padded to a multiple of */
3789         /* the algorithms block size */
3790         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3791         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3792                                 plaintext_pad_len);
3793         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3794         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3795
3796         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3797
3798         /* Create SNOW 3G operation */
3799         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3800                                         tdata->cipher_iv.len,
3801                                         tdata->validCipherLenInBits.len,
3802                                         0);
3803         if (retval < 0)
3804                 return retval;
3805
3806         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3807                                                 ut_params->op);
3808         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3809
3810         ut_params->obuf = ut_params->op->sym->m_dst;
3811         if (ut_params->obuf)
3812                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3813         else
3814                 ciphertext = plaintext;
3815
3816         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3817
3818         /* Validate obuf */
3819         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3820                 ciphertext,
3821                 tdata->ciphertext.data,
3822                 tdata->validDataLenInBits.len,
3823                 "SNOW 3G Ciphertext data not as expected");
3824         return 0;
3825 }
3826
3827 static int
3828 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
3829 {
3830         struct crypto_testsuite_params *ts_params = &testsuite_params;
3831         struct crypto_unittest_params *ut_params = &unittest_params;
3832
3833         int retval;
3834         unsigned int plaintext_pad_len;
3835         unsigned int plaintext_len;
3836         uint8_t buffer[10000];
3837         const uint8_t *ciphertext;
3838
3839         struct rte_cryptodev_info dev_info;
3840
3841         /* Verify the capabilities */
3842         struct rte_cryptodev_sym_capability_idx cap_idx;
3843         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3844         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3845         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3846                         &cap_idx) == NULL)
3847                 return -ENOTSUP;
3848
3849         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3850                 return -ENOTSUP;
3851
3852         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3853
3854         uint64_t feat_flags = dev_info.feature_flags;
3855
3856         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3857                 printf("Device doesn't support out-of-place scatter-gather "
3858                                 "in both input and output mbufs. "
3859                                 "Test Skipped.\n");
3860                 return -ENOTSUP;
3861         }
3862
3863         /* Create SNOW 3G session */
3864         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3865                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3866                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3867                                         tdata->key.data, tdata->key.len,
3868                                         tdata->cipher_iv.len);
3869         if (retval < 0)
3870                 return retval;
3871
3872         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3873         /* Append data which is padded to a multiple of */
3874         /* the algorithms block size */
3875         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3876
3877         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3878                         plaintext_pad_len, 10, 0);
3879         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3880                         plaintext_pad_len, 3, 0);
3881
3882         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3883                         "Failed to allocate input buffer in mempool");
3884         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3885                         "Failed to allocate output buffer in mempool");
3886
3887         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3888
3889         /* Create SNOW 3G operation */
3890         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3891                                         tdata->cipher_iv.len,
3892                                         tdata->validCipherLenInBits.len,
3893                                         0);
3894         if (retval < 0)
3895                 return retval;
3896
3897         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3898                                                 ut_params->op);
3899         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3900
3901         ut_params->obuf = ut_params->op->sym->m_dst;
3902         if (ut_params->obuf)
3903                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3904                                 plaintext_len, buffer);
3905         else
3906                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
3907                                 plaintext_len, buffer);
3908
3909         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3910
3911         /* Validate obuf */
3912         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3913                 ciphertext,
3914                 tdata->ciphertext.data,
3915                 tdata->validDataLenInBits.len,
3916                 "SNOW 3G Ciphertext data not as expected");
3917
3918         return 0;
3919 }
3920
3921 /* Shift right a buffer by "offset" bits, "offset" < 8 */
3922 static void
3923 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
3924 {
3925         uint8_t curr_byte, prev_byte;
3926         uint32_t length_in_bytes = ceil_byte_length(length + offset);
3927         uint8_t lower_byte_mask = (1 << offset) - 1;
3928         unsigned i;
3929
3930         prev_byte = buffer[0];
3931         buffer[0] >>= offset;
3932
3933         for (i = 1; i < length_in_bytes; i++) {
3934                 curr_byte = buffer[i];
3935                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
3936                                 (curr_byte >> offset);
3937                 prev_byte = curr_byte;
3938         }
3939 }
3940
3941 static int
3942 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
3943 {
3944         struct crypto_testsuite_params *ts_params = &testsuite_params;
3945         struct crypto_unittest_params *ut_params = &unittest_params;
3946         uint8_t *plaintext, *ciphertext;
3947         int retval;
3948         uint32_t plaintext_len;
3949         uint32_t plaintext_pad_len;
3950         uint8_t extra_offset = 4;
3951         uint8_t *expected_ciphertext_shifted;
3952         struct rte_cryptodev_info dev_info;
3953
3954         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3955         uint64_t feat_flags = dev_info.feature_flags;
3956
3957         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3958                         ((tdata->validDataLenInBits.len % 8) != 0)) {
3959                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3960                 return -ENOTSUP;
3961         }
3962
3963         /* Verify the capabilities */
3964         struct rte_cryptodev_sym_capability_idx cap_idx;
3965         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3966         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3967         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3968                         &cap_idx) == NULL)
3969                 return -ENOTSUP;
3970
3971         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3972                 return -ENOTSUP;
3973
3974         /* Create SNOW 3G session */
3975         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3976                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3977                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3978                                         tdata->key.data, tdata->key.len,
3979                                         tdata->cipher_iv.len);
3980         if (retval < 0)
3981                 return retval;
3982
3983         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3984         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3985
3986         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3987                         "Failed to allocate input buffer in mempool");
3988         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3989                         "Failed to allocate output buffer in mempool");
3990
3991         /* Clear mbuf payload */
3992         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3993                rte_pktmbuf_tailroom(ut_params->ibuf));
3994
3995         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
3996         /*
3997          * Append data which is padded to a
3998          * multiple of the algorithms block size
3999          */
4000         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4001
4002         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4003                                                 plaintext_pad_len);
4004
4005         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4006
4007         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4008         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4009
4010 #ifdef RTE_APP_TEST_DEBUG
4011         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4012 #endif
4013         /* Create SNOW 3G operation */
4014         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4015                                         tdata->cipher_iv.len,
4016                                         tdata->validCipherLenInBits.len,
4017                                         extra_offset);
4018         if (retval < 0)
4019                 return retval;
4020
4021         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4022                                                 ut_params->op);
4023         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4024
4025         ut_params->obuf = ut_params->op->sym->m_dst;
4026         if (ut_params->obuf)
4027                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4028         else
4029                 ciphertext = plaintext;
4030
4031 #ifdef RTE_APP_TEST_DEBUG
4032         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4033 #endif
4034
4035         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4036
4037         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4038                         "failed to reserve memory for ciphertext shifted\n");
4039
4040         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4041                         ceil_byte_length(tdata->ciphertext.len));
4042         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4043                         extra_offset);
4044         /* Validate obuf */
4045         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4046                 ciphertext,
4047                 expected_ciphertext_shifted,
4048                 tdata->validDataLenInBits.len,
4049                 extra_offset,
4050                 "SNOW 3G Ciphertext data not as expected");
4051         return 0;
4052 }
4053
4054 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4055 {
4056         struct crypto_testsuite_params *ts_params = &testsuite_params;
4057         struct crypto_unittest_params *ut_params = &unittest_params;
4058
4059         int retval;
4060
4061         uint8_t *plaintext, *ciphertext;
4062         unsigned ciphertext_pad_len;
4063         unsigned ciphertext_len;
4064         struct rte_cryptodev_info dev_info;
4065
4066         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4067         uint64_t feat_flags = dev_info.feature_flags;
4068
4069         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4070                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4071                 printf("Device doesn't support RAW data-path APIs.\n");
4072                 return -ENOTSUP;
4073         }
4074
4075         /* Verify the capabilities */
4076         struct rte_cryptodev_sym_capability_idx cap_idx;
4077         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4078         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4079         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4080                         &cap_idx) == NULL)
4081                 return -ENOTSUP;
4082
4083         /* Create SNOW 3G session */
4084         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4085                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4086                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4087                                         tdata->key.data, tdata->key.len,
4088                                         tdata->cipher_iv.len);
4089         if (retval < 0)
4090                 return retval;
4091
4092         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4093
4094         /* Clear mbuf payload */
4095         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4096                rte_pktmbuf_tailroom(ut_params->ibuf));
4097
4098         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4099         /* Append data which is padded to a multiple of */
4100         /* the algorithms block size */
4101         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4102         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4103                                 ciphertext_pad_len);
4104         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4105
4106         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4107
4108         /* Create SNOW 3G operation */
4109         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4110                                         tdata->cipher_iv.len,
4111                                         tdata->validCipherLenInBits.len,
4112                                         tdata->cipher.offset_bits);
4113         if (retval < 0)
4114                 return retval;
4115
4116         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4117                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4118                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4119         else
4120                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4121                                                 ut_params->op);
4122         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4123         ut_params->obuf = ut_params->op->sym->m_dst;
4124         if (ut_params->obuf)
4125                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4126         else
4127                 plaintext = ciphertext;
4128
4129         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4130
4131         /* Validate obuf */
4132         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4133                                 tdata->plaintext.data,
4134                                 tdata->validDataLenInBits.len,
4135                                 "SNOW 3G Plaintext data not as expected");
4136         return 0;
4137 }
4138
4139 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4140 {
4141         struct crypto_testsuite_params *ts_params = &testsuite_params;
4142         struct crypto_unittest_params *ut_params = &unittest_params;
4143
4144         int retval;
4145
4146         uint8_t *plaintext, *ciphertext;
4147         unsigned ciphertext_pad_len;
4148         unsigned ciphertext_len;
4149
4150         /* Verify the capabilities */
4151         struct rte_cryptodev_sym_capability_idx cap_idx;
4152         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4153         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4154         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4155                         &cap_idx) == NULL)
4156                 return -ENOTSUP;
4157
4158         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4159                 return -ENOTSUP;
4160
4161         /* Create SNOW 3G session */
4162         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4163                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4164                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4165                                         tdata->key.data, tdata->key.len,
4166                                         tdata->cipher_iv.len);
4167         if (retval < 0)
4168                 return retval;
4169
4170         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4171         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4172
4173         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4174                         "Failed to allocate input buffer");
4175         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4176                         "Failed to allocate output buffer");
4177
4178         /* Clear mbuf payload */
4179         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4180                rte_pktmbuf_tailroom(ut_params->ibuf));
4181
4182         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4183                        rte_pktmbuf_tailroom(ut_params->obuf));
4184
4185         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4186         /* Append data which is padded to a multiple of */
4187         /* the algorithms block size */
4188         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4189         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4190                                 ciphertext_pad_len);
4191         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4192         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4193
4194         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4195
4196         /* Create SNOW 3G operation */
4197         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4198                                         tdata->cipher_iv.len,
4199                                         tdata->validCipherLenInBits.len,
4200                                         0);
4201         if (retval < 0)
4202                 return retval;
4203
4204         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4205                                                 ut_params->op);
4206         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4207         ut_params->obuf = ut_params->op->sym->m_dst;
4208         if (ut_params->obuf)
4209                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4210         else
4211                 plaintext = ciphertext;
4212
4213         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4214
4215         /* Validate obuf */
4216         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4217                                 tdata->plaintext.data,
4218                                 tdata->validDataLenInBits.len,
4219                                 "SNOW 3G Plaintext data not as expected");
4220         return 0;
4221 }
4222
4223 static int
4224 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4225 {
4226         struct crypto_testsuite_params *ts_params = &testsuite_params;
4227         struct crypto_unittest_params *ut_params = &unittest_params;
4228
4229         int retval;
4230
4231         uint8_t *plaintext, *ciphertext;
4232         unsigned int plaintext_pad_len;
4233         unsigned int plaintext_len;
4234
4235         struct rte_cryptodev_info dev_info;
4236         struct rte_cryptodev_sym_capability_idx cap_idx;
4237
4238         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4239         uint64_t feat_flags = dev_info.feature_flags;
4240
4241         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4242                         ((tdata->validAuthLenInBits.len % 8 != 0) ||
4243                         (tdata->validDataLenInBits.len % 8 != 0))) {
4244                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4245                 return -ENOTSUP;
4246         }
4247
4248         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4249                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4250                 printf("Device doesn't support RAW data-path APIs.\n");
4251                 return -ENOTSUP;
4252         }
4253
4254         /* Check if device supports ZUC EEA3 */
4255         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4256         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4257
4258         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4259                         &cap_idx) == NULL)
4260                 return -ENOTSUP;
4261
4262         /* Check if device supports ZUC EIA3 */
4263         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4264         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4265
4266         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4267                         &cap_idx) == NULL)
4268                 return -ENOTSUP;
4269
4270         /* Create ZUC session */
4271         retval = create_zuc_cipher_auth_encrypt_generate_session(
4272                         ts_params->valid_devs[0],
4273                         tdata);
4274         if (retval < 0)
4275                 return retval;
4276         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4277
4278         /* clear mbuf payload */
4279         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4280                         rte_pktmbuf_tailroom(ut_params->ibuf));
4281
4282         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4283         /* Append data which is padded to a multiple of */
4284         /* the algorithms block size */
4285         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4286         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4287                                 plaintext_pad_len);
4288         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4289
4290         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4291
4292         /* Create ZUC operation */
4293         retval = create_zuc_cipher_hash_generate_operation(tdata);
4294         if (retval < 0)
4295                 return retval;
4296
4297         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4298                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4299                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4300         else
4301                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4302                         ut_params->op);
4303         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4304         ut_params->obuf = ut_params->op->sym->m_src;
4305         if (ut_params->obuf)
4306                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4307         else
4308                 ciphertext = plaintext;
4309
4310         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4311         /* Validate obuf */
4312         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4313                         ciphertext,
4314                         tdata->ciphertext.data,
4315                         tdata->validDataLenInBits.len,
4316                         "ZUC Ciphertext data not as expected");
4317
4318         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4319             + plaintext_pad_len;
4320
4321         /* Validate obuf */
4322         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4323                         ut_params->digest,
4324                         tdata->digest.data,
4325                         4,
4326                         "ZUC Generated auth tag not as expected");
4327         return 0;
4328 }
4329
4330 static int
4331 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4332 {
4333         struct crypto_testsuite_params *ts_params = &testsuite_params;
4334         struct crypto_unittest_params *ut_params = &unittest_params;
4335
4336         int retval;
4337
4338         uint8_t *plaintext, *ciphertext;
4339         unsigned plaintext_pad_len;
4340         unsigned plaintext_len;
4341         struct rte_cryptodev_info dev_info;
4342
4343         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4344         uint64_t feat_flags = dev_info.feature_flags;
4345
4346         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4347                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4348                 printf("Device doesn't support RAW data-path APIs.\n");
4349                 return -ENOTSUP;
4350         }
4351
4352         /* Verify the capabilities */
4353         struct rte_cryptodev_sym_capability_idx cap_idx;
4354         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4355         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4356         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4357                         &cap_idx) == NULL)
4358                 return -ENOTSUP;
4359         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4360         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4361         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4362                         &cap_idx) == NULL)
4363                 return -ENOTSUP;
4364
4365         /* Create SNOW 3G session */
4366         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4367                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4368                         RTE_CRYPTO_AUTH_OP_GENERATE,
4369                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4370                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4371                         tdata->key.data, tdata->key.len,
4372                         tdata->auth_iv.len, tdata->digest.len,
4373                         tdata->cipher_iv.len);
4374         if (retval < 0)
4375                 return retval;
4376         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4377
4378         /* clear mbuf payload */
4379         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4380                         rte_pktmbuf_tailroom(ut_params->ibuf));
4381
4382         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4383         /* Append data which is padded to a multiple of */
4384         /* the algorithms block size */
4385         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4386         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4387                                 plaintext_pad_len);
4388         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4389
4390         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4391
4392         /* Create SNOW 3G operation */
4393         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4394                         tdata->digest.len, tdata->auth_iv.data,
4395                         tdata->auth_iv.len,
4396                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4397                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4398                         tdata->validCipherLenInBits.len,
4399                         0,
4400                         tdata->validAuthLenInBits.len,
4401                         0
4402                         );
4403         if (retval < 0)
4404                 return retval;
4405
4406         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4407                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4408                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4409         else
4410                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4411                         ut_params->op);
4412         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4413         ut_params->obuf = ut_params->op->sym->m_src;
4414         if (ut_params->obuf)
4415                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4416         else
4417                 ciphertext = plaintext;
4418
4419         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4420         /* Validate obuf */
4421         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4422                         ciphertext,
4423                         tdata->ciphertext.data,
4424                         tdata->validDataLenInBits.len,
4425                         "SNOW 3G Ciphertext data not as expected");
4426
4427         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4428             + plaintext_pad_len;
4429
4430         /* Validate obuf */
4431         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4432                         ut_params->digest,
4433                         tdata->digest.data,
4434                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4435                         "SNOW 3G Generated auth tag not as expected");
4436         return 0;
4437 }
4438
4439 static int
4440 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4441         uint8_t op_mode, uint8_t verify)
4442 {
4443         struct crypto_testsuite_params *ts_params = &testsuite_params;
4444         struct crypto_unittest_params *ut_params = &unittest_params;
4445
4446         int retval;
4447
4448         uint8_t *plaintext = NULL, *ciphertext = NULL;
4449         unsigned int plaintext_pad_len;
4450         unsigned int plaintext_len;
4451         unsigned int ciphertext_pad_len;
4452         unsigned int ciphertext_len;
4453
4454         struct rte_cryptodev_info dev_info;
4455
4456         /* Verify the capabilities */
4457         struct rte_cryptodev_sym_capability_idx cap_idx;
4458         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4459         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4460         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4461                         &cap_idx) == NULL)
4462                 return -ENOTSUP;
4463         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4464         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4465         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4466                         &cap_idx) == NULL)
4467                 return -ENOTSUP;
4468
4469         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4470
4471         uint64_t feat_flags = dev_info.feature_flags;
4472
4473         if (op_mode == OUT_OF_PLACE) {
4474                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4475                         printf("Device doesn't support digest encrypted.\n");
4476                         return -ENOTSUP;
4477                 }
4478                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4479                         return -ENOTSUP;
4480         }
4481
4482         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4483                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4484                 printf("Device doesn't support RAW data-path APIs.\n");
4485                 return -ENOTSUP;
4486         }
4487
4488         /* Create SNOW 3G session */
4489         retval = create_wireless_algo_auth_cipher_session(
4490                         ts_params->valid_devs[0],
4491                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4492                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4493                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4494                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4495                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4496                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4497                         tdata->key.data, tdata->key.len,
4498                         tdata->auth_iv.len, tdata->digest.len,
4499                         tdata->cipher_iv.len);
4500
4501         if (retval < 0)
4502                 return retval;
4503
4504         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4505         if (op_mode == OUT_OF_PLACE)
4506                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4507
4508         /* clear mbuf payload */
4509         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4510                 rte_pktmbuf_tailroom(ut_params->ibuf));
4511         if (op_mode == OUT_OF_PLACE)
4512                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4513                         rte_pktmbuf_tailroom(ut_params->obuf));
4514
4515         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4516         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4517         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4518         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4519
4520         if (verify) {
4521                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4522                                         ciphertext_pad_len);
4523                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4524                 if (op_mode == OUT_OF_PLACE)
4525                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4526                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4527                         ciphertext_len);
4528         } else {
4529                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4530                                         plaintext_pad_len);
4531                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4532                 if (op_mode == OUT_OF_PLACE)
4533                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4534                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4535         }
4536
4537         /* Create SNOW 3G operation */
4538         retval = create_wireless_algo_auth_cipher_operation(
4539                 tdata->digest.data, tdata->digest.len,
4540                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4541                 tdata->auth_iv.data, tdata->auth_iv.len,
4542                 (tdata->digest.offset_bytes == 0 ?
4543                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4544                         : tdata->digest.offset_bytes),
4545                 tdata->validCipherLenInBits.len,
4546                 tdata->cipher.offset_bits,
4547                 tdata->validAuthLenInBits.len,
4548                 tdata->auth.offset_bits,
4549                 op_mode, 0, verify);
4550
4551         if (retval < 0)
4552                 return retval;
4553
4554         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4555                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4556                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4557         else
4558                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4559                         ut_params->op);
4560
4561         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4562
4563         ut_params->obuf = (op_mode == IN_PLACE ?
4564                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4565
4566         if (verify) {
4567                 if (ut_params->obuf)
4568                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4569                                                         uint8_t *);
4570                 else
4571                         plaintext = ciphertext +
4572                                 (tdata->cipher.offset_bits >> 3);
4573
4574                 debug_hexdump(stdout, "plaintext:", plaintext,
4575                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4576                 debug_hexdump(stdout, "plaintext expected:",
4577                         tdata->plaintext.data,
4578                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4579         } else {
4580                 if (ut_params->obuf)
4581                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4582                                                         uint8_t *);
4583                 else
4584                         ciphertext = plaintext;
4585
4586                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4587                         ciphertext_len);
4588                 debug_hexdump(stdout, "ciphertext expected:",
4589                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4590
4591                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4592                         + (tdata->digest.offset_bytes == 0 ?
4593                 plaintext_pad_len : tdata->digest.offset_bytes);
4594
4595                 debug_hexdump(stdout, "digest:", ut_params->digest,
4596                         tdata->digest.len);
4597                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
4598                                 tdata->digest.len);
4599         }
4600
4601         /* Validate obuf */
4602         if (verify) {
4603                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4604                         plaintext,
4605                         tdata->plaintext.data,
4606                         tdata->plaintext.len >> 3,
4607                         "SNOW 3G Plaintext data not as expected");
4608         } else {
4609                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4610                         ciphertext,
4611                         tdata->ciphertext.data,
4612                         tdata->validDataLenInBits.len,
4613                         "SNOW 3G Ciphertext data not as expected");
4614
4615                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4616                         ut_params->digest,
4617                         tdata->digest.data,
4618                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4619                         "SNOW 3G Generated auth tag not as expected");
4620         }
4621         return 0;
4622 }
4623
4624 static int
4625 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
4626         uint8_t op_mode, uint8_t verify)
4627 {
4628         struct crypto_testsuite_params *ts_params = &testsuite_params;
4629         struct crypto_unittest_params *ut_params = &unittest_params;
4630
4631         int retval;
4632
4633         const uint8_t *plaintext = NULL;
4634         const uint8_t *ciphertext = NULL;
4635         const uint8_t *digest = NULL;
4636         unsigned int plaintext_pad_len;
4637         unsigned int plaintext_len;
4638         unsigned int ciphertext_pad_len;
4639         unsigned int ciphertext_len;
4640         uint8_t buffer[10000];
4641         uint8_t digest_buffer[10000];
4642
4643         struct rte_cryptodev_info dev_info;
4644
4645         /* Verify the capabilities */
4646         struct rte_cryptodev_sym_capability_idx cap_idx;
4647         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4648         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4649         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4650                         &cap_idx) == NULL)
4651                 return -ENOTSUP;
4652         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4653         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4654         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4655                         &cap_idx) == NULL)
4656                 return -ENOTSUP;
4657
4658         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4659
4660         uint64_t feat_flags = dev_info.feature_flags;
4661
4662         if (op_mode == IN_PLACE) {
4663                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
4664                         printf("Device doesn't support in-place scatter-gather "
4665                                         "in both input and output mbufs.\n");
4666                         return -ENOTSUP;
4667                 }
4668                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4669                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4670                         printf("Device doesn't support RAW data-path APIs.\n");
4671                         return -ENOTSUP;
4672                 }
4673         } else {
4674                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4675                         return -ENOTSUP;
4676                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4677                         printf("Device doesn't support out-of-place scatter-gather "
4678                                         "in both input and output mbufs.\n");
4679                         return -ENOTSUP;
4680                 }
4681                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4682                         printf("Device doesn't support digest encrypted.\n");
4683                         return -ENOTSUP;
4684                 }
4685         }
4686
4687         /* Create SNOW 3G session */
4688         retval = create_wireless_algo_auth_cipher_session(
4689                         ts_params->valid_devs[0],
4690                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4691                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4692                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4693                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4694                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4695                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4696                         tdata->key.data, tdata->key.len,
4697                         tdata->auth_iv.len, tdata->digest.len,
4698                         tdata->cipher_iv.len);
4699
4700         if (retval < 0)
4701                 return retval;
4702
4703         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4704         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4705         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4706         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4707
4708         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4709                         plaintext_pad_len, 15, 0);
4710         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4711                         "Failed to allocate input buffer in mempool");
4712
4713         if (op_mode == OUT_OF_PLACE) {
4714                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4715                                 plaintext_pad_len, 15, 0);
4716                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
4717                                 "Failed to allocate output buffer in mempool");
4718         }
4719
4720         if (verify) {
4721                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
4722                         tdata->ciphertext.data);
4723                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4724                                         ciphertext_len, buffer);
4725                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4726                         ciphertext_len);
4727         } else {
4728                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
4729                         tdata->plaintext.data);
4730                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4731                                         plaintext_len, buffer);
4732                 debug_hexdump(stdout, "plaintext:", plaintext,
4733                         plaintext_len);
4734         }
4735         memset(buffer, 0, sizeof(buffer));
4736
4737         /* Create SNOW 3G operation */
4738         retval = create_wireless_algo_auth_cipher_operation(
4739                 tdata->digest.data, tdata->digest.len,
4740                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4741                 tdata->auth_iv.data, tdata->auth_iv.len,
4742                 (tdata->digest.offset_bytes == 0 ?
4743                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4744                         : tdata->digest.offset_bytes),
4745                 tdata->validCipherLenInBits.len,
4746                 tdata->cipher.offset_bits,
4747                 tdata->validAuthLenInBits.len,
4748                 tdata->auth.offset_bits,
4749                 op_mode, 1, verify);
4750
4751         if (retval < 0)
4752                 return retval;
4753
4754         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4755                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4756                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4757         else
4758                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4759                         ut_params->op);
4760
4761         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4762
4763         ut_params->obuf = (op_mode == IN_PLACE ?
4764                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4765
4766         if (verify) {
4767                 if (ut_params->obuf)
4768                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
4769                                         plaintext_len, buffer);
4770                 else
4771                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4772                                         plaintext_len, buffer);
4773
4774                 debug_hexdump(stdout, "plaintext:", plaintext,
4775                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4776                 debug_hexdump(stdout, "plaintext expected:",
4777                         tdata->plaintext.data,
4778                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4779         } else {
4780                 if (ut_params->obuf)
4781                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4782                                         ciphertext_len, buffer);
4783                 else
4784                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4785                                         ciphertext_len, buffer);
4786
4787                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4788                         ciphertext_len);
4789                 debug_hexdump(stdout, "ciphertext expected:",
4790                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4791
4792                 if (ut_params->obuf)
4793                         digest = rte_pktmbuf_read(ut_params->obuf,
4794                                 (tdata->digest.offset_bytes == 0 ?
4795                                 plaintext_pad_len : tdata->digest.offset_bytes),
4796                                 tdata->digest.len, digest_buffer);
4797                 else
4798                         digest = rte_pktmbuf_read(ut_params->ibuf,
4799                                 (tdata->digest.offset_bytes == 0 ?
4800                                 plaintext_pad_len : tdata->digest.offset_bytes),
4801                                 tdata->digest.len, digest_buffer);
4802
4803                 debug_hexdump(stdout, "digest:", digest,
4804                         tdata->digest.len);
4805                 debug_hexdump(stdout, "digest expected:",
4806                         tdata->digest.data, tdata->digest.len);
4807         }
4808
4809         /* Validate obuf */
4810         if (verify) {
4811                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4812                         plaintext,
4813                         tdata->plaintext.data,
4814                         tdata->plaintext.len >> 3,
4815                         "SNOW 3G Plaintext data not as expected");
4816         } else {
4817                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4818                         ciphertext,
4819                         tdata->ciphertext.data,
4820                         tdata->validDataLenInBits.len,
4821                         "SNOW 3G Ciphertext data not as expected");
4822
4823                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4824                         digest,
4825                         tdata->digest.data,
4826                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4827                         "SNOW 3G Generated auth tag not as expected");
4828         }
4829         return 0;
4830 }
4831
4832 static int
4833 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
4834         uint8_t op_mode, uint8_t verify)
4835 {
4836         struct crypto_testsuite_params *ts_params = &testsuite_params;
4837         struct crypto_unittest_params *ut_params = &unittest_params;
4838
4839         int retval;
4840
4841         uint8_t *plaintext = NULL, *ciphertext = NULL;
4842         unsigned int plaintext_pad_len;
4843         unsigned int plaintext_len;
4844         unsigned int ciphertext_pad_len;
4845         unsigned int ciphertext_len;
4846
4847         struct rte_cryptodev_info dev_info;
4848
4849         /* Verify the capabilities */
4850         struct rte_cryptodev_sym_capability_idx cap_idx;
4851         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4852         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
4853         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4854                         &cap_idx) == NULL)
4855                 return -ENOTSUP;
4856         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4857         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4858         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4859                         &cap_idx) == NULL)
4860                 return -ENOTSUP;
4861
4862         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4863
4864         uint64_t feat_flags = dev_info.feature_flags;
4865
4866         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4867                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4868                 printf("Device doesn't support RAW data-path APIs.\n");
4869                 return -ENOTSUP;
4870         }
4871
4872         if (op_mode == OUT_OF_PLACE) {
4873                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4874                         return -ENOTSUP;
4875                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4876                         printf("Device doesn't support digest encrypted.\n");
4877                         return -ENOTSUP;
4878                 }
4879         }
4880
4881         /* Create KASUMI session */
4882         retval = create_wireless_algo_auth_cipher_session(
4883                         ts_params->valid_devs[0],
4884                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4885                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4886                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4887                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4888                         RTE_CRYPTO_AUTH_KASUMI_F9,
4889                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4890                         tdata->key.data, tdata->key.len,
4891                         0, tdata->digest.len,
4892                         tdata->cipher_iv.len);
4893
4894         if (retval < 0)
4895                 return retval;
4896
4897         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4898         if (op_mode == OUT_OF_PLACE)
4899                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4900
4901         /* clear mbuf payload */
4902         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4903                 rte_pktmbuf_tailroom(ut_params->ibuf));
4904         if (op_mode == OUT_OF_PLACE)
4905                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4906                         rte_pktmbuf_tailroom(ut_params->obuf));
4907
4908         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4909         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4910         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4911         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4912
4913         if (verify) {
4914                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4915                                         ciphertext_pad_len);
4916                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4917                 if (op_mode == OUT_OF_PLACE)
4918                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4919                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4920                         ciphertext_len);
4921         } else {
4922                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4923                                         plaintext_pad_len);
4924                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4925                 if (op_mode == OUT_OF_PLACE)
4926                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4927                 debug_hexdump(stdout, "plaintext:", plaintext,
4928                         plaintext_len);
4929         }
4930
4931         /* Create KASUMI operation */
4932         retval = create_wireless_algo_auth_cipher_operation(
4933                 tdata->digest.data, tdata->digest.len,
4934                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4935                 NULL, 0,
4936                 (tdata->digest.offset_bytes == 0 ?
4937                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4938                         : tdata->digest.offset_bytes),
4939                 tdata->validCipherLenInBits.len,
4940                 tdata->validCipherOffsetInBits.len,
4941                 tdata->validAuthLenInBits.len,
4942                 0,
4943                 op_mode, 0, verify);
4944
4945         if (retval < 0)
4946                 return retval;
4947
4948         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4949                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4950                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4951         else
4952                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4953                         ut_params->op);
4954
4955         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4956
4957         ut_params->obuf = (op_mode == IN_PLACE ?
4958                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4959
4960
4961         if (verify) {
4962                 if (ut_params->obuf)
4963                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4964                                                         uint8_t *);
4965                 else
4966                         plaintext = ciphertext;
4967
4968                 debug_hexdump(stdout, "plaintext:", plaintext,
4969                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4970                 debug_hexdump(stdout, "plaintext expected:",
4971                         tdata->plaintext.data,
4972                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4973         } else {
4974                 if (ut_params->obuf)
4975                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4976                                                         uint8_t *);
4977                 else
4978                         ciphertext = plaintext;
4979
4980                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4981                         ciphertext_len);
4982                 debug_hexdump(stdout, "ciphertext expected:",
4983                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4984
4985                 ut_params->digest = rte_pktmbuf_mtod(
4986                         ut_params->obuf, uint8_t *) +
4987                         (tdata->digest.offset_bytes == 0 ?
4988                         plaintext_pad_len : tdata->digest.offset_bytes);
4989
4990                 debug_hexdump(stdout, "digest:", ut_params->digest,
4991                         tdata->digest.len);
4992                 debug_hexdump(stdout, "digest expected:",
4993                         tdata->digest.data, tdata->digest.len);
4994         }
4995
4996         /* Validate obuf */
4997         if (verify) {
4998                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4999                         plaintext,
5000                         tdata->plaintext.data,
5001                         tdata->plaintext.len >> 3,
5002                         "KASUMI Plaintext data not as expected");
5003         } else {
5004                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5005                         ciphertext,
5006                         tdata->ciphertext.data,
5007                         tdata->ciphertext.len >> 3,
5008                         "KASUMI Ciphertext data not as expected");
5009
5010                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5011                         ut_params->digest,
5012                         tdata->digest.data,
5013                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5014                         "KASUMI Generated auth tag not as expected");
5015         }
5016         return 0;
5017 }
5018
5019 static int
5020 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5021         uint8_t op_mode, uint8_t verify)
5022 {
5023         struct crypto_testsuite_params *ts_params = &testsuite_params;
5024         struct crypto_unittest_params *ut_params = &unittest_params;
5025
5026         int retval;
5027
5028         const uint8_t *plaintext = NULL;
5029         const uint8_t *ciphertext = NULL;
5030         const uint8_t *digest = NULL;
5031         unsigned int plaintext_pad_len;
5032         unsigned int plaintext_len;
5033         unsigned int ciphertext_pad_len;
5034         unsigned int ciphertext_len;
5035         uint8_t buffer[10000];
5036         uint8_t digest_buffer[10000];
5037
5038         struct rte_cryptodev_info dev_info;
5039
5040         /* Verify the capabilities */
5041         struct rte_cryptodev_sym_capability_idx cap_idx;
5042         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5043         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5044         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5045                         &cap_idx) == NULL)
5046                 return -ENOTSUP;
5047         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5048         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5049         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5050                         &cap_idx) == NULL)
5051                 return -ENOTSUP;
5052
5053         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5054
5055         uint64_t feat_flags = dev_info.feature_flags;
5056
5057         if (op_mode == IN_PLACE) {
5058                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5059                         printf("Device doesn't support in-place scatter-gather "
5060                                         "in both input and output mbufs.\n");
5061                         return -ENOTSUP;
5062                 }
5063                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5064                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5065                         printf("Device doesn't support RAW data-path APIs.\n");
5066                         return -ENOTSUP;
5067                 }
5068         } else {
5069                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5070                         return -ENOTSUP;
5071                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5072                         printf("Device doesn't support out-of-place scatter-gather "
5073                                         "in both input and output mbufs.\n");
5074                         return -ENOTSUP;
5075                 }
5076                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5077                         printf("Device doesn't support digest encrypted.\n");
5078                         return -ENOTSUP;
5079                 }
5080         }
5081
5082         /* Create KASUMI session */
5083         retval = create_wireless_algo_auth_cipher_session(
5084                         ts_params->valid_devs[0],
5085                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5086                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5087                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5088                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5089                         RTE_CRYPTO_AUTH_KASUMI_F9,
5090                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5091                         tdata->key.data, tdata->key.len,
5092                         0, tdata->digest.len,
5093                         tdata->cipher_iv.len);
5094
5095         if (retval < 0)
5096                 return retval;
5097
5098         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5099         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5100         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5101         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5102
5103         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5104                         plaintext_pad_len, 15, 0);
5105         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5106                         "Failed to allocate input buffer in mempool");
5107
5108         if (op_mode == OUT_OF_PLACE) {
5109                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5110                                 plaintext_pad_len, 15, 0);
5111                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5112                                 "Failed to allocate output buffer in mempool");
5113         }
5114
5115         if (verify) {
5116                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5117                         tdata->ciphertext.data);
5118                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5119                                         ciphertext_len, buffer);
5120                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5121                         ciphertext_len);
5122         } else {
5123                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5124                         tdata->plaintext.data);
5125                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5126                                         plaintext_len, buffer);
5127                 debug_hexdump(stdout, "plaintext:", plaintext,
5128                         plaintext_len);
5129         }
5130         memset(buffer, 0, sizeof(buffer));
5131
5132         /* Create KASUMI operation */
5133         retval = create_wireless_algo_auth_cipher_operation(
5134                 tdata->digest.data, tdata->digest.len,
5135                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5136                 NULL, 0,
5137                 (tdata->digest.offset_bytes == 0 ?
5138                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5139                         : tdata->digest.offset_bytes),
5140                 tdata->validCipherLenInBits.len,
5141                 tdata->validCipherOffsetInBits.len,
5142                 tdata->validAuthLenInBits.len,
5143                 0,
5144                 op_mode, 1, verify);
5145
5146         if (retval < 0)
5147                 return retval;
5148
5149         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5150                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5151                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5152         else
5153                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5154                         ut_params->op);
5155
5156         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5157
5158         ut_params->obuf = (op_mode == IN_PLACE ?
5159                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5160
5161         if (verify) {
5162                 if (ut_params->obuf)
5163                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5164                                         plaintext_len, buffer);
5165                 else
5166                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5167                                         plaintext_len, buffer);
5168
5169                 debug_hexdump(stdout, "plaintext:", plaintext,
5170                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5171                 debug_hexdump(stdout, "plaintext expected:",
5172                         tdata->plaintext.data,
5173                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5174         } else {
5175                 if (ut_params->obuf)
5176                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5177                                         ciphertext_len, buffer);
5178                 else
5179                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5180                                         ciphertext_len, buffer);
5181
5182                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5183                         ciphertext_len);
5184                 debug_hexdump(stdout, "ciphertext expected:",
5185                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5186
5187                 if (ut_params->obuf)
5188                         digest = rte_pktmbuf_read(ut_params->obuf,
5189                                 (tdata->digest.offset_bytes == 0 ?
5190                                 plaintext_pad_len : tdata->digest.offset_bytes),
5191                                 tdata->digest.len, digest_buffer);
5192                 else
5193                         digest = rte_pktmbuf_read(ut_params->ibuf,
5194                                 (tdata->digest.offset_bytes == 0 ?
5195                                 plaintext_pad_len : tdata->digest.offset_bytes),
5196                                 tdata->digest.len, digest_buffer);
5197
5198                 debug_hexdump(stdout, "digest:", digest,
5199                         tdata->digest.len);
5200                 debug_hexdump(stdout, "digest expected:",
5201                         tdata->digest.data, tdata->digest.len);
5202         }
5203
5204         /* Validate obuf */
5205         if (verify) {
5206                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5207                         plaintext,
5208                         tdata->plaintext.data,
5209                         tdata->plaintext.len >> 3,
5210                         "KASUMI Plaintext data not as expected");
5211         } else {
5212                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5213                         ciphertext,
5214                         tdata->ciphertext.data,
5215                         tdata->validDataLenInBits.len,
5216                         "KASUMI Ciphertext data not as expected");
5217
5218                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5219                         digest,
5220                         tdata->digest.data,
5221                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5222                         "KASUMI Generated auth tag not as expected");
5223         }
5224         return 0;
5225 }
5226
5227 static int
5228 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5229 {
5230         struct crypto_testsuite_params *ts_params = &testsuite_params;
5231         struct crypto_unittest_params *ut_params = &unittest_params;
5232
5233         int retval;
5234
5235         uint8_t *plaintext, *ciphertext;
5236         unsigned plaintext_pad_len;
5237         unsigned plaintext_len;
5238         struct rte_cryptodev_info dev_info;
5239
5240         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5241         uint64_t feat_flags = dev_info.feature_flags;
5242
5243         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5244                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5245                 printf("Device doesn't support RAW data-path APIs.\n");
5246                 return -ENOTSUP;
5247         }
5248
5249         /* Verify the capabilities */
5250         struct rte_cryptodev_sym_capability_idx cap_idx;
5251         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5252         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5253         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5254                         &cap_idx) == NULL)
5255                 return -ENOTSUP;
5256         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5257         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5258         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5259                         &cap_idx) == NULL)
5260                 return -ENOTSUP;
5261
5262         /* Create KASUMI session */
5263         retval = create_wireless_algo_cipher_auth_session(
5264                         ts_params->valid_devs[0],
5265                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5266                         RTE_CRYPTO_AUTH_OP_GENERATE,
5267                         RTE_CRYPTO_AUTH_KASUMI_F9,
5268                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5269                         tdata->key.data, tdata->key.len,
5270                         0, tdata->digest.len,
5271                         tdata->cipher_iv.len);
5272         if (retval < 0)
5273                 return retval;
5274
5275         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5276
5277         /* clear mbuf payload */
5278         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5279                         rte_pktmbuf_tailroom(ut_params->ibuf));
5280
5281         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5282         /* Append data which is padded to a multiple of */
5283         /* the algorithms block size */
5284         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5285         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5286                                 plaintext_pad_len);
5287         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5288
5289         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5290
5291         /* Create KASUMI operation */
5292         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5293                                 tdata->digest.len, NULL, 0,
5294                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5295                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5296                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5297                                 tdata->validCipherOffsetInBits.len,
5298                                 tdata->validAuthLenInBits.len,
5299                                 0
5300                                 );
5301         if (retval < 0)
5302                 return retval;
5303
5304         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5305                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5306                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5307         else
5308                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5309                         ut_params->op);
5310         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5311
5312         if (ut_params->op->sym->m_dst)
5313                 ut_params->obuf = ut_params->op->sym->m_dst;
5314         else
5315                 ut_params->obuf = ut_params->op->sym->m_src;
5316
5317         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5318                                 tdata->validCipherOffsetInBits.len >> 3);
5319
5320         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5321                         + plaintext_pad_len;
5322
5323         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5324                                 (tdata->validCipherOffsetInBits.len >> 3);
5325         /* Validate obuf */
5326         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5327                 ciphertext,
5328                 reference_ciphertext,
5329                 tdata->validCipherLenInBits.len,
5330                 "KASUMI Ciphertext data not as expected");
5331
5332         /* Validate obuf */
5333         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5334                 ut_params->digest,
5335                 tdata->digest.data,
5336                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5337                 "KASUMI Generated auth tag not as expected");
5338         return 0;
5339 }
5340
5341 static int
5342 test_zuc_encryption(const struct wireless_test_data *tdata)
5343 {
5344         struct crypto_testsuite_params *ts_params = &testsuite_params;
5345         struct crypto_unittest_params *ut_params = &unittest_params;
5346
5347         int retval;
5348         uint8_t *plaintext, *ciphertext;
5349         unsigned plaintext_pad_len;
5350         unsigned plaintext_len;
5351         struct rte_cryptodev_info dev_info;
5352
5353         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5354         uint64_t feat_flags = dev_info.feature_flags;
5355
5356         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5357                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5358                 printf("Device doesn't support RAW data-path APIs.\n");
5359                 return -ENOTSUP;
5360         }
5361
5362         struct rte_cryptodev_sym_capability_idx cap_idx;
5363
5364         /* Check if device supports ZUC EEA3 */
5365         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5366         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5367
5368         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5369                         &cap_idx) == NULL)
5370                 return -ENOTSUP;
5371
5372         /* Create ZUC session */
5373         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5374                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5375                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5376                                         tdata->key.data, tdata->key.len,
5377                                         tdata->cipher_iv.len);
5378         if (retval < 0)
5379                 return retval;
5380
5381         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5382
5383         /* Clear mbuf payload */
5384         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5385                rte_pktmbuf_tailroom(ut_params->ibuf));
5386
5387         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5388         /* Append data which is padded to a multiple */
5389         /* of the algorithms block size */
5390         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5391         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5392                                 plaintext_pad_len);
5393         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5394
5395         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5396
5397         /* Create ZUC operation */
5398         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5399                                         tdata->cipher_iv.len,
5400                                         tdata->plaintext.len,
5401                                         0);
5402         if (retval < 0)
5403                 return retval;
5404
5405         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5406                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5407                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5408         else
5409                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5410                                                 ut_params->op);
5411         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5412
5413         ut_params->obuf = ut_params->op->sym->m_dst;
5414         if (ut_params->obuf)
5415                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5416         else
5417                 ciphertext = plaintext;
5418
5419         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5420
5421         /* Validate obuf */
5422         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5423                 ciphertext,
5424                 tdata->ciphertext.data,
5425                 tdata->validCipherLenInBits.len,
5426                 "ZUC Ciphertext data not as expected");
5427         return 0;
5428 }
5429
5430 static int
5431 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5432 {
5433         struct crypto_testsuite_params *ts_params = &testsuite_params;
5434         struct crypto_unittest_params *ut_params = &unittest_params;
5435
5436         int retval;
5437
5438         unsigned int plaintext_pad_len;
5439         unsigned int plaintext_len;
5440         const uint8_t *ciphertext;
5441         uint8_t ciphertext_buffer[2048];
5442         struct rte_cryptodev_info dev_info;
5443
5444         struct rte_cryptodev_sym_capability_idx cap_idx;
5445
5446         /* Check if device supports ZUC EEA3 */
5447         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5448         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5449
5450         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5451                         &cap_idx) == NULL)
5452                 return -ENOTSUP;
5453
5454         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5455
5456         uint64_t feat_flags = dev_info.feature_flags;
5457
5458         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5459                 printf("Device doesn't support in-place scatter-gather. "
5460                                 "Test Skipped.\n");
5461                 return -ENOTSUP;
5462         }
5463
5464         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5465                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5466                 printf("Device doesn't support RAW data-path APIs.\n");
5467                 return -ENOTSUP;
5468         }
5469
5470         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5471
5472         /* Append data which is padded to a multiple */
5473         /* of the algorithms block size */
5474         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5475
5476         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5477                         plaintext_pad_len, 10, 0);
5478
5479         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5480                         tdata->plaintext.data);
5481
5482         /* Create ZUC session */
5483         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5484                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5485                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5486                         tdata->key.data, tdata->key.len,
5487                         tdata->cipher_iv.len);
5488         if (retval < 0)
5489                 return retval;
5490
5491         /* Clear mbuf payload */
5492
5493         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5494
5495         /* Create ZUC operation */
5496         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5497                         tdata->cipher_iv.len, tdata->plaintext.len,
5498                         0);
5499         if (retval < 0)
5500                 return retval;
5501
5502         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5503                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5504                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5505         else
5506                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5507                                                 ut_params->op);
5508         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5509
5510         ut_params->obuf = ut_params->op->sym->m_dst;
5511         if (ut_params->obuf)
5512                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
5513                         0, plaintext_len, ciphertext_buffer);
5514         else
5515                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
5516                         0, plaintext_len, ciphertext_buffer);
5517
5518         /* Validate obuf */
5519         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5520
5521         /* Validate obuf */
5522         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5523                 ciphertext,
5524                 tdata->ciphertext.data,
5525                 tdata->validCipherLenInBits.len,
5526                 "ZUC Ciphertext data not as expected");
5527
5528         return 0;
5529 }
5530
5531 static int
5532 test_zuc_authentication(const struct wireless_test_data *tdata)
5533 {
5534         struct crypto_testsuite_params *ts_params = &testsuite_params;
5535         struct crypto_unittest_params *ut_params = &unittest_params;
5536
5537         int retval;
5538         unsigned plaintext_pad_len;
5539         unsigned plaintext_len;
5540         uint8_t *plaintext;
5541
5542         struct rte_cryptodev_sym_capability_idx cap_idx;
5543         struct rte_cryptodev_info dev_info;
5544
5545         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5546         uint64_t feat_flags = dev_info.feature_flags;
5547
5548         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
5549                         (tdata->validAuthLenInBits.len % 8 != 0)) {
5550                 printf("Device doesn't support NON-Byte Aligned Data.\n");
5551                 return -ENOTSUP;
5552         }
5553
5554         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5555                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5556                 printf("Device doesn't support RAW data-path APIs.\n");
5557                 return -ENOTSUP;
5558         }
5559
5560         /* Check if device supports ZUC EIA3 */
5561         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5562         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5563
5564         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5565                         &cap_idx) == NULL)
5566                 return -ENOTSUP;
5567
5568         /* Create ZUC session */
5569         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
5570                         tdata->key.data, tdata->key.len,
5571                         tdata->auth_iv.len, tdata->digest.len,
5572                         RTE_CRYPTO_AUTH_OP_GENERATE,
5573                         RTE_CRYPTO_AUTH_ZUC_EIA3);
5574         if (retval < 0)
5575                 return retval;
5576
5577         /* alloc mbuf and set payload */
5578         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5579
5580         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5581         rte_pktmbuf_tailroom(ut_params->ibuf));
5582
5583         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5584         /* Append data which is padded to a multiple of */
5585         /* the algorithms block size */
5586         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5587         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5588                                 plaintext_pad_len);
5589         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5590
5591         /* Create ZUC operation */
5592         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
5593                         tdata->auth_iv.data, tdata->auth_iv.len,
5594                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5595                         tdata->validAuthLenInBits.len,
5596                         0);
5597         if (retval < 0)
5598                 return retval;
5599
5600         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5601                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5602                                 ut_params->op, 0, 1, 1, 0);
5603         else
5604                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5605                                 ut_params->op);
5606         ut_params->obuf = ut_params->op->sym->m_src;
5607         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5608         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5609                         + plaintext_pad_len;
5610
5611         /* Validate obuf */
5612         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5613         ut_params->digest,
5614         tdata->digest.data,
5615         tdata->digest.len,
5616         "ZUC Generated auth tag not as expected");
5617
5618         return 0;
5619 }
5620
5621 static int
5622 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
5623         uint8_t op_mode, uint8_t verify)
5624 {
5625         struct crypto_testsuite_params *ts_params = &testsuite_params;
5626         struct crypto_unittest_params *ut_params = &unittest_params;
5627
5628         int retval;
5629
5630         uint8_t *plaintext = NULL, *ciphertext = NULL;
5631         unsigned int plaintext_pad_len;
5632         unsigned int plaintext_len;
5633         unsigned int ciphertext_pad_len;
5634         unsigned int ciphertext_len;
5635
5636         struct rte_cryptodev_info dev_info;
5637         struct rte_cryptodev_sym_capability_idx cap_idx;
5638
5639         /* Check if device supports ZUC EIA3 */
5640         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5641         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5642
5643         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5644                         &cap_idx) == NULL)
5645                 return -ENOTSUP;
5646
5647         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5648
5649         uint64_t feat_flags = dev_info.feature_flags;
5650
5651         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5652                 printf("Device doesn't support digest encrypted.\n");
5653                 return -ENOTSUP;
5654         }
5655         if (op_mode == IN_PLACE) {
5656                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5657                         printf("Device doesn't support in-place scatter-gather "
5658                                         "in both input and output mbufs.\n");
5659                         return -ENOTSUP;
5660                 }
5661
5662                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5663                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5664                         printf("Device doesn't support RAW data-path APIs.\n");
5665                         return -ENOTSUP;
5666                 }
5667         } else {
5668                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5669                         return -ENOTSUP;
5670                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5671                         printf("Device doesn't support out-of-place scatter-gather "
5672                                         "in both input and output mbufs.\n");
5673                         return -ENOTSUP;
5674                 }
5675         }
5676
5677         /* Create ZUC session */
5678         retval = create_wireless_algo_auth_cipher_session(
5679                         ts_params->valid_devs[0],
5680                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5681                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5682                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5683                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5684                         RTE_CRYPTO_AUTH_ZUC_EIA3,
5685                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5686                         tdata->key.data, tdata->key.len,
5687                         tdata->auth_iv.len, tdata->digest.len,
5688                         tdata->cipher_iv.len);
5689
5690         if (retval < 0)
5691                 return retval;
5692
5693         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5694         if (op_mode == OUT_OF_PLACE)
5695                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5696
5697         /* clear mbuf payload */
5698         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5699                 rte_pktmbuf_tailroom(ut_params->ibuf));
5700         if (op_mode == OUT_OF_PLACE)
5701                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5702                         rte_pktmbuf_tailroom(ut_params->obuf));
5703
5704         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5705         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5706         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5707         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5708
5709         if (verify) {
5710                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5711                                         ciphertext_pad_len);
5712                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5713                 if (op_mode == OUT_OF_PLACE)
5714                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5715                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5716                         ciphertext_len);
5717         } else {
5718                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5719                                         plaintext_pad_len);
5720                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5721                 if (op_mode == OUT_OF_PLACE)
5722                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5723                 debug_hexdump(stdout, "plaintext:", plaintext,
5724                         plaintext_len);
5725         }
5726
5727         /* Create ZUC operation */
5728         retval = create_wireless_algo_auth_cipher_operation(
5729                 tdata->digest.data, tdata->digest.len,
5730                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5731                 tdata->auth_iv.data, tdata->auth_iv.len,
5732                 (tdata->digest.offset_bytes == 0 ?
5733                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5734                         : tdata->digest.offset_bytes),
5735                 tdata->validCipherLenInBits.len,
5736                 tdata->validCipherOffsetInBits.len,
5737                 tdata->validAuthLenInBits.len,
5738                 0,
5739                 op_mode, 0, verify);
5740
5741         if (retval < 0)
5742                 return retval;
5743
5744         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5745                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5746                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5747         else
5748                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5749                         ut_params->op);
5750
5751         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5752
5753         ut_params->obuf = (op_mode == IN_PLACE ?
5754                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5755
5756
5757         if (verify) {
5758                 if (ut_params->obuf)
5759                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5760                                                         uint8_t *);
5761                 else
5762                         plaintext = ciphertext;
5763
5764                 debug_hexdump(stdout, "plaintext:", plaintext,
5765                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5766                 debug_hexdump(stdout, "plaintext expected:",
5767                         tdata->plaintext.data,
5768                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5769         } else {
5770                 if (ut_params->obuf)
5771                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5772                                                         uint8_t *);
5773                 else
5774                         ciphertext = plaintext;
5775
5776                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5777                         ciphertext_len);
5778                 debug_hexdump(stdout, "ciphertext expected:",
5779                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5780
5781                 ut_params->digest = rte_pktmbuf_mtod(
5782                         ut_params->obuf, uint8_t *) +
5783                         (tdata->digest.offset_bytes == 0 ?
5784                         plaintext_pad_len : tdata->digest.offset_bytes);
5785
5786                 debug_hexdump(stdout, "digest:", ut_params->digest,
5787                         tdata->digest.len);
5788                 debug_hexdump(stdout, "digest expected:",
5789                         tdata->digest.data, tdata->digest.len);
5790         }
5791
5792         /* Validate obuf */
5793         if (verify) {
5794                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5795                         plaintext,
5796                         tdata->plaintext.data,
5797                         tdata->plaintext.len >> 3,
5798                         "ZUC Plaintext data not as expected");
5799         } else {
5800                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5801                         ciphertext,
5802                         tdata->ciphertext.data,
5803                         tdata->ciphertext.len >> 3,
5804                         "ZUC Ciphertext data not as expected");
5805
5806                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5807                         ut_params->digest,
5808                         tdata->digest.data,
5809                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5810                         "ZUC Generated auth tag not as expected");
5811         }
5812         return 0;
5813 }
5814
5815 static int
5816 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
5817         uint8_t op_mode, uint8_t verify)
5818 {
5819         struct crypto_testsuite_params *ts_params = &testsuite_params;
5820         struct crypto_unittest_params *ut_params = &unittest_params;
5821
5822         int retval;
5823
5824         const uint8_t *plaintext = NULL;
5825         const uint8_t *ciphertext = NULL;
5826         const uint8_t *digest = NULL;
5827         unsigned int plaintext_pad_len;
5828         unsigned int plaintext_len;
5829         unsigned int ciphertext_pad_len;
5830         unsigned int ciphertext_len;
5831         uint8_t buffer[10000];
5832         uint8_t digest_buffer[10000];
5833
5834         struct rte_cryptodev_info dev_info;
5835         struct rte_cryptodev_sym_capability_idx cap_idx;
5836
5837         /* Check if device supports ZUC EIA3 */
5838         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5839         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5840
5841         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5842                         &cap_idx) == NULL)
5843                 return -ENOTSUP;
5844
5845         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5846
5847         uint64_t feat_flags = dev_info.feature_flags;
5848
5849         if (op_mode == IN_PLACE) {
5850                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5851                         printf("Device doesn't support in-place scatter-gather "
5852                                         "in both input and output mbufs.\n");
5853                         return -ENOTSUP;
5854                 }
5855
5856                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5857                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5858                         printf("Device doesn't support RAW data-path APIs.\n");
5859                         return -ENOTSUP;
5860                 }
5861         } else {
5862                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5863                         return -ENOTSUP;
5864                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5865                         printf("Device doesn't support out-of-place scatter-gather "
5866                                         "in both input and output mbufs.\n");
5867                         return -ENOTSUP;
5868                 }
5869                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5870                         printf("Device doesn't support digest encrypted.\n");
5871                         return -ENOTSUP;
5872                 }
5873         }
5874
5875         /* Create ZUC session */
5876         retval = create_wireless_algo_auth_cipher_session(
5877                         ts_params->valid_devs[0],
5878                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5879                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5880                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5881                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5882                         RTE_CRYPTO_AUTH_ZUC_EIA3,
5883                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5884                         tdata->key.data, tdata->key.len,
5885                         tdata->auth_iv.len, tdata->digest.len,
5886                         tdata->cipher_iv.len);
5887
5888         if (retval < 0)
5889                 return retval;
5890
5891         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5892         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5893         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5894         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5895
5896         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5897                         plaintext_pad_len, 15, 0);
5898         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5899                         "Failed to allocate input buffer in mempool");
5900
5901         if (op_mode == OUT_OF_PLACE) {
5902                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5903                                 plaintext_pad_len, 15, 0);
5904                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5905                                 "Failed to allocate output buffer in mempool");
5906         }
5907
5908         if (verify) {
5909                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5910                         tdata->ciphertext.data);
5911                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5912                                         ciphertext_len, buffer);
5913                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5914                         ciphertext_len);
5915         } else {
5916                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5917                         tdata->plaintext.data);
5918                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5919                                         plaintext_len, buffer);
5920                 debug_hexdump(stdout, "plaintext:", plaintext,
5921                         plaintext_len);
5922         }
5923         memset(buffer, 0, sizeof(buffer));
5924
5925         /* Create ZUC operation */
5926         retval = create_wireless_algo_auth_cipher_operation(
5927                 tdata->digest.data, tdata->digest.len,
5928                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5929                 NULL, 0,
5930                 (tdata->digest.offset_bytes == 0 ?
5931                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5932                         : tdata->digest.offset_bytes),
5933                 tdata->validCipherLenInBits.len,
5934                 tdata->validCipherOffsetInBits.len,
5935                 tdata->validAuthLenInBits.len,
5936                 0,
5937                 op_mode, 1, verify);
5938
5939         if (retval < 0)
5940                 return retval;
5941
5942         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5943                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5944                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5945         else
5946                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5947                         ut_params->op);
5948
5949         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5950
5951         ut_params->obuf = (op_mode == IN_PLACE ?
5952                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5953
5954         if (verify) {
5955                 if (ut_params->obuf)
5956                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5957                                         plaintext_len, buffer);
5958                 else
5959                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5960                                         plaintext_len, buffer);
5961
5962                 debug_hexdump(stdout, "plaintext:", plaintext,
5963                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5964                 debug_hexdump(stdout, "plaintext expected:",
5965                         tdata->plaintext.data,
5966                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5967         } else {
5968                 if (ut_params->obuf)
5969                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5970                                         ciphertext_len, buffer);
5971                 else
5972                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5973                                         ciphertext_len, buffer);
5974
5975                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5976                         ciphertext_len);
5977                 debug_hexdump(stdout, "ciphertext expected:",
5978                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5979
5980                 if (ut_params->obuf)
5981                         digest = rte_pktmbuf_read(ut_params->obuf,
5982                                 (tdata->digest.offset_bytes == 0 ?
5983                                 plaintext_pad_len : tdata->digest.offset_bytes),
5984                                 tdata->digest.len, digest_buffer);
5985                 else
5986                         digest = rte_pktmbuf_read(ut_params->ibuf,
5987                                 (tdata->digest.offset_bytes == 0 ?
5988                                 plaintext_pad_len : tdata->digest.offset_bytes),
5989                                 tdata->digest.len, digest_buffer);
5990
5991                 debug_hexdump(stdout, "digest:", digest,
5992                         tdata->digest.len);
5993                 debug_hexdump(stdout, "digest expected:",
5994                         tdata->digest.data, tdata->digest.len);
5995         }
5996
5997         /* Validate obuf */
5998         if (verify) {
5999                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6000                         plaintext,
6001                         tdata->plaintext.data,
6002                         tdata->plaintext.len >> 3,
6003                         "ZUC Plaintext data not as expected");
6004         } else {
6005                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6006                         ciphertext,
6007                         tdata->ciphertext.data,
6008                         tdata->validDataLenInBits.len,
6009                         "ZUC Ciphertext data not as expected");
6010
6011                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6012                         digest,
6013                         tdata->digest.data,
6014                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6015                         "ZUC Generated auth tag not as expected");
6016         }
6017         return 0;
6018 }
6019
6020 static int
6021 test_kasumi_encryption_test_case_1(void)
6022 {
6023         return test_kasumi_encryption(&kasumi_test_case_1);
6024 }
6025
6026 static int
6027 test_kasumi_encryption_test_case_1_sgl(void)
6028 {
6029         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6030 }
6031
6032 static int
6033 test_kasumi_encryption_test_case_1_oop(void)
6034 {
6035         return test_kasumi_encryption_oop(&kasumi_test_case_1);
6036 }
6037
6038 static int
6039 test_kasumi_encryption_test_case_1_oop_sgl(void)
6040 {
6041         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6042 }
6043
6044 static int
6045 test_kasumi_encryption_test_case_2(void)
6046 {
6047         return test_kasumi_encryption(&kasumi_test_case_2);
6048 }
6049
6050 static int
6051 test_kasumi_encryption_test_case_3(void)
6052 {
6053         return test_kasumi_encryption(&kasumi_test_case_3);
6054 }
6055
6056 static int
6057 test_kasumi_encryption_test_case_4(void)
6058 {
6059         return test_kasumi_encryption(&kasumi_test_case_4);
6060 }
6061
6062 static int
6063 test_kasumi_encryption_test_case_5(void)
6064 {
6065         return test_kasumi_encryption(&kasumi_test_case_5);
6066 }
6067
6068 static int
6069 test_kasumi_decryption_test_case_1(void)
6070 {
6071         return test_kasumi_decryption(&kasumi_test_case_1);
6072 }
6073
6074 static int
6075 test_kasumi_decryption_test_case_1_oop(void)
6076 {
6077         return test_kasumi_decryption_oop(&kasumi_test_case_1);
6078 }
6079
6080 static int
6081 test_kasumi_decryption_test_case_2(void)
6082 {
6083         return test_kasumi_decryption(&kasumi_test_case_2);
6084 }
6085
6086 static int
6087 test_kasumi_decryption_test_case_3(void)
6088 {
6089         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6090         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6091                 return -ENOTSUP;
6092         return test_kasumi_decryption(&kasumi_test_case_3);
6093 }
6094
6095 static int
6096 test_kasumi_decryption_test_case_4(void)
6097 {
6098         return test_kasumi_decryption(&kasumi_test_case_4);
6099 }
6100
6101 static int
6102 test_kasumi_decryption_test_case_5(void)
6103 {
6104         return test_kasumi_decryption(&kasumi_test_case_5);
6105 }
6106 static int
6107 test_snow3g_encryption_test_case_1(void)
6108 {
6109         return test_snow3g_encryption(&snow3g_test_case_1);
6110 }
6111
6112 static int
6113 test_snow3g_encryption_test_case_1_oop(void)
6114 {
6115         return test_snow3g_encryption_oop(&snow3g_test_case_1);
6116 }
6117
6118 static int
6119 test_snow3g_encryption_test_case_1_oop_sgl(void)
6120 {
6121         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6122 }
6123
6124
6125 static int
6126 test_snow3g_encryption_test_case_1_offset_oop(void)
6127 {
6128         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6129 }
6130
6131 static int
6132 test_snow3g_encryption_test_case_2(void)
6133 {
6134         return test_snow3g_encryption(&snow3g_test_case_2);
6135 }
6136
6137 static int
6138 test_snow3g_encryption_test_case_3(void)
6139 {
6140         return test_snow3g_encryption(&snow3g_test_case_3);
6141 }
6142
6143 static int
6144 test_snow3g_encryption_test_case_4(void)
6145 {
6146         return test_snow3g_encryption(&snow3g_test_case_4);
6147 }
6148
6149 static int
6150 test_snow3g_encryption_test_case_5(void)
6151 {
6152         return test_snow3g_encryption(&snow3g_test_case_5);
6153 }
6154
6155 static int
6156 test_snow3g_decryption_test_case_1(void)
6157 {
6158         return test_snow3g_decryption(&snow3g_test_case_1);
6159 }
6160
6161 static int
6162 test_snow3g_decryption_test_case_1_oop(void)
6163 {
6164         return test_snow3g_decryption_oop(&snow3g_test_case_1);
6165 }
6166
6167 static int
6168 test_snow3g_decryption_test_case_2(void)
6169 {
6170         return test_snow3g_decryption(&snow3g_test_case_2);
6171 }
6172
6173 static int
6174 test_snow3g_decryption_test_case_3(void)
6175 {
6176         return test_snow3g_decryption(&snow3g_test_case_3);
6177 }
6178
6179 static int
6180 test_snow3g_decryption_test_case_4(void)
6181 {
6182         return test_snow3g_decryption(&snow3g_test_case_4);
6183 }
6184
6185 static int
6186 test_snow3g_decryption_test_case_5(void)
6187 {
6188         return test_snow3g_decryption(&snow3g_test_case_5);
6189 }
6190
6191 /*
6192  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6193  * Pattern digest from snow3g_test_data must be allocated as
6194  * 4 last bytes in plaintext.
6195  */
6196 static void
6197 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6198                 struct snow3g_hash_test_data *output)
6199 {
6200         if ((pattern != NULL) && (output != NULL)) {
6201                 output->key.len = pattern->key.len;
6202
6203                 memcpy(output->key.data,
6204                 pattern->key.data, pattern->key.len);
6205
6206                 output->auth_iv.len = pattern->auth_iv.len;
6207
6208                 memcpy(output->auth_iv.data,
6209                 pattern->auth_iv.data, pattern->auth_iv.len);
6210
6211                 output->plaintext.len = pattern->plaintext.len;
6212
6213                 memcpy(output->plaintext.data,
6214                 pattern->plaintext.data, pattern->plaintext.len >> 3);
6215
6216                 output->digest.len = pattern->digest.len;
6217
6218                 memcpy(output->digest.data,
6219                 &pattern->plaintext.data[pattern->digest.offset_bytes],
6220                 pattern->digest.len);
6221
6222                 output->validAuthLenInBits.len =
6223                 pattern->validAuthLenInBits.len;
6224         }
6225 }
6226
6227 /*
6228  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6229  */
6230 static int
6231 test_snow3g_decryption_with_digest_test_case_1(void)
6232 {
6233         struct snow3g_hash_test_data snow3g_hash_data;
6234
6235         /*
6236          * Function prepare data for hash veryfication test case.
6237          * Digest is allocated in 4 last bytes in plaintext, pattern.
6238          */
6239         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6240
6241         return test_snow3g_decryption(&snow3g_test_case_7) &
6242                         test_snow3g_authentication_verify(&snow3g_hash_data);
6243 }
6244
6245 static int
6246 test_snow3g_cipher_auth_test_case_1(void)
6247 {
6248         return test_snow3g_cipher_auth(&snow3g_test_case_3);
6249 }
6250
6251 static int
6252 test_snow3g_auth_cipher_test_case_1(void)
6253 {
6254         return test_snow3g_auth_cipher(
6255                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6256 }
6257
6258 static int
6259 test_snow3g_auth_cipher_test_case_2(void)
6260 {
6261         return test_snow3g_auth_cipher(
6262                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6263 }
6264
6265 static int
6266 test_snow3g_auth_cipher_test_case_2_oop(void)
6267 {
6268         return test_snow3g_auth_cipher(
6269                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6270 }
6271
6272 static int
6273 test_snow3g_auth_cipher_part_digest_enc(void)
6274 {
6275         return test_snow3g_auth_cipher(
6276                 &snow3g_auth_cipher_partial_digest_encryption,
6277                         IN_PLACE, 0);
6278 }
6279
6280 static int
6281 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6282 {
6283         return test_snow3g_auth_cipher(
6284                 &snow3g_auth_cipher_partial_digest_encryption,
6285                         OUT_OF_PLACE, 0);
6286 }
6287
6288 static int
6289 test_snow3g_auth_cipher_test_case_3_sgl(void)
6290 {
6291         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6292         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6293                 return -ENOTSUP;
6294         return test_snow3g_auth_cipher_sgl(
6295                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6296 }
6297
6298 static int
6299 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6300 {
6301         return test_snow3g_auth_cipher_sgl(
6302                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6303 }
6304
6305 static int
6306 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6307 {
6308         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6309         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6310                 return -ENOTSUP;
6311         return test_snow3g_auth_cipher_sgl(
6312                 &snow3g_auth_cipher_partial_digest_encryption,
6313                         IN_PLACE, 0);
6314 }
6315
6316 static int
6317 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6318 {
6319         return test_snow3g_auth_cipher_sgl(
6320                 &snow3g_auth_cipher_partial_digest_encryption,
6321                         OUT_OF_PLACE, 0);
6322 }
6323
6324 static int
6325 test_snow3g_auth_cipher_verify_test_case_1(void)
6326 {
6327         return test_snow3g_auth_cipher(
6328                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6329 }
6330
6331 static int
6332 test_snow3g_auth_cipher_verify_test_case_2(void)
6333 {
6334         return test_snow3g_auth_cipher(
6335                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6336 }
6337
6338 static int
6339 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6340 {
6341         return test_snow3g_auth_cipher(
6342                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6343 }
6344
6345 static int
6346 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6347 {
6348         return test_snow3g_auth_cipher(
6349                 &snow3g_auth_cipher_partial_digest_encryption,
6350                         IN_PLACE, 1);
6351 }
6352
6353 static int
6354 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6355 {
6356         return test_snow3g_auth_cipher(
6357                 &snow3g_auth_cipher_partial_digest_encryption,
6358                         OUT_OF_PLACE, 1);
6359 }
6360
6361 static int
6362 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6363 {
6364         return test_snow3g_auth_cipher_sgl(
6365                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6366 }
6367
6368 static int
6369 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6370 {
6371         return test_snow3g_auth_cipher_sgl(
6372                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6373 }
6374
6375 static int
6376 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6377 {
6378         return test_snow3g_auth_cipher_sgl(
6379                 &snow3g_auth_cipher_partial_digest_encryption,
6380                         IN_PLACE, 1);
6381 }
6382
6383 static int
6384 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6385 {
6386         return test_snow3g_auth_cipher_sgl(
6387                 &snow3g_auth_cipher_partial_digest_encryption,
6388                         OUT_OF_PLACE, 1);
6389 }
6390
6391 static int
6392 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6393 {
6394         return test_snow3g_auth_cipher(
6395                 &snow3g_test_case_7, IN_PLACE, 0);
6396 }
6397
6398 static int
6399 test_kasumi_auth_cipher_test_case_1(void)
6400 {
6401         return test_kasumi_auth_cipher(
6402                 &kasumi_test_case_3, IN_PLACE, 0);
6403 }
6404
6405 static int
6406 test_kasumi_auth_cipher_test_case_2(void)
6407 {
6408         return test_kasumi_auth_cipher(
6409                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6410 }
6411
6412 static int
6413 test_kasumi_auth_cipher_test_case_2_oop(void)
6414 {
6415         return test_kasumi_auth_cipher(
6416                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6417 }
6418
6419 static int
6420 test_kasumi_auth_cipher_test_case_2_sgl(void)
6421 {
6422         return test_kasumi_auth_cipher_sgl(
6423                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6424 }
6425
6426 static int
6427 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6428 {
6429         return test_kasumi_auth_cipher_sgl(
6430                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6431 }
6432
6433 static int
6434 test_kasumi_auth_cipher_verify_test_case_1(void)
6435 {
6436         return test_kasumi_auth_cipher(
6437                 &kasumi_test_case_3, IN_PLACE, 1);
6438 }
6439
6440 static int
6441 test_kasumi_auth_cipher_verify_test_case_2(void)
6442 {
6443         return test_kasumi_auth_cipher(
6444                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6445 }
6446
6447 static int
6448 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6449 {
6450         return test_kasumi_auth_cipher(
6451                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6452 }
6453
6454 static int
6455 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6456 {
6457         return test_kasumi_auth_cipher_sgl(
6458                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6459 }
6460
6461 static int
6462 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6463 {
6464         return test_kasumi_auth_cipher_sgl(
6465                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6466 }
6467
6468 static int
6469 test_kasumi_cipher_auth_test_case_1(void)
6470 {
6471         return test_kasumi_cipher_auth(&kasumi_test_case_6);
6472 }
6473
6474 static int
6475 test_zuc_encryption_test_case_1(void)
6476 {
6477         return test_zuc_encryption(&zuc_test_case_cipher_193b);
6478 }
6479
6480 static int
6481 test_zuc_encryption_test_case_2(void)
6482 {
6483         return test_zuc_encryption(&zuc_test_case_cipher_800b);
6484 }
6485
6486 static int
6487 test_zuc_encryption_test_case_3(void)
6488 {
6489         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
6490 }
6491
6492 static int
6493 test_zuc_encryption_test_case_4(void)
6494 {
6495         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
6496 }
6497
6498 static int
6499 test_zuc_encryption_test_case_5(void)
6500 {
6501         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
6502 }
6503
6504 static int
6505 test_zuc_encryption_test_case_6_sgl(void)
6506 {
6507         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
6508 }
6509
6510 static int
6511 test_zuc_hash_generate_test_case_1(void)
6512 {
6513         return test_zuc_authentication(&zuc_test_case_auth_1b);
6514 }
6515
6516 static int
6517 test_zuc_hash_generate_test_case_2(void)
6518 {
6519         return test_zuc_authentication(&zuc_test_case_auth_90b);
6520 }
6521
6522 static int
6523 test_zuc_hash_generate_test_case_3(void)
6524 {
6525         return test_zuc_authentication(&zuc_test_case_auth_577b);
6526 }
6527
6528 static int
6529 test_zuc_hash_generate_test_case_4(void)
6530 {
6531         return test_zuc_authentication(&zuc_test_case_auth_2079b);
6532 }
6533
6534 static int
6535 test_zuc_hash_generate_test_case_5(void)
6536 {
6537         return test_zuc_authentication(&zuc_test_auth_5670b);
6538 }
6539
6540 static int
6541 test_zuc_hash_generate_test_case_6(void)
6542 {
6543         return test_zuc_authentication(&zuc_test_case_auth_128b);
6544 }
6545
6546 static int
6547 test_zuc_hash_generate_test_case_7(void)
6548 {
6549         return test_zuc_authentication(&zuc_test_case_auth_2080b);
6550 }
6551
6552 static int
6553 test_zuc_hash_generate_test_case_8(void)
6554 {
6555         return test_zuc_authentication(&zuc_test_case_auth_584b);
6556 }
6557
6558 static int
6559 test_zuc_cipher_auth_test_case_1(void)
6560 {
6561         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
6562 }
6563
6564 static int
6565 test_zuc_cipher_auth_test_case_2(void)
6566 {
6567         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
6568 }
6569
6570 static int
6571 test_zuc_auth_cipher_test_case_1(void)
6572 {
6573         return test_zuc_auth_cipher(
6574                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
6575 }
6576
6577 static int
6578 test_zuc_auth_cipher_test_case_1_oop(void)
6579 {
6580         return test_zuc_auth_cipher(
6581                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
6582 }
6583
6584 static int
6585 test_zuc_auth_cipher_test_case_1_sgl(void)
6586 {
6587         return test_zuc_auth_cipher_sgl(
6588                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
6589 }
6590
6591 static int
6592 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
6593 {
6594         return test_zuc_auth_cipher_sgl(
6595                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
6596 }
6597
6598 static int
6599 test_zuc_auth_cipher_verify_test_case_1(void)
6600 {
6601         return test_zuc_auth_cipher(
6602                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
6603 }
6604
6605 static int
6606 test_zuc_auth_cipher_verify_test_case_1_oop(void)
6607 {
6608         return test_zuc_auth_cipher(
6609                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
6610 }
6611
6612 static int
6613 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
6614 {
6615         return test_zuc_auth_cipher_sgl(
6616                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
6617 }
6618
6619 static int
6620 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
6621 {
6622         return test_zuc_auth_cipher_sgl(
6623                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
6624 }
6625
6626 static int
6627 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
6628 {
6629         uint8_t dev_id = testsuite_params.valid_devs[0];
6630
6631         struct rte_cryptodev_sym_capability_idx cap_idx;
6632
6633         /* Check if device supports particular cipher algorithm */
6634         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6635         cap_idx.algo.cipher = tdata->cipher_algo;
6636         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
6637                 return -ENOTSUP;
6638
6639         /* Check if device supports particular hash algorithm */
6640         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6641         cap_idx.algo.auth = tdata->auth_algo;
6642         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
6643                 return -ENOTSUP;
6644
6645         return 0;
6646 }
6647
6648 static int
6649 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
6650         uint8_t op_mode, uint8_t verify)
6651 {
6652         struct crypto_testsuite_params *ts_params = &testsuite_params;
6653         struct crypto_unittest_params *ut_params = &unittest_params;
6654
6655         int retval;
6656
6657         uint8_t *plaintext = NULL, *ciphertext = NULL;
6658         unsigned int plaintext_pad_len;
6659         unsigned int plaintext_len;
6660         unsigned int ciphertext_pad_len;
6661         unsigned int ciphertext_len;
6662
6663         struct rte_cryptodev_info dev_info;
6664
6665         /* Check if device supports particular algorithms separately */
6666         if (test_mixed_check_if_unsupported(tdata))
6667                 return -ENOTSUP;
6668         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6669                 return -ENOTSUP;
6670
6671         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6672
6673         uint64_t feat_flags = dev_info.feature_flags;
6674
6675         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6676                 printf("Device doesn't support digest encrypted.\n");
6677                 return -ENOTSUP;
6678         }
6679
6680         if (op_mode == OUT_OF_PLACE)
6681                 return -ENOTSUP;
6682
6683         /* Create the session */
6684         if (verify)
6685                 retval = create_wireless_algo_cipher_auth_session(
6686                                 ts_params->valid_devs[0],
6687                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
6688                                 RTE_CRYPTO_AUTH_OP_VERIFY,
6689                                 tdata->auth_algo,
6690                                 tdata->cipher_algo,
6691                                 tdata->auth_key.data, tdata->auth_key.len,
6692                                 tdata->auth_iv.len, tdata->digest_enc.len,
6693                                 tdata->cipher_iv.len);
6694         else
6695                 retval = create_wireless_algo_auth_cipher_session(
6696                                 ts_params->valid_devs[0],
6697                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6698                                 RTE_CRYPTO_AUTH_OP_GENERATE,
6699                                 tdata->auth_algo,
6700                                 tdata->cipher_algo,
6701                                 tdata->auth_key.data, tdata->auth_key.len,
6702                                 tdata->auth_iv.len, tdata->digest_enc.len,
6703                                 tdata->cipher_iv.len);
6704         if (retval < 0)
6705                 return retval;
6706
6707         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6708         if (op_mode == OUT_OF_PLACE)
6709                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6710
6711         /* clear mbuf payload */
6712         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6713                 rte_pktmbuf_tailroom(ut_params->ibuf));
6714         if (op_mode == OUT_OF_PLACE) {
6715
6716                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6717                                 rte_pktmbuf_tailroom(ut_params->obuf));
6718         }
6719
6720         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
6721         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
6722         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6723         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6724
6725         if (verify) {
6726                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6727                                 ciphertext_pad_len);
6728                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6729                 if (op_mode == OUT_OF_PLACE)
6730                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6731                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6732                                 ciphertext_len);
6733         } else {
6734                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6735                                 plaintext_pad_len);
6736                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6737                 if (op_mode == OUT_OF_PLACE)
6738                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6739                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6740         }
6741
6742         /* Create the operation */
6743         retval = create_wireless_algo_auth_cipher_operation(
6744                         tdata->digest_enc.data, tdata->digest_enc.len,
6745                         tdata->cipher_iv.data, tdata->cipher_iv.len,
6746                         tdata->auth_iv.data, tdata->auth_iv.len,
6747                         (tdata->digest_enc.offset == 0 ?
6748                                 plaintext_pad_len
6749                                 : tdata->digest_enc.offset),
6750                         tdata->validCipherLen.len_bits,
6751                         tdata->cipher.offset_bits,
6752                         tdata->validAuthLen.len_bits,
6753                         tdata->auth.offset_bits,
6754                         op_mode, 0, verify);
6755
6756         if (retval < 0)
6757                 return retval;
6758
6759         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6760                         ut_params->op);
6761
6762         /* Check if the op failed because the device doesn't */
6763         /* support this particular combination of algorithms */
6764         if (ut_params->op == NULL && ut_params->op->status ==
6765                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
6766                 printf("Device doesn't support this mixed combination. "
6767                                 "Test Skipped.\n");
6768                 return -ENOTSUP;
6769         }
6770
6771         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6772
6773         ut_params->obuf = (op_mode == IN_PLACE ?
6774                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6775
6776         if (verify) {
6777                 if (ut_params->obuf)
6778                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6779                                                         uint8_t *);
6780                 else
6781                         plaintext = ciphertext +
6782                                         (tdata->cipher.offset_bits >> 3);
6783
6784                 debug_hexdump(stdout, "plaintext:", plaintext,
6785                                 tdata->plaintext.len_bits >> 3);
6786                 debug_hexdump(stdout, "plaintext expected:",
6787                                 tdata->plaintext.data,
6788                                 tdata->plaintext.len_bits >> 3);
6789         } else {
6790                 if (ut_params->obuf)
6791                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6792                                         uint8_t *);
6793                 else
6794                         ciphertext = plaintext;
6795
6796                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6797                                 ciphertext_len);
6798                 debug_hexdump(stdout, "ciphertext expected:",
6799                                 tdata->ciphertext.data,
6800                                 tdata->ciphertext.len_bits >> 3);
6801
6802                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6803                                 + (tdata->digest_enc.offset == 0 ?
6804                 plaintext_pad_len : tdata->digest_enc.offset);
6805
6806                 debug_hexdump(stdout, "digest:", ut_params->digest,
6807                                 tdata->digest_enc.len);
6808                 debug_hexdump(stdout, "digest expected:",
6809                                 tdata->digest_enc.data,
6810                                 tdata->digest_enc.len);
6811         }
6812
6813         /* Validate obuf */
6814         if (verify) {
6815                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6816                                 plaintext,
6817                                 tdata->plaintext.data,
6818                                 tdata->plaintext.len_bits >> 3,
6819                                 "Plaintext data not as expected");
6820         } else {
6821                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6822                                 ciphertext,
6823                                 tdata->ciphertext.data,
6824                                 tdata->validDataLen.len_bits,
6825                                 "Ciphertext data not as expected");
6826
6827                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6828                                 ut_params->digest,
6829                                 tdata->digest_enc.data,
6830                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
6831                                 "Generated auth tag not as expected");
6832         }
6833
6834         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6835                         "crypto op processing failed");
6836
6837         return 0;
6838 }
6839
6840 static int
6841 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
6842         uint8_t op_mode, uint8_t verify)
6843 {
6844         struct crypto_testsuite_params *ts_params = &testsuite_params;
6845         struct crypto_unittest_params *ut_params = &unittest_params;
6846
6847         int retval;
6848
6849         const uint8_t *plaintext = NULL;
6850         const uint8_t *ciphertext = NULL;
6851         const uint8_t *digest = NULL;
6852         unsigned int plaintext_pad_len;
6853         unsigned int plaintext_len;
6854         unsigned int ciphertext_pad_len;
6855         unsigned int ciphertext_len;
6856         uint8_t buffer[10000];
6857         uint8_t digest_buffer[10000];
6858
6859         struct rte_cryptodev_info dev_info;
6860
6861         /* Check if device supports particular algorithms */
6862         if (test_mixed_check_if_unsupported(tdata))
6863                 return -ENOTSUP;
6864         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6865                 return -ENOTSUP;
6866
6867         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6868
6869         uint64_t feat_flags = dev_info.feature_flags;
6870
6871         if (op_mode == IN_PLACE) {
6872                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6873                         printf("Device doesn't support in-place scatter-gather "
6874                                         "in both input and output mbufs.\n");
6875                         return -ENOTSUP;
6876                 }
6877         } else {
6878                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6879                         printf("Device doesn't support out-of-place scatter-gather "
6880                                         "in both input and output mbufs.\n");
6881                         return -ENOTSUP;
6882                 }
6883                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6884                         printf("Device doesn't support digest encrypted.\n");
6885                         return -ENOTSUP;
6886                 }
6887         }
6888
6889         /* Create the session */
6890         if (verify)
6891                 retval = create_wireless_algo_cipher_auth_session(
6892                                 ts_params->valid_devs[0],
6893                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
6894                                 RTE_CRYPTO_AUTH_OP_VERIFY,
6895                                 tdata->auth_algo,
6896                                 tdata->cipher_algo,
6897                                 tdata->auth_key.data, tdata->auth_key.len,
6898                                 tdata->auth_iv.len, tdata->digest_enc.len,
6899                                 tdata->cipher_iv.len);
6900         else
6901                 retval = create_wireless_algo_auth_cipher_session(
6902                                 ts_params->valid_devs[0],
6903                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6904                                 RTE_CRYPTO_AUTH_OP_GENERATE,
6905                                 tdata->auth_algo,
6906                                 tdata->cipher_algo,
6907                                 tdata->auth_key.data, tdata->auth_key.len,
6908                                 tdata->auth_iv.len, tdata->digest_enc.len,
6909                                 tdata->cipher_iv.len);
6910         if (retval < 0)
6911                 return retval;
6912
6913         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
6914         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
6915         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6916         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6917
6918         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6919                         ciphertext_pad_len, 15, 0);
6920         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6921                         "Failed to allocate input buffer in mempool");
6922
6923         if (op_mode == OUT_OF_PLACE) {
6924                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6925                                 plaintext_pad_len, 15, 0);
6926                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6927                                 "Failed to allocate output buffer in mempool");
6928         }
6929
6930         if (verify) {
6931                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6932                         tdata->ciphertext.data);
6933                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6934                                         ciphertext_len, buffer);
6935                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6936                         ciphertext_len);
6937         } else {
6938                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6939                         tdata->plaintext.data);
6940                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6941                                         plaintext_len, buffer);
6942                 debug_hexdump(stdout, "plaintext:", plaintext,
6943                         plaintext_len);
6944         }
6945         memset(buffer, 0, sizeof(buffer));
6946
6947         /* Create the operation */
6948         retval = create_wireless_algo_auth_cipher_operation(
6949                         tdata->digest_enc.data, tdata->digest_enc.len,
6950                         tdata->cipher_iv.data, tdata->cipher_iv.len,
6951                         tdata->auth_iv.data, tdata->auth_iv.len,
6952                         (tdata->digest_enc.offset == 0 ?
6953                                 plaintext_pad_len
6954                                 : tdata->digest_enc.offset),
6955                         tdata->validCipherLen.len_bits,
6956                         tdata->cipher.offset_bits,
6957                         tdata->validAuthLen.len_bits,
6958                         tdata->auth.offset_bits,
6959                         op_mode, 1, verify);
6960
6961         if (retval < 0)
6962                 return retval;
6963
6964         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6965                         ut_params->op);
6966
6967         /* Check if the op failed because the device doesn't */
6968         /* support this particular combination of algorithms */
6969         if (ut_params->op == NULL && ut_params->op->status ==
6970                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
6971                 printf("Device doesn't support this mixed combination. "
6972                                 "Test Skipped.\n");
6973                 return -ENOTSUP;
6974         }
6975
6976         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6977
6978         ut_params->obuf = (op_mode == IN_PLACE ?
6979                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6980
6981         if (verify) {
6982                 if (ut_params->obuf)
6983                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6984                                         plaintext_len, buffer);
6985                 else
6986                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6987                                         plaintext_len, buffer);
6988
6989                 debug_hexdump(stdout, "plaintext:", plaintext,
6990                                 (tdata->plaintext.len_bits >> 3) -
6991                                 tdata->digest_enc.len);
6992                 debug_hexdump(stdout, "plaintext expected:",
6993                                 tdata->plaintext.data,
6994                                 (tdata->plaintext.len_bits >> 3) -
6995                                 tdata->digest_enc.len);
6996         } else {
6997                 if (ut_params->obuf)
6998                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6999                                         ciphertext_len, buffer);
7000                 else
7001                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7002                                         ciphertext_len, buffer);
7003
7004                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7005                         ciphertext_len);
7006                 debug_hexdump(stdout, "ciphertext expected:",
7007                         tdata->ciphertext.data,
7008                         tdata->ciphertext.len_bits >> 3);
7009
7010                 if (ut_params->obuf)
7011                         digest = rte_pktmbuf_read(ut_params->obuf,
7012                                         (tdata->digest_enc.offset == 0 ?
7013                                                 plaintext_pad_len :
7014                                                 tdata->digest_enc.offset),
7015                                         tdata->digest_enc.len, digest_buffer);
7016                 else
7017                         digest = rte_pktmbuf_read(ut_params->ibuf,
7018                                         (tdata->digest_enc.offset == 0 ?
7019                                                 plaintext_pad_len :
7020                                                 tdata->digest_enc.offset),
7021                                         tdata->digest_enc.len, digest_buffer);
7022
7023                 debug_hexdump(stdout, "digest:", digest,
7024                                 tdata->digest_enc.len);
7025                 debug_hexdump(stdout, "digest expected:",
7026                                 tdata->digest_enc.data, tdata->digest_enc.len);
7027         }
7028
7029         /* Validate obuf */
7030         if (verify) {
7031                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7032                                 plaintext,
7033                                 tdata->plaintext.data,
7034                                 tdata->plaintext.len_bits >> 3,
7035                                 "Plaintext data not as expected");
7036         } else {
7037                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7038                                 ciphertext,
7039                                 tdata->ciphertext.data,
7040                                 tdata->validDataLen.len_bits,
7041                                 "Ciphertext data not as expected");
7042                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7043                                 digest,
7044                                 tdata->digest_enc.data,
7045                                 tdata->digest_enc.len,
7046                                 "Generated auth tag not as expected");
7047         }
7048
7049         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7050                         "crypto op processing failed");
7051
7052         return 0;
7053 }
7054
7055 /** AUTH AES CMAC + CIPHER AES CTR */
7056
7057 static int
7058 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7059 {
7060         return test_mixed_auth_cipher(
7061                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7062 }
7063
7064 static int
7065 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7066 {
7067         return test_mixed_auth_cipher(
7068                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7069 }
7070
7071 static int
7072 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7073 {
7074         return test_mixed_auth_cipher_sgl(
7075                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7076 }
7077
7078 static int
7079 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7080 {
7081         return test_mixed_auth_cipher_sgl(
7082                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7083 }
7084
7085 static int
7086 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7087 {
7088         return test_mixed_auth_cipher(
7089                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7090 }
7091
7092 static int
7093 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7094 {
7095         return test_mixed_auth_cipher(
7096                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7097 }
7098
7099 static int
7100 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7101 {
7102         return test_mixed_auth_cipher_sgl(
7103                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7104 }
7105
7106 static int
7107 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7108 {
7109         return test_mixed_auth_cipher_sgl(
7110                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7111 }
7112
7113 /** MIXED AUTH + CIPHER */
7114
7115 static int
7116 test_auth_zuc_cipher_snow_test_case_1(void)
7117 {
7118         return test_mixed_auth_cipher(
7119                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7120 }
7121
7122 static int
7123 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7124 {
7125         return test_mixed_auth_cipher(
7126                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7127 }
7128
7129 static int
7130 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7131 {
7132         return test_mixed_auth_cipher(
7133                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7134 }
7135
7136 static int
7137 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7138 {
7139         return test_mixed_auth_cipher(
7140                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7141 }
7142
7143 static int
7144 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7145 {
7146         return test_mixed_auth_cipher(
7147                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7148 }
7149
7150 static int
7151 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7152 {
7153         return test_mixed_auth_cipher(
7154                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7155 }
7156
7157 static int
7158 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7159 {
7160         return test_mixed_auth_cipher(
7161                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7162 }
7163
7164 static int
7165 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7166 {
7167         return test_mixed_auth_cipher(
7168                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7169 }
7170
7171 static int
7172 test_auth_snow_cipher_zuc_test_case_1(void)
7173 {
7174         return test_mixed_auth_cipher(
7175                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7176 }
7177
7178 static int
7179 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7180 {
7181         return test_mixed_auth_cipher(
7182                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7183 }
7184
7185 static int
7186 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7187 {
7188         return test_mixed_auth_cipher(
7189                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7190 }
7191
7192 static int
7193 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7194 {
7195         return test_mixed_auth_cipher(
7196                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7197 }
7198
7199 static int
7200 test_auth_null_cipher_snow_test_case_1(void)
7201 {
7202         return test_mixed_auth_cipher(
7203                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7204 }
7205
7206 static int
7207 test_verify_auth_null_cipher_snow_test_case_1(void)
7208 {
7209         return test_mixed_auth_cipher(
7210                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7211 }
7212
7213 static int
7214 test_auth_null_cipher_zuc_test_case_1(void)
7215 {
7216         return test_mixed_auth_cipher(
7217                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7218 }
7219
7220 static int
7221 test_verify_auth_null_cipher_zuc_test_case_1(void)
7222 {
7223         return test_mixed_auth_cipher(
7224                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7225 }
7226
7227 static int
7228 test_auth_snow_cipher_null_test_case_1(void)
7229 {
7230         return test_mixed_auth_cipher(
7231                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7232 }
7233
7234 static int
7235 test_verify_auth_snow_cipher_null_test_case_1(void)
7236 {
7237         return test_mixed_auth_cipher(
7238                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7239 }
7240
7241 static int
7242 test_auth_zuc_cipher_null_test_case_1(void)
7243 {
7244         return test_mixed_auth_cipher(
7245                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7246 }
7247
7248 static int
7249 test_verify_auth_zuc_cipher_null_test_case_1(void)
7250 {
7251         return test_mixed_auth_cipher(
7252                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7253 }
7254
7255 static int
7256 test_auth_null_cipher_aes_ctr_test_case_1(void)
7257 {
7258         return test_mixed_auth_cipher(
7259                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7260 }
7261
7262 static int
7263 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7264 {
7265         return test_mixed_auth_cipher(
7266                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7267 }
7268
7269 static int
7270 test_auth_aes_cmac_cipher_null_test_case_1(void)
7271 {
7272         return test_mixed_auth_cipher(
7273                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7274 }
7275
7276 static int
7277 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7278 {
7279         return test_mixed_auth_cipher(
7280                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7281 }
7282
7283 /* ***** AEAD algorithm Tests ***** */
7284
7285 static int
7286 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7287                 enum rte_crypto_aead_operation op,
7288                 const uint8_t *key, const uint8_t key_len,
7289                 const uint16_t aad_len, const uint8_t auth_len,
7290                 uint8_t iv_len)
7291 {
7292         uint8_t aead_key[key_len];
7293
7294         struct crypto_testsuite_params *ts_params = &testsuite_params;
7295         struct crypto_unittest_params *ut_params = &unittest_params;
7296
7297         memcpy(aead_key, key, key_len);
7298
7299         /* Setup AEAD Parameters */
7300         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7301         ut_params->aead_xform.next = NULL;
7302         ut_params->aead_xform.aead.algo = algo;
7303         ut_params->aead_xform.aead.op = op;
7304         ut_params->aead_xform.aead.key.data = aead_key;
7305         ut_params->aead_xform.aead.key.length = key_len;
7306         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7307         ut_params->aead_xform.aead.iv.length = iv_len;
7308         ut_params->aead_xform.aead.digest_length = auth_len;
7309         ut_params->aead_xform.aead.aad_length = aad_len;
7310
7311         debug_hexdump(stdout, "key:", key, key_len);
7312
7313         /* Create Crypto session*/
7314         ut_params->sess = rte_cryptodev_sym_session_create(
7315                         ts_params->session_mpool);
7316
7317         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7318                         &ut_params->aead_xform,
7319                         ts_params->session_priv_mpool);
7320
7321         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7322
7323         return 0;
7324 }
7325
7326 static int
7327 create_aead_xform(struct rte_crypto_op *op,
7328                 enum rte_crypto_aead_algorithm algo,
7329                 enum rte_crypto_aead_operation aead_op,
7330                 uint8_t *key, const uint8_t key_len,
7331                 const uint8_t aad_len, const uint8_t auth_len,
7332                 uint8_t iv_len)
7333 {
7334         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7335                         "failed to allocate space for crypto transform");
7336
7337         struct rte_crypto_sym_op *sym_op = op->sym;
7338
7339         /* Setup AEAD Parameters */
7340         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7341         sym_op->xform->next = NULL;
7342         sym_op->xform->aead.algo = algo;
7343         sym_op->xform->aead.op = aead_op;
7344         sym_op->xform->aead.key.data = key;
7345         sym_op->xform->aead.key.length = key_len;
7346         sym_op->xform->aead.iv.offset = IV_OFFSET;
7347         sym_op->xform->aead.iv.length = iv_len;
7348         sym_op->xform->aead.digest_length = auth_len;
7349         sym_op->xform->aead.aad_length = aad_len;
7350
7351         debug_hexdump(stdout, "key:", key, key_len);
7352
7353         return 0;
7354 }
7355
7356 static int
7357 create_aead_operation(enum rte_crypto_aead_operation op,
7358                 const struct aead_test_data *tdata)
7359 {
7360         struct crypto_testsuite_params *ts_params = &testsuite_params;
7361         struct crypto_unittest_params *ut_params = &unittest_params;
7362
7363         uint8_t *plaintext, *ciphertext;
7364         unsigned int aad_pad_len, plaintext_pad_len;
7365
7366         /* Generate Crypto op data structure */
7367         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7368                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7369         TEST_ASSERT_NOT_NULL(ut_params->op,
7370                         "Failed to allocate symmetric crypto operation struct");
7371
7372         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7373
7374         /* Append aad data */
7375         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7376                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7377                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7378                                 aad_pad_len);
7379                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7380                                 "no room to append aad");
7381
7382                 sym_op->aead.aad.phys_addr =
7383                                 rte_pktmbuf_iova(ut_params->ibuf);
7384                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
7385                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7386                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7387                         tdata->aad.len);
7388
7389                 /* Append IV at the end of the crypto operation*/
7390                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7391                                 uint8_t *, IV_OFFSET);
7392
7393                 /* Copy IV 1 byte after the IV pointer, according to the API */
7394                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7395                 debug_hexdump(stdout, "iv:", iv_ptr,
7396                         tdata->iv.len);
7397         } else {
7398                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7399                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7400                                 aad_pad_len);
7401                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7402                                 "no room to append aad");
7403
7404                 sym_op->aead.aad.phys_addr =
7405                                 rte_pktmbuf_iova(ut_params->ibuf);
7406                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7407                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7408                         tdata->aad.len);
7409
7410                 /* Append IV at the end of the crypto operation*/
7411                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7412                                 uint8_t *, IV_OFFSET);
7413
7414                 if (tdata->iv.len == 0) {
7415                         rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7416                         debug_hexdump(stdout, "iv:", iv_ptr,
7417                                 AES_GCM_J0_LENGTH);
7418                 } else {
7419                         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7420                         debug_hexdump(stdout, "iv:", iv_ptr,
7421                                 tdata->iv.len);
7422                 }
7423         }
7424
7425         /* Append plaintext/ciphertext */
7426         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7427                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7428                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7429                                 plaintext_pad_len);
7430                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7431
7432                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7433                 debug_hexdump(stdout, "plaintext:", plaintext,
7434                                 tdata->plaintext.len);
7435
7436                 if (ut_params->obuf) {
7437                         ciphertext = (uint8_t *)rte_pktmbuf_append(
7438                                         ut_params->obuf,
7439                                         plaintext_pad_len + aad_pad_len);
7440                         TEST_ASSERT_NOT_NULL(ciphertext,
7441                                         "no room to append ciphertext");
7442
7443                         memset(ciphertext + aad_pad_len, 0,
7444                                         tdata->ciphertext.len);
7445                 }
7446         } else {
7447                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7448                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7449                                 plaintext_pad_len);
7450                 TEST_ASSERT_NOT_NULL(ciphertext,
7451                                 "no room to append ciphertext");
7452
7453                 memcpy(ciphertext, tdata->ciphertext.data,
7454                                 tdata->ciphertext.len);
7455                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7456                                 tdata->ciphertext.len);
7457
7458                 if (ut_params->obuf) {
7459                         plaintext = (uint8_t *)rte_pktmbuf_append(
7460                                         ut_params->obuf,
7461                                         plaintext_pad_len + aad_pad_len);
7462                         TEST_ASSERT_NOT_NULL(plaintext,
7463                                         "no room to append plaintext");
7464
7465                         memset(plaintext + aad_pad_len, 0,
7466                                         tdata->plaintext.len);
7467                 }
7468         }
7469
7470         /* Append digest data */
7471         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7472                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7473                                 ut_params->obuf ? ut_params->obuf :
7474                                                 ut_params->ibuf,
7475                                                 tdata->auth_tag.len);
7476                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7477                                 "no room to append digest");
7478                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
7479                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7480                                 ut_params->obuf ? ut_params->obuf :
7481                                                 ut_params->ibuf,
7482                                                 plaintext_pad_len +
7483                                                 aad_pad_len);
7484         } else {
7485                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7486                                 ut_params->ibuf, tdata->auth_tag.len);
7487                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7488                                 "no room to append digest");
7489                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7490                                 ut_params->ibuf,
7491                                 plaintext_pad_len + aad_pad_len);
7492
7493                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
7494                         tdata->auth_tag.len);
7495                 debug_hexdump(stdout, "digest:",
7496                         sym_op->aead.digest.data,
7497                         tdata->auth_tag.len);
7498         }
7499
7500         sym_op->aead.data.length = tdata->plaintext.len;
7501         sym_op->aead.data.offset = aad_pad_len;
7502
7503         return 0;
7504 }
7505
7506 static int
7507 test_authenticated_encryption(const struct aead_test_data *tdata)
7508 {
7509         struct crypto_testsuite_params *ts_params = &testsuite_params;
7510         struct crypto_unittest_params *ut_params = &unittest_params;
7511
7512         int retval;
7513         uint8_t *ciphertext, *auth_tag;
7514         uint16_t plaintext_pad_len;
7515         uint32_t i;
7516         struct rte_cryptodev_info dev_info;
7517
7518         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7519         uint64_t feat_flags = dev_info.feature_flags;
7520
7521         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
7522                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
7523                 printf("Device doesn't support RAW data-path APIs.\n");
7524                 return -ENOTSUP;
7525         }
7526
7527         /* Verify the capabilities */
7528         struct rte_cryptodev_sym_capability_idx cap_idx;
7529         const struct rte_cryptodev_symmetric_capability *capability;
7530         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7531         cap_idx.algo.aead = tdata->algo;
7532         capability = rte_cryptodev_sym_capability_get(
7533                         ts_params->valid_devs[0], &cap_idx);
7534         if (capability == NULL)
7535                 return -ENOTSUP;
7536         if (rte_cryptodev_sym_capability_check_aead(
7537                         capability, tdata->key.len, tdata->auth_tag.len,
7538                         tdata->aad.len, tdata->iv.len))
7539                 return -ENOTSUP;
7540
7541         /* Create AEAD session */
7542         retval = create_aead_session(ts_params->valid_devs[0],
7543                         tdata->algo,
7544                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
7545                         tdata->key.data, tdata->key.len,
7546                         tdata->aad.len, tdata->auth_tag.len,
7547                         tdata->iv.len);
7548         if (retval < 0)
7549                 return retval;
7550
7551         if (tdata->aad.len > MBUF_SIZE) {
7552                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
7553                 /* Populate full size of add data */
7554                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
7555                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
7556         } else
7557                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7558
7559         /* clear mbuf payload */
7560         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7561                         rte_pktmbuf_tailroom(ut_params->ibuf));
7562
7563         /* Create AEAD operation */
7564         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
7565         if (retval < 0)
7566                 return retval;
7567
7568         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7569
7570         ut_params->op->sym->m_src = ut_params->ibuf;
7571
7572         /* Process crypto operation */
7573         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
7574                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
7575         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7576                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
7577                                 ut_params->op, 0, 0, 0, 0);
7578         else
7579                 TEST_ASSERT_NOT_NULL(
7580                         process_crypto_request(ts_params->valid_devs[0],
7581                         ut_params->op), "failed to process sym crypto op");
7582
7583         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7584                         "crypto op processing failed");
7585
7586         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7587
7588         if (ut_params->op->sym->m_dst) {
7589                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7590                                 uint8_t *);
7591                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
7592                                 uint8_t *, plaintext_pad_len);
7593         } else {
7594                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
7595                                 uint8_t *,
7596                                 ut_params->op->sym->cipher.data.offset);
7597                 auth_tag = ciphertext + plaintext_pad_len;
7598         }
7599
7600         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
7601         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
7602
7603         /* Validate obuf */
7604         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7605                         ciphertext,
7606                         tdata->ciphertext.data,
7607                         tdata->ciphertext.len,
7608                         "Ciphertext data not as expected");
7609
7610         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7611                         auth_tag,
7612                         tdata->auth_tag.data,
7613                         tdata->auth_tag.len,
7614                         "Generated auth tag not as expected");
7615
7616         return 0;
7617
7618 }
7619
7620 #ifdef RTE_LIBRTE_SECURITY
7621 static int
7622 security_proto_supported(enum rte_security_session_action_type action,
7623         enum rte_security_session_protocol proto)
7624 {
7625         struct crypto_testsuite_params *ts_params = &testsuite_params;
7626
7627         const struct rte_security_capability *capabilities;
7628         const struct rte_security_capability *capability;
7629         uint16_t i = 0;
7630
7631         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7632                                 rte_cryptodev_get_sec_ctx(
7633                                 ts_params->valid_devs[0]);
7634
7635
7636         capabilities = rte_security_capabilities_get(ctx);
7637
7638         if (capabilities == NULL)
7639                 return -ENOTSUP;
7640
7641         while ((capability = &capabilities[i++])->action !=
7642                         RTE_SECURITY_ACTION_TYPE_NONE) {
7643                 if (capability->action == action &&
7644                                 capability->protocol == proto)
7645                         return 0;
7646         }
7647
7648         return -ENOTSUP;
7649 }
7650
7651 /* Basic algorithm run function for async inplace mode.
7652  * Creates a session from input parameters and runs one operation
7653  * on input_vec. Checks the output of the crypto operation against
7654  * output_vec.
7655  */
7656 static int
7657 test_pdcp_proto(int i, int oop,
7658         enum rte_crypto_cipher_operation opc,
7659         enum rte_crypto_auth_operation opa,
7660         uint8_t *input_vec,
7661         unsigned int input_vec_len,
7662         uint8_t *output_vec,
7663         unsigned int output_vec_len)
7664 {
7665         struct crypto_testsuite_params *ts_params = &testsuite_params;
7666         struct crypto_unittest_params *ut_params = &unittest_params;
7667         uint8_t *plaintext;
7668         int ret = TEST_SUCCESS;
7669         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7670                                 rte_cryptodev_get_sec_ctx(
7671                                 ts_params->valid_devs[0]);
7672
7673         /* Verify the capabilities */
7674         struct rte_security_capability_idx sec_cap_idx;
7675
7676         sec_cap_idx.action = ut_params->type;
7677         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
7678         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
7679         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
7680                 return -ENOTSUP;
7681
7682         /* Generate test mbuf data */
7683         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7684
7685         /* clear mbuf payload */
7686         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7687                         rte_pktmbuf_tailroom(ut_params->ibuf));
7688
7689         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7690                                                   input_vec_len);
7691         memcpy(plaintext, input_vec, input_vec_len);
7692
7693         /* Out of place support */
7694         if (oop) {
7695                 /*
7696                  * For out-op-place we need to alloc another mbuf
7697                  */
7698                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7699                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
7700         }
7701
7702         /* Setup Cipher Parameters */
7703         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7704         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
7705         ut_params->cipher_xform.cipher.op = opc;
7706         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
7707         ut_params->cipher_xform.cipher.key.length =
7708                                         pdcp_test_params[i].cipher_key_len;
7709         ut_params->cipher_xform.cipher.iv.length =
7710                                 pdcp_test_packet_direction[i] ? 4 : 0;
7711         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
7712
7713         /* Setup HMAC Parameters if ICV header is required */
7714         if (pdcp_test_params[i].auth_alg != 0) {
7715                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7716                 ut_params->auth_xform.next = NULL;
7717                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
7718                 ut_params->auth_xform.auth.op = opa;
7719                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
7720                 ut_params->auth_xform.auth.key.length =
7721                                         pdcp_test_params[i].auth_key_len;
7722
7723                 ut_params->cipher_xform.next = &ut_params->auth_xform;
7724         } else {
7725                 ut_params->cipher_xform.next = NULL;
7726         }
7727
7728         struct rte_security_session_conf sess_conf = {
7729                 .action_type = ut_params->type,
7730                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
7731                 {.pdcp = {
7732                         .bearer = pdcp_test_bearer[i],
7733                         .domain = pdcp_test_params[i].domain,
7734                         .pkt_dir = pdcp_test_packet_direction[i],
7735                         .sn_size = pdcp_test_data_sn_size[i],
7736                         .hfn = pdcp_test_packet_direction[i] ?
7737                                 0 : pdcp_test_hfn[i],
7738                                 /**
7739                                  * hfn can be set as pdcp_test_hfn[i]
7740                                  * if hfn_ovrd is not set. Here, PDCP
7741                                  * packet direction is just used to
7742                                  * run half of the cases with session
7743                                  * HFN and other half with per packet
7744                                  * HFN.
7745                                  */
7746                         .hfn_threshold = pdcp_test_hfn_threshold[i],
7747                         .hfn_ovrd = pdcp_test_packet_direction[i] ? 1 : 0,
7748                 } },
7749                 .crypto_xform = &ut_params->cipher_xform
7750         };
7751
7752         /* Create security session */
7753         ut_params->sec_session = rte_security_session_create(ctx,
7754                                 &sess_conf, ts_params->session_priv_mpool);
7755
7756         if (!ut_params->sec_session) {
7757                 printf("TestCase %s()-%d line %d failed %s: ",
7758                         __func__, i, __LINE__, "Failed to allocate session");
7759                 ret = TEST_FAILED;
7760                 goto on_err;
7761         }
7762
7763         /* Generate crypto op data structure */
7764         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7765                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7766         if (!ut_params->op) {
7767                 printf("TestCase %s()-%d line %d failed %s: ",
7768                         __func__, i, __LINE__,
7769                         "Failed to allocate symmetric crypto operation struct");
7770                 ret = TEST_FAILED;
7771                 goto on_err;
7772         }
7773
7774         uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
7775                                         uint32_t *, IV_OFFSET);
7776         *per_pkt_hfn = pdcp_test_packet_direction[i] ? pdcp_test_hfn[i] : 0;
7777
7778         rte_security_attach_session(ut_params->op, ut_params->sec_session);
7779
7780         /* set crypto operation source mbuf */
7781         ut_params->op->sym->m_src = ut_params->ibuf;
7782         if (oop)
7783                 ut_params->op->sym->m_dst = ut_params->obuf;
7784
7785         /* Process crypto operation */
7786         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
7787                 == NULL) {
7788                 printf("TestCase %s()-%d line %d failed %s: ",
7789                         __func__, i, __LINE__,
7790                         "failed to process sym crypto op");
7791                 ret = TEST_FAILED;
7792                 goto on_err;
7793         }
7794
7795         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
7796                 printf("TestCase %s()-%d line %d failed %s: ",
7797                         __func__, i, __LINE__, "crypto op processing failed");
7798                 ret = TEST_FAILED;
7799                 goto on_err;
7800         }
7801
7802         /* Validate obuf */
7803         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
7804                         uint8_t *);
7805         if (oop) {
7806                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7807                                 uint8_t *);
7808         }
7809
7810         if (memcmp(ciphertext, output_vec, output_vec_len)) {
7811                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
7812                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
7813                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
7814                 ret = TEST_FAILED;
7815                 goto on_err;
7816         }
7817
7818 on_err:
7819         rte_crypto_op_free(ut_params->op);
7820         ut_params->op = NULL;
7821
7822         if (ut_params->sec_session)
7823                 rte_security_session_destroy(ctx, ut_params->sec_session);
7824         ut_params->sec_session = NULL;
7825
7826         rte_pktmbuf_free(ut_params->ibuf);
7827         ut_params->ibuf = NULL;
7828         if (oop) {
7829                 rte_pktmbuf_free(ut_params->obuf);
7830                 ut_params->obuf = NULL;
7831         }
7832
7833         return ret;
7834 }
7835
7836 static int
7837 test_pdcp_proto_SGL(int i, int oop,
7838         enum rte_crypto_cipher_operation opc,
7839         enum rte_crypto_auth_operation opa,
7840         uint8_t *input_vec,
7841         unsigned int input_vec_len,
7842         uint8_t *output_vec,
7843         unsigned int output_vec_len,
7844         uint32_t fragsz,
7845         uint32_t fragsz_oop)
7846 {
7847         struct crypto_testsuite_params *ts_params = &testsuite_params;
7848         struct crypto_unittest_params *ut_params = &unittest_params;
7849         uint8_t *plaintext;
7850         struct rte_mbuf *buf, *buf_oop = NULL;
7851         int ret = TEST_SUCCESS;
7852         int to_trn = 0;
7853         int to_trn_tbl[16];
7854         int segs = 1;
7855         unsigned int trn_data = 0;
7856         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7857                                 rte_cryptodev_get_sec_ctx(
7858                                 ts_params->valid_devs[0]);
7859
7860         /* Verify the capabilities */
7861         struct rte_security_capability_idx sec_cap_idx;
7862
7863         sec_cap_idx.action = ut_params->type;
7864         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
7865         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
7866         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
7867                 return -ENOTSUP;
7868
7869         if (fragsz > input_vec_len)
7870                 fragsz = input_vec_len;
7871
7872         uint16_t plaintext_len = fragsz;
7873         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
7874
7875         if (fragsz_oop > output_vec_len)
7876                 frag_size_oop = output_vec_len;
7877
7878         int ecx = 0;
7879         if (input_vec_len % fragsz != 0) {
7880                 if (input_vec_len / fragsz + 1 > 16)
7881                         return 1;
7882         } else if (input_vec_len / fragsz > 16)
7883                 return 1;
7884
7885         /* Out of place support */
7886         if (oop) {
7887                 /*
7888                  * For out-op-place we need to alloc another mbuf
7889                  */
7890                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7891                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
7892                 buf_oop = ut_params->obuf;
7893         }
7894
7895         /* Generate test mbuf data */
7896         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7897
7898         /* clear mbuf payload */
7899         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7900                         rte_pktmbuf_tailroom(ut_params->ibuf));
7901
7902         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7903                                                   plaintext_len);
7904         memcpy(plaintext, input_vec, plaintext_len);
7905         trn_data += plaintext_len;
7906
7907         buf = ut_params->ibuf;
7908
7909         /*
7910          * Loop until no more fragments
7911          */
7912
7913         while (trn_data < input_vec_len) {
7914                 ++segs;
7915                 to_trn = (input_vec_len - trn_data < fragsz) ?
7916                                 (input_vec_len - trn_data) : fragsz;
7917
7918                 to_trn_tbl[ecx++] = to_trn;
7919
7920                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7921                 buf = buf->next;
7922
7923                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
7924                                 rte_pktmbuf_tailroom(buf));
7925
7926                 /* OOP */
7927                 if (oop && !fragsz_oop) {
7928                         buf_oop->next =
7929                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
7930                         buf_oop = buf_oop->next;
7931                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7932                                         0, rte_pktmbuf_tailroom(buf_oop));
7933                         rte_pktmbuf_append(buf_oop, to_trn);
7934                 }
7935
7936                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
7937                                 to_trn);
7938
7939                 memcpy(plaintext, input_vec + trn_data, to_trn);
7940                 trn_data += to_trn;
7941         }
7942
7943         ut_params->ibuf->nb_segs = segs;
7944
7945         segs = 1;
7946         if (fragsz_oop && oop) {
7947                 to_trn = 0;
7948                 ecx = 0;
7949
7950                 trn_data = frag_size_oop;
7951                 while (trn_data < output_vec_len) {
7952                         ++segs;
7953                         to_trn =
7954                                 (output_vec_len - trn_data <
7955                                                 frag_size_oop) ?
7956                                 (output_vec_len - trn_data) :
7957                                                 frag_size_oop;
7958
7959                         to_trn_tbl[ecx++] = to_trn;
7960
7961                         buf_oop->next =
7962                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
7963                         buf_oop = buf_oop->next;
7964                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7965                                         0, rte_pktmbuf_tailroom(buf_oop));
7966                         rte_pktmbuf_append(buf_oop, to_trn);
7967
7968                         trn_data += to_trn;
7969                 }
7970                 ut_params->obuf->nb_segs = segs;
7971         }
7972
7973         /* Setup Cipher Parameters */
7974         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7975         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
7976         ut_params->cipher_xform.cipher.op = opc;
7977         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
7978         ut_params->cipher_xform.cipher.key.length =
7979                                         pdcp_test_params[i].cipher_key_len;
7980         ut_params->cipher_xform.cipher.iv.length = 0;
7981
7982         /* Setup HMAC Parameters if ICV header is required */
7983         if (pdcp_test_params[i].auth_alg != 0) {
7984                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7985                 ut_params->auth_xform.next = NULL;
7986                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
7987                 ut_params->auth_xform.auth.op = opa;
7988                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
7989                 ut_params->auth_xform.auth.key.length =
7990                                         pdcp_test_params[i].auth_key_len;
7991
7992                 ut_params->cipher_xform.next = &ut_params->auth_xform;
7993         } else {
7994                 ut_params->cipher_xform.next = NULL;
7995         }
7996
7997         struct rte_security_session_conf sess_conf = {
7998                 .action_type = ut_params->type,
7999                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8000                 {.pdcp = {
8001                         .bearer = pdcp_test_bearer[i],
8002                         .domain = pdcp_test_params[i].domain,
8003                         .pkt_dir = pdcp_test_packet_direction[i],
8004                         .sn_size = pdcp_test_data_sn_size[i],
8005                         .hfn = pdcp_test_hfn[i],
8006                         .hfn_threshold = pdcp_test_hfn_threshold[i],
8007                         .hfn_ovrd = 0,
8008                 } },
8009                 .crypto_xform = &ut_params->cipher_xform
8010         };
8011
8012         /* Create security session */
8013         ut_params->sec_session = rte_security_session_create(ctx,
8014                                 &sess_conf, ts_params->session_priv_mpool);
8015
8016         if (!ut_params->sec_session) {
8017                 printf("TestCase %s()-%d line %d failed %s: ",
8018                         __func__, i, __LINE__, "Failed to allocate session");
8019                 ret = TEST_FAILED;
8020                 goto on_err;
8021         }
8022
8023         /* Generate crypto op data structure */
8024         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8025                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8026         if (!ut_params->op) {
8027                 printf("TestCase %s()-%d line %d failed %s: ",
8028                         __func__, i, __LINE__,
8029                         "Failed to allocate symmetric crypto operation struct");
8030                 ret = TEST_FAILED;
8031                 goto on_err;
8032         }
8033
8034         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8035
8036         /* set crypto operation source mbuf */
8037         ut_params->op->sym->m_src = ut_params->ibuf;
8038         if (oop)
8039                 ut_params->op->sym->m_dst = ut_params->obuf;
8040
8041         /* Process crypto operation */
8042         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8043                 == NULL) {
8044                 printf("TestCase %s()-%d line %d failed %s: ",
8045                         __func__, i, __LINE__,
8046                         "failed to process sym crypto op");
8047                 ret = TEST_FAILED;
8048                 goto on_err;
8049         }
8050
8051         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8052                 printf("TestCase %s()-%d line %d failed %s: ",
8053                         __func__, i, __LINE__, "crypto op processing failed");
8054                 ret = TEST_FAILED;
8055                 goto on_err;
8056         }
8057
8058         /* Validate obuf */
8059         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8060                         uint8_t *);
8061         if (oop) {
8062                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8063                                 uint8_t *);
8064         }
8065         if (fragsz_oop)
8066                 fragsz = frag_size_oop;
8067         if (memcmp(ciphertext, output_vec, fragsz)) {
8068                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8069                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8070                 rte_hexdump(stdout, "reference", output_vec, fragsz);
8071                 ret = TEST_FAILED;
8072                 goto on_err;
8073         }
8074
8075         buf = ut_params->op->sym->m_src->next;
8076         if (oop)
8077                 buf = ut_params->op->sym->m_dst->next;
8078
8079         unsigned int off = fragsz;
8080
8081         ecx = 0;
8082         while (buf) {
8083                 ciphertext = rte_pktmbuf_mtod(buf,
8084                                 uint8_t *);
8085                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8086                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8087                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8088                         rte_hexdump(stdout, "reference", output_vec + off,
8089                                         to_trn_tbl[ecx]);
8090                         ret = TEST_FAILED;
8091                         goto on_err;
8092                 }
8093                 off += to_trn_tbl[ecx++];
8094                 buf = buf->next;
8095         }
8096 on_err:
8097         rte_crypto_op_free(ut_params->op);
8098         ut_params->op = NULL;
8099
8100         if (ut_params->sec_session)
8101                 rte_security_session_destroy(ctx, ut_params->sec_session);
8102         ut_params->sec_session = NULL;
8103
8104         rte_pktmbuf_free(ut_params->ibuf);
8105         ut_params->ibuf = NULL;
8106         if (oop) {
8107                 rte_pktmbuf_free(ut_params->obuf);
8108                 ut_params->obuf = NULL;
8109         }
8110
8111         return ret;
8112 }
8113
8114 int
8115 test_pdcp_proto_cplane_encap(int i)
8116 {
8117         return test_pdcp_proto(i, 0,
8118                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8119                 RTE_CRYPTO_AUTH_OP_GENERATE,
8120                 pdcp_test_data_in[i],
8121                 pdcp_test_data_in_len[i],
8122                 pdcp_test_data_out[i],
8123                 pdcp_test_data_in_len[i]+4);
8124 }
8125
8126 int
8127 test_pdcp_proto_uplane_encap(int i)
8128 {
8129         return test_pdcp_proto(i, 0,
8130                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8131                 RTE_CRYPTO_AUTH_OP_GENERATE,
8132                 pdcp_test_data_in[i],
8133                 pdcp_test_data_in_len[i],
8134                 pdcp_test_data_out[i],
8135                 pdcp_test_data_in_len[i]);
8136
8137 }
8138
8139 int
8140 test_pdcp_proto_uplane_encap_with_int(int i)
8141 {
8142         return test_pdcp_proto(i, 0,
8143                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8144                 RTE_CRYPTO_AUTH_OP_GENERATE,
8145                 pdcp_test_data_in[i],
8146                 pdcp_test_data_in_len[i],
8147                 pdcp_test_data_out[i],
8148                 pdcp_test_data_in_len[i] + 4);
8149 }
8150
8151 int
8152 test_pdcp_proto_cplane_decap(int i)
8153 {
8154         return test_pdcp_proto(i, 0,
8155                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
8156                 RTE_CRYPTO_AUTH_OP_VERIFY,
8157                 pdcp_test_data_out[i],
8158                 pdcp_test_data_in_len[i] + 4,
8159                 pdcp_test_data_in[i],
8160                 pdcp_test_data_in_len[i]);
8161 }
8162
8163 int
8164 test_pdcp_proto_uplane_decap(int i)
8165 {
8166         return test_pdcp_proto(i, 0,
8167                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
8168                 RTE_CRYPTO_AUTH_OP_VERIFY,
8169                 pdcp_test_data_out[i],
8170                 pdcp_test_data_in_len[i],
8171                 pdcp_test_data_in[i],
8172                 pdcp_test_data_in_len[i]);
8173 }
8174
8175 int
8176 test_pdcp_proto_uplane_decap_with_int(int i)
8177 {
8178         return test_pdcp_proto(i, 0,
8179                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
8180                 RTE_CRYPTO_AUTH_OP_VERIFY,
8181                 pdcp_test_data_out[i],
8182                 pdcp_test_data_in_len[i] + 4,
8183                 pdcp_test_data_in[i],
8184                 pdcp_test_data_in_len[i]);
8185 }
8186
8187 static int
8188 test_PDCP_PROTO_SGL_in_place_32B(void)
8189 {
8190         /* i can be used for running any PDCP case
8191          * In this case it is uplane 12-bit AES-SNOW DL encap
8192          */
8193         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8194         return test_pdcp_proto_SGL(i, IN_PLACE,
8195                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8196                         RTE_CRYPTO_AUTH_OP_GENERATE,
8197                         pdcp_test_data_in[i],
8198                         pdcp_test_data_in_len[i],
8199                         pdcp_test_data_out[i],
8200                         pdcp_test_data_in_len[i]+4,
8201                         32, 0);
8202 }
8203 static int
8204 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8205 {
8206         /* i can be used for running any PDCP case
8207          * In this case it is uplane 18-bit NULL-NULL DL encap
8208          */
8209         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8210         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8211                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8212                         RTE_CRYPTO_AUTH_OP_GENERATE,
8213                         pdcp_test_data_in[i],
8214                         pdcp_test_data_in_len[i],
8215                         pdcp_test_data_out[i],
8216                         pdcp_test_data_in_len[i]+4,
8217                         32, 128);
8218 }
8219 static int
8220 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8221 {
8222         /* i can be used for running any PDCP case
8223          * In this case it is uplane 18-bit AES DL encap
8224          */
8225         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8226                         + DOWNLINK;
8227         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8228                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8229                         RTE_CRYPTO_AUTH_OP_GENERATE,
8230                         pdcp_test_data_in[i],
8231                         pdcp_test_data_in_len[i],
8232                         pdcp_test_data_out[i],
8233                         pdcp_test_data_in_len[i],
8234                         32, 40);
8235 }
8236 static int
8237 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8238 {
8239         /* i can be used for running any PDCP case
8240          * In this case it is cplane 12-bit AES-ZUC DL encap
8241          */
8242         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8243         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8244                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8245                         RTE_CRYPTO_AUTH_OP_GENERATE,
8246                         pdcp_test_data_in[i],
8247                         pdcp_test_data_in_len[i],
8248                         pdcp_test_data_out[i],
8249                         pdcp_test_data_in_len[i]+4,
8250                         128, 32);
8251 }
8252
8253 static int
8254 test_PDCP_PROTO_all(void)
8255 {
8256         struct crypto_testsuite_params *ts_params = &testsuite_params;
8257         struct crypto_unittest_params *ut_params = &unittest_params;
8258         struct rte_cryptodev_info dev_info;
8259         int status;
8260
8261         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8262         uint64_t feat_flags = dev_info.feature_flags;
8263
8264         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8265                 return -ENOTSUP;
8266
8267         /* Set action type */
8268         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8269                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8270                 gbl_action_type;
8271
8272         if (security_proto_supported(ut_params->type,
8273                         RTE_SECURITY_PROTOCOL_PDCP) < 0)
8274                 return -ENOTSUP;
8275
8276         status = test_PDCP_PROTO_cplane_encap_all();
8277         status += test_PDCP_PROTO_cplane_decap_all();
8278         status += test_PDCP_PROTO_uplane_encap_all();
8279         status += test_PDCP_PROTO_uplane_decap_all();
8280         status += test_PDCP_PROTO_SGL_in_place_32B();
8281         status += test_PDCP_PROTO_SGL_oop_32B_128B();
8282         status += test_PDCP_PROTO_SGL_oop_32B_40B();
8283         status += test_PDCP_PROTO_SGL_oop_128B_32B();
8284
8285         if (status)
8286                 return TEST_FAILED;
8287         else
8288                 return TEST_SUCCESS;
8289 }
8290
8291 static int
8292 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
8293 {
8294         struct crypto_testsuite_params *ts_params = &testsuite_params;
8295         struct crypto_unittest_params *ut_params = &unittest_params;
8296         uint8_t *plaintext, *ciphertext;
8297         uint8_t *iv_ptr;
8298         int32_t cipher_len, crc_len;
8299         uint32_t crc_data_len;
8300         int ret = TEST_SUCCESS;
8301
8302         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8303                                         rte_cryptodev_get_sec_ctx(
8304                                                 ts_params->valid_devs[0]);
8305
8306         /* Verify the capabilities */
8307         struct rte_security_capability_idx sec_cap_idx;
8308         const struct rte_security_capability *sec_cap;
8309         const struct rte_cryptodev_capabilities *crypto_cap;
8310         const struct rte_cryptodev_symmetric_capability *sym_cap;
8311         int j = 0;
8312
8313         sec_cap_idx.action = ut_params->type;
8314         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8315         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
8316
8317         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8318         if (sec_cap == NULL)
8319                 return -ENOTSUP;
8320
8321         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8322                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8323                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8324                                 crypto_cap->sym.xform_type ==
8325                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
8326                                 crypto_cap->sym.cipher.algo ==
8327                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8328                         sym_cap = &crypto_cap->sym;
8329                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8330                                                 d_td->key.len,
8331                                                 d_td->iv.len) == 0)
8332                                 break;
8333                 }
8334         }
8335
8336         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8337                 return -ENOTSUP;
8338
8339         /* Setup source mbuf payload */
8340         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8341         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8342                         rte_pktmbuf_tailroom(ut_params->ibuf));
8343
8344         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8345                         d_td->ciphertext.len);
8346
8347         memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
8348
8349         /* Setup cipher session parameters */
8350         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8351         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8352         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
8353         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8354         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8355         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8356         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8357         ut_params->cipher_xform.next = NULL;
8358
8359         /* Setup DOCSIS session parameters */
8360         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
8361
8362         struct rte_security_session_conf sess_conf = {
8363                 .action_type = ut_params->type,
8364                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8365                 .docsis = ut_params->docsis_xform,
8366                 .crypto_xform = &ut_params->cipher_xform,
8367         };
8368
8369         /* Create security session */
8370         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
8371                                         ts_params->session_priv_mpool);
8372
8373         if (!ut_params->sec_session) {
8374                 printf("TestCase %s(%d) line %d: %s\n",
8375                         __func__, i, __LINE__, "failed to allocate session");
8376                 ret = TEST_FAILED;
8377                 goto on_err;
8378         }
8379
8380         /* Generate crypto op data structure */
8381         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8382                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8383         if (!ut_params->op) {
8384                 printf("TestCase %s(%d) line %d: %s\n",
8385                         __func__, i, __LINE__,
8386                         "failed to allocate symmetric crypto operation");
8387                 ret = TEST_FAILED;
8388                 goto on_err;
8389         }
8390
8391         /* Setup CRC operation parameters */
8392         crc_len = d_td->ciphertext.no_crc == false ?
8393                         (d_td->ciphertext.len -
8394                                 d_td->ciphertext.crc_offset -
8395                                 RTE_ETHER_CRC_LEN) :
8396                         0;
8397         crc_len = crc_len > 0 ? crc_len : 0;
8398         crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
8399         ut_params->op->sym->auth.data.length = crc_len;
8400         ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
8401
8402         /* Setup cipher operation parameters */
8403         cipher_len = d_td->ciphertext.no_cipher == false ?
8404                         (d_td->ciphertext.len -
8405                                 d_td->ciphertext.cipher_offset) :
8406                         0;
8407         cipher_len = cipher_len > 0 ? cipher_len : 0;
8408         ut_params->op->sym->cipher.data.length = cipher_len;
8409         ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
8410
8411         /* Setup cipher IV */
8412         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
8413         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
8414
8415         /* Attach session to operation */
8416         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8417
8418         /* Set crypto operation mbufs */
8419         ut_params->op->sym->m_src = ut_params->ibuf;
8420         ut_params->op->sym->m_dst = NULL;
8421
8422         /* Process crypto operation */
8423         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
8424                         NULL) {
8425                 printf("TestCase %s(%d) line %d: %s\n",
8426                         __func__, i, __LINE__,
8427                         "failed to process security crypto op");
8428                 ret = TEST_FAILED;
8429                 goto on_err;
8430         }
8431
8432         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8433                 printf("TestCase %s(%d) line %d: %s\n",
8434                         __func__, i, __LINE__, "crypto op processing failed");
8435                 ret = TEST_FAILED;
8436                 goto on_err;
8437         }
8438
8439         /* Validate plaintext */
8440         plaintext = ciphertext;
8441
8442         if (memcmp(plaintext, d_td->plaintext.data,
8443                         d_td->plaintext.len - crc_data_len)) {
8444                 printf("TestCase %s(%d) line %d: %s\n",
8445                         __func__, i, __LINE__, "plaintext not as expected\n");
8446                 rte_hexdump(stdout, "expected", d_td->plaintext.data,
8447                                 d_td->plaintext.len);
8448                 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
8449                 ret = TEST_FAILED;
8450                 goto on_err;
8451         }
8452
8453 on_err:
8454         rte_crypto_op_free(ut_params->op);
8455         ut_params->op = NULL;
8456
8457         if (ut_params->sec_session)
8458                 rte_security_session_destroy(ctx, ut_params->sec_session);
8459         ut_params->sec_session = NULL;
8460
8461         rte_pktmbuf_free(ut_params->ibuf);
8462         ut_params->ibuf = NULL;
8463
8464         return ret;
8465 }
8466
8467 static int
8468 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
8469 {
8470         struct crypto_testsuite_params *ts_params = &testsuite_params;
8471         struct crypto_unittest_params *ut_params = &unittest_params;
8472         uint8_t *plaintext, *ciphertext;
8473         uint8_t *iv_ptr;
8474         int32_t cipher_len, crc_len;
8475         int ret = TEST_SUCCESS;
8476
8477         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8478                                         rte_cryptodev_get_sec_ctx(
8479                                                 ts_params->valid_devs[0]);
8480
8481         /* Verify the capabilities */
8482         struct rte_security_capability_idx sec_cap_idx;
8483         const struct rte_security_capability *sec_cap;
8484         const struct rte_cryptodev_capabilities *crypto_cap;
8485         const struct rte_cryptodev_symmetric_capability *sym_cap;
8486         int j = 0;
8487
8488         sec_cap_idx.action = ut_params->type;
8489         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8490         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
8491
8492         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8493         if (sec_cap == NULL)
8494                 return -ENOTSUP;
8495
8496         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8497                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8498                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8499                                 crypto_cap->sym.xform_type ==
8500                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
8501                                 crypto_cap->sym.cipher.algo ==
8502                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8503                         sym_cap = &crypto_cap->sym;
8504                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8505                                                 d_td->key.len,
8506                                                 d_td->iv.len) == 0)
8507                                 break;
8508                 }
8509         }
8510
8511         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8512                 return -ENOTSUP;
8513
8514         /* Setup source mbuf payload */
8515         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8516         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8517                         rte_pktmbuf_tailroom(ut_params->ibuf));
8518
8519         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8520                         d_td->plaintext.len);
8521
8522         memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
8523
8524         /* Setup cipher session parameters */
8525         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8526         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8527         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
8528         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8529         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8530         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8531         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8532         ut_params->cipher_xform.next = NULL;
8533
8534         /* Setup DOCSIS session parameters */
8535         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
8536
8537         struct rte_security_session_conf sess_conf = {
8538                 .action_type = ut_params->type,
8539                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8540                 .docsis = ut_params->docsis_xform,
8541                 .crypto_xform = &ut_params->cipher_xform,
8542         };
8543
8544         /* Create security session */
8545         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
8546                                         ts_params->session_priv_mpool);
8547
8548         if (!ut_params->sec_session) {
8549                 printf("TestCase %s(%d) line %d: %s\n",
8550                         __func__, i, __LINE__, "failed to allocate session");
8551                 ret = TEST_FAILED;
8552                 goto on_err;
8553         }
8554
8555         /* Generate crypto op data structure */
8556         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8557                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8558         if (!ut_params->op) {
8559                 printf("TestCase %s(%d) line %d: %s\n",
8560                         __func__, i, __LINE__,
8561                         "failed to allocate security crypto operation");
8562                 ret = TEST_FAILED;
8563                 goto on_err;
8564         }
8565
8566         /* Setup CRC operation parameters */
8567         crc_len = d_td->plaintext.no_crc == false ?
8568                         (d_td->plaintext.len -
8569                                 d_td->plaintext.crc_offset -
8570                                 RTE_ETHER_CRC_LEN) :
8571                         0;
8572         crc_len = crc_len > 0 ? crc_len : 0;
8573         ut_params->op->sym->auth.data.length = crc_len;
8574         ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
8575
8576         /* Setup cipher operation parameters */
8577         cipher_len = d_td->plaintext.no_cipher == false ?
8578                         (d_td->plaintext.len -
8579                                 d_td->plaintext.cipher_offset) :
8580                         0;
8581         cipher_len = cipher_len > 0 ? cipher_len : 0;
8582         ut_params->op->sym->cipher.data.length = cipher_len;
8583         ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
8584
8585         /* Setup cipher IV */
8586         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
8587         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
8588
8589         /* Attach session to operation */
8590         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8591
8592         /* Set crypto operation mbufs */
8593         ut_params->op->sym->m_src = ut_params->ibuf;
8594         ut_params->op->sym->m_dst = NULL;
8595
8596         /* Process crypto operation */
8597         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
8598                         NULL) {
8599                 printf("TestCase %s(%d) line %d: %s\n",
8600                         __func__, i, __LINE__,
8601                         "failed to process security crypto op");
8602                 ret = TEST_FAILED;
8603                 goto on_err;
8604         }
8605
8606         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8607                 printf("TestCase %s(%d) line %d: %s\n",
8608                         __func__, i, __LINE__, "crypto op processing failed");
8609                 ret = TEST_FAILED;
8610                 goto on_err;
8611         }
8612
8613         /* Validate ciphertext */
8614         ciphertext = plaintext;
8615
8616         if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
8617                 printf("TestCase %s(%d) line %d: %s\n",
8618                         __func__, i, __LINE__, "ciphertext not as expected\n");
8619                 rte_hexdump(stdout, "expected", d_td->ciphertext.data,
8620                                 d_td->ciphertext.len);
8621                 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
8622                 ret = TEST_FAILED;
8623                 goto on_err;
8624         }
8625
8626 on_err:
8627         rte_crypto_op_free(ut_params->op);
8628         ut_params->op = NULL;
8629
8630         if (ut_params->sec_session)
8631                 rte_security_session_destroy(ctx, ut_params->sec_session);
8632         ut_params->sec_session = NULL;
8633
8634         rte_pktmbuf_free(ut_params->ibuf);
8635         ut_params->ibuf = NULL;
8636
8637         return ret;
8638 }
8639
8640 #define TEST_DOCSIS_COUNT(func) do {                    \
8641         int ret = func;                                 \
8642         if (ret == TEST_SUCCESS)  {                     \
8643                 printf("\t%2d)", n++);                  \
8644                 printf("+++++ PASSED:" #func"\n");      \
8645                 p++;                                    \
8646         } else if (ret == -ENOTSUP) {                   \
8647                 printf("\t%2d)", n++);                  \
8648                 printf("~~~~~ UNSUPP:" #func"\n");      \
8649                 u++;                                    \
8650         } else {                                        \
8651                 printf("\t%2d)", n++);                  \
8652                 printf("----- FAILED:" #func"\n");      \
8653                 f++;                                    \
8654         }                                               \
8655 } while (0)
8656
8657 static int
8658 test_DOCSIS_PROTO_uplink_all(void)
8659 {
8660         int p = 0, u = 0, f = 0, n = 0;
8661
8662         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
8663         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
8664         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
8665         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
8666         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
8667         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
8668         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
8669         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
8670         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
8671         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
8672         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
8673         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
8674         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
8675         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
8676         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
8677         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
8678         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
8679         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
8680         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
8681         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
8682         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
8683         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
8684         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
8685         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
8686         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
8687         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
8688
8689         if (f)
8690                 printf("## %s: %d passed out of %d (%d unsupported)\n",
8691                         __func__, p, n, u);
8692
8693         return f;
8694 };
8695
8696 static int
8697 test_DOCSIS_PROTO_downlink_all(void)
8698 {
8699         int p = 0, u = 0, f = 0, n = 0;
8700
8701         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
8702         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
8703         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
8704         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
8705         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
8706         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
8707         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
8708         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
8709         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
8710         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
8711         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
8712         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
8713         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
8714         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
8715         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
8716         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
8717         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
8718         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
8719         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
8720         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
8721         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
8722         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
8723         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
8724         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
8725         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
8726         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
8727
8728         if (f)
8729                 printf("## %s: %d passed out of %d (%d unsupported)\n",
8730                         __func__, p, n, u);
8731
8732         return f;
8733 };
8734
8735 static int
8736 test_DOCSIS_PROTO_all(void)
8737 {
8738         struct crypto_testsuite_params *ts_params = &testsuite_params;
8739         struct crypto_unittest_params *ut_params = &unittest_params;
8740         struct rte_cryptodev_info dev_info;
8741         int status;
8742
8743         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8744         uint64_t feat_flags = dev_info.feature_flags;
8745
8746         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8747                 return -ENOTSUP;
8748
8749         /* Set action type */
8750         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8751                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8752                 gbl_action_type;
8753
8754         if (security_proto_supported(ut_params->type,
8755                         RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
8756                 return -ENOTSUP;
8757
8758         status = test_DOCSIS_PROTO_uplink_all();
8759         status += test_DOCSIS_PROTO_downlink_all();
8760
8761         if (status)
8762                 return TEST_FAILED;
8763         else
8764                 return TEST_SUCCESS;
8765 }
8766 #endif
8767
8768 static int
8769 test_AES_GCM_authenticated_encryption_test_case_1(void)
8770 {
8771         return test_authenticated_encryption(&gcm_test_case_1);
8772 }
8773
8774 static int
8775 test_AES_GCM_authenticated_encryption_test_case_2(void)
8776 {
8777         return test_authenticated_encryption(&gcm_test_case_2);
8778 }
8779
8780 static int
8781 test_AES_GCM_authenticated_encryption_test_case_3(void)
8782 {
8783         return test_authenticated_encryption(&gcm_test_case_3);
8784 }
8785
8786 static int
8787 test_AES_GCM_authenticated_encryption_test_case_4(void)
8788 {
8789         return test_authenticated_encryption(&gcm_test_case_4);
8790 }
8791
8792 static int
8793 test_AES_GCM_authenticated_encryption_test_case_5(void)
8794 {
8795         return test_authenticated_encryption(&gcm_test_case_5);
8796 }
8797
8798 static int
8799 test_AES_GCM_authenticated_encryption_test_case_6(void)
8800 {
8801         return test_authenticated_encryption(&gcm_test_case_6);
8802 }
8803
8804 static int
8805 test_AES_GCM_authenticated_encryption_test_case_7(void)
8806 {
8807         return test_authenticated_encryption(&gcm_test_case_7);
8808 }
8809
8810 static int
8811 test_AES_GCM_authenticated_encryption_test_case_8(void)
8812 {
8813         return test_authenticated_encryption(&gcm_test_case_8);
8814 }
8815
8816 static int
8817 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
8818 {
8819         return test_authenticated_encryption(&gcm_J0_test_case_1);
8820 }
8821
8822 static int
8823 test_AES_GCM_auth_encryption_test_case_192_1(void)
8824 {
8825         return test_authenticated_encryption(&gcm_test_case_192_1);
8826 }
8827
8828 static int
8829 test_AES_GCM_auth_encryption_test_case_192_2(void)
8830 {
8831         return test_authenticated_encryption(&gcm_test_case_192_2);
8832 }
8833
8834 static int
8835 test_AES_GCM_auth_encryption_test_case_192_3(void)
8836 {
8837         return test_authenticated_encryption(&gcm_test_case_192_3);
8838 }
8839
8840 static int
8841 test_AES_GCM_auth_encryption_test_case_192_4(void)
8842 {
8843         return test_authenticated_encryption(&gcm_test_case_192_4);
8844 }
8845
8846 static int
8847 test_AES_GCM_auth_encryption_test_case_192_5(void)
8848 {
8849         return test_authenticated_encryption(&gcm_test_case_192_5);
8850 }
8851
8852 static int
8853 test_AES_GCM_auth_encryption_test_case_192_6(void)
8854 {
8855         return test_authenticated_encryption(&gcm_test_case_192_6);
8856 }
8857
8858 static int
8859 test_AES_GCM_auth_encryption_test_case_192_7(void)
8860 {
8861         return test_authenticated_encryption(&gcm_test_case_192_7);
8862 }
8863
8864 static int
8865 test_AES_GCM_auth_encryption_test_case_256_1(void)
8866 {
8867         return test_authenticated_encryption(&gcm_test_case_256_1);
8868 }
8869
8870 static int
8871 test_AES_GCM_auth_encryption_test_case_256_2(void)
8872 {
8873         return test_authenticated_encryption(&gcm_test_case_256_2);
8874 }
8875
8876 static int
8877 test_AES_GCM_auth_encryption_test_case_256_3(void)
8878 {
8879         return test_authenticated_encryption(&gcm_test_case_256_3);
8880 }
8881
8882 static int
8883 test_AES_GCM_auth_encryption_test_case_256_4(void)
8884 {
8885         return test_authenticated_encryption(&gcm_test_case_256_4);
8886 }
8887
8888 static int
8889 test_AES_GCM_auth_encryption_test_case_256_5(void)
8890 {
8891         return test_authenticated_encryption(&gcm_test_case_256_5);
8892 }
8893
8894 static int
8895 test_AES_GCM_auth_encryption_test_case_256_6(void)
8896 {
8897         return test_authenticated_encryption(&gcm_test_case_256_6);
8898 }
8899
8900 static int
8901 test_AES_GCM_auth_encryption_test_case_256_7(void)
8902 {
8903         return test_authenticated_encryption(&gcm_test_case_256_7);
8904 }
8905
8906 static int
8907 test_AES_GCM_auth_encryption_test_case_aad_1(void)
8908 {
8909         return test_authenticated_encryption(&gcm_test_case_aad_1);
8910 }
8911
8912 static int
8913 test_AES_GCM_auth_encryption_test_case_aad_2(void)
8914 {
8915         return test_authenticated_encryption(&gcm_test_case_aad_2);
8916 }
8917
8918 static int
8919 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
8920 {
8921         struct aead_test_data tdata;
8922         int res;
8923
8924         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
8925         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8926         tdata.iv.data[0] += 1;
8927         res = test_authenticated_encryption(&tdata);
8928         if (res == -ENOTSUP)
8929                 return res;
8930         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
8931         return TEST_SUCCESS;
8932 }
8933
8934 static int
8935 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
8936 {
8937         struct aead_test_data tdata;
8938         int res;
8939
8940         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
8941         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8942         tdata.plaintext.data[0] += 1;
8943         res = test_authenticated_encryption(&tdata);
8944         if (res == -ENOTSUP)
8945                 return res;
8946         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
8947         return TEST_SUCCESS;
8948 }
8949
8950 static int
8951 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
8952 {
8953         struct aead_test_data tdata;
8954         int res;
8955
8956         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
8957         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8958         tdata.ciphertext.data[0] += 1;
8959         res = test_authenticated_encryption(&tdata);
8960         if (res == -ENOTSUP)
8961                 return res;
8962         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
8963         return TEST_SUCCESS;
8964 }
8965
8966 static int
8967 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
8968 {
8969         struct aead_test_data tdata;
8970         int res;
8971
8972         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
8973         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8974         tdata.aad.len += 1;
8975         res = test_authenticated_encryption(&tdata);
8976         if (res == -ENOTSUP)
8977                 return res;
8978         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
8979         return TEST_SUCCESS;
8980 }
8981
8982 static int
8983 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
8984 {
8985         struct aead_test_data tdata;
8986         uint8_t aad[gcm_test_case_7.aad.len];
8987         int res;
8988
8989         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
8990         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
8991         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
8992         aad[0] += 1;
8993         tdata.aad.data = aad;
8994         res = test_authenticated_encryption(&tdata);
8995         if (res == -ENOTSUP)
8996                 return res;
8997         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
8998         return TEST_SUCCESS;
8999 }
9000
9001 static int
9002 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
9003 {
9004         struct aead_test_data tdata;
9005         int res;
9006
9007         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9008         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9009         tdata.auth_tag.data[0] += 1;
9010         res = test_authenticated_encryption(&tdata);
9011         if (res == -ENOTSUP)
9012                 return res;
9013         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9014         return TEST_SUCCESS;
9015 }
9016
9017 static int
9018 test_authenticated_decryption(const struct aead_test_data *tdata)
9019 {
9020         struct crypto_testsuite_params *ts_params = &testsuite_params;
9021         struct crypto_unittest_params *ut_params = &unittest_params;
9022
9023         int retval;
9024         uint8_t *plaintext;
9025         uint32_t i;
9026         struct rte_cryptodev_info dev_info;
9027
9028         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9029         uint64_t feat_flags = dev_info.feature_flags;
9030
9031         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9032                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9033                 printf("Device doesn't support RAW data-path APIs.\n");
9034                 return -ENOTSUP;
9035         }
9036
9037         /* Verify the capabilities */
9038         struct rte_cryptodev_sym_capability_idx cap_idx;
9039         const struct rte_cryptodev_symmetric_capability *capability;
9040         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9041         cap_idx.algo.aead = tdata->algo;
9042         capability = rte_cryptodev_sym_capability_get(
9043                         ts_params->valid_devs[0], &cap_idx);
9044         if (capability == NULL)
9045                 return -ENOTSUP;
9046         if (rte_cryptodev_sym_capability_check_aead(
9047                         capability, tdata->key.len, tdata->auth_tag.len,
9048                         tdata->aad.len, tdata->iv.len))
9049                 return -ENOTSUP;
9050
9051         /* Create AEAD session */
9052         retval = create_aead_session(ts_params->valid_devs[0],
9053                         tdata->algo,
9054                         RTE_CRYPTO_AEAD_OP_DECRYPT,
9055                         tdata->key.data, tdata->key.len,
9056                         tdata->aad.len, tdata->auth_tag.len,
9057                         tdata->iv.len);
9058         if (retval < 0)
9059                 return retval;
9060
9061         /* alloc mbuf and set payload */
9062         if (tdata->aad.len > MBUF_SIZE) {
9063                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9064                 /* Populate full size of add data */
9065                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
9066                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
9067         } else
9068                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9069
9070         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9071                         rte_pktmbuf_tailroom(ut_params->ibuf));
9072
9073         /* Create AEAD operation */
9074         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9075         if (retval < 0)
9076                 return retval;
9077
9078         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9079
9080         ut_params->op->sym->m_src = ut_params->ibuf;
9081
9082         /* Process crypto operation */
9083         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9084                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
9085         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9086                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9087                                 ut_params->op, 0, 0, 0, 0);
9088         else
9089                 TEST_ASSERT_NOT_NULL(
9090                         process_crypto_request(ts_params->valid_devs[0],
9091                         ut_params->op), "failed to process sym crypto op");
9092
9093         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9094                         "crypto op processing failed");
9095
9096         if (ut_params->op->sym->m_dst)
9097                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9098                                 uint8_t *);
9099         else
9100                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
9101                                 uint8_t *,
9102                                 ut_params->op->sym->cipher.data.offset);
9103
9104         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9105
9106         /* Validate obuf */
9107         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9108                         plaintext,
9109                         tdata->plaintext.data,
9110                         tdata->plaintext.len,
9111                         "Plaintext data not as expected");
9112
9113         TEST_ASSERT_EQUAL(ut_params->op->status,
9114                         RTE_CRYPTO_OP_STATUS_SUCCESS,
9115                         "Authentication failed");
9116
9117         return 0;
9118 }
9119
9120 static int
9121 test_AES_GCM_authenticated_decryption_test_case_1(void)
9122 {
9123         return test_authenticated_decryption(&gcm_test_case_1);
9124 }
9125
9126 static int
9127 test_AES_GCM_authenticated_decryption_test_case_2(void)
9128 {
9129         return test_authenticated_decryption(&gcm_test_case_2);
9130 }
9131
9132 static int
9133 test_AES_GCM_authenticated_decryption_test_case_3(void)
9134 {
9135         return test_authenticated_decryption(&gcm_test_case_3);
9136 }
9137
9138 static int
9139 test_AES_GCM_authenticated_decryption_test_case_4(void)
9140 {
9141         return test_authenticated_decryption(&gcm_test_case_4);
9142 }
9143
9144 static int
9145 test_AES_GCM_authenticated_decryption_test_case_5(void)
9146 {
9147         return test_authenticated_decryption(&gcm_test_case_5);
9148 }
9149
9150 static int
9151 test_AES_GCM_authenticated_decryption_test_case_6(void)
9152 {
9153         return test_authenticated_decryption(&gcm_test_case_6);
9154 }
9155
9156 static int
9157 test_AES_GCM_authenticated_decryption_test_case_7(void)
9158 {
9159         return test_authenticated_decryption(&gcm_test_case_7);
9160 }
9161
9162 static int
9163 test_AES_GCM_authenticated_decryption_test_case_8(void)
9164 {
9165         return test_authenticated_decryption(&gcm_test_case_8);
9166 }
9167
9168 static int
9169 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
9170 {
9171         return test_authenticated_decryption(&gcm_J0_test_case_1);
9172 }
9173
9174 static int
9175 test_AES_GCM_auth_decryption_test_case_192_1(void)
9176 {
9177         return test_authenticated_decryption(&gcm_test_case_192_1);
9178 }
9179
9180 static int
9181 test_AES_GCM_auth_decryption_test_case_192_2(void)
9182 {
9183         return test_authenticated_decryption(&gcm_test_case_192_2);
9184 }
9185
9186 static int
9187 test_AES_GCM_auth_decryption_test_case_192_3(void)
9188 {
9189         return test_authenticated_decryption(&gcm_test_case_192_3);
9190 }
9191
9192 static int
9193 test_AES_GCM_auth_decryption_test_case_192_4(void)
9194 {
9195         return test_authenticated_decryption(&gcm_test_case_192_4);
9196 }
9197
9198 static int
9199 test_AES_GCM_auth_decryption_test_case_192_5(void)
9200 {
9201         return test_authenticated_decryption(&gcm_test_case_192_5);
9202 }
9203
9204 static int
9205 test_AES_GCM_auth_decryption_test_case_192_6(void)
9206 {
9207         return test_authenticated_decryption(&gcm_test_case_192_6);
9208 }
9209
9210 static int
9211 test_AES_GCM_auth_decryption_test_case_192_7(void)
9212 {
9213         return test_authenticated_decryption(&gcm_test_case_192_7);
9214 }
9215
9216 static int
9217 test_AES_GCM_auth_decryption_test_case_256_1(void)
9218 {
9219         return test_authenticated_decryption(&gcm_test_case_256_1);
9220 }
9221
9222 static int
9223 test_AES_GCM_auth_decryption_test_case_256_2(void)
9224 {
9225         return test_authenticated_decryption(&gcm_test_case_256_2);
9226 }
9227
9228 static int
9229 test_AES_GCM_auth_decryption_test_case_256_3(void)
9230 {
9231         return test_authenticated_decryption(&gcm_test_case_256_3);
9232 }
9233
9234 static int
9235 test_AES_GCM_auth_decryption_test_case_256_4(void)
9236 {
9237         return test_authenticated_decryption(&gcm_test_case_256_4);
9238 }
9239
9240 static int
9241 test_AES_GCM_auth_decryption_test_case_256_5(void)
9242 {
9243         return test_authenticated_decryption(&gcm_test_case_256_5);
9244 }
9245
9246 static int
9247 test_AES_GCM_auth_decryption_test_case_256_6(void)
9248 {
9249         return test_authenticated_decryption(&gcm_test_case_256_6);
9250 }
9251
9252 static int
9253 test_AES_GCM_auth_decryption_test_case_256_7(void)
9254 {
9255         return test_authenticated_decryption(&gcm_test_case_256_7);
9256 }
9257
9258 static int
9259 test_AES_GCM_auth_decryption_test_case_aad_1(void)
9260 {
9261         return test_authenticated_decryption(&gcm_test_case_aad_1);
9262 }
9263
9264 static int
9265 test_AES_GCM_auth_decryption_test_case_aad_2(void)
9266 {
9267         return test_authenticated_decryption(&gcm_test_case_aad_2);
9268 }
9269
9270 static int
9271 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
9272 {
9273         struct aead_test_data tdata;
9274         int res;
9275
9276         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9277         tdata.iv.data[0] += 1;
9278         res = test_authenticated_decryption(&tdata);
9279         if (res == -ENOTSUP)
9280                 return res;
9281         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9282         return TEST_SUCCESS;
9283 }
9284
9285 static int
9286 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
9287 {
9288         struct aead_test_data tdata;
9289         int res;
9290
9291         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9292         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9293         tdata.plaintext.data[0] += 1;
9294         res = test_authenticated_decryption(&tdata);
9295         if (res == -ENOTSUP)
9296                 return res;
9297         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9298         return TEST_SUCCESS;
9299 }
9300
9301 static int
9302 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
9303 {
9304         struct aead_test_data tdata;
9305         int res;
9306
9307         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9308         tdata.ciphertext.data[0] += 1;
9309         res = test_authenticated_decryption(&tdata);
9310         if (res == -ENOTSUP)
9311                 return res;
9312         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9313         return TEST_SUCCESS;
9314 }
9315
9316 static int
9317 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
9318 {
9319         struct aead_test_data tdata;
9320         int res;
9321
9322         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9323         tdata.aad.len += 1;
9324         res = test_authenticated_decryption(&tdata);
9325         if (res == -ENOTSUP)
9326                 return res;
9327         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9328         return TEST_SUCCESS;
9329 }
9330
9331 static int
9332 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
9333 {
9334         struct aead_test_data tdata;
9335         uint8_t aad[gcm_test_case_7.aad.len];
9336         int res;
9337
9338         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9339         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9340         aad[0] += 1;
9341         tdata.aad.data = aad;
9342         res = test_authenticated_decryption(&tdata);
9343         if (res == -ENOTSUP)
9344                 return res;
9345         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9346         return TEST_SUCCESS;
9347 }
9348
9349 static int
9350 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
9351 {
9352         struct aead_test_data tdata;
9353         int res;
9354
9355         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9356         tdata.auth_tag.data[0] += 1;
9357         res = test_authenticated_decryption(&tdata);
9358         if (res == -ENOTSUP)
9359                 return res;
9360         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
9361         return TEST_SUCCESS;
9362 }
9363
9364 static int
9365 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
9366 {
9367         struct crypto_testsuite_params *ts_params = &testsuite_params;
9368         struct crypto_unittest_params *ut_params = &unittest_params;
9369
9370         int retval;
9371         uint8_t *ciphertext, *auth_tag;
9372         uint16_t plaintext_pad_len;
9373
9374         /* Verify the capabilities */
9375         struct rte_cryptodev_sym_capability_idx cap_idx;
9376         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9377         cap_idx.algo.aead = tdata->algo;
9378         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9379                         &cap_idx) == NULL)
9380                 return -ENOTSUP;
9381
9382         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9383                 return -ENOTSUP;
9384
9385         /* not supported with CPU crypto */
9386         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9387                 return -ENOTSUP;
9388
9389         /* Create AEAD session */
9390         retval = create_aead_session(ts_params->valid_devs[0],
9391                         tdata->algo,
9392                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
9393                         tdata->key.data, tdata->key.len,
9394                         tdata->aad.len, tdata->auth_tag.len,
9395                         tdata->iv.len);
9396         if (retval < 0)
9397                 return retval;
9398
9399         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9400         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9401
9402         /* clear mbuf payload */
9403         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9404                         rte_pktmbuf_tailroom(ut_params->ibuf));
9405         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
9406                         rte_pktmbuf_tailroom(ut_params->obuf));
9407
9408         /* Create AEAD operation */
9409         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
9410         if (retval < 0)
9411                 return retval;
9412
9413         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9414
9415         ut_params->op->sym->m_src = ut_params->ibuf;
9416         ut_params->op->sym->m_dst = ut_params->obuf;
9417
9418         /* Process crypto operation */
9419         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9420                         ut_params->op), "failed to process sym crypto op");
9421
9422         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9423                         "crypto op processing failed");
9424
9425         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9426
9427         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
9428                         ut_params->op->sym->cipher.data.offset);
9429         auth_tag = ciphertext + plaintext_pad_len;
9430
9431         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
9432         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
9433
9434         /* Validate obuf */
9435         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9436                         ciphertext,
9437                         tdata->ciphertext.data,
9438                         tdata->ciphertext.len,
9439                         "Ciphertext data not as expected");
9440
9441         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9442                         auth_tag,
9443                         tdata->auth_tag.data,
9444                         tdata->auth_tag.len,
9445                         "Generated auth tag not as expected");
9446
9447         return 0;
9448
9449 }
9450
9451 static int
9452 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
9453 {
9454         return test_authenticated_encryption_oop(&gcm_test_case_5);
9455 }
9456
9457 static int
9458 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
9459 {
9460         struct crypto_testsuite_params *ts_params = &testsuite_params;
9461         struct crypto_unittest_params *ut_params = &unittest_params;
9462
9463         int retval;
9464         uint8_t *plaintext;
9465
9466         /* Verify the capabilities */
9467         struct rte_cryptodev_sym_capability_idx cap_idx;
9468         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9469         cap_idx.algo.aead = tdata->algo;
9470         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9471                         &cap_idx) == NULL)
9472                 return -ENOTSUP;
9473
9474         /* not supported with CPU crypto and raw data-path APIs*/
9475         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
9476                         global_api_test_type == CRYPTODEV_RAW_API_TEST)
9477                 return -ENOTSUP;
9478
9479         /* Create AEAD session */
9480         retval = create_aead_session(ts_params->valid_devs[0],
9481                         tdata->algo,
9482                         RTE_CRYPTO_AEAD_OP_DECRYPT,
9483                         tdata->key.data, tdata->key.len,
9484                         tdata->aad.len, tdata->auth_tag.len,
9485                         tdata->iv.len);
9486         if (retval < 0)
9487                 return retval;
9488
9489         /* alloc mbuf and set payload */
9490         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9491         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9492
9493         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9494                         rte_pktmbuf_tailroom(ut_params->ibuf));
9495         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
9496                         rte_pktmbuf_tailroom(ut_params->obuf));
9497
9498         /* Create AEAD operation */
9499         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9500         if (retval < 0)
9501                 return retval;
9502
9503         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9504
9505         ut_params->op->sym->m_src = ut_params->ibuf;
9506         ut_params->op->sym->m_dst = ut_params->obuf;
9507
9508         /* Process crypto operation */
9509         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9510                         ut_params->op), "failed to process sym crypto op");
9511
9512         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9513                         "crypto op processing failed");
9514
9515         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
9516                         ut_params->op->sym->cipher.data.offset);
9517
9518         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9519
9520         /* Validate obuf */
9521         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9522                         plaintext,
9523                         tdata->plaintext.data,
9524                         tdata->plaintext.len,
9525                         "Plaintext data not as expected");
9526
9527         TEST_ASSERT_EQUAL(ut_params->op->status,
9528                         RTE_CRYPTO_OP_STATUS_SUCCESS,
9529                         "Authentication failed");
9530         return 0;
9531 }
9532
9533 static int
9534 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
9535 {
9536         return test_authenticated_decryption_oop(&gcm_test_case_5);
9537 }
9538
9539 static int
9540 test_authenticated_encryption_sessionless(
9541                 const struct aead_test_data *tdata)
9542 {
9543         struct crypto_testsuite_params *ts_params = &testsuite_params;
9544         struct crypto_unittest_params *ut_params = &unittest_params;
9545
9546         int retval;
9547         uint8_t *ciphertext, *auth_tag;
9548         uint16_t plaintext_pad_len;
9549         uint8_t key[tdata->key.len + 1];
9550         struct rte_cryptodev_info dev_info;
9551
9552         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9553         uint64_t feat_flags = dev_info.feature_flags;
9554
9555         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
9556                 printf("Device doesn't support Sessionless ops.\n");
9557                 return -ENOTSUP;
9558         }
9559
9560         /* not supported with CPU crypto */
9561         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9562                 return -ENOTSUP;
9563
9564         /* Verify the capabilities */
9565         struct rte_cryptodev_sym_capability_idx cap_idx;
9566         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9567         cap_idx.algo.aead = tdata->algo;
9568         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9569                         &cap_idx) == NULL)
9570                 return -ENOTSUP;
9571
9572         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9573
9574         /* clear mbuf payload */
9575         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9576                         rte_pktmbuf_tailroom(ut_params->ibuf));
9577
9578         /* Create AEAD operation */
9579         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
9580         if (retval < 0)
9581                 return retval;
9582
9583         /* Create GCM xform */
9584         memcpy(key, tdata->key.data, tdata->key.len);
9585         retval = create_aead_xform(ut_params->op,
9586                         tdata->algo,
9587                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
9588                         key, tdata->key.len,
9589                         tdata->aad.len, tdata->auth_tag.len,
9590                         tdata->iv.len);
9591         if (retval < 0)
9592                 return retval;
9593
9594         ut_params->op->sym->m_src = ut_params->ibuf;
9595
9596         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
9597                         RTE_CRYPTO_OP_SESSIONLESS,
9598                         "crypto op session type not sessionless");
9599
9600         /* Process crypto operation */
9601         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9602                         ut_params->op), "failed to process sym crypto op");
9603
9604         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
9605
9606         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9607                         "crypto op status not success");
9608
9609         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9610
9611         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9612                         ut_params->op->sym->cipher.data.offset);
9613         auth_tag = ciphertext + plaintext_pad_len;
9614
9615         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
9616         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
9617
9618         /* Validate obuf */
9619         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9620                         ciphertext,
9621                         tdata->ciphertext.data,
9622                         tdata->ciphertext.len,
9623                         "Ciphertext data not as expected");
9624
9625         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9626                         auth_tag,
9627                         tdata->auth_tag.data,
9628                         tdata->auth_tag.len,
9629                         "Generated auth tag not as expected");
9630
9631         return 0;
9632
9633 }
9634
9635 static int
9636 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
9637 {
9638         return test_authenticated_encryption_sessionless(
9639                         &gcm_test_case_5);
9640 }
9641
9642 static int
9643 test_authenticated_decryption_sessionless(
9644                 const struct aead_test_data *tdata)
9645 {
9646         struct crypto_testsuite_params *ts_params = &testsuite_params;
9647         struct crypto_unittest_params *ut_params = &unittest_params;
9648
9649         int retval;
9650         uint8_t *plaintext;
9651         uint8_t key[tdata->key.len + 1];
9652         struct rte_cryptodev_info dev_info;
9653
9654         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9655         uint64_t feat_flags = dev_info.feature_flags;
9656
9657         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
9658                 printf("Device doesn't support Sessionless ops.\n");
9659                 return -ENOTSUP;
9660         }
9661
9662         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9663                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9664                 printf("Device doesn't support RAW data-path APIs.\n");
9665                 return -ENOTSUP;
9666         }
9667
9668         /* not supported with CPU crypto */
9669         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9670                 return -ENOTSUP;
9671
9672         /* Verify the capabilities */
9673         struct rte_cryptodev_sym_capability_idx cap_idx;
9674         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9675         cap_idx.algo.aead = tdata->algo;
9676         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9677                         &cap_idx) == NULL)
9678                 return -ENOTSUP;
9679
9680         /* alloc mbuf and set payload */
9681         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9682
9683         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9684                         rte_pktmbuf_tailroom(ut_params->ibuf));
9685
9686         /* Create AEAD operation */
9687         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9688         if (retval < 0)
9689                 return retval;
9690
9691         /* Create AEAD xform */
9692         memcpy(key, tdata->key.data, tdata->key.len);
9693         retval = create_aead_xform(ut_params->op,
9694                         tdata->algo,
9695                         RTE_CRYPTO_AEAD_OP_DECRYPT,
9696                         key, tdata->key.len,
9697                         tdata->aad.len, tdata->auth_tag.len,
9698                         tdata->iv.len);
9699         if (retval < 0)
9700                 return retval;
9701
9702         ut_params->op->sym->m_src = ut_params->ibuf;
9703
9704         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
9705                         RTE_CRYPTO_OP_SESSIONLESS,
9706                         "crypto op session type not sessionless");
9707
9708         /* Process crypto operation */
9709         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9710                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9711                                 ut_params->op, 0, 0, 0, 0);
9712         else
9713                 TEST_ASSERT_NOT_NULL(process_crypto_request(
9714                         ts_params->valid_devs[0], ut_params->op),
9715                                 "failed to process sym crypto op");
9716
9717         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
9718
9719         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9720                         "crypto op status not success");
9721
9722         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9723                         ut_params->op->sym->cipher.data.offset);
9724
9725         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9726
9727         /* Validate obuf */
9728         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9729                         plaintext,
9730                         tdata->plaintext.data,
9731                         tdata->plaintext.len,
9732                         "Plaintext data not as expected");
9733
9734         TEST_ASSERT_EQUAL(ut_params->op->status,
9735                         RTE_CRYPTO_OP_STATUS_SUCCESS,
9736                         "Authentication failed");
9737         return 0;
9738 }
9739
9740 static int
9741 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
9742 {
9743         return test_authenticated_decryption_sessionless(
9744                         &gcm_test_case_5);
9745 }
9746
9747 static int
9748 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
9749 {
9750         return test_authenticated_encryption(&ccm_test_case_128_1);
9751 }
9752
9753 static int
9754 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
9755 {
9756         return test_authenticated_encryption(&ccm_test_case_128_2);
9757 }
9758
9759 static int
9760 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
9761 {
9762         return test_authenticated_encryption(&ccm_test_case_128_3);
9763 }
9764
9765 static int
9766 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
9767 {
9768         return test_authenticated_decryption(&ccm_test_case_128_1);
9769 }
9770
9771 static int
9772 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
9773 {
9774         return test_authenticated_decryption(&ccm_test_case_128_2);
9775 }
9776
9777 static int
9778 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
9779 {
9780         return test_authenticated_decryption(&ccm_test_case_128_3);
9781 }
9782
9783 static int
9784 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
9785 {
9786         return test_authenticated_encryption(&ccm_test_case_192_1);
9787 }
9788
9789 static int
9790 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
9791 {
9792         return test_authenticated_encryption(&ccm_test_case_192_2);
9793 }
9794
9795 static int
9796 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
9797 {
9798         return test_authenticated_encryption(&ccm_test_case_192_3);
9799 }
9800
9801 static int
9802 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
9803 {
9804         return test_authenticated_decryption(&ccm_test_case_192_1);
9805 }
9806
9807 static int
9808 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
9809 {
9810         return test_authenticated_decryption(&ccm_test_case_192_2);
9811 }
9812
9813 static int
9814 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
9815 {
9816         return test_authenticated_decryption(&ccm_test_case_192_3);
9817 }
9818
9819 static int
9820 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
9821 {
9822         return test_authenticated_encryption(&ccm_test_case_256_1);
9823 }
9824
9825 static int
9826 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
9827 {
9828         return test_authenticated_encryption(&ccm_test_case_256_2);
9829 }
9830
9831 static int
9832 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
9833 {
9834         return test_authenticated_encryption(&ccm_test_case_256_3);
9835 }
9836
9837 static int
9838 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
9839 {
9840         return test_authenticated_decryption(&ccm_test_case_256_1);
9841 }
9842
9843 static int
9844 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
9845 {
9846         return test_authenticated_decryption(&ccm_test_case_256_2);
9847 }
9848
9849 static int
9850 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
9851 {
9852         return test_authenticated_decryption(&ccm_test_case_256_3);
9853 }
9854
9855 static int
9856 test_stats(void)
9857 {
9858         struct crypto_testsuite_params *ts_params = &testsuite_params;
9859         struct rte_cryptodev_stats stats;
9860
9861         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9862                 return -ENOTSUP;
9863
9864         /* Verify the capabilities */
9865         struct rte_cryptodev_sym_capability_idx cap_idx;
9866         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9867         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
9868         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9869                         &cap_idx) == NULL)
9870                 return -ENOTSUP;
9871         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9872         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
9873         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9874                         &cap_idx) == NULL)
9875                 return -ENOTSUP;
9876
9877         if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
9878                         == -ENOTSUP)
9879                 return -ENOTSUP;
9880
9881         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
9882         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
9883                         &stats) == -ENODEV),
9884                 "rte_cryptodev_stats_get invalid dev failed");
9885         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
9886                 "rte_cryptodev_stats_get invalid Param failed");
9887
9888         /* Test expected values */
9889         test_AES_CBC_HMAC_SHA1_encrypt_digest();
9890         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
9891                         &stats),
9892                 "rte_cryptodev_stats_get failed");
9893         TEST_ASSERT((stats.enqueued_count == 1),
9894                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9895         TEST_ASSERT((stats.dequeued_count == 1),
9896                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9897         TEST_ASSERT((stats.enqueue_err_count == 0),
9898                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9899         TEST_ASSERT((stats.dequeue_err_count == 0),
9900                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9901
9902         /* invalid device but should ignore and not reset device stats*/
9903         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
9904         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
9905                         &stats),
9906                 "rte_cryptodev_stats_get failed");
9907         TEST_ASSERT((stats.enqueued_count == 1),
9908                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9909
9910         /* check that a valid reset clears stats */
9911         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
9912         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
9913                         &stats),
9914                                           "rte_cryptodev_stats_get failed");
9915         TEST_ASSERT((stats.enqueued_count == 0),
9916                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9917         TEST_ASSERT((stats.dequeued_count == 0),
9918                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
9919
9920         return TEST_SUCCESS;
9921 }
9922
9923 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
9924                                    struct crypto_unittest_params *ut_params,
9925                                    enum rte_crypto_auth_operation op,
9926                                    const struct HMAC_MD5_vector *test_case)
9927 {
9928         uint8_t key[64];
9929
9930         memcpy(key, test_case->key.data, test_case->key.len);
9931
9932         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9933         ut_params->auth_xform.next = NULL;
9934         ut_params->auth_xform.auth.op = op;
9935
9936         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
9937
9938         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
9939         ut_params->auth_xform.auth.key.length = test_case->key.len;
9940         ut_params->auth_xform.auth.key.data = key;
9941
9942         ut_params->sess = rte_cryptodev_sym_session_create(
9943                         ts_params->session_mpool);
9944
9945         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
9946                         ut_params->sess, &ut_params->auth_xform,
9947                         ts_params->session_priv_mpool);
9948
9949         if (ut_params->sess == NULL)
9950                 return TEST_FAILED;
9951
9952         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9953
9954         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9955                         rte_pktmbuf_tailroom(ut_params->ibuf));
9956
9957         return 0;
9958 }
9959
9960 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
9961                               const struct HMAC_MD5_vector *test_case,
9962                               uint8_t **plaintext)
9963 {
9964         uint16_t plaintext_pad_len;
9965
9966         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9967
9968         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
9969                                 16);
9970
9971         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9972                         plaintext_pad_len);
9973         memcpy(*plaintext, test_case->plaintext.data,
9974                         test_case->plaintext.len);
9975
9976         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
9977                         ut_params->ibuf, MD5_DIGEST_LEN);
9978         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
9979                         "no room to append digest");
9980         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
9981                         ut_params->ibuf, plaintext_pad_len);
9982
9983         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
9984                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
9985                            test_case->auth_tag.len);
9986         }
9987
9988         sym_op->auth.data.offset = 0;
9989         sym_op->auth.data.length = test_case->plaintext.len;
9990
9991         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9992         ut_params->op->sym->m_src = ut_params->ibuf;
9993
9994         return 0;
9995 }
9996
9997 static int
9998 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
9999 {
10000         uint16_t plaintext_pad_len;
10001         uint8_t *plaintext, *auth_tag;
10002
10003         struct crypto_testsuite_params *ts_params = &testsuite_params;
10004         struct crypto_unittest_params *ut_params = &unittest_params;
10005         struct rte_cryptodev_info dev_info;
10006
10007         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10008         uint64_t feat_flags = dev_info.feature_flags;
10009
10010         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10011                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10012                 printf("Device doesn't support RAW data-path APIs.\n");
10013                 return -ENOTSUP;
10014         }
10015
10016         /* Verify the capabilities */
10017         struct rte_cryptodev_sym_capability_idx cap_idx;
10018         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10019         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10020         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10021                         &cap_idx) == NULL)
10022                 return -ENOTSUP;
10023
10024         if (MD5_HMAC_create_session(ts_params, ut_params,
10025                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
10026                 return TEST_FAILED;
10027
10028         /* Generate Crypto op data structure */
10029         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10030                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10031         TEST_ASSERT_NOT_NULL(ut_params->op,
10032                         "Failed to allocate symmetric crypto operation struct");
10033
10034         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10035                                 16);
10036
10037         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10038                 return TEST_FAILED;
10039
10040         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10041                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10042                         ut_params->op);
10043         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10044                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10045                                 ut_params->op, 0, 1, 0, 0);
10046         else
10047                 TEST_ASSERT_NOT_NULL(
10048                         process_crypto_request(ts_params->valid_devs[0],
10049                                 ut_params->op),
10050                                 "failed to process sym crypto op");
10051
10052         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10053                         "crypto op processing failed");
10054
10055         if (ut_params->op->sym->m_dst) {
10056                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10057                                 uint8_t *, plaintext_pad_len);
10058         } else {
10059                 auth_tag = plaintext + plaintext_pad_len;
10060         }
10061
10062         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10063                         auth_tag,
10064                         test_case->auth_tag.data,
10065                         test_case->auth_tag.len,
10066                         "HMAC_MD5 generated tag not as expected");
10067
10068         return TEST_SUCCESS;
10069 }
10070
10071 static int
10072 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
10073 {
10074         uint8_t *plaintext;
10075
10076         struct crypto_testsuite_params *ts_params = &testsuite_params;
10077         struct crypto_unittest_params *ut_params = &unittest_params;
10078         struct rte_cryptodev_info dev_info;
10079
10080         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10081         uint64_t feat_flags = dev_info.feature_flags;
10082
10083         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10084                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10085                 printf("Device doesn't support RAW data-path APIs.\n");
10086                 return -ENOTSUP;
10087         }
10088
10089         /* Verify the capabilities */
10090         struct rte_cryptodev_sym_capability_idx cap_idx;
10091         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10092         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10093         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10094                         &cap_idx) == NULL)
10095                 return -ENOTSUP;
10096
10097         if (MD5_HMAC_create_session(ts_params, ut_params,
10098                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
10099                 return TEST_FAILED;
10100         }
10101
10102         /* Generate Crypto op data structure */
10103         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10104                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10105         TEST_ASSERT_NOT_NULL(ut_params->op,
10106                         "Failed to allocate symmetric crypto operation struct");
10107
10108         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10109                 return TEST_FAILED;
10110
10111         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10112                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10113                         ut_params->op);
10114         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10115                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10116                                 ut_params->op, 0, 1, 0, 0);
10117         else
10118                 TEST_ASSERT_NOT_NULL(
10119                         process_crypto_request(ts_params->valid_devs[0],
10120                                 ut_params->op),
10121                                 "failed to process sym crypto op");
10122
10123         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10124                         "HMAC_MD5 crypto op processing failed");
10125
10126         return TEST_SUCCESS;
10127 }
10128
10129 static int
10130 test_MD5_HMAC_generate_case_1(void)
10131 {
10132         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
10133 }
10134
10135 static int
10136 test_MD5_HMAC_verify_case_1(void)
10137 {
10138         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
10139 }
10140
10141 static int
10142 test_MD5_HMAC_generate_case_2(void)
10143 {
10144         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
10145 }
10146
10147 static int
10148 test_MD5_HMAC_verify_case_2(void)
10149 {
10150         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
10151 }
10152
10153 static int
10154 test_multi_session(void)
10155 {
10156         struct crypto_testsuite_params *ts_params = &testsuite_params;
10157         struct crypto_unittest_params *ut_params = &unittest_params;
10158
10159         struct rte_cryptodev_info dev_info;
10160         struct rte_cryptodev_sym_session **sessions;
10161
10162         uint16_t i;
10163
10164         /* Verify the capabilities */
10165         struct rte_cryptodev_sym_capability_idx cap_idx;
10166         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10167         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10168         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10169                         &cap_idx) == NULL)
10170                 return -ENOTSUP;
10171         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10172         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10173         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10174                         &cap_idx) == NULL)
10175                 return -ENOTSUP;
10176
10177         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
10178                         aes_cbc_key, hmac_sha512_key);
10179
10180
10181         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10182
10183         sessions = rte_malloc(NULL,
10184                         (sizeof(struct rte_cryptodev_sym_session *) *
10185                         MAX_NB_SESSIONS) + 1, 0);
10186
10187         /* Create multiple crypto sessions*/
10188         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10189
10190                 sessions[i] = rte_cryptodev_sym_session_create(
10191                                 ts_params->session_mpool);
10192
10193                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10194                                 sessions[i], &ut_params->auth_xform,
10195                                 ts_params->session_priv_mpool);
10196                 TEST_ASSERT_NOT_NULL(sessions[i],
10197                                 "Session creation failed at session number %u",
10198                                 i);
10199
10200                 /* Attempt to send a request on each session */
10201                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
10202                         sessions[i],
10203                         ut_params,
10204                         ts_params,
10205                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
10206                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
10207                         aes_cbc_iv),
10208                         "Failed to perform decrypt on request number %u.", i);
10209                 /* free crypto operation structure */
10210                 if (ut_params->op)
10211                         rte_crypto_op_free(ut_params->op);
10212
10213                 /*
10214                  * free mbuf - both obuf and ibuf are usually the same,
10215                  * so check if they point at the same address is necessary,
10216                  * to avoid freeing the mbuf twice.
10217                  */
10218                 if (ut_params->obuf) {
10219                         rte_pktmbuf_free(ut_params->obuf);
10220                         if (ut_params->ibuf == ut_params->obuf)
10221                                 ut_params->ibuf = 0;
10222                         ut_params->obuf = 0;
10223                 }
10224                 if (ut_params->ibuf) {
10225                         rte_pktmbuf_free(ut_params->ibuf);
10226                         ut_params->ibuf = 0;
10227                 }
10228         }
10229
10230         /* Next session create should fail */
10231         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10232                         sessions[i], &ut_params->auth_xform,
10233                         ts_params->session_priv_mpool);
10234         TEST_ASSERT_NULL(sessions[i],
10235                         "Session creation succeeded unexpectedly!");
10236
10237         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10238                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10239                                 sessions[i]);
10240                 rte_cryptodev_sym_session_free(sessions[i]);
10241         }
10242
10243         rte_free(sessions);
10244
10245         return TEST_SUCCESS;
10246 }
10247
10248 struct multi_session_params {
10249         struct crypto_unittest_params ut_params;
10250         uint8_t *cipher_key;
10251         uint8_t *hmac_key;
10252         const uint8_t *cipher;
10253         const uint8_t *digest;
10254         uint8_t *iv;
10255 };
10256
10257 #define MB_SESSION_NUMBER 3
10258
10259 static int
10260 test_multi_session_random_usage(void)
10261 {
10262         struct crypto_testsuite_params *ts_params = &testsuite_params;
10263         struct rte_cryptodev_info dev_info;
10264         struct rte_cryptodev_sym_session **sessions;
10265         uint32_t i, j;
10266         struct multi_session_params ut_paramz[] = {
10267
10268                 {
10269                         .cipher_key = ms_aes_cbc_key0,
10270                         .hmac_key = ms_hmac_key0,
10271                         .cipher = ms_aes_cbc_cipher0,
10272                         .digest = ms_hmac_digest0,
10273                         .iv = ms_aes_cbc_iv0
10274                 },
10275                 {
10276                         .cipher_key = ms_aes_cbc_key1,
10277                         .hmac_key = ms_hmac_key1,
10278                         .cipher = ms_aes_cbc_cipher1,
10279                         .digest = ms_hmac_digest1,
10280                         .iv = ms_aes_cbc_iv1
10281                 },
10282                 {
10283                         .cipher_key = ms_aes_cbc_key2,
10284                         .hmac_key = ms_hmac_key2,
10285                         .cipher = ms_aes_cbc_cipher2,
10286                         .digest = ms_hmac_digest2,
10287                         .iv = ms_aes_cbc_iv2
10288                 },
10289
10290         };
10291
10292         /* Verify the capabilities */
10293         struct rte_cryptodev_sym_capability_idx cap_idx;
10294         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10295         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10296         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10297                         &cap_idx) == NULL)
10298                 return -ENOTSUP;
10299         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10300         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10301         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10302                         &cap_idx) == NULL)
10303                 return -ENOTSUP;
10304
10305         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10306
10307         sessions = rte_malloc(NULL,
10308                         (sizeof(struct rte_cryptodev_sym_session *)
10309                                         * MAX_NB_SESSIONS) + 1, 0);
10310
10311         for (i = 0; i < MB_SESSION_NUMBER; i++) {
10312                 sessions[i] = rte_cryptodev_sym_session_create(
10313                                 ts_params->session_mpool);
10314
10315                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
10316                                 sizeof(struct crypto_unittest_params));
10317
10318                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
10319                                 &ut_paramz[i].ut_params,
10320                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
10321
10322                 /* Create multiple crypto sessions*/
10323                 rte_cryptodev_sym_session_init(
10324                                 ts_params->valid_devs[0],
10325                                 sessions[i],
10326                                 &ut_paramz[i].ut_params.auth_xform,
10327                                 ts_params->session_priv_mpool);
10328
10329                 TEST_ASSERT_NOT_NULL(sessions[i],
10330                                 "Session creation failed at session number %u",
10331                                 i);
10332
10333         }
10334
10335         srand(time(NULL));
10336         for (i = 0; i < 40000; i++) {
10337
10338                 j = rand() % MB_SESSION_NUMBER;
10339
10340                 TEST_ASSERT_SUCCESS(
10341                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
10342                                         sessions[j],
10343                                         &ut_paramz[j].ut_params,
10344                                         ts_params, ut_paramz[j].cipher,
10345                                         ut_paramz[j].digest,
10346                                         ut_paramz[j].iv),
10347                         "Failed to perform decrypt on request number %u.", i);
10348
10349                 if (ut_paramz[j].ut_params.op)
10350                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
10351
10352                 /*
10353                  * free mbuf - both obuf and ibuf are usually the same,
10354                  * so check if they point at the same address is necessary,
10355                  * to avoid freeing the mbuf twice.
10356                  */
10357                 if (ut_paramz[j].ut_params.obuf) {
10358                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
10359                         if (ut_paramz[j].ut_params.ibuf
10360                                         == ut_paramz[j].ut_params.obuf)
10361                                 ut_paramz[j].ut_params.ibuf = 0;
10362                         ut_paramz[j].ut_params.obuf = 0;
10363                 }
10364                 if (ut_paramz[j].ut_params.ibuf) {
10365                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
10366                         ut_paramz[j].ut_params.ibuf = 0;
10367                 }
10368         }
10369
10370         for (i = 0; i < MB_SESSION_NUMBER; i++) {
10371                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10372                                 sessions[i]);
10373                 rte_cryptodev_sym_session_free(sessions[i]);
10374         }
10375
10376         rte_free(sessions);
10377
10378         return TEST_SUCCESS;
10379 }
10380
10381 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
10382                         0xab, 0xab, 0xab, 0xab,
10383                         0xab, 0xab, 0xab, 0xab,
10384                         0xab, 0xab, 0xab, 0xab};
10385
10386 static int
10387 test_null_invalid_operation(void)
10388 {
10389         struct crypto_testsuite_params *ts_params = &testsuite_params;
10390         struct crypto_unittest_params *ut_params = &unittest_params;
10391         int ret;
10392
10393         /* This test is for NULL PMD only */
10394         if (gbl_driver_id != rte_cryptodev_driver_id_get(
10395                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
10396                 return -ENOTSUP;
10397
10398         /* Setup Cipher Parameters */
10399         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10400         ut_params->cipher_xform.next = NULL;
10401
10402         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
10403         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10404
10405         ut_params->sess = rte_cryptodev_sym_session_create(
10406                         ts_params->session_mpool);
10407
10408         /* Create Crypto session*/
10409         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10410                         ut_params->sess, &ut_params->cipher_xform,
10411                         ts_params->session_priv_mpool);
10412         TEST_ASSERT(ret < 0,
10413                         "Session creation succeeded unexpectedly");
10414
10415
10416         /* Setup HMAC Parameters */
10417         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10418         ut_params->auth_xform.next = NULL;
10419
10420         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
10421         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10422
10423         ut_params->sess = rte_cryptodev_sym_session_create(
10424                         ts_params->session_mpool);
10425
10426         /* Create Crypto session*/
10427         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10428                         ut_params->sess, &ut_params->auth_xform,
10429                         ts_params->session_priv_mpool);
10430         TEST_ASSERT(ret < 0,
10431                         "Session creation succeeded unexpectedly");
10432
10433         return TEST_SUCCESS;
10434 }
10435
10436
10437 #define NULL_BURST_LENGTH (32)
10438
10439 static int
10440 test_null_burst_operation(void)
10441 {
10442         struct crypto_testsuite_params *ts_params = &testsuite_params;
10443         struct crypto_unittest_params *ut_params = &unittest_params;
10444
10445         unsigned i, burst_len = NULL_BURST_LENGTH;
10446
10447         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
10448         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
10449
10450         /* This test is for NULL PMD only */
10451         if (gbl_driver_id != rte_cryptodev_driver_id_get(
10452                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
10453                 return -ENOTSUP;
10454
10455         /* Setup Cipher Parameters */
10456         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10457         ut_params->cipher_xform.next = &ut_params->auth_xform;
10458
10459         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
10460         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10461
10462         /* Setup HMAC Parameters */
10463         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10464         ut_params->auth_xform.next = NULL;
10465
10466         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
10467         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10468
10469         ut_params->sess = rte_cryptodev_sym_session_create(
10470                         ts_params->session_mpool);
10471
10472         /* Create Crypto session*/
10473         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10474                         ut_params->sess, &ut_params->cipher_xform,
10475                         ts_params->session_priv_mpool);
10476         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10477
10478         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
10479                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
10480                         burst_len, "failed to generate burst of crypto ops");
10481
10482         /* Generate an operation for each mbuf in burst */
10483         for (i = 0; i < burst_len; i++) {
10484                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10485
10486                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
10487
10488                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
10489                                 sizeof(unsigned));
10490                 *data = i;
10491
10492                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
10493
10494                 burst[i]->sym->m_src = m;
10495         }
10496
10497         /* Process crypto operation */
10498         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
10499                         0, burst, burst_len),
10500                         burst_len,
10501                         "Error enqueuing burst");
10502
10503         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
10504                         0, burst_dequeued, burst_len),
10505                         burst_len,
10506                         "Error dequeuing burst");
10507
10508
10509         for (i = 0; i < burst_len; i++) {
10510                 TEST_ASSERT_EQUAL(
10511                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
10512                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
10513                                         uint32_t *),
10514                         "data not as expected");
10515
10516                 rte_pktmbuf_free(burst[i]->sym->m_src);
10517                 rte_crypto_op_free(burst[i]);
10518         }
10519
10520         return TEST_SUCCESS;
10521 }
10522
10523 static void
10524 generate_gmac_large_plaintext(uint8_t *data)
10525 {
10526         uint16_t i;
10527
10528         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
10529                 memcpy(&data[i], &data[0], 32);
10530 }
10531
10532 static int
10533 create_gmac_operation(enum rte_crypto_auth_operation op,
10534                 const struct gmac_test_data *tdata)
10535 {
10536         struct crypto_testsuite_params *ts_params = &testsuite_params;
10537         struct crypto_unittest_params *ut_params = &unittest_params;
10538         struct rte_crypto_sym_op *sym_op;
10539
10540         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10541
10542         /* Generate Crypto op data structure */
10543         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10544                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10545         TEST_ASSERT_NOT_NULL(ut_params->op,
10546                         "Failed to allocate symmetric crypto operation struct");
10547
10548         sym_op = ut_params->op->sym;
10549
10550         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10551                         ut_params->ibuf, tdata->gmac_tag.len);
10552         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10553                         "no room to append digest");
10554
10555         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10556                         ut_params->ibuf, plaintext_pad_len);
10557
10558         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10559                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
10560                                 tdata->gmac_tag.len);
10561                 debug_hexdump(stdout, "digest:",
10562                                 sym_op->auth.digest.data,
10563                                 tdata->gmac_tag.len);
10564         }
10565
10566         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
10567                         uint8_t *, IV_OFFSET);
10568
10569         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
10570
10571         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
10572
10573         sym_op->cipher.data.length = 0;
10574         sym_op->cipher.data.offset = 0;
10575
10576         sym_op->auth.data.offset = 0;
10577         sym_op->auth.data.length = tdata->plaintext.len;
10578
10579         return 0;
10580 }
10581
10582 static int
10583 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
10584                 const struct gmac_test_data *tdata,
10585                 void *digest_mem, uint64_t digest_phys)
10586 {
10587         struct crypto_testsuite_params *ts_params = &testsuite_params;
10588         struct crypto_unittest_params *ut_params = &unittest_params;
10589         struct rte_crypto_sym_op *sym_op;
10590
10591         /* Generate Crypto op data structure */
10592         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10593                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10594         TEST_ASSERT_NOT_NULL(ut_params->op,
10595                         "Failed to allocate symmetric crypto operation struct");
10596
10597         sym_op = ut_params->op->sym;
10598
10599         sym_op->auth.digest.data = digest_mem;
10600         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10601                         "no room to append digest");
10602
10603         sym_op->auth.digest.phys_addr = digest_phys;
10604
10605         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10606                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
10607                                 tdata->gmac_tag.len);
10608                 debug_hexdump(stdout, "digest:",
10609                                 sym_op->auth.digest.data,
10610                                 tdata->gmac_tag.len);
10611         }
10612
10613         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
10614                         uint8_t *, IV_OFFSET);
10615
10616         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
10617
10618         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
10619
10620         sym_op->cipher.data.length = 0;
10621         sym_op->cipher.data.offset = 0;
10622
10623         sym_op->auth.data.offset = 0;
10624         sym_op->auth.data.length = tdata->plaintext.len;
10625
10626         return 0;
10627 }
10628
10629 static int create_gmac_session(uint8_t dev_id,
10630                 const struct gmac_test_data *tdata,
10631                 enum rte_crypto_auth_operation auth_op)
10632 {
10633         uint8_t auth_key[tdata->key.len];
10634
10635         struct crypto_testsuite_params *ts_params = &testsuite_params;
10636         struct crypto_unittest_params *ut_params = &unittest_params;
10637
10638         memcpy(auth_key, tdata->key.data, tdata->key.len);
10639
10640         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10641         ut_params->auth_xform.next = NULL;
10642
10643         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
10644         ut_params->auth_xform.auth.op = auth_op;
10645         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
10646         ut_params->auth_xform.auth.key.length = tdata->key.len;
10647         ut_params->auth_xform.auth.key.data = auth_key;
10648         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
10649         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
10650
10651
10652         ut_params->sess = rte_cryptodev_sym_session_create(
10653                         ts_params->session_mpool);
10654
10655         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
10656                         &ut_params->auth_xform,
10657                         ts_params->session_priv_mpool);
10658
10659         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10660
10661         return 0;
10662 }
10663
10664 static int
10665 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
10666 {
10667         struct crypto_testsuite_params *ts_params = &testsuite_params;
10668         struct crypto_unittest_params *ut_params = &unittest_params;
10669         struct rte_cryptodev_info dev_info;
10670
10671         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10672         uint64_t feat_flags = dev_info.feature_flags;
10673
10674         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10675                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10676                 printf("Device doesn't support RAW data-path APIs.\n");
10677                 return -ENOTSUP;
10678         }
10679
10680         int retval;
10681
10682         uint8_t *auth_tag, *plaintext;
10683         uint16_t plaintext_pad_len;
10684
10685         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
10686                               "No GMAC length in the source data");
10687
10688         /* Verify the capabilities */
10689         struct rte_cryptodev_sym_capability_idx cap_idx;
10690         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10691         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
10692         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10693                         &cap_idx) == NULL)
10694                 return -ENOTSUP;
10695
10696         retval = create_gmac_session(ts_params->valid_devs[0],
10697                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
10698
10699         if (retval < 0)
10700                 return retval;
10701
10702         if (tdata->plaintext.len > MBUF_SIZE)
10703                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10704         else
10705                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10706         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10707                         "Failed to allocate input buffer in mempool");
10708
10709         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10710                         rte_pktmbuf_tailroom(ut_params->ibuf));
10711
10712         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10713         /*
10714          * Runtime generate the large plain text instead of use hard code
10715          * plain text vector. It is done to avoid create huge source file
10716          * with the test vector.
10717          */
10718         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
10719                 generate_gmac_large_plaintext(tdata->plaintext.data);
10720
10721         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10722                                 plaintext_pad_len);
10723         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10724
10725         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
10726         debug_hexdump(stdout, "plaintext:", plaintext,
10727                         tdata->plaintext.len);
10728
10729         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
10730                         tdata);
10731
10732         if (retval < 0)
10733                 return retval;
10734
10735         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10736
10737         ut_params->op->sym->m_src = ut_params->ibuf;
10738
10739         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10740                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10741                         ut_params->op);
10742         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10743                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10744                                 ut_params->op, 0, 1, 0, 0);
10745         else
10746                 TEST_ASSERT_NOT_NULL(
10747                         process_crypto_request(ts_params->valid_devs[0],
10748                         ut_params->op), "failed to process sym crypto op");
10749
10750         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10751                         "crypto op processing failed");
10752
10753         if (ut_params->op->sym->m_dst) {
10754                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10755                                 uint8_t *, plaintext_pad_len);
10756         } else {
10757                 auth_tag = plaintext + plaintext_pad_len;
10758         }
10759
10760         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
10761
10762         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10763                         auth_tag,
10764                         tdata->gmac_tag.data,
10765                         tdata->gmac_tag.len,
10766                         "GMAC Generated auth tag not as expected");
10767
10768         return 0;
10769 }
10770
10771 static int
10772 test_AES_GMAC_authentication_test_case_1(void)
10773 {
10774         return test_AES_GMAC_authentication(&gmac_test_case_1);
10775 }
10776
10777 static int
10778 test_AES_GMAC_authentication_test_case_2(void)
10779 {
10780         return test_AES_GMAC_authentication(&gmac_test_case_2);
10781 }
10782
10783 static int
10784 test_AES_GMAC_authentication_test_case_3(void)
10785 {
10786         return test_AES_GMAC_authentication(&gmac_test_case_3);
10787 }
10788
10789 static int
10790 test_AES_GMAC_authentication_test_case_4(void)
10791 {
10792         return test_AES_GMAC_authentication(&gmac_test_case_4);
10793 }
10794
10795 static int
10796 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
10797 {
10798         struct crypto_testsuite_params *ts_params = &testsuite_params;
10799         struct crypto_unittest_params *ut_params = &unittest_params;
10800         int retval;
10801         uint32_t plaintext_pad_len;
10802         uint8_t *plaintext;
10803         struct rte_cryptodev_info dev_info;
10804
10805         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10806         uint64_t feat_flags = dev_info.feature_flags;
10807
10808         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10809                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10810                 printf("Device doesn't support RAW data-path APIs.\n");
10811                 return -ENOTSUP;
10812         }
10813
10814         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
10815                               "No GMAC length in the source data");
10816
10817         /* Verify the capabilities */
10818         struct rte_cryptodev_sym_capability_idx cap_idx;
10819         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10820         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
10821         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10822                         &cap_idx) == NULL)
10823                 return -ENOTSUP;
10824
10825         retval = create_gmac_session(ts_params->valid_devs[0],
10826                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
10827
10828         if (retval < 0)
10829                 return retval;
10830
10831         if (tdata->plaintext.len > MBUF_SIZE)
10832                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10833         else
10834                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10835         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10836                         "Failed to allocate input buffer in mempool");
10837
10838         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10839                         rte_pktmbuf_tailroom(ut_params->ibuf));
10840
10841         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10842
10843         /*
10844          * Runtime generate the large plain text instead of use hard code
10845          * plain text vector. It is done to avoid create huge source file
10846          * with the test vector.
10847          */
10848         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
10849                 generate_gmac_large_plaintext(tdata->plaintext.data);
10850
10851         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10852                                 plaintext_pad_len);
10853         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10854
10855         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
10856         debug_hexdump(stdout, "plaintext:", plaintext,
10857                         tdata->plaintext.len);
10858
10859         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
10860                         tdata);
10861
10862         if (retval < 0)
10863                 return retval;
10864
10865         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10866
10867         ut_params->op->sym->m_src = ut_params->ibuf;
10868
10869         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10870                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10871                         ut_params->op);
10872         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10873                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10874                                 ut_params->op, 0, 1, 0, 0);
10875         else
10876                 TEST_ASSERT_NOT_NULL(
10877                         process_crypto_request(ts_params->valid_devs[0],
10878                         ut_params->op), "failed to process sym crypto op");
10879
10880         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10881                         "crypto op processing failed");
10882
10883         return 0;
10884
10885 }
10886
10887 static int
10888 test_AES_GMAC_authentication_verify_test_case_1(void)
10889 {
10890         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
10891 }
10892
10893 static int
10894 test_AES_GMAC_authentication_verify_test_case_2(void)
10895 {
10896         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
10897 }
10898
10899 static int
10900 test_AES_GMAC_authentication_verify_test_case_3(void)
10901 {
10902         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
10903 }
10904
10905 static int
10906 test_AES_GMAC_authentication_verify_test_case_4(void)
10907 {
10908         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
10909 }
10910
10911 static int
10912 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
10913                                 uint32_t fragsz)
10914 {
10915         struct crypto_testsuite_params *ts_params = &testsuite_params;
10916         struct crypto_unittest_params *ut_params = &unittest_params;
10917         struct rte_cryptodev_info dev_info;
10918         uint64_t feature_flags;
10919         unsigned int trn_data = 0;
10920         void *digest_mem = NULL;
10921         uint32_t segs = 1;
10922         unsigned int to_trn = 0;
10923         struct rte_mbuf *buf = NULL;
10924         uint8_t *auth_tag, *plaintext;
10925         int retval;
10926
10927         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
10928                               "No GMAC length in the source data");
10929
10930         /* Verify the capabilities */
10931         struct rte_cryptodev_sym_capability_idx cap_idx;
10932         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10933         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
10934         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10935                         &cap_idx) == NULL)
10936                 return -ENOTSUP;
10937
10938         /* Check for any input SGL support */
10939         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10940         feature_flags = dev_info.feature_flags;
10941
10942         if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) &&
10943                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) &&
10944                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
10945                 return -ENOTSUP;
10946
10947         if (fragsz > tdata->plaintext.len)
10948                 fragsz = tdata->plaintext.len;
10949
10950         uint16_t plaintext_len = fragsz;
10951
10952         retval = create_gmac_session(ts_params->valid_devs[0],
10953                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
10954
10955         if (retval < 0)
10956                 return retval;
10957
10958         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10959         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10960                         "Failed to allocate input buffer in mempool");
10961
10962         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10963                         rte_pktmbuf_tailroom(ut_params->ibuf));
10964
10965         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10966                                 plaintext_len);
10967         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10968
10969         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
10970
10971         trn_data += plaintext_len;
10972
10973         buf = ut_params->ibuf;
10974
10975         /*
10976          * Loop until no more fragments
10977          */
10978
10979         while (trn_data < tdata->plaintext.len) {
10980                 ++segs;
10981                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
10982                                 (tdata->plaintext.len - trn_data) : fragsz;
10983
10984                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10985                 buf = buf->next;
10986
10987                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
10988                                 rte_pktmbuf_tailroom(buf));
10989
10990                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
10991                                 to_trn);
10992
10993                 memcpy(plaintext, tdata->plaintext.data + trn_data,
10994                                 to_trn);
10995                 trn_data += to_trn;
10996                 if (trn_data  == tdata->plaintext.len)
10997                         digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
10998                                         tdata->gmac_tag.len);
10999         }
11000         ut_params->ibuf->nb_segs = segs;
11001
11002         /*
11003          * Place digest at the end of the last buffer
11004          */
11005         uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11006
11007         if (!digest_mem) {
11008                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11009                                 + tdata->gmac_tag.len);
11010                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11011                                 tdata->plaintext.len);
11012         }
11013
11014         retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
11015                         tdata, digest_mem, digest_phys);
11016
11017         if (retval < 0)
11018                 return retval;
11019
11020         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11021
11022         ut_params->op->sym->m_src = ut_params->ibuf;
11023
11024         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11025                 return -ENOTSUP;
11026
11027         TEST_ASSERT_NOT_NULL(
11028                 process_crypto_request(ts_params->valid_devs[0],
11029                 ut_params->op), "failed to process sym crypto op");
11030
11031         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11032                         "crypto op processing failed");
11033
11034         auth_tag = digest_mem;
11035         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11036         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11037                         auth_tag,
11038                         tdata->gmac_tag.data,
11039                         tdata->gmac_tag.len,
11040                         "GMAC Generated auth tag not as expected");
11041
11042         return 0;
11043 }
11044
11045 /* Segment size not multiple of block size (16B) */
11046 static int
11047 test_AES_GMAC_authentication_SGL_40B(void)
11048 {
11049         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
11050 }
11051
11052 static int
11053 test_AES_GMAC_authentication_SGL_80B(void)
11054 {
11055         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
11056 }
11057
11058 static int
11059 test_AES_GMAC_authentication_SGL_2048B(void)
11060 {
11061         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
11062 }
11063
11064 /* Segment size not multiple of block size (16B) */
11065 static int
11066 test_AES_GMAC_authentication_SGL_2047B(void)
11067 {
11068         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
11069 }
11070
11071 struct test_crypto_vector {
11072         enum rte_crypto_cipher_algorithm crypto_algo;
11073         unsigned int cipher_offset;
11074         unsigned int cipher_len;
11075
11076         struct {
11077                 uint8_t data[64];
11078                 unsigned int len;
11079         } cipher_key;
11080
11081         struct {
11082                 uint8_t data[64];
11083                 unsigned int len;
11084         } iv;
11085
11086         struct {
11087                 const uint8_t *data;
11088                 unsigned int len;
11089         } plaintext;
11090
11091         struct {
11092                 const uint8_t *data;
11093                 unsigned int len;
11094         } ciphertext;
11095
11096         enum rte_crypto_auth_algorithm auth_algo;
11097         unsigned int auth_offset;
11098
11099         struct {
11100                 uint8_t data[128];
11101                 unsigned int len;
11102         } auth_key;
11103
11104         struct {
11105                 const uint8_t *data;
11106                 unsigned int len;
11107         } aad;
11108
11109         struct {
11110                 uint8_t data[128];
11111                 unsigned int len;
11112         } digest;
11113 };
11114
11115 static const struct test_crypto_vector
11116 hmac_sha1_test_crypto_vector = {
11117         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11118         .plaintext = {
11119                 .data = plaintext_hash,
11120                 .len = 512
11121         },
11122         .auth_key = {
11123                 .data = {
11124                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11125                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11126                         0xDE, 0xF4, 0xDE, 0xAD
11127                 },
11128                 .len = 20
11129         },
11130         .digest = {
11131                 .data = {
11132                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
11133                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
11134                         0x3F, 0x91, 0x64, 0x59
11135                 },
11136                 .len = 20
11137         }
11138 };
11139
11140 static const struct test_crypto_vector
11141 aes128_gmac_test_vector = {
11142         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
11143         .plaintext = {
11144                 .data = plaintext_hash,
11145                 .len = 512
11146         },
11147         .iv = {
11148                 .data = {
11149                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11150                         0x08, 0x09, 0x0A, 0x0B
11151                 },
11152                 .len = 12
11153         },
11154         .auth_key = {
11155                 .data = {
11156                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
11157                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
11158                 },
11159                 .len = 16
11160         },
11161         .digest = {
11162                 .data = {
11163                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
11164                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
11165                 },
11166                 .len = 16
11167         }
11168 };
11169
11170 static const struct test_crypto_vector
11171 aes128cbc_hmac_sha1_test_vector = {
11172         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
11173         .cipher_offset = 0,
11174         .cipher_len = 512,
11175         .cipher_key = {
11176                 .data = {
11177                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
11178                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
11179                 },
11180                 .len = 16
11181         },
11182         .iv = {
11183                 .data = {
11184                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11185                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
11186                 },
11187                 .len = 16
11188         },
11189         .plaintext = {
11190                 .data = plaintext_hash,
11191                 .len = 512
11192         },
11193         .ciphertext = {
11194                 .data = ciphertext512_aes128cbc,
11195                 .len = 512
11196         },
11197         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11198         .auth_offset = 0,
11199         .auth_key = {
11200                 .data = {
11201                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11202                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11203                         0xDE, 0xF4, 0xDE, 0xAD
11204                 },
11205                 .len = 20
11206         },
11207         .digest = {
11208                 .data = {
11209                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
11210                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
11211                         0x18, 0x8C, 0x1D, 0x32
11212                 },
11213                 .len = 20
11214         }
11215 };
11216
11217 static const struct test_crypto_vector
11218 aes128cbc_hmac_sha1_aad_test_vector = {
11219         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
11220         .cipher_offset = 8,
11221         .cipher_len = 496,
11222         .cipher_key = {
11223                 .data = {
11224                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
11225                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
11226                 },
11227                 .len = 16
11228         },
11229         .iv = {
11230                 .data = {
11231                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11232                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
11233                 },
11234                 .len = 16
11235         },
11236         .plaintext = {
11237                 .data = plaintext_hash,
11238                 .len = 512
11239         },
11240         .ciphertext = {
11241                 .data = ciphertext512_aes128cbc_aad,
11242                 .len = 512
11243         },
11244         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11245         .auth_offset = 0,
11246         .auth_key = {
11247                 .data = {
11248                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11249                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11250                         0xDE, 0xF4, 0xDE, 0xAD
11251                 },
11252                 .len = 20
11253         },
11254         .digest = {
11255                 .data = {
11256                         0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
11257                         0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
11258                         0x62, 0x0F, 0xFB, 0x10
11259                 },
11260                 .len = 20
11261         }
11262 };
11263
11264 static void
11265 data_corruption(uint8_t *data)
11266 {
11267         data[0] += 1;
11268 }
11269
11270 static void
11271 tag_corruption(uint8_t *data, unsigned int tag_offset)
11272 {
11273         data[tag_offset] += 1;
11274 }
11275
11276 static int
11277 create_auth_session(struct crypto_unittest_params *ut_params,
11278                 uint8_t dev_id,
11279                 const struct test_crypto_vector *reference,
11280                 enum rte_crypto_auth_operation auth_op)
11281 {
11282         struct crypto_testsuite_params *ts_params = &testsuite_params;
11283         uint8_t auth_key[reference->auth_key.len + 1];
11284
11285         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
11286
11287         /* Setup Authentication Parameters */
11288         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11289         ut_params->auth_xform.auth.op = auth_op;
11290         ut_params->auth_xform.next = NULL;
11291         ut_params->auth_xform.auth.algo = reference->auth_algo;
11292         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
11293         ut_params->auth_xform.auth.key.data = auth_key;
11294         ut_params->auth_xform.auth.digest_length = reference->digest.len;
11295
11296         /* Create Crypto session*/
11297         ut_params->sess = rte_cryptodev_sym_session_create(
11298                         ts_params->session_mpool);
11299
11300         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11301                                 &ut_params->auth_xform,
11302                                 ts_params->session_priv_mpool);
11303
11304         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11305
11306         return 0;
11307 }
11308
11309 static int
11310 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
11311                 uint8_t dev_id,
11312                 const struct test_crypto_vector *reference,
11313                 enum rte_crypto_auth_operation auth_op,
11314                 enum rte_crypto_cipher_operation cipher_op)
11315 {
11316         struct crypto_testsuite_params *ts_params = &testsuite_params;
11317         uint8_t cipher_key[reference->cipher_key.len + 1];
11318         uint8_t auth_key[reference->auth_key.len + 1];
11319
11320         memcpy(cipher_key, reference->cipher_key.data,
11321                         reference->cipher_key.len);
11322         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
11323
11324         /* Setup Authentication Parameters */
11325         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11326         ut_params->auth_xform.auth.op = auth_op;
11327         ut_params->auth_xform.auth.algo = reference->auth_algo;
11328         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
11329         ut_params->auth_xform.auth.key.data = auth_key;
11330         ut_params->auth_xform.auth.digest_length = reference->digest.len;
11331
11332         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
11333                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11334                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
11335         } else {
11336                 ut_params->auth_xform.next = &ut_params->cipher_xform;
11337
11338                 /* Setup Cipher Parameters */
11339                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11340                 ut_params->cipher_xform.next = NULL;
11341                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
11342                 ut_params->cipher_xform.cipher.op = cipher_op;
11343                 ut_params->cipher_xform.cipher.key.data = cipher_key;
11344                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
11345                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11346                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
11347         }
11348
11349         /* Create Crypto session*/
11350         ut_params->sess = rte_cryptodev_sym_session_create(
11351                         ts_params->session_mpool);
11352
11353         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11354                                 &ut_params->auth_xform,
11355                                 ts_params->session_priv_mpool);
11356
11357         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11358
11359         return 0;
11360 }
11361
11362 static int
11363 create_auth_operation(struct crypto_testsuite_params *ts_params,
11364                 struct crypto_unittest_params *ut_params,
11365                 const struct test_crypto_vector *reference,
11366                 unsigned int auth_generate)
11367 {
11368         /* Generate Crypto op data structure */
11369         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11370                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11371         TEST_ASSERT_NOT_NULL(ut_params->op,
11372                         "Failed to allocate pktmbuf offload");
11373
11374         /* Set crypto operation data parameters */
11375         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11376
11377         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11378
11379         /* set crypto operation source mbuf */
11380         sym_op->m_src = ut_params->ibuf;
11381
11382         /* digest */
11383         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11384                         ut_params->ibuf, reference->digest.len);
11385
11386         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11387                         "no room to append auth tag");
11388
11389         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11390                         ut_params->ibuf, reference->plaintext.len);
11391
11392         if (auth_generate)
11393                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
11394         else
11395                 memcpy(sym_op->auth.digest.data,
11396                                 reference->digest.data,
11397                                 reference->digest.len);
11398
11399         debug_hexdump(stdout, "digest:",
11400                         sym_op->auth.digest.data,
11401                         reference->digest.len);
11402
11403         sym_op->auth.data.length = reference->plaintext.len;
11404         sym_op->auth.data.offset = 0;
11405
11406         return 0;
11407 }
11408
11409 static int
11410 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
11411                 struct crypto_unittest_params *ut_params,
11412                 const struct test_crypto_vector *reference,
11413                 unsigned int auth_generate)
11414 {
11415         /* Generate Crypto op data structure */
11416         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11417                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11418         TEST_ASSERT_NOT_NULL(ut_params->op,
11419                         "Failed to allocate pktmbuf offload");
11420
11421         /* Set crypto operation data parameters */
11422         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11423
11424         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11425
11426         /* set crypto operation source mbuf */
11427         sym_op->m_src = ut_params->ibuf;
11428
11429         /* digest */
11430         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11431                         ut_params->ibuf, reference->digest.len);
11432
11433         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11434                         "no room to append auth tag");
11435
11436         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11437                         ut_params->ibuf, reference->ciphertext.len);
11438
11439         if (auth_generate)
11440                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
11441         else
11442                 memcpy(sym_op->auth.digest.data,
11443                                 reference->digest.data,
11444                                 reference->digest.len);
11445
11446         debug_hexdump(stdout, "digest:",
11447                         sym_op->auth.digest.data,
11448                         reference->digest.len);
11449
11450         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
11451                         reference->iv.data, reference->iv.len);
11452
11453         sym_op->cipher.data.length = 0;
11454         sym_op->cipher.data.offset = 0;
11455
11456         sym_op->auth.data.length = reference->plaintext.len;
11457         sym_op->auth.data.offset = 0;
11458
11459         return 0;
11460 }
11461
11462 static int
11463 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
11464                 struct crypto_unittest_params *ut_params,
11465                 const struct test_crypto_vector *reference,
11466                 unsigned int auth_generate)
11467 {
11468         /* Generate Crypto op data structure */
11469         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11470                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11471         TEST_ASSERT_NOT_NULL(ut_params->op,
11472                         "Failed to allocate pktmbuf offload");
11473
11474         /* Set crypto operation data parameters */
11475         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11476
11477         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11478
11479         /* set crypto operation source mbuf */
11480         sym_op->m_src = ut_params->ibuf;
11481
11482         /* digest */
11483         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11484                         ut_params->ibuf, reference->digest.len);
11485
11486         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11487                         "no room to append auth tag");
11488
11489         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11490                         ut_params->ibuf, reference->ciphertext.len);
11491
11492         if (auth_generate)
11493                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
11494         else
11495                 memcpy(sym_op->auth.digest.data,
11496                                 reference->digest.data,
11497                                 reference->digest.len);
11498
11499         debug_hexdump(stdout, "digest:",
11500                         sym_op->auth.digest.data,
11501                         reference->digest.len);
11502
11503         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
11504                         reference->iv.data, reference->iv.len);
11505
11506         sym_op->cipher.data.length = reference->cipher_len;
11507         sym_op->cipher.data.offset = reference->cipher_offset;
11508
11509         sym_op->auth.data.length = reference->plaintext.len;
11510         sym_op->auth.data.offset = reference->auth_offset;
11511
11512         return 0;
11513 }
11514
11515 static int
11516 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
11517                 struct crypto_unittest_params *ut_params,
11518                 const struct test_crypto_vector *reference)
11519 {
11520         return create_auth_operation(ts_params, ut_params, reference, 0);
11521 }
11522
11523 static int
11524 create_auth_verify_GMAC_operation(
11525                 struct crypto_testsuite_params *ts_params,
11526                 struct crypto_unittest_params *ut_params,
11527                 const struct test_crypto_vector *reference)
11528 {
11529         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
11530 }
11531
11532 static int
11533 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
11534                 struct crypto_unittest_params *ut_params,
11535                 const struct test_crypto_vector *reference)
11536 {
11537         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
11538 }
11539
11540 static int
11541 test_authentication_verify_fail_when_data_corruption(
11542                 struct crypto_testsuite_params *ts_params,
11543                 struct crypto_unittest_params *ut_params,
11544                 const struct test_crypto_vector *reference,
11545                 unsigned int data_corrupted)
11546 {
11547         int retval;
11548
11549         uint8_t *plaintext;
11550         struct rte_cryptodev_info dev_info;
11551
11552         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11553         uint64_t feat_flags = dev_info.feature_flags;
11554
11555         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11556                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11557                 printf("Device doesn't support RAW data-path APIs.\n");
11558                 return -ENOTSUP;
11559         }
11560
11561         /* Verify the capabilities */
11562         struct rte_cryptodev_sym_capability_idx cap_idx;
11563         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11564         cap_idx.algo.auth = reference->auth_algo;
11565         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11566                         &cap_idx) == NULL)
11567                 return -ENOTSUP;
11568
11569
11570         /* Create session */
11571         retval = create_auth_session(ut_params,
11572                         ts_params->valid_devs[0],
11573                         reference,
11574                         RTE_CRYPTO_AUTH_OP_VERIFY);
11575         if (retval < 0)
11576                 return retval;
11577
11578         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11579         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11580                         "Failed to allocate input buffer in mempool");
11581
11582         /* clear mbuf payload */
11583         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11584                         rte_pktmbuf_tailroom(ut_params->ibuf));
11585
11586         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11587                         reference->plaintext.len);
11588         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11589         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
11590
11591         debug_hexdump(stdout, "plaintext:", plaintext,
11592                 reference->plaintext.len);
11593
11594         /* Create operation */
11595         retval = create_auth_verify_operation(ts_params, ut_params, reference);
11596
11597         if (retval < 0)
11598                 return retval;
11599
11600         if (data_corrupted)
11601                 data_corruption(plaintext);
11602         else
11603                 tag_corruption(plaintext, reference->plaintext.len);
11604
11605         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
11606                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11607                         ut_params->op);
11608                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
11609                         RTE_CRYPTO_OP_STATUS_SUCCESS,
11610                         "authentication not failed");
11611         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11612                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11613                                 ut_params->op, 0, 1, 0, 0);
11614         else {
11615                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
11616                         ut_params->op);
11617                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
11618         }
11619
11620         return 0;
11621 }
11622
11623 static int
11624 test_authentication_verify_GMAC_fail_when_corruption(
11625                 struct crypto_testsuite_params *ts_params,
11626                 struct crypto_unittest_params *ut_params,
11627                 const struct test_crypto_vector *reference,
11628                 unsigned int data_corrupted)
11629 {
11630         int retval;
11631         uint8_t *plaintext;
11632         struct rte_cryptodev_info dev_info;
11633
11634         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11635         uint64_t feat_flags = dev_info.feature_flags;
11636
11637         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11638                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11639                 printf("Device doesn't support RAW data-path APIs.\n");
11640                 return -ENOTSUP;
11641         }
11642
11643         /* Verify the capabilities */
11644         struct rte_cryptodev_sym_capability_idx cap_idx;
11645         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11646         cap_idx.algo.auth = reference->auth_algo;
11647         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11648                         &cap_idx) == NULL)
11649                 return -ENOTSUP;
11650
11651         /* Create session */
11652         retval = create_auth_cipher_session(ut_params,
11653                         ts_params->valid_devs[0],
11654                         reference,
11655                         RTE_CRYPTO_AUTH_OP_VERIFY,
11656                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
11657         if (retval < 0)
11658                 return retval;
11659
11660         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11661         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11662                         "Failed to allocate input buffer in mempool");
11663
11664         /* clear mbuf payload */
11665         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11666                         rte_pktmbuf_tailroom(ut_params->ibuf));
11667
11668         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11669                         reference->plaintext.len);
11670         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11671         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
11672
11673         debug_hexdump(stdout, "plaintext:", plaintext,
11674                 reference->plaintext.len);
11675
11676         /* Create operation */
11677         retval = create_auth_verify_GMAC_operation(ts_params,
11678                         ut_params,
11679                         reference);
11680
11681         if (retval < 0)
11682                 return retval;
11683
11684         if (data_corrupted)
11685                 data_corruption(plaintext);
11686         else
11687                 tag_corruption(plaintext, reference->aad.len);
11688
11689         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
11690                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11691                         ut_params->op);
11692                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
11693                         RTE_CRYPTO_OP_STATUS_SUCCESS,
11694                         "authentication not failed");
11695         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11696                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11697                                 ut_params->op, 0, 1, 0, 0);
11698         else {
11699                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
11700                         ut_params->op);
11701                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
11702         }
11703
11704         return 0;
11705 }
11706
11707 static int
11708 test_authenticated_decryption_fail_when_corruption(
11709                 struct crypto_testsuite_params *ts_params,
11710                 struct crypto_unittest_params *ut_params,
11711                 const struct test_crypto_vector *reference,
11712                 unsigned int data_corrupted)
11713 {
11714         int retval;
11715
11716         uint8_t *ciphertext;
11717         struct rte_cryptodev_info dev_info;
11718
11719         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11720         uint64_t feat_flags = dev_info.feature_flags;
11721
11722         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11723                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11724                 printf("Device doesn't support RAW data-path APIs.\n");
11725                 return -ENOTSUP;
11726         }
11727
11728         /* Verify the capabilities */
11729         struct rte_cryptodev_sym_capability_idx cap_idx;
11730         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11731         cap_idx.algo.auth = reference->auth_algo;
11732         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11733                         &cap_idx) == NULL)
11734                 return -ENOTSUP;
11735         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11736         cap_idx.algo.cipher = reference->crypto_algo;
11737         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11738                         &cap_idx) == NULL)
11739                 return -ENOTSUP;
11740
11741         /* Create session */
11742         retval = create_auth_cipher_session(ut_params,
11743                         ts_params->valid_devs[0],
11744                         reference,
11745                         RTE_CRYPTO_AUTH_OP_VERIFY,
11746                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
11747         if (retval < 0)
11748                 return retval;
11749
11750         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11751         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11752                         "Failed to allocate input buffer in mempool");
11753
11754         /* clear mbuf payload */
11755         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11756                         rte_pktmbuf_tailroom(ut_params->ibuf));
11757
11758         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11759                         reference->ciphertext.len);
11760         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
11761         memcpy(ciphertext, reference->ciphertext.data,
11762                         reference->ciphertext.len);
11763
11764         /* Create operation */
11765         retval = create_cipher_auth_verify_operation(ts_params,
11766                         ut_params,
11767                         reference);
11768
11769         if (retval < 0)
11770                 return retval;
11771
11772         if (data_corrupted)
11773                 data_corruption(ciphertext);
11774         else
11775                 tag_corruption(ciphertext, reference->ciphertext.len);
11776
11777         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
11778                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11779                         ut_params->op);
11780                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
11781                         RTE_CRYPTO_OP_STATUS_SUCCESS,
11782                         "authentication not failed");
11783         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11784                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11785                                 ut_params->op, 1, 1, 0, 0);
11786         else {
11787                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
11788                         ut_params->op);
11789                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
11790         }
11791
11792         return 0;
11793 }
11794
11795 static int
11796 test_authenticated_encryt_with_esn(
11797                 struct crypto_testsuite_params *ts_params,
11798                 struct crypto_unittest_params *ut_params,
11799                 const struct test_crypto_vector *reference)
11800 {
11801         int retval;
11802
11803         uint8_t *authciphertext, *plaintext, *auth_tag;
11804         uint16_t plaintext_pad_len;
11805         uint8_t cipher_key[reference->cipher_key.len + 1];
11806         uint8_t auth_key[reference->auth_key.len + 1];
11807         struct rte_cryptodev_info dev_info;
11808
11809         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11810         uint64_t feat_flags = dev_info.feature_flags;
11811
11812         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11813                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11814                 printf("Device doesn't support RAW data-path APIs.\n");
11815                 return -ENOTSUP;
11816         }
11817
11818         /* Verify the capabilities */
11819         struct rte_cryptodev_sym_capability_idx cap_idx;
11820         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11821         cap_idx.algo.auth = reference->auth_algo;
11822         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11823                         &cap_idx) == NULL)
11824                 return -ENOTSUP;
11825         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11826         cap_idx.algo.cipher = reference->crypto_algo;
11827         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11828                         &cap_idx) == NULL)
11829                 return -ENOTSUP;
11830
11831         /* Create session */
11832         memcpy(cipher_key, reference->cipher_key.data,
11833                         reference->cipher_key.len);
11834         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
11835
11836         /* Setup Cipher Parameters */
11837         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11838         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
11839         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11840         ut_params->cipher_xform.cipher.key.data = cipher_key;
11841         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
11842         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11843         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
11844
11845         ut_params->cipher_xform.next = &ut_params->auth_xform;
11846
11847         /* Setup Authentication Parameters */
11848         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11849         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11850         ut_params->auth_xform.auth.algo = reference->auth_algo;
11851         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
11852         ut_params->auth_xform.auth.key.data = auth_key;
11853         ut_params->auth_xform.auth.digest_length = reference->digest.len;
11854         ut_params->auth_xform.next = NULL;
11855
11856         /* Create Crypto session*/
11857         ut_params->sess = rte_cryptodev_sym_session_create(
11858                         ts_params->session_mpool);
11859
11860         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11861                                 ut_params->sess,
11862                                 &ut_params->cipher_xform,
11863                                 ts_params->session_priv_mpool);
11864
11865         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11866
11867         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11868         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11869                         "Failed to allocate input buffer in mempool");
11870
11871         /* clear mbuf payload */
11872         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11873                         rte_pktmbuf_tailroom(ut_params->ibuf));
11874
11875         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11876                         reference->plaintext.len);
11877         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11878         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
11879
11880         /* Create operation */
11881         retval = create_cipher_auth_operation(ts_params,
11882                         ut_params,
11883                         reference, 0);
11884
11885         if (retval < 0)
11886                 return retval;
11887
11888         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11889                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11890                         ut_params->op);
11891         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11892                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11893                                 ut_params->op, 1, 1, 0, 0);
11894         else
11895                 ut_params->op = process_crypto_request(
11896                         ts_params->valid_devs[0], ut_params->op);
11897
11898         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
11899
11900         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11901                         "crypto op processing failed");
11902
11903         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
11904
11905         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
11906                         ut_params->op->sym->auth.data.offset);
11907         auth_tag = authciphertext + plaintext_pad_len;
11908         debug_hexdump(stdout, "ciphertext:", authciphertext,
11909                         reference->ciphertext.len);
11910         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
11911
11912         /* Validate obuf */
11913         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11914                         authciphertext,
11915                         reference->ciphertext.data,
11916                         reference->ciphertext.len,
11917                         "Ciphertext data not as expected");
11918
11919         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11920                         auth_tag,
11921                         reference->digest.data,
11922                         reference->digest.len,
11923                         "Generated digest not as expected");
11924
11925         return TEST_SUCCESS;
11926
11927 }
11928
11929 static int
11930 test_authenticated_decrypt_with_esn(
11931                 struct crypto_testsuite_params *ts_params,
11932                 struct crypto_unittest_params *ut_params,
11933                 const struct test_crypto_vector *reference)
11934 {
11935         int retval;
11936
11937         uint8_t *ciphertext;
11938         uint8_t cipher_key[reference->cipher_key.len + 1];
11939         uint8_t auth_key[reference->auth_key.len + 1];
11940         struct rte_cryptodev_info dev_info;
11941
11942         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11943         uint64_t feat_flags = dev_info.feature_flags;
11944
11945         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11946                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11947                 printf("Device doesn't support RAW data-path APIs.\n");
11948                 return -ENOTSUP;
11949         }
11950
11951         /* Verify the capabilities */
11952         struct rte_cryptodev_sym_capability_idx cap_idx;
11953         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11954         cap_idx.algo.auth = reference->auth_algo;
11955         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11956                         &cap_idx) == NULL)
11957                 return -ENOTSUP;
11958         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11959         cap_idx.algo.cipher = reference->crypto_algo;
11960         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11961                         &cap_idx) == NULL)
11962                 return -ENOTSUP;
11963
11964         /* Create session */
11965         memcpy(cipher_key, reference->cipher_key.data,
11966                         reference->cipher_key.len);
11967         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
11968
11969         /* Setup Authentication Parameters */
11970         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11971         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
11972         ut_params->auth_xform.auth.algo = reference->auth_algo;
11973         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
11974         ut_params->auth_xform.auth.key.data = auth_key;
11975         ut_params->auth_xform.auth.digest_length = reference->digest.len;
11976         ut_params->auth_xform.next = &ut_params->cipher_xform;
11977
11978         /* Setup Cipher Parameters */
11979         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11980         ut_params->cipher_xform.next = NULL;
11981         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
11982         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
11983         ut_params->cipher_xform.cipher.key.data = cipher_key;
11984         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
11985         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11986         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
11987
11988         /* Create Crypto session*/
11989         ut_params->sess = rte_cryptodev_sym_session_create(
11990                         ts_params->session_mpool);
11991
11992         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11993                                 ut_params->sess,
11994                                 &ut_params->auth_xform,
11995                                 ts_params->session_priv_mpool);
11996
11997         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11998
11999         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12000         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12001                         "Failed to allocate input buffer in mempool");
12002
12003         /* clear mbuf payload */
12004         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12005                         rte_pktmbuf_tailroom(ut_params->ibuf));
12006
12007         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12008                         reference->ciphertext.len);
12009         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12010         memcpy(ciphertext, reference->ciphertext.data,
12011                         reference->ciphertext.len);
12012
12013         /* Create operation */
12014         retval = create_cipher_auth_verify_operation(ts_params,
12015                         ut_params,
12016                         reference);
12017
12018         if (retval < 0)
12019                 return retval;
12020
12021         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12022                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12023                         ut_params->op);
12024         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12025                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12026                                 ut_params->op, 1, 1, 0, 0);
12027         else
12028                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12029                         ut_params->op);
12030
12031         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
12032         TEST_ASSERT_EQUAL(ut_params->op->status,
12033                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12034                         "crypto op processing passed");
12035
12036         ut_params->obuf = ut_params->op->sym->m_src;
12037         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
12038
12039         return 0;
12040 }
12041
12042 static int
12043 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
12044                 const struct aead_test_data *tdata,
12045                 void *digest_mem, uint64_t digest_phys)
12046 {
12047         struct crypto_testsuite_params *ts_params = &testsuite_params;
12048         struct crypto_unittest_params *ut_params = &unittest_params;
12049
12050         const unsigned int auth_tag_len = tdata->auth_tag.len;
12051         const unsigned int iv_len = tdata->iv.len;
12052         unsigned int aad_len = tdata->aad.len;
12053         unsigned int aad_len_pad = 0;
12054
12055         /* Generate Crypto op data structure */
12056         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12057                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12058         TEST_ASSERT_NOT_NULL(ut_params->op,
12059                 "Failed to allocate symmetric crypto operation struct");
12060
12061         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12062
12063         sym_op->aead.digest.data = digest_mem;
12064
12065         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
12066                         "no room to append digest");
12067
12068         sym_op->aead.digest.phys_addr = digest_phys;
12069
12070         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
12071                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
12072                                 auth_tag_len);
12073                 debug_hexdump(stdout, "digest:",
12074                                 sym_op->aead.digest.data,
12075                                 auth_tag_len);
12076         }
12077
12078         /* Append aad data */
12079         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
12080                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12081                                 uint8_t *, IV_OFFSET);
12082
12083                 /* Copy IV 1 byte after the IV pointer, according to the API */
12084                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
12085
12086                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
12087
12088                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12089                                 ut_params->ibuf, aad_len);
12090                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12091                                 "no room to prepend aad");
12092                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12093                                 ut_params->ibuf);
12094
12095                 memset(sym_op->aead.aad.data, 0, aad_len);
12096                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
12097                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12098
12099                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12100                 debug_hexdump(stdout, "aad:",
12101                                 sym_op->aead.aad.data, aad_len);
12102         } else {
12103                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12104                                 uint8_t *, IV_OFFSET);
12105
12106                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
12107
12108                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
12109
12110                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12111                                 ut_params->ibuf, aad_len_pad);
12112                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12113                                 "no room to prepend aad");
12114                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12115                                 ut_params->ibuf);
12116
12117                 memset(sym_op->aead.aad.data, 0, aad_len);
12118                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12119
12120                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12121                 debug_hexdump(stdout, "aad:",
12122                                 sym_op->aead.aad.data, aad_len);
12123         }
12124
12125         sym_op->aead.data.length = tdata->plaintext.len;
12126         sym_op->aead.data.offset = aad_len_pad;
12127
12128         return 0;
12129 }
12130
12131 #define SGL_MAX_NO      16
12132
12133 static int
12134 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
12135                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
12136 {
12137         struct crypto_testsuite_params *ts_params = &testsuite_params;
12138         struct crypto_unittest_params *ut_params = &unittest_params;
12139         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
12140         int retval;
12141         int to_trn = 0;
12142         int to_trn_tbl[SGL_MAX_NO];
12143         int segs = 1;
12144         unsigned int trn_data = 0;
12145         uint8_t *plaintext, *ciphertext, *auth_tag;
12146         struct rte_cryptodev_info dev_info;
12147
12148         /* Verify the capabilities */
12149         struct rte_cryptodev_sym_capability_idx cap_idx;
12150         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
12151         cap_idx.algo.aead = tdata->algo;
12152         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12153                         &cap_idx) == NULL)
12154                 return -ENOTSUP;
12155
12156         /* OOP not supported with CPU crypto */
12157         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12158                 return -ENOTSUP;
12159
12160         /* Detailed check for the particular SGL support flag */
12161         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12162         if (!oop) {
12163                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
12164                 if (sgl_in && (!(dev_info.feature_flags &
12165                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
12166                         return -ENOTSUP;
12167
12168                 uint64_t feat_flags = dev_info.feature_flags;
12169
12170                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12171                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12172                         printf("Device doesn't support RAW data-path APIs.\n");
12173                         return -ENOTSUP;
12174                 }
12175         } else {
12176                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
12177                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
12178                                 tdata->plaintext.len;
12179                 /* Raw data path API does not support OOP */
12180                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12181                         return -ENOTSUP;
12182                 if (sgl_in && !sgl_out) {
12183                         if (!(dev_info.feature_flags &
12184                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
12185                                 return -ENOTSUP;
12186                 } else if (!sgl_in && sgl_out) {
12187                         if (!(dev_info.feature_flags &
12188                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
12189                                 return -ENOTSUP;
12190                 } else if (sgl_in && sgl_out) {
12191                         if (!(dev_info.feature_flags &
12192                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
12193                                 return -ENOTSUP;
12194                 }
12195         }
12196
12197         if (fragsz > tdata->plaintext.len)
12198                 fragsz = tdata->plaintext.len;
12199
12200         uint16_t plaintext_len = fragsz;
12201         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
12202
12203         if (fragsz_oop > tdata->plaintext.len)
12204                 frag_size_oop = tdata->plaintext.len;
12205
12206         int ecx = 0;
12207         void *digest_mem = NULL;
12208
12209         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
12210
12211         if (tdata->plaintext.len % fragsz != 0) {
12212                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
12213                         return 1;
12214         }       else {
12215                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
12216                         return 1;
12217         }
12218
12219         /*
12220          * For out-op-place we need to alloc another mbuf
12221          */
12222         if (oop) {
12223                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12224                 rte_pktmbuf_append(ut_params->obuf,
12225                                 frag_size_oop + prepend_len);
12226                 buf_oop = ut_params->obuf;
12227         }
12228
12229         /* Create AEAD session */
12230         retval = create_aead_session(ts_params->valid_devs[0],
12231                         tdata->algo,
12232                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
12233                         tdata->key.data, tdata->key.len,
12234                         tdata->aad.len, tdata->auth_tag.len,
12235                         tdata->iv.len);
12236         if (retval < 0)
12237                 return retval;
12238
12239         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12240
12241         /* clear mbuf payload */
12242         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12243                         rte_pktmbuf_tailroom(ut_params->ibuf));
12244
12245         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12246                         plaintext_len);
12247
12248         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12249
12250         trn_data += plaintext_len;
12251
12252         buf = ut_params->ibuf;
12253
12254         /*
12255          * Loop until no more fragments
12256          */
12257
12258         while (trn_data < tdata->plaintext.len) {
12259                 ++segs;
12260                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
12261                                 (tdata->plaintext.len - trn_data) : fragsz;
12262
12263                 to_trn_tbl[ecx++] = to_trn;
12264
12265                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12266                 buf = buf->next;
12267
12268                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
12269                                 rte_pktmbuf_tailroom(buf));
12270
12271                 /* OOP */
12272                 if (oop && !fragsz_oop) {
12273                         buf_last_oop = buf_oop->next =
12274                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
12275                         buf_oop = buf_oop->next;
12276                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
12277                                         0, rte_pktmbuf_tailroom(buf_oop));
12278                         rte_pktmbuf_append(buf_oop, to_trn);
12279                 }
12280
12281                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
12282                                 to_trn);
12283
12284                 memcpy(plaintext, tdata->plaintext.data + trn_data,
12285                                 to_trn);
12286                 trn_data += to_trn;
12287                 if (trn_data  == tdata->plaintext.len) {
12288                         if (oop) {
12289                                 if (!fragsz_oop)
12290                                         digest_mem = rte_pktmbuf_append(buf_oop,
12291                                                 tdata->auth_tag.len);
12292                         } else
12293                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
12294                                         tdata->auth_tag.len);
12295                 }
12296         }
12297
12298         uint64_t digest_phys = 0;
12299
12300         ut_params->ibuf->nb_segs = segs;
12301
12302         segs = 1;
12303         if (fragsz_oop && oop) {
12304                 to_trn = 0;
12305                 ecx = 0;
12306
12307                 if (frag_size_oop == tdata->plaintext.len) {
12308                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
12309                                 tdata->auth_tag.len);
12310
12311                         digest_phys = rte_pktmbuf_iova_offset(
12312                                         ut_params->obuf,
12313                                         tdata->plaintext.len + prepend_len);
12314                 }
12315
12316                 trn_data = frag_size_oop;
12317                 while (trn_data < tdata->plaintext.len) {
12318                         ++segs;
12319                         to_trn =
12320                                 (tdata->plaintext.len - trn_data <
12321                                                 frag_size_oop) ?
12322                                 (tdata->plaintext.len - trn_data) :
12323                                                 frag_size_oop;
12324
12325                         to_trn_tbl[ecx++] = to_trn;
12326
12327                         buf_last_oop = buf_oop->next =
12328                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
12329                         buf_oop = buf_oop->next;
12330                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
12331                                         0, rte_pktmbuf_tailroom(buf_oop));
12332                         rte_pktmbuf_append(buf_oop, to_trn);
12333
12334                         trn_data += to_trn;
12335
12336                         if (trn_data  == tdata->plaintext.len) {
12337                                 digest_mem = rte_pktmbuf_append(buf_oop,
12338                                         tdata->auth_tag.len);
12339                         }
12340                 }
12341
12342                 ut_params->obuf->nb_segs = segs;
12343         }
12344
12345         /*
12346          * Place digest at the end of the last buffer
12347          */
12348         if (!digest_phys)
12349                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
12350         if (oop && buf_last_oop)
12351                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
12352
12353         if (!digest_mem && !oop) {
12354                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12355                                 + tdata->auth_tag.len);
12356                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
12357                                 tdata->plaintext.len);
12358         }
12359
12360         /* Create AEAD operation */
12361         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
12362                         tdata, digest_mem, digest_phys);
12363
12364         if (retval < 0)
12365                 return retval;
12366
12367         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12368
12369         ut_params->op->sym->m_src = ut_params->ibuf;
12370         if (oop)
12371                 ut_params->op->sym->m_dst = ut_params->obuf;
12372
12373         /* Process crypto operation */
12374         if (oop == IN_PLACE &&
12375                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12376                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
12377         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12378                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12379                                 ut_params->op, 0, 0, 0, 0);
12380         else
12381                 TEST_ASSERT_NOT_NULL(
12382                         process_crypto_request(ts_params->valid_devs[0],
12383                         ut_params->op), "failed to process sym crypto op");
12384
12385         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12386                         "crypto op processing failed");
12387
12388
12389         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
12390                         uint8_t *, prepend_len);
12391         if (oop) {
12392                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12393                                 uint8_t *, prepend_len);
12394         }
12395
12396         if (fragsz_oop)
12397                 fragsz = fragsz_oop;
12398
12399         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12400                         ciphertext,
12401                         tdata->ciphertext.data,
12402                         fragsz,
12403                         "Ciphertext data not as expected");
12404
12405         buf = ut_params->op->sym->m_src->next;
12406         if (oop)
12407                 buf = ut_params->op->sym->m_dst->next;
12408
12409         unsigned int off = fragsz;
12410
12411         ecx = 0;
12412         while (buf) {
12413                 ciphertext = rte_pktmbuf_mtod(buf,
12414                                 uint8_t *);
12415
12416                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
12417                                 ciphertext,
12418                                 tdata->ciphertext.data + off,
12419                                 to_trn_tbl[ecx],
12420                                 "Ciphertext data not as expected");
12421
12422                 off += to_trn_tbl[ecx++];
12423                 buf = buf->next;
12424         }
12425
12426         auth_tag = digest_mem;
12427         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12428                         auth_tag,
12429                         tdata->auth_tag.data,
12430                         tdata->auth_tag.len,
12431                         "Generated auth tag not as expected");
12432
12433         return 0;
12434 }
12435
12436 static int
12437 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
12438 {
12439         return test_authenticated_encryption_SGL(
12440                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
12441 }
12442
12443 static int
12444 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
12445 {
12446         return test_authenticated_encryption_SGL(
12447                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
12448 }
12449
12450 static int
12451 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
12452 {
12453         return test_authenticated_encryption_SGL(
12454                         &gcm_test_case_8, OUT_OF_PLACE, 400,
12455                         gcm_test_case_8.plaintext.len);
12456 }
12457
12458 static int
12459 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
12460 {
12461         /* This test is not for OPENSSL PMD */
12462         if (gbl_driver_id == rte_cryptodev_driver_id_get(
12463                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
12464                 return -ENOTSUP;
12465
12466         return test_authenticated_encryption_SGL(
12467                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
12468 }
12469
12470 static int
12471 test_authentication_verify_fail_when_data_corrupted(
12472                 struct crypto_testsuite_params *ts_params,
12473                 struct crypto_unittest_params *ut_params,
12474                 const struct test_crypto_vector *reference)
12475 {
12476         return test_authentication_verify_fail_when_data_corruption(
12477                         ts_params, ut_params, reference, 1);
12478 }
12479
12480 static int
12481 test_authentication_verify_fail_when_tag_corrupted(
12482                 struct crypto_testsuite_params *ts_params,
12483                 struct crypto_unittest_params *ut_params,
12484                 const struct test_crypto_vector *reference)
12485 {
12486         return test_authentication_verify_fail_when_data_corruption(
12487                         ts_params, ut_params, reference, 0);
12488 }
12489
12490 static int
12491 test_authentication_verify_GMAC_fail_when_data_corrupted(
12492                 struct crypto_testsuite_params *ts_params,
12493                 struct crypto_unittest_params *ut_params,
12494                 const struct test_crypto_vector *reference)
12495 {
12496         return test_authentication_verify_GMAC_fail_when_corruption(
12497                         ts_params, ut_params, reference, 1);
12498 }
12499
12500 static int
12501 test_authentication_verify_GMAC_fail_when_tag_corrupted(
12502                 struct crypto_testsuite_params *ts_params,
12503                 struct crypto_unittest_params *ut_params,
12504                 const struct test_crypto_vector *reference)
12505 {
12506         return test_authentication_verify_GMAC_fail_when_corruption(
12507                         ts_params, ut_params, reference, 0);
12508 }
12509
12510 static int
12511 test_authenticated_decryption_fail_when_data_corrupted(
12512                 struct crypto_testsuite_params *ts_params,
12513                 struct crypto_unittest_params *ut_params,
12514                 const struct test_crypto_vector *reference)
12515 {
12516         return test_authenticated_decryption_fail_when_corruption(
12517                         ts_params, ut_params, reference, 1);
12518 }
12519
12520 static int
12521 test_authenticated_decryption_fail_when_tag_corrupted(
12522                 struct crypto_testsuite_params *ts_params,
12523                 struct crypto_unittest_params *ut_params,
12524                 const struct test_crypto_vector *reference)
12525 {
12526         return test_authenticated_decryption_fail_when_corruption(
12527                         ts_params, ut_params, reference, 0);
12528 }
12529
12530 static int
12531 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
12532 {
12533         return test_authentication_verify_fail_when_data_corrupted(
12534                         &testsuite_params, &unittest_params,
12535                         &hmac_sha1_test_crypto_vector);
12536 }
12537
12538 static int
12539 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
12540 {
12541         return test_authentication_verify_fail_when_tag_corrupted(
12542                         &testsuite_params, &unittest_params,
12543                         &hmac_sha1_test_crypto_vector);
12544 }
12545
12546 static int
12547 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
12548 {
12549         return test_authentication_verify_GMAC_fail_when_data_corrupted(
12550                         &testsuite_params, &unittest_params,
12551                         &aes128_gmac_test_vector);
12552 }
12553
12554 static int
12555 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
12556 {
12557         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
12558                         &testsuite_params, &unittest_params,
12559                         &aes128_gmac_test_vector);
12560 }
12561
12562 static int
12563 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
12564 {
12565         return test_authenticated_decryption_fail_when_data_corrupted(
12566                         &testsuite_params,
12567                         &unittest_params,
12568                         &aes128cbc_hmac_sha1_test_vector);
12569 }
12570
12571 static int
12572 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
12573 {
12574         return test_authenticated_decryption_fail_when_tag_corrupted(
12575                         &testsuite_params,
12576                         &unittest_params,
12577                         &aes128cbc_hmac_sha1_test_vector);
12578 }
12579
12580 static int
12581 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
12582 {
12583         return test_authenticated_encryt_with_esn(
12584                         &testsuite_params,
12585                         &unittest_params,
12586                         &aes128cbc_hmac_sha1_aad_test_vector);
12587 }
12588
12589 static int
12590 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
12591 {
12592         return test_authenticated_decrypt_with_esn(
12593                         &testsuite_params,
12594                         &unittest_params,
12595                         &aes128cbc_hmac_sha1_aad_test_vector);
12596 }
12597
12598 static int
12599 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
12600 {
12601         return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
12602 }
12603
12604 static int
12605 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
12606 {
12607         return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
12608 }
12609
12610 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
12611
12612 /* global AESNI worker IDs for the scheduler test */
12613 uint8_t aesni_ids[2];
12614
12615 static int
12616 test_scheduler_attach_slave_op(void)
12617 {
12618         struct crypto_testsuite_params *ts_params = &testsuite_params;
12619         uint8_t sched_id = ts_params->valid_devs[0];
12620         uint32_t nb_devs, i, nb_devs_attached = 0;
12621         int ret;
12622         char vdev_name[32];
12623
12624         /* create 2 AESNI_MB if necessary */
12625         nb_devs = rte_cryptodev_device_count_by_driver(
12626                         rte_cryptodev_driver_id_get(
12627                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
12628         if (nb_devs < 2) {
12629                 for (i = nb_devs; i < 2; i++) {
12630                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
12631                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
12632                                         i);
12633                         ret = rte_vdev_init(vdev_name, NULL);
12634
12635                         TEST_ASSERT(ret == 0,
12636                                 "Failed to create instance %u of"
12637                                 " pmd : %s",
12638                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
12639                 }
12640         }
12641
12642         /* attach 2 AESNI_MB cdevs */
12643         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
12644                         i++) {
12645                 struct rte_cryptodev_info info;
12646                 unsigned int session_size;
12647
12648                 rte_cryptodev_info_get(i, &info);
12649                 if (info.driver_id != rte_cryptodev_driver_id_get(
12650                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
12651                         continue;
12652
12653                 session_size = rte_cryptodev_sym_get_private_session_size(i);
12654                 /*
12655                  * Create the session mempool again, since now there are new devices
12656                  * to use the mempool.
12657                  */
12658                 if (ts_params->session_mpool) {
12659                         rte_mempool_free(ts_params->session_mpool);
12660                         ts_params->session_mpool = NULL;
12661                 }
12662                 if (ts_params->session_priv_mpool) {
12663                         rte_mempool_free(ts_params->session_priv_mpool);
12664                         ts_params->session_priv_mpool = NULL;
12665                 }
12666
12667                 if (info.sym.max_nb_sessions != 0 &&
12668                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
12669                         RTE_LOG(ERR, USER1,
12670                                         "Device does not support "
12671                                         "at least %u sessions\n",
12672                                         MAX_NB_SESSIONS);
12673                         return TEST_FAILED;
12674                 }
12675                 /*
12676                  * Create mempool with maximum number of sessions,
12677                  * to include the session headers
12678                  */
12679                 if (ts_params->session_mpool == NULL) {
12680                         ts_params->session_mpool =
12681                                 rte_cryptodev_sym_session_pool_create(
12682                                                 "test_sess_mp",
12683                                                 MAX_NB_SESSIONS, 0, 0, 0,
12684                                                 SOCKET_ID_ANY);
12685                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
12686                                         "session mempool allocation failed");
12687                 }
12688
12689                 /*
12690                  * Create mempool with maximum number of sessions,
12691                  * to include device specific session private data
12692                  */
12693                 if (ts_params->session_priv_mpool == NULL) {
12694                         ts_params->session_priv_mpool = rte_mempool_create(
12695                                         "test_sess_mp_priv",
12696                                         MAX_NB_SESSIONS,
12697                                         session_size,
12698                                         0, 0, NULL, NULL, NULL,
12699                                         NULL, SOCKET_ID_ANY,
12700                                         0);
12701
12702                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
12703                                         "session mempool allocation failed");
12704                 }
12705
12706                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
12707                 ts_params->qp_conf.mp_session_private =
12708                                 ts_params->session_priv_mpool;
12709
12710                 ret = rte_cryptodev_scheduler_worker_attach(sched_id,
12711                                 (uint8_t)i);
12712
12713                 TEST_ASSERT(ret == 0,
12714                         "Failed to attach device %u of pmd : %s", i,
12715                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
12716
12717                 aesni_ids[nb_devs_attached] = (uint8_t)i;
12718
12719                 nb_devs_attached++;
12720         }
12721
12722         return 0;
12723 }
12724
12725 static int
12726 test_scheduler_detach_slave_op(void)
12727 {
12728         struct crypto_testsuite_params *ts_params = &testsuite_params;
12729         uint8_t sched_id = ts_params->valid_devs[0];
12730         uint32_t i;
12731         int ret;
12732
12733         for (i = 0; i < 2; i++) {
12734                 ret = rte_cryptodev_scheduler_worker_detach(sched_id,
12735                                 aesni_ids[i]);
12736                 TEST_ASSERT(ret == 0,
12737                         "Failed to detach device %u", aesni_ids[i]);
12738         }
12739
12740         return 0;
12741 }
12742
12743 static int
12744 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
12745 {
12746         struct crypto_testsuite_params *ts_params = &testsuite_params;
12747         uint8_t sched_id = ts_params->valid_devs[0];
12748         /* set mode */
12749         return rte_cryptodev_scheduler_mode_set(sched_id,
12750                 scheduler_mode);
12751 }
12752
12753 static int
12754 test_scheduler_mode_roundrobin_op(void)
12755 {
12756         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
12757                         0, "Failed to set roundrobin mode");
12758         return 0;
12759
12760 }
12761
12762 static int
12763 test_scheduler_mode_multicore_op(void)
12764 {
12765         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
12766                         0, "Failed to set multicore mode");
12767
12768         return 0;
12769 }
12770
12771 static int
12772 test_scheduler_mode_failover_op(void)
12773 {
12774         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
12775                         0, "Failed to set failover mode");
12776
12777         return 0;
12778 }
12779
12780 static int
12781 test_scheduler_mode_pkt_size_distr_op(void)
12782 {
12783         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
12784                         0, "Failed to set pktsize mode");
12785
12786         return 0;
12787 }
12788
12789 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
12790         .suite_name = "Crypto Device Scheduler Unit Test Suite",
12791         .setup = testsuite_setup,
12792         .teardown = testsuite_teardown,
12793         .unit_test_cases = {
12794                 /* Multi Core */
12795                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
12796                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op),
12797                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12798                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12799                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12800                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
12801
12802                 /* Round Robin */
12803                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
12804                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op),
12805                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12806                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12807                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12808                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
12809
12810                 /* Fail over */
12811                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
12812                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op),
12813                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12814                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12815                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12816                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
12817
12818                 /* PKT SIZE */
12819                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
12820                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op),
12821                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12822                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12823                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12824                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
12825
12826                 TEST_CASES_END() /**< NULL terminate unit test array */
12827         }
12828 };
12829
12830 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
12831
12832 static struct unit_test_suite cryptodev_testsuite  = {
12833         .suite_name = "Crypto Unit Test Suite",
12834         .setup = testsuite_setup,
12835         .teardown = testsuite_teardown,
12836         .unit_test_cases = {
12837                 TEST_CASE_ST(ut_setup, ut_teardown,
12838                                 test_device_configure_invalid_dev_id),
12839                 TEST_CASE_ST(ut_setup, ut_teardown,
12840                                 test_queue_pair_descriptor_setup),
12841                 TEST_CASE_ST(ut_setup, ut_teardown,
12842                                 test_device_configure_invalid_queue_pair_ids),
12843
12844                 TEST_CASE_ST(ut_setup, ut_teardown,
12845                                 test_multi_session),
12846                 TEST_CASE_ST(ut_setup, ut_teardown,
12847                                 test_multi_session_random_usage),
12848
12849                 TEST_CASE_ST(ut_setup, ut_teardown,
12850                         test_null_invalid_operation),
12851                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
12852
12853                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12854                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12855                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12856                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12857                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all),
12858                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all),
12859                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all),
12860                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12861                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
12862
12863                 /** AES CCM Authenticated Encryption 128 bits key */
12864                 TEST_CASE_ST(ut_setup, ut_teardown,
12865                         test_AES_CCM_authenticated_encryption_test_case_128_1),
12866                 TEST_CASE_ST(ut_setup, ut_teardown,
12867                         test_AES_CCM_authenticated_encryption_test_case_128_2),
12868                 TEST_CASE_ST(ut_setup, ut_teardown,
12869                         test_AES_CCM_authenticated_encryption_test_case_128_3),
12870
12871                 /** AES CCM Authenticated Decryption 128 bits key*/
12872                 TEST_CASE_ST(ut_setup, ut_teardown,
12873                         test_AES_CCM_authenticated_decryption_test_case_128_1),
12874                 TEST_CASE_ST(ut_setup, ut_teardown,
12875                         test_AES_CCM_authenticated_decryption_test_case_128_2),
12876                 TEST_CASE_ST(ut_setup, ut_teardown,
12877                         test_AES_CCM_authenticated_decryption_test_case_128_3),
12878
12879                 /** AES CCM Authenticated Encryption 192 bits key */
12880                 TEST_CASE_ST(ut_setup, ut_teardown,
12881                         test_AES_CCM_authenticated_encryption_test_case_192_1),
12882                 TEST_CASE_ST(ut_setup, ut_teardown,
12883                         test_AES_CCM_authenticated_encryption_test_case_192_2),
12884                 TEST_CASE_ST(ut_setup, ut_teardown,
12885                         test_AES_CCM_authenticated_encryption_test_case_192_3),
12886
12887                 /** AES CCM Authenticated Decryption 192 bits key*/
12888                 TEST_CASE_ST(ut_setup, ut_teardown,
12889                         test_AES_CCM_authenticated_decryption_test_case_192_1),
12890                 TEST_CASE_ST(ut_setup, ut_teardown,
12891                         test_AES_CCM_authenticated_decryption_test_case_192_2),
12892                 TEST_CASE_ST(ut_setup, ut_teardown,
12893                         test_AES_CCM_authenticated_decryption_test_case_192_3),
12894
12895                 /** AES CCM Authenticated Encryption 256 bits key */
12896                 TEST_CASE_ST(ut_setup, ut_teardown,
12897                         test_AES_CCM_authenticated_encryption_test_case_256_1),
12898                 TEST_CASE_ST(ut_setup, ut_teardown,
12899                         test_AES_CCM_authenticated_encryption_test_case_256_2),
12900                 TEST_CASE_ST(ut_setup, ut_teardown,
12901                         test_AES_CCM_authenticated_encryption_test_case_256_3),
12902
12903                 /** AES CCM Authenticated Decryption 256 bits key*/
12904                 TEST_CASE_ST(ut_setup, ut_teardown,
12905                         test_AES_CCM_authenticated_decryption_test_case_256_1),
12906                 TEST_CASE_ST(ut_setup, ut_teardown,
12907                         test_AES_CCM_authenticated_decryption_test_case_256_2),
12908                 TEST_CASE_ST(ut_setup, ut_teardown,
12909                         test_AES_CCM_authenticated_decryption_test_case_256_3),
12910
12911                 /** AES GCM Authenticated Encryption */
12912                 TEST_CASE_ST(ut_setup, ut_teardown,
12913                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
12914                 TEST_CASE_ST(ut_setup, ut_teardown,
12915                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
12916                 TEST_CASE_ST(ut_setup, ut_teardown,
12917                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
12918                 TEST_CASE_ST(ut_setup, ut_teardown,
12919                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
12920                 TEST_CASE_ST(ut_setup, ut_teardown,
12921                         test_AES_GCM_authenticated_encryption_test_case_1),
12922                 TEST_CASE_ST(ut_setup, ut_teardown,
12923                         test_AES_GCM_authenticated_encryption_test_case_2),
12924                 TEST_CASE_ST(ut_setup, ut_teardown,
12925                         test_AES_GCM_authenticated_encryption_test_case_3),
12926                 TEST_CASE_ST(ut_setup, ut_teardown,
12927                         test_AES_GCM_authenticated_encryption_test_case_4),
12928                 TEST_CASE_ST(ut_setup, ut_teardown,
12929                         test_AES_GCM_authenticated_encryption_test_case_5),
12930                 TEST_CASE_ST(ut_setup, ut_teardown,
12931                         test_AES_GCM_authenticated_encryption_test_case_6),
12932                 TEST_CASE_ST(ut_setup, ut_teardown,
12933                         test_AES_GCM_authenticated_encryption_test_case_7),
12934                 TEST_CASE_ST(ut_setup, ut_teardown,
12935                         test_AES_GCM_authenticated_encryption_test_case_8),
12936                 TEST_CASE_ST(ut_setup, ut_teardown,
12937                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
12938
12939                 /** AES GCM Authenticated Decryption */
12940                 TEST_CASE_ST(ut_setup, ut_teardown,
12941                         test_AES_GCM_authenticated_decryption_test_case_1),
12942                 TEST_CASE_ST(ut_setup, ut_teardown,
12943                         test_AES_GCM_authenticated_decryption_test_case_2),
12944                 TEST_CASE_ST(ut_setup, ut_teardown,
12945                         test_AES_GCM_authenticated_decryption_test_case_3),
12946                 TEST_CASE_ST(ut_setup, ut_teardown,
12947                         test_AES_GCM_authenticated_decryption_test_case_4),
12948                 TEST_CASE_ST(ut_setup, ut_teardown,
12949                         test_AES_GCM_authenticated_decryption_test_case_5),
12950                 TEST_CASE_ST(ut_setup, ut_teardown,
12951                         test_AES_GCM_authenticated_decryption_test_case_6),
12952                 TEST_CASE_ST(ut_setup, ut_teardown,
12953                         test_AES_GCM_authenticated_decryption_test_case_7),
12954                 TEST_CASE_ST(ut_setup, ut_teardown,
12955                         test_AES_GCM_authenticated_decryption_test_case_8),
12956                 TEST_CASE_ST(ut_setup, ut_teardown,
12957                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
12958
12959                 /** AES GCM Authenticated Encryption 192 bits key */
12960                 TEST_CASE_ST(ut_setup, ut_teardown,
12961                         test_AES_GCM_auth_encryption_test_case_192_1),
12962                 TEST_CASE_ST(ut_setup, ut_teardown,
12963                         test_AES_GCM_auth_encryption_test_case_192_2),
12964                 TEST_CASE_ST(ut_setup, ut_teardown,
12965                         test_AES_GCM_auth_encryption_test_case_192_3),
12966                 TEST_CASE_ST(ut_setup, ut_teardown,
12967                         test_AES_GCM_auth_encryption_test_case_192_4),
12968                 TEST_CASE_ST(ut_setup, ut_teardown,
12969                         test_AES_GCM_auth_encryption_test_case_192_5),
12970                 TEST_CASE_ST(ut_setup, ut_teardown,
12971                         test_AES_GCM_auth_encryption_test_case_192_6),
12972                 TEST_CASE_ST(ut_setup, ut_teardown,
12973                         test_AES_GCM_auth_encryption_test_case_192_7),
12974
12975                 /** AES GCM Authenticated Decryption 192 bits key */
12976                 TEST_CASE_ST(ut_setup, ut_teardown,
12977                         test_AES_GCM_auth_decryption_test_case_192_1),
12978                 TEST_CASE_ST(ut_setup, ut_teardown,
12979                         test_AES_GCM_auth_decryption_test_case_192_2),
12980                 TEST_CASE_ST(ut_setup, ut_teardown,
12981                         test_AES_GCM_auth_decryption_test_case_192_3),
12982                 TEST_CASE_ST(ut_setup, ut_teardown,
12983                         test_AES_GCM_auth_decryption_test_case_192_4),
12984                 TEST_CASE_ST(ut_setup, ut_teardown,
12985                         test_AES_GCM_auth_decryption_test_case_192_5),
12986                 TEST_CASE_ST(ut_setup, ut_teardown,
12987                         test_AES_GCM_auth_decryption_test_case_192_6),
12988                 TEST_CASE_ST(ut_setup, ut_teardown,
12989                         test_AES_GCM_auth_decryption_test_case_192_7),
12990
12991                 /** AES GCM Authenticated Encryption 256 bits key */
12992                 TEST_CASE_ST(ut_setup, ut_teardown,
12993                         test_AES_GCM_auth_encryption_test_case_256_1),
12994                 TEST_CASE_ST(ut_setup, ut_teardown,
12995                         test_AES_GCM_auth_encryption_test_case_256_2),
12996                 TEST_CASE_ST(ut_setup, ut_teardown,
12997                         test_AES_GCM_auth_encryption_test_case_256_3),
12998                 TEST_CASE_ST(ut_setup, ut_teardown,
12999                         test_AES_GCM_auth_encryption_test_case_256_4),
13000                 TEST_CASE_ST(ut_setup, ut_teardown,
13001                         test_AES_GCM_auth_encryption_test_case_256_5),
13002                 TEST_CASE_ST(ut_setup, ut_teardown,
13003                         test_AES_GCM_auth_encryption_test_case_256_6),
13004                 TEST_CASE_ST(ut_setup, ut_teardown,
13005                         test_AES_GCM_auth_encryption_test_case_256_7),
13006
13007                 /** AES GCM Authenticated Decryption 256 bits key */
13008                 TEST_CASE_ST(ut_setup, ut_teardown,
13009                         test_AES_GCM_auth_decryption_test_case_256_1),
13010                 TEST_CASE_ST(ut_setup, ut_teardown,
13011                         test_AES_GCM_auth_decryption_test_case_256_2),
13012                 TEST_CASE_ST(ut_setup, ut_teardown,
13013                         test_AES_GCM_auth_decryption_test_case_256_3),
13014                 TEST_CASE_ST(ut_setup, ut_teardown,
13015                         test_AES_GCM_auth_decryption_test_case_256_4),
13016                 TEST_CASE_ST(ut_setup, ut_teardown,
13017                         test_AES_GCM_auth_decryption_test_case_256_5),
13018                 TEST_CASE_ST(ut_setup, ut_teardown,
13019                         test_AES_GCM_auth_decryption_test_case_256_6),
13020                 TEST_CASE_ST(ut_setup, ut_teardown,
13021                         test_AES_GCM_auth_decryption_test_case_256_7),
13022
13023                 /** AES GCM Authenticated Encryption big aad size */
13024                 TEST_CASE_ST(ut_setup, ut_teardown,
13025                         test_AES_GCM_auth_encryption_test_case_aad_1),
13026                 TEST_CASE_ST(ut_setup, ut_teardown,
13027                         test_AES_GCM_auth_encryption_test_case_aad_2),
13028
13029                 /** AES GCM Authenticated Decryption big aad size */
13030                 TEST_CASE_ST(ut_setup, ut_teardown,
13031                         test_AES_GCM_auth_decryption_test_case_aad_1),
13032                 TEST_CASE_ST(ut_setup, ut_teardown,
13033                         test_AES_GCM_auth_decryption_test_case_aad_2),
13034
13035                 /** Out of place tests */
13036                 TEST_CASE_ST(ut_setup, ut_teardown,
13037                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
13038                 TEST_CASE_ST(ut_setup, ut_teardown,
13039                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
13040
13041                 /** Session-less tests */
13042                 TEST_CASE_ST(ut_setup, ut_teardown,
13043                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
13044                 TEST_CASE_ST(ut_setup, ut_teardown,
13045                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
13046
13047                 /** AES GMAC Authentication */
13048                 TEST_CASE_ST(ut_setup, ut_teardown,
13049                         test_AES_GMAC_authentication_test_case_1),
13050                 TEST_CASE_ST(ut_setup, ut_teardown,
13051                         test_AES_GMAC_authentication_verify_test_case_1),
13052                 TEST_CASE_ST(ut_setup, ut_teardown,
13053                         test_AES_GMAC_authentication_test_case_2),
13054                 TEST_CASE_ST(ut_setup, ut_teardown,
13055                         test_AES_GMAC_authentication_verify_test_case_2),
13056                 TEST_CASE_ST(ut_setup, ut_teardown,
13057                         test_AES_GMAC_authentication_test_case_3),
13058                 TEST_CASE_ST(ut_setup, ut_teardown,
13059                         test_AES_GMAC_authentication_verify_test_case_3),
13060                 TEST_CASE_ST(ut_setup, ut_teardown,
13061                         test_AES_GMAC_authentication_test_case_4),
13062                 TEST_CASE_ST(ut_setup, ut_teardown,
13063                         test_AES_GMAC_authentication_verify_test_case_4),
13064                 TEST_CASE_ST(ut_setup, ut_teardown,
13065                         test_AES_GMAC_authentication_SGL_40B),
13066                 TEST_CASE_ST(ut_setup, ut_teardown,
13067                         test_AES_GMAC_authentication_SGL_80B),
13068                 TEST_CASE_ST(ut_setup, ut_teardown,
13069                         test_AES_GMAC_authentication_SGL_2048B),
13070                 TEST_CASE_ST(ut_setup, ut_teardown,
13071                         test_AES_GMAC_authentication_SGL_2047B),
13072
13073                 /** Chacha20-Poly1305 */
13074                 TEST_CASE_ST(ut_setup, ut_teardown,
13075                         test_chacha20_poly1305_encrypt_test_case_rfc8439),
13076                 TEST_CASE_ST(ut_setup, ut_teardown,
13077                         test_chacha20_poly1305_decrypt_test_case_rfc8439),
13078                 /** SNOW 3G encrypt only (UEA2) */
13079                 TEST_CASE_ST(ut_setup, ut_teardown,
13080                         test_snow3g_encryption_test_case_1),
13081                 TEST_CASE_ST(ut_setup, ut_teardown,
13082                         test_snow3g_encryption_test_case_2),
13083                 TEST_CASE_ST(ut_setup, ut_teardown,
13084                         test_snow3g_encryption_test_case_3),
13085                 TEST_CASE_ST(ut_setup, ut_teardown,
13086                         test_snow3g_encryption_test_case_4),
13087                 TEST_CASE_ST(ut_setup, ut_teardown,
13088                         test_snow3g_encryption_test_case_5),
13089
13090                 TEST_CASE_ST(ut_setup, ut_teardown,
13091                         test_snow3g_encryption_test_case_1_oop),
13092                 TEST_CASE_ST(ut_setup, ut_teardown,
13093                         test_snow3g_encryption_test_case_1_oop_sgl),
13094                 TEST_CASE_ST(ut_setup, ut_teardown,
13095                         test_snow3g_encryption_test_case_1_offset_oop),
13096                 TEST_CASE_ST(ut_setup, ut_teardown,
13097                         test_snow3g_decryption_test_case_1_oop),
13098
13099                 /** SNOW 3G generate auth, then encrypt (UEA2) */
13100                 TEST_CASE_ST(ut_setup, ut_teardown,
13101                         test_snow3g_auth_cipher_test_case_1),
13102                 TEST_CASE_ST(ut_setup, ut_teardown,
13103                         test_snow3g_auth_cipher_test_case_2),
13104                 TEST_CASE_ST(ut_setup, ut_teardown,
13105                         test_snow3g_auth_cipher_test_case_2_oop),
13106                 TEST_CASE_ST(ut_setup, ut_teardown,
13107                         test_snow3g_auth_cipher_part_digest_enc),
13108                 TEST_CASE_ST(ut_setup, ut_teardown,
13109                         test_snow3g_auth_cipher_part_digest_enc_oop),
13110                 TEST_CASE_ST(ut_setup, ut_teardown,
13111                         test_snow3g_auth_cipher_test_case_3_sgl),
13112                 TEST_CASE_ST(ut_setup, ut_teardown,
13113                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
13114                 TEST_CASE_ST(ut_setup, ut_teardown,
13115                         test_snow3g_auth_cipher_part_digest_enc_sgl),
13116                 TEST_CASE_ST(ut_setup, ut_teardown,
13117                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
13118
13119                 /** SNOW 3G decrypt (UEA2), then verify auth */
13120                 TEST_CASE_ST(ut_setup, ut_teardown,
13121                         test_snow3g_auth_cipher_verify_test_case_1),
13122                 TEST_CASE_ST(ut_setup, ut_teardown,
13123                         test_snow3g_auth_cipher_verify_test_case_2),
13124                 TEST_CASE_ST(ut_setup, ut_teardown,
13125                         test_snow3g_auth_cipher_verify_test_case_2_oop),
13126                 TEST_CASE_ST(ut_setup, ut_teardown,
13127                         test_snow3g_auth_cipher_verify_part_digest_enc),
13128                 TEST_CASE_ST(ut_setup, ut_teardown,
13129                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
13130                 TEST_CASE_ST(ut_setup, ut_teardown,
13131                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
13132                 TEST_CASE_ST(ut_setup, ut_teardown,
13133                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
13134                 TEST_CASE_ST(ut_setup, ut_teardown,
13135                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
13136                 TEST_CASE_ST(ut_setup, ut_teardown,
13137                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
13138
13139                 /** SNOW 3G decrypt only (UEA2) */
13140                 TEST_CASE_ST(ut_setup, ut_teardown,
13141                         test_snow3g_decryption_test_case_1),
13142                 TEST_CASE_ST(ut_setup, ut_teardown,
13143                         test_snow3g_decryption_test_case_2),
13144                 TEST_CASE_ST(ut_setup, ut_teardown,
13145                         test_snow3g_decryption_test_case_3),
13146                 TEST_CASE_ST(ut_setup, ut_teardown,
13147                         test_snow3g_decryption_test_case_4),
13148                 TEST_CASE_ST(ut_setup, ut_teardown,
13149                         test_snow3g_decryption_test_case_5),
13150                 TEST_CASE_ST(ut_setup, ut_teardown,
13151                         test_snow3g_decryption_with_digest_test_case_1),
13152                 TEST_CASE_ST(ut_setup, ut_teardown,
13153                         test_snow3g_hash_generate_test_case_1),
13154                 TEST_CASE_ST(ut_setup, ut_teardown,
13155                         test_snow3g_hash_generate_test_case_2),
13156                 TEST_CASE_ST(ut_setup, ut_teardown,
13157                         test_snow3g_hash_generate_test_case_3),
13158                 /* Tests with buffers which length is not byte-aligned */
13159                 TEST_CASE_ST(ut_setup, ut_teardown,
13160                         test_snow3g_hash_generate_test_case_4),
13161                 TEST_CASE_ST(ut_setup, ut_teardown,
13162                         test_snow3g_hash_generate_test_case_5),
13163                 TEST_CASE_ST(ut_setup, ut_teardown,
13164                         test_snow3g_hash_generate_test_case_6),
13165                 TEST_CASE_ST(ut_setup, ut_teardown,
13166                         test_snow3g_hash_verify_test_case_1),
13167                 TEST_CASE_ST(ut_setup, ut_teardown,
13168                         test_snow3g_hash_verify_test_case_2),
13169                 TEST_CASE_ST(ut_setup, ut_teardown,
13170                         test_snow3g_hash_verify_test_case_3),
13171                 /* Tests with buffers which length is not byte-aligned */
13172                 TEST_CASE_ST(ut_setup, ut_teardown,
13173                         test_snow3g_hash_verify_test_case_4),
13174                 TEST_CASE_ST(ut_setup, ut_teardown,
13175                         test_snow3g_hash_verify_test_case_5),
13176                 TEST_CASE_ST(ut_setup, ut_teardown,
13177                         test_snow3g_hash_verify_test_case_6),
13178                 TEST_CASE_ST(ut_setup, ut_teardown,
13179                         test_snow3g_cipher_auth_test_case_1),
13180                 TEST_CASE_ST(ut_setup, ut_teardown,
13181                         test_snow3g_auth_cipher_with_digest_test_case_1),
13182
13183                 /** ZUC encrypt only (EEA3) */
13184                 TEST_CASE_ST(ut_setup, ut_teardown,
13185                         test_zuc_encryption_test_case_1),
13186                 TEST_CASE_ST(ut_setup, ut_teardown,
13187                         test_zuc_encryption_test_case_2),
13188                 TEST_CASE_ST(ut_setup, ut_teardown,
13189                         test_zuc_encryption_test_case_3),
13190                 TEST_CASE_ST(ut_setup, ut_teardown,
13191                         test_zuc_encryption_test_case_4),
13192                 TEST_CASE_ST(ut_setup, ut_teardown,
13193                         test_zuc_encryption_test_case_5),
13194                 TEST_CASE_ST(ut_setup, ut_teardown,
13195                         test_zuc_encryption_test_case_6_sgl),
13196
13197                 /** ZUC authenticate (EIA3) */
13198                 TEST_CASE_ST(ut_setup, ut_teardown,
13199                         test_zuc_hash_generate_test_case_1),
13200                 TEST_CASE_ST(ut_setup, ut_teardown,
13201                         test_zuc_hash_generate_test_case_2),
13202                 TEST_CASE_ST(ut_setup, ut_teardown,
13203                         test_zuc_hash_generate_test_case_3),
13204                 TEST_CASE_ST(ut_setup, ut_teardown,
13205                         test_zuc_hash_generate_test_case_4),
13206                 TEST_CASE_ST(ut_setup, ut_teardown,
13207                         test_zuc_hash_generate_test_case_5),
13208                 TEST_CASE_ST(ut_setup, ut_teardown,
13209                         test_zuc_hash_generate_test_case_6),
13210                 TEST_CASE_ST(ut_setup, ut_teardown,
13211                         test_zuc_hash_generate_test_case_7),
13212                 TEST_CASE_ST(ut_setup, ut_teardown,
13213                         test_zuc_hash_generate_test_case_8),
13214
13215                 /** ZUC alg-chain (EEA3/EIA3) */
13216                 TEST_CASE_ST(ut_setup, ut_teardown,
13217                         test_zuc_cipher_auth_test_case_1),
13218                 TEST_CASE_ST(ut_setup, ut_teardown,
13219                         test_zuc_cipher_auth_test_case_2),
13220
13221                 /** ZUC generate auth, then encrypt (EEA3) */
13222                 TEST_CASE_ST(ut_setup, ut_teardown,
13223                         test_zuc_auth_cipher_test_case_1),
13224                 TEST_CASE_ST(ut_setup, ut_teardown,
13225                         test_zuc_auth_cipher_test_case_1_oop),
13226                 TEST_CASE_ST(ut_setup, ut_teardown,
13227                         test_zuc_auth_cipher_test_case_1_sgl),
13228                 TEST_CASE_ST(ut_setup, ut_teardown,
13229                         test_zuc_auth_cipher_test_case_1_oop_sgl),
13230
13231                 /** ZUC decrypt (EEA3), then verify auth */
13232                 TEST_CASE_ST(ut_setup, ut_teardown,
13233                         test_zuc_auth_cipher_verify_test_case_1),
13234                 TEST_CASE_ST(ut_setup, ut_teardown,
13235                         test_zuc_auth_cipher_verify_test_case_1_oop),
13236                 TEST_CASE_ST(ut_setup, ut_teardown,
13237                         test_zuc_auth_cipher_verify_test_case_1_sgl),
13238                 TEST_CASE_ST(ut_setup, ut_teardown,
13239                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
13240
13241                 /** HMAC_MD5 Authentication */
13242                 TEST_CASE_ST(ut_setup, ut_teardown,
13243                         test_MD5_HMAC_generate_case_1),
13244                 TEST_CASE_ST(ut_setup, ut_teardown,
13245                         test_MD5_HMAC_verify_case_1),
13246                 TEST_CASE_ST(ut_setup, ut_teardown,
13247                         test_MD5_HMAC_generate_case_2),
13248                 TEST_CASE_ST(ut_setup, ut_teardown,
13249                         test_MD5_HMAC_verify_case_2),
13250
13251                 /** KASUMI hash only (UIA1) */
13252                 TEST_CASE_ST(ut_setup, ut_teardown,
13253                         test_kasumi_hash_generate_test_case_1),
13254                 TEST_CASE_ST(ut_setup, ut_teardown,
13255                         test_kasumi_hash_generate_test_case_2),
13256                 TEST_CASE_ST(ut_setup, ut_teardown,
13257                         test_kasumi_hash_generate_test_case_3),
13258                 TEST_CASE_ST(ut_setup, ut_teardown,
13259                         test_kasumi_hash_generate_test_case_4),
13260                 TEST_CASE_ST(ut_setup, ut_teardown,
13261                         test_kasumi_hash_generate_test_case_5),
13262                 TEST_CASE_ST(ut_setup, ut_teardown,
13263                         test_kasumi_hash_generate_test_case_6),
13264
13265                 TEST_CASE_ST(ut_setup, ut_teardown,
13266                         test_kasumi_hash_verify_test_case_1),
13267                 TEST_CASE_ST(ut_setup, ut_teardown,
13268                         test_kasumi_hash_verify_test_case_2),
13269                 TEST_CASE_ST(ut_setup, ut_teardown,
13270                         test_kasumi_hash_verify_test_case_3),
13271                 TEST_CASE_ST(ut_setup, ut_teardown,
13272                         test_kasumi_hash_verify_test_case_4),
13273                 TEST_CASE_ST(ut_setup, ut_teardown,
13274                         test_kasumi_hash_verify_test_case_5),
13275
13276                 /** KASUMI encrypt only (UEA1) */
13277                 TEST_CASE_ST(ut_setup, ut_teardown,
13278                         test_kasumi_encryption_test_case_1),
13279                 TEST_CASE_ST(ut_setup, ut_teardown,
13280                         test_kasumi_encryption_test_case_1_sgl),
13281                 TEST_CASE_ST(ut_setup, ut_teardown,
13282                         test_kasumi_encryption_test_case_1_oop),
13283                 TEST_CASE_ST(ut_setup, ut_teardown,
13284                         test_kasumi_encryption_test_case_1_oop_sgl),
13285                 TEST_CASE_ST(ut_setup, ut_teardown,
13286                         test_kasumi_encryption_test_case_2),
13287                 TEST_CASE_ST(ut_setup, ut_teardown,
13288                         test_kasumi_encryption_test_case_3),
13289                 TEST_CASE_ST(ut_setup, ut_teardown,
13290                         test_kasumi_encryption_test_case_4),
13291                 TEST_CASE_ST(ut_setup, ut_teardown,
13292                         test_kasumi_encryption_test_case_5),
13293
13294                 /** KASUMI decrypt only (UEA1) */
13295                 TEST_CASE_ST(ut_setup, ut_teardown,
13296                         test_kasumi_decryption_test_case_1),
13297                 TEST_CASE_ST(ut_setup, ut_teardown,
13298                         test_kasumi_decryption_test_case_2),
13299                 TEST_CASE_ST(ut_setup, ut_teardown,
13300                         test_kasumi_decryption_test_case_3),
13301                 TEST_CASE_ST(ut_setup, ut_teardown,
13302                         test_kasumi_decryption_test_case_4),
13303                 TEST_CASE_ST(ut_setup, ut_teardown,
13304                         test_kasumi_decryption_test_case_5),
13305                 TEST_CASE_ST(ut_setup, ut_teardown,
13306                         test_kasumi_decryption_test_case_1_oop),
13307
13308                 TEST_CASE_ST(ut_setup, ut_teardown,
13309                         test_kasumi_cipher_auth_test_case_1),
13310
13311                 /** KASUMI generate auth, then encrypt (F8) */
13312                 TEST_CASE_ST(ut_setup, ut_teardown,
13313                         test_kasumi_auth_cipher_test_case_1),
13314                 TEST_CASE_ST(ut_setup, ut_teardown,
13315                         test_kasumi_auth_cipher_test_case_2),
13316                 TEST_CASE_ST(ut_setup, ut_teardown,
13317                         test_kasumi_auth_cipher_test_case_2_oop),
13318                 TEST_CASE_ST(ut_setup, ut_teardown,
13319                         test_kasumi_auth_cipher_test_case_2_sgl),
13320                 TEST_CASE_ST(ut_setup, ut_teardown,
13321                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
13322
13323                 /** KASUMI decrypt (F8), then verify auth */
13324                 TEST_CASE_ST(ut_setup, ut_teardown,
13325                         test_kasumi_auth_cipher_verify_test_case_1),
13326                 TEST_CASE_ST(ut_setup, ut_teardown,
13327                         test_kasumi_auth_cipher_verify_test_case_2),
13328                 TEST_CASE_ST(ut_setup, ut_teardown,
13329                         test_kasumi_auth_cipher_verify_test_case_2_oop),
13330                 TEST_CASE_ST(ut_setup, ut_teardown,
13331                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
13332                 TEST_CASE_ST(ut_setup, ut_teardown,
13333                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
13334
13335                 /** ESN Testcase */
13336                 TEST_CASE_ST(ut_setup, ut_teardown,
13337                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
13338                 TEST_CASE_ST(ut_setup, ut_teardown,
13339                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
13340
13341                 /** Negative tests */
13342                 TEST_CASE_ST(ut_setup, ut_teardown,
13343                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13344                 TEST_CASE_ST(ut_setup, ut_teardown,
13345                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13346                 TEST_CASE_ST(ut_setup, ut_teardown,
13347                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
13348                 TEST_CASE_ST(ut_setup, ut_teardown,
13349                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
13350                 TEST_CASE_ST(ut_setup, ut_teardown,
13351                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
13352                 TEST_CASE_ST(ut_setup, ut_teardown,
13353                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
13354                 TEST_CASE_ST(ut_setup, ut_teardown,
13355                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
13356                 TEST_CASE_ST(ut_setup, ut_teardown,
13357                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
13358                 TEST_CASE_ST(ut_setup, ut_teardown,
13359                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
13360                 TEST_CASE_ST(ut_setup, ut_teardown,
13361                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
13362                 TEST_CASE_ST(ut_setup, ut_teardown,
13363                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
13364                 TEST_CASE_ST(ut_setup, ut_teardown,
13365                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
13366                 TEST_CASE_ST(ut_setup, ut_teardown,
13367                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
13368                 TEST_CASE_ST(ut_setup, ut_teardown,
13369                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
13370                 TEST_CASE_ST(ut_setup, ut_teardown,
13371                         authentication_verify_AES128_GMAC_fail_data_corrupt),
13372                 TEST_CASE_ST(ut_setup, ut_teardown,
13373                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
13374                 TEST_CASE_ST(ut_setup, ut_teardown,
13375                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13376                 TEST_CASE_ST(ut_setup, ut_teardown,
13377                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13378
13379                 /** Mixed CIPHER + HASH algorithms */
13380                 /** AUTH AES CMAC + CIPHER AES CTR */
13381                 TEST_CASE_ST(ut_setup, ut_teardown,
13382                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
13383                 TEST_CASE_ST(ut_setup, ut_teardown,
13384                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
13385                 TEST_CASE_ST(ut_setup, ut_teardown,
13386                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
13387                 TEST_CASE_ST(ut_setup, ut_teardown,
13388                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
13389                 TEST_CASE_ST(ut_setup, ut_teardown,
13390                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
13391                 TEST_CASE_ST(ut_setup, ut_teardown,
13392                        test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
13393                 TEST_CASE_ST(ut_setup, ut_teardown,
13394                        test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
13395                 TEST_CASE_ST(ut_setup, ut_teardown,
13396                    test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
13397
13398                 /** AUTH ZUC + CIPHER SNOW3G */
13399                 TEST_CASE_ST(ut_setup, ut_teardown,
13400                         test_auth_zuc_cipher_snow_test_case_1),
13401                 TEST_CASE_ST(ut_setup, ut_teardown,
13402                         test_verify_auth_zuc_cipher_snow_test_case_1),
13403                 /** AUTH AES CMAC + CIPHER SNOW3G */
13404                 TEST_CASE_ST(ut_setup, ut_teardown,
13405                         test_auth_aes_cmac_cipher_snow_test_case_1),
13406                 TEST_CASE_ST(ut_setup, ut_teardown,
13407                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
13408                 /** AUTH ZUC + CIPHER AES CTR */
13409                 TEST_CASE_ST(ut_setup, ut_teardown,
13410                         test_auth_zuc_cipher_aes_ctr_test_case_1),
13411                 TEST_CASE_ST(ut_setup, ut_teardown,
13412                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
13413                 /** AUTH SNOW3G + CIPHER AES CTR */
13414                 TEST_CASE_ST(ut_setup, ut_teardown,
13415                         test_auth_snow_cipher_aes_ctr_test_case_1),
13416                 TEST_CASE_ST(ut_setup, ut_teardown,
13417                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
13418                 /** AUTH SNOW3G + CIPHER ZUC */
13419                 TEST_CASE_ST(ut_setup, ut_teardown,
13420                         test_auth_snow_cipher_zuc_test_case_1),
13421                 TEST_CASE_ST(ut_setup, ut_teardown,
13422                         test_verify_auth_snow_cipher_zuc_test_case_1),
13423                 /** AUTH AES CMAC + CIPHER ZUC */
13424                 TEST_CASE_ST(ut_setup, ut_teardown,
13425                         test_auth_aes_cmac_cipher_zuc_test_case_1),
13426                 TEST_CASE_ST(ut_setup, ut_teardown,
13427                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
13428
13429                 /** AUTH NULL + CIPHER SNOW3G */
13430                 TEST_CASE_ST(ut_setup, ut_teardown,
13431                         test_auth_null_cipher_snow_test_case_1),
13432                 TEST_CASE_ST(ut_setup, ut_teardown,
13433                         test_verify_auth_null_cipher_snow_test_case_1),
13434                 /** AUTH NULL + CIPHER ZUC */
13435                 TEST_CASE_ST(ut_setup, ut_teardown,
13436                         test_auth_null_cipher_zuc_test_case_1),
13437                 TEST_CASE_ST(ut_setup, ut_teardown,
13438                         test_verify_auth_null_cipher_zuc_test_case_1),
13439                 /** AUTH SNOW3G + CIPHER NULL */
13440                 TEST_CASE_ST(ut_setup, ut_teardown,
13441                         test_auth_snow_cipher_null_test_case_1),
13442                 TEST_CASE_ST(ut_setup, ut_teardown,
13443                         test_verify_auth_snow_cipher_null_test_case_1),
13444                 /** AUTH ZUC + CIPHER NULL */
13445                 TEST_CASE_ST(ut_setup, ut_teardown,
13446                         test_auth_zuc_cipher_null_test_case_1),
13447                 TEST_CASE_ST(ut_setup, ut_teardown,
13448                         test_verify_auth_zuc_cipher_null_test_case_1),
13449                 /** AUTH NULL + CIPHER AES CTR */
13450                 TEST_CASE_ST(ut_setup, ut_teardown,
13451                         test_auth_null_cipher_aes_ctr_test_case_1),
13452                 TEST_CASE_ST(ut_setup, ut_teardown,
13453                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
13454                 /** AUTH AES CMAC + CIPHER NULL */
13455                 TEST_CASE_ST(ut_setup, ut_teardown,
13456                         test_auth_aes_cmac_cipher_null_test_case_1),
13457                 TEST_CASE_ST(ut_setup, ut_teardown,
13458                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
13459
13460 #ifdef RTE_LIBRTE_SECURITY
13461                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13462                         test_PDCP_PROTO_all),
13463                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13464                         test_DOCSIS_PROTO_all),
13465 #endif
13466                 TEST_CASES_END() /**< NULL terminate unit test array */
13467         }
13468 };
13469
13470 static struct unit_test_suite cryptodev_virtio_testsuite = {
13471         .suite_name = "Crypto VIRTIO Unit Test Suite",
13472         .setup = testsuite_setup,
13473         .teardown = testsuite_teardown,
13474         .unit_test_cases = {
13475                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13476
13477                 TEST_CASES_END() /**< NULL terminate unit test array */
13478         }
13479 };
13480
13481 static struct unit_test_suite cryptodev_caam_jr_testsuite  = {
13482         .suite_name = "Crypto CAAM JR Unit Test Suite",
13483         .setup = testsuite_setup,
13484         .teardown = testsuite_teardown,
13485         .unit_test_cases = {
13486                 TEST_CASE_ST(ut_setup, ut_teardown,
13487                              test_device_configure_invalid_dev_id),
13488                 TEST_CASE_ST(ut_setup, ut_teardown,
13489                              test_multi_session),
13490
13491                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13492                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13493                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13494                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13495                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13496
13497                 TEST_CASES_END() /**< NULL terminate unit test array */
13498         }
13499 };
13500
13501 static struct unit_test_suite cryptodev_mrvl_testsuite  = {
13502         .suite_name = "Crypto Device Marvell Component Test Suite",
13503         .setup = testsuite_setup,
13504         .teardown = testsuite_teardown,
13505         .unit_test_cases = {
13506                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13507                 TEST_CASE_ST(ut_setup, ut_teardown,
13508                                 test_multi_session_random_usage),
13509                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13510                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13511                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13512                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13513                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13514
13515                 /** Negative tests */
13516                 TEST_CASE_ST(ut_setup, ut_teardown,
13517                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13518                 TEST_CASE_ST(ut_setup, ut_teardown,
13519                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13520                 TEST_CASE_ST(ut_setup, ut_teardown,
13521                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13522                 TEST_CASE_ST(ut_setup, ut_teardown,
13523                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13524
13525                 TEST_CASES_END() /**< NULL terminate unit test array */
13526         }
13527 };
13528
13529 static struct unit_test_suite cryptodev_ccp_testsuite  = {
13530         .suite_name = "Crypto Device CCP Unit Test Suite",
13531         .setup = testsuite_setup,
13532         .teardown = testsuite_teardown,
13533         .unit_test_cases = {
13534                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13535                 TEST_CASE_ST(ut_setup, ut_teardown,
13536                                 test_multi_session_random_usage),
13537                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13538                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13539                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13540                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13541                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13542
13543                 /** Negative tests */
13544                 TEST_CASE_ST(ut_setup, ut_teardown,
13545                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13546                 TEST_CASE_ST(ut_setup, ut_teardown,
13547                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13548                 TEST_CASE_ST(ut_setup, ut_teardown,
13549                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13550                 TEST_CASE_ST(ut_setup, ut_teardown,
13551                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13552
13553                 TEST_CASES_END() /**< NULL terminate unit test array */
13554         }
13555 };
13556
13557 static int
13558 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
13559 {
13560         gbl_driver_id = rte_cryptodev_driver_id_get(
13561                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
13562
13563         if (gbl_driver_id == -1) {
13564                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
13565                 return TEST_SKIPPED;
13566         }
13567
13568         return unit_test_suite_runner(&cryptodev_testsuite);
13569 }
13570
13571 static int
13572 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
13573 {
13574         gbl_driver_id = rte_cryptodev_driver_id_get(
13575                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
13576
13577         if (gbl_driver_id == -1) {
13578                 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded.\n");
13579                 return TEST_FAILED;
13580         }
13581
13582         return unit_test_suite_runner(&cryptodev_virtio_testsuite);
13583 }
13584
13585 static int
13586 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
13587 {
13588         gbl_driver_id = rte_cryptodev_driver_id_get(
13589                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13590
13591         if (gbl_driver_id == -1) {
13592                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
13593                 return TEST_SKIPPED;
13594         }
13595
13596         return unit_test_suite_runner(&cryptodev_testsuite);
13597 }
13598
13599 static int
13600 test_cryptodev_cpu_aesni_mb(void)
13601 {
13602         int32_t rc;
13603         enum rte_security_session_action_type at;
13604
13605         gbl_driver_id = rte_cryptodev_driver_id_get(
13606                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13607
13608         if (gbl_driver_id == -1) {
13609                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
13610                 return TEST_SKIPPED;
13611         }
13612
13613         at = gbl_action_type;
13614         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
13615         rc = unit_test_suite_runner(&cryptodev_testsuite);
13616         gbl_action_type = at;
13617         return rc;
13618 }
13619
13620 static int
13621 test_cryptodev_openssl(void)
13622 {
13623         gbl_driver_id = rte_cryptodev_driver_id_get(
13624                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
13625
13626         if (gbl_driver_id == -1) {
13627                 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
13628                 return TEST_SKIPPED;
13629         }
13630
13631         return unit_test_suite_runner(&cryptodev_testsuite);
13632 }
13633
13634 static int
13635 test_cryptodev_aesni_gcm(void)
13636 {
13637         gbl_driver_id = rte_cryptodev_driver_id_get(
13638                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
13639
13640         if (gbl_driver_id == -1) {
13641                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n");
13642                 return TEST_SKIPPED;
13643         }
13644
13645         return unit_test_suite_runner(&cryptodev_testsuite);
13646 }
13647
13648 static int
13649 test_cryptodev_cpu_aesni_gcm(void)
13650 {
13651         int32_t rc;
13652         enum rte_security_session_action_type at;
13653
13654         gbl_driver_id = rte_cryptodev_driver_id_get(
13655                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
13656
13657         if (gbl_driver_id == -1) {
13658                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n");
13659                 return TEST_SKIPPED;
13660         }
13661
13662         at = gbl_action_type;
13663         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
13664         rc = unit_test_suite_runner(&cryptodev_testsuite);
13665         gbl_action_type = at;
13666         return rc;
13667 }
13668
13669 static int
13670 test_cryptodev_null(void)
13671 {
13672         gbl_driver_id = rte_cryptodev_driver_id_get(
13673                         RTE_STR(CRYPTODEV_NAME_NULL_PMD));
13674
13675         if (gbl_driver_id == -1) {
13676                 RTE_LOG(ERR, USER1, "NULL PMD must be loaded.\n");
13677                 return TEST_SKIPPED;
13678         }
13679
13680         return unit_test_suite_runner(&cryptodev_testsuite);
13681 }
13682
13683 static int
13684 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
13685 {
13686         gbl_driver_id = rte_cryptodev_driver_id_get(
13687                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
13688
13689         if (gbl_driver_id == -1) {
13690                 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded.\n");
13691                 return TEST_SKIPPED;
13692         }
13693
13694         return unit_test_suite_runner(&cryptodev_testsuite);
13695 }
13696
13697 static int
13698 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
13699 {
13700         gbl_driver_id = rte_cryptodev_driver_id_get(
13701                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
13702
13703         if (gbl_driver_id == -1) {
13704                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n");
13705                 return TEST_SKIPPED;
13706         }
13707
13708         return unit_test_suite_runner(&cryptodev_testsuite);
13709 }
13710
13711 static int
13712 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
13713 {
13714         gbl_driver_id = rte_cryptodev_driver_id_get(
13715                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
13716
13717         if (gbl_driver_id == -1) {
13718                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n");
13719                 return TEST_SKIPPED;
13720         }
13721
13722         return unit_test_suite_runner(&cryptodev_testsuite);
13723 }
13724
13725 static int
13726 test_cryptodev_armv8(void)
13727 {
13728         gbl_driver_id = rte_cryptodev_driver_id_get(
13729                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
13730
13731         if (gbl_driver_id == -1) {
13732                 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded.\n");
13733                 return TEST_SKIPPED;
13734         }
13735
13736         return unit_test_suite_runner(&cryptodev_testsuite);
13737 }
13738
13739 static int
13740 test_cryptodev_mrvl(void)
13741 {
13742         gbl_driver_id = rte_cryptodev_driver_id_get(
13743                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
13744
13745         if (gbl_driver_id == -1) {
13746                 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded.\n");
13747                 return TEST_SKIPPED;
13748         }
13749
13750         return unit_test_suite_runner(&cryptodev_mrvl_testsuite);
13751 }
13752
13753 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
13754
13755 static int
13756 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
13757 {
13758         gbl_driver_id = rte_cryptodev_driver_id_get(
13759                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13760
13761         if (gbl_driver_id == -1) {
13762                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
13763                 return TEST_SKIPPED;
13764         }
13765
13766         if (rte_cryptodev_driver_id_get(
13767                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
13768                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
13769                 return TEST_SKIPPED;
13770 }
13771         return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
13772 }
13773
13774 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
13775
13776 #endif
13777
13778 static int
13779 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
13780 {
13781         gbl_driver_id = rte_cryptodev_driver_id_get(
13782                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
13783
13784         if (gbl_driver_id == -1) {
13785                 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded.\n");
13786                 return TEST_SKIPPED;
13787         }
13788
13789         return unit_test_suite_runner(&cryptodev_testsuite);
13790 }
13791
13792 static int
13793 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
13794 {
13795         gbl_driver_id = rte_cryptodev_driver_id_get(
13796                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
13797
13798         if (gbl_driver_id == -1) {
13799                 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded.\n");
13800                 return TEST_SKIPPED;
13801         }
13802
13803         return unit_test_suite_runner(&cryptodev_testsuite);
13804 }
13805
13806 static int
13807 test_cryptodev_ccp(void)
13808 {
13809         gbl_driver_id = rte_cryptodev_driver_id_get(
13810                         RTE_STR(CRYPTODEV_NAME_CCP_PMD));
13811
13812         if (gbl_driver_id == -1) {
13813                 RTE_LOG(ERR, USER1, "CCP PMD must be loaded.\n");
13814                 return TEST_FAILED;
13815         }
13816
13817         return unit_test_suite_runner(&cryptodev_ccp_testsuite);
13818 }
13819
13820 static int
13821 test_cryptodev_octeontx(void)
13822 {
13823         gbl_driver_id = rte_cryptodev_driver_id_get(
13824                         RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
13825         if (gbl_driver_id == -1) {
13826                 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
13827                 return TEST_FAILED;
13828         }
13829         return unit_test_suite_runner(&cryptodev_testsuite);
13830 }
13831
13832 static int
13833 test_cryptodev_octeontx2(void)
13834 {
13835         gbl_driver_id = rte_cryptodev_driver_id_get(
13836                         RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
13837         if (gbl_driver_id == -1) {
13838                 RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded.\n");
13839                 return TEST_FAILED;
13840         }
13841         return unit_test_suite_runner(&cryptodev_testsuite);
13842 }
13843
13844 static int
13845 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/)
13846 {
13847         gbl_driver_id = rte_cryptodev_driver_id_get(
13848                         RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
13849
13850         if (gbl_driver_id == -1) {
13851                 RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded.\n");
13852                 return TEST_FAILED;
13853         }
13854
13855         return unit_test_suite_runner(&cryptodev_caam_jr_testsuite);
13856 }
13857
13858 static int
13859 test_cryptodev_nitrox(void)
13860 {
13861         gbl_driver_id = rte_cryptodev_driver_id_get(
13862                         RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
13863
13864         if (gbl_driver_id == -1) {
13865                 RTE_LOG(ERR, USER1, "NITROX PMD must be loaded.\n");
13866                 return TEST_FAILED;
13867         }
13868
13869         return unit_test_suite_runner(&cryptodev_testsuite);
13870 }
13871
13872 static int
13873 test_cryptodev_bcmfs(void)
13874 {
13875         gbl_driver_id = rte_cryptodev_driver_id_get(
13876                         RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
13877
13878         if (gbl_driver_id == -1) {
13879                 RTE_LOG(ERR, USER1, "BCMFS PMD must be loaded.\n");
13880                 return TEST_FAILED;
13881         }
13882
13883         return unit_test_suite_runner(&cryptodev_testsuite);
13884 }
13885
13886 static int
13887 test_cryptodev_qat_raw_api(void /*argv __rte_unused, int argc __rte_unused*/)
13888 {
13889         int ret;
13890
13891         gbl_driver_id = rte_cryptodev_driver_id_get(
13892                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
13893
13894         if (gbl_driver_id == -1) {
13895                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check that both "
13896                 "CONFIG_RTE_LIBRTE_PMD_QAT and CONFIG_RTE_LIBRTE_PMD_QAT_SYM "
13897                 "are enabled in config file to run this testsuite.\n");
13898                 return TEST_SKIPPED;
13899         }
13900
13901         global_api_test_type = CRYPTODEV_RAW_API_TEST;
13902         ret = unit_test_suite_runner(&cryptodev_testsuite);
13903         global_api_test_type = CRYPTODEV_API_TEST;
13904
13905         return ret;
13906 }
13907
13908 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
13909                 test_cryptodev_qat_raw_api);
13910 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
13911 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
13912 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
13913         test_cryptodev_cpu_aesni_mb);
13914 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
13915 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
13916 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
13917         test_cryptodev_cpu_aesni_gcm);
13918 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
13919 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
13920 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
13921 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
13922 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
13923 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
13924 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
13925 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
13926 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
13927 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
13928 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
13929 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
13930 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
13931 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
13932 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);