test/crypto: fix auth-cipher compare length in OOP
[dpdk.git] / app / test / test_cryptodev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation
3  * Copyright 2020 NXP
4  */
5
6 #include <time.h>
7
8 #include <rte_common.h>
9 #include <rte_hexdump.h>
10 #include <rte_mbuf.h>
11 #include <rte_malloc.h>
12 #include <rte_memcpy.h>
13 #include <rte_pause.h>
14 #include <rte_bus_vdev.h>
15 #include <rte_ether.h>
16
17 #include <rte_crypto.h>
18 #include <rte_cryptodev.h>
19 #include <rte_cryptodev_pmd.h>
20 #include <rte_string_fns.h>
21
22 #ifdef RTE_CRYPTO_SCHEDULER
23 #include <rte_cryptodev_scheduler.h>
24 #include <rte_cryptodev_scheduler_operations.h>
25 #endif
26
27 #include <rte_lcore.h>
28
29 #include "test.h"
30 #include "test_cryptodev.h"
31
32 #include "test_cryptodev_blockcipher.h"
33 #include "test_cryptodev_aes_test_vectors.h"
34 #include "test_cryptodev_des_test_vectors.h"
35 #include "test_cryptodev_hash_test_vectors.h"
36 #include "test_cryptodev_kasumi_test_vectors.h"
37 #include "test_cryptodev_kasumi_hash_test_vectors.h"
38 #include "test_cryptodev_snow3g_test_vectors.h"
39 #include "test_cryptodev_snow3g_hash_test_vectors.h"
40 #include "test_cryptodev_zuc_test_vectors.h"
41 #include "test_cryptodev_aead_test_vectors.h"
42 #include "test_cryptodev_hmac_test_vectors.h"
43 #include "test_cryptodev_mixed_test_vectors.h"
44 #ifdef RTE_LIB_SECURITY
45 #include "test_cryptodev_security_pdcp_test_vectors.h"
46 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
47 #include "test_cryptodev_security_pdcp_test_func.h"
48 #include "test_cryptodev_security_docsis_test_vectors.h"
49
50 #define SDAP_DISABLED   0
51 #define SDAP_ENABLED    1
52 #endif
53
54 #define VDEV_ARGS_SIZE 100
55 #define MAX_NB_SESSIONS 4
56
57 #define MAX_DRV_SERVICE_CTX_SIZE 256
58
59 #define MAX_RAW_DEQUEUE_COUNT   65535
60
61 #define IN_PLACE 0
62 #define OUT_OF_PLACE 1
63
64 #ifndef ARRAY_SIZE
65 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
66 #endif
67
68 static int gbl_driver_id;
69
70 static enum rte_security_session_action_type gbl_action_type =
71         RTE_SECURITY_ACTION_TYPE_NONE;
72
73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
74
75 struct crypto_testsuite_params {
76         struct rte_mempool *mbuf_pool;
77         struct rte_mempool *large_mbuf_pool;
78         struct rte_mempool *op_mpool;
79         struct rte_mempool *session_mpool;
80         struct rte_mempool *session_priv_mpool;
81         struct rte_cryptodev_config conf;
82         struct rte_cryptodev_qp_conf qp_conf;
83
84         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
85         uint8_t valid_dev_count;
86 };
87
88 struct crypto_unittest_params {
89         struct rte_crypto_sym_xform cipher_xform;
90         struct rte_crypto_sym_xform auth_xform;
91         struct rte_crypto_sym_xform aead_xform;
92 #ifdef RTE_LIB_SECURITY
93         struct rte_security_docsis_xform docsis_xform;
94 #endif
95
96         union {
97                 struct rte_cryptodev_sym_session *sess;
98 #ifdef RTE_LIB_SECURITY
99                 struct rte_security_session *sec_session;
100 #endif
101         };
102 #ifdef RTE_LIB_SECURITY
103         enum rte_security_session_action_type type;
104 #endif
105         struct rte_crypto_op *op;
106
107         struct rte_mbuf *obuf, *ibuf;
108
109         uint8_t *digest;
110 };
111
112 #define ALIGN_POW2_ROUNDUP(num, align) \
113         (((num) + (align) - 1) & ~((align) - 1))
114
115 /*
116  * Forward declarations.
117  */
118 static int
119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
120                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
121                 uint8_t *hmac_key);
122
123 static int
124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
125                 struct crypto_unittest_params *ut_params,
126                 struct crypto_testsuite_params *ts_param,
127                 const uint8_t *cipher,
128                 const uint8_t *digest,
129                 const uint8_t *iv);
130
131 static struct rte_mbuf *
132 setup_test_string(struct rte_mempool *mpool,
133                 const char *string, size_t len, uint8_t blocksize)
134 {
135         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
136         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
137
138         memset(m->buf_addr, 0, m->buf_len);
139         if (m) {
140                 char *dst = rte_pktmbuf_append(m, t_len);
141
142                 if (!dst) {
143                         rte_pktmbuf_free(m);
144                         return NULL;
145                 }
146                 if (string != NULL)
147                         rte_memcpy(dst, string, t_len);
148                 else
149                         memset(dst, 0, t_len);
150         }
151
152         return m;
153 }
154
155 /* Get number of bytes in X bits (rounding up) */
156 static uint32_t
157 ceil_byte_length(uint32_t num_bits)
158 {
159         if (num_bits % 8)
160                 return ((num_bits >> 3) + 1);
161         else
162                 return (num_bits >> 3);
163 }
164
165 static void
166 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused,
167                 uint8_t is_op_success)
168 {
169         struct rte_crypto_op *op = user_data;
170         op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
171                         RTE_CRYPTO_OP_STATUS_ERROR;
172 }
173
174 void
175 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
176                 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
177                 uint8_t len_in_bits, uint8_t cipher_iv_len)
178 {
179         struct rte_crypto_sym_op *sop = op->sym;
180         struct rte_crypto_op *ret_op = NULL;
181         struct rte_crypto_vec data_vec[UINT8_MAX];
182         struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
183         union rte_crypto_sym_ofs ofs;
184         struct rte_crypto_sym_vec vec;
185         struct rte_crypto_sgl sgl;
186         uint32_t max_len;
187         union rte_cryptodev_session_ctx sess;
188         uint32_t count = 0;
189         struct rte_crypto_raw_dp_ctx *ctx;
190         uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
191                         auth_len = 0;
192         int32_t n;
193         uint32_t n_success;
194         int ctx_service_size;
195         int32_t status = 0;
196         int enqueue_status, dequeue_status;
197
198         ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
199         if (ctx_service_size < 0) {
200                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
201                 return;
202         }
203
204         ctx = malloc(ctx_service_size);
205         if (!ctx) {
206                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
207                 return;
208         }
209
210         /* Both are enums, setting crypto_sess will suit any session type */
211         sess.crypto_sess = op->sym->session;
212
213         if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
214                         op->sess_type, sess, 0) < 0) {
215                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
216                 goto exit;
217         }
218
219         cipher_iv.iova = 0;
220         cipher_iv.va = NULL;
221         aad_auth_iv.iova = 0;
222         aad_auth_iv.va = NULL;
223         digest.iova = 0;
224         digest.va = NULL;
225         sgl.vec = data_vec;
226         vec.num = 1;
227         vec.sgl = &sgl;
228         vec.iv = &cipher_iv;
229         vec.digest = &digest;
230         vec.aad = &aad_auth_iv;
231         vec.status = &status;
232
233         ofs.raw = 0;
234
235         if (is_cipher && is_auth) {
236                 cipher_offset = sop->cipher.data.offset;
237                 cipher_len = sop->cipher.data.length;
238                 auth_offset = sop->auth.data.offset;
239                 auth_len = sop->auth.data.length;
240                 max_len = RTE_MAX(cipher_offset + cipher_len,
241                                 auth_offset + auth_len);
242                 if (len_in_bits) {
243                         max_len = max_len >> 3;
244                         cipher_offset = cipher_offset >> 3;
245                         auth_offset = auth_offset >> 3;
246                         cipher_len = cipher_len >> 3;
247                         auth_len = auth_len >> 3;
248                 }
249                 ofs.ofs.cipher.head = cipher_offset;
250                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
251                 ofs.ofs.auth.head = auth_offset;
252                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
253                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
254                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
255                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
256                                 op, void *, IV_OFFSET + cipher_iv_len);
257                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
258                                 cipher_iv_len);
259                 digest.va = (void *)sop->auth.digest.data;
260                 digest.iova = sop->auth.digest.phys_addr;
261
262         } else if (is_cipher) {
263                 cipher_offset = sop->cipher.data.offset;
264                 cipher_len = sop->cipher.data.length;
265                 max_len = cipher_len + cipher_offset;
266                 if (len_in_bits) {
267                         max_len = max_len >> 3;
268                         cipher_offset = cipher_offset >> 3;
269                         cipher_len = cipher_len >> 3;
270                 }
271                 ofs.ofs.cipher.head = cipher_offset;
272                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
273                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
274                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
275
276         } else if (is_auth) {
277                 auth_offset = sop->auth.data.offset;
278                 auth_len = sop->auth.data.length;
279                 max_len = auth_len + auth_offset;
280                 if (len_in_bits) {
281                         max_len = max_len >> 3;
282                         auth_offset = auth_offset >> 3;
283                         auth_len = auth_len >> 3;
284                 }
285                 ofs.ofs.auth.head = auth_offset;
286                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
287                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
288                                 op, void *, IV_OFFSET + cipher_iv_len);
289                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
290                                 cipher_iv_len);
291                 digest.va = (void *)sop->auth.digest.data;
292                 digest.iova = sop->auth.digest.phys_addr;
293
294         } else { /* aead */
295                 cipher_offset = sop->aead.data.offset;
296                 cipher_len = sop->aead.data.length;
297                 max_len = cipher_len + cipher_offset;
298                 if (len_in_bits) {
299                         max_len = max_len >> 3;
300                         cipher_offset = cipher_offset >> 3;
301                         cipher_len = cipher_len >> 3;
302                 }
303                 ofs.ofs.cipher.head = cipher_offset;
304                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
305                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
306                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
307                 aad_auth_iv.va = (void *)sop->aead.aad.data;
308                 aad_auth_iv.iova = sop->aead.aad.phys_addr;
309                 digest.va = (void *)sop->aead.digest.data;
310                 digest.iova = sop->aead.digest.phys_addr;
311         }
312
313         n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
314                         data_vec, RTE_DIM(data_vec));
315         if (n < 0 || n > sop->m_src->nb_segs) {
316                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
317                 goto exit;
318         }
319
320         sgl.num = n;
321
322         if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
323                         &enqueue_status) < 1) {
324                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
325                 goto exit;
326         }
327
328         if (enqueue_status == 0) {
329                 status = rte_cryptodev_raw_enqueue_done(ctx, 1);
330                 if (status < 0) {
331                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
332                         goto exit;
333                 }
334         } else if (enqueue_status < 0) {
335                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
336                 goto exit;
337         }
338
339         n = n_success = 0;
340         while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
341                 n = rte_cryptodev_raw_dequeue_burst(ctx,
342                         NULL, 1, post_process_raw_dp_op,
343                                 (void **)&ret_op, 0, &n_success,
344                                 &dequeue_status);
345                 if (dequeue_status < 0) {
346                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
347                         goto exit;
348                 }
349                 if (n == 0)
350                         rte_pause();
351         }
352
353         if (n == 1 && dequeue_status == 0) {
354                 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
355                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
356                         goto exit;
357                 }
358         }
359
360         op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
361                         n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
362                                         RTE_CRYPTO_OP_STATUS_SUCCESS;
363
364 exit:
365         free(ctx);
366 }
367
368 static void
369 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
370 {
371         int32_t n, st;
372         struct rte_crypto_sym_op *sop;
373         union rte_crypto_sym_ofs ofs;
374         struct rte_crypto_sgl sgl;
375         struct rte_crypto_sym_vec symvec;
376         struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
377         struct rte_crypto_vec vec[UINT8_MAX];
378
379         sop = op->sym;
380
381         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
382                 sop->aead.data.length, vec, RTE_DIM(vec));
383
384         if (n < 0 || n != sop->m_src->nb_segs) {
385                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
386                 return;
387         }
388
389         sgl.vec = vec;
390         sgl.num = n;
391         symvec.sgl = &sgl;
392         symvec.iv = &iv_ptr;
393         symvec.digest = &digest_ptr;
394         symvec.aad = &aad_ptr;
395         symvec.status = &st;
396         symvec.num = 1;
397
398         /* for CPU crypto the IOVA address is not required */
399         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
400         digest_ptr.va = (void *)sop->aead.digest.data;
401         aad_ptr.va = (void *)sop->aead.aad.data;
402
403         ofs.raw = 0;
404
405         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
406                 &symvec);
407
408         if (n != 1)
409                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
410         else
411                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
412 }
413
414 static void
415 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
416 {
417         int32_t n, st;
418         struct rte_crypto_sym_op *sop;
419         union rte_crypto_sym_ofs ofs;
420         struct rte_crypto_sgl sgl;
421         struct rte_crypto_sym_vec symvec;
422         struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
423         struct rte_crypto_vec vec[UINT8_MAX];
424
425         sop = op->sym;
426
427         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
428                 sop->auth.data.length, vec, RTE_DIM(vec));
429
430         if (n < 0 || n != sop->m_src->nb_segs) {
431                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
432                 return;
433         }
434
435         sgl.vec = vec;
436         sgl.num = n;
437         symvec.sgl = &sgl;
438         symvec.iv = &iv_ptr;
439         symvec.digest = &digest_ptr;
440         symvec.status = &st;
441         symvec.num = 1;
442
443         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
444         digest_ptr.va = (void *)sop->auth.digest.data;
445
446         ofs.raw = 0;
447         ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
448         ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
449                 (sop->cipher.data.offset + sop->cipher.data.length);
450
451         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
452                 &symvec);
453
454         if (n != 1)
455                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
456         else
457                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
458 }
459
460 static struct rte_crypto_op *
461 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
462 {
463
464         RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
465
466         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
467                 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
468                 return NULL;
469         }
470
471         op = NULL;
472
473         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
474                 rte_pause();
475
476         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
477                 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
478                 return NULL;
479         }
480
481         return op;
482 }
483
484 static struct crypto_testsuite_params testsuite_params = { NULL };
485 static struct crypto_unittest_params unittest_params;
486
487 static int
488 testsuite_setup(void)
489 {
490         struct crypto_testsuite_params *ts_params = &testsuite_params;
491         struct rte_cryptodev_info info;
492         uint32_t i = 0, nb_devs, dev_id;
493         int ret;
494         uint16_t qp_id;
495
496         memset(ts_params, 0, sizeof(*ts_params));
497
498         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
499         if (ts_params->mbuf_pool == NULL) {
500                 /* Not already created so create */
501                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
502                                 "CRYPTO_MBUFPOOL",
503                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
504                                 rte_socket_id());
505                 if (ts_params->mbuf_pool == NULL) {
506                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
507                         return TEST_FAILED;
508                 }
509         }
510
511         ts_params->large_mbuf_pool = rte_mempool_lookup(
512                         "CRYPTO_LARGE_MBUFPOOL");
513         if (ts_params->large_mbuf_pool == NULL) {
514                 /* Not already created so create */
515                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
516                                 "CRYPTO_LARGE_MBUFPOOL",
517                                 1, 0, 0, UINT16_MAX,
518                                 rte_socket_id());
519                 if (ts_params->large_mbuf_pool == NULL) {
520                         RTE_LOG(ERR, USER1,
521                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
522                         return TEST_FAILED;
523                 }
524         }
525
526         ts_params->op_mpool = rte_crypto_op_pool_create(
527                         "MBUF_CRYPTO_SYM_OP_POOL",
528                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
529                         NUM_MBUFS, MBUF_CACHE_SIZE,
530                         DEFAULT_NUM_XFORMS *
531                         sizeof(struct rte_crypto_sym_xform) +
532                         MAXIMUM_IV_LENGTH,
533                         rte_socket_id());
534         if (ts_params->op_mpool == NULL) {
535                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
536                 return TEST_FAILED;
537         }
538
539         /* Create an AESNI MB device if required */
540         if (gbl_driver_id == rte_cryptodev_driver_id_get(
541                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) {
542                 nb_devs = rte_cryptodev_device_count_by_driver(
543                                 rte_cryptodev_driver_id_get(
544                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
545                 if (nb_devs < 1) {
546                         ret = rte_vdev_init(
547                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
548
549                         TEST_ASSERT(ret == 0,
550                                 "Failed to create instance of"
551                                 " pmd : %s",
552                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
553                 }
554         }
555
556         /* Create an AESNI GCM device if required */
557         if (gbl_driver_id == rte_cryptodev_driver_id_get(
558                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))) {
559                 nb_devs = rte_cryptodev_device_count_by_driver(
560                                 rte_cryptodev_driver_id_get(
561                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)));
562                 if (nb_devs < 1) {
563                         TEST_ASSERT_SUCCESS(rte_vdev_init(
564                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
565                                 "Failed to create instance of"
566                                 " pmd : %s",
567                                 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
568                 }
569         }
570
571         /* Create a SNOW 3G device if required */
572         if (gbl_driver_id == rte_cryptodev_driver_id_get(
573                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))) {
574                 nb_devs = rte_cryptodev_device_count_by_driver(
575                                 rte_cryptodev_driver_id_get(
576                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)));
577                 if (nb_devs < 1) {
578                         TEST_ASSERT_SUCCESS(rte_vdev_init(
579                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
580                                 "Failed to create instance of"
581                                 " pmd : %s",
582                                 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
583                 }
584         }
585
586         /* Create a KASUMI device if required */
587         if (gbl_driver_id == rte_cryptodev_driver_id_get(
588                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))) {
589                 nb_devs = rte_cryptodev_device_count_by_driver(
590                                 rte_cryptodev_driver_id_get(
591                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)));
592                 if (nb_devs < 1) {
593                         TEST_ASSERT_SUCCESS(rte_vdev_init(
594                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
595                                 "Failed to create instance of"
596                                 " pmd : %s",
597                                 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
598                 }
599         }
600
601         /* Create a ZUC device if required */
602         if (gbl_driver_id == rte_cryptodev_driver_id_get(
603                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) {
604                 nb_devs = rte_cryptodev_device_count_by_driver(
605                                 rte_cryptodev_driver_id_get(
606                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)));
607                 if (nb_devs < 1) {
608                         TEST_ASSERT_SUCCESS(rte_vdev_init(
609                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL),
610                                 "Failed to create instance of"
611                                 " pmd : %s",
612                                 RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
613                 }
614         }
615
616         /* Create a NULL device if required */
617         if (gbl_driver_id == rte_cryptodev_driver_id_get(
618                         RTE_STR(CRYPTODEV_NAME_NULL_PMD))) {
619                 nb_devs = rte_cryptodev_device_count_by_driver(
620                                 rte_cryptodev_driver_id_get(
621                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD)));
622                 if (nb_devs < 1) {
623                         ret = rte_vdev_init(
624                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
625
626                         TEST_ASSERT(ret == 0,
627                                 "Failed to create instance of"
628                                 " pmd : %s",
629                                 RTE_STR(CRYPTODEV_NAME_NULL_PMD));
630                 }
631         }
632
633         /* Create an OPENSSL device if required */
634         if (gbl_driver_id == rte_cryptodev_driver_id_get(
635                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
636                 nb_devs = rte_cryptodev_device_count_by_driver(
637                                 rte_cryptodev_driver_id_get(
638                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
639                 if (nb_devs < 1) {
640                         ret = rte_vdev_init(
641                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
642                                 NULL);
643
644                         TEST_ASSERT(ret == 0, "Failed to create "
645                                 "instance of pmd : %s",
646                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
647                 }
648         }
649
650         /* Create a ARMv8 device if required */
651         if (gbl_driver_id == rte_cryptodev_driver_id_get(
652                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))) {
653                 nb_devs = rte_cryptodev_device_count_by_driver(
654                                 rte_cryptodev_driver_id_get(
655                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)));
656                 if (nb_devs < 1) {
657                         ret = rte_vdev_init(
658                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD),
659                                 NULL);
660
661                         TEST_ASSERT(ret == 0, "Failed to create "
662                                 "instance of pmd : %s",
663                                 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
664                 }
665         }
666
667         /* Create a MVSAM device if required */
668         if (gbl_driver_id == rte_cryptodev_driver_id_get(
669                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))) {
670                 nb_devs = rte_cryptodev_device_count_by_driver(
671                                 rte_cryptodev_driver_id_get(
672                                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)));
673                 if (nb_devs < 1) {
674                         ret = rte_vdev_init(
675                                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD),
676                                 NULL);
677
678                         TEST_ASSERT(ret == 0, "Failed to create "
679                                 "instance of pmd : %s",
680                                 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
681                 }
682         }
683
684         /* Create an CCP device if required */
685         if (gbl_driver_id == rte_cryptodev_driver_id_get(
686                         RTE_STR(CRYPTODEV_NAME_CCP_PMD))) {
687                 nb_devs = rte_cryptodev_device_count_by_driver(
688                                 rte_cryptodev_driver_id_get(
689                                 RTE_STR(CRYPTODEV_NAME_CCP_PMD)));
690                 if (nb_devs < 1) {
691                         ret = rte_vdev_init(
692                                 RTE_STR(CRYPTODEV_NAME_CCP_PMD),
693                                 NULL);
694
695                         TEST_ASSERT(ret == 0, "Failed to create "
696                                 "instance of pmd : %s",
697                                 RTE_STR(CRYPTODEV_NAME_CCP_PMD));
698                 }
699         }
700
701 #ifdef RTE_CRYPTO_SCHEDULER
702         char vdev_args[VDEV_ARGS_SIZE] = {""};
703         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
704                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
705         uint16_t worker_core_count = 0;
706         uint16_t socket_id = 0;
707
708         if (gbl_driver_id == rte_cryptodev_driver_id_get(
709                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
710
711                 /* Identify the Worker Cores
712                  * Use 2 worker cores for the device args
713                  */
714                 RTE_LCORE_FOREACH_WORKER(i) {
715                         if (worker_core_count > 1)
716                                 break;
717                         snprintf(vdev_args, sizeof(vdev_args),
718                                         "%s%d", temp_str, i);
719                         strcpy(temp_str, vdev_args);
720                         strlcat(temp_str, ";", sizeof(temp_str));
721                         worker_core_count++;
722                         socket_id = rte_lcore_to_socket_id(i);
723                 }
724                 if (worker_core_count != 2) {
725                         RTE_LOG(ERR, USER1,
726                                 "Cryptodev scheduler test require at least "
727                                 "two worker cores to run. "
728                                 "Please use the correct coremask.\n");
729                         return TEST_FAILED;
730                 }
731                 strcpy(temp_str, vdev_args);
732                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
733                                 temp_str, socket_id);
734                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
735                 nb_devs = rte_cryptodev_device_count_by_driver(
736                                 rte_cryptodev_driver_id_get(
737                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
738                 if (nb_devs < 1) {
739                         ret = rte_vdev_init(
740                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
741                                         vdev_args);
742                         TEST_ASSERT(ret == 0,
743                                 "Failed to create instance %u of"
744                                 " pmd : %s",
745                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
746                 }
747         }
748 #endif /* RTE_CRYPTO_SCHEDULER */
749
750         nb_devs = rte_cryptodev_count();
751         if (nb_devs < 1) {
752                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
753                 return TEST_SKIPPED;
754         }
755
756         /* Create list of valid crypto devs */
757         for (i = 0; i < nb_devs; i++) {
758                 rte_cryptodev_info_get(i, &info);
759                 if (info.driver_id == gbl_driver_id)
760                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
761         }
762
763         if (ts_params->valid_dev_count < 1)
764                 return TEST_FAILED;
765
766         /* Set up all the qps on the first of the valid devices found */
767
768         dev_id = ts_params->valid_devs[0];
769
770         rte_cryptodev_info_get(dev_id, &info);
771
772         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
773         ts_params->conf.socket_id = SOCKET_ID_ANY;
774         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
775
776         unsigned int session_size =
777                 rte_cryptodev_sym_get_private_session_size(dev_id);
778
779 #ifdef RTE_LIB_SECURITY
780         unsigned int security_session_size = rte_security_session_get_size(
781                         rte_cryptodev_get_sec_ctx(dev_id));
782
783         if (session_size < security_session_size)
784                 session_size = security_session_size;
785 #endif
786         /*
787          * Create mempool with maximum number of sessions.
788          */
789         if (info.sym.max_nb_sessions != 0 &&
790                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
791                 RTE_LOG(ERR, USER1, "Device does not support "
792                                 "at least %u sessions\n",
793                                 MAX_NB_SESSIONS);
794                 return TEST_FAILED;
795         }
796
797         ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
798                         "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
799                         SOCKET_ID_ANY);
800         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
801                         "session mempool allocation failed");
802
803         ts_params->session_priv_mpool = rte_mempool_create(
804                         "test_sess_mp_priv",
805                         MAX_NB_SESSIONS,
806                         session_size,
807                         0, 0, NULL, NULL, NULL,
808                         NULL, SOCKET_ID_ANY,
809                         0);
810         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
811                         "session mempool allocation failed");
812
813
814
815         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
816                         &ts_params->conf),
817                         "Failed to configure cryptodev %u with %u qps",
818                         dev_id, ts_params->conf.nb_queue_pairs);
819
820         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
821         ts_params->qp_conf.mp_session = ts_params->session_mpool;
822         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
823
824         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
825                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
826                         dev_id, qp_id, &ts_params->qp_conf,
827                         rte_cryptodev_socket_id(dev_id)),
828                         "Failed to setup queue pair %u on cryptodev %u",
829                         qp_id, dev_id);
830         }
831
832         return TEST_SUCCESS;
833 }
834
835 static void
836 testsuite_teardown(void)
837 {
838         struct crypto_testsuite_params *ts_params = &testsuite_params;
839         int res;
840
841         if (ts_params->mbuf_pool != NULL) {
842                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
843                 rte_mempool_avail_count(ts_params->mbuf_pool));
844         }
845
846         if (ts_params->op_mpool != NULL) {
847                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
848                 rte_mempool_avail_count(ts_params->op_mpool));
849         }
850
851         /* Free session mempools */
852         if (ts_params->session_priv_mpool != NULL) {
853                 rte_mempool_free(ts_params->session_priv_mpool);
854                 ts_params->session_priv_mpool = NULL;
855         }
856
857         if (ts_params->session_mpool != NULL) {
858                 rte_mempool_free(ts_params->session_mpool);
859                 ts_params->session_mpool = NULL;
860         }
861
862         res = rte_cryptodev_close(ts_params->valid_devs[0]);
863         if (res)
864                 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
865 }
866
867 static int
868 dev_configure_and_start(uint64_t ff_disable)
869 {
870         struct crypto_testsuite_params *ts_params = &testsuite_params;
871         struct crypto_unittest_params *ut_params = &unittest_params;
872
873         uint16_t qp_id;
874
875         /* Clear unit test parameters before running test */
876         memset(ut_params, 0, sizeof(*ut_params));
877
878         /* Reconfigure device to default parameters */
879         ts_params->conf.socket_id = SOCKET_ID_ANY;
880         ts_params->conf.ff_disable = ff_disable;
881         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
882         ts_params->qp_conf.mp_session = ts_params->session_mpool;
883         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
884
885         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
886                         &ts_params->conf),
887                         "Failed to configure cryptodev %u",
888                         ts_params->valid_devs[0]);
889
890         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
891                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
892                         ts_params->valid_devs[0], qp_id,
893                         &ts_params->qp_conf,
894                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
895                         "Failed to setup queue pair %u on cryptodev %u",
896                         qp_id, ts_params->valid_devs[0]);
897         }
898
899
900         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
901
902         /* Start the device */
903         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
904                         "Failed to start cryptodev %u",
905                         ts_params->valid_devs[0]);
906
907         return TEST_SUCCESS;
908 }
909
910 static int
911 ut_setup(void)
912 {
913         /* Configure and start the device with security feature disabled */
914         return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
915 }
916
917 static int
918 ut_setup_security(void)
919 {
920         /* Configure and start the device with no features disabled */
921         return dev_configure_and_start(0);
922 }
923
924 static void
925 ut_teardown(void)
926 {
927         struct crypto_testsuite_params *ts_params = &testsuite_params;
928         struct crypto_unittest_params *ut_params = &unittest_params;
929         struct rte_cryptodev_stats stats;
930
931         /* free crypto session structure */
932 #ifdef RTE_LIB_SECURITY
933         if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
934                 if (ut_params->sec_session) {
935                         rte_security_session_destroy(rte_cryptodev_get_sec_ctx
936                                                 (ts_params->valid_devs[0]),
937                                                 ut_params->sec_session);
938                         ut_params->sec_session = NULL;
939                 }
940         } else
941 #endif
942         {
943                 if (ut_params->sess) {
944                         rte_cryptodev_sym_session_clear(
945                                         ts_params->valid_devs[0],
946                                         ut_params->sess);
947                         rte_cryptodev_sym_session_free(ut_params->sess);
948                         ut_params->sess = NULL;
949                 }
950         }
951
952         /* free crypto operation structure */
953         if (ut_params->op)
954                 rte_crypto_op_free(ut_params->op);
955
956         /*
957          * free mbuf - both obuf and ibuf are usually the same,
958          * so check if they point at the same address is necessary,
959          * to avoid freeing the mbuf twice.
960          */
961         if (ut_params->obuf) {
962                 rte_pktmbuf_free(ut_params->obuf);
963                 if (ut_params->ibuf == ut_params->obuf)
964                         ut_params->ibuf = 0;
965                 ut_params->obuf = 0;
966         }
967         if (ut_params->ibuf) {
968                 rte_pktmbuf_free(ut_params->ibuf);
969                 ut_params->ibuf = 0;
970         }
971
972         if (ts_params->mbuf_pool != NULL)
973                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
974                         rte_mempool_avail_count(ts_params->mbuf_pool));
975
976         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
977
978         /* Stop the device */
979         rte_cryptodev_stop(ts_params->valid_devs[0]);
980 }
981
982 static int
983 test_device_configure_invalid_dev_id(void)
984 {
985         struct crypto_testsuite_params *ts_params = &testsuite_params;
986         uint16_t dev_id, num_devs = 0;
987
988         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
989                         "Need at least %d devices for test", 1);
990
991         /* valid dev_id values */
992         dev_id = ts_params->valid_devs[0];
993
994         /* Stop the device in case it's started so it can be configured */
995         rte_cryptodev_stop(dev_id);
996
997         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
998                         "Failed test for rte_cryptodev_configure: "
999                         "invalid dev_num %u", dev_id);
1000
1001         /* invalid dev_id values */
1002         dev_id = num_devs;
1003
1004         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1005                         "Failed test for rte_cryptodev_configure: "
1006                         "invalid dev_num %u", dev_id);
1007
1008         dev_id = 0xff;
1009
1010         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1011                         "Failed test for rte_cryptodev_configure:"
1012                         "invalid dev_num %u", dev_id);
1013
1014         return TEST_SUCCESS;
1015 }
1016
1017 static int
1018 test_device_configure_invalid_queue_pair_ids(void)
1019 {
1020         struct crypto_testsuite_params *ts_params = &testsuite_params;
1021         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1022
1023         /* Stop the device in case it's started so it can be configured */
1024         rte_cryptodev_stop(ts_params->valid_devs[0]);
1025
1026         /* valid - max value queue pairs */
1027         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1028
1029         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1030                         &ts_params->conf),
1031                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1032                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1033
1034         /* valid - one queue pairs */
1035         ts_params->conf.nb_queue_pairs = 1;
1036
1037         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1038                         &ts_params->conf),
1039                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1040                         ts_params->valid_devs[0],
1041                         ts_params->conf.nb_queue_pairs);
1042
1043
1044         /* invalid - zero queue pairs */
1045         ts_params->conf.nb_queue_pairs = 0;
1046
1047         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1048                         &ts_params->conf),
1049                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1050                         " invalid qps: %u",
1051                         ts_params->valid_devs[0],
1052                         ts_params->conf.nb_queue_pairs);
1053
1054
1055         /* invalid - max value supported by field queue pairs */
1056         ts_params->conf.nb_queue_pairs = UINT16_MAX;
1057
1058         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1059                         &ts_params->conf),
1060                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1061                         " invalid qps: %u",
1062                         ts_params->valid_devs[0],
1063                         ts_params->conf.nb_queue_pairs);
1064
1065
1066         /* invalid - max value + 1 queue pairs */
1067         ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1068
1069         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1070                         &ts_params->conf),
1071                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1072                         " invalid qps: %u",
1073                         ts_params->valid_devs[0],
1074                         ts_params->conf.nb_queue_pairs);
1075
1076         /* revert to original testsuite value */
1077         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1078
1079         return TEST_SUCCESS;
1080 }
1081
1082 static int
1083 test_queue_pair_descriptor_setup(void)
1084 {
1085         struct crypto_testsuite_params *ts_params = &testsuite_params;
1086         struct rte_cryptodev_qp_conf qp_conf = {
1087                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
1088         };
1089         uint16_t qp_id;
1090
1091         /* Stop the device in case it's started so it can be configured */
1092         rte_cryptodev_stop(ts_params->valid_devs[0]);
1093
1094         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1095                         &ts_params->conf),
1096                         "Failed to configure cryptodev %u",
1097                         ts_params->valid_devs[0]);
1098
1099         /*
1100          * Test various ring sizes on this device. memzones can't be
1101          * freed so are re-used if ring is released and re-created.
1102          */
1103         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1104         qp_conf.mp_session = ts_params->session_mpool;
1105         qp_conf.mp_session_private = ts_params->session_priv_mpool;
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 = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
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 = MAX_NUM_OPS_INFLIGHT; /* valid */
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: num_inflights"
1142                                 " %u on qp %u on cryptodev %u",
1143                                 qp_conf.nb_descriptors, qp_id,
1144                                 ts_params->valid_devs[0]);
1145         }
1146
1147         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1148
1149         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1150                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1151                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1152                                 rte_cryptodev_socket_id(
1153                                                 ts_params->valid_devs[0])),
1154                                 "Failed test for"
1155                                 " rte_cryptodev_queue_pair_setup:"
1156                                 "num_inflights %u on qp %u on cryptodev %u",
1157                                 qp_conf.nb_descriptors, qp_id,
1158                                 ts_params->valid_devs[0]);
1159         }
1160
1161         /* test invalid queue pair id */
1162         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
1163
1164         qp_id = ts_params->conf.nb_queue_pairs;         /*invalid */
1165
1166         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1167                         ts_params->valid_devs[0],
1168                         qp_id, &qp_conf,
1169                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1170                         "Failed test for rte_cryptodev_queue_pair_setup:"
1171                         "invalid qp %u on cryptodev %u",
1172                         qp_id, ts_params->valid_devs[0]);
1173
1174         qp_id = 0xffff; /*invalid*/
1175
1176         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1177                         ts_params->valid_devs[0],
1178                         qp_id, &qp_conf,
1179                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1180                         "Failed test for rte_cryptodev_queue_pair_setup:"
1181                         "invalid qp %u on cryptodev %u",
1182                         qp_id, ts_params->valid_devs[0]);
1183
1184         return TEST_SUCCESS;
1185 }
1186
1187 /* ***** Plaintext data for tests ***** */
1188
1189 const char catch_22_quote_1[] =
1190                 "There was only one catch and that was Catch-22, which "
1191                 "specified that a concern for one's safety in the face of "
1192                 "dangers that were real and immediate was the process of a "
1193                 "rational mind. Orr was crazy and could be grounded. All he "
1194                 "had to do was ask; and as soon as he did, he would no longer "
1195                 "be crazy and would have to fly more missions. Orr would be "
1196                 "crazy to fly more missions and sane if he didn't, but if he "
1197                 "was sane he had to fly them. If he flew them he was crazy "
1198                 "and didn't have to; but if he didn't want to he was sane and "
1199                 "had to. Yossarian was moved very deeply by the absolute "
1200                 "simplicity of this clause of Catch-22 and let out a "
1201                 "respectful whistle. \"That's some catch, that Catch-22\", he "
1202                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
1203
1204 const char catch_22_quote[] =
1205                 "What a lousy earth! He wondered how many people were "
1206                 "destitute that same night even in his own prosperous country, "
1207                 "how many homes were shanties, how many husbands were drunk "
1208                 "and wives socked, and how many children were bullied, abused, "
1209                 "or abandoned. How many families hungered for food they could "
1210                 "not afford to buy? How many hearts were broken? How many "
1211                 "suicides would take place that same night, how many people "
1212                 "would go insane? How many cockroaches and landlords would "
1213                 "triumph? How many winners were losers, successes failures, "
1214                 "and rich men poor men? How many wise guys were stupid? How "
1215                 "many happy endings were unhappy endings? How many honest men "
1216                 "were liars, brave men cowards, loyal men traitors, how many "
1217                 "sainted men were corrupt, how many people in positions of "
1218                 "trust had sold their souls to bodyguards, how many had never "
1219                 "had souls? How many straight-and-narrow paths were crooked "
1220                 "paths? How many best families were worst families and how "
1221                 "many good people were bad people? When you added them all up "
1222                 "and then subtracted, you might be left with only the children, "
1223                 "and perhaps with Albert Einstein and an old violinist or "
1224                 "sculptor somewhere.";
1225
1226 #define QUOTE_480_BYTES         (480)
1227 #define QUOTE_512_BYTES         (512)
1228 #define QUOTE_768_BYTES         (768)
1229 #define QUOTE_1024_BYTES        (1024)
1230
1231
1232
1233 /* ***** SHA1 Hash Tests ***** */
1234
1235 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
1236
1237 static uint8_t hmac_sha1_key[] = {
1238         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1239         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1240         0xDE, 0xF4, 0xDE, 0xAD };
1241
1242 /* ***** SHA224 Hash Tests ***** */
1243
1244 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
1245
1246
1247 /* ***** AES-CBC Cipher Tests ***** */
1248
1249 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
1250 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
1251
1252 static uint8_t aes_cbc_key[] = {
1253         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1254         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1255
1256 static uint8_t aes_cbc_iv[] = {
1257         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1258         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1259
1260
1261 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1262
1263 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1264         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1265         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1266         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1267         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1268         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1269         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1270         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1271         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1272         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1273         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1274         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1275         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1276         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1277         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1278         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1279         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1280         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1281         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1282         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1283         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1284         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1285         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1286         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1287         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1288         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1289         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1290         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1291         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1292         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1293         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1294         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1295         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1296         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1297         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1298         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1299         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1300         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1301         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1302         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1303         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1304         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1305         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1306         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1307         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1308         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1309         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1310         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1311         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1312         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1313         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1314         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1315         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1316         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1317         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1318         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1319         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1320         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1321         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1322         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1323         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1324         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1325         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1326         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1327         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1328 };
1329
1330 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1331         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1332         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1333         0x18, 0x8c, 0x1d, 0x32
1334 };
1335
1336
1337 /* Multisession Vector context Test */
1338 /*Begin Session 0 */
1339 static uint8_t ms_aes_cbc_key0[] = {
1340         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1341         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1342 };
1343
1344 static uint8_t ms_aes_cbc_iv0[] = {
1345         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1346         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1347 };
1348
1349 static const uint8_t ms_aes_cbc_cipher0[] = {
1350                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1351                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1352                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1353                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1354                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1355                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1356                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1357                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1358                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1359                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1360                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1361                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1362                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1363                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1364                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1365                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1366                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1367                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1368                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1369                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1370                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1371                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1372                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1373                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1374                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1375                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1376                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1377                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1378                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1379                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1380                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1381                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1382                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1383                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1384                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1385                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1386                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1387                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1388                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1389                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1390                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1391                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1392                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1393                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1394                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1395                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1396                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1397                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1398                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1399                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1400                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1401                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1402                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1403                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1404                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1405                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1406                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1407                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1408                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1409                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1410                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1411                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1412                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1413                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1414 };
1415
1416
1417 static  uint8_t ms_hmac_key0[] = {
1418                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1419                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1420                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1421                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1422                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1423                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1424                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1425                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1426 };
1427
1428 static const uint8_t ms_hmac_digest0[] = {
1429                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1430                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1431                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1432                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1433                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1434                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1435                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1436                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1437                 };
1438
1439 /* End Session 0 */
1440 /* Begin session 1 */
1441
1442 static  uint8_t ms_aes_cbc_key1[] = {
1443                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1444                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1445 };
1446
1447 static  uint8_t ms_aes_cbc_iv1[] = {
1448         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1449         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1450 };
1451
1452 static const uint8_t ms_aes_cbc_cipher1[] = {
1453                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1454                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1455                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1456                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1457                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1458                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1459                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1460                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1461                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1462                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1463                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1464                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1465                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1466                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1467                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1468                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1469                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1470                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1471                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1472                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1473                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1474                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1475                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1476                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1477                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1478                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1479                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1480                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1481                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1482                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1483                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1484                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1485                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1486                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1487                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1488                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1489                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1490                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1491                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1492                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1493                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1494                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1495                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1496                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1497                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1498                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1499                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1500                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1501                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1502                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1503                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1504                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1505                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1506                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1507                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1508                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1509                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1510                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1511                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1512                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1513                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1514                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1515                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1516                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1517
1518 };
1519
1520 static uint8_t ms_hmac_key1[] = {
1521                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1522                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1523                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1524                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1525                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1526                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1527                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1528                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1529 };
1530
1531 static const uint8_t ms_hmac_digest1[] = {
1532                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1533                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1534                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1535                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1536                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1537                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1538                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1539                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1540 };
1541 /* End Session 1  */
1542 /* Begin Session 2 */
1543 static  uint8_t ms_aes_cbc_key2[] = {
1544                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1545                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1546 };
1547
1548 static  uint8_t ms_aes_cbc_iv2[] = {
1549                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1550                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1551 };
1552
1553 static const uint8_t ms_aes_cbc_cipher2[] = {
1554                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1555                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1556                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1557                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1558                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1559                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1560                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1561                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1562                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1563                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1564                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1565                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1566                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1567                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1568                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1569                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1570                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1571                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1572                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1573                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1574                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1575                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1576                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1577                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1578                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1579                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1580                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1581                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1582                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1583                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1584                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1585                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1586                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1587                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1588                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1589                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1590                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1591                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1592                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1593                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1594                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1595                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1596                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1597                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1598                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1599                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
1600                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
1601                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
1602                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
1603                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
1604                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
1605                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
1606                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
1607                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
1608                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
1609                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
1610                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
1611                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
1612                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
1613                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
1614                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
1615                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
1616                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
1617                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
1618 };
1619
1620 static  uint8_t ms_hmac_key2[] = {
1621                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1622                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1623                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1624                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1625                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1626                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1627                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1628                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1629 };
1630
1631 static const uint8_t ms_hmac_digest2[] = {
1632                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
1633                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
1634                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
1635                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
1636                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
1637                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
1638                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
1639                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
1640 };
1641
1642 /* End Session 2 */
1643
1644
1645 static int
1646 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
1647 {
1648         struct crypto_testsuite_params *ts_params = &testsuite_params;
1649         struct crypto_unittest_params *ut_params = &unittest_params;
1650
1651         /* Verify the capabilities */
1652         struct rte_cryptodev_sym_capability_idx cap_idx;
1653         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1654         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
1655         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
1656                         &cap_idx) == NULL)
1657                 return -ENOTSUP;
1658         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1659         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
1660         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
1661                         &cap_idx) == NULL)
1662                 return -ENOTSUP;
1663
1664         /* Generate test mbuf data and space for digest */
1665         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1666                         catch_22_quote, QUOTE_512_BYTES, 0);
1667
1668         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1669                         DIGEST_BYTE_LENGTH_SHA1);
1670         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1671
1672         /* Setup Cipher Parameters */
1673         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1674         ut_params->cipher_xform.next = &ut_params->auth_xform;
1675
1676         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1677         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1678         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1679         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1680         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1681         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1682
1683         /* Setup HMAC Parameters */
1684         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1685
1686         ut_params->auth_xform.next = NULL;
1687
1688         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1689         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1690         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1691         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1692         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1693
1694         ut_params->sess = rte_cryptodev_sym_session_create(
1695                         ts_params->session_mpool);
1696
1697         /* Create crypto session*/
1698         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
1699                         ut_params->sess, &ut_params->cipher_xform,
1700                         ts_params->session_priv_mpool);
1701         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1702
1703         /* Generate crypto op data structure */
1704         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1705                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1706         TEST_ASSERT_NOT_NULL(ut_params->op,
1707                         "Failed to allocate symmetric crypto operation struct");
1708
1709         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1710
1711         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1712
1713         /* set crypto operation source mbuf */
1714         sym_op->m_src = ut_params->ibuf;
1715
1716         /* Set crypto operation authentication parameters */
1717         sym_op->auth.digest.data = ut_params->digest;
1718         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
1719                         ut_params->ibuf, QUOTE_512_BYTES);
1720
1721         sym_op->auth.data.offset = 0;
1722         sym_op->auth.data.length = QUOTE_512_BYTES;
1723
1724         /* Copy IV at the end of the crypto operation */
1725         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1726                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
1727
1728         /* Set crypto operation cipher parameters */
1729         sym_op->cipher.data.offset = 0;
1730         sym_op->cipher.data.length = QUOTE_512_BYTES;
1731
1732         /* Process crypto operation */
1733         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
1734                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
1735                         ut_params->op);
1736         else
1737                 TEST_ASSERT_NOT_NULL(
1738                         process_crypto_request(ts_params->valid_devs[0],
1739                                 ut_params->op),
1740                                 "failed to process sym crypto op");
1741
1742         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1743                         "crypto op processing failed");
1744
1745         /* Validate obuf */
1746         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
1747                         uint8_t *);
1748
1749         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1750                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1751                         QUOTE_512_BYTES,
1752                         "ciphertext data not as expected");
1753
1754         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1755
1756         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1757                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1758                         gbl_driver_id == rte_cryptodev_driver_id_get(
1759                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
1760                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1761                                         DIGEST_BYTE_LENGTH_SHA1,
1762                         "Generated digest data not as expected");
1763
1764         return TEST_SUCCESS;
1765 }
1766
1767 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1768
1769 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
1770
1771 static uint8_t hmac_sha512_key[] = {
1772         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1773         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1774         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1775         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1776         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1777         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1778         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1779         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1780
1781 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1782         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1783         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1784         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1785         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1786         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1787         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1788         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1789         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1790
1791
1792
1793 static int
1794 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1795                 struct crypto_unittest_params *ut_params,
1796                 uint8_t *cipher_key,
1797                 uint8_t *hmac_key);
1798
1799 static int
1800 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1801                 struct crypto_unittest_params *ut_params,
1802                 struct crypto_testsuite_params *ts_params,
1803                 const uint8_t *cipher,
1804                 const uint8_t *digest,
1805                 const uint8_t *iv);
1806
1807
1808 static int
1809 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1810                 struct crypto_unittest_params *ut_params,
1811                 uint8_t *cipher_key,
1812                 uint8_t *hmac_key)
1813 {
1814
1815         /* Setup Cipher Parameters */
1816         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1817         ut_params->cipher_xform.next = NULL;
1818
1819         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1820         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1821         ut_params->cipher_xform.cipher.key.data = cipher_key;
1822         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1823         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1824         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1825
1826         /* Setup HMAC Parameters */
1827         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1828         ut_params->auth_xform.next = &ut_params->cipher_xform;
1829
1830         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1831         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1832         ut_params->auth_xform.auth.key.data = hmac_key;
1833         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1834         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1835
1836         return TEST_SUCCESS;
1837 }
1838
1839
1840 static int
1841 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1842                 struct crypto_unittest_params *ut_params,
1843                 struct crypto_testsuite_params *ts_params,
1844                 const uint8_t *cipher,
1845                 const uint8_t *digest,
1846                 const uint8_t *iv)
1847 {
1848         /* Generate test mbuf data and digest */
1849         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1850                         (const char *)
1851                         cipher,
1852                         QUOTE_512_BYTES, 0);
1853
1854         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1855                         DIGEST_BYTE_LENGTH_SHA512);
1856         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1857
1858         rte_memcpy(ut_params->digest,
1859                         digest,
1860                         DIGEST_BYTE_LENGTH_SHA512);
1861
1862         /* Generate Crypto op data structure */
1863         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1864                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1865         TEST_ASSERT_NOT_NULL(ut_params->op,
1866                         "Failed to allocate symmetric crypto operation struct");
1867
1868         rte_crypto_op_attach_sym_session(ut_params->op, sess);
1869
1870         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1871
1872         /* set crypto operation source mbuf */
1873         sym_op->m_src = ut_params->ibuf;
1874
1875         sym_op->auth.digest.data = ut_params->digest;
1876         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
1877                         ut_params->ibuf, QUOTE_512_BYTES);
1878
1879         sym_op->auth.data.offset = 0;
1880         sym_op->auth.data.length = QUOTE_512_BYTES;
1881
1882         /* Copy IV at the end of the crypto operation */
1883         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1884                         iv, CIPHER_IV_LENGTH_AES_CBC);
1885
1886         sym_op->cipher.data.offset = 0;
1887         sym_op->cipher.data.length = QUOTE_512_BYTES;
1888
1889         /* Process crypto operation */
1890         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
1891                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
1892                         ut_params->op);
1893         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
1894                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
1895                                 ut_params->op, 1, 1, 0, 0);
1896         else
1897                 TEST_ASSERT_NOT_NULL(
1898                                 process_crypto_request(ts_params->valid_devs[0],
1899                                         ut_params->op),
1900                                         "failed to process sym crypto op");
1901
1902         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1903                         "crypto op processing failed");
1904
1905         ut_params->obuf = ut_params->op->sym->m_src;
1906
1907         /* Validate obuf */
1908         TEST_ASSERT_BUFFERS_ARE_EQUAL(
1909                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
1910                         catch_22_quote,
1911                         QUOTE_512_BYTES,
1912                         "Plaintext data not as expected");
1913
1914         /* Validate obuf */
1915         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1916                         "Digest verification failed");
1917
1918         return TEST_SUCCESS;
1919 }
1920
1921 static int
1922 test_blockcipher(enum blockcipher_test_type test_type)
1923 {
1924         struct crypto_testsuite_params *ts_params = &testsuite_params;
1925         int status;
1926
1927         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1928                 ts_params->op_mpool,
1929                 ts_params->session_mpool, ts_params->session_priv_mpool,
1930                 ts_params->valid_devs[0],
1931                 test_type);
1932
1933         if (status == -ENOTSUP)
1934                 return status;
1935
1936         TEST_ASSERT_EQUAL(status, 0, "Test failed");
1937
1938         return TEST_SUCCESS;
1939 }
1940
1941 static int
1942 test_AES_cipheronly_all(void)
1943 {
1944         return test_blockcipher(BLKCIPHER_AES_CIPHERONLY_TYPE);
1945 }
1946
1947 static int
1948 test_AES_docsis_all(void)
1949 {
1950         /* Data-path service does not support DOCSIS yet */
1951         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
1952                 return -ENOTSUP;
1953         return test_blockcipher(BLKCIPHER_AES_DOCSIS_TYPE);
1954 }
1955
1956 static int
1957 test_DES_docsis_all(void)
1958 {
1959         /* Data-path service does not support DOCSIS yet */
1960         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
1961                 return -ENOTSUP;
1962         return test_blockcipher(BLKCIPHER_DES_DOCSIS_TYPE);
1963 }
1964
1965 static int
1966 test_DES_cipheronly_all(void)
1967 {
1968         return test_blockcipher(BLKCIPHER_DES_CIPHERONLY_TYPE);
1969 }
1970
1971 static int
1972 test_authonly_all(void)
1973 {
1974         return test_blockcipher(BLKCIPHER_AUTHONLY_TYPE);
1975 }
1976
1977 static int
1978 test_AES_chain_all(void)
1979 {
1980         return test_blockcipher(BLKCIPHER_AES_CHAIN_TYPE);
1981 }
1982
1983 static int
1984 test_3DES_chain_all(void)
1985 {
1986         return test_blockcipher(BLKCIPHER_3DES_CHAIN_TYPE);
1987 }
1988
1989 static int
1990 test_3DES_cipheronly_all(void)
1991 {
1992         return test_blockcipher(BLKCIPHER_3DES_CIPHERONLY_TYPE);
1993 }
1994
1995 /* ***** SNOW 3G Tests ***** */
1996 static int
1997 create_wireless_algo_hash_session(uint8_t dev_id,
1998         const uint8_t *key, const uint8_t key_len,
1999         const uint8_t iv_len, const uint8_t auth_len,
2000         enum rte_crypto_auth_operation op,
2001         enum rte_crypto_auth_algorithm algo)
2002 {
2003         uint8_t hash_key[key_len];
2004         int status;
2005
2006         struct crypto_testsuite_params *ts_params = &testsuite_params;
2007         struct crypto_unittest_params *ut_params = &unittest_params;
2008
2009         memcpy(hash_key, key, key_len);
2010
2011         debug_hexdump(stdout, "key:", key, key_len);
2012
2013         /* Setup Authentication Parameters */
2014         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2015         ut_params->auth_xform.next = NULL;
2016
2017         ut_params->auth_xform.auth.op = op;
2018         ut_params->auth_xform.auth.algo = algo;
2019         ut_params->auth_xform.auth.key.length = key_len;
2020         ut_params->auth_xform.auth.key.data = hash_key;
2021         ut_params->auth_xform.auth.digest_length = auth_len;
2022         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2023         ut_params->auth_xform.auth.iv.length = iv_len;
2024         ut_params->sess = rte_cryptodev_sym_session_create(
2025                         ts_params->session_mpool);
2026
2027         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2028                         &ut_params->auth_xform,
2029                         ts_params->session_priv_mpool);
2030         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2031         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2032         return 0;
2033 }
2034
2035 static int
2036 create_wireless_algo_cipher_session(uint8_t dev_id,
2037                         enum rte_crypto_cipher_operation op,
2038                         enum rte_crypto_cipher_algorithm algo,
2039                         const uint8_t *key, const uint8_t key_len,
2040                         uint8_t iv_len)
2041 {
2042         uint8_t cipher_key[key_len];
2043         int status;
2044         struct crypto_testsuite_params *ts_params = &testsuite_params;
2045         struct crypto_unittest_params *ut_params = &unittest_params;
2046
2047         memcpy(cipher_key, key, key_len);
2048
2049         /* Setup Cipher Parameters */
2050         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2051         ut_params->cipher_xform.next = NULL;
2052
2053         ut_params->cipher_xform.cipher.algo = algo;
2054         ut_params->cipher_xform.cipher.op = op;
2055         ut_params->cipher_xform.cipher.key.data = cipher_key;
2056         ut_params->cipher_xform.cipher.key.length = key_len;
2057         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2058         ut_params->cipher_xform.cipher.iv.length = iv_len;
2059
2060         debug_hexdump(stdout, "key:", key, key_len);
2061
2062         /* Create Crypto session */
2063         ut_params->sess = rte_cryptodev_sym_session_create(
2064                         ts_params->session_mpool);
2065
2066         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2067                         &ut_params->cipher_xform,
2068                         ts_params->session_priv_mpool);
2069         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2070         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2071         return 0;
2072 }
2073
2074 static int
2075 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2076                         unsigned int cipher_len,
2077                         unsigned int cipher_offset)
2078 {
2079         struct crypto_testsuite_params *ts_params = &testsuite_params;
2080         struct crypto_unittest_params *ut_params = &unittest_params;
2081
2082         /* Generate Crypto op data structure */
2083         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2084                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2085         TEST_ASSERT_NOT_NULL(ut_params->op,
2086                                 "Failed to allocate pktmbuf offload");
2087
2088         /* Set crypto operation data parameters */
2089         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2090
2091         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2092
2093         /* set crypto operation source mbuf */
2094         sym_op->m_src = ut_params->ibuf;
2095
2096         /* iv */
2097         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2098                         iv, iv_len);
2099         sym_op->cipher.data.length = cipher_len;
2100         sym_op->cipher.data.offset = cipher_offset;
2101         return 0;
2102 }
2103
2104 static int
2105 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2106                         unsigned int cipher_len,
2107                         unsigned int cipher_offset)
2108 {
2109         struct crypto_testsuite_params *ts_params = &testsuite_params;
2110         struct crypto_unittest_params *ut_params = &unittest_params;
2111
2112         /* Generate Crypto op data structure */
2113         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2114                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2115         TEST_ASSERT_NOT_NULL(ut_params->op,
2116                                 "Failed to allocate pktmbuf offload");
2117
2118         /* Set crypto operation data parameters */
2119         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2120
2121         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2122
2123         /* set crypto operation source mbuf */
2124         sym_op->m_src = ut_params->ibuf;
2125         sym_op->m_dst = ut_params->obuf;
2126
2127         /* iv */
2128         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2129                         iv, iv_len);
2130         sym_op->cipher.data.length = cipher_len;
2131         sym_op->cipher.data.offset = cipher_offset;
2132         return 0;
2133 }
2134
2135 static int
2136 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2137                 enum rte_crypto_cipher_operation cipher_op,
2138                 enum rte_crypto_auth_operation auth_op,
2139                 enum rte_crypto_auth_algorithm auth_algo,
2140                 enum rte_crypto_cipher_algorithm cipher_algo,
2141                 const uint8_t *key, uint8_t key_len,
2142                 uint8_t auth_iv_len, uint8_t auth_len,
2143                 uint8_t cipher_iv_len)
2144
2145 {
2146         uint8_t cipher_auth_key[key_len];
2147         int status;
2148
2149         struct crypto_testsuite_params *ts_params = &testsuite_params;
2150         struct crypto_unittest_params *ut_params = &unittest_params;
2151
2152         memcpy(cipher_auth_key, key, key_len);
2153
2154         /* Setup Authentication Parameters */
2155         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2156         ut_params->auth_xform.next = NULL;
2157
2158         ut_params->auth_xform.auth.op = auth_op;
2159         ut_params->auth_xform.auth.algo = auth_algo;
2160         ut_params->auth_xform.auth.key.length = key_len;
2161         /* Hash key = cipher key */
2162         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2163         ut_params->auth_xform.auth.digest_length = auth_len;
2164         /* Auth IV will be after cipher IV */
2165         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2166         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2167
2168         /* Setup Cipher Parameters */
2169         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2170         ut_params->cipher_xform.next = &ut_params->auth_xform;
2171
2172         ut_params->cipher_xform.cipher.algo = cipher_algo;
2173         ut_params->cipher_xform.cipher.op = cipher_op;
2174         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2175         ut_params->cipher_xform.cipher.key.length = key_len;
2176         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2177         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2178
2179         debug_hexdump(stdout, "key:", key, key_len);
2180
2181         /* Create Crypto session*/
2182         ut_params->sess = rte_cryptodev_sym_session_create(
2183                         ts_params->session_mpool);
2184         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2185
2186         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2187                         &ut_params->cipher_xform,
2188                         ts_params->session_priv_mpool);
2189         if (status == -ENOTSUP)
2190                 return status;
2191
2192         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2193         return 0;
2194 }
2195
2196 static int
2197 create_wireless_cipher_auth_session(uint8_t dev_id,
2198                 enum rte_crypto_cipher_operation cipher_op,
2199                 enum rte_crypto_auth_operation auth_op,
2200                 enum rte_crypto_auth_algorithm auth_algo,
2201                 enum rte_crypto_cipher_algorithm cipher_algo,
2202                 const struct wireless_test_data *tdata)
2203 {
2204         const uint8_t key_len = tdata->key.len;
2205         uint8_t cipher_auth_key[key_len];
2206         int status;
2207
2208         struct crypto_testsuite_params *ts_params = &testsuite_params;
2209         struct crypto_unittest_params *ut_params = &unittest_params;
2210         const uint8_t *key = tdata->key.data;
2211         const uint8_t auth_len = tdata->digest.len;
2212         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2213         uint8_t auth_iv_len = tdata->auth_iv.len;
2214
2215         memcpy(cipher_auth_key, key, key_len);
2216
2217         /* Setup Authentication Parameters */
2218         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2219         ut_params->auth_xform.next = NULL;
2220
2221         ut_params->auth_xform.auth.op = auth_op;
2222         ut_params->auth_xform.auth.algo = auth_algo;
2223         ut_params->auth_xform.auth.key.length = key_len;
2224         /* Hash key = cipher key */
2225         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2226         ut_params->auth_xform.auth.digest_length = auth_len;
2227         /* Auth IV will be after cipher IV */
2228         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2229         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2230
2231         /* Setup Cipher Parameters */
2232         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2233         ut_params->cipher_xform.next = &ut_params->auth_xform;
2234
2235         ut_params->cipher_xform.cipher.algo = cipher_algo;
2236         ut_params->cipher_xform.cipher.op = cipher_op;
2237         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2238         ut_params->cipher_xform.cipher.key.length = key_len;
2239         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2240         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2241
2242
2243         debug_hexdump(stdout, "key:", key, key_len);
2244
2245         /* Create Crypto session*/
2246         ut_params->sess = rte_cryptodev_sym_session_create(
2247                         ts_params->session_mpool);
2248
2249         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2250                         &ut_params->cipher_xform,
2251                         ts_params->session_priv_mpool);
2252         if (status == -ENOTSUP)
2253                 return status;
2254
2255         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2256         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2257         return 0;
2258 }
2259
2260 static int
2261 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2262                 const struct wireless_test_data *tdata)
2263 {
2264         return create_wireless_cipher_auth_session(dev_id,
2265                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2266                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2267                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2268 }
2269
2270 static int
2271 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2272                 enum rte_crypto_cipher_operation cipher_op,
2273                 enum rte_crypto_auth_operation auth_op,
2274                 enum rte_crypto_auth_algorithm auth_algo,
2275                 enum rte_crypto_cipher_algorithm cipher_algo,
2276                 const uint8_t *key, const uint8_t key_len,
2277                 uint8_t auth_iv_len, uint8_t auth_len,
2278                 uint8_t cipher_iv_len)
2279 {
2280         uint8_t auth_cipher_key[key_len];
2281         int status;
2282         struct crypto_testsuite_params *ts_params = &testsuite_params;
2283         struct crypto_unittest_params *ut_params = &unittest_params;
2284
2285         memcpy(auth_cipher_key, key, key_len);
2286
2287         /* Setup Authentication Parameters */
2288         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2289         ut_params->auth_xform.auth.op = auth_op;
2290         ut_params->auth_xform.next = &ut_params->cipher_xform;
2291         ut_params->auth_xform.auth.algo = auth_algo;
2292         ut_params->auth_xform.auth.key.length = key_len;
2293         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2294         ut_params->auth_xform.auth.digest_length = auth_len;
2295         /* Auth IV will be after cipher IV */
2296         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2297         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2298
2299         /* Setup Cipher Parameters */
2300         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2301         ut_params->cipher_xform.next = NULL;
2302         ut_params->cipher_xform.cipher.algo = cipher_algo;
2303         ut_params->cipher_xform.cipher.op = cipher_op;
2304         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2305         ut_params->cipher_xform.cipher.key.length = key_len;
2306         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2307         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2308
2309         debug_hexdump(stdout, "key:", key, key_len);
2310
2311         /* Create Crypto session*/
2312         ut_params->sess = rte_cryptodev_sym_session_create(
2313                         ts_params->session_mpool);
2314         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2315
2316         if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2317                 ut_params->auth_xform.next = NULL;
2318                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2319                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2320                                 &ut_params->cipher_xform,
2321                                 ts_params->session_priv_mpool);
2322
2323         } else
2324                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2325                                 &ut_params->auth_xform,
2326                                 ts_params->session_priv_mpool);
2327
2328         if (status == -ENOTSUP)
2329                 return status;
2330
2331         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2332
2333         return 0;
2334 }
2335
2336 static int
2337 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2338                 unsigned int auth_tag_len,
2339                 const uint8_t *iv, unsigned int iv_len,
2340                 unsigned int data_pad_len,
2341                 enum rte_crypto_auth_operation op,
2342                 unsigned int auth_len, unsigned int auth_offset)
2343 {
2344         struct crypto_testsuite_params *ts_params = &testsuite_params;
2345
2346         struct crypto_unittest_params *ut_params = &unittest_params;
2347
2348         /* Generate Crypto op data structure */
2349         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2350                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2351         TEST_ASSERT_NOT_NULL(ut_params->op,
2352                 "Failed to allocate pktmbuf offload");
2353
2354         /* Set crypto operation data parameters */
2355         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2356
2357         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2358
2359         /* set crypto operation source mbuf */
2360         sym_op->m_src = ut_params->ibuf;
2361
2362         /* iv */
2363         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2364                         iv, iv_len);
2365         /* digest */
2366         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2367                                         ut_params->ibuf, auth_tag_len);
2368
2369         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2370                                 "no room to append auth tag");
2371         ut_params->digest = sym_op->auth.digest.data;
2372         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2373                         ut_params->ibuf, data_pad_len);
2374         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2375                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2376         else
2377                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2378
2379         debug_hexdump(stdout, "digest:",
2380                 sym_op->auth.digest.data,
2381                 auth_tag_len);
2382
2383         sym_op->auth.data.length = auth_len;
2384         sym_op->auth.data.offset = auth_offset;
2385
2386         return 0;
2387 }
2388
2389 static int
2390 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2391         enum rte_crypto_auth_operation op)
2392 {
2393         struct crypto_testsuite_params *ts_params = &testsuite_params;
2394         struct crypto_unittest_params *ut_params = &unittest_params;
2395
2396         const uint8_t *auth_tag = tdata->digest.data;
2397         const unsigned int auth_tag_len = tdata->digest.len;
2398         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2399         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2400
2401         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2402         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2403         const uint8_t *auth_iv = tdata->auth_iv.data;
2404         const uint8_t auth_iv_len = tdata->auth_iv.len;
2405         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2406         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2407
2408         /* Generate Crypto op data structure */
2409         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2410                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2411         TEST_ASSERT_NOT_NULL(ut_params->op,
2412                         "Failed to allocate pktmbuf offload");
2413         /* Set crypto operation data parameters */
2414         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2415
2416         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2417
2418         /* set crypto operation source mbuf */
2419         sym_op->m_src = ut_params->ibuf;
2420
2421         /* digest */
2422         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2423                         ut_params->ibuf, auth_tag_len);
2424
2425         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2426                         "no room to append auth tag");
2427         ut_params->digest = sym_op->auth.digest.data;
2428         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2429                         ut_params->ibuf, data_pad_len);
2430         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2431                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2432         else
2433                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2434
2435         debug_hexdump(stdout, "digest:",
2436                 sym_op->auth.digest.data,
2437                 auth_tag_len);
2438
2439         /* Copy cipher and auth IVs at the end of the crypto operation */
2440         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2441                                                 IV_OFFSET);
2442         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2443         iv_ptr += cipher_iv_len;
2444         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2445
2446         sym_op->cipher.data.length = cipher_len;
2447         sym_op->cipher.data.offset = 0;
2448         sym_op->auth.data.length = auth_len;
2449         sym_op->auth.data.offset = 0;
2450
2451         return 0;
2452 }
2453
2454 static int
2455 create_zuc_cipher_hash_generate_operation(
2456                 const struct wireless_test_data *tdata)
2457 {
2458         return create_wireless_cipher_hash_operation(tdata,
2459                 RTE_CRYPTO_AUTH_OP_GENERATE);
2460 }
2461
2462 static int
2463 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2464                 const unsigned auth_tag_len,
2465                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2466                 unsigned data_pad_len,
2467                 enum rte_crypto_auth_operation op,
2468                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2469                 const unsigned cipher_len, const unsigned cipher_offset,
2470                 const unsigned auth_len, const unsigned auth_offset)
2471 {
2472         struct crypto_testsuite_params *ts_params = &testsuite_params;
2473         struct crypto_unittest_params *ut_params = &unittest_params;
2474
2475         enum rte_crypto_cipher_algorithm cipher_algo =
2476                         ut_params->cipher_xform.cipher.algo;
2477         enum rte_crypto_auth_algorithm auth_algo =
2478                         ut_params->auth_xform.auth.algo;
2479
2480         /* Generate Crypto op data structure */
2481         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2482                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2483         TEST_ASSERT_NOT_NULL(ut_params->op,
2484                         "Failed to allocate pktmbuf offload");
2485         /* Set crypto operation data parameters */
2486         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2487
2488         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2489
2490         /* set crypto operation source mbuf */
2491         sym_op->m_src = ut_params->ibuf;
2492
2493         /* digest */
2494         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2495                         ut_params->ibuf, auth_tag_len);
2496
2497         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2498                         "no room to append auth tag");
2499         ut_params->digest = sym_op->auth.digest.data;
2500
2501         if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2502                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2503                                 ut_params->ibuf, data_pad_len);
2504         } else {
2505                 struct rte_mbuf *m = ut_params->ibuf;
2506                 unsigned int offset = data_pad_len;
2507
2508                 while (offset > m->data_len && m->next != NULL) {
2509                         offset -= m->data_len;
2510                         m = m->next;
2511                 }
2512                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2513                         m, offset);
2514         }
2515
2516         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2517                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2518         else
2519                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2520
2521         debug_hexdump(stdout, "digest:",
2522                 sym_op->auth.digest.data,
2523                 auth_tag_len);
2524
2525         /* Copy cipher and auth IVs at the end of the crypto operation */
2526         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2527                                                 IV_OFFSET);
2528         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2529         iv_ptr += cipher_iv_len;
2530         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2531
2532         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2533                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2534                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2535                 sym_op->cipher.data.length = cipher_len;
2536                 sym_op->cipher.data.offset = cipher_offset;
2537         } else {
2538                 sym_op->cipher.data.length = cipher_len >> 3;
2539                 sym_op->cipher.data.offset = cipher_offset >> 3;
2540         }
2541
2542         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2543                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2544                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2545                 sym_op->auth.data.length = auth_len;
2546                 sym_op->auth.data.offset = auth_offset;
2547         } else {
2548                 sym_op->auth.data.length = auth_len >> 3;
2549                 sym_op->auth.data.offset = auth_offset >> 3;
2550         }
2551
2552         return 0;
2553 }
2554
2555 static int
2556 create_wireless_algo_auth_cipher_operation(
2557                 const uint8_t *auth_tag, unsigned int auth_tag_len,
2558                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2559                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2560                 unsigned int data_pad_len,
2561                 unsigned int cipher_len, unsigned int cipher_offset,
2562                 unsigned int auth_len, unsigned int auth_offset,
2563                 uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2564 {
2565         struct crypto_testsuite_params *ts_params = &testsuite_params;
2566         struct crypto_unittest_params *ut_params = &unittest_params;
2567
2568         enum rte_crypto_cipher_algorithm cipher_algo =
2569                         ut_params->cipher_xform.cipher.algo;
2570         enum rte_crypto_auth_algorithm auth_algo =
2571                         ut_params->auth_xform.auth.algo;
2572
2573         /* Generate Crypto op data structure */
2574         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2575                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2576         TEST_ASSERT_NOT_NULL(ut_params->op,
2577                         "Failed to allocate pktmbuf offload");
2578
2579         /* Set crypto operation data parameters */
2580         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2581
2582         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2583
2584         /* set crypto operation mbufs */
2585         sym_op->m_src = ut_params->ibuf;
2586         if (op_mode == OUT_OF_PLACE)
2587                 sym_op->m_dst = ut_params->obuf;
2588
2589         /* digest */
2590         if (!do_sgl) {
2591                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2592                         (op_mode == IN_PLACE ?
2593                                 ut_params->ibuf : ut_params->obuf),
2594                         uint8_t *, data_pad_len);
2595                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2596                         (op_mode == IN_PLACE ?
2597                                 ut_params->ibuf : ut_params->obuf),
2598                         data_pad_len);
2599                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2600         } else {
2601                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2602                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2603                                 sym_op->m_src : sym_op->m_dst);
2604                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2605                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2606                         sgl_buf = sgl_buf->next;
2607                 }
2608                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2609                                 uint8_t *, remaining_off);
2610                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2611                                 remaining_off);
2612                 memset(sym_op->auth.digest.data, 0, remaining_off);
2613                 while (sgl_buf->next != NULL) {
2614                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2615                                 0, rte_pktmbuf_data_len(sgl_buf));
2616                         sgl_buf = sgl_buf->next;
2617                 }
2618         }
2619
2620         /* Copy digest for the verification */
2621         if (verify)
2622                 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2623
2624         /* Copy cipher and auth IVs at the end of the crypto operation */
2625         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
2626                         ut_params->op, uint8_t *, IV_OFFSET);
2627
2628         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2629         iv_ptr += cipher_iv_len;
2630         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2631
2632         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2633                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2634                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2635                 sym_op->cipher.data.length = cipher_len;
2636                 sym_op->cipher.data.offset = cipher_offset;
2637         } else {
2638                 sym_op->cipher.data.length = cipher_len >> 3;
2639                 sym_op->cipher.data.offset = cipher_offset >> 3;
2640         }
2641
2642         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2643                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2644                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2645                 sym_op->auth.data.length = auth_len;
2646                 sym_op->auth.data.offset = auth_offset;
2647         } else {
2648                 sym_op->auth.data.length = auth_len >> 3;
2649                 sym_op->auth.data.offset = auth_offset >> 3;
2650         }
2651
2652         return 0;
2653 }
2654
2655 static int
2656 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2657 {
2658         struct crypto_testsuite_params *ts_params = &testsuite_params;
2659         struct crypto_unittest_params *ut_params = &unittest_params;
2660
2661         int retval;
2662         unsigned plaintext_pad_len;
2663         unsigned plaintext_len;
2664         uint8_t *plaintext;
2665         struct rte_cryptodev_info dev_info;
2666
2667         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2668         uint64_t feat_flags = dev_info.feature_flags;
2669
2670         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
2671                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
2672                 printf("Device doesn't support NON-Byte Aligned Data.\n");
2673                 return -ENOTSUP;
2674         }
2675
2676         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2677                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2678                 printf("Device doesn't support RAW data-path APIs.\n");
2679                 return -ENOTSUP;
2680         }
2681
2682         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2683                 return -ENOTSUP;
2684
2685         /* Verify the capabilities */
2686         struct rte_cryptodev_sym_capability_idx cap_idx;
2687         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2688         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2689         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2690                         &cap_idx) == NULL)
2691                 return -ENOTSUP;
2692
2693         /* Create SNOW 3G session */
2694         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2695                         tdata->key.data, tdata->key.len,
2696                         tdata->auth_iv.len, tdata->digest.len,
2697                         RTE_CRYPTO_AUTH_OP_GENERATE,
2698                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2699         if (retval < 0)
2700                 return retval;
2701
2702         /* alloc mbuf and set payload */
2703         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2704
2705         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2706         rte_pktmbuf_tailroom(ut_params->ibuf));
2707
2708         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2709         /* Append data which is padded to a multiple of */
2710         /* the algorithms block size */
2711         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2712         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2713                                 plaintext_pad_len);
2714         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2715
2716         /* Create SNOW 3G operation */
2717         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2718                         tdata->auth_iv.data, tdata->auth_iv.len,
2719                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2720                         tdata->validAuthLenInBits.len,
2721                         0);
2722         if (retval < 0)
2723                 return retval;
2724
2725         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2726                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2727                                 ut_params->op, 0, 1, 1, 0);
2728         else
2729                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2730                                 ut_params->op);
2731         ut_params->obuf = ut_params->op->sym->m_src;
2732         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2733         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2734                         + plaintext_pad_len;
2735
2736         /* Validate obuf */
2737         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2738         ut_params->digest,
2739         tdata->digest.data,
2740         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2741         "SNOW 3G Generated auth tag not as expected");
2742
2743         return 0;
2744 }
2745
2746 static int
2747 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2748 {
2749         struct crypto_testsuite_params *ts_params = &testsuite_params;
2750         struct crypto_unittest_params *ut_params = &unittest_params;
2751
2752         int retval;
2753         unsigned plaintext_pad_len;
2754         unsigned plaintext_len;
2755         uint8_t *plaintext;
2756         struct rte_cryptodev_info dev_info;
2757
2758         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2759         uint64_t feat_flags = dev_info.feature_flags;
2760
2761         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
2762                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
2763                 printf("Device doesn't support NON-Byte Aligned Data.\n");
2764                 return -ENOTSUP;
2765         }
2766
2767         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2768                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2769                 printf("Device doesn't support RAW data-path APIs.\n");
2770                 return -ENOTSUP;
2771         }
2772
2773         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2774                 return -ENOTSUP;
2775
2776         /* Verify the capabilities */
2777         struct rte_cryptodev_sym_capability_idx cap_idx;
2778         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2779         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2780         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2781                         &cap_idx) == NULL)
2782                 return -ENOTSUP;
2783
2784         /* Create SNOW 3G session */
2785         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2786                                 tdata->key.data, tdata->key.len,
2787                                 tdata->auth_iv.len, tdata->digest.len,
2788                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2789                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2790         if (retval < 0)
2791                 return retval;
2792         /* alloc mbuf and set payload */
2793         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2794
2795         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2796         rte_pktmbuf_tailroom(ut_params->ibuf));
2797
2798         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2799         /* Append data which is padded to a multiple of */
2800         /* the algorithms block size */
2801         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2802         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2803                                 plaintext_pad_len);
2804         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2805
2806         /* Create SNOW 3G operation */
2807         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2808                         tdata->digest.len,
2809                         tdata->auth_iv.data, tdata->auth_iv.len,
2810                         plaintext_pad_len,
2811                         RTE_CRYPTO_AUTH_OP_VERIFY,
2812                         tdata->validAuthLenInBits.len,
2813                         0);
2814         if (retval < 0)
2815                 return retval;
2816
2817         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2818                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2819                                 ut_params->op, 0, 1, 1, 0);
2820         else
2821                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2822                                 ut_params->op);
2823         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2824         ut_params->obuf = ut_params->op->sym->m_src;
2825         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2826                                 + plaintext_pad_len;
2827
2828         /* Validate obuf */
2829         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2830                 return 0;
2831         else
2832                 return -1;
2833
2834         return 0;
2835 }
2836
2837 static int
2838 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
2839 {
2840         struct crypto_testsuite_params *ts_params = &testsuite_params;
2841         struct crypto_unittest_params *ut_params = &unittest_params;
2842
2843         int retval;
2844         unsigned plaintext_pad_len;
2845         unsigned plaintext_len;
2846         uint8_t *plaintext;
2847         struct rte_cryptodev_info dev_info;
2848
2849         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2850         uint64_t feat_flags = dev_info.feature_flags;
2851
2852         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2853                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2854                 printf("Device doesn't support RAW data-path APIs.\n");
2855                 return -ENOTSUP;
2856         }
2857
2858         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2859                 return -ENOTSUP;
2860
2861         /* Verify the capabilities */
2862         struct rte_cryptodev_sym_capability_idx cap_idx;
2863         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2864         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
2865         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2866                         &cap_idx) == NULL)
2867                 return -ENOTSUP;
2868
2869         /* Create KASUMI session */
2870         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2871                         tdata->key.data, tdata->key.len,
2872                         0, tdata->digest.len,
2873                         RTE_CRYPTO_AUTH_OP_GENERATE,
2874                         RTE_CRYPTO_AUTH_KASUMI_F9);
2875         if (retval < 0)
2876                 return retval;
2877
2878         /* alloc mbuf and set payload */
2879         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2880
2881         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2882         rte_pktmbuf_tailroom(ut_params->ibuf));
2883
2884         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2885         /* Append data which is padded to a multiple of */
2886         /* the algorithms block size */
2887         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2888         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2889                                 plaintext_pad_len);
2890         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2891
2892         /* Create KASUMI operation */
2893         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2894                         NULL, 0,
2895                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2896                         tdata->plaintext.len,
2897                         0);
2898         if (retval < 0)
2899                 return retval;
2900
2901         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2902                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2903                         ut_params->op);
2904         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2905                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2906                                 ut_params->op, 0, 1, 1, 0);
2907         else
2908                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2909                         ut_params->op);
2910
2911         ut_params->obuf = ut_params->op->sym->m_src;
2912         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2913         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2914                         + plaintext_pad_len;
2915
2916         /* Validate obuf */
2917         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2918         ut_params->digest,
2919         tdata->digest.data,
2920         DIGEST_BYTE_LENGTH_KASUMI_F9,
2921         "KASUMI Generated auth tag not as expected");
2922
2923         return 0;
2924 }
2925
2926 static int
2927 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
2928 {
2929         struct crypto_testsuite_params *ts_params = &testsuite_params;
2930         struct crypto_unittest_params *ut_params = &unittest_params;
2931
2932         int retval;
2933         unsigned plaintext_pad_len;
2934         unsigned plaintext_len;
2935         uint8_t *plaintext;
2936         struct rte_cryptodev_info dev_info;
2937
2938         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2939         uint64_t feat_flags = dev_info.feature_flags;
2940
2941         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2942                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2943                 printf("Device doesn't support RAW data-path APIs.\n");
2944                 return -ENOTSUP;
2945         }
2946
2947         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2948                 return -ENOTSUP;
2949
2950         /* Verify the capabilities */
2951         struct rte_cryptodev_sym_capability_idx cap_idx;
2952         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2953         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
2954         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2955                         &cap_idx) == NULL)
2956                 return -ENOTSUP;
2957
2958         /* Create KASUMI session */
2959         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2960                                 tdata->key.data, tdata->key.len,
2961                                 0, tdata->digest.len,
2962                                 RTE_CRYPTO_AUTH_OP_VERIFY,
2963                                 RTE_CRYPTO_AUTH_KASUMI_F9);
2964         if (retval < 0)
2965                 return retval;
2966         /* alloc mbuf and set payload */
2967         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2968
2969         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2970         rte_pktmbuf_tailroom(ut_params->ibuf));
2971
2972         plaintext_len = ceil_byte_length(tdata->plaintext.len);
2973         /* Append data which is padded to a multiple */
2974         /* of the algorithms block size */
2975         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2976         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2977                                 plaintext_pad_len);
2978         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2979
2980         /* Create KASUMI operation */
2981         retval = create_wireless_algo_hash_operation(tdata->digest.data,
2982                         tdata->digest.len,
2983                         NULL, 0,
2984                         plaintext_pad_len,
2985                         RTE_CRYPTO_AUTH_OP_VERIFY,
2986                         tdata->plaintext.len,
2987                         0);
2988         if (retval < 0)
2989                 return retval;
2990
2991         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2992                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2993                                 ut_params->op, 0, 1, 1, 0);
2994         else
2995                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2996                                 ut_params->op);
2997         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2998         ut_params->obuf = ut_params->op->sym->m_src;
2999         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3000                                 + plaintext_pad_len;
3001
3002         /* Validate obuf */
3003         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3004                 return 0;
3005         else
3006                 return -1;
3007
3008         return 0;
3009 }
3010
3011 static int
3012 test_snow3g_hash_generate_test_case_1(void)
3013 {
3014         return test_snow3g_authentication(&snow3g_hash_test_case_1);
3015 }
3016
3017 static int
3018 test_snow3g_hash_generate_test_case_2(void)
3019 {
3020         return test_snow3g_authentication(&snow3g_hash_test_case_2);
3021 }
3022
3023 static int
3024 test_snow3g_hash_generate_test_case_3(void)
3025 {
3026         return test_snow3g_authentication(&snow3g_hash_test_case_3);
3027 }
3028
3029 static int
3030 test_snow3g_hash_generate_test_case_4(void)
3031 {
3032         return test_snow3g_authentication(&snow3g_hash_test_case_4);
3033 }
3034
3035 static int
3036 test_snow3g_hash_generate_test_case_5(void)
3037 {
3038         return test_snow3g_authentication(&snow3g_hash_test_case_5);
3039 }
3040
3041 static int
3042 test_snow3g_hash_generate_test_case_6(void)
3043 {
3044         return test_snow3g_authentication(&snow3g_hash_test_case_6);
3045 }
3046
3047 static int
3048 test_snow3g_hash_verify_test_case_1(void)
3049 {
3050         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3051
3052 }
3053
3054 static int
3055 test_snow3g_hash_verify_test_case_2(void)
3056 {
3057         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3058 }
3059
3060 static int
3061 test_snow3g_hash_verify_test_case_3(void)
3062 {
3063         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3064 }
3065
3066 static int
3067 test_snow3g_hash_verify_test_case_4(void)
3068 {
3069         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3070 }
3071
3072 static int
3073 test_snow3g_hash_verify_test_case_5(void)
3074 {
3075         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3076 }
3077
3078 static int
3079 test_snow3g_hash_verify_test_case_6(void)
3080 {
3081         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3082 }
3083
3084 static int
3085 test_kasumi_hash_generate_test_case_1(void)
3086 {
3087         return test_kasumi_authentication(&kasumi_hash_test_case_1);
3088 }
3089
3090 static int
3091 test_kasumi_hash_generate_test_case_2(void)
3092 {
3093         return test_kasumi_authentication(&kasumi_hash_test_case_2);
3094 }
3095
3096 static int
3097 test_kasumi_hash_generate_test_case_3(void)
3098 {
3099         return test_kasumi_authentication(&kasumi_hash_test_case_3);
3100 }
3101
3102 static int
3103 test_kasumi_hash_generate_test_case_4(void)
3104 {
3105         return test_kasumi_authentication(&kasumi_hash_test_case_4);
3106 }
3107
3108 static int
3109 test_kasumi_hash_generate_test_case_5(void)
3110 {
3111         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3112 }
3113
3114 static int
3115 test_kasumi_hash_generate_test_case_6(void)
3116 {
3117         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3118 }
3119
3120 static int
3121 test_kasumi_hash_verify_test_case_1(void)
3122 {
3123         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3124 }
3125
3126 static int
3127 test_kasumi_hash_verify_test_case_2(void)
3128 {
3129         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3130 }
3131
3132 static int
3133 test_kasumi_hash_verify_test_case_3(void)
3134 {
3135         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3136 }
3137
3138 static int
3139 test_kasumi_hash_verify_test_case_4(void)
3140 {
3141         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3142 }
3143
3144 static int
3145 test_kasumi_hash_verify_test_case_5(void)
3146 {
3147         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3148 }
3149
3150 static int
3151 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3152 {
3153         struct crypto_testsuite_params *ts_params = &testsuite_params;
3154         struct crypto_unittest_params *ut_params = &unittest_params;
3155
3156         int retval;
3157         uint8_t *plaintext, *ciphertext;
3158         unsigned plaintext_pad_len;
3159         unsigned plaintext_len;
3160         struct rte_cryptodev_info dev_info;
3161
3162         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3163         uint64_t feat_flags = dev_info.feature_flags;
3164
3165         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3166                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3167                 printf("Device doesn't support RAW data-path APIs.\n");
3168                 return -ENOTSUP;
3169         }
3170
3171         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3172                 return -ENOTSUP;
3173
3174         /* Verify the capabilities */
3175         struct rte_cryptodev_sym_capability_idx cap_idx;
3176         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3177         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3178         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3179                         &cap_idx) == NULL)
3180                 return -ENOTSUP;
3181
3182         /* Create KASUMI session */
3183         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3184                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3185                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3186                                         tdata->key.data, tdata->key.len,
3187                                         tdata->cipher_iv.len);
3188         if (retval < 0)
3189                 return retval;
3190
3191         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3192
3193         /* Clear mbuf payload */
3194         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3195                rte_pktmbuf_tailroom(ut_params->ibuf));
3196
3197         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3198         /* Append data which is padded to a multiple */
3199         /* of the algorithms block size */
3200         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3201         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3202                                 plaintext_pad_len);
3203         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3204
3205         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3206
3207         /* Create KASUMI operation */
3208         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3209                                 tdata->cipher_iv.len,
3210                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3211                                 tdata->validCipherOffsetInBits.len);
3212         if (retval < 0)
3213                 return retval;
3214
3215         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3216                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3217                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3218         else
3219                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3220                                 ut_params->op);
3221         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3222
3223         ut_params->obuf = ut_params->op->sym->m_dst;
3224         if (ut_params->obuf)
3225                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3226         else
3227                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3228
3229         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3230
3231         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3232                                 (tdata->validCipherOffsetInBits.len >> 3);
3233         /* Validate obuf */
3234         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3235                 ciphertext,
3236                 reference_ciphertext,
3237                 tdata->validCipherLenInBits.len,
3238                 "KASUMI Ciphertext data not as expected");
3239         return 0;
3240 }
3241
3242 static int
3243 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3244 {
3245         struct crypto_testsuite_params *ts_params = &testsuite_params;
3246         struct crypto_unittest_params *ut_params = &unittest_params;
3247
3248         int retval;
3249
3250         unsigned int plaintext_pad_len;
3251         unsigned int plaintext_len;
3252
3253         uint8_t buffer[10000];
3254         const uint8_t *ciphertext;
3255
3256         struct rte_cryptodev_info dev_info;
3257
3258         /* Verify the capabilities */
3259         struct rte_cryptodev_sym_capability_idx cap_idx;
3260         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3261         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3262         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3263                         &cap_idx) == NULL)
3264                 return -ENOTSUP;
3265
3266         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3267
3268         uint64_t feat_flags = dev_info.feature_flags;
3269
3270         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3271                 printf("Device doesn't support in-place scatter-gather. "
3272                                 "Test Skipped.\n");
3273                 return -ENOTSUP;
3274         }
3275
3276         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3277                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3278                 printf("Device doesn't support RAW data-path APIs.\n");
3279                 return -ENOTSUP;
3280         }
3281
3282         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3283                 return -ENOTSUP;
3284
3285         /* Create KASUMI session */
3286         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3287                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3288                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3289                                         tdata->key.data, tdata->key.len,
3290                                         tdata->cipher_iv.len);
3291         if (retval < 0)
3292                 return retval;
3293
3294         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3295
3296
3297         /* Append data which is padded to a multiple */
3298         /* of the algorithms block size */
3299         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3300
3301         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3302                         plaintext_pad_len, 10, 0);
3303
3304         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3305
3306         /* Create KASUMI operation */
3307         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3308                                 tdata->cipher_iv.len,
3309                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3310                                 tdata->validCipherOffsetInBits.len);
3311         if (retval < 0)
3312                 return retval;
3313
3314         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3315                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3316                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3317         else
3318                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3319                                                 ut_params->op);
3320         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3321
3322         ut_params->obuf = ut_params->op->sym->m_dst;
3323
3324         if (ut_params->obuf)
3325                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3326                                 plaintext_len, buffer);
3327         else
3328                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3329                                 tdata->validCipherOffsetInBits.len >> 3,
3330                                 plaintext_len, buffer);
3331
3332         /* Validate obuf */
3333         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3334
3335         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3336                                 (tdata->validCipherOffsetInBits.len >> 3);
3337         /* Validate obuf */
3338         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3339                 ciphertext,
3340                 reference_ciphertext,
3341                 tdata->validCipherLenInBits.len,
3342                 "KASUMI Ciphertext data not as expected");
3343         return 0;
3344 }
3345
3346 static int
3347 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3348 {
3349         struct crypto_testsuite_params *ts_params = &testsuite_params;
3350         struct crypto_unittest_params *ut_params = &unittest_params;
3351
3352         int retval;
3353         uint8_t *plaintext, *ciphertext;
3354         unsigned plaintext_pad_len;
3355         unsigned plaintext_len;
3356
3357         /* Verify the capabilities */
3358         struct rte_cryptodev_sym_capability_idx cap_idx;
3359         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3360         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3361         /* Data-path service does not support OOP */
3362         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3363                         &cap_idx) == NULL)
3364                 return -ENOTSUP;
3365
3366         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3367                 return -ENOTSUP;
3368
3369         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3370                 return -ENOTSUP;
3371
3372         /* Create KASUMI session */
3373         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3374                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3375                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3376                                         tdata->key.data, tdata->key.len,
3377                                         tdata->cipher_iv.len);
3378         if (retval < 0)
3379                 return retval;
3380
3381         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3382         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3383
3384         /* Clear mbuf payload */
3385         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3386                rte_pktmbuf_tailroom(ut_params->ibuf));
3387
3388         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3389         /* Append data which is padded to a multiple */
3390         /* of the algorithms block size */
3391         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3392         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3393                                 plaintext_pad_len);
3394         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3395         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3396
3397         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3398
3399         /* Create KASUMI operation */
3400         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3401                                 tdata->cipher_iv.len,
3402                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3403                                 tdata->validCipherOffsetInBits.len);
3404         if (retval < 0)
3405                 return retval;
3406
3407         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3408                                                 ut_params->op);
3409         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3410
3411         ut_params->obuf = ut_params->op->sym->m_dst;
3412         if (ut_params->obuf)
3413                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3414         else
3415                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3416
3417         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3418
3419         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3420                                 (tdata->validCipherOffsetInBits.len >> 3);
3421         /* Validate obuf */
3422         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3423                 ciphertext,
3424                 reference_ciphertext,
3425                 tdata->validCipherLenInBits.len,
3426                 "KASUMI Ciphertext data not as expected");
3427         return 0;
3428 }
3429
3430 static int
3431 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3432 {
3433         struct crypto_testsuite_params *ts_params = &testsuite_params;
3434         struct crypto_unittest_params *ut_params = &unittest_params;
3435
3436         int retval;
3437         unsigned int plaintext_pad_len;
3438         unsigned int plaintext_len;
3439
3440         const uint8_t *ciphertext;
3441         uint8_t buffer[2048];
3442
3443         struct rte_cryptodev_info dev_info;
3444
3445         /* Verify the capabilities */
3446         struct rte_cryptodev_sym_capability_idx cap_idx;
3447         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3448         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3449         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3450                         &cap_idx) == NULL)
3451                 return -ENOTSUP;
3452
3453         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3454                 return -ENOTSUP;
3455
3456         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3457                 return -ENOTSUP;
3458
3459         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3460
3461         uint64_t feat_flags = dev_info.feature_flags;
3462         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3463                 printf("Device doesn't support out-of-place scatter-gather "
3464                                 "in both input and output mbufs. "
3465                                 "Test Skipped.\n");
3466                 return -ENOTSUP;
3467         }
3468
3469         /* Create KASUMI session */
3470         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3471                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3472                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3473                                         tdata->key.data, tdata->key.len,
3474                                         tdata->cipher_iv.len);
3475         if (retval < 0)
3476                 return retval;
3477
3478         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3479         /* Append data which is padded to a multiple */
3480         /* of the algorithms block size */
3481         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3482
3483         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3484                         plaintext_pad_len, 10, 0);
3485         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3486                         plaintext_pad_len, 3, 0);
3487
3488         /* Append data which is padded to a multiple */
3489         /* of the algorithms block size */
3490         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3491
3492         /* Create KASUMI operation */
3493         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3494                                 tdata->cipher_iv.len,
3495                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3496                                 tdata->validCipherOffsetInBits.len);
3497         if (retval < 0)
3498                 return retval;
3499
3500         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3501                                                 ut_params->op);
3502         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3503
3504         ut_params->obuf = ut_params->op->sym->m_dst;
3505         if (ut_params->obuf)
3506                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3507                                 plaintext_pad_len, buffer);
3508         else
3509                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3510                                 tdata->validCipherOffsetInBits.len >> 3,
3511                                 plaintext_pad_len, buffer);
3512
3513         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3514                                 (tdata->validCipherOffsetInBits.len >> 3);
3515         /* Validate obuf */
3516         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3517                 ciphertext,
3518                 reference_ciphertext,
3519                 tdata->validCipherLenInBits.len,
3520                 "KASUMI Ciphertext data not as expected");
3521         return 0;
3522 }
3523
3524
3525 static int
3526 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3527 {
3528         struct crypto_testsuite_params *ts_params = &testsuite_params;
3529         struct crypto_unittest_params *ut_params = &unittest_params;
3530
3531         int retval;
3532         uint8_t *ciphertext, *plaintext;
3533         unsigned ciphertext_pad_len;
3534         unsigned ciphertext_len;
3535
3536         /* Verify the capabilities */
3537         struct rte_cryptodev_sym_capability_idx cap_idx;
3538         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3539         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3540         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3541                         &cap_idx) == NULL)
3542                 return -ENOTSUP;
3543
3544         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3545                 return -ENOTSUP;
3546
3547         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3548                 return -ENOTSUP;
3549
3550         /* Create KASUMI session */
3551         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3552                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3553                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3554                                         tdata->key.data, tdata->key.len,
3555                                         tdata->cipher_iv.len);
3556         if (retval < 0)
3557                 return retval;
3558
3559         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3560         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3561
3562         /* Clear mbuf payload */
3563         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3564                rte_pktmbuf_tailroom(ut_params->ibuf));
3565
3566         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3567         /* Append data which is padded to a multiple */
3568         /* of the algorithms block size */
3569         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3570         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3571                                 ciphertext_pad_len);
3572         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3573         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3574
3575         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3576
3577         /* Create KASUMI operation */
3578         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3579                                 tdata->cipher_iv.len,
3580                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3581                                 tdata->validCipherOffsetInBits.len);
3582         if (retval < 0)
3583                 return retval;
3584
3585         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3586                                                 ut_params->op);
3587         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3588
3589         ut_params->obuf = ut_params->op->sym->m_dst;
3590         if (ut_params->obuf)
3591                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3592         else
3593                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3594
3595         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3596
3597         const uint8_t *reference_plaintext = tdata->plaintext.data +
3598                                 (tdata->validCipherOffsetInBits.len >> 3);
3599         /* Validate obuf */
3600         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3601                 plaintext,
3602                 reference_plaintext,
3603                 tdata->validCipherLenInBits.len,
3604                 "KASUMI Plaintext data not as expected");
3605         return 0;
3606 }
3607
3608 static int
3609 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3610 {
3611         struct crypto_testsuite_params *ts_params = &testsuite_params;
3612         struct crypto_unittest_params *ut_params = &unittest_params;
3613
3614         int retval;
3615         uint8_t *ciphertext, *plaintext;
3616         unsigned ciphertext_pad_len;
3617         unsigned ciphertext_len;
3618         struct rte_cryptodev_info dev_info;
3619
3620         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3621         uint64_t feat_flags = dev_info.feature_flags;
3622
3623         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3624                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3625                 printf("Device doesn't support RAW data-path APIs.\n");
3626                 return -ENOTSUP;
3627         }
3628
3629         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3630                 return -ENOTSUP;
3631
3632         /* Verify the capabilities */
3633         struct rte_cryptodev_sym_capability_idx cap_idx;
3634         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3635         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3636         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3637                         &cap_idx) == NULL)
3638                 return -ENOTSUP;
3639
3640         /* Create KASUMI session */
3641         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3642                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3643                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3644                                         tdata->key.data, tdata->key.len,
3645                                         tdata->cipher_iv.len);
3646         if (retval < 0)
3647                 return retval;
3648
3649         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3650
3651         /* Clear mbuf payload */
3652         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3653                rte_pktmbuf_tailroom(ut_params->ibuf));
3654
3655         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3656         /* Append data which is padded to a multiple */
3657         /* of the algorithms block size */
3658         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3659         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3660                                 ciphertext_pad_len);
3661         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3662
3663         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3664
3665         /* Create KASUMI operation */
3666         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3667                                         tdata->cipher_iv.len,
3668                                         tdata->ciphertext.len,
3669                                         tdata->validCipherOffsetInBits.len);
3670         if (retval < 0)
3671                 return retval;
3672
3673         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3674                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3675                                 ut_params->op, 1, 0, 1, 0);
3676         else
3677                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3678                                                 ut_params->op);
3679         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3680
3681         ut_params->obuf = ut_params->op->sym->m_dst;
3682         if (ut_params->obuf)
3683                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3684         else
3685                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3686
3687         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3688
3689         const uint8_t *reference_plaintext = tdata->plaintext.data +
3690                                 (tdata->validCipherOffsetInBits.len >> 3);
3691         /* Validate obuf */
3692         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3693                 plaintext,
3694                 reference_plaintext,
3695                 tdata->validCipherLenInBits.len,
3696                 "KASUMI Plaintext data not as expected");
3697         return 0;
3698 }
3699
3700 static int
3701 test_snow3g_encryption(const struct snow3g_test_data *tdata)
3702 {
3703         struct crypto_testsuite_params *ts_params = &testsuite_params;
3704         struct crypto_unittest_params *ut_params = &unittest_params;
3705
3706         int retval;
3707         uint8_t *plaintext, *ciphertext;
3708         unsigned plaintext_pad_len;
3709         unsigned plaintext_len;
3710         struct rte_cryptodev_info dev_info;
3711
3712         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3713         uint64_t feat_flags = dev_info.feature_flags;
3714
3715         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3716                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3717                 printf("Device doesn't support RAW data-path APIs.\n");
3718                 return -ENOTSUP;
3719         }
3720
3721         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3722                 return -ENOTSUP;
3723
3724         /* Verify the capabilities */
3725         struct rte_cryptodev_sym_capability_idx cap_idx;
3726         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3727         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3728         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3729                         &cap_idx) == NULL)
3730                 return -ENOTSUP;
3731
3732         /* Create SNOW 3G session */
3733         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3734                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3735                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3736                                         tdata->key.data, tdata->key.len,
3737                                         tdata->cipher_iv.len);
3738         if (retval < 0)
3739                 return retval;
3740
3741         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3742
3743         /* Clear mbuf payload */
3744         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3745                rte_pktmbuf_tailroom(ut_params->ibuf));
3746
3747         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3748         /* Append data which is padded to a multiple of */
3749         /* the algorithms block size */
3750         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3751         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3752                                 plaintext_pad_len);
3753         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3754
3755         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3756
3757         /* Create SNOW 3G operation */
3758         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3759                                         tdata->cipher_iv.len,
3760                                         tdata->validCipherLenInBits.len,
3761                                         0);
3762         if (retval < 0)
3763                 return retval;
3764
3765         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3766                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3767                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3768         else
3769                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3770                                                 ut_params->op);
3771         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3772
3773         ut_params->obuf = ut_params->op->sym->m_dst;
3774         if (ut_params->obuf)
3775                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3776         else
3777                 ciphertext = plaintext;
3778
3779         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3780
3781         /* Validate obuf */
3782         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3783                 ciphertext,
3784                 tdata->ciphertext.data,
3785                 tdata->validDataLenInBits.len,
3786                 "SNOW 3G Ciphertext data not as expected");
3787         return 0;
3788 }
3789
3790
3791 static int
3792 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
3793 {
3794         struct crypto_testsuite_params *ts_params = &testsuite_params;
3795         struct crypto_unittest_params *ut_params = &unittest_params;
3796         uint8_t *plaintext, *ciphertext;
3797
3798         int retval;
3799         unsigned plaintext_pad_len;
3800         unsigned plaintext_len;
3801
3802         /* Verify the capabilities */
3803         struct rte_cryptodev_sym_capability_idx cap_idx;
3804         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3805         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3806         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3807                         &cap_idx) == NULL)
3808                 return -ENOTSUP;
3809
3810         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3811                 return -ENOTSUP;
3812
3813         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3814                 return -ENOTSUP;
3815
3816         /* Create SNOW 3G session */
3817         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3818                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3819                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3820                                         tdata->key.data, tdata->key.len,
3821                                         tdata->cipher_iv.len);
3822         if (retval < 0)
3823                 return retval;
3824
3825         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3826         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3827
3828         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3829                         "Failed to allocate input buffer in mempool");
3830         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3831                         "Failed to allocate output buffer in mempool");
3832
3833         /* Clear mbuf payload */
3834         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3835                rte_pktmbuf_tailroom(ut_params->ibuf));
3836
3837         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3838         /* Append data which is padded to a multiple of */
3839         /* the algorithms block size */
3840         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3841         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3842                                 plaintext_pad_len);
3843         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3844         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3845
3846         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3847
3848         /* Create SNOW 3G operation */
3849         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3850                                         tdata->cipher_iv.len,
3851                                         tdata->validCipherLenInBits.len,
3852                                         0);
3853         if (retval < 0)
3854                 return retval;
3855
3856         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3857                                                 ut_params->op);
3858         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3859
3860         ut_params->obuf = ut_params->op->sym->m_dst;
3861         if (ut_params->obuf)
3862                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3863         else
3864                 ciphertext = plaintext;
3865
3866         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3867
3868         /* Validate obuf */
3869         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3870                 ciphertext,
3871                 tdata->ciphertext.data,
3872                 tdata->validDataLenInBits.len,
3873                 "SNOW 3G Ciphertext data not as expected");
3874         return 0;
3875 }
3876
3877 static int
3878 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
3879 {
3880         struct crypto_testsuite_params *ts_params = &testsuite_params;
3881         struct crypto_unittest_params *ut_params = &unittest_params;
3882
3883         int retval;
3884         unsigned int plaintext_pad_len;
3885         unsigned int plaintext_len;
3886         uint8_t buffer[10000];
3887         const uint8_t *ciphertext;
3888
3889         struct rte_cryptodev_info dev_info;
3890
3891         /* Verify the capabilities */
3892         struct rte_cryptodev_sym_capability_idx cap_idx;
3893         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3894         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3895         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3896                         &cap_idx) == NULL)
3897                 return -ENOTSUP;
3898
3899         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3900                 return -ENOTSUP;
3901
3902         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3903                 return -ENOTSUP;
3904
3905         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3906
3907         uint64_t feat_flags = dev_info.feature_flags;
3908
3909         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3910                 printf("Device doesn't support out-of-place scatter-gather "
3911                                 "in both input and output mbufs. "
3912                                 "Test Skipped.\n");
3913                 return -ENOTSUP;
3914         }
3915
3916         /* Create SNOW 3G session */
3917         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3918                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3919                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3920                                         tdata->key.data, tdata->key.len,
3921                                         tdata->cipher_iv.len);
3922         if (retval < 0)
3923                 return retval;
3924
3925         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3926         /* Append data which is padded to a multiple of */
3927         /* the algorithms block size */
3928         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3929
3930         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3931                         plaintext_pad_len, 10, 0);
3932         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3933                         plaintext_pad_len, 3, 0);
3934
3935         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3936                         "Failed to allocate input buffer in mempool");
3937         TEST_ASSERT_NOT_NULL(ut_params->obuf,
3938                         "Failed to allocate output buffer in mempool");
3939
3940         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3941
3942         /* Create SNOW 3G operation */
3943         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3944                                         tdata->cipher_iv.len,
3945                                         tdata->validCipherLenInBits.len,
3946                                         0);
3947         if (retval < 0)
3948                 return retval;
3949
3950         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3951                                                 ut_params->op);
3952         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3953
3954         ut_params->obuf = ut_params->op->sym->m_dst;
3955         if (ut_params->obuf)
3956                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3957                                 plaintext_len, buffer);
3958         else
3959                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
3960                                 plaintext_len, buffer);
3961
3962         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3963
3964         /* Validate obuf */
3965         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3966                 ciphertext,
3967                 tdata->ciphertext.data,
3968                 tdata->validDataLenInBits.len,
3969                 "SNOW 3G Ciphertext data not as expected");
3970
3971         return 0;
3972 }
3973
3974 /* Shift right a buffer by "offset" bits, "offset" < 8 */
3975 static void
3976 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
3977 {
3978         uint8_t curr_byte, prev_byte;
3979         uint32_t length_in_bytes = ceil_byte_length(length + offset);
3980         uint8_t lower_byte_mask = (1 << offset) - 1;
3981         unsigned i;
3982
3983         prev_byte = buffer[0];
3984         buffer[0] >>= offset;
3985
3986         for (i = 1; i < length_in_bytes; i++) {
3987                 curr_byte = buffer[i];
3988                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
3989                                 (curr_byte >> offset);
3990                 prev_byte = curr_byte;
3991         }
3992 }
3993
3994 static int
3995 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
3996 {
3997         struct crypto_testsuite_params *ts_params = &testsuite_params;
3998         struct crypto_unittest_params *ut_params = &unittest_params;
3999         uint8_t *plaintext, *ciphertext;
4000         int retval;
4001         uint32_t plaintext_len;
4002         uint32_t plaintext_pad_len;
4003         uint8_t extra_offset = 4;
4004         uint8_t *expected_ciphertext_shifted;
4005         struct rte_cryptodev_info dev_info;
4006
4007         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4008         uint64_t feat_flags = dev_info.feature_flags;
4009
4010         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4011                         ((tdata->validDataLenInBits.len % 8) != 0)) {
4012                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4013                 return -ENOTSUP;
4014         }
4015
4016         /* Verify the capabilities */
4017         struct rte_cryptodev_sym_capability_idx cap_idx;
4018         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4019         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4020         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4021                         &cap_idx) == NULL)
4022                 return -ENOTSUP;
4023
4024         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4025                 return -ENOTSUP;
4026
4027         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4028                 return -ENOTSUP;
4029
4030         /* Create SNOW 3G session */
4031         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4032                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4033                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4034                                         tdata->key.data, tdata->key.len,
4035                                         tdata->cipher_iv.len);
4036         if (retval < 0)
4037                 return retval;
4038
4039         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4040         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4041
4042         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4043                         "Failed to allocate input buffer in mempool");
4044         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4045                         "Failed to allocate output buffer in mempool");
4046
4047         /* Clear mbuf payload */
4048         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4049                rte_pktmbuf_tailroom(ut_params->ibuf));
4050
4051         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4052         /*
4053          * Append data which is padded to a
4054          * multiple of the algorithms block size
4055          */
4056         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4057
4058         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4059                                                 plaintext_pad_len);
4060
4061         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4062
4063         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4064         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4065
4066 #ifdef RTE_APP_TEST_DEBUG
4067         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4068 #endif
4069         /* Create SNOW 3G operation */
4070         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4071                                         tdata->cipher_iv.len,
4072                                         tdata->validCipherLenInBits.len,
4073                                         extra_offset);
4074         if (retval < 0)
4075                 return retval;
4076
4077         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4078                                                 ut_params->op);
4079         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4080
4081         ut_params->obuf = ut_params->op->sym->m_dst;
4082         if (ut_params->obuf)
4083                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4084         else
4085                 ciphertext = plaintext;
4086
4087 #ifdef RTE_APP_TEST_DEBUG
4088         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4089 #endif
4090
4091         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4092
4093         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4094                         "failed to reserve memory for ciphertext shifted\n");
4095
4096         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4097                         ceil_byte_length(tdata->ciphertext.len));
4098         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4099                         extra_offset);
4100         /* Validate obuf */
4101         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4102                 ciphertext,
4103                 expected_ciphertext_shifted,
4104                 tdata->validDataLenInBits.len,
4105                 extra_offset,
4106                 "SNOW 3G Ciphertext data not as expected");
4107         return 0;
4108 }
4109
4110 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4111 {
4112         struct crypto_testsuite_params *ts_params = &testsuite_params;
4113         struct crypto_unittest_params *ut_params = &unittest_params;
4114
4115         int retval;
4116
4117         uint8_t *plaintext, *ciphertext;
4118         unsigned ciphertext_pad_len;
4119         unsigned ciphertext_len;
4120         struct rte_cryptodev_info dev_info;
4121
4122         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4123         uint64_t feat_flags = dev_info.feature_flags;
4124
4125         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4126                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4127                 printf("Device doesn't support RAW data-path APIs.\n");
4128                 return -ENOTSUP;
4129         }
4130
4131         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4132                 return -ENOTSUP;
4133
4134         /* Verify the capabilities */
4135         struct rte_cryptodev_sym_capability_idx cap_idx;
4136         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4137         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4138         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4139                         &cap_idx) == NULL)
4140                 return -ENOTSUP;
4141
4142         /* Create SNOW 3G session */
4143         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4144                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4145                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4146                                         tdata->key.data, tdata->key.len,
4147                                         tdata->cipher_iv.len);
4148         if (retval < 0)
4149                 return retval;
4150
4151         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4152
4153         /* Clear mbuf payload */
4154         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4155                rte_pktmbuf_tailroom(ut_params->ibuf));
4156
4157         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4158         /* Append data which is padded to a multiple of */
4159         /* the algorithms block size */
4160         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4161         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4162                                 ciphertext_pad_len);
4163         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4164
4165         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4166
4167         /* Create SNOW 3G operation */
4168         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4169                                         tdata->cipher_iv.len,
4170                                         tdata->validCipherLenInBits.len,
4171                                         tdata->cipher.offset_bits);
4172         if (retval < 0)
4173                 return retval;
4174
4175         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4176                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4177                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4178         else
4179                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4180                                                 ut_params->op);
4181         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4182         ut_params->obuf = ut_params->op->sym->m_dst;
4183         if (ut_params->obuf)
4184                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4185         else
4186                 plaintext = ciphertext;
4187
4188         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4189
4190         /* Validate obuf */
4191         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4192                                 tdata->plaintext.data,
4193                                 tdata->validDataLenInBits.len,
4194                                 "SNOW 3G Plaintext data not as expected");
4195         return 0;
4196 }
4197
4198 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4199 {
4200         struct crypto_testsuite_params *ts_params = &testsuite_params;
4201         struct crypto_unittest_params *ut_params = &unittest_params;
4202
4203         int retval;
4204
4205         uint8_t *plaintext, *ciphertext;
4206         unsigned ciphertext_pad_len;
4207         unsigned ciphertext_len;
4208
4209         /* Verify the capabilities */
4210         struct rte_cryptodev_sym_capability_idx cap_idx;
4211         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4212         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4213         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4214                         &cap_idx) == NULL)
4215                 return -ENOTSUP;
4216
4217         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4218                 return -ENOTSUP;
4219
4220         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4221                 return -ENOTSUP;
4222
4223         /* Create SNOW 3G session */
4224         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4225                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4226                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4227                                         tdata->key.data, tdata->key.len,
4228                                         tdata->cipher_iv.len);
4229         if (retval < 0)
4230                 return retval;
4231
4232         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4233         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4234
4235         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4236                         "Failed to allocate input buffer");
4237         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4238                         "Failed to allocate output buffer");
4239
4240         /* Clear mbuf payload */
4241         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4242                rte_pktmbuf_tailroom(ut_params->ibuf));
4243
4244         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4245                        rte_pktmbuf_tailroom(ut_params->obuf));
4246
4247         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4248         /* Append data which is padded to a multiple of */
4249         /* the algorithms block size */
4250         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4251         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4252                                 ciphertext_pad_len);
4253         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4254         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4255
4256         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4257
4258         /* Create SNOW 3G operation */
4259         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4260                                         tdata->cipher_iv.len,
4261                                         tdata->validCipherLenInBits.len,
4262                                         0);
4263         if (retval < 0)
4264                 return retval;
4265
4266         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4267                                                 ut_params->op);
4268         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4269         ut_params->obuf = ut_params->op->sym->m_dst;
4270         if (ut_params->obuf)
4271                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4272         else
4273                 plaintext = ciphertext;
4274
4275         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4276
4277         /* Validate obuf */
4278         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4279                                 tdata->plaintext.data,
4280                                 tdata->validDataLenInBits.len,
4281                                 "SNOW 3G Plaintext data not as expected");
4282         return 0;
4283 }
4284
4285 static int
4286 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4287 {
4288         struct crypto_testsuite_params *ts_params = &testsuite_params;
4289         struct crypto_unittest_params *ut_params = &unittest_params;
4290
4291         int retval;
4292
4293         uint8_t *plaintext, *ciphertext;
4294         unsigned int plaintext_pad_len;
4295         unsigned int plaintext_len;
4296
4297         struct rte_cryptodev_info dev_info;
4298         struct rte_cryptodev_sym_capability_idx cap_idx;
4299
4300         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4301         uint64_t feat_flags = dev_info.feature_flags;
4302
4303         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4304                         ((tdata->validAuthLenInBits.len % 8 != 0) ||
4305                         (tdata->validDataLenInBits.len % 8 != 0))) {
4306                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4307                 return -ENOTSUP;
4308         }
4309
4310         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4311                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4312                 printf("Device doesn't support RAW data-path APIs.\n");
4313                 return -ENOTSUP;
4314         }
4315
4316         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4317                 return -ENOTSUP;
4318
4319         /* Check if device supports ZUC EEA3 */
4320         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4321         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4322
4323         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4324                         &cap_idx) == NULL)
4325                 return -ENOTSUP;
4326
4327         /* Check if device supports ZUC EIA3 */
4328         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4329         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4330
4331         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4332                         &cap_idx) == NULL)
4333                 return -ENOTSUP;
4334
4335         /* Create ZUC session */
4336         retval = create_zuc_cipher_auth_encrypt_generate_session(
4337                         ts_params->valid_devs[0],
4338                         tdata);
4339         if (retval < 0)
4340                 return retval;
4341         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4342
4343         /* clear mbuf payload */
4344         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4345                         rte_pktmbuf_tailroom(ut_params->ibuf));
4346
4347         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4348         /* Append data which is padded to a multiple of */
4349         /* the algorithms block size */
4350         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4351         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4352                                 plaintext_pad_len);
4353         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4354
4355         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4356
4357         /* Create ZUC operation */
4358         retval = create_zuc_cipher_hash_generate_operation(tdata);
4359         if (retval < 0)
4360                 return retval;
4361
4362         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4363                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4364                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4365         else
4366                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4367                         ut_params->op);
4368         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4369         ut_params->obuf = ut_params->op->sym->m_src;
4370         if (ut_params->obuf)
4371                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4372         else
4373                 ciphertext = plaintext;
4374
4375         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4376         /* Validate obuf */
4377         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4378                         ciphertext,
4379                         tdata->ciphertext.data,
4380                         tdata->validDataLenInBits.len,
4381                         "ZUC Ciphertext data not as expected");
4382
4383         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4384             + plaintext_pad_len;
4385
4386         /* Validate obuf */
4387         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4388                         ut_params->digest,
4389                         tdata->digest.data,
4390                         4,
4391                         "ZUC Generated auth tag not as expected");
4392         return 0;
4393 }
4394
4395 static int
4396 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4397 {
4398         struct crypto_testsuite_params *ts_params = &testsuite_params;
4399         struct crypto_unittest_params *ut_params = &unittest_params;
4400
4401         int retval;
4402
4403         uint8_t *plaintext, *ciphertext;
4404         unsigned plaintext_pad_len;
4405         unsigned plaintext_len;
4406         struct rte_cryptodev_info dev_info;
4407
4408         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4409         uint64_t feat_flags = dev_info.feature_flags;
4410
4411         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4412                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4413                 printf("Device doesn't support RAW data-path APIs.\n");
4414                 return -ENOTSUP;
4415         }
4416
4417         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4418                 return -ENOTSUP;
4419
4420         /* Verify the capabilities */
4421         struct rte_cryptodev_sym_capability_idx cap_idx;
4422         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4423         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4424         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4425                         &cap_idx) == NULL)
4426                 return -ENOTSUP;
4427         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4428         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4429         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4430                         &cap_idx) == NULL)
4431                 return -ENOTSUP;
4432
4433         /* Create SNOW 3G session */
4434         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4435                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4436                         RTE_CRYPTO_AUTH_OP_GENERATE,
4437                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4438                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4439                         tdata->key.data, tdata->key.len,
4440                         tdata->auth_iv.len, tdata->digest.len,
4441                         tdata->cipher_iv.len);
4442         if (retval < 0)
4443                 return retval;
4444         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4445
4446         /* clear mbuf payload */
4447         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4448                         rte_pktmbuf_tailroom(ut_params->ibuf));
4449
4450         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4451         /* Append data which is padded to a multiple of */
4452         /* the algorithms block size */
4453         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4454         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4455                                 plaintext_pad_len);
4456         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4457
4458         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4459
4460         /* Create SNOW 3G operation */
4461         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4462                         tdata->digest.len, tdata->auth_iv.data,
4463                         tdata->auth_iv.len,
4464                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4465                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4466                         tdata->validCipherLenInBits.len,
4467                         0,
4468                         tdata->validAuthLenInBits.len,
4469                         0
4470                         );
4471         if (retval < 0)
4472                 return retval;
4473
4474         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4475                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4476                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4477         else
4478                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4479                         ut_params->op);
4480         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4481         ut_params->obuf = ut_params->op->sym->m_src;
4482         if (ut_params->obuf)
4483                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4484         else
4485                 ciphertext = plaintext;
4486
4487         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4488         /* Validate obuf */
4489         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4490                         ciphertext,
4491                         tdata->ciphertext.data,
4492                         tdata->validDataLenInBits.len,
4493                         "SNOW 3G Ciphertext data not as expected");
4494
4495         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4496             + plaintext_pad_len;
4497
4498         /* Validate obuf */
4499         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4500                         ut_params->digest,
4501                         tdata->digest.data,
4502                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4503                         "SNOW 3G Generated auth tag not as expected");
4504         return 0;
4505 }
4506
4507 static int
4508 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4509         uint8_t op_mode, uint8_t verify)
4510 {
4511         struct crypto_testsuite_params *ts_params = &testsuite_params;
4512         struct crypto_unittest_params *ut_params = &unittest_params;
4513
4514         int retval;
4515
4516         uint8_t *plaintext = NULL, *ciphertext = NULL;
4517         unsigned int plaintext_pad_len;
4518         unsigned int plaintext_len;
4519         unsigned int ciphertext_pad_len;
4520         unsigned int ciphertext_len;
4521
4522         struct rte_cryptodev_info dev_info;
4523
4524         /* Verify the capabilities */
4525         struct rte_cryptodev_sym_capability_idx cap_idx;
4526         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4527         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4528         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4529                         &cap_idx) == NULL)
4530                 return -ENOTSUP;
4531         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4532         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4533         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4534                         &cap_idx) == NULL)
4535                 return -ENOTSUP;
4536
4537         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4538                 return -ENOTSUP;
4539
4540         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4541
4542         uint64_t feat_flags = dev_info.feature_flags;
4543
4544         if (op_mode == OUT_OF_PLACE) {
4545                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4546                         printf("Device doesn't support digest encrypted.\n");
4547                         return -ENOTSUP;
4548                 }
4549                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4550                         return -ENOTSUP;
4551         }
4552
4553         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4554                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4555                 printf("Device doesn't support RAW data-path APIs.\n");
4556                 return -ENOTSUP;
4557         }
4558
4559         /* Create SNOW 3G session */
4560         retval = create_wireless_algo_auth_cipher_session(
4561                         ts_params->valid_devs[0],
4562                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4563                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4564                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4565                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4566                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4567                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4568                         tdata->key.data, tdata->key.len,
4569                         tdata->auth_iv.len, tdata->digest.len,
4570                         tdata->cipher_iv.len);
4571
4572         if (retval < 0)
4573                 return retval;
4574
4575         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4576         if (op_mode == OUT_OF_PLACE)
4577                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4578
4579         /* clear mbuf payload */
4580         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4581                 rte_pktmbuf_tailroom(ut_params->ibuf));
4582         if (op_mode == OUT_OF_PLACE)
4583                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4584                         rte_pktmbuf_tailroom(ut_params->obuf));
4585
4586         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4587         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4588         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4589         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4590
4591         if (verify) {
4592                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4593                                         ciphertext_pad_len);
4594                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4595                 if (op_mode == OUT_OF_PLACE)
4596                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4597                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4598                         ciphertext_len);
4599         } else {
4600                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4601                                         plaintext_pad_len);
4602                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4603                 if (op_mode == OUT_OF_PLACE)
4604                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4605                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4606         }
4607
4608         /* Create SNOW 3G operation */
4609         retval = create_wireless_algo_auth_cipher_operation(
4610                 tdata->digest.data, tdata->digest.len,
4611                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4612                 tdata->auth_iv.data, tdata->auth_iv.len,
4613                 (tdata->digest.offset_bytes == 0 ?
4614                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4615                         : tdata->digest.offset_bytes),
4616                 tdata->validCipherLenInBits.len,
4617                 tdata->cipher.offset_bits,
4618                 tdata->validAuthLenInBits.len,
4619                 tdata->auth.offset_bits,
4620                 op_mode, 0, verify);
4621
4622         if (retval < 0)
4623                 return retval;
4624
4625         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4626                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4627                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4628         else
4629                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4630                         ut_params->op);
4631
4632         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4633
4634         ut_params->obuf = (op_mode == IN_PLACE ?
4635                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4636
4637         if (verify) {
4638                 if (ut_params->obuf)
4639                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4640                                                         uint8_t *);
4641                 else
4642                         plaintext = ciphertext +
4643                                 (tdata->cipher.offset_bits >> 3);
4644
4645                 debug_hexdump(stdout, "plaintext:", plaintext,
4646                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4647                 debug_hexdump(stdout, "plaintext expected:",
4648                         tdata->plaintext.data,
4649                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4650         } else {
4651                 if (ut_params->obuf)
4652                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4653                                                         uint8_t *);
4654                 else
4655                         ciphertext = plaintext;
4656
4657                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4658                         ciphertext_len);
4659                 debug_hexdump(stdout, "ciphertext expected:",
4660                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4661
4662                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4663                         + (tdata->digest.offset_bytes == 0 ?
4664                 plaintext_pad_len : tdata->digest.offset_bytes);
4665
4666                 debug_hexdump(stdout, "digest:", ut_params->digest,
4667                         tdata->digest.len);
4668                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
4669                                 tdata->digest.len);
4670         }
4671
4672         /* Validate obuf */
4673         if (verify) {
4674                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4675                         plaintext,
4676                         tdata->plaintext.data,
4677                         (tdata->plaintext.len - tdata->cipher.offset_bits -
4678                          (tdata->digest.len << 3)),
4679                         tdata->cipher.offset_bits,
4680                         "SNOW 3G Plaintext data not as expected");
4681         } else {
4682                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4683                         ciphertext,
4684                         tdata->ciphertext.data,
4685                         (tdata->validDataLenInBits.len -
4686                          tdata->cipher.offset_bits),
4687                         tdata->cipher.offset_bits,
4688                         "SNOW 3G Ciphertext data not as expected");
4689
4690                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4691                         ut_params->digest,
4692                         tdata->digest.data,
4693                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4694                         "SNOW 3G Generated auth tag not as expected");
4695         }
4696         return 0;
4697 }
4698
4699 static int
4700 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
4701         uint8_t op_mode, uint8_t verify)
4702 {
4703         struct crypto_testsuite_params *ts_params = &testsuite_params;
4704         struct crypto_unittest_params *ut_params = &unittest_params;
4705
4706         int retval;
4707
4708         const uint8_t *plaintext = NULL;
4709         const uint8_t *ciphertext = NULL;
4710         const uint8_t *digest = NULL;
4711         unsigned int plaintext_pad_len;
4712         unsigned int plaintext_len;
4713         unsigned int ciphertext_pad_len;
4714         unsigned int ciphertext_len;
4715         uint8_t buffer[10000];
4716         uint8_t digest_buffer[10000];
4717
4718         struct rte_cryptodev_info dev_info;
4719
4720         /* Verify the capabilities */
4721         struct rte_cryptodev_sym_capability_idx cap_idx;
4722         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4723         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4724         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4725                         &cap_idx) == NULL)
4726                 return -ENOTSUP;
4727         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4728         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4729         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4730                         &cap_idx) == NULL)
4731                 return -ENOTSUP;
4732
4733         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4734                 return -ENOTSUP;
4735
4736         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4737
4738         uint64_t feat_flags = dev_info.feature_flags;
4739
4740         if (op_mode == IN_PLACE) {
4741                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
4742                         printf("Device doesn't support in-place scatter-gather "
4743                                         "in both input and output mbufs.\n");
4744                         return -ENOTSUP;
4745                 }
4746                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4747                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4748                         printf("Device doesn't support RAW data-path APIs.\n");
4749                         return -ENOTSUP;
4750                 }
4751         } else {
4752                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4753                         return -ENOTSUP;
4754                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4755                         printf("Device doesn't support out-of-place scatter-gather "
4756                                         "in both input and output mbufs.\n");
4757                         return -ENOTSUP;
4758                 }
4759                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4760                         printf("Device doesn't support digest encrypted.\n");
4761                         return -ENOTSUP;
4762                 }
4763         }
4764
4765         /* Create SNOW 3G session */
4766         retval = create_wireless_algo_auth_cipher_session(
4767                         ts_params->valid_devs[0],
4768                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4769                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4770                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4771                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4772                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4773                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4774                         tdata->key.data, tdata->key.len,
4775                         tdata->auth_iv.len, tdata->digest.len,
4776                         tdata->cipher_iv.len);
4777
4778         if (retval < 0)
4779                 return retval;
4780
4781         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4782         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4783         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4784         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4785
4786         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4787                         plaintext_pad_len, 15, 0);
4788         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4789                         "Failed to allocate input buffer in mempool");
4790
4791         if (op_mode == OUT_OF_PLACE) {
4792                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4793                                 plaintext_pad_len, 15, 0);
4794                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
4795                                 "Failed to allocate output buffer in mempool");
4796         }
4797
4798         if (verify) {
4799                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
4800                         tdata->ciphertext.data);
4801                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4802                                         ciphertext_len, buffer);
4803                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4804                         ciphertext_len);
4805         } else {
4806                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
4807                         tdata->plaintext.data);
4808                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4809                                         plaintext_len, buffer);
4810                 debug_hexdump(stdout, "plaintext:", plaintext,
4811                         plaintext_len);
4812         }
4813         memset(buffer, 0, sizeof(buffer));
4814
4815         /* Create SNOW 3G operation */
4816         retval = create_wireless_algo_auth_cipher_operation(
4817                 tdata->digest.data, tdata->digest.len,
4818                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4819                 tdata->auth_iv.data, tdata->auth_iv.len,
4820                 (tdata->digest.offset_bytes == 0 ?
4821                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4822                         : tdata->digest.offset_bytes),
4823                 tdata->validCipherLenInBits.len,
4824                 tdata->cipher.offset_bits,
4825                 tdata->validAuthLenInBits.len,
4826                 tdata->auth.offset_bits,
4827                 op_mode, 1, verify);
4828
4829         if (retval < 0)
4830                 return retval;
4831
4832         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4833                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4834                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4835         else
4836                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4837                         ut_params->op);
4838
4839         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4840
4841         ut_params->obuf = (op_mode == IN_PLACE ?
4842                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4843
4844         if (verify) {
4845                 if (ut_params->obuf)
4846                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
4847                                         plaintext_len, buffer);
4848                 else
4849                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4850                                         plaintext_len, buffer);
4851
4852                 debug_hexdump(stdout, "plaintext:", plaintext,
4853                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4854                 debug_hexdump(stdout, "plaintext expected:",
4855                         tdata->plaintext.data,
4856                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4857         } else {
4858                 if (ut_params->obuf)
4859                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4860                                         ciphertext_len, buffer);
4861                 else
4862                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4863                                         ciphertext_len, buffer);
4864
4865                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4866                         ciphertext_len);
4867                 debug_hexdump(stdout, "ciphertext expected:",
4868                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4869
4870                 if (ut_params->obuf)
4871                         digest = rte_pktmbuf_read(ut_params->obuf,
4872                                 (tdata->digest.offset_bytes == 0 ?
4873                                 plaintext_pad_len : tdata->digest.offset_bytes),
4874                                 tdata->digest.len, digest_buffer);
4875                 else
4876                         digest = rte_pktmbuf_read(ut_params->ibuf,
4877                                 (tdata->digest.offset_bytes == 0 ?
4878                                 plaintext_pad_len : tdata->digest.offset_bytes),
4879                                 tdata->digest.len, digest_buffer);
4880
4881                 debug_hexdump(stdout, "digest:", digest,
4882                         tdata->digest.len);
4883                 debug_hexdump(stdout, "digest expected:",
4884                         tdata->digest.data, tdata->digest.len);
4885         }
4886
4887         /* Validate obuf */
4888         if (verify) {
4889                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4890                         plaintext,
4891                         tdata->plaintext.data,
4892                         (tdata->plaintext.len - tdata->cipher.offset_bits -
4893                          (tdata->digest.len << 3)),
4894                         tdata->cipher.offset_bits,
4895                         "SNOW 3G Plaintext data not as expected");
4896         } else {
4897                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4898                         ciphertext,
4899                         tdata->ciphertext.data,
4900                         (tdata->validDataLenInBits.len -
4901                          tdata->cipher.offset_bits),
4902                         tdata->cipher.offset_bits,
4903                         "SNOW 3G Ciphertext data not as expected");
4904
4905                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4906                         digest,
4907                         tdata->digest.data,
4908                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4909                         "SNOW 3G Generated auth tag not as expected");
4910         }
4911         return 0;
4912 }
4913
4914 static int
4915 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
4916         uint8_t op_mode, uint8_t verify)
4917 {
4918         struct crypto_testsuite_params *ts_params = &testsuite_params;
4919         struct crypto_unittest_params *ut_params = &unittest_params;
4920
4921         int retval;
4922
4923         uint8_t *plaintext = NULL, *ciphertext = NULL;
4924         unsigned int plaintext_pad_len;
4925         unsigned int plaintext_len;
4926         unsigned int ciphertext_pad_len;
4927         unsigned int ciphertext_len;
4928
4929         struct rte_cryptodev_info dev_info;
4930
4931         /* Verify the capabilities */
4932         struct rte_cryptodev_sym_capability_idx cap_idx;
4933         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4934         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
4935         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4936                         &cap_idx) == NULL)
4937                 return -ENOTSUP;
4938         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4939         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4940         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4941                         &cap_idx) == NULL)
4942                 return -ENOTSUP;
4943
4944         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4945
4946         uint64_t feat_flags = dev_info.feature_flags;
4947
4948         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4949                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4950                 printf("Device doesn't support RAW data-path APIs.\n");
4951                 return -ENOTSUP;
4952         }
4953
4954         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4955                 return -ENOTSUP;
4956
4957         if (op_mode == OUT_OF_PLACE) {
4958                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4959                         return -ENOTSUP;
4960                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4961                         printf("Device doesn't support digest encrypted.\n");
4962                         return -ENOTSUP;
4963                 }
4964         }
4965
4966         /* Create KASUMI session */
4967         retval = create_wireless_algo_auth_cipher_session(
4968                         ts_params->valid_devs[0],
4969                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4970                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4971                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4972                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4973                         RTE_CRYPTO_AUTH_KASUMI_F9,
4974                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4975                         tdata->key.data, tdata->key.len,
4976                         0, tdata->digest.len,
4977                         tdata->cipher_iv.len);
4978
4979         if (retval < 0)
4980                 return retval;
4981
4982         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4983         if (op_mode == OUT_OF_PLACE)
4984                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4985
4986         /* clear mbuf payload */
4987         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4988                 rte_pktmbuf_tailroom(ut_params->ibuf));
4989         if (op_mode == OUT_OF_PLACE)
4990                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4991                         rte_pktmbuf_tailroom(ut_params->obuf));
4992
4993         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4994         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4995         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4996         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4997
4998         if (verify) {
4999                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5000                                         ciphertext_pad_len);
5001                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5002                 if (op_mode == OUT_OF_PLACE)
5003                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5004                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5005                         ciphertext_len);
5006         } else {
5007                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5008                                         plaintext_pad_len);
5009                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5010                 if (op_mode == OUT_OF_PLACE)
5011                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5012                 debug_hexdump(stdout, "plaintext:", plaintext,
5013                         plaintext_len);
5014         }
5015
5016         /* Create KASUMI operation */
5017         retval = create_wireless_algo_auth_cipher_operation(
5018                 tdata->digest.data, tdata->digest.len,
5019                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5020                 NULL, 0,
5021                 (tdata->digest.offset_bytes == 0 ?
5022                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5023                         : tdata->digest.offset_bytes),
5024                 tdata->validCipherLenInBits.len,
5025                 tdata->validCipherOffsetInBits.len,
5026                 tdata->validAuthLenInBits.len,
5027                 0,
5028                 op_mode, 0, verify);
5029
5030         if (retval < 0)
5031                 return retval;
5032
5033         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5034                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5035                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5036         else
5037                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5038                         ut_params->op);
5039
5040         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5041
5042         ut_params->obuf = (op_mode == IN_PLACE ?
5043                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5044
5045
5046         if (verify) {
5047                 if (ut_params->obuf)
5048                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5049                                                         uint8_t *);
5050                 else
5051                         plaintext = ciphertext;
5052
5053                 debug_hexdump(stdout, "plaintext:", plaintext,
5054                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5055                 debug_hexdump(stdout, "plaintext expected:",
5056                         tdata->plaintext.data,
5057                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5058         } else {
5059                 if (ut_params->obuf)
5060                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5061                                                         uint8_t *);
5062                 else
5063                         ciphertext = plaintext;
5064
5065                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5066                         ciphertext_len);
5067                 debug_hexdump(stdout, "ciphertext expected:",
5068                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5069
5070                 ut_params->digest = rte_pktmbuf_mtod(
5071                         ut_params->obuf, uint8_t *) +
5072                         (tdata->digest.offset_bytes == 0 ?
5073                         plaintext_pad_len : tdata->digest.offset_bytes);
5074
5075                 debug_hexdump(stdout, "digest:", ut_params->digest,
5076                         tdata->digest.len);
5077                 debug_hexdump(stdout, "digest expected:",
5078                         tdata->digest.data, tdata->digest.len);
5079         }
5080
5081         /* Validate obuf */
5082         if (verify) {
5083                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5084                         plaintext,
5085                         tdata->plaintext.data,
5086                         tdata->plaintext.len >> 3,
5087                         "KASUMI Plaintext data not as expected");
5088         } else {
5089                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5090                         ciphertext,
5091                         tdata->ciphertext.data,
5092                         tdata->ciphertext.len >> 3,
5093                         "KASUMI Ciphertext data not as expected");
5094
5095                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5096                         ut_params->digest,
5097                         tdata->digest.data,
5098                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5099                         "KASUMI Generated auth tag not as expected");
5100         }
5101         return 0;
5102 }
5103
5104 static int
5105 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5106         uint8_t op_mode, uint8_t verify)
5107 {
5108         struct crypto_testsuite_params *ts_params = &testsuite_params;
5109         struct crypto_unittest_params *ut_params = &unittest_params;
5110
5111         int retval;
5112
5113         const uint8_t *plaintext = NULL;
5114         const uint8_t *ciphertext = NULL;
5115         const uint8_t *digest = NULL;
5116         unsigned int plaintext_pad_len;
5117         unsigned int plaintext_len;
5118         unsigned int ciphertext_pad_len;
5119         unsigned int ciphertext_len;
5120         uint8_t buffer[10000];
5121         uint8_t digest_buffer[10000];
5122
5123         struct rte_cryptodev_info dev_info;
5124
5125         /* Verify the capabilities */
5126         struct rte_cryptodev_sym_capability_idx cap_idx;
5127         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5128         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5129         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5130                         &cap_idx) == NULL)
5131                 return -ENOTSUP;
5132         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5133         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5134         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5135                         &cap_idx) == NULL)
5136                 return -ENOTSUP;
5137
5138         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5139                 return -ENOTSUP;
5140
5141         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5142
5143         uint64_t feat_flags = dev_info.feature_flags;
5144
5145         if (op_mode == IN_PLACE) {
5146                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5147                         printf("Device doesn't support in-place scatter-gather "
5148                                         "in both input and output mbufs.\n");
5149                         return -ENOTSUP;
5150                 }
5151                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5152                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5153                         printf("Device doesn't support RAW data-path APIs.\n");
5154                         return -ENOTSUP;
5155                 }
5156         } else {
5157                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5158                         return -ENOTSUP;
5159                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5160                         printf("Device doesn't support out-of-place scatter-gather "
5161                                         "in both input and output mbufs.\n");
5162                         return -ENOTSUP;
5163                 }
5164                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5165                         printf("Device doesn't support digest encrypted.\n");
5166                         return -ENOTSUP;
5167                 }
5168         }
5169
5170         /* Create KASUMI session */
5171         retval = create_wireless_algo_auth_cipher_session(
5172                         ts_params->valid_devs[0],
5173                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5174                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5175                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5176                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5177                         RTE_CRYPTO_AUTH_KASUMI_F9,
5178                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5179                         tdata->key.data, tdata->key.len,
5180                         0, tdata->digest.len,
5181                         tdata->cipher_iv.len);
5182
5183         if (retval < 0)
5184                 return retval;
5185
5186         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5187         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5188         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5189         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5190
5191         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5192                         plaintext_pad_len, 15, 0);
5193         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5194                         "Failed to allocate input buffer in mempool");
5195
5196         if (op_mode == OUT_OF_PLACE) {
5197                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5198                                 plaintext_pad_len, 15, 0);
5199                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5200                                 "Failed to allocate output buffer in mempool");
5201         }
5202
5203         if (verify) {
5204                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5205                         tdata->ciphertext.data);
5206                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5207                                         ciphertext_len, buffer);
5208                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5209                         ciphertext_len);
5210         } else {
5211                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5212                         tdata->plaintext.data);
5213                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5214                                         plaintext_len, buffer);
5215                 debug_hexdump(stdout, "plaintext:", plaintext,
5216                         plaintext_len);
5217         }
5218         memset(buffer, 0, sizeof(buffer));
5219
5220         /* Create KASUMI operation */
5221         retval = create_wireless_algo_auth_cipher_operation(
5222                 tdata->digest.data, tdata->digest.len,
5223                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5224                 NULL, 0,
5225                 (tdata->digest.offset_bytes == 0 ?
5226                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5227                         : tdata->digest.offset_bytes),
5228                 tdata->validCipherLenInBits.len,
5229                 tdata->validCipherOffsetInBits.len,
5230                 tdata->validAuthLenInBits.len,
5231                 0,
5232                 op_mode, 1, verify);
5233
5234         if (retval < 0)
5235                 return retval;
5236
5237         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5238                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5239                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5240         else
5241                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5242                         ut_params->op);
5243
5244         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5245
5246         ut_params->obuf = (op_mode == IN_PLACE ?
5247                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5248
5249         if (verify) {
5250                 if (ut_params->obuf)
5251                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5252                                         plaintext_len, buffer);
5253                 else
5254                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5255                                         plaintext_len, buffer);
5256
5257                 debug_hexdump(stdout, "plaintext:", plaintext,
5258                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5259                 debug_hexdump(stdout, "plaintext expected:",
5260                         tdata->plaintext.data,
5261                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5262         } else {
5263                 if (ut_params->obuf)
5264                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5265                                         ciphertext_len, buffer);
5266                 else
5267                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5268                                         ciphertext_len, buffer);
5269
5270                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5271                         ciphertext_len);
5272                 debug_hexdump(stdout, "ciphertext expected:",
5273                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5274
5275                 if (ut_params->obuf)
5276                         digest = rte_pktmbuf_read(ut_params->obuf,
5277                                 (tdata->digest.offset_bytes == 0 ?
5278                                 plaintext_pad_len : tdata->digest.offset_bytes),
5279                                 tdata->digest.len, digest_buffer);
5280                 else
5281                         digest = rte_pktmbuf_read(ut_params->ibuf,
5282                                 (tdata->digest.offset_bytes == 0 ?
5283                                 plaintext_pad_len : tdata->digest.offset_bytes),
5284                                 tdata->digest.len, digest_buffer);
5285
5286                 debug_hexdump(stdout, "digest:", digest,
5287                         tdata->digest.len);
5288                 debug_hexdump(stdout, "digest expected:",
5289                         tdata->digest.data, tdata->digest.len);
5290         }
5291
5292         /* Validate obuf */
5293         if (verify) {
5294                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5295                         plaintext,
5296                         tdata->plaintext.data,
5297                         tdata->plaintext.len >> 3,
5298                         "KASUMI Plaintext data not as expected");
5299         } else {
5300                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5301                         ciphertext,
5302                         tdata->ciphertext.data,
5303                         tdata->validDataLenInBits.len,
5304                         "KASUMI Ciphertext data not as expected");
5305
5306                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5307                         digest,
5308                         tdata->digest.data,
5309                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5310                         "KASUMI Generated auth tag not as expected");
5311         }
5312         return 0;
5313 }
5314
5315 static int
5316 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5317 {
5318         struct crypto_testsuite_params *ts_params = &testsuite_params;
5319         struct crypto_unittest_params *ut_params = &unittest_params;
5320
5321         int retval;
5322
5323         uint8_t *plaintext, *ciphertext;
5324         unsigned plaintext_pad_len;
5325         unsigned plaintext_len;
5326         struct rte_cryptodev_info dev_info;
5327
5328         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5329         uint64_t feat_flags = dev_info.feature_flags;
5330
5331         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5332                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5333                 printf("Device doesn't support RAW data-path APIs.\n");
5334                 return -ENOTSUP;
5335         }
5336
5337         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5338                 return -ENOTSUP;
5339
5340         /* Verify the capabilities */
5341         struct rte_cryptodev_sym_capability_idx cap_idx;
5342         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5343         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5344         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5345                         &cap_idx) == NULL)
5346                 return -ENOTSUP;
5347         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5348         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5349         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5350                         &cap_idx) == NULL)
5351                 return -ENOTSUP;
5352
5353         /* Create KASUMI session */
5354         retval = create_wireless_algo_cipher_auth_session(
5355                         ts_params->valid_devs[0],
5356                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5357                         RTE_CRYPTO_AUTH_OP_GENERATE,
5358                         RTE_CRYPTO_AUTH_KASUMI_F9,
5359                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5360                         tdata->key.data, tdata->key.len,
5361                         0, tdata->digest.len,
5362                         tdata->cipher_iv.len);
5363         if (retval < 0)
5364                 return retval;
5365
5366         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5367
5368         /* clear mbuf payload */
5369         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5370                         rte_pktmbuf_tailroom(ut_params->ibuf));
5371
5372         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5373         /* Append data which is padded to a multiple of */
5374         /* the algorithms block size */
5375         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5376         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5377                                 plaintext_pad_len);
5378         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5379
5380         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5381
5382         /* Create KASUMI operation */
5383         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5384                                 tdata->digest.len, NULL, 0,
5385                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5386                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5387                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5388                                 tdata->validCipherOffsetInBits.len,
5389                                 tdata->validAuthLenInBits.len,
5390                                 0
5391                                 );
5392         if (retval < 0)
5393                 return retval;
5394
5395         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5396                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5397                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5398         else
5399                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5400                         ut_params->op);
5401         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5402
5403         if (ut_params->op->sym->m_dst)
5404                 ut_params->obuf = ut_params->op->sym->m_dst;
5405         else
5406                 ut_params->obuf = ut_params->op->sym->m_src;
5407
5408         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5409                                 tdata->validCipherOffsetInBits.len >> 3);
5410
5411         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5412                         + plaintext_pad_len;
5413
5414         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5415                                 (tdata->validCipherOffsetInBits.len >> 3);
5416         /* Validate obuf */
5417         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5418                 ciphertext,
5419                 reference_ciphertext,
5420                 tdata->validCipherLenInBits.len,
5421                 "KASUMI Ciphertext data not as expected");
5422
5423         /* Validate obuf */
5424         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5425                 ut_params->digest,
5426                 tdata->digest.data,
5427                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5428                 "KASUMI Generated auth tag not as expected");
5429         return 0;
5430 }
5431
5432 static int
5433 test_zuc_encryption(const struct wireless_test_data *tdata)
5434 {
5435         struct crypto_testsuite_params *ts_params = &testsuite_params;
5436         struct crypto_unittest_params *ut_params = &unittest_params;
5437
5438         int retval;
5439         uint8_t *plaintext, *ciphertext;
5440         unsigned plaintext_pad_len;
5441         unsigned plaintext_len;
5442         struct rte_cryptodev_info dev_info;
5443
5444         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5445         uint64_t feat_flags = dev_info.feature_flags;
5446
5447         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5448                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5449                 printf("Device doesn't support RAW data-path APIs.\n");
5450                 return -ENOTSUP;
5451         }
5452
5453         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5454                 return -ENOTSUP;
5455
5456         struct rte_cryptodev_sym_capability_idx cap_idx;
5457
5458         /* Check if device supports ZUC EEA3 */
5459         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5460         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5461
5462         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5463                         &cap_idx) == NULL)
5464                 return -ENOTSUP;
5465
5466         /* Create ZUC session */
5467         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5468                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5469                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5470                                         tdata->key.data, tdata->key.len,
5471                                         tdata->cipher_iv.len);
5472         if (retval < 0)
5473                 return retval;
5474
5475         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5476
5477         /* Clear mbuf payload */
5478         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5479                rte_pktmbuf_tailroom(ut_params->ibuf));
5480
5481         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5482         /* Append data which is padded to a multiple */
5483         /* of the algorithms block size */
5484         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5485         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5486                                 plaintext_pad_len);
5487         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5488
5489         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5490
5491         /* Create ZUC operation */
5492         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5493                                         tdata->cipher_iv.len,
5494                                         tdata->plaintext.len,
5495                                         0);
5496         if (retval < 0)
5497                 return retval;
5498
5499         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5500                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5501                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5502         else
5503                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5504                                                 ut_params->op);
5505         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5506
5507         ut_params->obuf = ut_params->op->sym->m_dst;
5508         if (ut_params->obuf)
5509                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5510         else
5511                 ciphertext = plaintext;
5512
5513         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5514
5515         /* Validate obuf */
5516         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5517                 ciphertext,
5518                 tdata->ciphertext.data,
5519                 tdata->validCipherLenInBits.len,
5520                 "ZUC Ciphertext data not as expected");
5521         return 0;
5522 }
5523
5524 static int
5525 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5526 {
5527         struct crypto_testsuite_params *ts_params = &testsuite_params;
5528         struct crypto_unittest_params *ut_params = &unittest_params;
5529
5530         int retval;
5531
5532         unsigned int plaintext_pad_len;
5533         unsigned int plaintext_len;
5534         const uint8_t *ciphertext;
5535         uint8_t ciphertext_buffer[2048];
5536         struct rte_cryptodev_info dev_info;
5537
5538         struct rte_cryptodev_sym_capability_idx cap_idx;
5539
5540         /* Check if device supports ZUC EEA3 */
5541         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5542         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5543
5544         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5545                         &cap_idx) == NULL)
5546                 return -ENOTSUP;
5547
5548         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5549                 return -ENOTSUP;
5550
5551         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5552
5553         uint64_t feat_flags = dev_info.feature_flags;
5554
5555         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5556                 printf("Device doesn't support in-place scatter-gather. "
5557                                 "Test Skipped.\n");
5558                 return -ENOTSUP;
5559         }
5560
5561         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5562                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5563                 printf("Device doesn't support RAW data-path APIs.\n");
5564                 return -ENOTSUP;
5565         }
5566
5567         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5568
5569         /* Append data which is padded to a multiple */
5570         /* of the algorithms block size */
5571         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5572
5573         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5574                         plaintext_pad_len, 10, 0);
5575
5576         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5577                         tdata->plaintext.data);
5578
5579         /* Create ZUC session */
5580         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5581                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5582                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5583                         tdata->key.data, tdata->key.len,
5584                         tdata->cipher_iv.len);
5585         if (retval < 0)
5586                 return retval;
5587
5588         /* Clear mbuf payload */
5589
5590         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5591
5592         /* Create ZUC operation */
5593         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5594                         tdata->cipher_iv.len, tdata->plaintext.len,
5595                         0);
5596         if (retval < 0)
5597                 return retval;
5598
5599         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5600                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5601                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5602         else
5603                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5604                                                 ut_params->op);
5605         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5606
5607         ut_params->obuf = ut_params->op->sym->m_dst;
5608         if (ut_params->obuf)
5609                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
5610                         0, plaintext_len, ciphertext_buffer);
5611         else
5612                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
5613                         0, plaintext_len, ciphertext_buffer);
5614
5615         /* Validate obuf */
5616         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5617
5618         /* Validate obuf */
5619         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5620                 ciphertext,
5621                 tdata->ciphertext.data,
5622                 tdata->validCipherLenInBits.len,
5623                 "ZUC Ciphertext data not as expected");
5624
5625         return 0;
5626 }
5627
5628 static int
5629 test_zuc_authentication(const struct wireless_test_data *tdata)
5630 {
5631         struct crypto_testsuite_params *ts_params = &testsuite_params;
5632         struct crypto_unittest_params *ut_params = &unittest_params;
5633
5634         int retval;
5635         unsigned plaintext_pad_len;
5636         unsigned plaintext_len;
5637         uint8_t *plaintext;
5638
5639         struct rte_cryptodev_sym_capability_idx cap_idx;
5640         struct rte_cryptodev_info dev_info;
5641
5642         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5643         uint64_t feat_flags = dev_info.feature_flags;
5644
5645         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
5646                         (tdata->validAuthLenInBits.len % 8 != 0)) {
5647                 printf("Device doesn't support NON-Byte Aligned Data.\n");
5648                 return -ENOTSUP;
5649         }
5650
5651         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5652                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5653                 printf("Device doesn't support RAW data-path APIs.\n");
5654                 return -ENOTSUP;
5655         }
5656
5657         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5658                 return -ENOTSUP;
5659
5660         /* Check if device supports ZUC EIA3 */
5661         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5662         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5663
5664         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5665                         &cap_idx) == NULL)
5666                 return -ENOTSUP;
5667
5668         /* Create ZUC session */
5669         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
5670                         tdata->key.data, tdata->key.len,
5671                         tdata->auth_iv.len, tdata->digest.len,
5672                         RTE_CRYPTO_AUTH_OP_GENERATE,
5673                         RTE_CRYPTO_AUTH_ZUC_EIA3);
5674         if (retval < 0)
5675                 return retval;
5676
5677         /* alloc mbuf and set payload */
5678         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5679
5680         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5681         rte_pktmbuf_tailroom(ut_params->ibuf));
5682
5683         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5684         /* Append data which is padded to a multiple of */
5685         /* the algorithms block size */
5686         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5687         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5688                                 plaintext_pad_len);
5689         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5690
5691         /* Create ZUC operation */
5692         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
5693                         tdata->auth_iv.data, tdata->auth_iv.len,
5694                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5695                         tdata->validAuthLenInBits.len,
5696                         0);
5697         if (retval < 0)
5698                 return retval;
5699
5700         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5701                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5702                                 ut_params->op, 0, 1, 1, 0);
5703         else
5704                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5705                                 ut_params->op);
5706         ut_params->obuf = ut_params->op->sym->m_src;
5707         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5708         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5709                         + plaintext_pad_len;
5710
5711         /* Validate obuf */
5712         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5713         ut_params->digest,
5714         tdata->digest.data,
5715         tdata->digest.len,
5716         "ZUC Generated auth tag not as expected");
5717
5718         return 0;
5719 }
5720
5721 static int
5722 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
5723         uint8_t op_mode, uint8_t verify)
5724 {
5725         struct crypto_testsuite_params *ts_params = &testsuite_params;
5726         struct crypto_unittest_params *ut_params = &unittest_params;
5727
5728         int retval;
5729
5730         uint8_t *plaintext = NULL, *ciphertext = NULL;
5731         unsigned int plaintext_pad_len;
5732         unsigned int plaintext_len;
5733         unsigned int ciphertext_pad_len;
5734         unsigned int ciphertext_len;
5735
5736         struct rte_cryptodev_info dev_info;
5737         struct rte_cryptodev_sym_capability_idx cap_idx;
5738
5739         /* Check if device supports ZUC EIA3 */
5740         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5741         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5742
5743         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5744                         &cap_idx) == NULL)
5745                 return -ENOTSUP;
5746
5747         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5748
5749         uint64_t feat_flags = dev_info.feature_flags;
5750
5751         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5752                 printf("Device doesn't support digest encrypted.\n");
5753                 return -ENOTSUP;
5754         }
5755         if (op_mode == IN_PLACE) {
5756                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5757                         printf("Device doesn't support in-place scatter-gather "
5758                                         "in both input and output mbufs.\n");
5759                         return -ENOTSUP;
5760                 }
5761
5762                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5763                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5764                         printf("Device doesn't support RAW data-path APIs.\n");
5765                         return -ENOTSUP;
5766                 }
5767         } else {
5768                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5769                         return -ENOTSUP;
5770                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5771                         printf("Device doesn't support out-of-place scatter-gather "
5772                                         "in both input and output mbufs.\n");
5773                         return -ENOTSUP;
5774                 }
5775         }
5776
5777         /* Create ZUC session */
5778         retval = create_wireless_algo_auth_cipher_session(
5779                         ts_params->valid_devs[0],
5780                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5781                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5782                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5783                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5784                         RTE_CRYPTO_AUTH_ZUC_EIA3,
5785                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5786                         tdata->key.data, tdata->key.len,
5787                         tdata->auth_iv.len, tdata->digest.len,
5788                         tdata->cipher_iv.len);
5789
5790         if (retval < 0)
5791                 return retval;
5792
5793         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5794         if (op_mode == OUT_OF_PLACE)
5795                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5796
5797         /* clear mbuf payload */
5798         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5799                 rte_pktmbuf_tailroom(ut_params->ibuf));
5800         if (op_mode == OUT_OF_PLACE)
5801                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5802                         rte_pktmbuf_tailroom(ut_params->obuf));
5803
5804         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5805         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5806         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5807         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5808
5809         if (verify) {
5810                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5811                                         ciphertext_pad_len);
5812                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5813                 if (op_mode == OUT_OF_PLACE)
5814                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5815                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5816                         ciphertext_len);
5817         } else {
5818                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5819                                         plaintext_pad_len);
5820                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5821                 if (op_mode == OUT_OF_PLACE)
5822                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5823                 debug_hexdump(stdout, "plaintext:", plaintext,
5824                         plaintext_len);
5825         }
5826
5827         /* Create ZUC operation */
5828         retval = create_wireless_algo_auth_cipher_operation(
5829                 tdata->digest.data, tdata->digest.len,
5830                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5831                 tdata->auth_iv.data, tdata->auth_iv.len,
5832                 (tdata->digest.offset_bytes == 0 ?
5833                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5834                         : tdata->digest.offset_bytes),
5835                 tdata->validCipherLenInBits.len,
5836                 tdata->validCipherOffsetInBits.len,
5837                 tdata->validAuthLenInBits.len,
5838                 0,
5839                 op_mode, 0, verify);
5840
5841         if (retval < 0)
5842                 return retval;
5843
5844         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5845                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5846                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5847         else
5848                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5849                         ut_params->op);
5850
5851         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5852
5853         ut_params->obuf = (op_mode == IN_PLACE ?
5854                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5855
5856
5857         if (verify) {
5858                 if (ut_params->obuf)
5859                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5860                                                         uint8_t *);
5861                 else
5862                         plaintext = ciphertext;
5863
5864                 debug_hexdump(stdout, "plaintext:", plaintext,
5865                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5866                 debug_hexdump(stdout, "plaintext expected:",
5867                         tdata->plaintext.data,
5868                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5869         } else {
5870                 if (ut_params->obuf)
5871                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5872                                                         uint8_t *);
5873                 else
5874                         ciphertext = plaintext;
5875
5876                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5877                         ciphertext_len);
5878                 debug_hexdump(stdout, "ciphertext expected:",
5879                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5880
5881                 ut_params->digest = rte_pktmbuf_mtod(
5882                         ut_params->obuf, uint8_t *) +
5883                         (tdata->digest.offset_bytes == 0 ?
5884                         plaintext_pad_len : tdata->digest.offset_bytes);
5885
5886                 debug_hexdump(stdout, "digest:", ut_params->digest,
5887                         tdata->digest.len);
5888                 debug_hexdump(stdout, "digest expected:",
5889                         tdata->digest.data, tdata->digest.len);
5890         }
5891
5892         /* Validate obuf */
5893         if (verify) {
5894                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5895                         plaintext,
5896                         tdata->plaintext.data,
5897                         tdata->plaintext.len >> 3,
5898                         "ZUC Plaintext data not as expected");
5899         } else {
5900                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5901                         ciphertext,
5902                         tdata->ciphertext.data,
5903                         tdata->ciphertext.len >> 3,
5904                         "ZUC Ciphertext data not as expected");
5905
5906                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5907                         ut_params->digest,
5908                         tdata->digest.data,
5909                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5910                         "ZUC Generated auth tag not as expected");
5911         }
5912         return 0;
5913 }
5914
5915 static int
5916 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
5917         uint8_t op_mode, uint8_t verify)
5918 {
5919         struct crypto_testsuite_params *ts_params = &testsuite_params;
5920         struct crypto_unittest_params *ut_params = &unittest_params;
5921
5922         int retval;
5923
5924         const uint8_t *plaintext = NULL;
5925         const uint8_t *ciphertext = NULL;
5926         const uint8_t *digest = NULL;
5927         unsigned int plaintext_pad_len;
5928         unsigned int plaintext_len;
5929         unsigned int ciphertext_pad_len;
5930         unsigned int ciphertext_len;
5931         uint8_t buffer[10000];
5932         uint8_t digest_buffer[10000];
5933
5934         struct rte_cryptodev_info dev_info;
5935         struct rte_cryptodev_sym_capability_idx cap_idx;
5936
5937         /* Check if device supports ZUC EIA3 */
5938         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5939         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5940
5941         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5942                         &cap_idx) == NULL)
5943                 return -ENOTSUP;
5944
5945         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5946
5947         uint64_t feat_flags = dev_info.feature_flags;
5948
5949         if (op_mode == IN_PLACE) {
5950                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5951                         printf("Device doesn't support in-place scatter-gather "
5952                                         "in both input and output mbufs.\n");
5953                         return -ENOTSUP;
5954                 }
5955
5956                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5957                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5958                         printf("Device doesn't support RAW data-path APIs.\n");
5959                         return -ENOTSUP;
5960                 }
5961         } else {
5962                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5963                         return -ENOTSUP;
5964                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5965                         printf("Device doesn't support out-of-place scatter-gather "
5966                                         "in both input and output mbufs.\n");
5967                         return -ENOTSUP;
5968                 }
5969                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5970                         printf("Device doesn't support digest encrypted.\n");
5971                         return -ENOTSUP;
5972                 }
5973         }
5974
5975         /* Create ZUC session */
5976         retval = create_wireless_algo_auth_cipher_session(
5977                         ts_params->valid_devs[0],
5978                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5979                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5980                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5981                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5982                         RTE_CRYPTO_AUTH_ZUC_EIA3,
5983                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5984                         tdata->key.data, tdata->key.len,
5985                         tdata->auth_iv.len, tdata->digest.len,
5986                         tdata->cipher_iv.len);
5987
5988         if (retval < 0)
5989                 return retval;
5990
5991         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5992         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5993         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5994         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5995
5996         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5997                         plaintext_pad_len, 15, 0);
5998         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5999                         "Failed to allocate input buffer in mempool");
6000
6001         if (op_mode == OUT_OF_PLACE) {
6002                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6003                                 plaintext_pad_len, 15, 0);
6004                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6005                                 "Failed to allocate output buffer in mempool");
6006         }
6007
6008         if (verify) {
6009                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6010                         tdata->ciphertext.data);
6011                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6012                                         ciphertext_len, buffer);
6013                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6014                         ciphertext_len);
6015         } else {
6016                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6017                         tdata->plaintext.data);
6018                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6019                                         plaintext_len, buffer);
6020                 debug_hexdump(stdout, "plaintext:", plaintext,
6021                         plaintext_len);
6022         }
6023         memset(buffer, 0, sizeof(buffer));
6024
6025         /* Create ZUC operation */
6026         retval = create_wireless_algo_auth_cipher_operation(
6027                 tdata->digest.data, tdata->digest.len,
6028                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6029                 NULL, 0,
6030                 (tdata->digest.offset_bytes == 0 ?
6031                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6032                         : tdata->digest.offset_bytes),
6033                 tdata->validCipherLenInBits.len,
6034                 tdata->validCipherOffsetInBits.len,
6035                 tdata->validAuthLenInBits.len,
6036                 0,
6037                 op_mode, 1, verify);
6038
6039         if (retval < 0)
6040                 return retval;
6041
6042         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6043                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6044                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6045         else
6046                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6047                         ut_params->op);
6048
6049         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6050
6051         ut_params->obuf = (op_mode == IN_PLACE ?
6052                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6053
6054         if (verify) {
6055                 if (ut_params->obuf)
6056                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6057                                         plaintext_len, buffer);
6058                 else
6059                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6060                                         plaintext_len, buffer);
6061
6062                 debug_hexdump(stdout, "plaintext:", plaintext,
6063                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6064                 debug_hexdump(stdout, "plaintext expected:",
6065                         tdata->plaintext.data,
6066                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6067         } else {
6068                 if (ut_params->obuf)
6069                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6070                                         ciphertext_len, buffer);
6071                 else
6072                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6073                                         ciphertext_len, buffer);
6074
6075                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6076                         ciphertext_len);
6077                 debug_hexdump(stdout, "ciphertext expected:",
6078                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6079
6080                 if (ut_params->obuf)
6081                         digest = rte_pktmbuf_read(ut_params->obuf,
6082                                 (tdata->digest.offset_bytes == 0 ?
6083                                 plaintext_pad_len : tdata->digest.offset_bytes),
6084                                 tdata->digest.len, digest_buffer);
6085                 else
6086                         digest = rte_pktmbuf_read(ut_params->ibuf,
6087                                 (tdata->digest.offset_bytes == 0 ?
6088                                 plaintext_pad_len : tdata->digest.offset_bytes),
6089                                 tdata->digest.len, digest_buffer);
6090
6091                 debug_hexdump(stdout, "digest:", digest,
6092                         tdata->digest.len);
6093                 debug_hexdump(stdout, "digest expected:",
6094                         tdata->digest.data, tdata->digest.len);
6095         }
6096
6097         /* Validate obuf */
6098         if (verify) {
6099                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6100                         plaintext,
6101                         tdata->plaintext.data,
6102                         tdata->plaintext.len >> 3,
6103                         "ZUC Plaintext data not as expected");
6104         } else {
6105                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6106                         ciphertext,
6107                         tdata->ciphertext.data,
6108                         tdata->validDataLenInBits.len,
6109                         "ZUC Ciphertext data not as expected");
6110
6111                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6112                         digest,
6113                         tdata->digest.data,
6114                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6115                         "ZUC Generated auth tag not as expected");
6116         }
6117         return 0;
6118 }
6119
6120 static int
6121 test_kasumi_encryption_test_case_1(void)
6122 {
6123         return test_kasumi_encryption(&kasumi_test_case_1);
6124 }
6125
6126 static int
6127 test_kasumi_encryption_test_case_1_sgl(void)
6128 {
6129         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6130 }
6131
6132 static int
6133 test_kasumi_encryption_test_case_1_oop(void)
6134 {
6135         return test_kasumi_encryption_oop(&kasumi_test_case_1);
6136 }
6137
6138 static int
6139 test_kasumi_encryption_test_case_1_oop_sgl(void)
6140 {
6141         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6142 }
6143
6144 static int
6145 test_kasumi_encryption_test_case_2(void)
6146 {
6147         return test_kasumi_encryption(&kasumi_test_case_2);
6148 }
6149
6150 static int
6151 test_kasumi_encryption_test_case_3(void)
6152 {
6153         return test_kasumi_encryption(&kasumi_test_case_3);
6154 }
6155
6156 static int
6157 test_kasumi_encryption_test_case_4(void)
6158 {
6159         return test_kasumi_encryption(&kasumi_test_case_4);
6160 }
6161
6162 static int
6163 test_kasumi_encryption_test_case_5(void)
6164 {
6165         return test_kasumi_encryption(&kasumi_test_case_5);
6166 }
6167
6168 static int
6169 test_kasumi_decryption_test_case_1(void)
6170 {
6171         return test_kasumi_decryption(&kasumi_test_case_1);
6172 }
6173
6174 static int
6175 test_kasumi_decryption_test_case_1_oop(void)
6176 {
6177         return test_kasumi_decryption_oop(&kasumi_test_case_1);
6178 }
6179
6180 static int
6181 test_kasumi_decryption_test_case_2(void)
6182 {
6183         return test_kasumi_decryption(&kasumi_test_case_2);
6184 }
6185
6186 static int
6187 test_kasumi_decryption_test_case_3(void)
6188 {
6189         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6190         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6191                 return -ENOTSUP;
6192         return test_kasumi_decryption(&kasumi_test_case_3);
6193 }
6194
6195 static int
6196 test_kasumi_decryption_test_case_4(void)
6197 {
6198         return test_kasumi_decryption(&kasumi_test_case_4);
6199 }
6200
6201 static int
6202 test_kasumi_decryption_test_case_5(void)
6203 {
6204         return test_kasumi_decryption(&kasumi_test_case_5);
6205 }
6206 static int
6207 test_snow3g_encryption_test_case_1(void)
6208 {
6209         return test_snow3g_encryption(&snow3g_test_case_1);
6210 }
6211
6212 static int
6213 test_snow3g_encryption_test_case_1_oop(void)
6214 {
6215         return test_snow3g_encryption_oop(&snow3g_test_case_1);
6216 }
6217
6218 static int
6219 test_snow3g_encryption_test_case_1_oop_sgl(void)
6220 {
6221         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6222 }
6223
6224
6225 static int
6226 test_snow3g_encryption_test_case_1_offset_oop(void)
6227 {
6228         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6229 }
6230
6231 static int
6232 test_snow3g_encryption_test_case_2(void)
6233 {
6234         return test_snow3g_encryption(&snow3g_test_case_2);
6235 }
6236
6237 static int
6238 test_snow3g_encryption_test_case_3(void)
6239 {
6240         return test_snow3g_encryption(&snow3g_test_case_3);
6241 }
6242
6243 static int
6244 test_snow3g_encryption_test_case_4(void)
6245 {
6246         return test_snow3g_encryption(&snow3g_test_case_4);
6247 }
6248
6249 static int
6250 test_snow3g_encryption_test_case_5(void)
6251 {
6252         return test_snow3g_encryption(&snow3g_test_case_5);
6253 }
6254
6255 static int
6256 test_snow3g_decryption_test_case_1(void)
6257 {
6258         return test_snow3g_decryption(&snow3g_test_case_1);
6259 }
6260
6261 static int
6262 test_snow3g_decryption_test_case_1_oop(void)
6263 {
6264         return test_snow3g_decryption_oop(&snow3g_test_case_1);
6265 }
6266
6267 static int
6268 test_snow3g_decryption_test_case_2(void)
6269 {
6270         return test_snow3g_decryption(&snow3g_test_case_2);
6271 }
6272
6273 static int
6274 test_snow3g_decryption_test_case_3(void)
6275 {
6276         return test_snow3g_decryption(&snow3g_test_case_3);
6277 }
6278
6279 static int
6280 test_snow3g_decryption_test_case_4(void)
6281 {
6282         return test_snow3g_decryption(&snow3g_test_case_4);
6283 }
6284
6285 static int
6286 test_snow3g_decryption_test_case_5(void)
6287 {
6288         return test_snow3g_decryption(&snow3g_test_case_5);
6289 }
6290
6291 /*
6292  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6293  * Pattern digest from snow3g_test_data must be allocated as
6294  * 4 last bytes in plaintext.
6295  */
6296 static void
6297 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6298                 struct snow3g_hash_test_data *output)
6299 {
6300         if ((pattern != NULL) && (output != NULL)) {
6301                 output->key.len = pattern->key.len;
6302
6303                 memcpy(output->key.data,
6304                 pattern->key.data, pattern->key.len);
6305
6306                 output->auth_iv.len = pattern->auth_iv.len;
6307
6308                 memcpy(output->auth_iv.data,
6309                 pattern->auth_iv.data, pattern->auth_iv.len);
6310
6311                 output->plaintext.len = pattern->plaintext.len;
6312
6313                 memcpy(output->plaintext.data,
6314                 pattern->plaintext.data, pattern->plaintext.len >> 3);
6315
6316                 output->digest.len = pattern->digest.len;
6317
6318                 memcpy(output->digest.data,
6319                 &pattern->plaintext.data[pattern->digest.offset_bytes],
6320                 pattern->digest.len);
6321
6322                 output->validAuthLenInBits.len =
6323                 pattern->validAuthLenInBits.len;
6324         }
6325 }
6326
6327 /*
6328  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6329  */
6330 static int
6331 test_snow3g_decryption_with_digest_test_case_1(void)
6332 {
6333         struct snow3g_hash_test_data snow3g_hash_data;
6334         struct rte_cryptodev_info dev_info;
6335         struct crypto_testsuite_params *ts_params = &testsuite_params;
6336
6337         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6338         uint64_t feat_flags = dev_info.feature_flags;
6339
6340         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6341                 printf("Device doesn't support encrypted digest operations.\n");
6342                 return -ENOTSUP;
6343         }
6344
6345         /*
6346          * Function prepare data for hash veryfication test case.
6347          * Digest is allocated in 4 last bytes in plaintext, pattern.
6348          */
6349         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6350
6351         return test_snow3g_decryption(&snow3g_test_case_7) &
6352                         test_snow3g_authentication_verify(&snow3g_hash_data);
6353 }
6354
6355 static int
6356 test_snow3g_cipher_auth_test_case_1(void)
6357 {
6358         return test_snow3g_cipher_auth(&snow3g_test_case_3);
6359 }
6360
6361 static int
6362 test_snow3g_auth_cipher_test_case_1(void)
6363 {
6364         return test_snow3g_auth_cipher(
6365                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6366 }
6367
6368 static int
6369 test_snow3g_auth_cipher_test_case_2(void)
6370 {
6371         return test_snow3g_auth_cipher(
6372                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6373 }
6374
6375 static int
6376 test_snow3g_auth_cipher_test_case_2_oop(void)
6377 {
6378         return test_snow3g_auth_cipher(
6379                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6380 }
6381
6382 static int
6383 test_snow3g_auth_cipher_part_digest_enc(void)
6384 {
6385         return test_snow3g_auth_cipher(
6386                 &snow3g_auth_cipher_partial_digest_encryption,
6387                         IN_PLACE, 0);
6388 }
6389
6390 static int
6391 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6392 {
6393         return test_snow3g_auth_cipher(
6394                 &snow3g_auth_cipher_partial_digest_encryption,
6395                         OUT_OF_PLACE, 0);
6396 }
6397
6398 static int
6399 test_snow3g_auth_cipher_test_case_3_sgl(void)
6400 {
6401         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6402         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6403                 return -ENOTSUP;
6404         return test_snow3g_auth_cipher_sgl(
6405                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6406 }
6407
6408 static int
6409 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6410 {
6411         return test_snow3g_auth_cipher_sgl(
6412                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6413 }
6414
6415 static int
6416 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6417 {
6418         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6419         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6420                 return -ENOTSUP;
6421         return test_snow3g_auth_cipher_sgl(
6422                 &snow3g_auth_cipher_partial_digest_encryption,
6423                         IN_PLACE, 0);
6424 }
6425
6426 static int
6427 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6428 {
6429         return test_snow3g_auth_cipher_sgl(
6430                 &snow3g_auth_cipher_partial_digest_encryption,
6431                         OUT_OF_PLACE, 0);
6432 }
6433
6434 static int
6435 test_snow3g_auth_cipher_verify_test_case_1(void)
6436 {
6437         return test_snow3g_auth_cipher(
6438                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6439 }
6440
6441 static int
6442 test_snow3g_auth_cipher_verify_test_case_2(void)
6443 {
6444         return test_snow3g_auth_cipher(
6445                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6446 }
6447
6448 static int
6449 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6450 {
6451         return test_snow3g_auth_cipher(
6452                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6453 }
6454
6455 static int
6456 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6457 {
6458         return test_snow3g_auth_cipher(
6459                 &snow3g_auth_cipher_partial_digest_encryption,
6460                         IN_PLACE, 1);
6461 }
6462
6463 static int
6464 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6465 {
6466         return test_snow3g_auth_cipher(
6467                 &snow3g_auth_cipher_partial_digest_encryption,
6468                         OUT_OF_PLACE, 1);
6469 }
6470
6471 static int
6472 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6473 {
6474         return test_snow3g_auth_cipher_sgl(
6475                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6476 }
6477
6478 static int
6479 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6480 {
6481         return test_snow3g_auth_cipher_sgl(
6482                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6483 }
6484
6485 static int
6486 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6487 {
6488         return test_snow3g_auth_cipher_sgl(
6489                 &snow3g_auth_cipher_partial_digest_encryption,
6490                         IN_PLACE, 1);
6491 }
6492
6493 static int
6494 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6495 {
6496         return test_snow3g_auth_cipher_sgl(
6497                 &snow3g_auth_cipher_partial_digest_encryption,
6498                         OUT_OF_PLACE, 1);
6499 }
6500
6501 static int
6502 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6503 {
6504         return test_snow3g_auth_cipher(
6505                 &snow3g_test_case_7, IN_PLACE, 0);
6506 }
6507
6508 static int
6509 test_kasumi_auth_cipher_test_case_1(void)
6510 {
6511         return test_kasumi_auth_cipher(
6512                 &kasumi_test_case_3, IN_PLACE, 0);
6513 }
6514
6515 static int
6516 test_kasumi_auth_cipher_test_case_2(void)
6517 {
6518         return test_kasumi_auth_cipher(
6519                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6520 }
6521
6522 static int
6523 test_kasumi_auth_cipher_test_case_2_oop(void)
6524 {
6525         return test_kasumi_auth_cipher(
6526                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6527 }
6528
6529 static int
6530 test_kasumi_auth_cipher_test_case_2_sgl(void)
6531 {
6532         return test_kasumi_auth_cipher_sgl(
6533                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6534 }
6535
6536 static int
6537 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6538 {
6539         return test_kasumi_auth_cipher_sgl(
6540                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6541 }
6542
6543 static int
6544 test_kasumi_auth_cipher_verify_test_case_1(void)
6545 {
6546         return test_kasumi_auth_cipher(
6547                 &kasumi_test_case_3, IN_PLACE, 1);
6548 }
6549
6550 static int
6551 test_kasumi_auth_cipher_verify_test_case_2(void)
6552 {
6553         return test_kasumi_auth_cipher(
6554                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6555 }
6556
6557 static int
6558 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6559 {
6560         return test_kasumi_auth_cipher(
6561                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6562 }
6563
6564 static int
6565 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6566 {
6567         return test_kasumi_auth_cipher_sgl(
6568                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6569 }
6570
6571 static int
6572 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6573 {
6574         return test_kasumi_auth_cipher_sgl(
6575                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6576 }
6577
6578 static int
6579 test_kasumi_cipher_auth_test_case_1(void)
6580 {
6581         return test_kasumi_cipher_auth(&kasumi_test_case_6);
6582 }
6583
6584 static int
6585 test_zuc_encryption_test_case_1(void)
6586 {
6587         return test_zuc_encryption(&zuc_test_case_cipher_193b);
6588 }
6589
6590 static int
6591 test_zuc_encryption_test_case_2(void)
6592 {
6593         return test_zuc_encryption(&zuc_test_case_cipher_800b);
6594 }
6595
6596 static int
6597 test_zuc_encryption_test_case_3(void)
6598 {
6599         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
6600 }
6601
6602 static int
6603 test_zuc_encryption_test_case_4(void)
6604 {
6605         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
6606 }
6607
6608 static int
6609 test_zuc_encryption_test_case_5(void)
6610 {
6611         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
6612 }
6613
6614 static int
6615 test_zuc_encryption_test_case_6_sgl(void)
6616 {
6617         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
6618 }
6619
6620 static int
6621 test_zuc_hash_generate_test_case_1(void)
6622 {
6623         return test_zuc_authentication(&zuc_test_case_auth_1b);
6624 }
6625
6626 static int
6627 test_zuc_hash_generate_test_case_2(void)
6628 {
6629         return test_zuc_authentication(&zuc_test_case_auth_90b);
6630 }
6631
6632 static int
6633 test_zuc_hash_generate_test_case_3(void)
6634 {
6635         return test_zuc_authentication(&zuc_test_case_auth_577b);
6636 }
6637
6638 static int
6639 test_zuc_hash_generate_test_case_4(void)
6640 {
6641         return test_zuc_authentication(&zuc_test_case_auth_2079b);
6642 }
6643
6644 static int
6645 test_zuc_hash_generate_test_case_5(void)
6646 {
6647         return test_zuc_authentication(&zuc_test_auth_5670b);
6648 }
6649
6650 static int
6651 test_zuc_hash_generate_test_case_6(void)
6652 {
6653         return test_zuc_authentication(&zuc_test_case_auth_128b);
6654 }
6655
6656 static int
6657 test_zuc_hash_generate_test_case_7(void)
6658 {
6659         return test_zuc_authentication(&zuc_test_case_auth_2080b);
6660 }
6661
6662 static int
6663 test_zuc_hash_generate_test_case_8(void)
6664 {
6665         return test_zuc_authentication(&zuc_test_case_auth_584b);
6666 }
6667
6668 static int
6669 test_zuc_cipher_auth_test_case_1(void)
6670 {
6671         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
6672 }
6673
6674 static int
6675 test_zuc_cipher_auth_test_case_2(void)
6676 {
6677         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
6678 }
6679
6680 static int
6681 test_zuc_auth_cipher_test_case_1(void)
6682 {
6683         return test_zuc_auth_cipher(
6684                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
6685 }
6686
6687 static int
6688 test_zuc_auth_cipher_test_case_1_oop(void)
6689 {
6690         return test_zuc_auth_cipher(
6691                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
6692 }
6693
6694 static int
6695 test_zuc_auth_cipher_test_case_1_sgl(void)
6696 {
6697         return test_zuc_auth_cipher_sgl(
6698                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
6699 }
6700
6701 static int
6702 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
6703 {
6704         return test_zuc_auth_cipher_sgl(
6705                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
6706 }
6707
6708 static int
6709 test_zuc_auth_cipher_verify_test_case_1(void)
6710 {
6711         return test_zuc_auth_cipher(
6712                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
6713 }
6714
6715 static int
6716 test_zuc_auth_cipher_verify_test_case_1_oop(void)
6717 {
6718         return test_zuc_auth_cipher(
6719                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
6720 }
6721
6722 static int
6723 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
6724 {
6725         return test_zuc_auth_cipher_sgl(
6726                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
6727 }
6728
6729 static int
6730 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
6731 {
6732         return test_zuc_auth_cipher_sgl(
6733                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
6734 }
6735
6736 static int
6737 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
6738 {
6739         uint8_t dev_id = testsuite_params.valid_devs[0];
6740
6741         struct rte_cryptodev_sym_capability_idx cap_idx;
6742
6743         /* Check if device supports particular cipher algorithm */
6744         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6745         cap_idx.algo.cipher = tdata->cipher_algo;
6746         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
6747                 return -ENOTSUP;
6748
6749         /* Check if device supports particular hash algorithm */
6750         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6751         cap_idx.algo.auth = tdata->auth_algo;
6752         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
6753                 return -ENOTSUP;
6754
6755         return 0;
6756 }
6757
6758 static int
6759 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
6760         uint8_t op_mode, uint8_t verify)
6761 {
6762         struct crypto_testsuite_params *ts_params = &testsuite_params;
6763         struct crypto_unittest_params *ut_params = &unittest_params;
6764
6765         int retval;
6766
6767         uint8_t *plaintext = NULL, *ciphertext = NULL;
6768         unsigned int plaintext_pad_len;
6769         unsigned int plaintext_len;
6770         unsigned int ciphertext_pad_len;
6771         unsigned int ciphertext_len;
6772
6773         struct rte_cryptodev_info dev_info;
6774         struct rte_crypto_op *op;
6775
6776         /* Check if device supports particular algorithms separately */
6777         if (test_mixed_check_if_unsupported(tdata))
6778                 return -ENOTSUP;
6779         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6780                 return -ENOTSUP;
6781
6782         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6783
6784         uint64_t feat_flags = dev_info.feature_flags;
6785
6786         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6787                 printf("Device doesn't support digest encrypted.\n");
6788                 return -ENOTSUP;
6789         }
6790
6791         /* Create the session */
6792         if (verify)
6793                 retval = create_wireless_algo_cipher_auth_session(
6794                                 ts_params->valid_devs[0],
6795                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
6796                                 RTE_CRYPTO_AUTH_OP_VERIFY,
6797                                 tdata->auth_algo,
6798                                 tdata->cipher_algo,
6799                                 tdata->auth_key.data, tdata->auth_key.len,
6800                                 tdata->auth_iv.len, tdata->digest_enc.len,
6801                                 tdata->cipher_iv.len);
6802         else
6803                 retval = create_wireless_algo_auth_cipher_session(
6804                                 ts_params->valid_devs[0],
6805                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6806                                 RTE_CRYPTO_AUTH_OP_GENERATE,
6807                                 tdata->auth_algo,
6808                                 tdata->cipher_algo,
6809                                 tdata->auth_key.data, tdata->auth_key.len,
6810                                 tdata->auth_iv.len, tdata->digest_enc.len,
6811                                 tdata->cipher_iv.len);
6812         if (retval < 0)
6813                 return retval;
6814
6815         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6816         if (op_mode == OUT_OF_PLACE)
6817                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6818
6819         /* clear mbuf payload */
6820         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6821                 rte_pktmbuf_tailroom(ut_params->ibuf));
6822         if (op_mode == OUT_OF_PLACE) {
6823
6824                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6825                                 rte_pktmbuf_tailroom(ut_params->obuf));
6826         }
6827
6828         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
6829         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
6830         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6831         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6832
6833         if (verify) {
6834                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6835                                 ciphertext_pad_len);
6836                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6837                 if (op_mode == OUT_OF_PLACE)
6838                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6839                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6840                                 ciphertext_len);
6841         } else {
6842                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6843                                 plaintext_pad_len);
6844                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6845                 if (op_mode == OUT_OF_PLACE)
6846                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6847                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6848         }
6849
6850         /* Create the operation */
6851         retval = create_wireless_algo_auth_cipher_operation(
6852                         tdata->digest_enc.data, tdata->digest_enc.len,
6853                         tdata->cipher_iv.data, tdata->cipher_iv.len,
6854                         tdata->auth_iv.data, tdata->auth_iv.len,
6855                         (tdata->digest_enc.offset == 0 ?
6856                                 plaintext_pad_len
6857                                 : tdata->digest_enc.offset),
6858                         tdata->validCipherLen.len_bits,
6859                         tdata->cipher.offset_bits,
6860                         tdata->validAuthLen.len_bits,
6861                         tdata->auth.offset_bits,
6862                         op_mode, 0, verify);
6863
6864         if (retval < 0)
6865                 return retval;
6866
6867         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
6868
6869         /* Check if the op failed because the device doesn't */
6870         /* support this particular combination of algorithms */
6871         if (op == NULL && ut_params->op->status ==
6872                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
6873                 printf("Device doesn't support this mixed combination. "
6874                                 "Test Skipped.\n");
6875                 return -ENOTSUP;
6876         }
6877         ut_params->op = op;
6878
6879         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6880
6881         ut_params->obuf = (op_mode == IN_PLACE ?
6882                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6883
6884         if (verify) {
6885                 if (ut_params->obuf)
6886                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6887                                                         uint8_t *);
6888                 else
6889                         plaintext = ciphertext +
6890                                         (tdata->cipher.offset_bits >> 3);
6891
6892                 debug_hexdump(stdout, "plaintext:", plaintext,
6893                                 tdata->plaintext.len_bits >> 3);
6894                 debug_hexdump(stdout, "plaintext expected:",
6895                                 tdata->plaintext.data,
6896                                 tdata->plaintext.len_bits >> 3);
6897         } else {
6898                 if (ut_params->obuf)
6899                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6900                                         uint8_t *);
6901                 else
6902                         ciphertext = plaintext;
6903
6904                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6905                                 ciphertext_len);
6906                 debug_hexdump(stdout, "ciphertext expected:",
6907                                 tdata->ciphertext.data,
6908                                 tdata->ciphertext.len_bits >> 3);
6909
6910                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6911                                 + (tdata->digest_enc.offset == 0 ?
6912                 plaintext_pad_len : tdata->digest_enc.offset);
6913
6914                 debug_hexdump(stdout, "digest:", ut_params->digest,
6915                                 tdata->digest_enc.len);
6916                 debug_hexdump(stdout, "digest expected:",
6917                                 tdata->digest_enc.data,
6918                                 tdata->digest_enc.len);
6919         }
6920
6921         /* Validate obuf */
6922         if (verify) {
6923                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6924                                 plaintext,
6925                                 tdata->plaintext.data,
6926                                 tdata->plaintext.len_bits >> 3,
6927                                 "Plaintext data not as expected");
6928         } else {
6929                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6930                                 ciphertext,
6931                                 tdata->ciphertext.data,
6932                                 tdata->validDataLen.len_bits,
6933                                 "Ciphertext data not as expected");
6934
6935                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6936                                 ut_params->digest,
6937                                 tdata->digest_enc.data,
6938                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
6939                                 "Generated auth tag not as expected");
6940         }
6941
6942         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6943                         "crypto op processing failed");
6944
6945         return 0;
6946 }
6947
6948 static int
6949 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
6950         uint8_t op_mode, uint8_t verify)
6951 {
6952         struct crypto_testsuite_params *ts_params = &testsuite_params;
6953         struct crypto_unittest_params *ut_params = &unittest_params;
6954
6955         int retval;
6956
6957         const uint8_t *plaintext = NULL;
6958         const uint8_t *ciphertext = NULL;
6959         const uint8_t *digest = NULL;
6960         unsigned int plaintext_pad_len;
6961         unsigned int plaintext_len;
6962         unsigned int ciphertext_pad_len;
6963         unsigned int ciphertext_len;
6964         uint8_t buffer[10000];
6965         uint8_t digest_buffer[10000];
6966
6967         struct rte_cryptodev_info dev_info;
6968         struct rte_crypto_op *op;
6969
6970         /* Check if device supports particular algorithms */
6971         if (test_mixed_check_if_unsupported(tdata))
6972                 return -ENOTSUP;
6973         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6974                 return -ENOTSUP;
6975
6976         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6977
6978         uint64_t feat_flags = dev_info.feature_flags;
6979
6980         if (op_mode == IN_PLACE) {
6981                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6982                         printf("Device doesn't support in-place scatter-gather "
6983                                         "in both input and output mbufs.\n");
6984                         return -ENOTSUP;
6985                 }
6986         } else {
6987                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6988                         printf("Device doesn't support out-of-place scatter-gather "
6989                                         "in both input and output mbufs.\n");
6990                         return -ENOTSUP;
6991                 }
6992                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6993                         printf("Device doesn't support digest encrypted.\n");
6994                         return -ENOTSUP;
6995                 }
6996         }
6997
6998         /* Create the session */
6999         if (verify)
7000                 retval = create_wireless_algo_cipher_auth_session(
7001                                 ts_params->valid_devs[0],
7002                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7003                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7004                                 tdata->auth_algo,
7005                                 tdata->cipher_algo,
7006                                 tdata->auth_key.data, tdata->auth_key.len,
7007                                 tdata->auth_iv.len, tdata->digest_enc.len,
7008                                 tdata->cipher_iv.len);
7009         else
7010                 retval = create_wireless_algo_auth_cipher_session(
7011                                 ts_params->valid_devs[0],
7012                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7013                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7014                                 tdata->auth_algo,
7015                                 tdata->cipher_algo,
7016                                 tdata->auth_key.data, tdata->auth_key.len,
7017                                 tdata->auth_iv.len, tdata->digest_enc.len,
7018                                 tdata->cipher_iv.len);
7019         if (retval < 0)
7020                 return retval;
7021
7022         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7023         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7024         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7025         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7026
7027         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7028                         ciphertext_pad_len, 15, 0);
7029         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7030                         "Failed to allocate input buffer in mempool");
7031
7032         if (op_mode == OUT_OF_PLACE) {
7033                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7034                                 plaintext_pad_len, 15, 0);
7035                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
7036                                 "Failed to allocate output buffer in mempool");
7037         }
7038
7039         if (verify) {
7040                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7041                         tdata->ciphertext.data);
7042                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7043                                         ciphertext_len, buffer);
7044                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7045                         ciphertext_len);
7046         } else {
7047                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7048                         tdata->plaintext.data);
7049                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7050                                         plaintext_len, buffer);
7051                 debug_hexdump(stdout, "plaintext:", plaintext,
7052                         plaintext_len);
7053         }
7054         memset(buffer, 0, sizeof(buffer));
7055
7056         /* Create the operation */
7057         retval = create_wireless_algo_auth_cipher_operation(
7058                         tdata->digest_enc.data, tdata->digest_enc.len,
7059                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7060                         tdata->auth_iv.data, tdata->auth_iv.len,
7061                         (tdata->digest_enc.offset == 0 ?
7062                                 plaintext_pad_len
7063                                 : tdata->digest_enc.offset),
7064                         tdata->validCipherLen.len_bits,
7065                         tdata->cipher.offset_bits,
7066                         tdata->validAuthLen.len_bits,
7067                         tdata->auth.offset_bits,
7068                         op_mode, 1, verify);
7069
7070         if (retval < 0)
7071                 return retval;
7072
7073         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7074
7075         /* Check if the op failed because the device doesn't */
7076         /* support this particular combination of algorithms */
7077         if (op == NULL && ut_params->op->status ==
7078                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7079                 printf("Device doesn't support this mixed combination. "
7080                                 "Test Skipped.\n");
7081                 return -ENOTSUP;
7082         }
7083         ut_params->op = op;
7084
7085         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7086
7087         ut_params->obuf = (op_mode == IN_PLACE ?
7088                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7089
7090         if (verify) {
7091                 if (ut_params->obuf)
7092                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7093                                         plaintext_len, buffer);
7094                 else
7095                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7096                                         plaintext_len, buffer);
7097
7098                 debug_hexdump(stdout, "plaintext:", plaintext,
7099                                 (tdata->plaintext.len_bits >> 3) -
7100                                 tdata->digest_enc.len);
7101                 debug_hexdump(stdout, "plaintext expected:",
7102                                 tdata->plaintext.data,
7103                                 (tdata->plaintext.len_bits >> 3) -
7104                                 tdata->digest_enc.len);
7105         } else {
7106                 if (ut_params->obuf)
7107                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7108                                         ciphertext_len, buffer);
7109                 else
7110                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7111                                         ciphertext_len, buffer);
7112
7113                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7114                         ciphertext_len);
7115                 debug_hexdump(stdout, "ciphertext expected:",
7116                         tdata->ciphertext.data,
7117                         tdata->ciphertext.len_bits >> 3);
7118
7119                 if (ut_params->obuf)
7120                         digest = rte_pktmbuf_read(ut_params->obuf,
7121                                         (tdata->digest_enc.offset == 0 ?
7122                                                 plaintext_pad_len :
7123                                                 tdata->digest_enc.offset),
7124                                         tdata->digest_enc.len, digest_buffer);
7125                 else
7126                         digest = rte_pktmbuf_read(ut_params->ibuf,
7127                                         (tdata->digest_enc.offset == 0 ?
7128                                                 plaintext_pad_len :
7129                                                 tdata->digest_enc.offset),
7130                                         tdata->digest_enc.len, digest_buffer);
7131
7132                 debug_hexdump(stdout, "digest:", digest,
7133                                 tdata->digest_enc.len);
7134                 debug_hexdump(stdout, "digest expected:",
7135                                 tdata->digest_enc.data, tdata->digest_enc.len);
7136         }
7137
7138         /* Validate obuf */
7139         if (verify) {
7140                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7141                                 plaintext,
7142                                 tdata->plaintext.data,
7143                                 tdata->plaintext.len_bits >> 3,
7144                                 "Plaintext data not as expected");
7145         } else {
7146                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7147                                 ciphertext,
7148                                 tdata->ciphertext.data,
7149                                 tdata->validDataLen.len_bits,
7150                                 "Ciphertext data not as expected");
7151                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7152                                 digest,
7153                                 tdata->digest_enc.data,
7154                                 tdata->digest_enc.len,
7155                                 "Generated auth tag not as expected");
7156         }
7157
7158         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7159                         "crypto op processing failed");
7160
7161         return 0;
7162 }
7163
7164 /** AUTH AES CMAC + CIPHER AES CTR */
7165
7166 static int
7167 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7168 {
7169         return test_mixed_auth_cipher(
7170                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7171 }
7172
7173 static int
7174 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7175 {
7176         return test_mixed_auth_cipher(
7177                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7178 }
7179
7180 static int
7181 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7182 {
7183         return test_mixed_auth_cipher_sgl(
7184                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7185 }
7186
7187 static int
7188 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7189 {
7190         return test_mixed_auth_cipher_sgl(
7191                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7192 }
7193
7194 static int
7195 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7196 {
7197         return test_mixed_auth_cipher(
7198                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7199 }
7200
7201 static int
7202 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7203 {
7204         return test_mixed_auth_cipher(
7205                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7206 }
7207
7208 static int
7209 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7210 {
7211         return test_mixed_auth_cipher_sgl(
7212                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7213 }
7214
7215 static int
7216 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7217 {
7218         return test_mixed_auth_cipher_sgl(
7219                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7220 }
7221
7222 /** MIXED AUTH + CIPHER */
7223
7224 static int
7225 test_auth_zuc_cipher_snow_test_case_1(void)
7226 {
7227         return test_mixed_auth_cipher(
7228                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7229 }
7230
7231 static int
7232 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7233 {
7234         return test_mixed_auth_cipher(
7235                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7236 }
7237
7238 static int
7239 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7240 {
7241         return test_mixed_auth_cipher(
7242                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7243 }
7244
7245 static int
7246 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7247 {
7248         return test_mixed_auth_cipher(
7249                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7250 }
7251
7252 static int
7253 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7254 {
7255         return test_mixed_auth_cipher(
7256                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7257 }
7258
7259 static int
7260 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7261 {
7262         return test_mixed_auth_cipher(
7263                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7264 }
7265
7266 static int
7267 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7268 {
7269         return test_mixed_auth_cipher(
7270                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7271 }
7272
7273 static int
7274 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7275 {
7276         return test_mixed_auth_cipher(
7277                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7278 }
7279
7280 static int
7281 test_auth_snow_cipher_zuc_test_case_1(void)
7282 {
7283         return test_mixed_auth_cipher(
7284                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7285 }
7286
7287 static int
7288 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7289 {
7290         return test_mixed_auth_cipher(
7291                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7292 }
7293
7294 static int
7295 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7296 {
7297         return test_mixed_auth_cipher(
7298                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7299 }
7300
7301 static int
7302 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7303 {
7304         return test_mixed_auth_cipher(
7305                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7306 }
7307
7308 static int
7309 test_auth_null_cipher_snow_test_case_1(void)
7310 {
7311         return test_mixed_auth_cipher(
7312                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7313 }
7314
7315 static int
7316 test_verify_auth_null_cipher_snow_test_case_1(void)
7317 {
7318         return test_mixed_auth_cipher(
7319                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7320 }
7321
7322 static int
7323 test_auth_null_cipher_zuc_test_case_1(void)
7324 {
7325         return test_mixed_auth_cipher(
7326                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7327 }
7328
7329 static int
7330 test_verify_auth_null_cipher_zuc_test_case_1(void)
7331 {
7332         return test_mixed_auth_cipher(
7333                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7334 }
7335
7336 static int
7337 test_auth_snow_cipher_null_test_case_1(void)
7338 {
7339         return test_mixed_auth_cipher(
7340                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7341 }
7342
7343 static int
7344 test_verify_auth_snow_cipher_null_test_case_1(void)
7345 {
7346         return test_mixed_auth_cipher(
7347                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7348 }
7349
7350 static int
7351 test_auth_zuc_cipher_null_test_case_1(void)
7352 {
7353         return test_mixed_auth_cipher(
7354                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7355 }
7356
7357 static int
7358 test_verify_auth_zuc_cipher_null_test_case_1(void)
7359 {
7360         return test_mixed_auth_cipher(
7361                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7362 }
7363
7364 static int
7365 test_auth_null_cipher_aes_ctr_test_case_1(void)
7366 {
7367         return test_mixed_auth_cipher(
7368                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7369 }
7370
7371 static int
7372 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7373 {
7374         return test_mixed_auth_cipher(
7375                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7376 }
7377
7378 static int
7379 test_auth_aes_cmac_cipher_null_test_case_1(void)
7380 {
7381         return test_mixed_auth_cipher(
7382                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7383 }
7384
7385 static int
7386 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7387 {
7388         return test_mixed_auth_cipher(
7389                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7390 }
7391
7392 /* ***** AEAD algorithm Tests ***** */
7393
7394 static int
7395 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7396                 enum rte_crypto_aead_operation op,
7397                 const uint8_t *key, const uint8_t key_len,
7398                 const uint16_t aad_len, const uint8_t auth_len,
7399                 uint8_t iv_len)
7400 {
7401         uint8_t aead_key[key_len];
7402
7403         struct crypto_testsuite_params *ts_params = &testsuite_params;
7404         struct crypto_unittest_params *ut_params = &unittest_params;
7405
7406         memcpy(aead_key, key, key_len);
7407
7408         /* Setup AEAD Parameters */
7409         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7410         ut_params->aead_xform.next = NULL;
7411         ut_params->aead_xform.aead.algo = algo;
7412         ut_params->aead_xform.aead.op = op;
7413         ut_params->aead_xform.aead.key.data = aead_key;
7414         ut_params->aead_xform.aead.key.length = key_len;
7415         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7416         ut_params->aead_xform.aead.iv.length = iv_len;
7417         ut_params->aead_xform.aead.digest_length = auth_len;
7418         ut_params->aead_xform.aead.aad_length = aad_len;
7419
7420         debug_hexdump(stdout, "key:", key, key_len);
7421
7422         /* Create Crypto session*/
7423         ut_params->sess = rte_cryptodev_sym_session_create(
7424                         ts_params->session_mpool);
7425
7426         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7427                         &ut_params->aead_xform,
7428                         ts_params->session_priv_mpool);
7429
7430         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7431
7432         return 0;
7433 }
7434
7435 static int
7436 create_aead_xform(struct rte_crypto_op *op,
7437                 enum rte_crypto_aead_algorithm algo,
7438                 enum rte_crypto_aead_operation aead_op,
7439                 uint8_t *key, const uint8_t key_len,
7440                 const uint8_t aad_len, const uint8_t auth_len,
7441                 uint8_t iv_len)
7442 {
7443         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7444                         "failed to allocate space for crypto transform");
7445
7446         struct rte_crypto_sym_op *sym_op = op->sym;
7447
7448         /* Setup AEAD Parameters */
7449         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7450         sym_op->xform->next = NULL;
7451         sym_op->xform->aead.algo = algo;
7452         sym_op->xform->aead.op = aead_op;
7453         sym_op->xform->aead.key.data = key;
7454         sym_op->xform->aead.key.length = key_len;
7455         sym_op->xform->aead.iv.offset = IV_OFFSET;
7456         sym_op->xform->aead.iv.length = iv_len;
7457         sym_op->xform->aead.digest_length = auth_len;
7458         sym_op->xform->aead.aad_length = aad_len;
7459
7460         debug_hexdump(stdout, "key:", key, key_len);
7461
7462         return 0;
7463 }
7464
7465 static int
7466 create_aead_operation(enum rte_crypto_aead_operation op,
7467                 const struct aead_test_data *tdata)
7468 {
7469         struct crypto_testsuite_params *ts_params = &testsuite_params;
7470         struct crypto_unittest_params *ut_params = &unittest_params;
7471
7472         uint8_t *plaintext, *ciphertext;
7473         unsigned int aad_pad_len, plaintext_pad_len;
7474
7475         /* Generate Crypto op data structure */
7476         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7477                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7478         TEST_ASSERT_NOT_NULL(ut_params->op,
7479                         "Failed to allocate symmetric crypto operation struct");
7480
7481         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7482
7483         /* Append aad data */
7484         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7485                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7486                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7487                                 aad_pad_len);
7488                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7489                                 "no room to append aad");
7490
7491                 sym_op->aead.aad.phys_addr =
7492                                 rte_pktmbuf_iova(ut_params->ibuf);
7493                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
7494                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7495                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7496                         tdata->aad.len);
7497
7498                 /* Append IV at the end of the crypto operation*/
7499                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7500                                 uint8_t *, IV_OFFSET);
7501
7502                 /* Copy IV 1 byte after the IV pointer, according to the API */
7503                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7504                 debug_hexdump(stdout, "iv:", iv_ptr,
7505                         tdata->iv.len);
7506         } else {
7507                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7508                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7509                                 aad_pad_len);
7510                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7511                                 "no room to append aad");
7512
7513                 sym_op->aead.aad.phys_addr =
7514                                 rte_pktmbuf_iova(ut_params->ibuf);
7515                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7516                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7517                         tdata->aad.len);
7518
7519                 /* Append IV at the end of the crypto operation*/
7520                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7521                                 uint8_t *, IV_OFFSET);
7522
7523                 if (tdata->iv.len == 0) {
7524                         rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7525                         debug_hexdump(stdout, "iv:", iv_ptr,
7526                                 AES_GCM_J0_LENGTH);
7527                 } else {
7528                         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7529                         debug_hexdump(stdout, "iv:", iv_ptr,
7530                                 tdata->iv.len);
7531                 }
7532         }
7533
7534         /* Append plaintext/ciphertext */
7535         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7536                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7537                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7538                                 plaintext_pad_len);
7539                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7540
7541                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7542                 debug_hexdump(stdout, "plaintext:", plaintext,
7543                                 tdata->plaintext.len);
7544
7545                 if (ut_params->obuf) {
7546                         ciphertext = (uint8_t *)rte_pktmbuf_append(
7547                                         ut_params->obuf,
7548                                         plaintext_pad_len + aad_pad_len);
7549                         TEST_ASSERT_NOT_NULL(ciphertext,
7550                                         "no room to append ciphertext");
7551
7552                         memset(ciphertext + aad_pad_len, 0,
7553                                         tdata->ciphertext.len);
7554                 }
7555         } else {
7556                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7557                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7558                                 plaintext_pad_len);
7559                 TEST_ASSERT_NOT_NULL(ciphertext,
7560                                 "no room to append ciphertext");
7561
7562                 memcpy(ciphertext, tdata->ciphertext.data,
7563                                 tdata->ciphertext.len);
7564                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7565                                 tdata->ciphertext.len);
7566
7567                 if (ut_params->obuf) {
7568                         plaintext = (uint8_t *)rte_pktmbuf_append(
7569                                         ut_params->obuf,
7570                                         plaintext_pad_len + aad_pad_len);
7571                         TEST_ASSERT_NOT_NULL(plaintext,
7572                                         "no room to append plaintext");
7573
7574                         memset(plaintext + aad_pad_len, 0,
7575                                         tdata->plaintext.len);
7576                 }
7577         }
7578
7579         /* Append digest data */
7580         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7581                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7582                                 ut_params->obuf ? ut_params->obuf :
7583                                                 ut_params->ibuf,
7584                                                 tdata->auth_tag.len);
7585                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7586                                 "no room to append digest");
7587                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
7588                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7589                                 ut_params->obuf ? ut_params->obuf :
7590                                                 ut_params->ibuf,
7591                                                 plaintext_pad_len +
7592                                                 aad_pad_len);
7593         } else {
7594                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7595                                 ut_params->ibuf, tdata->auth_tag.len);
7596                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7597                                 "no room to append digest");
7598                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7599                                 ut_params->ibuf,
7600                                 plaintext_pad_len + aad_pad_len);
7601
7602                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
7603                         tdata->auth_tag.len);
7604                 debug_hexdump(stdout, "digest:",
7605                         sym_op->aead.digest.data,
7606                         tdata->auth_tag.len);
7607         }
7608
7609         sym_op->aead.data.length = tdata->plaintext.len;
7610         sym_op->aead.data.offset = aad_pad_len;
7611
7612         return 0;
7613 }
7614
7615 static int
7616 test_authenticated_encryption(const struct aead_test_data *tdata)
7617 {
7618         struct crypto_testsuite_params *ts_params = &testsuite_params;
7619         struct crypto_unittest_params *ut_params = &unittest_params;
7620
7621         int retval;
7622         uint8_t *ciphertext, *auth_tag;
7623         uint16_t plaintext_pad_len;
7624         uint32_t i;
7625         struct rte_cryptodev_info dev_info;
7626
7627         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7628         uint64_t feat_flags = dev_info.feature_flags;
7629
7630         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
7631                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
7632                 printf("Device doesn't support RAW data-path APIs.\n");
7633                 return -ENOTSUP;
7634         }
7635
7636         /* Verify the capabilities */
7637         struct rte_cryptodev_sym_capability_idx cap_idx;
7638         const struct rte_cryptodev_symmetric_capability *capability;
7639         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7640         cap_idx.algo.aead = tdata->algo;
7641         capability = rte_cryptodev_sym_capability_get(
7642                         ts_params->valid_devs[0], &cap_idx);
7643         if (capability == NULL)
7644                 return -ENOTSUP;
7645         if (rte_cryptodev_sym_capability_check_aead(
7646                         capability, tdata->key.len, tdata->auth_tag.len,
7647                         tdata->aad.len, tdata->iv.len))
7648                 return -ENOTSUP;
7649
7650         /* Create AEAD session */
7651         retval = create_aead_session(ts_params->valid_devs[0],
7652                         tdata->algo,
7653                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
7654                         tdata->key.data, tdata->key.len,
7655                         tdata->aad.len, tdata->auth_tag.len,
7656                         tdata->iv.len);
7657         if (retval < 0)
7658                 return retval;
7659
7660         if (tdata->aad.len > MBUF_SIZE) {
7661                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
7662                 /* Populate full size of add data */
7663                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
7664                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
7665         } else
7666                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7667
7668         /* clear mbuf payload */
7669         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7670                         rte_pktmbuf_tailroom(ut_params->ibuf));
7671
7672         /* Create AEAD operation */
7673         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
7674         if (retval < 0)
7675                 return retval;
7676
7677         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7678
7679         ut_params->op->sym->m_src = ut_params->ibuf;
7680
7681         /* Process crypto operation */
7682         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
7683                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
7684         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7685                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
7686                                 ut_params->op, 0, 0, 0, 0);
7687         else
7688                 TEST_ASSERT_NOT_NULL(
7689                         process_crypto_request(ts_params->valid_devs[0],
7690                         ut_params->op), "failed to process sym crypto op");
7691
7692         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7693                         "crypto op processing failed");
7694
7695         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7696
7697         if (ut_params->op->sym->m_dst) {
7698                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7699                                 uint8_t *);
7700                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
7701                                 uint8_t *, plaintext_pad_len);
7702         } else {
7703                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
7704                                 uint8_t *,
7705                                 ut_params->op->sym->cipher.data.offset);
7706                 auth_tag = ciphertext + plaintext_pad_len;
7707         }
7708
7709         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
7710         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
7711
7712         /* Validate obuf */
7713         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7714                         ciphertext,
7715                         tdata->ciphertext.data,
7716                         tdata->ciphertext.len,
7717                         "Ciphertext data not as expected");
7718
7719         TEST_ASSERT_BUFFERS_ARE_EQUAL(
7720                         auth_tag,
7721                         tdata->auth_tag.data,
7722                         tdata->auth_tag.len,
7723                         "Generated auth tag not as expected");
7724
7725         return 0;
7726
7727 }
7728
7729 #ifdef RTE_LIB_SECURITY
7730 static int
7731 security_proto_supported(enum rte_security_session_action_type action,
7732         enum rte_security_session_protocol proto)
7733 {
7734         struct crypto_testsuite_params *ts_params = &testsuite_params;
7735
7736         const struct rte_security_capability *capabilities;
7737         const struct rte_security_capability *capability;
7738         uint16_t i = 0;
7739
7740         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7741                                 rte_cryptodev_get_sec_ctx(
7742                                 ts_params->valid_devs[0]);
7743
7744
7745         capabilities = rte_security_capabilities_get(ctx);
7746
7747         if (capabilities == NULL)
7748                 return -ENOTSUP;
7749
7750         while ((capability = &capabilities[i++])->action !=
7751                         RTE_SECURITY_ACTION_TYPE_NONE) {
7752                 if (capability->action == action &&
7753                                 capability->protocol == proto)
7754                         return 0;
7755         }
7756
7757         return -ENOTSUP;
7758 }
7759
7760 /* Basic algorithm run function for async inplace mode.
7761  * Creates a session from input parameters and runs one operation
7762  * on input_vec. Checks the output of the crypto operation against
7763  * output_vec.
7764  */
7765 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
7766                            enum rte_crypto_auth_operation opa,
7767                            const uint8_t *input_vec, unsigned int input_vec_len,
7768                            const uint8_t *output_vec,
7769                            unsigned int output_vec_len,
7770                            enum rte_crypto_cipher_algorithm cipher_alg,
7771                            const uint8_t *cipher_key, uint32_t cipher_key_len,
7772                            enum rte_crypto_auth_algorithm auth_alg,
7773                            const uint8_t *auth_key, uint32_t auth_key_len,
7774                            uint8_t bearer, enum rte_security_pdcp_domain domain,
7775                            uint8_t packet_direction, uint8_t sn_size,
7776                            uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
7777 {
7778         struct crypto_testsuite_params *ts_params = &testsuite_params;
7779         struct crypto_unittest_params *ut_params = &unittest_params;
7780         uint8_t *plaintext;
7781         int ret = TEST_SUCCESS;
7782         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7783                                 rte_cryptodev_get_sec_ctx(
7784                                 ts_params->valid_devs[0]);
7785
7786         /* Verify the capabilities */
7787         struct rte_security_capability_idx sec_cap_idx;
7788
7789         sec_cap_idx.action = ut_params->type;
7790         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
7791         sec_cap_idx.pdcp.domain = domain;
7792         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
7793                 return -ENOTSUP;
7794
7795         /* Generate test mbuf data */
7796         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7797
7798         /* clear mbuf payload */
7799         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7800                         rte_pktmbuf_tailroom(ut_params->ibuf));
7801
7802         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7803                                                   input_vec_len);
7804         memcpy(plaintext, input_vec, input_vec_len);
7805
7806         /* Out of place support */
7807         if (oop) {
7808                 /*
7809                  * For out-op-place we need to alloc another mbuf
7810                  */
7811                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7812                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
7813         }
7814
7815         /* Setup Cipher Parameters */
7816         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7817         ut_params->cipher_xform.cipher.algo = cipher_alg;
7818         ut_params->cipher_xform.cipher.op = opc;
7819         ut_params->cipher_xform.cipher.key.data = cipher_key;
7820         ut_params->cipher_xform.cipher.key.length = cipher_key_len;
7821         ut_params->cipher_xform.cipher.iv.length =
7822                                 packet_direction ? 4 : 0;
7823         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
7824
7825         /* Setup HMAC Parameters if ICV header is required */
7826         if (auth_alg != 0) {
7827                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7828                 ut_params->auth_xform.next = NULL;
7829                 ut_params->auth_xform.auth.algo = auth_alg;
7830                 ut_params->auth_xform.auth.op = opa;
7831                 ut_params->auth_xform.auth.key.data = auth_key;
7832                 ut_params->auth_xform.auth.key.length = auth_key_len;
7833
7834                 ut_params->cipher_xform.next = &ut_params->auth_xform;
7835         } else {
7836                 ut_params->cipher_xform.next = NULL;
7837         }
7838
7839         struct rte_security_session_conf sess_conf = {
7840                 .action_type = ut_params->type,
7841                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
7842                 {.pdcp = {
7843                         .bearer = bearer,
7844                         .domain = domain,
7845                         .pkt_dir = packet_direction,
7846                         .sn_size = sn_size,
7847                         .hfn = packet_direction ? 0 : hfn,
7848                         /**
7849                          * hfn can be set as pdcp_test_hfn[i]
7850                          * if hfn_ovrd is not set. Here, PDCP
7851                          * packet direction is just used to
7852                          * run half of the cases with session
7853                          * HFN and other half with per packet
7854                          * HFN.
7855                          */
7856                         .hfn_threshold = hfn_threshold,
7857                         .hfn_ovrd = packet_direction ? 1 : 0,
7858                         .sdap_enabled = sdap,
7859                 } },
7860                 .crypto_xform = &ut_params->cipher_xform
7861         };
7862
7863         /* Create security session */
7864         ut_params->sec_session = rte_security_session_create(ctx,
7865                                 &sess_conf, ts_params->session_mpool,
7866                                 ts_params->session_priv_mpool);
7867
7868         if (!ut_params->sec_session) {
7869                 printf("TestCase %s()-%d line %d failed %s: ",
7870                         __func__, i, __LINE__, "Failed to allocate session");
7871                 ret = TEST_FAILED;
7872                 goto on_err;
7873         }
7874
7875         /* Generate crypto op data structure */
7876         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7877                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7878         if (!ut_params->op) {
7879                 printf("TestCase %s()-%d line %d failed %s: ",
7880                         __func__, i, __LINE__,
7881                         "Failed to allocate symmetric crypto operation struct");
7882                 ret = TEST_FAILED;
7883                 goto on_err;
7884         }
7885
7886         uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
7887                                         uint32_t *, IV_OFFSET);
7888         *per_pkt_hfn = packet_direction ? hfn : 0;
7889
7890         rte_security_attach_session(ut_params->op, ut_params->sec_session);
7891
7892         /* set crypto operation source mbuf */
7893         ut_params->op->sym->m_src = ut_params->ibuf;
7894         if (oop)
7895                 ut_params->op->sym->m_dst = ut_params->obuf;
7896
7897         /* Process crypto operation */
7898         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
7899                 == NULL) {
7900                 printf("TestCase %s()-%d line %d failed %s: ",
7901                         __func__, i, __LINE__,
7902                         "failed to process sym crypto op");
7903                 ret = TEST_FAILED;
7904                 goto on_err;
7905         }
7906
7907         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
7908                 printf("TestCase %s()-%d line %d failed %s: ",
7909                         __func__, i, __LINE__, "crypto op processing failed");
7910                 ret = TEST_FAILED;
7911                 goto on_err;
7912         }
7913
7914         /* Validate obuf */
7915         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
7916                         uint8_t *);
7917         if (oop) {
7918                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7919                                 uint8_t *);
7920         }
7921
7922         if (memcmp(ciphertext, output_vec, output_vec_len)) {
7923                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
7924                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
7925                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
7926                 ret = TEST_FAILED;
7927                 goto on_err;
7928         }
7929
7930 on_err:
7931         rte_crypto_op_free(ut_params->op);
7932         ut_params->op = NULL;
7933
7934         if (ut_params->sec_session)
7935                 rte_security_session_destroy(ctx, ut_params->sec_session);
7936         ut_params->sec_session = NULL;
7937
7938         rte_pktmbuf_free(ut_params->ibuf);
7939         ut_params->ibuf = NULL;
7940         if (oop) {
7941                 rte_pktmbuf_free(ut_params->obuf);
7942                 ut_params->obuf = NULL;
7943         }
7944
7945         return ret;
7946 }
7947
7948 static int
7949 test_pdcp_proto_SGL(int i, int oop,
7950         enum rte_crypto_cipher_operation opc,
7951         enum rte_crypto_auth_operation opa,
7952         uint8_t *input_vec,
7953         unsigned int input_vec_len,
7954         uint8_t *output_vec,
7955         unsigned int output_vec_len,
7956         uint32_t fragsz,
7957         uint32_t fragsz_oop)
7958 {
7959         struct crypto_testsuite_params *ts_params = &testsuite_params;
7960         struct crypto_unittest_params *ut_params = &unittest_params;
7961         uint8_t *plaintext;
7962         struct rte_mbuf *buf, *buf_oop = NULL;
7963         int ret = TEST_SUCCESS;
7964         int to_trn = 0;
7965         int to_trn_tbl[16];
7966         int segs = 1;
7967         unsigned int trn_data = 0;
7968         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7969                                 rte_cryptodev_get_sec_ctx(
7970                                 ts_params->valid_devs[0]);
7971
7972         /* Verify the capabilities */
7973         struct rte_security_capability_idx sec_cap_idx;
7974
7975         sec_cap_idx.action = ut_params->type;
7976         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
7977         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
7978         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
7979                 return -ENOTSUP;
7980
7981         if (fragsz > input_vec_len)
7982                 fragsz = input_vec_len;
7983
7984         uint16_t plaintext_len = fragsz;
7985         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
7986
7987         if (fragsz_oop > output_vec_len)
7988                 frag_size_oop = output_vec_len;
7989
7990         int ecx = 0;
7991         if (input_vec_len % fragsz != 0) {
7992                 if (input_vec_len / fragsz + 1 > 16)
7993                         return 1;
7994         } else if (input_vec_len / fragsz > 16)
7995                 return 1;
7996
7997         /* Out of place support */
7998         if (oop) {
7999                 /*
8000                  * For out-op-place we need to alloc another mbuf
8001                  */
8002                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8003                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8004                 buf_oop = ut_params->obuf;
8005         }
8006
8007         /* Generate test mbuf data */
8008         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8009
8010         /* clear mbuf payload */
8011         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8012                         rte_pktmbuf_tailroom(ut_params->ibuf));
8013
8014         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8015                                                   plaintext_len);
8016         memcpy(plaintext, input_vec, plaintext_len);
8017         trn_data += plaintext_len;
8018
8019         buf = ut_params->ibuf;
8020
8021         /*
8022          * Loop until no more fragments
8023          */
8024
8025         while (trn_data < input_vec_len) {
8026                 ++segs;
8027                 to_trn = (input_vec_len - trn_data < fragsz) ?
8028                                 (input_vec_len - trn_data) : fragsz;
8029
8030                 to_trn_tbl[ecx++] = to_trn;
8031
8032                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8033                 buf = buf->next;
8034
8035                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8036                                 rte_pktmbuf_tailroom(buf));
8037
8038                 /* OOP */
8039                 if (oop && !fragsz_oop) {
8040                         buf_oop->next =
8041                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8042                         buf_oop = buf_oop->next;
8043                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8044                                         0, rte_pktmbuf_tailroom(buf_oop));
8045                         rte_pktmbuf_append(buf_oop, to_trn);
8046                 }
8047
8048                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8049                                 to_trn);
8050
8051                 memcpy(plaintext, input_vec + trn_data, to_trn);
8052                 trn_data += to_trn;
8053         }
8054
8055         ut_params->ibuf->nb_segs = segs;
8056
8057         segs = 1;
8058         if (fragsz_oop && oop) {
8059                 to_trn = 0;
8060                 ecx = 0;
8061
8062                 trn_data = frag_size_oop;
8063                 while (trn_data < output_vec_len) {
8064                         ++segs;
8065                         to_trn =
8066                                 (output_vec_len - trn_data <
8067                                                 frag_size_oop) ?
8068                                 (output_vec_len - trn_data) :
8069                                                 frag_size_oop;
8070
8071                         to_trn_tbl[ecx++] = to_trn;
8072
8073                         buf_oop->next =
8074                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
8075                         buf_oop = buf_oop->next;
8076                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8077                                         0, rte_pktmbuf_tailroom(buf_oop));
8078                         rte_pktmbuf_append(buf_oop, to_trn);
8079
8080                         trn_data += to_trn;
8081                 }
8082                 ut_params->obuf->nb_segs = segs;
8083         }
8084
8085         /* Setup Cipher Parameters */
8086         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8087         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8088         ut_params->cipher_xform.cipher.op = opc;
8089         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8090         ut_params->cipher_xform.cipher.key.length =
8091                                         pdcp_test_params[i].cipher_key_len;
8092         ut_params->cipher_xform.cipher.iv.length = 0;
8093
8094         /* Setup HMAC Parameters if ICV header is required */
8095         if (pdcp_test_params[i].auth_alg != 0) {
8096                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8097                 ut_params->auth_xform.next = NULL;
8098                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8099                 ut_params->auth_xform.auth.op = opa;
8100                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8101                 ut_params->auth_xform.auth.key.length =
8102                                         pdcp_test_params[i].auth_key_len;
8103
8104                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8105         } else {
8106                 ut_params->cipher_xform.next = NULL;
8107         }
8108
8109         struct rte_security_session_conf sess_conf = {
8110                 .action_type = ut_params->type,
8111                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8112                 {.pdcp = {
8113                         .bearer = pdcp_test_bearer[i],
8114                         .domain = pdcp_test_params[i].domain,
8115                         .pkt_dir = pdcp_test_packet_direction[i],
8116                         .sn_size = pdcp_test_data_sn_size[i],
8117                         .hfn = pdcp_test_hfn[i],
8118                         .hfn_threshold = pdcp_test_hfn_threshold[i],
8119                         .hfn_ovrd = 0,
8120                 } },
8121                 .crypto_xform = &ut_params->cipher_xform
8122         };
8123
8124         /* Create security session */
8125         ut_params->sec_session = rte_security_session_create(ctx,
8126                                 &sess_conf, ts_params->session_mpool,
8127                                 ts_params->session_priv_mpool);
8128
8129         if (!ut_params->sec_session) {
8130                 printf("TestCase %s()-%d line %d failed %s: ",
8131                         __func__, i, __LINE__, "Failed to allocate session");
8132                 ret = TEST_FAILED;
8133                 goto on_err;
8134         }
8135
8136         /* Generate crypto op data structure */
8137         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8138                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8139         if (!ut_params->op) {
8140                 printf("TestCase %s()-%d line %d failed %s: ",
8141                         __func__, i, __LINE__,
8142                         "Failed to allocate symmetric crypto operation struct");
8143                 ret = TEST_FAILED;
8144                 goto on_err;
8145         }
8146
8147         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8148
8149         /* set crypto operation source mbuf */
8150         ut_params->op->sym->m_src = ut_params->ibuf;
8151         if (oop)
8152                 ut_params->op->sym->m_dst = ut_params->obuf;
8153
8154         /* Process crypto operation */
8155         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8156                 == NULL) {
8157                 printf("TestCase %s()-%d line %d failed %s: ",
8158                         __func__, i, __LINE__,
8159                         "failed to process sym crypto op");
8160                 ret = TEST_FAILED;
8161                 goto on_err;
8162         }
8163
8164         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8165                 printf("TestCase %s()-%d line %d failed %s: ",
8166                         __func__, i, __LINE__, "crypto op processing failed");
8167                 ret = TEST_FAILED;
8168                 goto on_err;
8169         }
8170
8171         /* Validate obuf */
8172         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8173                         uint8_t *);
8174         if (oop) {
8175                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8176                                 uint8_t *);
8177         }
8178         if (fragsz_oop)
8179                 fragsz = frag_size_oop;
8180         if (memcmp(ciphertext, output_vec, fragsz)) {
8181                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8182                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8183                 rte_hexdump(stdout, "reference", output_vec, fragsz);
8184                 ret = TEST_FAILED;
8185                 goto on_err;
8186         }
8187
8188         buf = ut_params->op->sym->m_src->next;
8189         if (oop)
8190                 buf = ut_params->op->sym->m_dst->next;
8191
8192         unsigned int off = fragsz;
8193
8194         ecx = 0;
8195         while (buf) {
8196                 ciphertext = rte_pktmbuf_mtod(buf,
8197                                 uint8_t *);
8198                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8199                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8200                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8201                         rte_hexdump(stdout, "reference", output_vec + off,
8202                                         to_trn_tbl[ecx]);
8203                         ret = TEST_FAILED;
8204                         goto on_err;
8205                 }
8206                 off += to_trn_tbl[ecx++];
8207                 buf = buf->next;
8208         }
8209 on_err:
8210         rte_crypto_op_free(ut_params->op);
8211         ut_params->op = NULL;
8212
8213         if (ut_params->sec_session)
8214                 rte_security_session_destroy(ctx, ut_params->sec_session);
8215         ut_params->sec_session = NULL;
8216
8217         rte_pktmbuf_free(ut_params->ibuf);
8218         ut_params->ibuf = NULL;
8219         if (oop) {
8220                 rte_pktmbuf_free(ut_params->obuf);
8221                 ut_params->obuf = NULL;
8222         }
8223
8224         return ret;
8225 }
8226
8227 int
8228 test_pdcp_proto_cplane_encap(int i)
8229 {
8230         return test_pdcp_proto(
8231                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8232                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8233                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8234                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8235                 pdcp_test_params[i].cipher_key_len,
8236                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8237                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8238                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8239                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8240                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8241 }
8242
8243 int
8244 test_pdcp_proto_uplane_encap(int i)
8245 {
8246         return test_pdcp_proto(
8247                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8248                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8249                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8250                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8251                 pdcp_test_params[i].cipher_key_len,
8252                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8253                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8254                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8255                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8256                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8257 }
8258
8259 int
8260 test_pdcp_proto_uplane_encap_with_int(int i)
8261 {
8262         return test_pdcp_proto(
8263                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8264                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8265                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8266                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8267                 pdcp_test_params[i].cipher_key_len,
8268                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8269                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8270                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8271                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8272                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8273 }
8274
8275 int
8276 test_pdcp_proto_cplane_decap(int i)
8277 {
8278         return test_pdcp_proto(
8279                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8280                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8281                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8282                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8283                 pdcp_test_params[i].cipher_key_len,
8284                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8285                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8286                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8287                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8288                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8289 }
8290
8291 int
8292 test_pdcp_proto_uplane_decap(int i)
8293 {
8294         return test_pdcp_proto(
8295                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8296                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8297                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8298                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8299                 pdcp_test_params[i].cipher_key_len,
8300                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8301                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8302                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8303                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8304                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8305 }
8306
8307 int
8308 test_pdcp_proto_uplane_decap_with_int(int i)
8309 {
8310         return test_pdcp_proto(
8311                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8312                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8313                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8314                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8315                 pdcp_test_params[i].cipher_key_len,
8316                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8317                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8318                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8319                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8320                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8321 }
8322
8323 static int
8324 test_PDCP_PROTO_SGL_in_place_32B(void)
8325 {
8326         /* i can be used for running any PDCP case
8327          * In this case it is uplane 12-bit AES-SNOW DL encap
8328          */
8329         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8330         return test_pdcp_proto_SGL(i, IN_PLACE,
8331                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8332                         RTE_CRYPTO_AUTH_OP_GENERATE,
8333                         pdcp_test_data_in[i],
8334                         pdcp_test_data_in_len[i],
8335                         pdcp_test_data_out[i],
8336                         pdcp_test_data_in_len[i]+4,
8337                         32, 0);
8338 }
8339 static int
8340 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8341 {
8342         /* i can be used for running any PDCP case
8343          * In this case it is uplane 18-bit NULL-NULL DL encap
8344          */
8345         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8346         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8347                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8348                         RTE_CRYPTO_AUTH_OP_GENERATE,
8349                         pdcp_test_data_in[i],
8350                         pdcp_test_data_in_len[i],
8351                         pdcp_test_data_out[i],
8352                         pdcp_test_data_in_len[i]+4,
8353                         32, 128);
8354 }
8355 static int
8356 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8357 {
8358         /* i can be used for running any PDCP case
8359          * In this case it is uplane 18-bit AES DL encap
8360          */
8361         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8362                         + DOWNLINK;
8363         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8364                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8365                         RTE_CRYPTO_AUTH_OP_GENERATE,
8366                         pdcp_test_data_in[i],
8367                         pdcp_test_data_in_len[i],
8368                         pdcp_test_data_out[i],
8369                         pdcp_test_data_in_len[i],
8370                         32, 40);
8371 }
8372 static int
8373 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8374 {
8375         /* i can be used for running any PDCP case
8376          * In this case it is cplane 12-bit AES-ZUC DL encap
8377          */
8378         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8379         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8380                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8381                         RTE_CRYPTO_AUTH_OP_GENERATE,
8382                         pdcp_test_data_in[i],
8383                         pdcp_test_data_in_len[i],
8384                         pdcp_test_data_out[i],
8385                         pdcp_test_data_in_len[i]+4,
8386                         128, 32);
8387 }
8388
8389 static int
8390 test_PDCP_SDAP_PROTO_encap_all(void)
8391 {
8392         int i = 0, size = 0;
8393         int err, all_err = TEST_SUCCESS;
8394         const struct pdcp_sdap_test *cur_test;
8395
8396         size = ARRAY_SIZE(list_pdcp_sdap_tests);
8397
8398         for (i = 0; i < size; i++) {
8399                 cur_test = &list_pdcp_sdap_tests[i];
8400                 err = test_pdcp_proto(
8401                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8402                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8403                         cur_test->in_len, cur_test->data_out,
8404                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8405                         cur_test->param.cipher_alg, cur_test->cipher_key,
8406                         cur_test->param.cipher_key_len,
8407                         cur_test->param.auth_alg,
8408                         cur_test->auth_key, cur_test->param.auth_key_len,
8409                         cur_test->bearer, cur_test->param.domain,
8410                         cur_test->packet_direction, cur_test->sn_size,
8411                         cur_test->hfn,
8412                         cur_test->hfn_threshold, SDAP_ENABLED);
8413                 if (err) {
8414                         printf("\t%d) %s: Encapsulation failed\n",
8415                                         cur_test->test_idx,
8416                                         cur_test->param.name);
8417                         err = TEST_FAILED;
8418                 } else {
8419                         printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8420                                         cur_test->param.name);
8421                         err = TEST_SUCCESS;
8422                 }
8423                 all_err += err;
8424         }
8425
8426         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8427
8428         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8429 }
8430
8431 static int
8432 test_PDCP_SDAP_PROTO_decap_all(void)
8433 {
8434         int i = 0, size = 0;
8435         int err, all_err = TEST_SUCCESS;
8436         const struct pdcp_sdap_test *cur_test;
8437
8438         size = ARRAY_SIZE(list_pdcp_sdap_tests);
8439
8440         for (i = 0; i < size; i++) {
8441                 cur_test = &list_pdcp_sdap_tests[i];
8442                 err = test_pdcp_proto(
8443                         i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8444                         RTE_CRYPTO_AUTH_OP_VERIFY,
8445                         cur_test->data_out,
8446                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8447                         cur_test->data_in, cur_test->in_len,
8448                         cur_test->param.cipher_alg,
8449                         cur_test->cipher_key, cur_test->param.cipher_key_len,
8450                         cur_test->param.auth_alg, cur_test->auth_key,
8451                         cur_test->param.auth_key_len, cur_test->bearer,
8452                         cur_test->param.domain, cur_test->packet_direction,
8453                         cur_test->sn_size, cur_test->hfn,
8454                         cur_test->hfn_threshold, SDAP_ENABLED);
8455                 if (err) {
8456                         printf("\t%d) %s: Decapsulation failed\n",
8457                                         cur_test->test_idx,
8458                                         cur_test->param.name);
8459                         err = TEST_FAILED;
8460                 } else {
8461                         printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8462                                         cur_test->param.name);
8463                         err = TEST_SUCCESS;
8464                 }
8465                 all_err += err;
8466         }
8467
8468         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8469
8470         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8471 }
8472
8473 static int
8474 test_PDCP_PROTO_all(void)
8475 {
8476         struct crypto_testsuite_params *ts_params = &testsuite_params;
8477         struct crypto_unittest_params *ut_params = &unittest_params;
8478         struct rte_cryptodev_info dev_info;
8479         int status;
8480
8481         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8482         uint64_t feat_flags = dev_info.feature_flags;
8483
8484         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8485                 return -ENOTSUP;
8486
8487         /* Set action type */
8488         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8489                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8490                 gbl_action_type;
8491
8492         if (security_proto_supported(ut_params->type,
8493                         RTE_SECURITY_PROTOCOL_PDCP) < 0)
8494                 return -ENOTSUP;
8495
8496         status = test_PDCP_PROTO_cplane_encap_all();
8497         status += test_PDCP_PROTO_cplane_decap_all();
8498         status += test_PDCP_PROTO_uplane_encap_all();
8499         status += test_PDCP_PROTO_uplane_decap_all();
8500         status += test_PDCP_PROTO_SGL_in_place_32B();
8501         status += test_PDCP_PROTO_SGL_oop_32B_128B();
8502         status += test_PDCP_PROTO_SGL_oop_32B_40B();
8503         status += test_PDCP_PROTO_SGL_oop_128B_32B();
8504         status += test_PDCP_SDAP_PROTO_encap_all();
8505         status += test_PDCP_SDAP_PROTO_decap_all();
8506
8507         if (status)
8508                 return TEST_FAILED;
8509         else
8510                 return TEST_SUCCESS;
8511 }
8512
8513 static int
8514 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
8515 {
8516         struct crypto_testsuite_params *ts_params = &testsuite_params;
8517         struct crypto_unittest_params *ut_params = &unittest_params;
8518         uint8_t *plaintext, *ciphertext;
8519         uint8_t *iv_ptr;
8520         int32_t cipher_len, crc_len;
8521         uint32_t crc_data_len;
8522         int ret = TEST_SUCCESS;
8523
8524         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8525                                         rte_cryptodev_get_sec_ctx(
8526                                                 ts_params->valid_devs[0]);
8527
8528         /* Verify the capabilities */
8529         struct rte_security_capability_idx sec_cap_idx;
8530         const struct rte_security_capability *sec_cap;
8531         const struct rte_cryptodev_capabilities *crypto_cap;
8532         const struct rte_cryptodev_symmetric_capability *sym_cap;
8533         int j = 0;
8534
8535         sec_cap_idx.action = ut_params->type;
8536         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8537         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
8538
8539         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8540         if (sec_cap == NULL)
8541                 return -ENOTSUP;
8542
8543         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8544                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8545                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8546                                 crypto_cap->sym.xform_type ==
8547                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
8548                                 crypto_cap->sym.cipher.algo ==
8549                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8550                         sym_cap = &crypto_cap->sym;
8551                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8552                                                 d_td->key.len,
8553                                                 d_td->iv.len) == 0)
8554                                 break;
8555                 }
8556         }
8557
8558         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8559                 return -ENOTSUP;
8560
8561         /* Setup source mbuf payload */
8562         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8563         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8564                         rte_pktmbuf_tailroom(ut_params->ibuf));
8565
8566         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8567                         d_td->ciphertext.len);
8568
8569         memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
8570
8571         /* Setup cipher session parameters */
8572         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8573         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8574         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
8575         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8576         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8577         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8578         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8579         ut_params->cipher_xform.next = NULL;
8580
8581         /* Setup DOCSIS session parameters */
8582         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
8583
8584         struct rte_security_session_conf sess_conf = {
8585                 .action_type = ut_params->type,
8586                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8587                 .docsis = ut_params->docsis_xform,
8588                 .crypto_xform = &ut_params->cipher_xform,
8589         };
8590
8591         /* Create security session */
8592         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
8593                                         ts_params->session_mpool,
8594                                         ts_params->session_priv_mpool);
8595
8596         if (!ut_params->sec_session) {
8597                 printf("TestCase %s(%d) line %d: %s\n",
8598                         __func__, i, __LINE__, "failed to allocate session");
8599                 ret = TEST_FAILED;
8600                 goto on_err;
8601         }
8602
8603         /* Generate crypto op data structure */
8604         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8605                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8606         if (!ut_params->op) {
8607                 printf("TestCase %s(%d) line %d: %s\n",
8608                         __func__, i, __LINE__,
8609                         "failed to allocate symmetric crypto operation");
8610                 ret = TEST_FAILED;
8611                 goto on_err;
8612         }
8613
8614         /* Setup CRC operation parameters */
8615         crc_len = d_td->ciphertext.no_crc == false ?
8616                         (d_td->ciphertext.len -
8617                                 d_td->ciphertext.crc_offset -
8618                                 RTE_ETHER_CRC_LEN) :
8619                         0;
8620         crc_len = crc_len > 0 ? crc_len : 0;
8621         crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
8622         ut_params->op->sym->auth.data.length = crc_len;
8623         ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
8624
8625         /* Setup cipher operation parameters */
8626         cipher_len = d_td->ciphertext.no_cipher == false ?
8627                         (d_td->ciphertext.len -
8628                                 d_td->ciphertext.cipher_offset) :
8629                         0;
8630         cipher_len = cipher_len > 0 ? cipher_len : 0;
8631         ut_params->op->sym->cipher.data.length = cipher_len;
8632         ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
8633
8634         /* Setup cipher IV */
8635         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
8636         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
8637
8638         /* Attach session to operation */
8639         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8640
8641         /* Set crypto operation mbufs */
8642         ut_params->op->sym->m_src = ut_params->ibuf;
8643         ut_params->op->sym->m_dst = NULL;
8644
8645         /* Process crypto operation */
8646         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
8647                         NULL) {
8648                 printf("TestCase %s(%d) line %d: %s\n",
8649                         __func__, i, __LINE__,
8650                         "failed to process security crypto op");
8651                 ret = TEST_FAILED;
8652                 goto on_err;
8653         }
8654
8655         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8656                 printf("TestCase %s(%d) line %d: %s\n",
8657                         __func__, i, __LINE__, "crypto op processing failed");
8658                 ret = TEST_FAILED;
8659                 goto on_err;
8660         }
8661
8662         /* Validate plaintext */
8663         plaintext = ciphertext;
8664
8665         if (memcmp(plaintext, d_td->plaintext.data,
8666                         d_td->plaintext.len - crc_data_len)) {
8667                 printf("TestCase %s(%d) line %d: %s\n",
8668                         __func__, i, __LINE__, "plaintext not as expected\n");
8669                 rte_hexdump(stdout, "expected", d_td->plaintext.data,
8670                                 d_td->plaintext.len);
8671                 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
8672                 ret = TEST_FAILED;
8673                 goto on_err;
8674         }
8675
8676 on_err:
8677         rte_crypto_op_free(ut_params->op);
8678         ut_params->op = NULL;
8679
8680         if (ut_params->sec_session)
8681                 rte_security_session_destroy(ctx, ut_params->sec_session);
8682         ut_params->sec_session = NULL;
8683
8684         rte_pktmbuf_free(ut_params->ibuf);
8685         ut_params->ibuf = NULL;
8686
8687         return ret;
8688 }
8689
8690 static int
8691 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
8692 {
8693         struct crypto_testsuite_params *ts_params = &testsuite_params;
8694         struct crypto_unittest_params *ut_params = &unittest_params;
8695         uint8_t *plaintext, *ciphertext;
8696         uint8_t *iv_ptr;
8697         int32_t cipher_len, crc_len;
8698         int ret = TEST_SUCCESS;
8699
8700         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8701                                         rte_cryptodev_get_sec_ctx(
8702                                                 ts_params->valid_devs[0]);
8703
8704         /* Verify the capabilities */
8705         struct rte_security_capability_idx sec_cap_idx;
8706         const struct rte_security_capability *sec_cap;
8707         const struct rte_cryptodev_capabilities *crypto_cap;
8708         const struct rte_cryptodev_symmetric_capability *sym_cap;
8709         int j = 0;
8710
8711         sec_cap_idx.action = ut_params->type;
8712         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8713         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
8714
8715         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8716         if (sec_cap == NULL)
8717                 return -ENOTSUP;
8718
8719         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8720                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8721                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8722                                 crypto_cap->sym.xform_type ==
8723                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
8724                                 crypto_cap->sym.cipher.algo ==
8725                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8726                         sym_cap = &crypto_cap->sym;
8727                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8728                                                 d_td->key.len,
8729                                                 d_td->iv.len) == 0)
8730                                 break;
8731                 }
8732         }
8733
8734         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8735                 return -ENOTSUP;
8736
8737         /* Setup source mbuf payload */
8738         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8739         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8740                         rte_pktmbuf_tailroom(ut_params->ibuf));
8741
8742         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8743                         d_td->plaintext.len);
8744
8745         memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
8746
8747         /* Setup cipher session parameters */
8748         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8749         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8750         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
8751         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8752         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8753         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8754         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8755         ut_params->cipher_xform.next = NULL;
8756
8757         /* Setup DOCSIS session parameters */
8758         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
8759
8760         struct rte_security_session_conf sess_conf = {
8761                 .action_type = ut_params->type,
8762                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8763                 .docsis = ut_params->docsis_xform,
8764                 .crypto_xform = &ut_params->cipher_xform,
8765         };
8766
8767         /* Create security session */
8768         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
8769                                         ts_params->session_mpool,
8770                                         ts_params->session_priv_mpool);
8771
8772         if (!ut_params->sec_session) {
8773                 printf("TestCase %s(%d) line %d: %s\n",
8774                         __func__, i, __LINE__, "failed to allocate session");
8775                 ret = TEST_FAILED;
8776                 goto on_err;
8777         }
8778
8779         /* Generate crypto op data structure */
8780         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8781                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8782         if (!ut_params->op) {
8783                 printf("TestCase %s(%d) line %d: %s\n",
8784                         __func__, i, __LINE__,
8785                         "failed to allocate security crypto operation");
8786                 ret = TEST_FAILED;
8787                 goto on_err;
8788         }
8789
8790         /* Setup CRC operation parameters */
8791         crc_len = d_td->plaintext.no_crc == false ?
8792                         (d_td->plaintext.len -
8793                                 d_td->plaintext.crc_offset -
8794                                 RTE_ETHER_CRC_LEN) :
8795                         0;
8796         crc_len = crc_len > 0 ? crc_len : 0;
8797         ut_params->op->sym->auth.data.length = crc_len;
8798         ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
8799
8800         /* Setup cipher operation parameters */
8801         cipher_len = d_td->plaintext.no_cipher == false ?
8802                         (d_td->plaintext.len -
8803                                 d_td->plaintext.cipher_offset) :
8804                         0;
8805         cipher_len = cipher_len > 0 ? cipher_len : 0;
8806         ut_params->op->sym->cipher.data.length = cipher_len;
8807         ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
8808
8809         /* Setup cipher IV */
8810         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
8811         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
8812
8813         /* Attach session to operation */
8814         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8815
8816         /* Set crypto operation mbufs */
8817         ut_params->op->sym->m_src = ut_params->ibuf;
8818         ut_params->op->sym->m_dst = NULL;
8819
8820         /* Process crypto operation */
8821         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
8822                         NULL) {
8823                 printf("TestCase %s(%d) line %d: %s\n",
8824                         __func__, i, __LINE__,
8825                         "failed to process security crypto op");
8826                 ret = TEST_FAILED;
8827                 goto on_err;
8828         }
8829
8830         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8831                 printf("TestCase %s(%d) line %d: %s\n",
8832                         __func__, i, __LINE__, "crypto op processing failed");
8833                 ret = TEST_FAILED;
8834                 goto on_err;
8835         }
8836
8837         /* Validate ciphertext */
8838         ciphertext = plaintext;
8839
8840         if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
8841                 printf("TestCase %s(%d) line %d: %s\n",
8842                         __func__, i, __LINE__, "ciphertext not as expected\n");
8843                 rte_hexdump(stdout, "expected", d_td->ciphertext.data,
8844                                 d_td->ciphertext.len);
8845                 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
8846                 ret = TEST_FAILED;
8847                 goto on_err;
8848         }
8849
8850 on_err:
8851         rte_crypto_op_free(ut_params->op);
8852         ut_params->op = NULL;
8853
8854         if (ut_params->sec_session)
8855                 rte_security_session_destroy(ctx, ut_params->sec_session);
8856         ut_params->sec_session = NULL;
8857
8858         rte_pktmbuf_free(ut_params->ibuf);
8859         ut_params->ibuf = NULL;
8860
8861         return ret;
8862 }
8863
8864 #define TEST_DOCSIS_COUNT(func) do {                    \
8865         int ret = func;                                 \
8866         if (ret == TEST_SUCCESS)  {                     \
8867                 printf("\t%2d)", n++);                  \
8868                 printf("+++++ PASSED:" #func"\n");      \
8869                 p++;                                    \
8870         } else if (ret == -ENOTSUP) {                   \
8871                 printf("\t%2d)", n++);                  \
8872                 printf("~~~~~ UNSUPP:" #func"\n");      \
8873                 u++;                                    \
8874         } else {                                        \
8875                 printf("\t%2d)", n++);                  \
8876                 printf("----- FAILED:" #func"\n");      \
8877                 f++;                                    \
8878         }                                               \
8879 } while (0)
8880
8881 static int
8882 test_DOCSIS_PROTO_uplink_all(void)
8883 {
8884         int p = 0, u = 0, f = 0, n = 0;
8885
8886         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
8887         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
8888         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
8889         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
8890         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
8891         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
8892         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
8893         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
8894         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
8895         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
8896         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
8897         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
8898         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
8899         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
8900         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
8901         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
8902         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
8903         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
8904         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
8905         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
8906         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
8907         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
8908         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
8909         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
8910         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
8911         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
8912
8913         if (f)
8914                 printf("## %s: %d passed out of %d (%d unsupported)\n",
8915                         __func__, p, n, u);
8916
8917         return f;
8918 };
8919
8920 static int
8921 test_DOCSIS_PROTO_downlink_all(void)
8922 {
8923         int p = 0, u = 0, f = 0, n = 0;
8924
8925         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
8926         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
8927         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
8928         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
8929         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
8930         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
8931         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
8932         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
8933         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
8934         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
8935         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
8936         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
8937         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
8938         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
8939         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
8940         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
8941         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
8942         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
8943         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
8944         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
8945         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
8946         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
8947         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
8948         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
8949         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
8950         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
8951
8952         if (f)
8953                 printf("## %s: %d passed out of %d (%d unsupported)\n",
8954                         __func__, p, n, u);
8955
8956         return f;
8957 };
8958
8959 static int
8960 test_DOCSIS_PROTO_all(void)
8961 {
8962         struct crypto_testsuite_params *ts_params = &testsuite_params;
8963         struct crypto_unittest_params *ut_params = &unittest_params;
8964         struct rte_cryptodev_info dev_info;
8965         int status;
8966
8967         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8968         uint64_t feat_flags = dev_info.feature_flags;
8969
8970         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8971                 return -ENOTSUP;
8972
8973         /* Set action type */
8974         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8975                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8976                 gbl_action_type;
8977
8978         if (security_proto_supported(ut_params->type,
8979                         RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
8980                 return -ENOTSUP;
8981
8982         status = test_DOCSIS_PROTO_uplink_all();
8983         status += test_DOCSIS_PROTO_downlink_all();
8984
8985         if (status)
8986                 return TEST_FAILED;
8987         else
8988                 return TEST_SUCCESS;
8989 }
8990 #endif
8991
8992 static int
8993 test_AES_GCM_authenticated_encryption_test_case_1(void)
8994 {
8995         return test_authenticated_encryption(&gcm_test_case_1);
8996 }
8997
8998 static int
8999 test_AES_GCM_authenticated_encryption_test_case_2(void)
9000 {
9001         return test_authenticated_encryption(&gcm_test_case_2);
9002 }
9003
9004 static int
9005 test_AES_GCM_authenticated_encryption_test_case_3(void)
9006 {
9007         return test_authenticated_encryption(&gcm_test_case_3);
9008 }
9009
9010 static int
9011 test_AES_GCM_authenticated_encryption_test_case_4(void)
9012 {
9013         return test_authenticated_encryption(&gcm_test_case_4);
9014 }
9015
9016 static int
9017 test_AES_GCM_authenticated_encryption_test_case_5(void)
9018 {
9019         return test_authenticated_encryption(&gcm_test_case_5);
9020 }
9021
9022 static int
9023 test_AES_GCM_authenticated_encryption_test_case_6(void)
9024 {
9025         return test_authenticated_encryption(&gcm_test_case_6);
9026 }
9027
9028 static int
9029 test_AES_GCM_authenticated_encryption_test_case_7(void)
9030 {
9031         return test_authenticated_encryption(&gcm_test_case_7);
9032 }
9033
9034 static int
9035 test_AES_GCM_authenticated_encryption_test_case_8(void)
9036 {
9037         return test_authenticated_encryption(&gcm_test_case_8);
9038 }
9039
9040 static int
9041 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9042 {
9043         return test_authenticated_encryption(&gcm_J0_test_case_1);
9044 }
9045
9046 static int
9047 test_AES_GCM_auth_encryption_test_case_192_1(void)
9048 {
9049         return test_authenticated_encryption(&gcm_test_case_192_1);
9050 }
9051
9052 static int
9053 test_AES_GCM_auth_encryption_test_case_192_2(void)
9054 {
9055         return test_authenticated_encryption(&gcm_test_case_192_2);
9056 }
9057
9058 static int
9059 test_AES_GCM_auth_encryption_test_case_192_3(void)
9060 {
9061         return test_authenticated_encryption(&gcm_test_case_192_3);
9062 }
9063
9064 static int
9065 test_AES_GCM_auth_encryption_test_case_192_4(void)
9066 {
9067         return test_authenticated_encryption(&gcm_test_case_192_4);
9068 }
9069
9070 static int
9071 test_AES_GCM_auth_encryption_test_case_192_5(void)
9072 {
9073         return test_authenticated_encryption(&gcm_test_case_192_5);
9074 }
9075
9076 static int
9077 test_AES_GCM_auth_encryption_test_case_192_6(void)
9078 {
9079         return test_authenticated_encryption(&gcm_test_case_192_6);
9080 }
9081
9082 static int
9083 test_AES_GCM_auth_encryption_test_case_192_7(void)
9084 {
9085         return test_authenticated_encryption(&gcm_test_case_192_7);
9086 }
9087
9088 static int
9089 test_AES_GCM_auth_encryption_test_case_256_1(void)
9090 {
9091         return test_authenticated_encryption(&gcm_test_case_256_1);
9092 }
9093
9094 static int
9095 test_AES_GCM_auth_encryption_test_case_256_2(void)
9096 {
9097         return test_authenticated_encryption(&gcm_test_case_256_2);
9098 }
9099
9100 static int
9101 test_AES_GCM_auth_encryption_test_case_256_3(void)
9102 {
9103         return test_authenticated_encryption(&gcm_test_case_256_3);
9104 }
9105
9106 static int
9107 test_AES_GCM_auth_encryption_test_case_256_4(void)
9108 {
9109         return test_authenticated_encryption(&gcm_test_case_256_4);
9110 }
9111
9112 static int
9113 test_AES_GCM_auth_encryption_test_case_256_5(void)
9114 {
9115         return test_authenticated_encryption(&gcm_test_case_256_5);
9116 }
9117
9118 static int
9119 test_AES_GCM_auth_encryption_test_case_256_6(void)
9120 {
9121         return test_authenticated_encryption(&gcm_test_case_256_6);
9122 }
9123
9124 static int
9125 test_AES_GCM_auth_encryption_test_case_256_7(void)
9126 {
9127         return test_authenticated_encryption(&gcm_test_case_256_7);
9128 }
9129
9130 static int
9131 test_AES_GCM_auth_encryption_test_case_aad_1(void)
9132 {
9133         return test_authenticated_encryption(&gcm_test_case_aad_1);
9134 }
9135
9136 static int
9137 test_AES_GCM_auth_encryption_test_case_aad_2(void)
9138 {
9139         return test_authenticated_encryption(&gcm_test_case_aad_2);
9140 }
9141
9142 static int
9143 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
9144 {
9145         struct aead_test_data tdata;
9146         int res;
9147
9148         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9149         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9150         tdata.iv.data[0] += 1;
9151         res = test_authenticated_encryption(&tdata);
9152         if (res == -ENOTSUP)
9153                 return res;
9154         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9155         return TEST_SUCCESS;
9156 }
9157
9158 static int
9159 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
9160 {
9161         struct aead_test_data tdata;
9162         int res;
9163
9164         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9165         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9166         tdata.plaintext.data[0] += 1;
9167         res = test_authenticated_encryption(&tdata);
9168         if (res == -ENOTSUP)
9169                 return res;
9170         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9171         return TEST_SUCCESS;
9172 }
9173
9174 static int
9175 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
9176 {
9177         struct aead_test_data tdata;
9178         int res;
9179
9180         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9181         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9182         tdata.ciphertext.data[0] += 1;
9183         res = test_authenticated_encryption(&tdata);
9184         if (res == -ENOTSUP)
9185                 return res;
9186         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9187         return TEST_SUCCESS;
9188 }
9189
9190 static int
9191 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
9192 {
9193         struct aead_test_data tdata;
9194         int res;
9195
9196         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9197         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9198         tdata.aad.len += 1;
9199         res = test_authenticated_encryption(&tdata);
9200         if (res == -ENOTSUP)
9201                 return res;
9202         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9203         return TEST_SUCCESS;
9204 }
9205
9206 static int
9207 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
9208 {
9209         struct aead_test_data tdata;
9210         uint8_t aad[gcm_test_case_7.aad.len];
9211         int res;
9212
9213         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9214         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9215         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9216         aad[0] += 1;
9217         tdata.aad.data = aad;
9218         res = test_authenticated_encryption(&tdata);
9219         if (res == -ENOTSUP)
9220                 return res;
9221         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9222         return TEST_SUCCESS;
9223 }
9224
9225 static int
9226 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
9227 {
9228         struct aead_test_data tdata;
9229         int res;
9230
9231         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9232         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9233         tdata.auth_tag.data[0] += 1;
9234         res = test_authenticated_encryption(&tdata);
9235         if (res == -ENOTSUP)
9236                 return res;
9237         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9238         return TEST_SUCCESS;
9239 }
9240
9241 static int
9242 test_authenticated_decryption(const struct aead_test_data *tdata)
9243 {
9244         struct crypto_testsuite_params *ts_params = &testsuite_params;
9245         struct crypto_unittest_params *ut_params = &unittest_params;
9246
9247         int retval;
9248         uint8_t *plaintext;
9249         uint32_t i;
9250         struct rte_cryptodev_info dev_info;
9251
9252         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9253         uint64_t feat_flags = dev_info.feature_flags;
9254
9255         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9256                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9257                 printf("Device doesn't support RAW data-path APIs.\n");
9258                 return -ENOTSUP;
9259         }
9260
9261         /* Verify the capabilities */
9262         struct rte_cryptodev_sym_capability_idx cap_idx;
9263         const struct rte_cryptodev_symmetric_capability *capability;
9264         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9265         cap_idx.algo.aead = tdata->algo;
9266         capability = rte_cryptodev_sym_capability_get(
9267                         ts_params->valid_devs[0], &cap_idx);
9268         if (capability == NULL)
9269                 return -ENOTSUP;
9270         if (rte_cryptodev_sym_capability_check_aead(
9271                         capability, tdata->key.len, tdata->auth_tag.len,
9272                         tdata->aad.len, tdata->iv.len))
9273                 return -ENOTSUP;
9274
9275         /* Create AEAD session */
9276         retval = create_aead_session(ts_params->valid_devs[0],
9277                         tdata->algo,
9278                         RTE_CRYPTO_AEAD_OP_DECRYPT,
9279                         tdata->key.data, tdata->key.len,
9280                         tdata->aad.len, tdata->auth_tag.len,
9281                         tdata->iv.len);
9282         if (retval < 0)
9283                 return retval;
9284
9285         /* alloc mbuf and set payload */
9286         if (tdata->aad.len > MBUF_SIZE) {
9287                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9288                 /* Populate full size of add data */
9289                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
9290                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
9291         } else
9292                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9293
9294         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9295                         rte_pktmbuf_tailroom(ut_params->ibuf));
9296
9297         /* Create AEAD operation */
9298         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9299         if (retval < 0)
9300                 return retval;
9301
9302         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9303
9304         ut_params->op->sym->m_src = ut_params->ibuf;
9305
9306         /* Process crypto operation */
9307         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9308                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
9309         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9310                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9311                                 ut_params->op, 0, 0, 0, 0);
9312         else
9313                 TEST_ASSERT_NOT_NULL(
9314                         process_crypto_request(ts_params->valid_devs[0],
9315                         ut_params->op), "failed to process sym crypto op");
9316
9317         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9318                         "crypto op processing failed");
9319
9320         if (ut_params->op->sym->m_dst)
9321                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9322                                 uint8_t *);
9323         else
9324                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
9325                                 uint8_t *,
9326                                 ut_params->op->sym->cipher.data.offset);
9327
9328         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9329
9330         /* Validate obuf */
9331         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9332                         plaintext,
9333                         tdata->plaintext.data,
9334                         tdata->plaintext.len,
9335                         "Plaintext data not as expected");
9336
9337         TEST_ASSERT_EQUAL(ut_params->op->status,
9338                         RTE_CRYPTO_OP_STATUS_SUCCESS,
9339                         "Authentication failed");
9340
9341         return 0;
9342 }
9343
9344 static int
9345 test_AES_GCM_authenticated_decryption_test_case_1(void)
9346 {
9347         return test_authenticated_decryption(&gcm_test_case_1);
9348 }
9349
9350 static int
9351 test_AES_GCM_authenticated_decryption_test_case_2(void)
9352 {
9353         return test_authenticated_decryption(&gcm_test_case_2);
9354 }
9355
9356 static int
9357 test_AES_GCM_authenticated_decryption_test_case_3(void)
9358 {
9359         return test_authenticated_decryption(&gcm_test_case_3);
9360 }
9361
9362 static int
9363 test_AES_GCM_authenticated_decryption_test_case_4(void)
9364 {
9365         return test_authenticated_decryption(&gcm_test_case_4);
9366 }
9367
9368 static int
9369 test_AES_GCM_authenticated_decryption_test_case_5(void)
9370 {
9371         return test_authenticated_decryption(&gcm_test_case_5);
9372 }
9373
9374 static int
9375 test_AES_GCM_authenticated_decryption_test_case_6(void)
9376 {
9377         return test_authenticated_decryption(&gcm_test_case_6);
9378 }
9379
9380 static int
9381 test_AES_GCM_authenticated_decryption_test_case_7(void)
9382 {
9383         return test_authenticated_decryption(&gcm_test_case_7);
9384 }
9385
9386 static int
9387 test_AES_GCM_authenticated_decryption_test_case_8(void)
9388 {
9389         return test_authenticated_decryption(&gcm_test_case_8);
9390 }
9391
9392 static int
9393 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
9394 {
9395         return test_authenticated_decryption(&gcm_J0_test_case_1);
9396 }
9397
9398 static int
9399 test_AES_GCM_auth_decryption_test_case_192_1(void)
9400 {
9401         return test_authenticated_decryption(&gcm_test_case_192_1);
9402 }
9403
9404 static int
9405 test_AES_GCM_auth_decryption_test_case_192_2(void)
9406 {
9407         return test_authenticated_decryption(&gcm_test_case_192_2);
9408 }
9409
9410 static int
9411 test_AES_GCM_auth_decryption_test_case_192_3(void)
9412 {
9413         return test_authenticated_decryption(&gcm_test_case_192_3);
9414 }
9415
9416 static int
9417 test_AES_GCM_auth_decryption_test_case_192_4(void)
9418 {
9419         return test_authenticated_decryption(&gcm_test_case_192_4);
9420 }
9421
9422 static int
9423 test_AES_GCM_auth_decryption_test_case_192_5(void)
9424 {
9425         return test_authenticated_decryption(&gcm_test_case_192_5);
9426 }
9427
9428 static int
9429 test_AES_GCM_auth_decryption_test_case_192_6(void)
9430 {
9431         return test_authenticated_decryption(&gcm_test_case_192_6);
9432 }
9433
9434 static int
9435 test_AES_GCM_auth_decryption_test_case_192_7(void)
9436 {
9437         return test_authenticated_decryption(&gcm_test_case_192_7);
9438 }
9439
9440 static int
9441 test_AES_GCM_auth_decryption_test_case_256_1(void)
9442 {
9443         return test_authenticated_decryption(&gcm_test_case_256_1);
9444 }
9445
9446 static int
9447 test_AES_GCM_auth_decryption_test_case_256_2(void)
9448 {
9449         return test_authenticated_decryption(&gcm_test_case_256_2);
9450 }
9451
9452 static int
9453 test_AES_GCM_auth_decryption_test_case_256_3(void)
9454 {
9455         return test_authenticated_decryption(&gcm_test_case_256_3);
9456 }
9457
9458 static int
9459 test_AES_GCM_auth_decryption_test_case_256_4(void)
9460 {
9461         return test_authenticated_decryption(&gcm_test_case_256_4);
9462 }
9463
9464 static int
9465 test_AES_GCM_auth_decryption_test_case_256_5(void)
9466 {
9467         return test_authenticated_decryption(&gcm_test_case_256_5);
9468 }
9469
9470 static int
9471 test_AES_GCM_auth_decryption_test_case_256_6(void)
9472 {
9473         return test_authenticated_decryption(&gcm_test_case_256_6);
9474 }
9475
9476 static int
9477 test_AES_GCM_auth_decryption_test_case_256_7(void)
9478 {
9479         return test_authenticated_decryption(&gcm_test_case_256_7);
9480 }
9481
9482 static int
9483 test_AES_GCM_auth_decryption_test_case_aad_1(void)
9484 {
9485         return test_authenticated_decryption(&gcm_test_case_aad_1);
9486 }
9487
9488 static int
9489 test_AES_GCM_auth_decryption_test_case_aad_2(void)
9490 {
9491         return test_authenticated_decryption(&gcm_test_case_aad_2);
9492 }
9493
9494 static int
9495 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
9496 {
9497         struct aead_test_data tdata;
9498         int res;
9499
9500         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9501         tdata.iv.data[0] += 1;
9502         res = test_authenticated_decryption(&tdata);
9503         if (res == -ENOTSUP)
9504                 return res;
9505         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9506         return TEST_SUCCESS;
9507 }
9508
9509 static int
9510 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
9511 {
9512         struct aead_test_data tdata;
9513         int res;
9514
9515         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9516         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9517         tdata.plaintext.data[0] += 1;
9518         res = test_authenticated_decryption(&tdata);
9519         if (res == -ENOTSUP)
9520                 return res;
9521         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9522         return TEST_SUCCESS;
9523 }
9524
9525 static int
9526 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
9527 {
9528         struct aead_test_data tdata;
9529         int res;
9530
9531         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9532         tdata.ciphertext.data[0] += 1;
9533         res = test_authenticated_decryption(&tdata);
9534         if (res == -ENOTSUP)
9535                 return res;
9536         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9537         return TEST_SUCCESS;
9538 }
9539
9540 static int
9541 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
9542 {
9543         struct aead_test_data tdata;
9544         int res;
9545
9546         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9547         tdata.aad.len += 1;
9548         res = test_authenticated_decryption(&tdata);
9549         if (res == -ENOTSUP)
9550                 return res;
9551         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9552         return TEST_SUCCESS;
9553 }
9554
9555 static int
9556 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
9557 {
9558         struct aead_test_data tdata;
9559         uint8_t aad[gcm_test_case_7.aad.len];
9560         int res;
9561
9562         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9563         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9564         aad[0] += 1;
9565         tdata.aad.data = aad;
9566         res = test_authenticated_decryption(&tdata);
9567         if (res == -ENOTSUP)
9568                 return res;
9569         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9570         return TEST_SUCCESS;
9571 }
9572
9573 static int
9574 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
9575 {
9576         struct aead_test_data tdata;
9577         int res;
9578
9579         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9580         tdata.auth_tag.data[0] += 1;
9581         res = test_authenticated_decryption(&tdata);
9582         if (res == -ENOTSUP)
9583                 return res;
9584         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
9585         return TEST_SUCCESS;
9586 }
9587
9588 static int
9589 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
9590 {
9591         struct crypto_testsuite_params *ts_params = &testsuite_params;
9592         struct crypto_unittest_params *ut_params = &unittest_params;
9593
9594         int retval;
9595         uint8_t *ciphertext, *auth_tag;
9596         uint16_t plaintext_pad_len;
9597
9598         /* Verify the capabilities */
9599         struct rte_cryptodev_sym_capability_idx cap_idx;
9600         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9601         cap_idx.algo.aead = tdata->algo;
9602         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9603                         &cap_idx) == NULL)
9604                 return -ENOTSUP;
9605
9606         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9607                 return -ENOTSUP;
9608
9609         /* not supported with CPU crypto */
9610         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9611                 return -ENOTSUP;
9612
9613         /* Create AEAD session */
9614         retval = create_aead_session(ts_params->valid_devs[0],
9615                         tdata->algo,
9616                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
9617                         tdata->key.data, tdata->key.len,
9618                         tdata->aad.len, tdata->auth_tag.len,
9619                         tdata->iv.len);
9620         if (retval < 0)
9621                 return retval;
9622
9623         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9624         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9625
9626         /* clear mbuf payload */
9627         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9628                         rte_pktmbuf_tailroom(ut_params->ibuf));
9629         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
9630                         rte_pktmbuf_tailroom(ut_params->obuf));
9631
9632         /* Create AEAD operation */
9633         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
9634         if (retval < 0)
9635                 return retval;
9636
9637         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9638
9639         ut_params->op->sym->m_src = ut_params->ibuf;
9640         ut_params->op->sym->m_dst = ut_params->obuf;
9641
9642         /* Process crypto operation */
9643         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9644                         ut_params->op), "failed to process sym crypto op");
9645
9646         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9647                         "crypto op processing failed");
9648
9649         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9650
9651         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
9652                         ut_params->op->sym->cipher.data.offset);
9653         auth_tag = ciphertext + plaintext_pad_len;
9654
9655         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
9656         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
9657
9658         /* Validate obuf */
9659         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9660                         ciphertext,
9661                         tdata->ciphertext.data,
9662                         tdata->ciphertext.len,
9663                         "Ciphertext data not as expected");
9664
9665         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9666                         auth_tag,
9667                         tdata->auth_tag.data,
9668                         tdata->auth_tag.len,
9669                         "Generated auth tag not as expected");
9670
9671         return 0;
9672
9673 }
9674
9675 static int
9676 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
9677 {
9678         return test_authenticated_encryption_oop(&gcm_test_case_5);
9679 }
9680
9681 static int
9682 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
9683 {
9684         struct crypto_testsuite_params *ts_params = &testsuite_params;
9685         struct crypto_unittest_params *ut_params = &unittest_params;
9686
9687         int retval;
9688         uint8_t *plaintext;
9689
9690         /* Verify the capabilities */
9691         struct rte_cryptodev_sym_capability_idx cap_idx;
9692         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9693         cap_idx.algo.aead = tdata->algo;
9694         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9695                         &cap_idx) == NULL)
9696                 return -ENOTSUP;
9697
9698         /* not supported with CPU crypto and raw data-path APIs*/
9699         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
9700                         global_api_test_type == CRYPTODEV_RAW_API_TEST)
9701                 return -ENOTSUP;
9702
9703         /* Create AEAD session */
9704         retval = create_aead_session(ts_params->valid_devs[0],
9705                         tdata->algo,
9706                         RTE_CRYPTO_AEAD_OP_DECRYPT,
9707                         tdata->key.data, tdata->key.len,
9708                         tdata->aad.len, tdata->auth_tag.len,
9709                         tdata->iv.len);
9710         if (retval < 0)
9711                 return retval;
9712
9713         /* alloc mbuf and set payload */
9714         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9715         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9716
9717         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9718                         rte_pktmbuf_tailroom(ut_params->ibuf));
9719         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
9720                         rte_pktmbuf_tailroom(ut_params->obuf));
9721
9722         /* Create AEAD operation */
9723         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9724         if (retval < 0)
9725                 return retval;
9726
9727         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9728
9729         ut_params->op->sym->m_src = ut_params->ibuf;
9730         ut_params->op->sym->m_dst = ut_params->obuf;
9731
9732         /* Process crypto operation */
9733         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9734                         ut_params->op), "failed to process sym crypto op");
9735
9736         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9737                         "crypto op processing failed");
9738
9739         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
9740                         ut_params->op->sym->cipher.data.offset);
9741
9742         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9743
9744         /* Validate obuf */
9745         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9746                         plaintext,
9747                         tdata->plaintext.data,
9748                         tdata->plaintext.len,
9749                         "Plaintext data not as expected");
9750
9751         TEST_ASSERT_EQUAL(ut_params->op->status,
9752                         RTE_CRYPTO_OP_STATUS_SUCCESS,
9753                         "Authentication failed");
9754         return 0;
9755 }
9756
9757 static int
9758 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
9759 {
9760         return test_authenticated_decryption_oop(&gcm_test_case_5);
9761 }
9762
9763 static int
9764 test_authenticated_encryption_sessionless(
9765                 const struct aead_test_data *tdata)
9766 {
9767         struct crypto_testsuite_params *ts_params = &testsuite_params;
9768         struct crypto_unittest_params *ut_params = &unittest_params;
9769
9770         int retval;
9771         uint8_t *ciphertext, *auth_tag;
9772         uint16_t plaintext_pad_len;
9773         uint8_t key[tdata->key.len + 1];
9774         struct rte_cryptodev_info dev_info;
9775
9776         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9777         uint64_t feat_flags = dev_info.feature_flags;
9778
9779         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
9780                 printf("Device doesn't support Sessionless ops.\n");
9781                 return -ENOTSUP;
9782         }
9783
9784         /* not supported with CPU crypto */
9785         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9786                 return -ENOTSUP;
9787
9788         /* Verify the capabilities */
9789         struct rte_cryptodev_sym_capability_idx cap_idx;
9790         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9791         cap_idx.algo.aead = tdata->algo;
9792         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9793                         &cap_idx) == NULL)
9794                 return -ENOTSUP;
9795
9796         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9797
9798         /* clear mbuf payload */
9799         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9800                         rte_pktmbuf_tailroom(ut_params->ibuf));
9801
9802         /* Create AEAD operation */
9803         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
9804         if (retval < 0)
9805                 return retval;
9806
9807         /* Create GCM xform */
9808         memcpy(key, tdata->key.data, tdata->key.len);
9809         retval = create_aead_xform(ut_params->op,
9810                         tdata->algo,
9811                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
9812                         key, tdata->key.len,
9813                         tdata->aad.len, tdata->auth_tag.len,
9814                         tdata->iv.len);
9815         if (retval < 0)
9816                 return retval;
9817
9818         ut_params->op->sym->m_src = ut_params->ibuf;
9819
9820         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
9821                         RTE_CRYPTO_OP_SESSIONLESS,
9822                         "crypto op session type not sessionless");
9823
9824         /* Process crypto operation */
9825         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9826                         ut_params->op), "failed to process sym crypto op");
9827
9828         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
9829
9830         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9831                         "crypto op status not success");
9832
9833         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9834
9835         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9836                         ut_params->op->sym->cipher.data.offset);
9837         auth_tag = ciphertext + plaintext_pad_len;
9838
9839         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
9840         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
9841
9842         /* Validate obuf */
9843         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9844                         ciphertext,
9845                         tdata->ciphertext.data,
9846                         tdata->ciphertext.len,
9847                         "Ciphertext data not as expected");
9848
9849         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9850                         auth_tag,
9851                         tdata->auth_tag.data,
9852                         tdata->auth_tag.len,
9853                         "Generated auth tag not as expected");
9854
9855         return 0;
9856
9857 }
9858
9859 static int
9860 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
9861 {
9862         return test_authenticated_encryption_sessionless(
9863                         &gcm_test_case_5);
9864 }
9865
9866 static int
9867 test_authenticated_decryption_sessionless(
9868                 const struct aead_test_data *tdata)
9869 {
9870         struct crypto_testsuite_params *ts_params = &testsuite_params;
9871         struct crypto_unittest_params *ut_params = &unittest_params;
9872
9873         int retval;
9874         uint8_t *plaintext;
9875         uint8_t key[tdata->key.len + 1];
9876         struct rte_cryptodev_info dev_info;
9877
9878         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9879         uint64_t feat_flags = dev_info.feature_flags;
9880
9881         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
9882                 printf("Device doesn't support Sessionless ops.\n");
9883                 return -ENOTSUP;
9884         }
9885
9886         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9887                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9888                 printf("Device doesn't support RAW data-path APIs.\n");
9889                 return -ENOTSUP;
9890         }
9891
9892         /* not supported with CPU crypto */
9893         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9894                 return -ENOTSUP;
9895
9896         /* Verify the capabilities */
9897         struct rte_cryptodev_sym_capability_idx cap_idx;
9898         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9899         cap_idx.algo.aead = tdata->algo;
9900         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9901                         &cap_idx) == NULL)
9902                 return -ENOTSUP;
9903
9904         /* alloc mbuf and set payload */
9905         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9906
9907         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9908                         rte_pktmbuf_tailroom(ut_params->ibuf));
9909
9910         /* Create AEAD operation */
9911         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9912         if (retval < 0)
9913                 return retval;
9914
9915         /* Create AEAD xform */
9916         memcpy(key, tdata->key.data, tdata->key.len);
9917         retval = create_aead_xform(ut_params->op,
9918                         tdata->algo,
9919                         RTE_CRYPTO_AEAD_OP_DECRYPT,
9920                         key, tdata->key.len,
9921                         tdata->aad.len, tdata->auth_tag.len,
9922                         tdata->iv.len);
9923         if (retval < 0)
9924                 return retval;
9925
9926         ut_params->op->sym->m_src = ut_params->ibuf;
9927
9928         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
9929                         RTE_CRYPTO_OP_SESSIONLESS,
9930                         "crypto op session type not sessionless");
9931
9932         /* Process crypto operation */
9933         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9934                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9935                                 ut_params->op, 0, 0, 0, 0);
9936         else
9937                 TEST_ASSERT_NOT_NULL(process_crypto_request(
9938                         ts_params->valid_devs[0], ut_params->op),
9939                                 "failed to process sym crypto op");
9940
9941         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
9942
9943         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9944                         "crypto op status not success");
9945
9946         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9947                         ut_params->op->sym->cipher.data.offset);
9948
9949         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9950
9951         /* Validate obuf */
9952         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9953                         plaintext,
9954                         tdata->plaintext.data,
9955                         tdata->plaintext.len,
9956                         "Plaintext data not as expected");
9957
9958         TEST_ASSERT_EQUAL(ut_params->op->status,
9959                         RTE_CRYPTO_OP_STATUS_SUCCESS,
9960                         "Authentication failed");
9961         return 0;
9962 }
9963
9964 static int
9965 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
9966 {
9967         return test_authenticated_decryption_sessionless(
9968                         &gcm_test_case_5);
9969 }
9970
9971 static int
9972 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
9973 {
9974         return test_authenticated_encryption(&ccm_test_case_128_1);
9975 }
9976
9977 static int
9978 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
9979 {
9980         return test_authenticated_encryption(&ccm_test_case_128_2);
9981 }
9982
9983 static int
9984 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
9985 {
9986         return test_authenticated_encryption(&ccm_test_case_128_3);
9987 }
9988
9989 static int
9990 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
9991 {
9992         return test_authenticated_decryption(&ccm_test_case_128_1);
9993 }
9994
9995 static int
9996 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
9997 {
9998         return test_authenticated_decryption(&ccm_test_case_128_2);
9999 }
10000
10001 static int
10002 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10003 {
10004         return test_authenticated_decryption(&ccm_test_case_128_3);
10005 }
10006
10007 static int
10008 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10009 {
10010         return test_authenticated_encryption(&ccm_test_case_192_1);
10011 }
10012
10013 static int
10014 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10015 {
10016         return test_authenticated_encryption(&ccm_test_case_192_2);
10017 }
10018
10019 static int
10020 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10021 {
10022         return test_authenticated_encryption(&ccm_test_case_192_3);
10023 }
10024
10025 static int
10026 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10027 {
10028         return test_authenticated_decryption(&ccm_test_case_192_1);
10029 }
10030
10031 static int
10032 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10033 {
10034         return test_authenticated_decryption(&ccm_test_case_192_2);
10035 }
10036
10037 static int
10038 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10039 {
10040         return test_authenticated_decryption(&ccm_test_case_192_3);
10041 }
10042
10043 static int
10044 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
10045 {
10046         return test_authenticated_encryption(&ccm_test_case_256_1);
10047 }
10048
10049 static int
10050 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
10051 {
10052         return test_authenticated_encryption(&ccm_test_case_256_2);
10053 }
10054
10055 static int
10056 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
10057 {
10058         return test_authenticated_encryption(&ccm_test_case_256_3);
10059 }
10060
10061 static int
10062 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
10063 {
10064         return test_authenticated_decryption(&ccm_test_case_256_1);
10065 }
10066
10067 static int
10068 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
10069 {
10070         return test_authenticated_decryption(&ccm_test_case_256_2);
10071 }
10072
10073 static int
10074 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
10075 {
10076         return test_authenticated_decryption(&ccm_test_case_256_3);
10077 }
10078
10079 static int
10080 test_stats(void)
10081 {
10082         struct crypto_testsuite_params *ts_params = &testsuite_params;
10083         struct rte_cryptodev_stats stats;
10084
10085         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10086                 return -ENOTSUP;
10087
10088         /* Verify the capabilities */
10089         struct rte_cryptodev_sym_capability_idx cap_idx;
10090         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10091         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
10092         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10093                         &cap_idx) == NULL)
10094                 return -ENOTSUP;
10095         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10096         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10097         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10098                         &cap_idx) == NULL)
10099                 return -ENOTSUP;
10100
10101         if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
10102                         == -ENOTSUP)
10103                 return -ENOTSUP;
10104
10105         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10106         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
10107                         &stats) == -ENODEV),
10108                 "rte_cryptodev_stats_get invalid dev failed");
10109         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
10110                 "rte_cryptodev_stats_get invalid Param failed");
10111
10112         /* Test expected values */
10113         test_AES_CBC_HMAC_SHA1_encrypt_digest();
10114         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10115                         &stats),
10116                 "rte_cryptodev_stats_get failed");
10117         TEST_ASSERT((stats.enqueued_count == 1),
10118                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10119         TEST_ASSERT((stats.dequeued_count == 1),
10120                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10121         TEST_ASSERT((stats.enqueue_err_count == 0),
10122                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10123         TEST_ASSERT((stats.dequeue_err_count == 0),
10124                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10125
10126         /* invalid device but should ignore and not reset device stats*/
10127         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
10128         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10129                         &stats),
10130                 "rte_cryptodev_stats_get failed");
10131         TEST_ASSERT((stats.enqueued_count == 1),
10132                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10133
10134         /* check that a valid reset clears stats */
10135         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10136         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10137                         &stats),
10138                                           "rte_cryptodev_stats_get failed");
10139         TEST_ASSERT((stats.enqueued_count == 0),
10140                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10141         TEST_ASSERT((stats.dequeued_count == 0),
10142                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10143
10144         return TEST_SUCCESS;
10145 }
10146
10147 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
10148                                    struct crypto_unittest_params *ut_params,
10149                                    enum rte_crypto_auth_operation op,
10150                                    const struct HMAC_MD5_vector *test_case)
10151 {
10152         uint8_t key[64];
10153
10154         memcpy(key, test_case->key.data, test_case->key.len);
10155
10156         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10157         ut_params->auth_xform.next = NULL;
10158         ut_params->auth_xform.auth.op = op;
10159
10160         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
10161
10162         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
10163         ut_params->auth_xform.auth.key.length = test_case->key.len;
10164         ut_params->auth_xform.auth.key.data = key;
10165
10166         ut_params->sess = rte_cryptodev_sym_session_create(
10167                         ts_params->session_mpool);
10168
10169         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10170                         ut_params->sess, &ut_params->auth_xform,
10171                         ts_params->session_priv_mpool);
10172
10173         if (ut_params->sess == NULL)
10174                 return TEST_FAILED;
10175
10176         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10177
10178         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10179                         rte_pktmbuf_tailroom(ut_params->ibuf));
10180
10181         return 0;
10182 }
10183
10184 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
10185                               const struct HMAC_MD5_vector *test_case,
10186                               uint8_t **plaintext)
10187 {
10188         uint16_t plaintext_pad_len;
10189
10190         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10191
10192         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10193                                 16);
10194
10195         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10196                         plaintext_pad_len);
10197         memcpy(*plaintext, test_case->plaintext.data,
10198                         test_case->plaintext.len);
10199
10200         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10201                         ut_params->ibuf, MD5_DIGEST_LEN);
10202         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10203                         "no room to append digest");
10204         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10205                         ut_params->ibuf, plaintext_pad_len);
10206
10207         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10208                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
10209                            test_case->auth_tag.len);
10210         }
10211
10212         sym_op->auth.data.offset = 0;
10213         sym_op->auth.data.length = test_case->plaintext.len;
10214
10215         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10216         ut_params->op->sym->m_src = ut_params->ibuf;
10217
10218         return 0;
10219 }
10220
10221 static int
10222 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
10223 {
10224         uint16_t plaintext_pad_len;
10225         uint8_t *plaintext, *auth_tag;
10226
10227         struct crypto_testsuite_params *ts_params = &testsuite_params;
10228         struct crypto_unittest_params *ut_params = &unittest_params;
10229         struct rte_cryptodev_info dev_info;
10230
10231         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10232         uint64_t feat_flags = dev_info.feature_flags;
10233
10234         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10235                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10236                 printf("Device doesn't support RAW data-path APIs.\n");
10237                 return -ENOTSUP;
10238         }
10239
10240         /* Verify the capabilities */
10241         struct rte_cryptodev_sym_capability_idx cap_idx;
10242         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10243         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10244         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10245                         &cap_idx) == NULL)
10246                 return -ENOTSUP;
10247
10248         if (MD5_HMAC_create_session(ts_params, ut_params,
10249                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
10250                 return TEST_FAILED;
10251
10252         /* Generate Crypto op data structure */
10253         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10254                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10255         TEST_ASSERT_NOT_NULL(ut_params->op,
10256                         "Failed to allocate symmetric crypto operation struct");
10257
10258         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10259                                 16);
10260
10261         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10262                 return TEST_FAILED;
10263
10264         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10265                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10266                         ut_params->op);
10267         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10268                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10269                                 ut_params->op, 0, 1, 0, 0);
10270         else
10271                 TEST_ASSERT_NOT_NULL(
10272                         process_crypto_request(ts_params->valid_devs[0],
10273                                 ut_params->op),
10274                                 "failed to process sym crypto op");
10275
10276         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10277                         "crypto op processing failed");
10278
10279         if (ut_params->op->sym->m_dst) {
10280                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10281                                 uint8_t *, plaintext_pad_len);
10282         } else {
10283                 auth_tag = plaintext + plaintext_pad_len;
10284         }
10285
10286         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10287                         auth_tag,
10288                         test_case->auth_tag.data,
10289                         test_case->auth_tag.len,
10290                         "HMAC_MD5 generated tag not as expected");
10291
10292         return TEST_SUCCESS;
10293 }
10294
10295 static int
10296 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
10297 {
10298         uint8_t *plaintext;
10299
10300         struct crypto_testsuite_params *ts_params = &testsuite_params;
10301         struct crypto_unittest_params *ut_params = &unittest_params;
10302         struct rte_cryptodev_info dev_info;
10303
10304         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10305         uint64_t feat_flags = dev_info.feature_flags;
10306
10307         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10308                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10309                 printf("Device doesn't support RAW data-path APIs.\n");
10310                 return -ENOTSUP;
10311         }
10312
10313         /* Verify the capabilities */
10314         struct rte_cryptodev_sym_capability_idx cap_idx;
10315         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10316         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10317         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10318                         &cap_idx) == NULL)
10319                 return -ENOTSUP;
10320
10321         if (MD5_HMAC_create_session(ts_params, ut_params,
10322                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
10323                 return TEST_FAILED;
10324         }
10325
10326         /* Generate Crypto op data structure */
10327         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10328                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10329         TEST_ASSERT_NOT_NULL(ut_params->op,
10330                         "Failed to allocate symmetric crypto operation struct");
10331
10332         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10333                 return TEST_FAILED;
10334
10335         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10336                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10337                         ut_params->op);
10338         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10339                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10340                                 ut_params->op, 0, 1, 0, 0);
10341         else
10342                 TEST_ASSERT_NOT_NULL(
10343                         process_crypto_request(ts_params->valid_devs[0],
10344                                 ut_params->op),
10345                                 "failed to process sym crypto op");
10346
10347         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10348                         "HMAC_MD5 crypto op processing failed");
10349
10350         return TEST_SUCCESS;
10351 }
10352
10353 static int
10354 test_MD5_HMAC_generate_case_1(void)
10355 {
10356         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
10357 }
10358
10359 static int
10360 test_MD5_HMAC_verify_case_1(void)
10361 {
10362         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
10363 }
10364
10365 static int
10366 test_MD5_HMAC_generate_case_2(void)
10367 {
10368         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
10369 }
10370
10371 static int
10372 test_MD5_HMAC_verify_case_2(void)
10373 {
10374         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
10375 }
10376
10377 static int
10378 test_multi_session(void)
10379 {
10380         struct crypto_testsuite_params *ts_params = &testsuite_params;
10381         struct crypto_unittest_params *ut_params = &unittest_params;
10382
10383         struct rte_cryptodev_info dev_info;
10384         struct rte_cryptodev_sym_session **sessions;
10385
10386         uint16_t i;
10387
10388         /* Verify the capabilities */
10389         struct rte_cryptodev_sym_capability_idx cap_idx;
10390         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10391         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10392         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10393                         &cap_idx) == NULL)
10394                 return -ENOTSUP;
10395         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10396         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10397         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10398                         &cap_idx) == NULL)
10399                 return -ENOTSUP;
10400
10401         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
10402                         aes_cbc_key, hmac_sha512_key);
10403
10404
10405         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10406
10407         sessions = rte_malloc(NULL,
10408                         (sizeof(struct rte_cryptodev_sym_session *) *
10409                         MAX_NB_SESSIONS) + 1, 0);
10410
10411         /* Create multiple crypto sessions*/
10412         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10413
10414                 sessions[i] = rte_cryptodev_sym_session_create(
10415                                 ts_params->session_mpool);
10416
10417                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10418                                 sessions[i], &ut_params->auth_xform,
10419                                 ts_params->session_priv_mpool);
10420                 TEST_ASSERT_NOT_NULL(sessions[i],
10421                                 "Session creation failed at session number %u",
10422                                 i);
10423
10424                 /* Attempt to send a request on each session */
10425                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
10426                         sessions[i],
10427                         ut_params,
10428                         ts_params,
10429                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
10430                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
10431                         aes_cbc_iv),
10432                         "Failed to perform decrypt on request number %u.", i);
10433                 /* free crypto operation structure */
10434                 if (ut_params->op)
10435                         rte_crypto_op_free(ut_params->op);
10436
10437                 /*
10438                  * free mbuf - both obuf and ibuf are usually the same,
10439                  * so check if they point at the same address is necessary,
10440                  * to avoid freeing the mbuf twice.
10441                  */
10442                 if (ut_params->obuf) {
10443                         rte_pktmbuf_free(ut_params->obuf);
10444                         if (ut_params->ibuf == ut_params->obuf)
10445                                 ut_params->ibuf = 0;
10446                         ut_params->obuf = 0;
10447                 }
10448                 if (ut_params->ibuf) {
10449                         rte_pktmbuf_free(ut_params->ibuf);
10450                         ut_params->ibuf = 0;
10451                 }
10452         }
10453
10454         /* Next session create should fail */
10455         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10456                         sessions[i], &ut_params->auth_xform,
10457                         ts_params->session_priv_mpool);
10458         TEST_ASSERT_NULL(sessions[i],
10459                         "Session creation succeeded unexpectedly!");
10460
10461         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10462                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10463                                 sessions[i]);
10464                 rte_cryptodev_sym_session_free(sessions[i]);
10465         }
10466
10467         rte_free(sessions);
10468
10469         return TEST_SUCCESS;
10470 }
10471
10472 struct multi_session_params {
10473         struct crypto_unittest_params ut_params;
10474         uint8_t *cipher_key;
10475         uint8_t *hmac_key;
10476         const uint8_t *cipher;
10477         const uint8_t *digest;
10478         uint8_t *iv;
10479 };
10480
10481 #define MB_SESSION_NUMBER 3
10482
10483 static int
10484 test_multi_session_random_usage(void)
10485 {
10486         struct crypto_testsuite_params *ts_params = &testsuite_params;
10487         struct rte_cryptodev_info dev_info;
10488         struct rte_cryptodev_sym_session **sessions;
10489         uint32_t i, j;
10490         struct multi_session_params ut_paramz[] = {
10491
10492                 {
10493                         .cipher_key = ms_aes_cbc_key0,
10494                         .hmac_key = ms_hmac_key0,
10495                         .cipher = ms_aes_cbc_cipher0,
10496                         .digest = ms_hmac_digest0,
10497                         .iv = ms_aes_cbc_iv0
10498                 },
10499                 {
10500                         .cipher_key = ms_aes_cbc_key1,
10501                         .hmac_key = ms_hmac_key1,
10502                         .cipher = ms_aes_cbc_cipher1,
10503                         .digest = ms_hmac_digest1,
10504                         .iv = ms_aes_cbc_iv1
10505                 },
10506                 {
10507                         .cipher_key = ms_aes_cbc_key2,
10508                         .hmac_key = ms_hmac_key2,
10509                         .cipher = ms_aes_cbc_cipher2,
10510                         .digest = ms_hmac_digest2,
10511                         .iv = ms_aes_cbc_iv2
10512                 },
10513
10514         };
10515
10516         /* Verify the capabilities */
10517         struct rte_cryptodev_sym_capability_idx cap_idx;
10518         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10519         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10520         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10521                         &cap_idx) == NULL)
10522                 return -ENOTSUP;
10523         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10524         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10525         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10526                         &cap_idx) == NULL)
10527                 return -ENOTSUP;
10528
10529         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10530
10531         sessions = rte_malloc(NULL,
10532                         (sizeof(struct rte_cryptodev_sym_session *)
10533                                         * MAX_NB_SESSIONS) + 1, 0);
10534
10535         for (i = 0; i < MB_SESSION_NUMBER; i++) {
10536                 sessions[i] = rte_cryptodev_sym_session_create(
10537                                 ts_params->session_mpool);
10538
10539                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
10540                                 sizeof(struct crypto_unittest_params));
10541
10542                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
10543                                 &ut_paramz[i].ut_params,
10544                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
10545
10546                 /* Create multiple crypto sessions*/
10547                 rte_cryptodev_sym_session_init(
10548                                 ts_params->valid_devs[0],
10549                                 sessions[i],
10550                                 &ut_paramz[i].ut_params.auth_xform,
10551                                 ts_params->session_priv_mpool);
10552
10553                 TEST_ASSERT_NOT_NULL(sessions[i],
10554                                 "Session creation failed at session number %u",
10555                                 i);
10556
10557         }
10558
10559         srand(time(NULL));
10560         for (i = 0; i < 40000; i++) {
10561
10562                 j = rand() % MB_SESSION_NUMBER;
10563
10564                 TEST_ASSERT_SUCCESS(
10565                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
10566                                         sessions[j],
10567                                         &ut_paramz[j].ut_params,
10568                                         ts_params, ut_paramz[j].cipher,
10569                                         ut_paramz[j].digest,
10570                                         ut_paramz[j].iv),
10571                         "Failed to perform decrypt on request number %u.", i);
10572
10573                 if (ut_paramz[j].ut_params.op)
10574                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
10575
10576                 /*
10577                  * free mbuf - both obuf and ibuf are usually the same,
10578                  * so check if they point at the same address is necessary,
10579                  * to avoid freeing the mbuf twice.
10580                  */
10581                 if (ut_paramz[j].ut_params.obuf) {
10582                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
10583                         if (ut_paramz[j].ut_params.ibuf
10584                                         == ut_paramz[j].ut_params.obuf)
10585                                 ut_paramz[j].ut_params.ibuf = 0;
10586                         ut_paramz[j].ut_params.obuf = 0;
10587                 }
10588                 if (ut_paramz[j].ut_params.ibuf) {
10589                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
10590                         ut_paramz[j].ut_params.ibuf = 0;
10591                 }
10592         }
10593
10594         for (i = 0; i < MB_SESSION_NUMBER; i++) {
10595                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10596                                 sessions[i]);
10597                 rte_cryptodev_sym_session_free(sessions[i]);
10598         }
10599
10600         rte_free(sessions);
10601
10602         return TEST_SUCCESS;
10603 }
10604
10605 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
10606                         0xab, 0xab, 0xab, 0xab,
10607                         0xab, 0xab, 0xab, 0xab,
10608                         0xab, 0xab, 0xab, 0xab};
10609
10610 static int
10611 test_null_invalid_operation(void)
10612 {
10613         struct crypto_testsuite_params *ts_params = &testsuite_params;
10614         struct crypto_unittest_params *ut_params = &unittest_params;
10615         int ret;
10616
10617         /* This test is for NULL PMD only */
10618         if (gbl_driver_id != rte_cryptodev_driver_id_get(
10619                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
10620                 return -ENOTSUP;
10621
10622         /* Setup Cipher Parameters */
10623         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10624         ut_params->cipher_xform.next = NULL;
10625
10626         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
10627         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10628
10629         ut_params->sess = rte_cryptodev_sym_session_create(
10630                         ts_params->session_mpool);
10631
10632         /* Create Crypto session*/
10633         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10634                         ut_params->sess, &ut_params->cipher_xform,
10635                         ts_params->session_priv_mpool);
10636         TEST_ASSERT(ret < 0,
10637                         "Session creation succeeded unexpectedly");
10638
10639
10640         /* Setup HMAC Parameters */
10641         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10642         ut_params->auth_xform.next = NULL;
10643
10644         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
10645         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10646
10647         ut_params->sess = rte_cryptodev_sym_session_create(
10648                         ts_params->session_mpool);
10649
10650         /* Create Crypto session*/
10651         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10652                         ut_params->sess, &ut_params->auth_xform,
10653                         ts_params->session_priv_mpool);
10654         TEST_ASSERT(ret < 0,
10655                         "Session creation succeeded unexpectedly");
10656
10657         return TEST_SUCCESS;
10658 }
10659
10660
10661 #define NULL_BURST_LENGTH (32)
10662
10663 static int
10664 test_null_burst_operation(void)
10665 {
10666         struct crypto_testsuite_params *ts_params = &testsuite_params;
10667         struct crypto_unittest_params *ut_params = &unittest_params;
10668
10669         unsigned i, burst_len = NULL_BURST_LENGTH;
10670
10671         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
10672         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
10673
10674         /* This test is for NULL PMD only */
10675         if (gbl_driver_id != rte_cryptodev_driver_id_get(
10676                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
10677                 return -ENOTSUP;
10678
10679         /* Setup Cipher Parameters */
10680         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10681         ut_params->cipher_xform.next = &ut_params->auth_xform;
10682
10683         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
10684         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10685
10686         /* Setup HMAC Parameters */
10687         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10688         ut_params->auth_xform.next = NULL;
10689
10690         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
10691         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10692
10693         ut_params->sess = rte_cryptodev_sym_session_create(
10694                         ts_params->session_mpool);
10695
10696         /* Create Crypto session*/
10697         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10698                         ut_params->sess, &ut_params->cipher_xform,
10699                         ts_params->session_priv_mpool);
10700         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10701
10702         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
10703                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
10704                         burst_len, "failed to generate burst of crypto ops");
10705
10706         /* Generate an operation for each mbuf in burst */
10707         for (i = 0; i < burst_len; i++) {
10708                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10709
10710                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
10711
10712                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
10713                                 sizeof(unsigned));
10714                 *data = i;
10715
10716                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
10717
10718                 burst[i]->sym->m_src = m;
10719         }
10720
10721         /* Process crypto operation */
10722         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
10723                         0, burst, burst_len),
10724                         burst_len,
10725                         "Error enqueuing burst");
10726
10727         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
10728                         0, burst_dequeued, burst_len),
10729                         burst_len,
10730                         "Error dequeuing burst");
10731
10732
10733         for (i = 0; i < burst_len; i++) {
10734                 TEST_ASSERT_EQUAL(
10735                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
10736                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
10737                                         uint32_t *),
10738                         "data not as expected");
10739
10740                 rte_pktmbuf_free(burst[i]->sym->m_src);
10741                 rte_crypto_op_free(burst[i]);
10742         }
10743
10744         return TEST_SUCCESS;
10745 }
10746
10747 static uint16_t
10748 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
10749                   uint16_t nb_ops, void *user_param)
10750 {
10751         RTE_SET_USED(dev_id);
10752         RTE_SET_USED(qp_id);
10753         RTE_SET_USED(ops);
10754         RTE_SET_USED(user_param);
10755
10756         printf("crypto enqueue callback called\n");
10757         return nb_ops;
10758 }
10759
10760 static uint16_t
10761 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
10762                   uint16_t nb_ops, void *user_param)
10763 {
10764         RTE_SET_USED(dev_id);
10765         RTE_SET_USED(qp_id);
10766         RTE_SET_USED(ops);
10767         RTE_SET_USED(user_param);
10768
10769         printf("crypto dequeue callback called\n");
10770         return nb_ops;
10771 }
10772
10773 /*
10774  * Thread using enqueue/dequeue callback with RCU.
10775  */
10776 static int
10777 test_enqdeq_callback_thread(void *arg)
10778 {
10779         RTE_SET_USED(arg);
10780         /* DP thread calls rte_cryptodev_enqueue_burst()/
10781          * rte_cryptodev_dequeue_burst() and invokes callback.
10782          */
10783         test_null_burst_operation();
10784         return 0;
10785 }
10786
10787 static int
10788 test_enq_callback_setup(void)
10789 {
10790         struct crypto_testsuite_params *ts_params = &testsuite_params;
10791         struct rte_cryptodev_info dev_info;
10792         struct rte_cryptodev_qp_conf qp_conf = {
10793                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
10794         };
10795
10796         struct rte_cryptodev_cb *cb;
10797         uint16_t qp_id = 0;
10798
10799         /* Stop the device in case it's started so it can be configured */
10800         rte_cryptodev_stop(ts_params->valid_devs[0]);
10801
10802         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10803
10804         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
10805                         &ts_params->conf),
10806                         "Failed to configure cryptodev %u",
10807                         ts_params->valid_devs[0]);
10808
10809         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
10810         qp_conf.mp_session = ts_params->session_mpool;
10811         qp_conf.mp_session_private = ts_params->session_priv_mpool;
10812
10813         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
10814                         ts_params->valid_devs[0], qp_id, &qp_conf,
10815                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
10816                         "Failed test for "
10817                         "rte_cryptodev_queue_pair_setup: num_inflights "
10818                         "%u on qp %u on cryptodev %u",
10819                         qp_conf.nb_descriptors, qp_id,
10820                         ts_params->valid_devs[0]);
10821
10822         /* Test with invalid crypto device */
10823         cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
10824                         qp_id, test_enq_callback, NULL);
10825         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
10826                         "cryptodev %u did not fail",
10827                         qp_id, RTE_CRYPTO_MAX_DEVS);
10828
10829         /* Test with invalid queue pair */
10830         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
10831                         dev_info.max_nb_queue_pairs + 1,
10832                         test_enq_callback, NULL);
10833         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
10834                         "cryptodev %u did not fail",
10835                         dev_info.max_nb_queue_pairs + 1,
10836                         ts_params->valid_devs[0]);
10837
10838         /* Test with NULL callback */
10839         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
10840                         qp_id, NULL, NULL);
10841         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
10842                         "cryptodev %u did not fail",
10843                         qp_id, ts_params->valid_devs[0]);
10844
10845         /* Test with valid configuration */
10846         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
10847                         qp_id, test_enq_callback, NULL);
10848         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
10849                         "qp %u on cryptodev %u",
10850                         qp_id, ts_params->valid_devs[0]);
10851
10852         rte_cryptodev_start(ts_params->valid_devs[0]);
10853
10854         /* Launch a thread */
10855         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
10856                                 rte_get_next_lcore(-1, 1, 0));
10857
10858         /* Wait until reader exited. */
10859         rte_eal_mp_wait_lcore();
10860
10861         /* Test with invalid crypto device */
10862         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
10863                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
10864                         "Expected call to fail as crypto device is invalid");
10865
10866         /* Test with invalid queue pair */
10867         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
10868                         ts_params->valid_devs[0],
10869                         dev_info.max_nb_queue_pairs + 1, cb),
10870                         "Expected call to fail as queue pair is invalid");
10871
10872         /* Test with NULL callback */
10873         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
10874                         ts_params->valid_devs[0], qp_id, NULL),
10875                         "Expected call to fail as callback is NULL");
10876
10877         /* Test with valid configuration */
10878         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
10879                         ts_params->valid_devs[0], qp_id, cb),
10880                         "Failed test to remove callback on "
10881                         "qp %u on cryptodev %u",
10882                         qp_id, ts_params->valid_devs[0]);
10883
10884         return TEST_SUCCESS;
10885 }
10886
10887 static int
10888 test_deq_callback_setup(void)
10889 {
10890         struct crypto_testsuite_params *ts_params = &testsuite_params;
10891         struct rte_cryptodev_info dev_info;
10892         struct rte_cryptodev_qp_conf qp_conf = {
10893                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
10894         };
10895
10896         struct rte_cryptodev_cb *cb;
10897         uint16_t qp_id = 0;
10898
10899         /* Stop the device in case it's started so it can be configured */
10900         rte_cryptodev_stop(ts_params->valid_devs[0]);
10901
10902         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10903
10904         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
10905                         &ts_params->conf),
10906                         "Failed to configure cryptodev %u",
10907                         ts_params->valid_devs[0]);
10908
10909         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
10910         qp_conf.mp_session = ts_params->session_mpool;
10911         qp_conf.mp_session_private = ts_params->session_priv_mpool;
10912
10913         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
10914                         ts_params->valid_devs[0], qp_id, &qp_conf,
10915                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
10916                         "Failed test for "
10917                         "rte_cryptodev_queue_pair_setup: num_inflights "
10918                         "%u on qp %u on cryptodev %u",
10919                         qp_conf.nb_descriptors, qp_id,
10920                         ts_params->valid_devs[0]);
10921
10922         /* Test with invalid crypto device */
10923         cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
10924                         qp_id, test_deq_callback, NULL);
10925         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
10926                         "cryptodev %u did not fail",
10927                         qp_id, RTE_CRYPTO_MAX_DEVS);
10928
10929         /* Test with invalid queue pair */
10930         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
10931                         dev_info.max_nb_queue_pairs + 1,
10932                         test_deq_callback, NULL);
10933         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
10934                         "cryptodev %u did not fail",
10935                         dev_info.max_nb_queue_pairs + 1,
10936                         ts_params->valid_devs[0]);
10937
10938         /* Test with NULL callback */
10939         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
10940                         qp_id, NULL, NULL);
10941         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
10942                         "cryptodev %u did not fail",
10943                         qp_id, ts_params->valid_devs[0]);
10944
10945         /* Test with valid configuration */
10946         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
10947                         qp_id, test_deq_callback, NULL);
10948         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
10949                         "qp %u on cryptodev %u",
10950                         qp_id, ts_params->valid_devs[0]);
10951
10952         rte_cryptodev_start(ts_params->valid_devs[0]);
10953
10954         /* Launch a thread */
10955         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
10956                                 rte_get_next_lcore(-1, 1, 0));
10957
10958         /* Wait until reader exited. */
10959         rte_eal_mp_wait_lcore();
10960
10961         /* Test with invalid crypto device */
10962         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
10963                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
10964                         "Expected call to fail as crypto device is invalid");
10965
10966         /* Test with invalid queue pair */
10967         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
10968                         ts_params->valid_devs[0],
10969                         dev_info.max_nb_queue_pairs + 1, cb),
10970                         "Expected call to fail as queue pair is invalid");
10971
10972         /* Test with NULL callback */
10973         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
10974                         ts_params->valid_devs[0], qp_id, NULL),
10975                         "Expected call to fail as callback is NULL");
10976
10977         /* Test with valid configuration */
10978         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
10979                         ts_params->valid_devs[0], qp_id, cb),
10980                         "Failed test to remove callback on "
10981                         "qp %u on cryptodev %u",
10982                         qp_id, ts_params->valid_devs[0]);
10983
10984         return TEST_SUCCESS;
10985 }
10986
10987 static void
10988 generate_gmac_large_plaintext(uint8_t *data)
10989 {
10990         uint16_t i;
10991
10992         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
10993                 memcpy(&data[i], &data[0], 32);
10994 }
10995
10996 static int
10997 create_gmac_operation(enum rte_crypto_auth_operation op,
10998                 const struct gmac_test_data *tdata)
10999 {
11000         struct crypto_testsuite_params *ts_params = &testsuite_params;
11001         struct crypto_unittest_params *ut_params = &unittest_params;
11002         struct rte_crypto_sym_op *sym_op;
11003
11004         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11005
11006         /* Generate Crypto op data structure */
11007         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11008                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11009         TEST_ASSERT_NOT_NULL(ut_params->op,
11010                         "Failed to allocate symmetric crypto operation struct");
11011
11012         sym_op = ut_params->op->sym;
11013
11014         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11015                         ut_params->ibuf, tdata->gmac_tag.len);
11016         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11017                         "no room to append digest");
11018
11019         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11020                         ut_params->ibuf, plaintext_pad_len);
11021
11022         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11023                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11024                                 tdata->gmac_tag.len);
11025                 debug_hexdump(stdout, "digest:",
11026                                 sym_op->auth.digest.data,
11027                                 tdata->gmac_tag.len);
11028         }
11029
11030         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11031                         uint8_t *, IV_OFFSET);
11032
11033         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11034
11035         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11036
11037         sym_op->cipher.data.length = 0;
11038         sym_op->cipher.data.offset = 0;
11039
11040         sym_op->auth.data.offset = 0;
11041         sym_op->auth.data.length = tdata->plaintext.len;
11042
11043         return 0;
11044 }
11045
11046 static int
11047 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
11048                 const struct gmac_test_data *tdata,
11049                 void *digest_mem, uint64_t digest_phys)
11050 {
11051         struct crypto_testsuite_params *ts_params = &testsuite_params;
11052         struct crypto_unittest_params *ut_params = &unittest_params;
11053         struct rte_crypto_sym_op *sym_op;
11054
11055         /* Generate Crypto op data structure */
11056         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11057                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11058         TEST_ASSERT_NOT_NULL(ut_params->op,
11059                         "Failed to allocate symmetric crypto operation struct");
11060
11061         sym_op = ut_params->op->sym;
11062
11063         sym_op->auth.digest.data = digest_mem;
11064         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11065                         "no room to append digest");
11066
11067         sym_op->auth.digest.phys_addr = digest_phys;
11068
11069         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11070                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11071                                 tdata->gmac_tag.len);
11072                 debug_hexdump(stdout, "digest:",
11073                                 sym_op->auth.digest.data,
11074                                 tdata->gmac_tag.len);
11075         }
11076
11077         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11078                         uint8_t *, IV_OFFSET);
11079
11080         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11081
11082         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11083
11084         sym_op->cipher.data.length = 0;
11085         sym_op->cipher.data.offset = 0;
11086
11087         sym_op->auth.data.offset = 0;
11088         sym_op->auth.data.length = tdata->plaintext.len;
11089
11090         return 0;
11091 }
11092
11093 static int create_gmac_session(uint8_t dev_id,
11094                 const struct gmac_test_data *tdata,
11095                 enum rte_crypto_auth_operation auth_op)
11096 {
11097         uint8_t auth_key[tdata->key.len];
11098
11099         struct crypto_testsuite_params *ts_params = &testsuite_params;
11100         struct crypto_unittest_params *ut_params = &unittest_params;
11101
11102         memcpy(auth_key, tdata->key.data, tdata->key.len);
11103
11104         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11105         ut_params->auth_xform.next = NULL;
11106
11107         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
11108         ut_params->auth_xform.auth.op = auth_op;
11109         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
11110         ut_params->auth_xform.auth.key.length = tdata->key.len;
11111         ut_params->auth_xform.auth.key.data = auth_key;
11112         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11113         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
11114
11115
11116         ut_params->sess = rte_cryptodev_sym_session_create(
11117                         ts_params->session_mpool);
11118
11119         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11120                         &ut_params->auth_xform,
11121                         ts_params->session_priv_mpool);
11122
11123         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11124
11125         return 0;
11126 }
11127
11128 static int
11129 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
11130 {
11131         struct crypto_testsuite_params *ts_params = &testsuite_params;
11132         struct crypto_unittest_params *ut_params = &unittest_params;
11133         struct rte_cryptodev_info dev_info;
11134
11135         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11136         uint64_t feat_flags = dev_info.feature_flags;
11137
11138         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11139                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11140                 printf("Device doesn't support RAW data-path APIs.\n");
11141                 return -ENOTSUP;
11142         }
11143
11144         int retval;
11145
11146         uint8_t *auth_tag, *plaintext;
11147         uint16_t plaintext_pad_len;
11148
11149         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11150                               "No GMAC length in the source data");
11151
11152         /* Verify the capabilities */
11153         struct rte_cryptodev_sym_capability_idx cap_idx;
11154         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11155         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11156         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11157                         &cap_idx) == NULL)
11158                 return -ENOTSUP;
11159
11160         retval = create_gmac_session(ts_params->valid_devs[0],
11161                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11162
11163         if (retval < 0)
11164                 return retval;
11165
11166         if (tdata->plaintext.len > MBUF_SIZE)
11167                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11168         else
11169                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11170         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11171                         "Failed to allocate input buffer in mempool");
11172
11173         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11174                         rte_pktmbuf_tailroom(ut_params->ibuf));
11175
11176         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11177         /*
11178          * Runtime generate the large plain text instead of use hard code
11179          * plain text vector. It is done to avoid create huge source file
11180          * with the test vector.
11181          */
11182         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11183                 generate_gmac_large_plaintext(tdata->plaintext.data);
11184
11185         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11186                                 plaintext_pad_len);
11187         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11188
11189         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11190         debug_hexdump(stdout, "plaintext:", plaintext,
11191                         tdata->plaintext.len);
11192
11193         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
11194                         tdata);
11195
11196         if (retval < 0)
11197                 return retval;
11198
11199         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11200
11201         ut_params->op->sym->m_src = ut_params->ibuf;
11202
11203         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11204                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11205                         ut_params->op);
11206         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11207                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11208                                 ut_params->op, 0, 1, 0, 0);
11209         else
11210                 TEST_ASSERT_NOT_NULL(
11211                         process_crypto_request(ts_params->valid_devs[0],
11212                         ut_params->op), "failed to process sym crypto op");
11213
11214         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11215                         "crypto op processing failed");
11216
11217         if (ut_params->op->sym->m_dst) {
11218                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11219                                 uint8_t *, plaintext_pad_len);
11220         } else {
11221                 auth_tag = plaintext + plaintext_pad_len;
11222         }
11223
11224         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11225
11226         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11227                         auth_tag,
11228                         tdata->gmac_tag.data,
11229                         tdata->gmac_tag.len,
11230                         "GMAC Generated auth tag not as expected");
11231
11232         return 0;
11233 }
11234
11235 static int
11236 test_AES_GMAC_authentication_test_case_1(void)
11237 {
11238         return test_AES_GMAC_authentication(&gmac_test_case_1);
11239 }
11240
11241 static int
11242 test_AES_GMAC_authentication_test_case_2(void)
11243 {
11244         return test_AES_GMAC_authentication(&gmac_test_case_2);
11245 }
11246
11247 static int
11248 test_AES_GMAC_authentication_test_case_3(void)
11249 {
11250         return test_AES_GMAC_authentication(&gmac_test_case_3);
11251 }
11252
11253 static int
11254 test_AES_GMAC_authentication_test_case_4(void)
11255 {
11256         return test_AES_GMAC_authentication(&gmac_test_case_4);
11257 }
11258
11259 static int
11260 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
11261 {
11262         struct crypto_testsuite_params *ts_params = &testsuite_params;
11263         struct crypto_unittest_params *ut_params = &unittest_params;
11264         int retval;
11265         uint32_t plaintext_pad_len;
11266         uint8_t *plaintext;
11267         struct rte_cryptodev_info dev_info;
11268
11269         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11270         uint64_t feat_flags = dev_info.feature_flags;
11271
11272         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11273                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11274                 printf("Device doesn't support RAW data-path APIs.\n");
11275                 return -ENOTSUP;
11276         }
11277
11278         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11279                               "No GMAC length in the source data");
11280
11281         /* Verify the capabilities */
11282         struct rte_cryptodev_sym_capability_idx cap_idx;
11283         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11284         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11285         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11286                         &cap_idx) == NULL)
11287                 return -ENOTSUP;
11288
11289         retval = create_gmac_session(ts_params->valid_devs[0],
11290                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
11291
11292         if (retval < 0)
11293                 return retval;
11294
11295         if (tdata->plaintext.len > MBUF_SIZE)
11296                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11297         else
11298                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11299         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11300                         "Failed to allocate input buffer in mempool");
11301
11302         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11303                         rte_pktmbuf_tailroom(ut_params->ibuf));
11304
11305         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11306
11307         /*
11308          * Runtime generate the large plain text instead of use hard code
11309          * plain text vector. It is done to avoid create huge source file
11310          * with the test vector.
11311          */
11312         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11313                 generate_gmac_large_plaintext(tdata->plaintext.data);
11314
11315         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11316                                 plaintext_pad_len);
11317         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11318
11319         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11320         debug_hexdump(stdout, "plaintext:", plaintext,
11321                         tdata->plaintext.len);
11322
11323         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
11324                         tdata);
11325
11326         if (retval < 0)
11327                 return retval;
11328
11329         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11330
11331         ut_params->op->sym->m_src = ut_params->ibuf;
11332
11333         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11334                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11335                         ut_params->op);
11336         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11337                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11338                                 ut_params->op, 0, 1, 0, 0);
11339         else
11340                 TEST_ASSERT_NOT_NULL(
11341                         process_crypto_request(ts_params->valid_devs[0],
11342                         ut_params->op), "failed to process sym crypto op");
11343
11344         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11345                         "crypto op processing failed");
11346
11347         return 0;
11348
11349 }
11350
11351 static int
11352 test_AES_GMAC_authentication_verify_test_case_1(void)
11353 {
11354         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
11355 }
11356
11357 static int
11358 test_AES_GMAC_authentication_verify_test_case_2(void)
11359 {
11360         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
11361 }
11362
11363 static int
11364 test_AES_GMAC_authentication_verify_test_case_3(void)
11365 {
11366         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
11367 }
11368
11369 static int
11370 test_AES_GMAC_authentication_verify_test_case_4(void)
11371 {
11372         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
11373 }
11374
11375 static int
11376 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
11377                                 uint32_t fragsz)
11378 {
11379         struct crypto_testsuite_params *ts_params = &testsuite_params;
11380         struct crypto_unittest_params *ut_params = &unittest_params;
11381         struct rte_cryptodev_info dev_info;
11382         uint64_t feature_flags;
11383         unsigned int trn_data = 0;
11384         void *digest_mem = NULL;
11385         uint32_t segs = 1;
11386         unsigned int to_trn = 0;
11387         struct rte_mbuf *buf = NULL;
11388         uint8_t *auth_tag, *plaintext;
11389         int retval;
11390
11391         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11392                               "No GMAC length in the source data");
11393
11394         /* Verify the capabilities */
11395         struct rte_cryptodev_sym_capability_idx cap_idx;
11396         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11397         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11398         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11399                         &cap_idx) == NULL)
11400                 return -ENOTSUP;
11401
11402         /* Check for any input SGL support */
11403         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11404         feature_flags = dev_info.feature_flags;
11405
11406         if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
11407                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
11408                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
11409                 return -ENOTSUP;
11410
11411         if (fragsz > tdata->plaintext.len)
11412                 fragsz = tdata->plaintext.len;
11413
11414         uint16_t plaintext_len = fragsz;
11415
11416         retval = create_gmac_session(ts_params->valid_devs[0],
11417                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11418
11419         if (retval < 0)
11420                 return retval;
11421
11422         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11423         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11424                         "Failed to allocate input buffer in mempool");
11425
11426         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11427                         rte_pktmbuf_tailroom(ut_params->ibuf));
11428
11429         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11430                                 plaintext_len);
11431         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11432
11433         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
11434
11435         trn_data += plaintext_len;
11436
11437         buf = ut_params->ibuf;
11438
11439         /*
11440          * Loop until no more fragments
11441          */
11442
11443         while (trn_data < tdata->plaintext.len) {
11444                 ++segs;
11445                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
11446                                 (tdata->plaintext.len - trn_data) : fragsz;
11447
11448                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11449                 buf = buf->next;
11450
11451                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
11452                                 rte_pktmbuf_tailroom(buf));
11453
11454                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
11455                                 to_trn);
11456
11457                 memcpy(plaintext, tdata->plaintext.data + trn_data,
11458                                 to_trn);
11459                 trn_data += to_trn;
11460                 if (trn_data  == tdata->plaintext.len)
11461                         digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
11462                                         tdata->gmac_tag.len);
11463         }
11464         ut_params->ibuf->nb_segs = segs;
11465
11466         /*
11467          * Place digest at the end of the last buffer
11468          */
11469         uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11470
11471         if (!digest_mem) {
11472                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11473                                 + tdata->gmac_tag.len);
11474                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11475                                 tdata->plaintext.len);
11476         }
11477
11478         retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
11479                         tdata, digest_mem, digest_phys);
11480
11481         if (retval < 0)
11482                 return retval;
11483
11484         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11485
11486         ut_params->op->sym->m_src = ut_params->ibuf;
11487
11488         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11489                 return -ENOTSUP;
11490
11491         TEST_ASSERT_NOT_NULL(
11492                 process_crypto_request(ts_params->valid_devs[0],
11493                 ut_params->op), "failed to process sym crypto op");
11494
11495         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11496                         "crypto op processing failed");
11497
11498         auth_tag = digest_mem;
11499         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11500         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11501                         auth_tag,
11502                         tdata->gmac_tag.data,
11503                         tdata->gmac_tag.len,
11504                         "GMAC Generated auth tag not as expected");
11505
11506         return 0;
11507 }
11508
11509 /* Segment size not multiple of block size (16B) */
11510 static int
11511 test_AES_GMAC_authentication_SGL_40B(void)
11512 {
11513         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
11514 }
11515
11516 static int
11517 test_AES_GMAC_authentication_SGL_80B(void)
11518 {
11519         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
11520 }
11521
11522 static int
11523 test_AES_GMAC_authentication_SGL_2048B(void)
11524 {
11525         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
11526 }
11527
11528 /* Segment size not multiple of block size (16B) */
11529 static int
11530 test_AES_GMAC_authentication_SGL_2047B(void)
11531 {
11532         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
11533 }
11534
11535 struct test_crypto_vector {
11536         enum rte_crypto_cipher_algorithm crypto_algo;
11537         unsigned int cipher_offset;
11538         unsigned int cipher_len;
11539
11540         struct {
11541                 uint8_t data[64];
11542                 unsigned int len;
11543         } cipher_key;
11544
11545         struct {
11546                 uint8_t data[64];
11547                 unsigned int len;
11548         } iv;
11549
11550         struct {
11551                 const uint8_t *data;
11552                 unsigned int len;
11553         } plaintext;
11554
11555         struct {
11556                 const uint8_t *data;
11557                 unsigned int len;
11558         } ciphertext;
11559
11560         enum rte_crypto_auth_algorithm auth_algo;
11561         unsigned int auth_offset;
11562
11563         struct {
11564                 uint8_t data[128];
11565                 unsigned int len;
11566         } auth_key;
11567
11568         struct {
11569                 const uint8_t *data;
11570                 unsigned int len;
11571         } aad;
11572
11573         struct {
11574                 uint8_t data[128];
11575                 unsigned int len;
11576         } digest;
11577 };
11578
11579 static const struct test_crypto_vector
11580 hmac_sha1_test_crypto_vector = {
11581         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11582         .plaintext = {
11583                 .data = plaintext_hash,
11584                 .len = 512
11585         },
11586         .auth_key = {
11587                 .data = {
11588                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11589                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11590                         0xDE, 0xF4, 0xDE, 0xAD
11591                 },
11592                 .len = 20
11593         },
11594         .digest = {
11595                 .data = {
11596                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
11597                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
11598                         0x3F, 0x91, 0x64, 0x59
11599                 },
11600                 .len = 20
11601         }
11602 };
11603
11604 static const struct test_crypto_vector
11605 aes128_gmac_test_vector = {
11606         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
11607         .plaintext = {
11608                 .data = plaintext_hash,
11609                 .len = 512
11610         },
11611         .iv = {
11612                 .data = {
11613                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11614                         0x08, 0x09, 0x0A, 0x0B
11615                 },
11616                 .len = 12
11617         },
11618         .auth_key = {
11619                 .data = {
11620                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
11621                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
11622                 },
11623                 .len = 16
11624         },
11625         .digest = {
11626                 .data = {
11627                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
11628                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
11629                 },
11630                 .len = 16
11631         }
11632 };
11633
11634 static const struct test_crypto_vector
11635 aes128cbc_hmac_sha1_test_vector = {
11636         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
11637         .cipher_offset = 0,
11638         .cipher_len = 512,
11639         .cipher_key = {
11640                 .data = {
11641                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
11642                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
11643                 },
11644                 .len = 16
11645         },
11646         .iv = {
11647                 .data = {
11648                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11649                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
11650                 },
11651                 .len = 16
11652         },
11653         .plaintext = {
11654                 .data = plaintext_hash,
11655                 .len = 512
11656         },
11657         .ciphertext = {
11658                 .data = ciphertext512_aes128cbc,
11659                 .len = 512
11660         },
11661         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11662         .auth_offset = 0,
11663         .auth_key = {
11664                 .data = {
11665                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11666                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11667                         0xDE, 0xF4, 0xDE, 0xAD
11668                 },
11669                 .len = 20
11670         },
11671         .digest = {
11672                 .data = {
11673                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
11674                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
11675                         0x18, 0x8C, 0x1D, 0x32
11676                 },
11677                 .len = 20
11678         }
11679 };
11680
11681 static const struct test_crypto_vector
11682 aes128cbc_hmac_sha1_aad_test_vector = {
11683         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
11684         .cipher_offset = 8,
11685         .cipher_len = 496,
11686         .cipher_key = {
11687                 .data = {
11688                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
11689                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
11690                 },
11691                 .len = 16
11692         },
11693         .iv = {
11694                 .data = {
11695                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11696                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
11697                 },
11698                 .len = 16
11699         },
11700         .plaintext = {
11701                 .data = plaintext_hash,
11702                 .len = 512
11703         },
11704         .ciphertext = {
11705                 .data = ciphertext512_aes128cbc_aad,
11706                 .len = 512
11707         },
11708         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11709         .auth_offset = 0,
11710         .auth_key = {
11711                 .data = {
11712                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11713                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11714                         0xDE, 0xF4, 0xDE, 0xAD
11715                 },
11716                 .len = 20
11717         },
11718         .digest = {
11719                 .data = {
11720                         0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
11721                         0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
11722                         0x62, 0x0F, 0xFB, 0x10
11723                 },
11724                 .len = 20
11725         }
11726 };
11727
11728 static void
11729 data_corruption(uint8_t *data)
11730 {
11731         data[0] += 1;
11732 }
11733
11734 static void
11735 tag_corruption(uint8_t *data, unsigned int tag_offset)
11736 {
11737         data[tag_offset] += 1;
11738 }
11739
11740 static int
11741 create_auth_session(struct crypto_unittest_params *ut_params,
11742                 uint8_t dev_id,
11743                 const struct test_crypto_vector *reference,
11744                 enum rte_crypto_auth_operation auth_op)
11745 {
11746         struct crypto_testsuite_params *ts_params = &testsuite_params;
11747         uint8_t auth_key[reference->auth_key.len + 1];
11748
11749         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
11750
11751         /* Setup Authentication Parameters */
11752         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11753         ut_params->auth_xform.auth.op = auth_op;
11754         ut_params->auth_xform.next = NULL;
11755         ut_params->auth_xform.auth.algo = reference->auth_algo;
11756         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
11757         ut_params->auth_xform.auth.key.data = auth_key;
11758         ut_params->auth_xform.auth.digest_length = reference->digest.len;
11759
11760         /* Create Crypto session*/
11761         ut_params->sess = rte_cryptodev_sym_session_create(
11762                         ts_params->session_mpool);
11763
11764         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11765                                 &ut_params->auth_xform,
11766                                 ts_params->session_priv_mpool);
11767
11768         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11769
11770         return 0;
11771 }
11772
11773 static int
11774 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
11775                 uint8_t dev_id,
11776                 const struct test_crypto_vector *reference,
11777                 enum rte_crypto_auth_operation auth_op,
11778                 enum rte_crypto_cipher_operation cipher_op)
11779 {
11780         struct crypto_testsuite_params *ts_params = &testsuite_params;
11781         uint8_t cipher_key[reference->cipher_key.len + 1];
11782         uint8_t auth_key[reference->auth_key.len + 1];
11783
11784         memcpy(cipher_key, reference->cipher_key.data,
11785                         reference->cipher_key.len);
11786         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
11787
11788         /* Setup Authentication Parameters */
11789         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11790         ut_params->auth_xform.auth.op = auth_op;
11791         ut_params->auth_xform.auth.algo = reference->auth_algo;
11792         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
11793         ut_params->auth_xform.auth.key.data = auth_key;
11794         ut_params->auth_xform.auth.digest_length = reference->digest.len;
11795
11796         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
11797                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11798                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
11799         } else {
11800                 ut_params->auth_xform.next = &ut_params->cipher_xform;
11801
11802                 /* Setup Cipher Parameters */
11803                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11804                 ut_params->cipher_xform.next = NULL;
11805                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
11806                 ut_params->cipher_xform.cipher.op = cipher_op;
11807                 ut_params->cipher_xform.cipher.key.data = cipher_key;
11808                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
11809                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11810                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
11811         }
11812
11813         /* Create Crypto session*/
11814         ut_params->sess = rte_cryptodev_sym_session_create(
11815                         ts_params->session_mpool);
11816
11817         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11818                                 &ut_params->auth_xform,
11819                                 ts_params->session_priv_mpool);
11820
11821         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11822
11823         return 0;
11824 }
11825
11826 static int
11827 create_auth_operation(struct crypto_testsuite_params *ts_params,
11828                 struct crypto_unittest_params *ut_params,
11829                 const struct test_crypto_vector *reference,
11830                 unsigned int auth_generate)
11831 {
11832         /* Generate Crypto op data structure */
11833         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11834                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11835         TEST_ASSERT_NOT_NULL(ut_params->op,
11836                         "Failed to allocate pktmbuf offload");
11837
11838         /* Set crypto operation data parameters */
11839         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11840
11841         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11842
11843         /* set crypto operation source mbuf */
11844         sym_op->m_src = ut_params->ibuf;
11845
11846         /* digest */
11847         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11848                         ut_params->ibuf, reference->digest.len);
11849
11850         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11851                         "no room to append auth tag");
11852
11853         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11854                         ut_params->ibuf, reference->plaintext.len);
11855
11856         if (auth_generate)
11857                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
11858         else
11859                 memcpy(sym_op->auth.digest.data,
11860                                 reference->digest.data,
11861                                 reference->digest.len);
11862
11863         debug_hexdump(stdout, "digest:",
11864                         sym_op->auth.digest.data,
11865                         reference->digest.len);
11866
11867         sym_op->auth.data.length = reference->plaintext.len;
11868         sym_op->auth.data.offset = 0;
11869
11870         return 0;
11871 }
11872
11873 static int
11874 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
11875                 struct crypto_unittest_params *ut_params,
11876                 const struct test_crypto_vector *reference,
11877                 unsigned int auth_generate)
11878 {
11879         /* Generate Crypto op data structure */
11880         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11881                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11882         TEST_ASSERT_NOT_NULL(ut_params->op,
11883                         "Failed to allocate pktmbuf offload");
11884
11885         /* Set crypto operation data parameters */
11886         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11887
11888         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11889
11890         /* set crypto operation source mbuf */
11891         sym_op->m_src = ut_params->ibuf;
11892
11893         /* digest */
11894         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11895                         ut_params->ibuf, reference->digest.len);
11896
11897         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11898                         "no room to append auth tag");
11899
11900         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11901                         ut_params->ibuf, reference->ciphertext.len);
11902
11903         if (auth_generate)
11904                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
11905         else
11906                 memcpy(sym_op->auth.digest.data,
11907                                 reference->digest.data,
11908                                 reference->digest.len);
11909
11910         debug_hexdump(stdout, "digest:",
11911                         sym_op->auth.digest.data,
11912                         reference->digest.len);
11913
11914         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
11915                         reference->iv.data, reference->iv.len);
11916
11917         sym_op->cipher.data.length = 0;
11918         sym_op->cipher.data.offset = 0;
11919
11920         sym_op->auth.data.length = reference->plaintext.len;
11921         sym_op->auth.data.offset = 0;
11922
11923         return 0;
11924 }
11925
11926 static int
11927 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
11928                 struct crypto_unittest_params *ut_params,
11929                 const struct test_crypto_vector *reference,
11930                 unsigned int auth_generate)
11931 {
11932         /* Generate Crypto op data structure */
11933         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11934                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11935         TEST_ASSERT_NOT_NULL(ut_params->op,
11936                         "Failed to allocate pktmbuf offload");
11937
11938         /* Set crypto operation data parameters */
11939         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11940
11941         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11942
11943         /* set crypto operation source mbuf */
11944         sym_op->m_src = ut_params->ibuf;
11945
11946         /* digest */
11947         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11948                         ut_params->ibuf, reference->digest.len);
11949
11950         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11951                         "no room to append auth tag");
11952
11953         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11954                         ut_params->ibuf, reference->ciphertext.len);
11955
11956         if (auth_generate)
11957                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
11958         else
11959                 memcpy(sym_op->auth.digest.data,
11960                                 reference->digest.data,
11961                                 reference->digest.len);
11962
11963         debug_hexdump(stdout, "digest:",
11964                         sym_op->auth.digest.data,
11965                         reference->digest.len);
11966
11967         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
11968                         reference->iv.data, reference->iv.len);
11969
11970         sym_op->cipher.data.length = reference->cipher_len;
11971         sym_op->cipher.data.offset = reference->cipher_offset;
11972
11973         sym_op->auth.data.length = reference->plaintext.len;
11974         sym_op->auth.data.offset = reference->auth_offset;
11975
11976         return 0;
11977 }
11978
11979 static int
11980 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
11981                 struct crypto_unittest_params *ut_params,
11982                 const struct test_crypto_vector *reference)
11983 {
11984         return create_auth_operation(ts_params, ut_params, reference, 0);
11985 }
11986
11987 static int
11988 create_auth_verify_GMAC_operation(
11989                 struct crypto_testsuite_params *ts_params,
11990                 struct crypto_unittest_params *ut_params,
11991                 const struct test_crypto_vector *reference)
11992 {
11993         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
11994 }
11995
11996 static int
11997 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
11998                 struct crypto_unittest_params *ut_params,
11999                 const struct test_crypto_vector *reference)
12000 {
12001         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12002 }
12003
12004 static int
12005 test_authentication_verify_fail_when_data_corruption(
12006                 struct crypto_testsuite_params *ts_params,
12007                 struct crypto_unittest_params *ut_params,
12008                 const struct test_crypto_vector *reference,
12009                 unsigned int data_corrupted)
12010 {
12011         int retval;
12012
12013         uint8_t *plaintext;
12014         struct rte_cryptodev_info dev_info;
12015
12016         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12017         uint64_t feat_flags = dev_info.feature_flags;
12018
12019         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12020                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12021                 printf("Device doesn't support RAW data-path APIs.\n");
12022                 return -ENOTSUP;
12023         }
12024
12025         /* Verify the capabilities */
12026         struct rte_cryptodev_sym_capability_idx cap_idx;
12027         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12028         cap_idx.algo.auth = reference->auth_algo;
12029         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12030                         &cap_idx) == NULL)
12031                 return -ENOTSUP;
12032
12033
12034         /* Create session */
12035         retval = create_auth_session(ut_params,
12036                         ts_params->valid_devs[0],
12037                         reference,
12038                         RTE_CRYPTO_AUTH_OP_VERIFY);
12039         if (retval < 0)
12040                 return retval;
12041
12042         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12043         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12044                         "Failed to allocate input buffer in mempool");
12045
12046         /* clear mbuf payload */
12047         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12048                         rte_pktmbuf_tailroom(ut_params->ibuf));
12049
12050         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12051                         reference->plaintext.len);
12052         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12053         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12054
12055         debug_hexdump(stdout, "plaintext:", plaintext,
12056                 reference->plaintext.len);
12057
12058         /* Create operation */
12059         retval = create_auth_verify_operation(ts_params, ut_params, reference);
12060
12061         if (retval < 0)
12062                 return retval;
12063
12064         if (data_corrupted)
12065                 data_corruption(plaintext);
12066         else
12067                 tag_corruption(plaintext, reference->plaintext.len);
12068
12069         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12070                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12071                         ut_params->op);
12072                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12073                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12074                         "authentication not failed");
12075         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12076                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12077                                 ut_params->op, 0, 1, 0, 0);
12078         else {
12079                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12080                         ut_params->op);
12081                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12082         }
12083
12084         return 0;
12085 }
12086
12087 static int
12088 test_authentication_verify_GMAC_fail_when_corruption(
12089                 struct crypto_testsuite_params *ts_params,
12090                 struct crypto_unittest_params *ut_params,
12091                 const struct test_crypto_vector *reference,
12092                 unsigned int data_corrupted)
12093 {
12094         int retval;
12095         uint8_t *plaintext;
12096         struct rte_cryptodev_info dev_info;
12097
12098         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12099         uint64_t feat_flags = dev_info.feature_flags;
12100
12101         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12102                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12103                 printf("Device doesn't support RAW data-path APIs.\n");
12104                 return -ENOTSUP;
12105         }
12106
12107         /* Verify the capabilities */
12108         struct rte_cryptodev_sym_capability_idx cap_idx;
12109         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12110         cap_idx.algo.auth = reference->auth_algo;
12111         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12112                         &cap_idx) == NULL)
12113                 return -ENOTSUP;
12114
12115         /* Create session */
12116         retval = create_auth_cipher_session(ut_params,
12117                         ts_params->valid_devs[0],
12118                         reference,
12119                         RTE_CRYPTO_AUTH_OP_VERIFY,
12120                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12121         if (retval < 0)
12122                 return retval;
12123
12124         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12125         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12126                         "Failed to allocate input buffer in mempool");
12127
12128         /* clear mbuf payload */
12129         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12130                         rte_pktmbuf_tailroom(ut_params->ibuf));
12131
12132         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12133                         reference->plaintext.len);
12134         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12135         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12136
12137         debug_hexdump(stdout, "plaintext:", plaintext,
12138                 reference->plaintext.len);
12139
12140         /* Create operation */
12141         retval = create_auth_verify_GMAC_operation(ts_params,
12142                         ut_params,
12143                         reference);
12144
12145         if (retval < 0)
12146                 return retval;
12147
12148         if (data_corrupted)
12149                 data_corruption(plaintext);
12150         else
12151                 tag_corruption(plaintext, reference->aad.len);
12152
12153         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12154                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12155                         ut_params->op);
12156                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12157                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12158                         "authentication not failed");
12159         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12160                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12161                                 ut_params->op, 0, 1, 0, 0);
12162         else {
12163                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12164                         ut_params->op);
12165                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12166         }
12167
12168         return 0;
12169 }
12170
12171 static int
12172 test_authenticated_decryption_fail_when_corruption(
12173                 struct crypto_testsuite_params *ts_params,
12174                 struct crypto_unittest_params *ut_params,
12175                 const struct test_crypto_vector *reference,
12176                 unsigned int data_corrupted)
12177 {
12178         int retval;
12179
12180         uint8_t *ciphertext;
12181         struct rte_cryptodev_info dev_info;
12182
12183         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12184         uint64_t feat_flags = dev_info.feature_flags;
12185
12186         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12187                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12188                 printf("Device doesn't support RAW data-path APIs.\n");
12189                 return -ENOTSUP;
12190         }
12191
12192         /* Verify the capabilities */
12193         struct rte_cryptodev_sym_capability_idx cap_idx;
12194         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12195         cap_idx.algo.auth = reference->auth_algo;
12196         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12197                         &cap_idx) == NULL)
12198                 return -ENOTSUP;
12199         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12200         cap_idx.algo.cipher = reference->crypto_algo;
12201         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12202                         &cap_idx) == NULL)
12203                 return -ENOTSUP;
12204
12205         /* Create session */
12206         retval = create_auth_cipher_session(ut_params,
12207                         ts_params->valid_devs[0],
12208                         reference,
12209                         RTE_CRYPTO_AUTH_OP_VERIFY,
12210                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12211         if (retval < 0)
12212                 return retval;
12213
12214         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12215         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12216                         "Failed to allocate input buffer in mempool");
12217
12218         /* clear mbuf payload */
12219         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12220                         rte_pktmbuf_tailroom(ut_params->ibuf));
12221
12222         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12223                         reference->ciphertext.len);
12224         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12225         memcpy(ciphertext, reference->ciphertext.data,
12226                         reference->ciphertext.len);
12227
12228         /* Create operation */
12229         retval = create_cipher_auth_verify_operation(ts_params,
12230                         ut_params,
12231                         reference);
12232
12233         if (retval < 0)
12234                 return retval;
12235
12236         if (data_corrupted)
12237                 data_corruption(ciphertext);
12238         else
12239                 tag_corruption(ciphertext, reference->ciphertext.len);
12240
12241         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12242                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12243                         ut_params->op);
12244                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12245                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12246                         "authentication not failed");
12247         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12248                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12249                                 ut_params->op, 1, 1, 0, 0);
12250         else {
12251                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12252                         ut_params->op);
12253                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12254         }
12255
12256         return 0;
12257 }
12258
12259 static int
12260 test_authenticated_encryt_with_esn(
12261                 struct crypto_testsuite_params *ts_params,
12262                 struct crypto_unittest_params *ut_params,
12263                 const struct test_crypto_vector *reference)
12264 {
12265         int retval;
12266
12267         uint8_t *authciphertext, *plaintext, *auth_tag;
12268         uint16_t plaintext_pad_len;
12269         uint8_t cipher_key[reference->cipher_key.len + 1];
12270         uint8_t auth_key[reference->auth_key.len + 1];
12271         struct rte_cryptodev_info dev_info;
12272
12273         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12274         uint64_t feat_flags = dev_info.feature_flags;
12275
12276         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12277                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12278                 printf("Device doesn't support RAW data-path APIs.\n");
12279                 return -ENOTSUP;
12280         }
12281
12282         /* Verify the capabilities */
12283         struct rte_cryptodev_sym_capability_idx cap_idx;
12284         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12285         cap_idx.algo.auth = reference->auth_algo;
12286         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12287                         &cap_idx) == NULL)
12288                 return -ENOTSUP;
12289         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12290         cap_idx.algo.cipher = reference->crypto_algo;
12291         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12292                         &cap_idx) == NULL)
12293                 return -ENOTSUP;
12294
12295         /* Create session */
12296         memcpy(cipher_key, reference->cipher_key.data,
12297                         reference->cipher_key.len);
12298         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12299
12300         /* Setup Cipher Parameters */
12301         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12302         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12303         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12304         ut_params->cipher_xform.cipher.key.data = cipher_key;
12305         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12306         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12307         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12308
12309         ut_params->cipher_xform.next = &ut_params->auth_xform;
12310
12311         /* Setup Authentication Parameters */
12312         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12313         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12314         ut_params->auth_xform.auth.algo = reference->auth_algo;
12315         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12316         ut_params->auth_xform.auth.key.data = auth_key;
12317         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12318         ut_params->auth_xform.next = NULL;
12319
12320         /* Create Crypto session*/
12321         ut_params->sess = rte_cryptodev_sym_session_create(
12322                         ts_params->session_mpool);
12323
12324         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12325                                 ut_params->sess,
12326                                 &ut_params->cipher_xform,
12327                                 ts_params->session_priv_mpool);
12328
12329         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12330
12331         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12332         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12333                         "Failed to allocate input buffer in mempool");
12334
12335         /* clear mbuf payload */
12336         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12337                         rte_pktmbuf_tailroom(ut_params->ibuf));
12338
12339         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12340                         reference->plaintext.len);
12341         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12342         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12343
12344         /* Create operation */
12345         retval = create_cipher_auth_operation(ts_params,
12346                         ut_params,
12347                         reference, 0);
12348
12349         if (retval < 0)
12350                 return retval;
12351
12352         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12353                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12354                         ut_params->op);
12355         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12356                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12357                                 ut_params->op, 1, 1, 0, 0);
12358         else
12359                 ut_params->op = process_crypto_request(
12360                         ts_params->valid_devs[0], ut_params->op);
12361
12362         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
12363
12364         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12365                         "crypto op processing failed");
12366
12367         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
12368
12369         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
12370                         ut_params->op->sym->auth.data.offset);
12371         auth_tag = authciphertext + plaintext_pad_len;
12372         debug_hexdump(stdout, "ciphertext:", authciphertext,
12373                         reference->ciphertext.len);
12374         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
12375
12376         /* Validate obuf */
12377         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12378                         authciphertext,
12379                         reference->ciphertext.data,
12380                         reference->ciphertext.len,
12381                         "Ciphertext data not as expected");
12382
12383         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12384                         auth_tag,
12385                         reference->digest.data,
12386                         reference->digest.len,
12387                         "Generated digest not as expected");
12388
12389         return TEST_SUCCESS;
12390
12391 }
12392
12393 static int
12394 test_authenticated_decrypt_with_esn(
12395                 struct crypto_testsuite_params *ts_params,
12396                 struct crypto_unittest_params *ut_params,
12397                 const struct test_crypto_vector *reference)
12398 {
12399         int retval;
12400
12401         uint8_t *ciphertext;
12402         uint8_t cipher_key[reference->cipher_key.len + 1];
12403         uint8_t auth_key[reference->auth_key.len + 1];
12404         struct rte_cryptodev_info dev_info;
12405
12406         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12407         uint64_t feat_flags = dev_info.feature_flags;
12408
12409         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12410                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12411                 printf("Device doesn't support RAW data-path APIs.\n");
12412                 return -ENOTSUP;
12413         }
12414
12415         /* Verify the capabilities */
12416         struct rte_cryptodev_sym_capability_idx cap_idx;
12417         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12418         cap_idx.algo.auth = reference->auth_algo;
12419         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12420                         &cap_idx) == NULL)
12421                 return -ENOTSUP;
12422         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12423         cap_idx.algo.cipher = reference->crypto_algo;
12424         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12425                         &cap_idx) == NULL)
12426                 return -ENOTSUP;
12427
12428         /* Create session */
12429         memcpy(cipher_key, reference->cipher_key.data,
12430                         reference->cipher_key.len);
12431         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12432
12433         /* Setup Authentication Parameters */
12434         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12435         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
12436         ut_params->auth_xform.auth.algo = reference->auth_algo;
12437         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12438         ut_params->auth_xform.auth.key.data = auth_key;
12439         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12440         ut_params->auth_xform.next = &ut_params->cipher_xform;
12441
12442         /* Setup Cipher Parameters */
12443         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12444         ut_params->cipher_xform.next = NULL;
12445         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12446         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
12447         ut_params->cipher_xform.cipher.key.data = cipher_key;
12448         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12449         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12450         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12451
12452         /* Create Crypto session*/
12453         ut_params->sess = rte_cryptodev_sym_session_create(
12454                         ts_params->session_mpool);
12455
12456         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12457                                 ut_params->sess,
12458                                 &ut_params->auth_xform,
12459                                 ts_params->session_priv_mpool);
12460
12461         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12462
12463         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12464         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12465                         "Failed to allocate input buffer in mempool");
12466
12467         /* clear mbuf payload */
12468         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12469                         rte_pktmbuf_tailroom(ut_params->ibuf));
12470
12471         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12472                         reference->ciphertext.len);
12473         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12474         memcpy(ciphertext, reference->ciphertext.data,
12475                         reference->ciphertext.len);
12476
12477         /* Create operation */
12478         retval = create_cipher_auth_verify_operation(ts_params,
12479                         ut_params,
12480                         reference);
12481
12482         if (retval < 0)
12483                 return retval;
12484
12485         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12486                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12487                         ut_params->op);
12488         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12489                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12490                                 ut_params->op, 1, 1, 0, 0);
12491         else
12492                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12493                         ut_params->op);
12494
12495         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
12496         TEST_ASSERT_EQUAL(ut_params->op->status,
12497                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12498                         "crypto op processing passed");
12499
12500         ut_params->obuf = ut_params->op->sym->m_src;
12501         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
12502
12503         return 0;
12504 }
12505
12506 static int
12507 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
12508                 const struct aead_test_data *tdata,
12509                 void *digest_mem, uint64_t digest_phys)
12510 {
12511         struct crypto_testsuite_params *ts_params = &testsuite_params;
12512         struct crypto_unittest_params *ut_params = &unittest_params;
12513
12514         const unsigned int auth_tag_len = tdata->auth_tag.len;
12515         const unsigned int iv_len = tdata->iv.len;
12516         unsigned int aad_len = tdata->aad.len;
12517         unsigned int aad_len_pad = 0;
12518
12519         /* Generate Crypto op data structure */
12520         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12521                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12522         TEST_ASSERT_NOT_NULL(ut_params->op,
12523                 "Failed to allocate symmetric crypto operation struct");
12524
12525         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12526
12527         sym_op->aead.digest.data = digest_mem;
12528
12529         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
12530                         "no room to append digest");
12531
12532         sym_op->aead.digest.phys_addr = digest_phys;
12533
12534         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
12535                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
12536                                 auth_tag_len);
12537                 debug_hexdump(stdout, "digest:",
12538                                 sym_op->aead.digest.data,
12539                                 auth_tag_len);
12540         }
12541
12542         /* Append aad data */
12543         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
12544                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12545                                 uint8_t *, IV_OFFSET);
12546
12547                 /* Copy IV 1 byte after the IV pointer, according to the API */
12548                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
12549
12550                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
12551
12552                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12553                                 ut_params->ibuf, aad_len);
12554                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12555                                 "no room to prepend aad");
12556                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12557                                 ut_params->ibuf);
12558
12559                 memset(sym_op->aead.aad.data, 0, aad_len);
12560                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
12561                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12562
12563                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12564                 debug_hexdump(stdout, "aad:",
12565                                 sym_op->aead.aad.data, aad_len);
12566         } else {
12567                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12568                                 uint8_t *, IV_OFFSET);
12569
12570                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
12571
12572                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
12573
12574                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12575                                 ut_params->ibuf, aad_len_pad);
12576                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12577                                 "no room to prepend aad");
12578                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12579                                 ut_params->ibuf);
12580
12581                 memset(sym_op->aead.aad.data, 0, aad_len);
12582                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12583
12584                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12585                 debug_hexdump(stdout, "aad:",
12586                                 sym_op->aead.aad.data, aad_len);
12587         }
12588
12589         sym_op->aead.data.length = tdata->plaintext.len;
12590         sym_op->aead.data.offset = aad_len_pad;
12591
12592         return 0;
12593 }
12594
12595 #define SGL_MAX_NO      16
12596
12597 static int
12598 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
12599                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
12600 {
12601         struct crypto_testsuite_params *ts_params = &testsuite_params;
12602         struct crypto_unittest_params *ut_params = &unittest_params;
12603         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
12604         int retval;
12605         int to_trn = 0;
12606         int to_trn_tbl[SGL_MAX_NO];
12607         int segs = 1;
12608         unsigned int trn_data = 0;
12609         uint8_t *plaintext, *ciphertext, *auth_tag;
12610         struct rte_cryptodev_info dev_info;
12611
12612         /* Verify the capabilities */
12613         struct rte_cryptodev_sym_capability_idx cap_idx;
12614         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
12615         cap_idx.algo.aead = tdata->algo;
12616         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12617                         &cap_idx) == NULL)
12618                 return -ENOTSUP;
12619
12620         /* OOP not supported with CPU crypto */
12621         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12622                 return -ENOTSUP;
12623
12624         /* Detailed check for the particular SGL support flag */
12625         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12626         if (!oop) {
12627                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
12628                 if (sgl_in && (!(dev_info.feature_flags &
12629                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
12630                         return -ENOTSUP;
12631
12632                 uint64_t feat_flags = dev_info.feature_flags;
12633
12634                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12635                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12636                         printf("Device doesn't support RAW data-path APIs.\n");
12637                         return -ENOTSUP;
12638                 }
12639         } else {
12640                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
12641                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
12642                                 tdata->plaintext.len;
12643                 /* Raw data path API does not support OOP */
12644                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12645                         return -ENOTSUP;
12646                 if (sgl_in && !sgl_out) {
12647                         if (!(dev_info.feature_flags &
12648                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
12649                                 return -ENOTSUP;
12650                 } else if (!sgl_in && sgl_out) {
12651                         if (!(dev_info.feature_flags &
12652                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
12653                                 return -ENOTSUP;
12654                 } else if (sgl_in && sgl_out) {
12655                         if (!(dev_info.feature_flags &
12656                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
12657                                 return -ENOTSUP;
12658                 }
12659         }
12660
12661         if (fragsz > tdata->plaintext.len)
12662                 fragsz = tdata->plaintext.len;
12663
12664         uint16_t plaintext_len = fragsz;
12665         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
12666
12667         if (fragsz_oop > tdata->plaintext.len)
12668                 frag_size_oop = tdata->plaintext.len;
12669
12670         int ecx = 0;
12671         void *digest_mem = NULL;
12672
12673         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
12674
12675         if (tdata->plaintext.len % fragsz != 0) {
12676                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
12677                         return 1;
12678         }       else {
12679                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
12680                         return 1;
12681         }
12682
12683         /*
12684          * For out-op-place we need to alloc another mbuf
12685          */
12686         if (oop) {
12687                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12688                 rte_pktmbuf_append(ut_params->obuf,
12689                                 frag_size_oop + prepend_len);
12690                 buf_oop = ut_params->obuf;
12691         }
12692
12693         /* Create AEAD session */
12694         retval = create_aead_session(ts_params->valid_devs[0],
12695                         tdata->algo,
12696                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
12697                         tdata->key.data, tdata->key.len,
12698                         tdata->aad.len, tdata->auth_tag.len,
12699                         tdata->iv.len);
12700         if (retval < 0)
12701                 return retval;
12702
12703         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12704
12705         /* clear mbuf payload */
12706         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12707                         rte_pktmbuf_tailroom(ut_params->ibuf));
12708
12709         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12710                         plaintext_len);
12711
12712         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12713
12714         trn_data += plaintext_len;
12715
12716         buf = ut_params->ibuf;
12717
12718         /*
12719          * Loop until no more fragments
12720          */
12721
12722         while (trn_data < tdata->plaintext.len) {
12723                 ++segs;
12724                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
12725                                 (tdata->plaintext.len - trn_data) : fragsz;
12726
12727                 to_trn_tbl[ecx++] = to_trn;
12728
12729                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12730                 buf = buf->next;
12731
12732                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
12733                                 rte_pktmbuf_tailroom(buf));
12734
12735                 /* OOP */
12736                 if (oop && !fragsz_oop) {
12737                         buf_last_oop = buf_oop->next =
12738                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
12739                         buf_oop = buf_oop->next;
12740                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
12741                                         0, rte_pktmbuf_tailroom(buf_oop));
12742                         rte_pktmbuf_append(buf_oop, to_trn);
12743                 }
12744
12745                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
12746                                 to_trn);
12747
12748                 memcpy(plaintext, tdata->plaintext.data + trn_data,
12749                                 to_trn);
12750                 trn_data += to_trn;
12751                 if (trn_data  == tdata->plaintext.len) {
12752                         if (oop) {
12753                                 if (!fragsz_oop)
12754                                         digest_mem = rte_pktmbuf_append(buf_oop,
12755                                                 tdata->auth_tag.len);
12756                         } else
12757                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
12758                                         tdata->auth_tag.len);
12759                 }
12760         }
12761
12762         uint64_t digest_phys = 0;
12763
12764         ut_params->ibuf->nb_segs = segs;
12765
12766         segs = 1;
12767         if (fragsz_oop && oop) {
12768                 to_trn = 0;
12769                 ecx = 0;
12770
12771                 if (frag_size_oop == tdata->plaintext.len) {
12772                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
12773                                 tdata->auth_tag.len);
12774
12775                         digest_phys = rte_pktmbuf_iova_offset(
12776                                         ut_params->obuf,
12777                                         tdata->plaintext.len + prepend_len);
12778                 }
12779
12780                 trn_data = frag_size_oop;
12781                 while (trn_data < tdata->plaintext.len) {
12782                         ++segs;
12783                         to_trn =
12784                                 (tdata->plaintext.len - trn_data <
12785                                                 frag_size_oop) ?
12786                                 (tdata->plaintext.len - trn_data) :
12787                                                 frag_size_oop;
12788
12789                         to_trn_tbl[ecx++] = to_trn;
12790
12791                         buf_last_oop = buf_oop->next =
12792                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
12793                         buf_oop = buf_oop->next;
12794                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
12795                                         0, rte_pktmbuf_tailroom(buf_oop));
12796                         rte_pktmbuf_append(buf_oop, to_trn);
12797
12798                         trn_data += to_trn;
12799
12800                         if (trn_data  == tdata->plaintext.len) {
12801                                 digest_mem = rte_pktmbuf_append(buf_oop,
12802                                         tdata->auth_tag.len);
12803                         }
12804                 }
12805
12806                 ut_params->obuf->nb_segs = segs;
12807         }
12808
12809         /*
12810          * Place digest at the end of the last buffer
12811          */
12812         if (!digest_phys)
12813                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
12814         if (oop && buf_last_oop)
12815                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
12816
12817         if (!digest_mem && !oop) {
12818                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12819                                 + tdata->auth_tag.len);
12820                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
12821                                 tdata->plaintext.len);
12822         }
12823
12824         /* Create AEAD operation */
12825         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
12826                         tdata, digest_mem, digest_phys);
12827
12828         if (retval < 0)
12829                 return retval;
12830
12831         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12832
12833         ut_params->op->sym->m_src = ut_params->ibuf;
12834         if (oop)
12835                 ut_params->op->sym->m_dst = ut_params->obuf;
12836
12837         /* Process crypto operation */
12838         if (oop == IN_PLACE &&
12839                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12840                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
12841         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12842                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12843                                 ut_params->op, 0, 0, 0, 0);
12844         else
12845                 TEST_ASSERT_NOT_NULL(
12846                         process_crypto_request(ts_params->valid_devs[0],
12847                         ut_params->op), "failed to process sym crypto op");
12848
12849         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12850                         "crypto op processing failed");
12851
12852
12853         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
12854                         uint8_t *, prepend_len);
12855         if (oop) {
12856                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12857                                 uint8_t *, prepend_len);
12858         }
12859
12860         if (fragsz_oop)
12861                 fragsz = fragsz_oop;
12862
12863         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12864                         ciphertext,
12865                         tdata->ciphertext.data,
12866                         fragsz,
12867                         "Ciphertext data not as expected");
12868
12869         buf = ut_params->op->sym->m_src->next;
12870         if (oop)
12871                 buf = ut_params->op->sym->m_dst->next;
12872
12873         unsigned int off = fragsz;
12874
12875         ecx = 0;
12876         while (buf) {
12877                 ciphertext = rte_pktmbuf_mtod(buf,
12878                                 uint8_t *);
12879
12880                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
12881                                 ciphertext,
12882                                 tdata->ciphertext.data + off,
12883                                 to_trn_tbl[ecx],
12884                                 "Ciphertext data not as expected");
12885
12886                 off += to_trn_tbl[ecx++];
12887                 buf = buf->next;
12888         }
12889
12890         auth_tag = digest_mem;
12891         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12892                         auth_tag,
12893                         tdata->auth_tag.data,
12894                         tdata->auth_tag.len,
12895                         "Generated auth tag not as expected");
12896
12897         return 0;
12898 }
12899
12900 static int
12901 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
12902 {
12903         return test_authenticated_encryption_SGL(
12904                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
12905 }
12906
12907 static int
12908 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
12909 {
12910         return test_authenticated_encryption_SGL(
12911                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
12912 }
12913
12914 static int
12915 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
12916 {
12917         return test_authenticated_encryption_SGL(
12918                         &gcm_test_case_8, OUT_OF_PLACE, 400,
12919                         gcm_test_case_8.plaintext.len);
12920 }
12921
12922 static int
12923 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
12924 {
12925         /* This test is not for OPENSSL PMD */
12926         if (gbl_driver_id == rte_cryptodev_driver_id_get(
12927                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
12928                 return -ENOTSUP;
12929
12930         return test_authenticated_encryption_SGL(
12931                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
12932 }
12933
12934 static int
12935 test_authentication_verify_fail_when_data_corrupted(
12936                 struct crypto_testsuite_params *ts_params,
12937                 struct crypto_unittest_params *ut_params,
12938                 const struct test_crypto_vector *reference)
12939 {
12940         return test_authentication_verify_fail_when_data_corruption(
12941                         ts_params, ut_params, reference, 1);
12942 }
12943
12944 static int
12945 test_authentication_verify_fail_when_tag_corrupted(
12946                 struct crypto_testsuite_params *ts_params,
12947                 struct crypto_unittest_params *ut_params,
12948                 const struct test_crypto_vector *reference)
12949 {
12950         return test_authentication_verify_fail_when_data_corruption(
12951                         ts_params, ut_params, reference, 0);
12952 }
12953
12954 static int
12955 test_authentication_verify_GMAC_fail_when_data_corrupted(
12956                 struct crypto_testsuite_params *ts_params,
12957                 struct crypto_unittest_params *ut_params,
12958                 const struct test_crypto_vector *reference)
12959 {
12960         return test_authentication_verify_GMAC_fail_when_corruption(
12961                         ts_params, ut_params, reference, 1);
12962 }
12963
12964 static int
12965 test_authentication_verify_GMAC_fail_when_tag_corrupted(
12966                 struct crypto_testsuite_params *ts_params,
12967                 struct crypto_unittest_params *ut_params,
12968                 const struct test_crypto_vector *reference)
12969 {
12970         return test_authentication_verify_GMAC_fail_when_corruption(
12971                         ts_params, ut_params, reference, 0);
12972 }
12973
12974 static int
12975 test_authenticated_decryption_fail_when_data_corrupted(
12976                 struct crypto_testsuite_params *ts_params,
12977                 struct crypto_unittest_params *ut_params,
12978                 const struct test_crypto_vector *reference)
12979 {
12980         return test_authenticated_decryption_fail_when_corruption(
12981                         ts_params, ut_params, reference, 1);
12982 }
12983
12984 static int
12985 test_authenticated_decryption_fail_when_tag_corrupted(
12986                 struct crypto_testsuite_params *ts_params,
12987                 struct crypto_unittest_params *ut_params,
12988                 const struct test_crypto_vector *reference)
12989 {
12990         return test_authenticated_decryption_fail_when_corruption(
12991                         ts_params, ut_params, reference, 0);
12992 }
12993
12994 static int
12995 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
12996 {
12997         return test_authentication_verify_fail_when_data_corrupted(
12998                         &testsuite_params, &unittest_params,
12999                         &hmac_sha1_test_crypto_vector);
13000 }
13001
13002 static int
13003 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13004 {
13005         return test_authentication_verify_fail_when_tag_corrupted(
13006                         &testsuite_params, &unittest_params,
13007                         &hmac_sha1_test_crypto_vector);
13008 }
13009
13010 static int
13011 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
13012 {
13013         return test_authentication_verify_GMAC_fail_when_data_corrupted(
13014                         &testsuite_params, &unittest_params,
13015                         &aes128_gmac_test_vector);
13016 }
13017
13018 static int
13019 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
13020 {
13021         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
13022                         &testsuite_params, &unittest_params,
13023                         &aes128_gmac_test_vector);
13024 }
13025
13026 static int
13027 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
13028 {
13029         return test_authenticated_decryption_fail_when_data_corrupted(
13030                         &testsuite_params,
13031                         &unittest_params,
13032                         &aes128cbc_hmac_sha1_test_vector);
13033 }
13034
13035 static int
13036 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
13037 {
13038         return test_authenticated_decryption_fail_when_tag_corrupted(
13039                         &testsuite_params,
13040                         &unittest_params,
13041                         &aes128cbc_hmac_sha1_test_vector);
13042 }
13043
13044 static int
13045 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13046 {
13047         return test_authenticated_encryt_with_esn(
13048                         &testsuite_params,
13049                         &unittest_params,
13050                         &aes128cbc_hmac_sha1_aad_test_vector);
13051 }
13052
13053 static int
13054 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13055 {
13056         return test_authenticated_decrypt_with_esn(
13057                         &testsuite_params,
13058                         &unittest_params,
13059                         &aes128cbc_hmac_sha1_aad_test_vector);
13060 }
13061
13062 static int
13063 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
13064 {
13065         return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
13066 }
13067
13068 static int
13069 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
13070 {
13071         return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
13072 }
13073
13074 #ifdef RTE_CRYPTO_SCHEDULER
13075
13076 /* global AESNI worker IDs for the scheduler test */
13077 uint8_t aesni_ids[2];
13078
13079 static int
13080 test_scheduler_attach_slave_op(void)
13081 {
13082         struct crypto_testsuite_params *ts_params = &testsuite_params;
13083         uint8_t sched_id = ts_params->valid_devs[0];
13084         uint32_t nb_devs, i, nb_devs_attached = 0;
13085         int ret;
13086         char vdev_name[32];
13087
13088         /* create 2 AESNI_MB if necessary */
13089         nb_devs = rte_cryptodev_device_count_by_driver(
13090                         rte_cryptodev_driver_id_get(
13091                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
13092         if (nb_devs < 2) {
13093                 for (i = nb_devs; i < 2; i++) {
13094                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
13095                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
13096                                         i);
13097                         ret = rte_vdev_init(vdev_name, NULL);
13098
13099                         TEST_ASSERT(ret == 0,
13100                                 "Failed to create instance %u of"
13101                                 " pmd : %s",
13102                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13103                 }
13104         }
13105
13106         /* attach 2 AESNI_MB cdevs */
13107         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
13108                         i++) {
13109                 struct rte_cryptodev_info info;
13110                 unsigned int session_size;
13111
13112                 rte_cryptodev_info_get(i, &info);
13113                 if (info.driver_id != rte_cryptodev_driver_id_get(
13114                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
13115                         continue;
13116
13117                 session_size = rte_cryptodev_sym_get_private_session_size(i);
13118                 /*
13119                  * Create the session mempool again, since now there are new devices
13120                  * to use the mempool.
13121                  */
13122                 if (ts_params->session_mpool) {
13123                         rte_mempool_free(ts_params->session_mpool);
13124                         ts_params->session_mpool = NULL;
13125                 }
13126                 if (ts_params->session_priv_mpool) {
13127                         rte_mempool_free(ts_params->session_priv_mpool);
13128                         ts_params->session_priv_mpool = NULL;
13129                 }
13130
13131                 if (info.sym.max_nb_sessions != 0 &&
13132                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
13133                         RTE_LOG(ERR, USER1,
13134                                         "Device does not support "
13135                                         "at least %u sessions\n",
13136                                         MAX_NB_SESSIONS);
13137                         return TEST_FAILED;
13138                 }
13139                 /*
13140                  * Create mempool with maximum number of sessions,
13141                  * to include the session headers
13142                  */
13143                 if (ts_params->session_mpool == NULL) {
13144                         ts_params->session_mpool =
13145                                 rte_cryptodev_sym_session_pool_create(
13146                                                 "test_sess_mp",
13147                                                 MAX_NB_SESSIONS, 0, 0, 0,
13148                                                 SOCKET_ID_ANY);
13149                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
13150                                         "session mempool allocation failed");
13151                 }
13152
13153                 /*
13154                  * Create mempool with maximum number of sessions,
13155                  * to include device specific session private data
13156                  */
13157                 if (ts_params->session_priv_mpool == NULL) {
13158                         ts_params->session_priv_mpool = rte_mempool_create(
13159                                         "test_sess_mp_priv",
13160                                         MAX_NB_SESSIONS,
13161                                         session_size,
13162                                         0, 0, NULL, NULL, NULL,
13163                                         NULL, SOCKET_ID_ANY,
13164                                         0);
13165
13166                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
13167                                         "session mempool allocation failed");
13168                 }
13169
13170                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
13171                 ts_params->qp_conf.mp_session_private =
13172                                 ts_params->session_priv_mpool;
13173
13174                 ret = rte_cryptodev_scheduler_worker_attach(sched_id,
13175                                 (uint8_t)i);
13176
13177                 TEST_ASSERT(ret == 0,
13178                         "Failed to attach device %u of pmd : %s", i,
13179                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13180
13181                 aesni_ids[nb_devs_attached] = (uint8_t)i;
13182
13183                 nb_devs_attached++;
13184         }
13185
13186         return 0;
13187 }
13188
13189 static int
13190 test_scheduler_detach_slave_op(void)
13191 {
13192         struct crypto_testsuite_params *ts_params = &testsuite_params;
13193         uint8_t sched_id = ts_params->valid_devs[0];
13194         uint32_t i;
13195         int ret;
13196
13197         for (i = 0; i < 2; i++) {
13198                 ret = rte_cryptodev_scheduler_worker_detach(sched_id,
13199                                 aesni_ids[i]);
13200                 TEST_ASSERT(ret == 0,
13201                         "Failed to detach device %u", aesni_ids[i]);
13202         }
13203
13204         return 0;
13205 }
13206
13207 static int
13208 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
13209 {
13210         struct crypto_testsuite_params *ts_params = &testsuite_params;
13211         uint8_t sched_id = ts_params->valid_devs[0];
13212         /* set mode */
13213         return rte_cryptodev_scheduler_mode_set(sched_id,
13214                 scheduler_mode);
13215 }
13216
13217 static int
13218 test_scheduler_mode_roundrobin_op(void)
13219 {
13220         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
13221                         0, "Failed to set roundrobin mode");
13222         return 0;
13223
13224 }
13225
13226 static int
13227 test_scheduler_mode_multicore_op(void)
13228 {
13229         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
13230                         0, "Failed to set multicore mode");
13231
13232         return 0;
13233 }
13234
13235 static int
13236 test_scheduler_mode_failover_op(void)
13237 {
13238         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
13239                         0, "Failed to set failover mode");
13240
13241         return 0;
13242 }
13243
13244 static int
13245 test_scheduler_mode_pkt_size_distr_op(void)
13246 {
13247         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
13248                         0, "Failed to set pktsize mode");
13249
13250         return 0;
13251 }
13252
13253 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
13254         .suite_name = "Crypto Device Scheduler Unit Test Suite",
13255         .setup = testsuite_setup,
13256         .teardown = testsuite_teardown,
13257         .unit_test_cases = {
13258                 /* Multi Core */
13259                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
13260                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op),
13261                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13262                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13263                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13264                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
13265
13266                 /* Round Robin */
13267                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
13268                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op),
13269                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13270                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13271                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13272                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
13273
13274                 /* Fail over */
13275                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
13276                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op),
13277                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13278                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13279                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13280                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
13281
13282                 /* PKT SIZE */
13283                 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
13284                 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op),
13285                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13286                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13287                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13288                 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
13289
13290                 TEST_CASES_END() /**< NULL terminate unit test array */
13291         }
13292 };
13293
13294 #endif /* RTE_CRYPTO_SCHEDULER */
13295
13296 static struct unit_test_suite cryptodev_testsuite  = {
13297         .suite_name = "Crypto Unit Test Suite",
13298         .setup = testsuite_setup,
13299         .teardown = testsuite_teardown,
13300         .unit_test_cases = {
13301                 TEST_CASE_ST(ut_setup, ut_teardown,
13302                                 test_device_configure_invalid_dev_id),
13303                 TEST_CASE_ST(ut_setup, ut_teardown,
13304                                 test_queue_pair_descriptor_setup),
13305                 TEST_CASE_ST(ut_setup, ut_teardown,
13306                                 test_device_configure_invalid_queue_pair_ids),
13307                 TEST_CASE_ST(ut_setup, ut_teardown,
13308                                 test_multi_session),
13309                 TEST_CASE_ST(ut_setup, ut_teardown,
13310                                 test_multi_session_random_usage),
13311
13312                 TEST_CASE_ST(ut_setup, ut_teardown,
13313                         test_null_invalid_operation),
13314                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
13315                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13316                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13317                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13318                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13319                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all),
13320                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all),
13321                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all),
13322                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13323                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
13324
13325                 /** AES CCM Authenticated Encryption 128 bits key */
13326                 TEST_CASE_ST(ut_setup, ut_teardown,
13327                         test_AES_CCM_authenticated_encryption_test_case_128_1),
13328                 TEST_CASE_ST(ut_setup, ut_teardown,
13329                         test_AES_CCM_authenticated_encryption_test_case_128_2),
13330                 TEST_CASE_ST(ut_setup, ut_teardown,
13331                         test_AES_CCM_authenticated_encryption_test_case_128_3),
13332
13333                 /** AES CCM Authenticated Decryption 128 bits key*/
13334                 TEST_CASE_ST(ut_setup, ut_teardown,
13335                         test_AES_CCM_authenticated_decryption_test_case_128_1),
13336                 TEST_CASE_ST(ut_setup, ut_teardown,
13337                         test_AES_CCM_authenticated_decryption_test_case_128_2),
13338                 TEST_CASE_ST(ut_setup, ut_teardown,
13339                         test_AES_CCM_authenticated_decryption_test_case_128_3),
13340
13341                 /** AES CCM Authenticated Encryption 192 bits key */
13342                 TEST_CASE_ST(ut_setup, ut_teardown,
13343                         test_AES_CCM_authenticated_encryption_test_case_192_1),
13344                 TEST_CASE_ST(ut_setup, ut_teardown,
13345                         test_AES_CCM_authenticated_encryption_test_case_192_2),
13346                 TEST_CASE_ST(ut_setup, ut_teardown,
13347                         test_AES_CCM_authenticated_encryption_test_case_192_3),
13348
13349                 /** AES CCM Authenticated Decryption 192 bits key*/
13350                 TEST_CASE_ST(ut_setup, ut_teardown,
13351                         test_AES_CCM_authenticated_decryption_test_case_192_1),
13352                 TEST_CASE_ST(ut_setup, ut_teardown,
13353                         test_AES_CCM_authenticated_decryption_test_case_192_2),
13354                 TEST_CASE_ST(ut_setup, ut_teardown,
13355                         test_AES_CCM_authenticated_decryption_test_case_192_3),
13356
13357                 /** AES CCM Authenticated Encryption 256 bits key */
13358                 TEST_CASE_ST(ut_setup, ut_teardown,
13359                         test_AES_CCM_authenticated_encryption_test_case_256_1),
13360                 TEST_CASE_ST(ut_setup, ut_teardown,
13361                         test_AES_CCM_authenticated_encryption_test_case_256_2),
13362                 TEST_CASE_ST(ut_setup, ut_teardown,
13363                         test_AES_CCM_authenticated_encryption_test_case_256_3),
13364
13365                 /** AES CCM Authenticated Decryption 256 bits key*/
13366                 TEST_CASE_ST(ut_setup, ut_teardown,
13367                         test_AES_CCM_authenticated_decryption_test_case_256_1),
13368                 TEST_CASE_ST(ut_setup, ut_teardown,
13369                         test_AES_CCM_authenticated_decryption_test_case_256_2),
13370                 TEST_CASE_ST(ut_setup, ut_teardown,
13371                         test_AES_CCM_authenticated_decryption_test_case_256_3),
13372
13373                 /** AES GCM Authenticated Encryption */
13374                 TEST_CASE_ST(ut_setup, ut_teardown,
13375                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
13376                 TEST_CASE_ST(ut_setup, ut_teardown,
13377                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
13378                 TEST_CASE_ST(ut_setup, ut_teardown,
13379                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
13380                 TEST_CASE_ST(ut_setup, ut_teardown,
13381                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
13382                 TEST_CASE_ST(ut_setup, ut_teardown,
13383                         test_AES_GCM_authenticated_encryption_test_case_1),
13384                 TEST_CASE_ST(ut_setup, ut_teardown,
13385                         test_AES_GCM_authenticated_encryption_test_case_2),
13386                 TEST_CASE_ST(ut_setup, ut_teardown,
13387                         test_AES_GCM_authenticated_encryption_test_case_3),
13388                 TEST_CASE_ST(ut_setup, ut_teardown,
13389                         test_AES_GCM_authenticated_encryption_test_case_4),
13390                 TEST_CASE_ST(ut_setup, ut_teardown,
13391                         test_AES_GCM_authenticated_encryption_test_case_5),
13392                 TEST_CASE_ST(ut_setup, ut_teardown,
13393                         test_AES_GCM_authenticated_encryption_test_case_6),
13394                 TEST_CASE_ST(ut_setup, ut_teardown,
13395                         test_AES_GCM_authenticated_encryption_test_case_7),
13396                 TEST_CASE_ST(ut_setup, ut_teardown,
13397                         test_AES_GCM_authenticated_encryption_test_case_8),
13398                 TEST_CASE_ST(ut_setup, ut_teardown,
13399                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
13400
13401                 /** AES GCM Authenticated Decryption */
13402                 TEST_CASE_ST(ut_setup, ut_teardown,
13403                         test_AES_GCM_authenticated_decryption_test_case_1),
13404                 TEST_CASE_ST(ut_setup, ut_teardown,
13405                         test_AES_GCM_authenticated_decryption_test_case_2),
13406                 TEST_CASE_ST(ut_setup, ut_teardown,
13407                         test_AES_GCM_authenticated_decryption_test_case_3),
13408                 TEST_CASE_ST(ut_setup, ut_teardown,
13409                         test_AES_GCM_authenticated_decryption_test_case_4),
13410                 TEST_CASE_ST(ut_setup, ut_teardown,
13411                         test_AES_GCM_authenticated_decryption_test_case_5),
13412                 TEST_CASE_ST(ut_setup, ut_teardown,
13413                         test_AES_GCM_authenticated_decryption_test_case_6),
13414                 TEST_CASE_ST(ut_setup, ut_teardown,
13415                         test_AES_GCM_authenticated_decryption_test_case_7),
13416                 TEST_CASE_ST(ut_setup, ut_teardown,
13417                         test_AES_GCM_authenticated_decryption_test_case_8),
13418                 TEST_CASE_ST(ut_setup, ut_teardown,
13419                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
13420
13421                 /** AES GCM Authenticated Encryption 192 bits key */
13422                 TEST_CASE_ST(ut_setup, ut_teardown,
13423                         test_AES_GCM_auth_encryption_test_case_192_1),
13424                 TEST_CASE_ST(ut_setup, ut_teardown,
13425                         test_AES_GCM_auth_encryption_test_case_192_2),
13426                 TEST_CASE_ST(ut_setup, ut_teardown,
13427                         test_AES_GCM_auth_encryption_test_case_192_3),
13428                 TEST_CASE_ST(ut_setup, ut_teardown,
13429                         test_AES_GCM_auth_encryption_test_case_192_4),
13430                 TEST_CASE_ST(ut_setup, ut_teardown,
13431                         test_AES_GCM_auth_encryption_test_case_192_5),
13432                 TEST_CASE_ST(ut_setup, ut_teardown,
13433                         test_AES_GCM_auth_encryption_test_case_192_6),
13434                 TEST_CASE_ST(ut_setup, ut_teardown,
13435                         test_AES_GCM_auth_encryption_test_case_192_7),
13436
13437                 /** AES GCM Authenticated Decryption 192 bits key */
13438                 TEST_CASE_ST(ut_setup, ut_teardown,
13439                         test_AES_GCM_auth_decryption_test_case_192_1),
13440                 TEST_CASE_ST(ut_setup, ut_teardown,
13441                         test_AES_GCM_auth_decryption_test_case_192_2),
13442                 TEST_CASE_ST(ut_setup, ut_teardown,
13443                         test_AES_GCM_auth_decryption_test_case_192_3),
13444                 TEST_CASE_ST(ut_setup, ut_teardown,
13445                         test_AES_GCM_auth_decryption_test_case_192_4),
13446                 TEST_CASE_ST(ut_setup, ut_teardown,
13447                         test_AES_GCM_auth_decryption_test_case_192_5),
13448                 TEST_CASE_ST(ut_setup, ut_teardown,
13449                         test_AES_GCM_auth_decryption_test_case_192_6),
13450                 TEST_CASE_ST(ut_setup, ut_teardown,
13451                         test_AES_GCM_auth_decryption_test_case_192_7),
13452
13453                 /** AES GCM Authenticated Encryption 256 bits key */
13454                 TEST_CASE_ST(ut_setup, ut_teardown,
13455                         test_AES_GCM_auth_encryption_test_case_256_1),
13456                 TEST_CASE_ST(ut_setup, ut_teardown,
13457                         test_AES_GCM_auth_encryption_test_case_256_2),
13458                 TEST_CASE_ST(ut_setup, ut_teardown,
13459                         test_AES_GCM_auth_encryption_test_case_256_3),
13460                 TEST_CASE_ST(ut_setup, ut_teardown,
13461                         test_AES_GCM_auth_encryption_test_case_256_4),
13462                 TEST_CASE_ST(ut_setup, ut_teardown,
13463                         test_AES_GCM_auth_encryption_test_case_256_5),
13464                 TEST_CASE_ST(ut_setup, ut_teardown,
13465                         test_AES_GCM_auth_encryption_test_case_256_6),
13466                 TEST_CASE_ST(ut_setup, ut_teardown,
13467                         test_AES_GCM_auth_encryption_test_case_256_7),
13468
13469                 /** AES GCM Authenticated Decryption 256 bits key */
13470                 TEST_CASE_ST(ut_setup, ut_teardown,
13471                         test_AES_GCM_auth_decryption_test_case_256_1),
13472                 TEST_CASE_ST(ut_setup, ut_teardown,
13473                         test_AES_GCM_auth_decryption_test_case_256_2),
13474                 TEST_CASE_ST(ut_setup, ut_teardown,
13475                         test_AES_GCM_auth_decryption_test_case_256_3),
13476                 TEST_CASE_ST(ut_setup, ut_teardown,
13477                         test_AES_GCM_auth_decryption_test_case_256_4),
13478                 TEST_CASE_ST(ut_setup, ut_teardown,
13479                         test_AES_GCM_auth_decryption_test_case_256_5),
13480                 TEST_CASE_ST(ut_setup, ut_teardown,
13481                         test_AES_GCM_auth_decryption_test_case_256_6),
13482                 TEST_CASE_ST(ut_setup, ut_teardown,
13483                         test_AES_GCM_auth_decryption_test_case_256_7),
13484
13485                 /** AES GCM Authenticated Encryption big aad size */
13486                 TEST_CASE_ST(ut_setup, ut_teardown,
13487                         test_AES_GCM_auth_encryption_test_case_aad_1),
13488                 TEST_CASE_ST(ut_setup, ut_teardown,
13489                         test_AES_GCM_auth_encryption_test_case_aad_2),
13490
13491                 /** AES GCM Authenticated Decryption big aad size */
13492                 TEST_CASE_ST(ut_setup, ut_teardown,
13493                         test_AES_GCM_auth_decryption_test_case_aad_1),
13494                 TEST_CASE_ST(ut_setup, ut_teardown,
13495                         test_AES_GCM_auth_decryption_test_case_aad_2),
13496
13497                 /** Out of place tests */
13498                 TEST_CASE_ST(ut_setup, ut_teardown,
13499                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
13500                 TEST_CASE_ST(ut_setup, ut_teardown,
13501                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
13502
13503                 /** Session-less tests */
13504                 TEST_CASE_ST(ut_setup, ut_teardown,
13505                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
13506                 TEST_CASE_ST(ut_setup, ut_teardown,
13507                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
13508
13509                 /** AES GMAC Authentication */
13510                 TEST_CASE_ST(ut_setup, ut_teardown,
13511                         test_AES_GMAC_authentication_test_case_1),
13512                 TEST_CASE_ST(ut_setup, ut_teardown,
13513                         test_AES_GMAC_authentication_verify_test_case_1),
13514                 TEST_CASE_ST(ut_setup, ut_teardown,
13515                         test_AES_GMAC_authentication_test_case_2),
13516                 TEST_CASE_ST(ut_setup, ut_teardown,
13517                         test_AES_GMAC_authentication_verify_test_case_2),
13518                 TEST_CASE_ST(ut_setup, ut_teardown,
13519                         test_AES_GMAC_authentication_test_case_3),
13520                 TEST_CASE_ST(ut_setup, ut_teardown,
13521                         test_AES_GMAC_authentication_verify_test_case_3),
13522                 TEST_CASE_ST(ut_setup, ut_teardown,
13523                         test_AES_GMAC_authentication_test_case_4),
13524                 TEST_CASE_ST(ut_setup, ut_teardown,
13525                         test_AES_GMAC_authentication_verify_test_case_4),
13526                 TEST_CASE_ST(ut_setup, ut_teardown,
13527                         test_AES_GMAC_authentication_SGL_40B),
13528                 TEST_CASE_ST(ut_setup, ut_teardown,
13529                         test_AES_GMAC_authentication_SGL_80B),
13530                 TEST_CASE_ST(ut_setup, ut_teardown,
13531                         test_AES_GMAC_authentication_SGL_2048B),
13532                 TEST_CASE_ST(ut_setup, ut_teardown,
13533                         test_AES_GMAC_authentication_SGL_2047B),
13534
13535                 /** Chacha20-Poly1305 */
13536                 TEST_CASE_ST(ut_setup, ut_teardown,
13537                         test_chacha20_poly1305_encrypt_test_case_rfc8439),
13538                 TEST_CASE_ST(ut_setup, ut_teardown,
13539                         test_chacha20_poly1305_decrypt_test_case_rfc8439),
13540                 /** SNOW 3G encrypt only (UEA2) */
13541                 TEST_CASE_ST(ut_setup, ut_teardown,
13542                         test_snow3g_encryption_test_case_1),
13543                 TEST_CASE_ST(ut_setup, ut_teardown,
13544                         test_snow3g_encryption_test_case_2),
13545                 TEST_CASE_ST(ut_setup, ut_teardown,
13546                         test_snow3g_encryption_test_case_3),
13547                 TEST_CASE_ST(ut_setup, ut_teardown,
13548                         test_snow3g_encryption_test_case_4),
13549                 TEST_CASE_ST(ut_setup, ut_teardown,
13550                         test_snow3g_encryption_test_case_5),
13551
13552                 TEST_CASE_ST(ut_setup, ut_teardown,
13553                         test_snow3g_encryption_test_case_1_oop),
13554                 TEST_CASE_ST(ut_setup, ut_teardown,
13555                         test_snow3g_encryption_test_case_1_oop_sgl),
13556                 TEST_CASE_ST(ut_setup, ut_teardown,
13557                         test_snow3g_encryption_test_case_1_offset_oop),
13558                 TEST_CASE_ST(ut_setup, ut_teardown,
13559                         test_snow3g_decryption_test_case_1_oop),
13560
13561                 /** SNOW 3G generate auth, then encrypt (UEA2) */
13562                 TEST_CASE_ST(ut_setup, ut_teardown,
13563                         test_snow3g_auth_cipher_test_case_1),
13564                 TEST_CASE_ST(ut_setup, ut_teardown,
13565                         test_snow3g_auth_cipher_test_case_2),
13566                 TEST_CASE_ST(ut_setup, ut_teardown,
13567                         test_snow3g_auth_cipher_test_case_2_oop),
13568                 TEST_CASE_ST(ut_setup, ut_teardown,
13569                         test_snow3g_auth_cipher_part_digest_enc),
13570                 TEST_CASE_ST(ut_setup, ut_teardown,
13571                         test_snow3g_auth_cipher_part_digest_enc_oop),
13572                 TEST_CASE_ST(ut_setup, ut_teardown,
13573                         test_snow3g_auth_cipher_test_case_3_sgl),
13574                 TEST_CASE_ST(ut_setup, ut_teardown,
13575                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
13576                 TEST_CASE_ST(ut_setup, ut_teardown,
13577                         test_snow3g_auth_cipher_part_digest_enc_sgl),
13578                 TEST_CASE_ST(ut_setup, ut_teardown,
13579                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
13580
13581                 /** SNOW 3G decrypt (UEA2), then verify auth */
13582                 TEST_CASE_ST(ut_setup, ut_teardown,
13583                         test_snow3g_auth_cipher_verify_test_case_1),
13584                 TEST_CASE_ST(ut_setup, ut_teardown,
13585                         test_snow3g_auth_cipher_verify_test_case_2),
13586                 TEST_CASE_ST(ut_setup, ut_teardown,
13587                         test_snow3g_auth_cipher_verify_test_case_2_oop),
13588                 TEST_CASE_ST(ut_setup, ut_teardown,
13589                         test_snow3g_auth_cipher_verify_part_digest_enc),
13590                 TEST_CASE_ST(ut_setup, ut_teardown,
13591                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
13592                 TEST_CASE_ST(ut_setup, ut_teardown,
13593                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
13594                 TEST_CASE_ST(ut_setup, ut_teardown,
13595                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
13596                 TEST_CASE_ST(ut_setup, ut_teardown,
13597                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
13598                 TEST_CASE_ST(ut_setup, ut_teardown,
13599                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
13600
13601                 /** SNOW 3G decrypt only (UEA2) */
13602                 TEST_CASE_ST(ut_setup, ut_teardown,
13603                         test_snow3g_decryption_test_case_1),
13604                 TEST_CASE_ST(ut_setup, ut_teardown,
13605                         test_snow3g_decryption_test_case_2),
13606                 TEST_CASE_ST(ut_setup, ut_teardown,
13607                         test_snow3g_decryption_test_case_3),
13608                 TEST_CASE_ST(ut_setup, ut_teardown,
13609                         test_snow3g_decryption_test_case_4),
13610                 TEST_CASE_ST(ut_setup, ut_teardown,
13611                         test_snow3g_decryption_test_case_5),
13612                 TEST_CASE_ST(ut_setup, ut_teardown,
13613                         test_snow3g_decryption_with_digest_test_case_1),
13614                 TEST_CASE_ST(ut_setup, ut_teardown,
13615                         test_snow3g_hash_generate_test_case_1),
13616                 TEST_CASE_ST(ut_setup, ut_teardown,
13617                         test_snow3g_hash_generate_test_case_2),
13618                 TEST_CASE_ST(ut_setup, ut_teardown,
13619                         test_snow3g_hash_generate_test_case_3),
13620                 /* Tests with buffers which length is not byte-aligned */
13621                 TEST_CASE_ST(ut_setup, ut_teardown,
13622                         test_snow3g_hash_generate_test_case_4),
13623                 TEST_CASE_ST(ut_setup, ut_teardown,
13624                         test_snow3g_hash_generate_test_case_5),
13625                 TEST_CASE_ST(ut_setup, ut_teardown,
13626                         test_snow3g_hash_generate_test_case_6),
13627                 TEST_CASE_ST(ut_setup, ut_teardown,
13628                         test_snow3g_hash_verify_test_case_1),
13629                 TEST_CASE_ST(ut_setup, ut_teardown,
13630                         test_snow3g_hash_verify_test_case_2),
13631                 TEST_CASE_ST(ut_setup, ut_teardown,
13632                         test_snow3g_hash_verify_test_case_3),
13633                 /* Tests with buffers which length is not byte-aligned */
13634                 TEST_CASE_ST(ut_setup, ut_teardown,
13635                         test_snow3g_hash_verify_test_case_4),
13636                 TEST_CASE_ST(ut_setup, ut_teardown,
13637                         test_snow3g_hash_verify_test_case_5),
13638                 TEST_CASE_ST(ut_setup, ut_teardown,
13639                         test_snow3g_hash_verify_test_case_6),
13640                 TEST_CASE_ST(ut_setup, ut_teardown,
13641                         test_snow3g_cipher_auth_test_case_1),
13642                 TEST_CASE_ST(ut_setup, ut_teardown,
13643                         test_snow3g_auth_cipher_with_digest_test_case_1),
13644
13645                 /** ZUC encrypt only (EEA3) */
13646                 TEST_CASE_ST(ut_setup, ut_teardown,
13647                         test_zuc_encryption_test_case_1),
13648                 TEST_CASE_ST(ut_setup, ut_teardown,
13649                         test_zuc_encryption_test_case_2),
13650                 TEST_CASE_ST(ut_setup, ut_teardown,
13651                         test_zuc_encryption_test_case_3),
13652                 TEST_CASE_ST(ut_setup, ut_teardown,
13653                         test_zuc_encryption_test_case_4),
13654                 TEST_CASE_ST(ut_setup, ut_teardown,
13655                         test_zuc_encryption_test_case_5),
13656                 TEST_CASE_ST(ut_setup, ut_teardown,
13657                         test_zuc_encryption_test_case_6_sgl),
13658
13659                 /** ZUC authenticate (EIA3) */
13660                 TEST_CASE_ST(ut_setup, ut_teardown,
13661                         test_zuc_hash_generate_test_case_1),
13662                 TEST_CASE_ST(ut_setup, ut_teardown,
13663                         test_zuc_hash_generate_test_case_2),
13664                 TEST_CASE_ST(ut_setup, ut_teardown,
13665                         test_zuc_hash_generate_test_case_3),
13666                 TEST_CASE_ST(ut_setup, ut_teardown,
13667                         test_zuc_hash_generate_test_case_4),
13668                 TEST_CASE_ST(ut_setup, ut_teardown,
13669                         test_zuc_hash_generate_test_case_5),
13670                 TEST_CASE_ST(ut_setup, ut_teardown,
13671                         test_zuc_hash_generate_test_case_6),
13672                 TEST_CASE_ST(ut_setup, ut_teardown,
13673                         test_zuc_hash_generate_test_case_7),
13674                 TEST_CASE_ST(ut_setup, ut_teardown,
13675                         test_zuc_hash_generate_test_case_8),
13676
13677                 /** ZUC alg-chain (EEA3/EIA3) */
13678                 TEST_CASE_ST(ut_setup, ut_teardown,
13679                         test_zuc_cipher_auth_test_case_1),
13680                 TEST_CASE_ST(ut_setup, ut_teardown,
13681                         test_zuc_cipher_auth_test_case_2),
13682
13683                 /** ZUC generate auth, then encrypt (EEA3) */
13684                 TEST_CASE_ST(ut_setup, ut_teardown,
13685                         test_zuc_auth_cipher_test_case_1),
13686                 TEST_CASE_ST(ut_setup, ut_teardown,
13687                         test_zuc_auth_cipher_test_case_1_oop),
13688                 TEST_CASE_ST(ut_setup, ut_teardown,
13689                         test_zuc_auth_cipher_test_case_1_sgl),
13690                 TEST_CASE_ST(ut_setup, ut_teardown,
13691                         test_zuc_auth_cipher_test_case_1_oop_sgl),
13692
13693                 /** ZUC decrypt (EEA3), then verify auth */
13694                 TEST_CASE_ST(ut_setup, ut_teardown,
13695                         test_zuc_auth_cipher_verify_test_case_1),
13696                 TEST_CASE_ST(ut_setup, ut_teardown,
13697                         test_zuc_auth_cipher_verify_test_case_1_oop),
13698                 TEST_CASE_ST(ut_setup, ut_teardown,
13699                         test_zuc_auth_cipher_verify_test_case_1_sgl),
13700                 TEST_CASE_ST(ut_setup, ut_teardown,
13701                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
13702
13703                 /** HMAC_MD5 Authentication */
13704                 TEST_CASE_ST(ut_setup, ut_teardown,
13705                         test_MD5_HMAC_generate_case_1),
13706                 TEST_CASE_ST(ut_setup, ut_teardown,
13707                         test_MD5_HMAC_verify_case_1),
13708                 TEST_CASE_ST(ut_setup, ut_teardown,
13709                         test_MD5_HMAC_generate_case_2),
13710                 TEST_CASE_ST(ut_setup, ut_teardown,
13711                         test_MD5_HMAC_verify_case_2),
13712
13713                 /** KASUMI hash only (UIA1) */
13714                 TEST_CASE_ST(ut_setup, ut_teardown,
13715                         test_kasumi_hash_generate_test_case_1),
13716                 TEST_CASE_ST(ut_setup, ut_teardown,
13717                         test_kasumi_hash_generate_test_case_2),
13718                 TEST_CASE_ST(ut_setup, ut_teardown,
13719                         test_kasumi_hash_generate_test_case_3),
13720                 TEST_CASE_ST(ut_setup, ut_teardown,
13721                         test_kasumi_hash_generate_test_case_4),
13722                 TEST_CASE_ST(ut_setup, ut_teardown,
13723                         test_kasumi_hash_generate_test_case_5),
13724                 TEST_CASE_ST(ut_setup, ut_teardown,
13725                         test_kasumi_hash_generate_test_case_6),
13726
13727                 TEST_CASE_ST(ut_setup, ut_teardown,
13728                         test_kasumi_hash_verify_test_case_1),
13729                 TEST_CASE_ST(ut_setup, ut_teardown,
13730                         test_kasumi_hash_verify_test_case_2),
13731                 TEST_CASE_ST(ut_setup, ut_teardown,
13732                         test_kasumi_hash_verify_test_case_3),
13733                 TEST_CASE_ST(ut_setup, ut_teardown,
13734                         test_kasumi_hash_verify_test_case_4),
13735                 TEST_CASE_ST(ut_setup, ut_teardown,
13736                         test_kasumi_hash_verify_test_case_5),
13737
13738                 /** KASUMI encrypt only (UEA1) */
13739                 TEST_CASE_ST(ut_setup, ut_teardown,
13740                         test_kasumi_encryption_test_case_1),
13741                 TEST_CASE_ST(ut_setup, ut_teardown,
13742                         test_kasumi_encryption_test_case_1_sgl),
13743                 TEST_CASE_ST(ut_setup, ut_teardown,
13744                         test_kasumi_encryption_test_case_1_oop),
13745                 TEST_CASE_ST(ut_setup, ut_teardown,
13746                         test_kasumi_encryption_test_case_1_oop_sgl),
13747                 TEST_CASE_ST(ut_setup, ut_teardown,
13748                         test_kasumi_encryption_test_case_2),
13749                 TEST_CASE_ST(ut_setup, ut_teardown,
13750                         test_kasumi_encryption_test_case_3),
13751                 TEST_CASE_ST(ut_setup, ut_teardown,
13752                         test_kasumi_encryption_test_case_4),
13753                 TEST_CASE_ST(ut_setup, ut_teardown,
13754                         test_kasumi_encryption_test_case_5),
13755
13756                 /** KASUMI decrypt only (UEA1) */
13757                 TEST_CASE_ST(ut_setup, ut_teardown,
13758                         test_kasumi_decryption_test_case_1),
13759                 TEST_CASE_ST(ut_setup, ut_teardown,
13760                         test_kasumi_decryption_test_case_2),
13761                 TEST_CASE_ST(ut_setup, ut_teardown,
13762                         test_kasumi_decryption_test_case_3),
13763                 TEST_CASE_ST(ut_setup, ut_teardown,
13764                         test_kasumi_decryption_test_case_4),
13765                 TEST_CASE_ST(ut_setup, ut_teardown,
13766                         test_kasumi_decryption_test_case_5),
13767                 TEST_CASE_ST(ut_setup, ut_teardown,
13768                         test_kasumi_decryption_test_case_1_oop),
13769
13770                 TEST_CASE_ST(ut_setup, ut_teardown,
13771                         test_kasumi_cipher_auth_test_case_1),
13772
13773                 /** KASUMI generate auth, then encrypt (F8) */
13774                 TEST_CASE_ST(ut_setup, ut_teardown,
13775                         test_kasumi_auth_cipher_test_case_1),
13776                 TEST_CASE_ST(ut_setup, ut_teardown,
13777                         test_kasumi_auth_cipher_test_case_2),
13778                 TEST_CASE_ST(ut_setup, ut_teardown,
13779                         test_kasumi_auth_cipher_test_case_2_oop),
13780                 TEST_CASE_ST(ut_setup, ut_teardown,
13781                         test_kasumi_auth_cipher_test_case_2_sgl),
13782                 TEST_CASE_ST(ut_setup, ut_teardown,
13783                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
13784
13785                 /** KASUMI decrypt (F8), then verify auth */
13786                 TEST_CASE_ST(ut_setup, ut_teardown,
13787                         test_kasumi_auth_cipher_verify_test_case_1),
13788                 TEST_CASE_ST(ut_setup, ut_teardown,
13789                         test_kasumi_auth_cipher_verify_test_case_2),
13790                 TEST_CASE_ST(ut_setup, ut_teardown,
13791                         test_kasumi_auth_cipher_verify_test_case_2_oop),
13792                 TEST_CASE_ST(ut_setup, ut_teardown,
13793                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
13794                 TEST_CASE_ST(ut_setup, ut_teardown,
13795                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
13796
13797                 /** ESN Testcase */
13798                 TEST_CASE_ST(ut_setup, ut_teardown,
13799                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
13800                 TEST_CASE_ST(ut_setup, ut_teardown,
13801                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
13802
13803                 /** Negative tests */
13804                 TEST_CASE_ST(ut_setup, ut_teardown,
13805                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13806                 TEST_CASE_ST(ut_setup, ut_teardown,
13807                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13808                 TEST_CASE_ST(ut_setup, ut_teardown,
13809                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
13810                 TEST_CASE_ST(ut_setup, ut_teardown,
13811                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
13812                 TEST_CASE_ST(ut_setup, ut_teardown,
13813                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
13814                 TEST_CASE_ST(ut_setup, ut_teardown,
13815                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
13816                 TEST_CASE_ST(ut_setup, ut_teardown,
13817                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
13818                 TEST_CASE_ST(ut_setup, ut_teardown,
13819                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
13820                 TEST_CASE_ST(ut_setup, ut_teardown,
13821                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
13822                 TEST_CASE_ST(ut_setup, ut_teardown,
13823                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
13824                 TEST_CASE_ST(ut_setup, ut_teardown,
13825                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
13826                 TEST_CASE_ST(ut_setup, ut_teardown,
13827                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
13828                 TEST_CASE_ST(ut_setup, ut_teardown,
13829                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
13830                 TEST_CASE_ST(ut_setup, ut_teardown,
13831                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
13832                 TEST_CASE_ST(ut_setup, ut_teardown,
13833                         authentication_verify_AES128_GMAC_fail_data_corrupt),
13834                 TEST_CASE_ST(ut_setup, ut_teardown,
13835                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
13836                 TEST_CASE_ST(ut_setup, ut_teardown,
13837                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13838                 TEST_CASE_ST(ut_setup, ut_teardown,
13839                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13840
13841                 /** Mixed CIPHER + HASH algorithms */
13842                 /** AUTH AES CMAC + CIPHER AES CTR */
13843                 TEST_CASE_ST(ut_setup, ut_teardown,
13844                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
13845                 TEST_CASE_ST(ut_setup, ut_teardown,
13846                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
13847                 TEST_CASE_ST(ut_setup, ut_teardown,
13848                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
13849                 TEST_CASE_ST(ut_setup, ut_teardown,
13850                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
13851                 TEST_CASE_ST(ut_setup, ut_teardown,
13852                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
13853                 TEST_CASE_ST(ut_setup, ut_teardown,
13854                        test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
13855                 TEST_CASE_ST(ut_setup, ut_teardown,
13856                        test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
13857                 TEST_CASE_ST(ut_setup, ut_teardown,
13858                    test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
13859
13860                 /** AUTH ZUC + CIPHER SNOW3G */
13861                 TEST_CASE_ST(ut_setup, ut_teardown,
13862                         test_auth_zuc_cipher_snow_test_case_1),
13863                 TEST_CASE_ST(ut_setup, ut_teardown,
13864                         test_verify_auth_zuc_cipher_snow_test_case_1),
13865                 /** AUTH AES CMAC + CIPHER SNOW3G */
13866                 TEST_CASE_ST(ut_setup, ut_teardown,
13867                         test_auth_aes_cmac_cipher_snow_test_case_1),
13868                 TEST_CASE_ST(ut_setup, ut_teardown,
13869                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
13870                 /** AUTH ZUC + CIPHER AES CTR */
13871                 TEST_CASE_ST(ut_setup, ut_teardown,
13872                         test_auth_zuc_cipher_aes_ctr_test_case_1),
13873                 TEST_CASE_ST(ut_setup, ut_teardown,
13874                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
13875                 /** AUTH SNOW3G + CIPHER AES CTR */
13876                 TEST_CASE_ST(ut_setup, ut_teardown,
13877                         test_auth_snow_cipher_aes_ctr_test_case_1),
13878                 TEST_CASE_ST(ut_setup, ut_teardown,
13879                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
13880                 /** AUTH SNOW3G + CIPHER ZUC */
13881                 TEST_CASE_ST(ut_setup, ut_teardown,
13882                         test_auth_snow_cipher_zuc_test_case_1),
13883                 TEST_CASE_ST(ut_setup, ut_teardown,
13884                         test_verify_auth_snow_cipher_zuc_test_case_1),
13885                 /** AUTH AES CMAC + CIPHER ZUC */
13886                 TEST_CASE_ST(ut_setup, ut_teardown,
13887                         test_auth_aes_cmac_cipher_zuc_test_case_1),
13888                 TEST_CASE_ST(ut_setup, ut_teardown,
13889                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
13890
13891                 /** AUTH NULL + CIPHER SNOW3G */
13892                 TEST_CASE_ST(ut_setup, ut_teardown,
13893                         test_auth_null_cipher_snow_test_case_1),
13894                 TEST_CASE_ST(ut_setup, ut_teardown,
13895                         test_verify_auth_null_cipher_snow_test_case_1),
13896                 /** AUTH NULL + CIPHER ZUC */
13897                 TEST_CASE_ST(ut_setup, ut_teardown,
13898                         test_auth_null_cipher_zuc_test_case_1),
13899                 TEST_CASE_ST(ut_setup, ut_teardown,
13900                         test_verify_auth_null_cipher_zuc_test_case_1),
13901                 /** AUTH SNOW3G + CIPHER NULL */
13902                 TEST_CASE_ST(ut_setup, ut_teardown,
13903                         test_auth_snow_cipher_null_test_case_1),
13904                 TEST_CASE_ST(ut_setup, ut_teardown,
13905                         test_verify_auth_snow_cipher_null_test_case_1),
13906                 /** AUTH ZUC + CIPHER NULL */
13907                 TEST_CASE_ST(ut_setup, ut_teardown,
13908                         test_auth_zuc_cipher_null_test_case_1),
13909                 TEST_CASE_ST(ut_setup, ut_teardown,
13910                         test_verify_auth_zuc_cipher_null_test_case_1),
13911                 /** AUTH NULL + CIPHER AES CTR */
13912                 TEST_CASE_ST(ut_setup, ut_teardown,
13913                         test_auth_null_cipher_aes_ctr_test_case_1),
13914                 TEST_CASE_ST(ut_setup, ut_teardown,
13915                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
13916                 /** AUTH AES CMAC + CIPHER NULL */
13917                 TEST_CASE_ST(ut_setup, ut_teardown,
13918                         test_auth_aes_cmac_cipher_null_test_case_1),
13919                 TEST_CASE_ST(ut_setup, ut_teardown,
13920                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
13921
13922 #ifdef RTE_LIB_SECURITY
13923                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13924                         test_PDCP_PROTO_all),
13925                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13926                         test_DOCSIS_PROTO_all),
13927 #endif
13928                 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
13929                 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
13930                 TEST_CASES_END() /**< NULL terminate unit test array */
13931         }
13932 };
13933
13934 static struct unit_test_suite cryptodev_virtio_testsuite = {
13935         .suite_name = "Crypto VIRTIO Unit Test Suite",
13936         .setup = testsuite_setup,
13937         .teardown = testsuite_teardown,
13938         .unit_test_cases = {
13939                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13940
13941                 TEST_CASES_END() /**< NULL terminate unit test array */
13942         }
13943 };
13944
13945 static struct unit_test_suite cryptodev_caam_jr_testsuite  = {
13946         .suite_name = "Crypto CAAM JR Unit Test Suite",
13947         .setup = testsuite_setup,
13948         .teardown = testsuite_teardown,
13949         .unit_test_cases = {
13950                 TEST_CASE_ST(ut_setup, ut_teardown,
13951                              test_device_configure_invalid_dev_id),
13952                 TEST_CASE_ST(ut_setup, ut_teardown,
13953                              test_multi_session),
13954
13955                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13956                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13957                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13958                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13959                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13960
13961                 TEST_CASES_END() /**< NULL terminate unit test array */
13962         }
13963 };
13964
13965 static struct unit_test_suite cryptodev_mrvl_testsuite  = {
13966         .suite_name = "Crypto Device Marvell Component Test Suite",
13967         .setup = testsuite_setup,
13968         .teardown = testsuite_teardown,
13969         .unit_test_cases = {
13970                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13971                 TEST_CASE_ST(ut_setup, ut_teardown,
13972                                 test_multi_session_random_usage),
13973                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13974                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13975                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13976                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13977                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13978
13979                 /** Negative tests */
13980                 TEST_CASE_ST(ut_setup, ut_teardown,
13981                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13982                 TEST_CASE_ST(ut_setup, ut_teardown,
13983                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13984                 TEST_CASE_ST(ut_setup, ut_teardown,
13985                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13986                 TEST_CASE_ST(ut_setup, ut_teardown,
13987                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13988
13989                 TEST_CASES_END() /**< NULL terminate unit test array */
13990         }
13991 };
13992
13993 static struct unit_test_suite cryptodev_ccp_testsuite  = {
13994         .suite_name = "Crypto Device CCP Unit Test Suite",
13995         .setup = testsuite_setup,
13996         .teardown = testsuite_teardown,
13997         .unit_test_cases = {
13998                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13999                 TEST_CASE_ST(ut_setup, ut_teardown,
14000                                 test_multi_session_random_usage),
14001                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
14002                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
14003                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
14004                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
14005                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
14006
14007                 /** Negative tests */
14008                 TEST_CASE_ST(ut_setup, ut_teardown,
14009                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
14010                 TEST_CASE_ST(ut_setup, ut_teardown,
14011                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
14012                 TEST_CASE_ST(ut_setup, ut_teardown,
14013                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
14014                 TEST_CASE_ST(ut_setup, ut_teardown,
14015                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
14016
14017                 TEST_CASES_END() /**< NULL terminate unit test array */
14018         }
14019 };
14020
14021 static int
14022 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
14023 {
14024         gbl_driver_id = rte_cryptodev_driver_id_get(
14025                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14026
14027         if (gbl_driver_id == -1) {
14028                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
14029                 return TEST_SKIPPED;
14030         }
14031
14032         return unit_test_suite_runner(&cryptodev_testsuite);
14033 }
14034
14035 static int
14036 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
14037 {
14038         gbl_driver_id = rte_cryptodev_driver_id_get(
14039                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
14040
14041         if (gbl_driver_id == -1) {
14042                 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded.\n");
14043                 return TEST_FAILED;
14044         }
14045
14046         return unit_test_suite_runner(&cryptodev_virtio_testsuite);
14047 }
14048
14049 static int
14050 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
14051 {
14052         gbl_driver_id = rte_cryptodev_driver_id_get(
14053                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14054
14055         if (gbl_driver_id == -1) {
14056                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
14057                 return TEST_SKIPPED;
14058         }
14059
14060         return unit_test_suite_runner(&cryptodev_testsuite);
14061 }
14062
14063 static int
14064 test_cryptodev_cpu_aesni_mb(void)
14065 {
14066         int32_t rc;
14067         enum rte_security_session_action_type at;
14068
14069         gbl_driver_id = rte_cryptodev_driver_id_get(
14070                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14071
14072         if (gbl_driver_id == -1) {
14073                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
14074                 return TEST_SKIPPED;
14075         }
14076
14077         at = gbl_action_type;
14078         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14079         rc = unit_test_suite_runner(&cryptodev_testsuite);
14080         gbl_action_type = at;
14081         return rc;
14082 }
14083
14084 static int
14085 test_cryptodev_openssl(void)
14086 {
14087         gbl_driver_id = rte_cryptodev_driver_id_get(
14088                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
14089
14090         if (gbl_driver_id == -1) {
14091                 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
14092                 return TEST_SKIPPED;
14093         }
14094
14095         return unit_test_suite_runner(&cryptodev_testsuite);
14096 }
14097
14098 static int
14099 test_cryptodev_aesni_gcm(void)
14100 {
14101         gbl_driver_id = rte_cryptodev_driver_id_get(
14102                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14103
14104         if (gbl_driver_id == -1) {
14105                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n");
14106                 return TEST_SKIPPED;
14107         }
14108
14109         return unit_test_suite_runner(&cryptodev_testsuite);
14110 }
14111
14112 static int
14113 test_cryptodev_cpu_aesni_gcm(void)
14114 {
14115         int32_t rc;
14116         enum rte_security_session_action_type at;
14117
14118         gbl_driver_id = rte_cryptodev_driver_id_get(
14119                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14120
14121         if (gbl_driver_id == -1) {
14122                 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n");
14123                 return TEST_SKIPPED;
14124         }
14125
14126         at = gbl_action_type;
14127         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14128         rc = unit_test_suite_runner(&cryptodev_testsuite);
14129         gbl_action_type = at;
14130         return rc;
14131 }
14132
14133 static int
14134 test_cryptodev_null(void)
14135 {
14136         gbl_driver_id = rte_cryptodev_driver_id_get(
14137                         RTE_STR(CRYPTODEV_NAME_NULL_PMD));
14138
14139         if (gbl_driver_id == -1) {
14140                 RTE_LOG(ERR, USER1, "NULL PMD must be loaded.\n");
14141                 return TEST_SKIPPED;
14142         }
14143
14144         return unit_test_suite_runner(&cryptodev_testsuite);
14145 }
14146
14147 static int
14148 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
14149 {
14150         gbl_driver_id = rte_cryptodev_driver_id_get(
14151                         RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
14152
14153         if (gbl_driver_id == -1) {
14154                 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded.\n");
14155                 return TEST_SKIPPED;
14156         }
14157
14158         return unit_test_suite_runner(&cryptodev_testsuite);
14159 }
14160
14161 static int
14162 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
14163 {
14164         gbl_driver_id = rte_cryptodev_driver_id_get(
14165                         RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
14166
14167         if (gbl_driver_id == -1) {
14168                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n");
14169                 return TEST_SKIPPED;
14170         }
14171
14172         return unit_test_suite_runner(&cryptodev_testsuite);
14173 }
14174
14175 static int
14176 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
14177 {
14178         gbl_driver_id = rte_cryptodev_driver_id_get(
14179                         RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
14180
14181         if (gbl_driver_id == -1) {
14182                 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n");
14183                 return TEST_SKIPPED;
14184         }
14185
14186         return unit_test_suite_runner(&cryptodev_testsuite);
14187 }
14188
14189 static int
14190 test_cryptodev_armv8(void)
14191 {
14192         gbl_driver_id = rte_cryptodev_driver_id_get(
14193                         RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
14194
14195         if (gbl_driver_id == -1) {
14196                 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded.\n");
14197                 return TEST_SKIPPED;
14198         }
14199
14200         return unit_test_suite_runner(&cryptodev_testsuite);
14201 }
14202
14203 static int
14204 test_cryptodev_mrvl(void)
14205 {
14206         gbl_driver_id = rte_cryptodev_driver_id_get(
14207                         RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
14208
14209         if (gbl_driver_id == -1) {
14210                 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded.\n");
14211                 return TEST_SKIPPED;
14212         }
14213
14214         return unit_test_suite_runner(&cryptodev_mrvl_testsuite);
14215 }
14216
14217 #ifdef RTE_CRYPTO_SCHEDULER
14218
14219 static int
14220 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
14221 {
14222         gbl_driver_id = rte_cryptodev_driver_id_get(
14223                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14224
14225         if (gbl_driver_id == -1) {
14226                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
14227                 return TEST_SKIPPED;
14228         }
14229
14230         if (rte_cryptodev_driver_id_get(
14231                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
14232                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
14233                 return TEST_SKIPPED;
14234 }
14235         return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
14236 }
14237
14238 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
14239
14240 #endif
14241
14242 static int
14243 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
14244 {
14245         gbl_driver_id = rte_cryptodev_driver_id_get(
14246                         RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
14247
14248         if (gbl_driver_id == -1) {
14249                 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded.\n");
14250                 return TEST_SKIPPED;
14251         }
14252
14253         return unit_test_suite_runner(&cryptodev_testsuite);
14254 }
14255
14256 static int
14257 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
14258 {
14259         gbl_driver_id = rte_cryptodev_driver_id_get(
14260                         RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
14261
14262         if (gbl_driver_id == -1) {
14263                 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded.\n");
14264                 return TEST_SKIPPED;
14265         }
14266
14267         return unit_test_suite_runner(&cryptodev_testsuite);
14268 }
14269
14270 static int
14271 test_cryptodev_ccp(void)
14272 {
14273         gbl_driver_id = rte_cryptodev_driver_id_get(
14274                         RTE_STR(CRYPTODEV_NAME_CCP_PMD));
14275
14276         if (gbl_driver_id == -1) {
14277                 RTE_LOG(ERR, USER1, "CCP PMD must be loaded.\n");
14278                 return TEST_FAILED;
14279         }
14280
14281         return unit_test_suite_runner(&cryptodev_ccp_testsuite);
14282 }
14283
14284 static int
14285 test_cryptodev_octeontx(void)
14286 {
14287         gbl_driver_id = rte_cryptodev_driver_id_get(
14288                         RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
14289         if (gbl_driver_id == -1) {
14290                 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
14291                 return TEST_FAILED;
14292         }
14293         return unit_test_suite_runner(&cryptodev_testsuite);
14294 }
14295
14296 static int
14297 test_cryptodev_octeontx2(void)
14298 {
14299         gbl_driver_id = rte_cryptodev_driver_id_get(
14300                         RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
14301         if (gbl_driver_id == -1) {
14302                 RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded.\n");
14303                 return TEST_FAILED;
14304         }
14305         return unit_test_suite_runner(&cryptodev_testsuite);
14306 }
14307
14308 static int
14309 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/)
14310 {
14311         gbl_driver_id = rte_cryptodev_driver_id_get(
14312                         RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
14313
14314         if (gbl_driver_id == -1) {
14315                 RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded.\n");
14316                 return TEST_FAILED;
14317         }
14318
14319         return unit_test_suite_runner(&cryptodev_caam_jr_testsuite);
14320 }
14321
14322 static int
14323 test_cryptodev_nitrox(void)
14324 {
14325         gbl_driver_id = rte_cryptodev_driver_id_get(
14326                         RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
14327
14328         if (gbl_driver_id == -1) {
14329                 RTE_LOG(ERR, USER1, "NITROX PMD must be loaded.\n");
14330                 return TEST_FAILED;
14331         }
14332
14333         return unit_test_suite_runner(&cryptodev_testsuite);
14334 }
14335
14336 static int
14337 test_cryptodev_bcmfs(void)
14338 {
14339         gbl_driver_id = rte_cryptodev_driver_id_get(
14340                         RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
14341
14342         if (gbl_driver_id == -1) {
14343                 RTE_LOG(ERR, USER1, "BCMFS PMD must be loaded.\n");
14344                 return TEST_FAILED;
14345         }
14346
14347         return unit_test_suite_runner(&cryptodev_testsuite);
14348 }
14349
14350 static int
14351 test_cryptodev_qat_raw_api(void /*argv __rte_unused, int argc __rte_unused*/)
14352 {
14353         int ret;
14354
14355         gbl_driver_id = rte_cryptodev_driver_id_get(
14356                         RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14357
14358         if (gbl_driver_id == -1) {
14359                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
14360                 return TEST_SKIPPED;
14361         }
14362
14363         global_api_test_type = CRYPTODEV_RAW_API_TEST;
14364         ret = unit_test_suite_runner(&cryptodev_testsuite);
14365         global_api_test_type = CRYPTODEV_API_TEST;
14366
14367         return ret;
14368 }
14369
14370 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
14371                 test_cryptodev_qat_raw_api);
14372 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
14373 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
14374 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
14375         test_cryptodev_cpu_aesni_mb);
14376 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
14377 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
14378 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
14379         test_cryptodev_cpu_aesni_gcm);
14380 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
14381 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
14382 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
14383 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
14384 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
14385 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
14386 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
14387 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
14388 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
14389 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
14390 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
14391 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
14392 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
14393 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
14394 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);