test/crypto: move test suite parameters to header file
[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_unittest_params {
76         struct rte_crypto_sym_xform cipher_xform;
77         struct rte_crypto_sym_xform auth_xform;
78         struct rte_crypto_sym_xform aead_xform;
79 #ifdef RTE_LIB_SECURITY
80         struct rte_security_docsis_xform docsis_xform;
81 #endif
82
83         union {
84                 struct rte_cryptodev_sym_session *sess;
85 #ifdef RTE_LIB_SECURITY
86                 struct rte_security_session *sec_session;
87 #endif
88         };
89 #ifdef RTE_LIB_SECURITY
90         enum rte_security_session_action_type type;
91 #endif
92         struct rte_crypto_op *op;
93
94         struct rte_mbuf *obuf, *ibuf;
95
96         uint8_t *digest;
97 };
98
99 #define ALIGN_POW2_ROUNDUP(num, align) \
100         (((num) + (align) - 1) & ~((align) - 1))
101
102 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)  \
103         for (j = 0; j < num_child_ts; index++, j++)                     \
104                 parent_ts.unit_test_suites[index] = child_ts[j]
105
106 /*
107  * Forward declarations.
108  */
109 static int
110 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
111                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
112                 uint8_t *hmac_key);
113
114 static int
115 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
116                 struct crypto_unittest_params *ut_params,
117                 struct crypto_testsuite_params *ts_param,
118                 const uint8_t *cipher,
119                 const uint8_t *digest,
120                 const uint8_t *iv);
121
122 static struct rte_mbuf *
123 setup_test_string(struct rte_mempool *mpool,
124                 const char *string, size_t len, uint8_t blocksize)
125 {
126         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
127         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
128
129         memset(m->buf_addr, 0, m->buf_len);
130         if (m) {
131                 char *dst = rte_pktmbuf_append(m, t_len);
132
133                 if (!dst) {
134                         rte_pktmbuf_free(m);
135                         return NULL;
136                 }
137                 if (string != NULL)
138                         rte_memcpy(dst, string, t_len);
139                 else
140                         memset(dst, 0, t_len);
141         }
142
143         return m;
144 }
145
146 /* Get number of bytes in X bits (rounding up) */
147 static uint32_t
148 ceil_byte_length(uint32_t num_bits)
149 {
150         if (num_bits % 8)
151                 return ((num_bits >> 3) + 1);
152         else
153                 return (num_bits >> 3);
154 }
155
156 static void
157 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused,
158                 uint8_t is_op_success)
159 {
160         struct rte_crypto_op *op = user_data;
161         op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
162                         RTE_CRYPTO_OP_STATUS_ERROR;
163 }
164
165 void
166 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
167                 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
168                 uint8_t len_in_bits, uint8_t cipher_iv_len)
169 {
170         struct rte_crypto_sym_op *sop = op->sym;
171         struct rte_crypto_op *ret_op = NULL;
172         struct rte_crypto_vec data_vec[UINT8_MAX];
173         struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
174         union rte_crypto_sym_ofs ofs;
175         struct rte_crypto_sym_vec vec;
176         struct rte_crypto_sgl sgl;
177         uint32_t max_len;
178         union rte_cryptodev_session_ctx sess;
179         uint32_t count = 0;
180         struct rte_crypto_raw_dp_ctx *ctx;
181         uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
182                         auth_len = 0;
183         int32_t n;
184         uint32_t n_success;
185         int ctx_service_size;
186         int32_t status = 0;
187         int enqueue_status, dequeue_status;
188
189         ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
190         if (ctx_service_size < 0) {
191                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
192                 return;
193         }
194
195         ctx = malloc(ctx_service_size);
196         if (!ctx) {
197                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
198                 return;
199         }
200
201         /* Both are enums, setting crypto_sess will suit any session type */
202         sess.crypto_sess = op->sym->session;
203
204         if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
205                         op->sess_type, sess, 0) < 0) {
206                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
207                 goto exit;
208         }
209
210         cipher_iv.iova = 0;
211         cipher_iv.va = NULL;
212         aad_auth_iv.iova = 0;
213         aad_auth_iv.va = NULL;
214         digest.iova = 0;
215         digest.va = NULL;
216         sgl.vec = data_vec;
217         vec.num = 1;
218         vec.sgl = &sgl;
219         vec.iv = &cipher_iv;
220         vec.digest = &digest;
221         vec.aad = &aad_auth_iv;
222         vec.status = &status;
223
224         ofs.raw = 0;
225
226         if (is_cipher && is_auth) {
227                 cipher_offset = sop->cipher.data.offset;
228                 cipher_len = sop->cipher.data.length;
229                 auth_offset = sop->auth.data.offset;
230                 auth_len = sop->auth.data.length;
231                 max_len = RTE_MAX(cipher_offset + cipher_len,
232                                 auth_offset + auth_len);
233                 if (len_in_bits) {
234                         max_len = max_len >> 3;
235                         cipher_offset = cipher_offset >> 3;
236                         auth_offset = auth_offset >> 3;
237                         cipher_len = cipher_len >> 3;
238                         auth_len = auth_len >> 3;
239                 }
240                 ofs.ofs.cipher.head = cipher_offset;
241                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
242                 ofs.ofs.auth.head = auth_offset;
243                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
244                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
245                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
246                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
247                                 op, void *, IV_OFFSET + cipher_iv_len);
248                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
249                                 cipher_iv_len);
250                 digest.va = (void *)sop->auth.digest.data;
251                 digest.iova = sop->auth.digest.phys_addr;
252
253         } else if (is_cipher) {
254                 cipher_offset = sop->cipher.data.offset;
255                 cipher_len = sop->cipher.data.length;
256                 max_len = cipher_len + cipher_offset;
257                 if (len_in_bits) {
258                         max_len = max_len >> 3;
259                         cipher_offset = cipher_offset >> 3;
260                         cipher_len = cipher_len >> 3;
261                 }
262                 ofs.ofs.cipher.head = cipher_offset;
263                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
264                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
265                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
266
267         } else if (is_auth) {
268                 auth_offset = sop->auth.data.offset;
269                 auth_len = sop->auth.data.length;
270                 max_len = auth_len + auth_offset;
271                 if (len_in_bits) {
272                         max_len = max_len >> 3;
273                         auth_offset = auth_offset >> 3;
274                         auth_len = auth_len >> 3;
275                 }
276                 ofs.ofs.auth.head = auth_offset;
277                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
278                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
279                                 op, void *, IV_OFFSET + cipher_iv_len);
280                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
281                                 cipher_iv_len);
282                 digest.va = (void *)sop->auth.digest.data;
283                 digest.iova = sop->auth.digest.phys_addr;
284
285         } else { /* aead */
286                 cipher_offset = sop->aead.data.offset;
287                 cipher_len = sop->aead.data.length;
288                 max_len = cipher_len + cipher_offset;
289                 if (len_in_bits) {
290                         max_len = max_len >> 3;
291                         cipher_offset = cipher_offset >> 3;
292                         cipher_len = cipher_len >> 3;
293                 }
294                 ofs.ofs.cipher.head = cipher_offset;
295                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
296                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
297                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
298                 aad_auth_iv.va = (void *)sop->aead.aad.data;
299                 aad_auth_iv.iova = sop->aead.aad.phys_addr;
300                 digest.va = (void *)sop->aead.digest.data;
301                 digest.iova = sop->aead.digest.phys_addr;
302         }
303
304         n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
305                         data_vec, RTE_DIM(data_vec));
306         if (n < 0 || n > sop->m_src->nb_segs) {
307                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
308                 goto exit;
309         }
310
311         sgl.num = n;
312
313         if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
314                         &enqueue_status) < 1) {
315                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
316                 goto exit;
317         }
318
319         if (enqueue_status == 0) {
320                 status = rte_cryptodev_raw_enqueue_done(ctx, 1);
321                 if (status < 0) {
322                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
323                         goto exit;
324                 }
325         } else if (enqueue_status < 0) {
326                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
327                 goto exit;
328         }
329
330         n = n_success = 0;
331         while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
332                 n = rte_cryptodev_raw_dequeue_burst(ctx,
333                         NULL, 1, post_process_raw_dp_op,
334                                 (void **)&ret_op, 0, &n_success,
335                                 &dequeue_status);
336                 if (dequeue_status < 0) {
337                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
338                         goto exit;
339                 }
340                 if (n == 0)
341                         rte_pause();
342         }
343
344         if (n == 1 && dequeue_status == 0) {
345                 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
346                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
347                         goto exit;
348                 }
349         }
350
351         op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
352                         n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
353                                         RTE_CRYPTO_OP_STATUS_SUCCESS;
354
355 exit:
356         free(ctx);
357 }
358
359 static void
360 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
361 {
362         int32_t n, st;
363         struct rte_crypto_sym_op *sop;
364         union rte_crypto_sym_ofs ofs;
365         struct rte_crypto_sgl sgl;
366         struct rte_crypto_sym_vec symvec;
367         struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
368         struct rte_crypto_vec vec[UINT8_MAX];
369
370         sop = op->sym;
371
372         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
373                 sop->aead.data.length, vec, RTE_DIM(vec));
374
375         if (n < 0 || n != sop->m_src->nb_segs) {
376                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
377                 return;
378         }
379
380         sgl.vec = vec;
381         sgl.num = n;
382         symvec.sgl = &sgl;
383         symvec.iv = &iv_ptr;
384         symvec.digest = &digest_ptr;
385         symvec.aad = &aad_ptr;
386         symvec.status = &st;
387         symvec.num = 1;
388
389         /* for CPU crypto the IOVA address is not required */
390         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
391         digest_ptr.va = (void *)sop->aead.digest.data;
392         aad_ptr.va = (void *)sop->aead.aad.data;
393
394         ofs.raw = 0;
395
396         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
397                 &symvec);
398
399         if (n != 1)
400                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
401         else
402                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
403 }
404
405 static void
406 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
407 {
408         int32_t n, st;
409         struct rte_crypto_sym_op *sop;
410         union rte_crypto_sym_ofs ofs;
411         struct rte_crypto_sgl sgl;
412         struct rte_crypto_sym_vec symvec;
413         struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
414         struct rte_crypto_vec vec[UINT8_MAX];
415
416         sop = op->sym;
417
418         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
419                 sop->auth.data.length, vec, RTE_DIM(vec));
420
421         if (n < 0 || n != sop->m_src->nb_segs) {
422                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
423                 return;
424         }
425
426         sgl.vec = vec;
427         sgl.num = n;
428         symvec.sgl = &sgl;
429         symvec.iv = &iv_ptr;
430         symvec.digest = &digest_ptr;
431         symvec.status = &st;
432         symvec.num = 1;
433
434         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
435         digest_ptr.va = (void *)sop->auth.digest.data;
436
437         ofs.raw = 0;
438         ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
439         ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
440                 (sop->cipher.data.offset + sop->cipher.data.length);
441
442         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
443                 &symvec);
444
445         if (n != 1)
446                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
447         else
448                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
449 }
450
451 static struct rte_crypto_op *
452 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
453 {
454
455         RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
456
457         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
458                 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
459                 return NULL;
460         }
461
462         op = NULL;
463
464         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
465                 rte_pause();
466
467         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
468                 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
469                 return NULL;
470         }
471
472         return op;
473 }
474
475 static struct crypto_testsuite_params testsuite_params = { NULL };
476 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
477 static struct crypto_unittest_params unittest_params;
478
479 static int
480 testsuite_setup(void)
481 {
482         struct crypto_testsuite_params *ts_params = &testsuite_params;
483         struct rte_cryptodev_info info;
484         uint32_t i = 0, nb_devs, dev_id;
485         uint16_t qp_id;
486
487         memset(ts_params, 0, sizeof(*ts_params));
488
489         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
490         if (ts_params->mbuf_pool == NULL) {
491                 /* Not already created so create */
492                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
493                                 "CRYPTO_MBUFPOOL",
494                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
495                                 rte_socket_id());
496                 if (ts_params->mbuf_pool == NULL) {
497                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
498                         return TEST_FAILED;
499                 }
500         }
501
502         ts_params->large_mbuf_pool = rte_mempool_lookup(
503                         "CRYPTO_LARGE_MBUFPOOL");
504         if (ts_params->large_mbuf_pool == NULL) {
505                 /* Not already created so create */
506                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
507                                 "CRYPTO_LARGE_MBUFPOOL",
508                                 1, 0, 0, UINT16_MAX,
509                                 rte_socket_id());
510                 if (ts_params->large_mbuf_pool == NULL) {
511                         RTE_LOG(ERR, USER1,
512                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
513                         return TEST_FAILED;
514                 }
515         }
516
517         ts_params->op_mpool = rte_crypto_op_pool_create(
518                         "MBUF_CRYPTO_SYM_OP_POOL",
519                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
520                         NUM_MBUFS, MBUF_CACHE_SIZE,
521                         DEFAULT_NUM_XFORMS *
522                         sizeof(struct rte_crypto_sym_xform) +
523                         MAXIMUM_IV_LENGTH,
524                         rte_socket_id());
525         if (ts_params->op_mpool == NULL) {
526                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
527                 return TEST_FAILED;
528         }
529
530         nb_devs = rte_cryptodev_count();
531         if (nb_devs < 1) {
532                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
533                 return TEST_SKIPPED;
534         }
535
536         if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
537                 RTE_LOG(WARNING, USER1, "No %s devices found?\n",
538                                 rte_cryptodev_driver_name_get(gbl_driver_id));
539                 return TEST_SKIPPED;
540         }
541
542         /* Create list of valid crypto devs */
543         for (i = 0; i < nb_devs; i++) {
544                 rte_cryptodev_info_get(i, &info);
545                 if (info.driver_id == gbl_driver_id)
546                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
547         }
548
549         if (ts_params->valid_dev_count < 1)
550                 return TEST_FAILED;
551
552         /* Set up all the qps on the first of the valid devices found */
553
554         dev_id = ts_params->valid_devs[0];
555
556         rte_cryptodev_info_get(dev_id, &info);
557
558         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
559         ts_params->conf.socket_id = SOCKET_ID_ANY;
560         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
561
562         unsigned int session_size =
563                 rte_cryptodev_sym_get_private_session_size(dev_id);
564
565 #ifdef RTE_LIB_SECURITY
566         unsigned int security_session_size = rte_security_session_get_size(
567                         rte_cryptodev_get_sec_ctx(dev_id));
568
569         if (session_size < security_session_size)
570                 session_size = security_session_size;
571 #endif
572         /*
573          * Create mempool with maximum number of sessions.
574          */
575         if (info.sym.max_nb_sessions != 0 &&
576                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
577                 RTE_LOG(ERR, USER1, "Device does not support "
578                                 "at least %u sessions\n",
579                                 MAX_NB_SESSIONS);
580                 return TEST_FAILED;
581         }
582
583         ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
584                         "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
585                         SOCKET_ID_ANY);
586         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
587                         "session mempool allocation failed");
588
589         ts_params->session_priv_mpool = rte_mempool_create(
590                         "test_sess_mp_priv",
591                         MAX_NB_SESSIONS,
592                         session_size,
593                         0, 0, NULL, NULL, NULL,
594                         NULL, SOCKET_ID_ANY,
595                         0);
596         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
597                         "session mempool allocation failed");
598
599
600
601         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
602                         &ts_params->conf),
603                         "Failed to configure cryptodev %u with %u qps",
604                         dev_id, ts_params->conf.nb_queue_pairs);
605
606         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
607         ts_params->qp_conf.mp_session = ts_params->session_mpool;
608         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
609
610         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
611                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
612                         dev_id, qp_id, &ts_params->qp_conf,
613                         rte_cryptodev_socket_id(dev_id)),
614                         "Failed to setup queue pair %u on cryptodev %u",
615                         qp_id, dev_id);
616         }
617
618         return TEST_SUCCESS;
619 }
620
621 static void
622 testsuite_teardown(void)
623 {
624         struct crypto_testsuite_params *ts_params = &testsuite_params;
625         int res;
626
627         if (ts_params->mbuf_pool != NULL) {
628                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
629                 rte_mempool_avail_count(ts_params->mbuf_pool));
630         }
631
632         if (ts_params->op_mpool != NULL) {
633                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
634                 rte_mempool_avail_count(ts_params->op_mpool));
635         }
636
637         /* Free session mempools */
638         if (ts_params->session_priv_mpool != NULL) {
639                 rte_mempool_free(ts_params->session_priv_mpool);
640                 ts_params->session_priv_mpool = NULL;
641         }
642
643         if (ts_params->session_mpool != NULL) {
644                 rte_mempool_free(ts_params->session_mpool);
645                 ts_params->session_mpool = NULL;
646         }
647
648         res = rte_cryptodev_close(ts_params->valid_devs[0]);
649         if (res)
650                 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
651 }
652
653 static int
654 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
655                 const int *algs, uint16_t num_algs)
656 {
657         uint8_t dev_id = testsuite_params.valid_devs[0];
658         bool some_alg_supported = FALSE;
659         uint16_t i;
660
661         for (i = 0; i < num_algs && !some_alg_supported; i++) {
662                 struct rte_cryptodev_sym_capability_idx alg = {
663                         type, {algs[i]}
664                 };
665                 if (rte_cryptodev_sym_capability_get(dev_id,
666                                 &alg) != NULL)
667                         some_alg_supported = TRUE;
668         }
669         if (!some_alg_supported)
670                 return TEST_SKIPPED;
671
672         return 0;
673 }
674
675 int
676 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
677                 uint16_t num_ciphers)
678 {
679         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
680                         (const int *) ciphers, num_ciphers);
681 }
682
683 int
684 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
685                 uint16_t num_auths)
686 {
687         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
688                         (const int *) auths, num_auths);
689 }
690
691 int
692 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
693                 uint16_t num_aeads)
694 {
695         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
696                         (const int *) aeads, num_aeads);
697 }
698
699 static int
700 null_testsuite_setup(void)
701 {
702         struct crypto_testsuite_params *ts_params = &testsuite_params;
703         uint8_t dev_id = ts_params->valid_devs[0];
704         struct rte_cryptodev_info dev_info;
705         const enum rte_crypto_cipher_algorithm ciphers[] = {
706                 RTE_CRYPTO_CIPHER_NULL
707         };
708         const enum rte_crypto_auth_algorithm auths[] = {
709                 RTE_CRYPTO_AUTH_NULL
710         };
711
712         rte_cryptodev_info_get(dev_id, &dev_info);
713
714         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
715                 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
716                                 "testsuite not met\n");
717                 return TEST_SKIPPED;
718         }
719
720         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
721                         && check_auth_capabilities_supported(auths,
722                         RTE_DIM(auths)) != 0) {
723                 RTE_LOG(INFO, USER1, "Capability requirements for NULL "
724                                 "testsuite not met\n");
725                 return TEST_SKIPPED;
726         }
727
728         return 0;
729 }
730
731 static int
732 crypto_gen_testsuite_setup(void)
733 {
734         struct crypto_testsuite_params *ts_params = &testsuite_params;
735         uint8_t dev_id = ts_params->valid_devs[0];
736         struct rte_cryptodev_info dev_info;
737
738         rte_cryptodev_info_get(dev_id, &dev_info);
739
740         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
741                 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
742                                 "testsuite not met\n");
743                 return TEST_SKIPPED;
744         }
745
746         return 0;
747 }
748
749 #ifdef RTE_LIB_SECURITY
750 static int
751 pdcp_proto_testsuite_setup(void)
752 {
753         struct crypto_testsuite_params *ts_params = &testsuite_params;
754         uint8_t dev_id = ts_params->valid_devs[0];
755         struct rte_cryptodev_info dev_info;
756         const enum rte_crypto_cipher_algorithm ciphers[] = {
757                 RTE_CRYPTO_CIPHER_NULL,
758                 RTE_CRYPTO_CIPHER_AES_CTR,
759                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
760                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
761         };
762         const enum rte_crypto_auth_algorithm auths[] = {
763                 RTE_CRYPTO_AUTH_NULL,
764                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
765                 RTE_CRYPTO_AUTH_AES_CMAC,
766                 RTE_CRYPTO_AUTH_ZUC_EIA3
767         };
768
769         rte_cryptodev_info_get(dev_id, &dev_info);
770
771         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
772                         !(dev_info.feature_flags &
773                         RTE_CRYPTODEV_FF_SECURITY)) {
774                 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
775                                 "testsuite not met\n");
776                 return TEST_SKIPPED;
777         }
778
779         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
780                         && check_auth_capabilities_supported(auths,
781                         RTE_DIM(auths)) != 0) {
782                 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
783                                 "testsuite not met\n");
784                 return TEST_SKIPPED;
785         }
786
787         return 0;
788 }
789
790 static int
791 docsis_proto_testsuite_setup(void)
792 {
793         struct crypto_testsuite_params *ts_params = &testsuite_params;
794         uint8_t dev_id = ts_params->valid_devs[0];
795         struct rte_cryptodev_info dev_info;
796         const enum rte_crypto_cipher_algorithm ciphers[] = {
797                 RTE_CRYPTO_CIPHER_AES_DOCSISBPI
798         };
799
800         rte_cryptodev_info_get(dev_id, &dev_info);
801
802         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
803                         !(dev_info.feature_flags &
804                         RTE_CRYPTODEV_FF_SECURITY)) {
805                 RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis "
806                                 "Proto testsuite not met\n");
807                 return TEST_SKIPPED;
808         }
809
810         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
811                 RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto "
812                                 "testsuite not met\n");
813                 return TEST_SKIPPED;
814         }
815
816         return 0;
817 }
818 #endif
819
820 static int
821 aes_ccm_auth_testsuite_setup(void)
822 {
823         struct crypto_testsuite_params *ts_params = &testsuite_params;
824         uint8_t dev_id = ts_params->valid_devs[0];
825         struct rte_cryptodev_info dev_info;
826         const enum rte_crypto_aead_algorithm aeads[] = {
827                 RTE_CRYPTO_AEAD_AES_CCM
828         };
829
830         rte_cryptodev_info_get(dev_id, &dev_info);
831
832         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
833                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
834                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
835                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
836                                 "testsuite not met\n");
837                 return TEST_SKIPPED;
838         }
839
840         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
841                 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
842                                 "testsuite not met\n");
843                 return TEST_SKIPPED;
844         }
845
846         return 0;
847 }
848
849 static int
850 aes_gcm_auth_testsuite_setup(void)
851 {
852         struct crypto_testsuite_params *ts_params = &testsuite_params;
853         uint8_t dev_id = ts_params->valid_devs[0];
854         struct rte_cryptodev_info dev_info;
855         const enum rte_crypto_aead_algorithm aeads[] = {
856                 RTE_CRYPTO_AEAD_AES_GCM
857         };
858
859         rte_cryptodev_info_get(dev_id, &dev_info);
860
861         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
862                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
863                                 "testsuite not met\n");
864                 return TEST_SKIPPED;
865         }
866
867         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
868                 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
869                                 "testsuite not met\n");
870                 return TEST_SKIPPED;
871         }
872
873         return 0;
874 }
875
876 static int
877 aes_gmac_auth_testsuite_setup(void)
878 {
879         struct crypto_testsuite_params *ts_params = &testsuite_params;
880         uint8_t dev_id = ts_params->valid_devs[0];
881         struct rte_cryptodev_info dev_info;
882         const enum rte_crypto_auth_algorithm auths[] = {
883                 RTE_CRYPTO_AUTH_AES_GMAC
884         };
885
886         rte_cryptodev_info_get(dev_id, &dev_info);
887
888         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
889                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
890                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
891                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
892                                 "testsuite not met\n");
893                 return TEST_SKIPPED;
894         }
895
896         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
897                 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
898                                 "testsuite not met\n");
899                 return TEST_SKIPPED;
900         }
901
902         return 0;
903 }
904
905 static int
906 chacha20_poly1305_testsuite_setup(void)
907 {
908         struct crypto_testsuite_params *ts_params = &testsuite_params;
909         uint8_t dev_id = ts_params->valid_devs[0];
910         struct rte_cryptodev_info dev_info;
911         const enum rte_crypto_aead_algorithm aeads[] = {
912                 RTE_CRYPTO_AEAD_CHACHA20_POLY1305
913         };
914
915         rte_cryptodev_info_get(dev_id, &dev_info);
916
917         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
918                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
919                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
920                 RTE_LOG(INFO, USER1, "Feature flag requirements for "
921                                 "Chacha20-Poly1305 testsuite not met\n");
922                 return TEST_SKIPPED;
923         }
924
925         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
926                 RTE_LOG(INFO, USER1, "Capability requirements for "
927                                 "Chacha20-Poly1305 testsuite not met\n");
928                 return TEST_SKIPPED;
929         }
930
931         return 0;
932 }
933
934 static int
935 snow3g_testsuite_setup(void)
936 {
937         struct crypto_testsuite_params *ts_params = &testsuite_params;
938         uint8_t dev_id = ts_params->valid_devs[0];
939         struct rte_cryptodev_info dev_info;
940         const enum rte_crypto_cipher_algorithm ciphers[] = {
941                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
942
943         };
944         const enum rte_crypto_auth_algorithm auths[] = {
945                 RTE_CRYPTO_AUTH_SNOW3G_UIA2
946         };
947
948         rte_cryptodev_info_get(dev_id, &dev_info);
949
950         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
951                 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
952                                 "testsuite not met\n");
953                 return TEST_SKIPPED;
954         }
955
956         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
957                         && check_auth_capabilities_supported(auths,
958                         RTE_DIM(auths)) != 0) {
959                 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
960                                 "testsuite not met\n");
961                 return TEST_SKIPPED;
962         }
963
964         return 0;
965 }
966
967 static int
968 zuc_testsuite_setup(void)
969 {
970         struct crypto_testsuite_params *ts_params = &testsuite_params;
971         uint8_t dev_id = ts_params->valid_devs[0];
972         struct rte_cryptodev_info dev_info;
973         const enum rte_crypto_cipher_algorithm ciphers[] = {
974                 RTE_CRYPTO_CIPHER_ZUC_EEA3
975         };
976         const enum rte_crypto_auth_algorithm auths[] = {
977                 RTE_CRYPTO_AUTH_ZUC_EIA3
978         };
979
980         rte_cryptodev_info_get(dev_id, &dev_info);
981
982         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
983                 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
984                                 "testsuite not met\n");
985                 return TEST_SKIPPED;
986         }
987
988         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
989                         && check_auth_capabilities_supported(auths,
990                         RTE_DIM(auths)) != 0) {
991                 RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
992                                 "testsuite not met\n");
993                 return TEST_SKIPPED;
994         }
995
996         return 0;
997 }
998
999 static int
1000 hmac_md5_auth_testsuite_setup(void)
1001 {
1002         struct crypto_testsuite_params *ts_params = &testsuite_params;
1003         uint8_t dev_id = ts_params->valid_devs[0];
1004         struct rte_cryptodev_info dev_info;
1005         const enum rte_crypto_auth_algorithm auths[] = {
1006                 RTE_CRYPTO_AUTH_MD5_HMAC
1007         };
1008
1009         rte_cryptodev_info_get(dev_id, &dev_info);
1010
1011         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1012                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1013                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1014                 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1015                                 "Auth testsuite not met\n");
1016                 return TEST_SKIPPED;
1017         }
1018
1019         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1020                 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1021                                 "testsuite not met\n");
1022                 return TEST_SKIPPED;
1023         }
1024
1025         return 0;
1026 }
1027
1028 static int
1029 kasumi_testsuite_setup(void)
1030 {
1031         struct crypto_testsuite_params *ts_params = &testsuite_params;
1032         uint8_t dev_id = ts_params->valid_devs[0];
1033         struct rte_cryptodev_info dev_info;
1034         const enum rte_crypto_cipher_algorithm ciphers[] = {
1035                 RTE_CRYPTO_CIPHER_KASUMI_F8
1036         };
1037         const enum rte_crypto_auth_algorithm auths[] = {
1038                 RTE_CRYPTO_AUTH_KASUMI_F9
1039         };
1040
1041         rte_cryptodev_info_get(dev_id, &dev_info);
1042
1043         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1044                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1045                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1046                 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1047                                 "testsuite not met\n");
1048                 return TEST_SKIPPED;
1049         }
1050
1051         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1052                         && check_auth_capabilities_supported(auths,
1053                         RTE_DIM(auths)) != 0) {
1054                 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1055                                 "testsuite not met\n");
1056                 return TEST_SKIPPED;
1057         }
1058
1059         return 0;
1060 }
1061
1062 static int
1063 negative_aes_gcm_testsuite_setup(void)
1064 {
1065         struct crypto_testsuite_params *ts_params = &testsuite_params;
1066         uint8_t dev_id = ts_params->valid_devs[0];
1067         struct rte_cryptodev_info dev_info;
1068         const enum rte_crypto_aead_algorithm aeads[] = {
1069                 RTE_CRYPTO_AEAD_AES_GCM
1070         };
1071
1072         rte_cryptodev_info_get(dev_id, &dev_info);
1073
1074         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1075                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1076                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1077                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1078                                 "AES GCM testsuite not met\n");
1079                 return TEST_SKIPPED;
1080         }
1081
1082         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1083                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1084                                 "AES GCM testsuite not met\n");
1085                 return TEST_SKIPPED;
1086         }
1087
1088         return 0;
1089 }
1090
1091 static int
1092 negative_aes_gmac_testsuite_setup(void)
1093 {
1094         struct crypto_testsuite_params *ts_params = &testsuite_params;
1095         uint8_t dev_id = ts_params->valid_devs[0];
1096         struct rte_cryptodev_info dev_info;
1097         const enum rte_crypto_auth_algorithm auths[] = {
1098                 RTE_CRYPTO_AUTH_AES_GMAC
1099         };
1100
1101         rte_cryptodev_info_get(dev_id, &dev_info);
1102
1103         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1104                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1105                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1106                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1107                                 "AES GMAC testsuite not met\n");
1108                 return TEST_SKIPPED;
1109         }
1110
1111         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1112                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1113                                 "AES GMAC testsuite not met\n");
1114                 return TEST_SKIPPED;
1115         }
1116
1117         return 0;
1118 }
1119
1120 static int
1121 mixed_cipher_hash_testsuite_setup(void)
1122 {
1123         struct crypto_testsuite_params *ts_params = &testsuite_params;
1124         uint8_t dev_id = ts_params->valid_devs[0];
1125         struct rte_cryptodev_info dev_info;
1126         uint64_t feat_flags;
1127         const enum rte_crypto_cipher_algorithm ciphers[] = {
1128                 RTE_CRYPTO_CIPHER_NULL,
1129                 RTE_CRYPTO_CIPHER_AES_CTR,
1130                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
1131                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1132         };
1133         const enum rte_crypto_auth_algorithm auths[] = {
1134                 RTE_CRYPTO_AUTH_NULL,
1135                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1136                 RTE_CRYPTO_AUTH_AES_CMAC,
1137                 RTE_CRYPTO_AUTH_ZUC_EIA3
1138         };
1139
1140         rte_cryptodev_info_get(dev_id, &dev_info);
1141         feat_flags = dev_info.feature_flags;
1142
1143         if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1144                         (global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1145                 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1146                                 "Cipher Hash testsuite not met\n");
1147                 return TEST_SKIPPED;
1148         }
1149
1150         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1151                         && check_auth_capabilities_supported(auths,
1152                         RTE_DIM(auths)) != 0) {
1153                 RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1154                                 "Cipher Hash testsuite not met\n");
1155                 return TEST_SKIPPED;
1156         }
1157
1158         return 0;
1159 }
1160
1161 static int
1162 esn_testsuite_setup(void)
1163 {
1164         struct crypto_testsuite_params *ts_params = &testsuite_params;
1165         uint8_t dev_id = ts_params->valid_devs[0];
1166         struct rte_cryptodev_info dev_info;
1167         const enum rte_crypto_cipher_algorithm ciphers[] = {
1168                 RTE_CRYPTO_CIPHER_AES_CBC
1169         };
1170         const enum rte_crypto_auth_algorithm auths[] = {
1171                 RTE_CRYPTO_AUTH_SHA1_HMAC
1172         };
1173
1174         rte_cryptodev_info_get(dev_id, &dev_info);
1175
1176         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1177                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1178                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1179                 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1180                                 "testsuite not met\n");
1181                 return TEST_SKIPPED;
1182         }
1183
1184         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1185                         && check_auth_capabilities_supported(auths,
1186                         RTE_DIM(auths)) != 0) {
1187                 RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1188                                 "testsuite not met\n");
1189                 return TEST_SKIPPED;
1190         }
1191
1192         return 0;
1193 }
1194
1195 static int
1196 multi_session_testsuite_setup(void)
1197 {
1198         struct crypto_testsuite_params *ts_params = &testsuite_params;
1199         uint8_t dev_id = ts_params->valid_devs[0];
1200         struct rte_cryptodev_info dev_info;
1201         const enum rte_crypto_cipher_algorithm ciphers[] = {
1202                 RTE_CRYPTO_CIPHER_AES_CBC
1203         };
1204         const enum rte_crypto_auth_algorithm auths[] = {
1205                 RTE_CRYPTO_AUTH_SHA512_HMAC
1206         };
1207
1208         rte_cryptodev_info_get(dev_id, &dev_info);
1209
1210         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1211                 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1212                                 "Session testsuite not met\n");
1213                 return TEST_SKIPPED;
1214         }
1215
1216         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1217                         && check_auth_capabilities_supported(auths,
1218                         RTE_DIM(auths)) != 0) {
1219                 RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1220                                 "Session testsuite not met\n");
1221                 return TEST_SKIPPED;
1222         }
1223
1224         return 0;
1225 }
1226
1227 static int
1228 negative_hmac_sha1_testsuite_setup(void)
1229 {
1230         struct crypto_testsuite_params *ts_params = &testsuite_params;
1231         uint8_t dev_id = ts_params->valid_devs[0];
1232         struct rte_cryptodev_info dev_info;
1233         const enum rte_crypto_cipher_algorithm ciphers[] = {
1234                 RTE_CRYPTO_CIPHER_AES_CBC
1235         };
1236         const enum rte_crypto_auth_algorithm auths[] = {
1237                 RTE_CRYPTO_AUTH_SHA1_HMAC
1238         };
1239
1240         rte_cryptodev_info_get(dev_id, &dev_info);
1241
1242         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1243                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1244                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1245                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1246                                 "HMAC SHA1 testsuite not met\n");
1247                 return TEST_SKIPPED;
1248         }
1249
1250         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1251                         && check_auth_capabilities_supported(auths,
1252                         RTE_DIM(auths)) != 0) {
1253                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1254                                 "HMAC SHA1 testsuite not met\n");
1255                 return TEST_SKIPPED;
1256         }
1257
1258         return 0;
1259 }
1260
1261 static int
1262 dev_configure_and_start(uint64_t ff_disable)
1263 {
1264         struct crypto_testsuite_params *ts_params = &testsuite_params;
1265         struct crypto_unittest_params *ut_params = &unittest_params;
1266
1267         uint16_t qp_id;
1268
1269         /* Clear unit test parameters before running test */
1270         memset(ut_params, 0, sizeof(*ut_params));
1271
1272         /* Reconfigure device to default parameters */
1273         ts_params->conf.socket_id = SOCKET_ID_ANY;
1274         ts_params->conf.ff_disable = ff_disable;
1275         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1276         ts_params->qp_conf.mp_session = ts_params->session_mpool;
1277         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1278
1279         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1280                         &ts_params->conf),
1281                         "Failed to configure cryptodev %u",
1282                         ts_params->valid_devs[0]);
1283
1284         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1285                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1286                         ts_params->valid_devs[0], qp_id,
1287                         &ts_params->qp_conf,
1288                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1289                         "Failed to setup queue pair %u on cryptodev %u",
1290                         qp_id, ts_params->valid_devs[0]);
1291         }
1292
1293
1294         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1295
1296         /* Start the device */
1297         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1298                         "Failed to start cryptodev %u",
1299                         ts_params->valid_devs[0]);
1300
1301         return TEST_SUCCESS;
1302 }
1303
1304 int
1305 ut_setup(void)
1306 {
1307         /* Configure and start the device with security feature disabled */
1308         return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1309 }
1310
1311 static int
1312 ut_setup_security(void)
1313 {
1314         /* Configure and start the device with no features disabled */
1315         return dev_configure_and_start(0);
1316 }
1317
1318 void
1319 ut_teardown(void)
1320 {
1321         struct crypto_testsuite_params *ts_params = &testsuite_params;
1322         struct crypto_unittest_params *ut_params = &unittest_params;
1323         struct rte_cryptodev_stats stats;
1324
1325         /* free crypto session structure */
1326 #ifdef RTE_LIB_SECURITY
1327         if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1328                 if (ut_params->sec_session) {
1329                         rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1330                                                 (ts_params->valid_devs[0]),
1331                                                 ut_params->sec_session);
1332                         ut_params->sec_session = NULL;
1333                 }
1334         } else
1335 #endif
1336         {
1337                 if (ut_params->sess) {
1338                         rte_cryptodev_sym_session_clear(
1339                                         ts_params->valid_devs[0],
1340                                         ut_params->sess);
1341                         rte_cryptodev_sym_session_free(ut_params->sess);
1342                         ut_params->sess = NULL;
1343                 }
1344         }
1345
1346         /* free crypto operation structure */
1347         if (ut_params->op)
1348                 rte_crypto_op_free(ut_params->op);
1349
1350         /*
1351          * free mbuf - both obuf and ibuf are usually the same,
1352          * so check if they point at the same address is necessary,
1353          * to avoid freeing the mbuf twice.
1354          */
1355         if (ut_params->obuf) {
1356                 rte_pktmbuf_free(ut_params->obuf);
1357                 if (ut_params->ibuf == ut_params->obuf)
1358                         ut_params->ibuf = 0;
1359                 ut_params->obuf = 0;
1360         }
1361         if (ut_params->ibuf) {
1362                 rte_pktmbuf_free(ut_params->ibuf);
1363                 ut_params->ibuf = 0;
1364         }
1365
1366         if (ts_params->mbuf_pool != NULL)
1367                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1368                         rte_mempool_avail_count(ts_params->mbuf_pool));
1369
1370         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1371
1372         /* Stop the device */
1373         rte_cryptodev_stop(ts_params->valid_devs[0]);
1374 }
1375
1376 static int
1377 test_device_configure_invalid_dev_id(void)
1378 {
1379         struct crypto_testsuite_params *ts_params = &testsuite_params;
1380         uint16_t dev_id, num_devs = 0;
1381
1382         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1383                         "Need at least %d devices for test", 1);
1384
1385         /* valid dev_id values */
1386         dev_id = ts_params->valid_devs[0];
1387
1388         /* Stop the device in case it's started so it can be configured */
1389         rte_cryptodev_stop(dev_id);
1390
1391         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1392                         "Failed test for rte_cryptodev_configure: "
1393                         "invalid dev_num %u", dev_id);
1394
1395         /* invalid dev_id values */
1396         dev_id = num_devs;
1397
1398         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1399                         "Failed test for rte_cryptodev_configure: "
1400                         "invalid dev_num %u", dev_id);
1401
1402         dev_id = 0xff;
1403
1404         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1405                         "Failed test for rte_cryptodev_configure:"
1406                         "invalid dev_num %u", dev_id);
1407
1408         return TEST_SUCCESS;
1409 }
1410
1411 static int
1412 test_device_configure_invalid_queue_pair_ids(void)
1413 {
1414         struct crypto_testsuite_params *ts_params = &testsuite_params;
1415         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1416
1417         /* Stop the device in case it's started so it can be configured */
1418         rte_cryptodev_stop(ts_params->valid_devs[0]);
1419
1420         /* valid - max value queue pairs */
1421         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1422
1423         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1424                         &ts_params->conf),
1425                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1426                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1427
1428         /* valid - one queue pairs */
1429         ts_params->conf.nb_queue_pairs = 1;
1430
1431         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1432                         &ts_params->conf),
1433                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1434                         ts_params->valid_devs[0],
1435                         ts_params->conf.nb_queue_pairs);
1436
1437
1438         /* invalid - zero queue pairs */
1439         ts_params->conf.nb_queue_pairs = 0;
1440
1441         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1442                         &ts_params->conf),
1443                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1444                         " invalid qps: %u",
1445                         ts_params->valid_devs[0],
1446                         ts_params->conf.nb_queue_pairs);
1447
1448
1449         /* invalid - max value supported by field queue pairs */
1450         ts_params->conf.nb_queue_pairs = UINT16_MAX;
1451
1452         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1453                         &ts_params->conf),
1454                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1455                         " invalid qps: %u",
1456                         ts_params->valid_devs[0],
1457                         ts_params->conf.nb_queue_pairs);
1458
1459
1460         /* invalid - max value + 1 queue pairs */
1461         ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1462
1463         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1464                         &ts_params->conf),
1465                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1466                         " invalid qps: %u",
1467                         ts_params->valid_devs[0],
1468                         ts_params->conf.nb_queue_pairs);
1469
1470         /* revert to original testsuite value */
1471         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1472
1473         return TEST_SUCCESS;
1474 }
1475
1476 static int
1477 test_queue_pair_descriptor_setup(void)
1478 {
1479         struct crypto_testsuite_params *ts_params = &testsuite_params;
1480         struct rte_cryptodev_qp_conf qp_conf = {
1481                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
1482         };
1483         uint16_t qp_id;
1484
1485         /* Stop the device in case it's started so it can be configured */
1486         rte_cryptodev_stop(ts_params->valid_devs[0]);
1487
1488         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1489                         &ts_params->conf),
1490                         "Failed to configure cryptodev %u",
1491                         ts_params->valid_devs[0]);
1492
1493         /*
1494          * Test various ring sizes on this device. memzones can't be
1495          * freed so are re-used if ring is released and re-created.
1496          */
1497         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1498         qp_conf.mp_session = ts_params->session_mpool;
1499         qp_conf.mp_session_private = ts_params->session_priv_mpool;
1500
1501         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1502                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1503                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1504                                 rte_cryptodev_socket_id(
1505                                                 ts_params->valid_devs[0])),
1506                                 "Failed test for "
1507                                 "rte_cryptodev_queue_pair_setup: num_inflights "
1508                                 "%u on qp %u on cryptodev %u",
1509                                 qp_conf.nb_descriptors, qp_id,
1510                                 ts_params->valid_devs[0]);
1511         }
1512
1513         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1514
1515         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1516                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1517                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1518                                 rte_cryptodev_socket_id(
1519                                                 ts_params->valid_devs[0])),
1520                                 "Failed test for"
1521                                 " rte_cryptodev_queue_pair_setup: num_inflights"
1522                                 " %u on qp %u on cryptodev %u",
1523                                 qp_conf.nb_descriptors, qp_id,
1524                                 ts_params->valid_devs[0]);
1525         }
1526
1527         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1528
1529         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1530                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1531                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1532                                 rte_cryptodev_socket_id(
1533                                                 ts_params->valid_devs[0])),
1534                                 "Failed test for "
1535                                 "rte_cryptodev_queue_pair_setup: num_inflights"
1536                                 " %u on qp %u on cryptodev %u",
1537                                 qp_conf.nb_descriptors, qp_id,
1538                                 ts_params->valid_devs[0]);
1539         }
1540
1541         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1542
1543         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1544                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1545                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1546                                 rte_cryptodev_socket_id(
1547                                                 ts_params->valid_devs[0])),
1548                                 "Failed test for"
1549                                 " rte_cryptodev_queue_pair_setup:"
1550                                 "num_inflights %u on qp %u on cryptodev %u",
1551                                 qp_conf.nb_descriptors, qp_id,
1552                                 ts_params->valid_devs[0]);
1553         }
1554
1555         /* test invalid queue pair id */
1556         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
1557
1558         qp_id = ts_params->conf.nb_queue_pairs;         /*invalid */
1559
1560         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1561                         ts_params->valid_devs[0],
1562                         qp_id, &qp_conf,
1563                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1564                         "Failed test for rte_cryptodev_queue_pair_setup:"
1565                         "invalid qp %u on cryptodev %u",
1566                         qp_id, ts_params->valid_devs[0]);
1567
1568         qp_id = 0xffff; /*invalid*/
1569
1570         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1571                         ts_params->valid_devs[0],
1572                         qp_id, &qp_conf,
1573                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1574                         "Failed test for rte_cryptodev_queue_pair_setup:"
1575                         "invalid qp %u on cryptodev %u",
1576                         qp_id, ts_params->valid_devs[0]);
1577
1578         return TEST_SUCCESS;
1579 }
1580
1581 /* ***** Plaintext data for tests ***** */
1582
1583 const char catch_22_quote_1[] =
1584                 "There was only one catch and that was Catch-22, which "
1585                 "specified that a concern for one's safety in the face of "
1586                 "dangers that were real and immediate was the process of a "
1587                 "rational mind. Orr was crazy and could be grounded. All he "
1588                 "had to do was ask; and as soon as he did, he would no longer "
1589                 "be crazy and would have to fly more missions. Orr would be "
1590                 "crazy to fly more missions and sane if he didn't, but if he "
1591                 "was sane he had to fly them. If he flew them he was crazy "
1592                 "and didn't have to; but if he didn't want to he was sane and "
1593                 "had to. Yossarian was moved very deeply by the absolute "
1594                 "simplicity of this clause of Catch-22 and let out a "
1595                 "respectful whistle. \"That's some catch, that Catch-22\", he "
1596                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
1597
1598 const char catch_22_quote[] =
1599                 "What a lousy earth! He wondered how many people were "
1600                 "destitute that same night even in his own prosperous country, "
1601                 "how many homes were shanties, how many husbands were drunk "
1602                 "and wives socked, and how many children were bullied, abused, "
1603                 "or abandoned. How many families hungered for food they could "
1604                 "not afford to buy? How many hearts were broken? How many "
1605                 "suicides would take place that same night, how many people "
1606                 "would go insane? How many cockroaches and landlords would "
1607                 "triumph? How many winners were losers, successes failures, "
1608                 "and rich men poor men? How many wise guys were stupid? How "
1609                 "many happy endings were unhappy endings? How many honest men "
1610                 "were liars, brave men cowards, loyal men traitors, how many "
1611                 "sainted men were corrupt, how many people in positions of "
1612                 "trust had sold their souls to bodyguards, how many had never "
1613                 "had souls? How many straight-and-narrow paths were crooked "
1614                 "paths? How many best families were worst families and how "
1615                 "many good people were bad people? When you added them all up "
1616                 "and then subtracted, you might be left with only the children, "
1617                 "and perhaps with Albert Einstein and an old violinist or "
1618                 "sculptor somewhere.";
1619
1620 #define QUOTE_480_BYTES         (480)
1621 #define QUOTE_512_BYTES         (512)
1622 #define QUOTE_768_BYTES         (768)
1623 #define QUOTE_1024_BYTES        (1024)
1624
1625
1626
1627 /* ***** SHA1 Hash Tests ***** */
1628
1629 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
1630
1631 static uint8_t hmac_sha1_key[] = {
1632         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1633         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1634         0xDE, 0xF4, 0xDE, 0xAD };
1635
1636 /* ***** SHA224 Hash Tests ***** */
1637
1638 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
1639
1640
1641 /* ***** AES-CBC Cipher Tests ***** */
1642
1643 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
1644 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
1645
1646 static uint8_t aes_cbc_key[] = {
1647         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1648         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1649
1650 static uint8_t aes_cbc_iv[] = {
1651         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1652         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1653
1654
1655 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1656
1657 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1658         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1659         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1660         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1661         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1662         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1663         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1664         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1665         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1666         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1667         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1668         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1669         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1670         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1671         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1672         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1673         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1674         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1675         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1676         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1677         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1678         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1679         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1680         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1681         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1682         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1683         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1684         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1685         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1686         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1687         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1688         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1689         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1690         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1691         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1692         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1693         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1694         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1695         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1696         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1697         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1698         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1699         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1700         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1701         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1702         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1703         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1704         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1705         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1706         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1707         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1708         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1709         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1710         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1711         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1712         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1713         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1714         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1715         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1716         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1717         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1718         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1719         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1720         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1721         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1722 };
1723
1724 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1725         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1726         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1727         0x18, 0x8c, 0x1d, 0x32
1728 };
1729
1730
1731 /* Multisession Vector context Test */
1732 /*Begin Session 0 */
1733 static uint8_t ms_aes_cbc_key0[] = {
1734         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1735         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1736 };
1737
1738 static uint8_t ms_aes_cbc_iv0[] = {
1739         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1740         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1741 };
1742
1743 static const uint8_t ms_aes_cbc_cipher0[] = {
1744                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1745                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1746                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1747                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1748                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1749                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1750                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1751                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1752                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1753                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1754                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1755                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1756                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1757                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1758                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1759                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1760                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1761                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1762                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1763                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1764                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1765                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1766                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1767                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1768                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1769                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1770                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1771                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1772                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1773                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1774                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1775                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1776                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1777                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1778                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1779                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1780                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1781                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1782                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1783                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1784                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1785                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1786                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1787                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1788                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1789                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1790                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1791                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1792                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1793                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1794                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1795                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1796                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1797                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1798                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1799                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1800                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1801                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1802                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1803                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1804                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1805                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1806                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1807                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1808 };
1809
1810
1811 static  uint8_t ms_hmac_key0[] = {
1812                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1813                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1814                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1815                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1816                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1817                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1818                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1819                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1820 };
1821
1822 static const uint8_t ms_hmac_digest0[] = {
1823                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1824                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1825                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1826                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1827                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1828                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1829                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1830                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1831                 };
1832
1833 /* End Session 0 */
1834 /* Begin session 1 */
1835
1836 static  uint8_t ms_aes_cbc_key1[] = {
1837                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1838                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1839 };
1840
1841 static  uint8_t ms_aes_cbc_iv1[] = {
1842         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1843         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1844 };
1845
1846 static const uint8_t ms_aes_cbc_cipher1[] = {
1847                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1848                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1849                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1850                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1851                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1852                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1853                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1854                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1855                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1856                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1857                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1858                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1859                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1860                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1861                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1862                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1863                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1864                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1865                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1866                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1867                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1868                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1869                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1870                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1871                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1872                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1873                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1874                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1875                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1876                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1877                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1878                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1879                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1880                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1881                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1882                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1883                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1884                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1885                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1886                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1887                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1888                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1889                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1890                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1891                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1892                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1893                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1894                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1895                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1896                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1897                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1898                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1899                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1900                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1901                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1902                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1903                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1904                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1905                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1906                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1907                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1908                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1909                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1910                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1911
1912 };
1913
1914 static uint8_t ms_hmac_key1[] = {
1915                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1916                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1917                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1918                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1919                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1920                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1921                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1922                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1923 };
1924
1925 static const uint8_t ms_hmac_digest1[] = {
1926                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1927                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1928                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1929                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1930                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1931                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1932                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1933                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1934 };
1935 /* End Session 1  */
1936 /* Begin Session 2 */
1937 static  uint8_t ms_aes_cbc_key2[] = {
1938                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1939                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1940 };
1941
1942 static  uint8_t ms_aes_cbc_iv2[] = {
1943                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1944                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1945 };
1946
1947 static const uint8_t ms_aes_cbc_cipher2[] = {
1948                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1949                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1950                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1951                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1952                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1953                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1954                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1955                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1956                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1957                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1958                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1959                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1960                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1961                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1962                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1963                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1964                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1965                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1966                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1967                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1968                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1969                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1970                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1971                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1972                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1973                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1974                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1975                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1976                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1977                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1978                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1979                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1980                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1981                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1982                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1983                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1984                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1985                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1986                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1987                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1988                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1989                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1990                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1991                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1992                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1993                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
1994                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
1995                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
1996                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
1997                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
1998                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
1999                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2000                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2001                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2002                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2003                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2004                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2005                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2006                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2007                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2008                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2009                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2010                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2011                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2012 };
2013
2014 static  uint8_t ms_hmac_key2[] = {
2015                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2016                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2017                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2018                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2019                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2020                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2021                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2022                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2023 };
2024
2025 static const uint8_t ms_hmac_digest2[] = {
2026                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2027                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2028                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2029                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2030                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2031                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2032                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2033                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2034 };
2035
2036 /* End Session 2 */
2037
2038
2039 static int
2040 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2041 {
2042         struct crypto_testsuite_params *ts_params = &testsuite_params;
2043         struct crypto_unittest_params *ut_params = &unittest_params;
2044
2045         /* Verify the capabilities */
2046         struct rte_cryptodev_sym_capability_idx cap_idx;
2047         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2048         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2049         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2050                         &cap_idx) == NULL)
2051                 return TEST_SKIPPED;
2052         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2053         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2054         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2055                         &cap_idx) == NULL)
2056                 return TEST_SKIPPED;
2057
2058         /* Generate test mbuf data and space for digest */
2059         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2060                         catch_22_quote, QUOTE_512_BYTES, 0);
2061
2062         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2063                         DIGEST_BYTE_LENGTH_SHA1);
2064         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2065
2066         /* Setup Cipher Parameters */
2067         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2068         ut_params->cipher_xform.next = &ut_params->auth_xform;
2069
2070         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2071         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2072         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2073         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2074         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2075         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2076
2077         /* Setup HMAC Parameters */
2078         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2079
2080         ut_params->auth_xform.next = NULL;
2081
2082         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2083         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2084         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2085         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2086         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2087
2088         ut_params->sess = rte_cryptodev_sym_session_create(
2089                         ts_params->session_mpool);
2090
2091         /* Create crypto session*/
2092         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2093                         ut_params->sess, &ut_params->cipher_xform,
2094                         ts_params->session_priv_mpool);
2095         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2096
2097         /* Generate crypto op data structure */
2098         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2099                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2100         TEST_ASSERT_NOT_NULL(ut_params->op,
2101                         "Failed to allocate symmetric crypto operation struct");
2102
2103         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2104
2105         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2106
2107         /* set crypto operation source mbuf */
2108         sym_op->m_src = ut_params->ibuf;
2109
2110         /* Set crypto operation authentication parameters */
2111         sym_op->auth.digest.data = ut_params->digest;
2112         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2113                         ut_params->ibuf, QUOTE_512_BYTES);
2114
2115         sym_op->auth.data.offset = 0;
2116         sym_op->auth.data.length = QUOTE_512_BYTES;
2117
2118         /* Copy IV at the end of the crypto operation */
2119         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2120                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2121
2122         /* Set crypto operation cipher parameters */
2123         sym_op->cipher.data.offset = 0;
2124         sym_op->cipher.data.length = QUOTE_512_BYTES;
2125
2126         /* Process crypto operation */
2127         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2128                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2129                         ut_params->op);
2130         else
2131                 TEST_ASSERT_NOT_NULL(
2132                         process_crypto_request(ts_params->valid_devs[0],
2133                                 ut_params->op),
2134                                 "failed to process sym crypto op");
2135
2136         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2137                         "crypto op processing failed");
2138
2139         /* Validate obuf */
2140         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2141                         uint8_t *);
2142
2143         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2144                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2145                         QUOTE_512_BYTES,
2146                         "ciphertext data not as expected");
2147
2148         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2149
2150         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2151                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2152                         gbl_driver_id == rte_cryptodev_driver_id_get(
2153                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2154                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2155                                         DIGEST_BYTE_LENGTH_SHA1,
2156                         "Generated digest data not as expected");
2157
2158         return TEST_SUCCESS;
2159 }
2160
2161 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2162
2163 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2164
2165 static uint8_t hmac_sha512_key[] = {
2166         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2167         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2168         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2169         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2170         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2171         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2172         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2173         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2174
2175 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2176         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2177         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2178         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2179         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2180         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2181         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2182         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2183         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2184
2185
2186
2187 static int
2188 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2189                 struct crypto_unittest_params *ut_params,
2190                 uint8_t *cipher_key,
2191                 uint8_t *hmac_key);
2192
2193 static int
2194 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2195                 struct crypto_unittest_params *ut_params,
2196                 struct crypto_testsuite_params *ts_params,
2197                 const uint8_t *cipher,
2198                 const uint8_t *digest,
2199                 const uint8_t *iv);
2200
2201
2202 static int
2203 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2204                 struct crypto_unittest_params *ut_params,
2205                 uint8_t *cipher_key,
2206                 uint8_t *hmac_key)
2207 {
2208
2209         /* Setup Cipher Parameters */
2210         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2211         ut_params->cipher_xform.next = NULL;
2212
2213         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2214         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2215         ut_params->cipher_xform.cipher.key.data = cipher_key;
2216         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2217         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2218         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2219
2220         /* Setup HMAC Parameters */
2221         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2222         ut_params->auth_xform.next = &ut_params->cipher_xform;
2223
2224         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2225         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2226         ut_params->auth_xform.auth.key.data = hmac_key;
2227         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2228         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2229
2230         return TEST_SUCCESS;
2231 }
2232
2233
2234 static int
2235 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2236                 struct crypto_unittest_params *ut_params,
2237                 struct crypto_testsuite_params *ts_params,
2238                 const uint8_t *cipher,
2239                 const uint8_t *digest,
2240                 const uint8_t *iv)
2241 {
2242         /* Generate test mbuf data and digest */
2243         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2244                         (const char *)
2245                         cipher,
2246                         QUOTE_512_BYTES, 0);
2247
2248         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2249                         DIGEST_BYTE_LENGTH_SHA512);
2250         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2251
2252         rte_memcpy(ut_params->digest,
2253                         digest,
2254                         DIGEST_BYTE_LENGTH_SHA512);
2255
2256         /* Generate Crypto op data structure */
2257         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2258                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2259         TEST_ASSERT_NOT_NULL(ut_params->op,
2260                         "Failed to allocate symmetric crypto operation struct");
2261
2262         rte_crypto_op_attach_sym_session(ut_params->op, sess);
2263
2264         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2265
2266         /* set crypto operation source mbuf */
2267         sym_op->m_src = ut_params->ibuf;
2268
2269         sym_op->auth.digest.data = ut_params->digest;
2270         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2271                         ut_params->ibuf, QUOTE_512_BYTES);
2272
2273         sym_op->auth.data.offset = 0;
2274         sym_op->auth.data.length = QUOTE_512_BYTES;
2275
2276         /* Copy IV at the end of the crypto operation */
2277         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2278                         iv, CIPHER_IV_LENGTH_AES_CBC);
2279
2280         sym_op->cipher.data.offset = 0;
2281         sym_op->cipher.data.length = QUOTE_512_BYTES;
2282
2283         /* Process crypto operation */
2284         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2285                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2286                         ut_params->op);
2287         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2288                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2289                                 ut_params->op, 1, 1, 0, 0);
2290         else
2291                 TEST_ASSERT_NOT_NULL(
2292                                 process_crypto_request(ts_params->valid_devs[0],
2293                                         ut_params->op),
2294                                         "failed to process sym crypto op");
2295
2296         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2297                         "crypto op processing failed");
2298
2299         ut_params->obuf = ut_params->op->sym->m_src;
2300
2301         /* Validate obuf */
2302         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2303                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2304                         catch_22_quote,
2305                         QUOTE_512_BYTES,
2306                         "Plaintext data not as expected");
2307
2308         /* Validate obuf */
2309         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2310                         "Digest verification failed");
2311
2312         return TEST_SUCCESS;
2313 }
2314
2315 static int
2316 test_blockcipher(enum blockcipher_test_type test_type)
2317 {
2318         struct crypto_testsuite_params *ts_params = &testsuite_params;
2319         int status;
2320
2321         status = test_blockcipher_all_tests(ts_params->mbuf_pool,
2322                 ts_params->op_mpool,
2323                 ts_params->session_mpool, ts_params->session_priv_mpool,
2324                 ts_params->valid_devs[0],
2325                 test_type);
2326
2327         if (status == -ENOTSUP)
2328                 return status;
2329
2330         TEST_ASSERT_EQUAL(status, 0, "Test failed");
2331
2332         return TEST_SUCCESS;
2333 }
2334
2335 static int
2336 test_AES_cipheronly_all(void)
2337 {
2338         return test_blockcipher(BLKCIPHER_AES_CIPHERONLY_TYPE);
2339 }
2340
2341 static int
2342 test_AES_docsis_all(void)
2343 {
2344         /* Data-path service does not support DOCSIS yet */
2345         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2346                 return TEST_SKIPPED;
2347         return test_blockcipher(BLKCIPHER_AES_DOCSIS_TYPE);
2348 }
2349
2350 static int
2351 test_DES_docsis_all(void)
2352 {
2353         /* Data-path service does not support DOCSIS yet */
2354         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2355                 return TEST_SKIPPED;
2356         return test_blockcipher(BLKCIPHER_DES_DOCSIS_TYPE);
2357 }
2358
2359 static int
2360 test_DES_cipheronly_all(void)
2361 {
2362         return test_blockcipher(BLKCIPHER_DES_CIPHERONLY_TYPE);
2363 }
2364
2365 static int
2366 test_authonly_all(void)
2367 {
2368         return test_blockcipher(BLKCIPHER_AUTHONLY_TYPE);
2369 }
2370
2371 static int
2372 test_AES_chain_all(void)
2373 {
2374         return test_blockcipher(BLKCIPHER_AES_CHAIN_TYPE);
2375 }
2376
2377 static int
2378 test_3DES_chain_all(void)
2379 {
2380         return test_blockcipher(BLKCIPHER_3DES_CHAIN_TYPE);
2381 }
2382
2383 static int
2384 test_3DES_cipheronly_all(void)
2385 {
2386         return test_blockcipher(BLKCIPHER_3DES_CIPHERONLY_TYPE);
2387 }
2388
2389 /* ***** SNOW 3G Tests ***** */
2390 static int
2391 create_wireless_algo_hash_session(uint8_t dev_id,
2392         const uint8_t *key, const uint8_t key_len,
2393         const uint8_t iv_len, const uint8_t auth_len,
2394         enum rte_crypto_auth_operation op,
2395         enum rte_crypto_auth_algorithm algo)
2396 {
2397         uint8_t hash_key[key_len];
2398         int status;
2399
2400         struct crypto_testsuite_params *ts_params = &testsuite_params;
2401         struct crypto_unittest_params *ut_params = &unittest_params;
2402
2403         memcpy(hash_key, key, key_len);
2404
2405         debug_hexdump(stdout, "key:", key, key_len);
2406
2407         /* Setup Authentication Parameters */
2408         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2409         ut_params->auth_xform.next = NULL;
2410
2411         ut_params->auth_xform.auth.op = op;
2412         ut_params->auth_xform.auth.algo = algo;
2413         ut_params->auth_xform.auth.key.length = key_len;
2414         ut_params->auth_xform.auth.key.data = hash_key;
2415         ut_params->auth_xform.auth.digest_length = auth_len;
2416         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2417         ut_params->auth_xform.auth.iv.length = iv_len;
2418         ut_params->sess = rte_cryptodev_sym_session_create(
2419                         ts_params->session_mpool);
2420
2421         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2422                         &ut_params->auth_xform,
2423                         ts_params->session_priv_mpool);
2424         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2425         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2426         return 0;
2427 }
2428
2429 static int
2430 create_wireless_algo_cipher_session(uint8_t dev_id,
2431                         enum rte_crypto_cipher_operation op,
2432                         enum rte_crypto_cipher_algorithm algo,
2433                         const uint8_t *key, const uint8_t key_len,
2434                         uint8_t iv_len)
2435 {
2436         uint8_t cipher_key[key_len];
2437         int status;
2438         struct crypto_testsuite_params *ts_params = &testsuite_params;
2439         struct crypto_unittest_params *ut_params = &unittest_params;
2440
2441         memcpy(cipher_key, key, key_len);
2442
2443         /* Setup Cipher Parameters */
2444         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2445         ut_params->cipher_xform.next = NULL;
2446
2447         ut_params->cipher_xform.cipher.algo = algo;
2448         ut_params->cipher_xform.cipher.op = op;
2449         ut_params->cipher_xform.cipher.key.data = cipher_key;
2450         ut_params->cipher_xform.cipher.key.length = key_len;
2451         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2452         ut_params->cipher_xform.cipher.iv.length = iv_len;
2453
2454         debug_hexdump(stdout, "key:", key, key_len);
2455
2456         /* Create Crypto session */
2457         ut_params->sess = rte_cryptodev_sym_session_create(
2458                         ts_params->session_mpool);
2459
2460         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2461                         &ut_params->cipher_xform,
2462                         ts_params->session_priv_mpool);
2463         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2464         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2465         return 0;
2466 }
2467
2468 static int
2469 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2470                         unsigned int cipher_len,
2471                         unsigned int cipher_offset)
2472 {
2473         struct crypto_testsuite_params *ts_params = &testsuite_params;
2474         struct crypto_unittest_params *ut_params = &unittest_params;
2475
2476         /* Generate Crypto op data structure */
2477         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2478                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2479         TEST_ASSERT_NOT_NULL(ut_params->op,
2480                                 "Failed to allocate pktmbuf offload");
2481
2482         /* Set crypto operation data parameters */
2483         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2484
2485         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2486
2487         /* set crypto operation source mbuf */
2488         sym_op->m_src = ut_params->ibuf;
2489
2490         /* iv */
2491         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2492                         iv, iv_len);
2493         sym_op->cipher.data.length = cipher_len;
2494         sym_op->cipher.data.offset = cipher_offset;
2495         return 0;
2496 }
2497
2498 static int
2499 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2500                         unsigned int cipher_len,
2501                         unsigned int cipher_offset)
2502 {
2503         struct crypto_testsuite_params *ts_params = &testsuite_params;
2504         struct crypto_unittest_params *ut_params = &unittest_params;
2505
2506         /* Generate Crypto op data structure */
2507         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2508                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2509         TEST_ASSERT_NOT_NULL(ut_params->op,
2510                                 "Failed to allocate pktmbuf offload");
2511
2512         /* Set crypto operation data parameters */
2513         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2514
2515         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2516
2517         /* set crypto operation source mbuf */
2518         sym_op->m_src = ut_params->ibuf;
2519         sym_op->m_dst = ut_params->obuf;
2520
2521         /* iv */
2522         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2523                         iv, iv_len);
2524         sym_op->cipher.data.length = cipher_len;
2525         sym_op->cipher.data.offset = cipher_offset;
2526         return 0;
2527 }
2528
2529 static int
2530 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2531                 enum rte_crypto_cipher_operation cipher_op,
2532                 enum rte_crypto_auth_operation auth_op,
2533                 enum rte_crypto_auth_algorithm auth_algo,
2534                 enum rte_crypto_cipher_algorithm cipher_algo,
2535                 const uint8_t *key, uint8_t key_len,
2536                 uint8_t auth_iv_len, uint8_t auth_len,
2537                 uint8_t cipher_iv_len)
2538
2539 {
2540         uint8_t cipher_auth_key[key_len];
2541         int status;
2542
2543         struct crypto_testsuite_params *ts_params = &testsuite_params;
2544         struct crypto_unittest_params *ut_params = &unittest_params;
2545
2546         memcpy(cipher_auth_key, key, key_len);
2547
2548         /* Setup Authentication Parameters */
2549         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2550         ut_params->auth_xform.next = NULL;
2551
2552         ut_params->auth_xform.auth.op = auth_op;
2553         ut_params->auth_xform.auth.algo = auth_algo;
2554         ut_params->auth_xform.auth.key.length = key_len;
2555         /* Hash key = cipher key */
2556         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2557         ut_params->auth_xform.auth.digest_length = auth_len;
2558         /* Auth IV will be after cipher IV */
2559         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2560         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2561
2562         /* Setup Cipher Parameters */
2563         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2564         ut_params->cipher_xform.next = &ut_params->auth_xform;
2565
2566         ut_params->cipher_xform.cipher.algo = cipher_algo;
2567         ut_params->cipher_xform.cipher.op = cipher_op;
2568         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2569         ut_params->cipher_xform.cipher.key.length = key_len;
2570         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2571         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2572
2573         debug_hexdump(stdout, "key:", key, key_len);
2574
2575         /* Create Crypto session*/
2576         ut_params->sess = rte_cryptodev_sym_session_create(
2577                         ts_params->session_mpool);
2578         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2579
2580         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2581                         &ut_params->cipher_xform,
2582                         ts_params->session_priv_mpool);
2583         if (status == -ENOTSUP)
2584                 return TEST_SKIPPED;
2585
2586         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2587         return 0;
2588 }
2589
2590 static int
2591 create_wireless_cipher_auth_session(uint8_t dev_id,
2592                 enum rte_crypto_cipher_operation cipher_op,
2593                 enum rte_crypto_auth_operation auth_op,
2594                 enum rte_crypto_auth_algorithm auth_algo,
2595                 enum rte_crypto_cipher_algorithm cipher_algo,
2596                 const struct wireless_test_data *tdata)
2597 {
2598         const uint8_t key_len = tdata->key.len;
2599         uint8_t cipher_auth_key[key_len];
2600         int status;
2601
2602         struct crypto_testsuite_params *ts_params = &testsuite_params;
2603         struct crypto_unittest_params *ut_params = &unittest_params;
2604         const uint8_t *key = tdata->key.data;
2605         const uint8_t auth_len = tdata->digest.len;
2606         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2607         uint8_t auth_iv_len = tdata->auth_iv.len;
2608
2609         memcpy(cipher_auth_key, key, key_len);
2610
2611         /* Setup Authentication Parameters */
2612         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2613         ut_params->auth_xform.next = NULL;
2614
2615         ut_params->auth_xform.auth.op = auth_op;
2616         ut_params->auth_xform.auth.algo = auth_algo;
2617         ut_params->auth_xform.auth.key.length = key_len;
2618         /* Hash key = cipher key */
2619         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2620         ut_params->auth_xform.auth.digest_length = auth_len;
2621         /* Auth IV will be after cipher IV */
2622         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2623         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2624
2625         /* Setup Cipher Parameters */
2626         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2627         ut_params->cipher_xform.next = &ut_params->auth_xform;
2628
2629         ut_params->cipher_xform.cipher.algo = cipher_algo;
2630         ut_params->cipher_xform.cipher.op = cipher_op;
2631         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2632         ut_params->cipher_xform.cipher.key.length = key_len;
2633         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2634         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2635
2636
2637         debug_hexdump(stdout, "key:", key, key_len);
2638
2639         /* Create Crypto session*/
2640         ut_params->sess = rte_cryptodev_sym_session_create(
2641                         ts_params->session_mpool);
2642
2643         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2644                         &ut_params->cipher_xform,
2645                         ts_params->session_priv_mpool);
2646         if (status == -ENOTSUP)
2647                 return TEST_SKIPPED;
2648
2649         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2650         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2651         return 0;
2652 }
2653
2654 static int
2655 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2656                 const struct wireless_test_data *tdata)
2657 {
2658         return create_wireless_cipher_auth_session(dev_id,
2659                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2660                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2661                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2662 }
2663
2664 static int
2665 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2666                 enum rte_crypto_cipher_operation cipher_op,
2667                 enum rte_crypto_auth_operation auth_op,
2668                 enum rte_crypto_auth_algorithm auth_algo,
2669                 enum rte_crypto_cipher_algorithm cipher_algo,
2670                 const uint8_t *key, const uint8_t key_len,
2671                 uint8_t auth_iv_len, uint8_t auth_len,
2672                 uint8_t cipher_iv_len)
2673 {
2674         uint8_t auth_cipher_key[key_len];
2675         int status;
2676         struct crypto_testsuite_params *ts_params = &testsuite_params;
2677         struct crypto_unittest_params *ut_params = &unittest_params;
2678
2679         memcpy(auth_cipher_key, key, key_len);
2680
2681         /* Setup Authentication Parameters */
2682         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2683         ut_params->auth_xform.auth.op = auth_op;
2684         ut_params->auth_xform.next = &ut_params->cipher_xform;
2685         ut_params->auth_xform.auth.algo = auth_algo;
2686         ut_params->auth_xform.auth.key.length = key_len;
2687         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2688         ut_params->auth_xform.auth.digest_length = auth_len;
2689         /* Auth IV will be after cipher IV */
2690         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2691         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2692
2693         /* Setup Cipher Parameters */
2694         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2695         ut_params->cipher_xform.next = NULL;
2696         ut_params->cipher_xform.cipher.algo = cipher_algo;
2697         ut_params->cipher_xform.cipher.op = cipher_op;
2698         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2699         ut_params->cipher_xform.cipher.key.length = key_len;
2700         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2701         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2702
2703         debug_hexdump(stdout, "key:", key, key_len);
2704
2705         /* Create Crypto session*/
2706         ut_params->sess = rte_cryptodev_sym_session_create(
2707                         ts_params->session_mpool);
2708         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2709
2710         if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2711                 ut_params->auth_xform.next = NULL;
2712                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2713                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2714                                 &ut_params->cipher_xform,
2715                                 ts_params->session_priv_mpool);
2716
2717         } else
2718                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2719                                 &ut_params->auth_xform,
2720                                 ts_params->session_priv_mpool);
2721
2722         if (status == -ENOTSUP)
2723                 return TEST_SKIPPED;
2724
2725         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2726
2727         return 0;
2728 }
2729
2730 static int
2731 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2732                 unsigned int auth_tag_len,
2733                 const uint8_t *iv, unsigned int iv_len,
2734                 unsigned int data_pad_len,
2735                 enum rte_crypto_auth_operation op,
2736                 unsigned int auth_len, unsigned int auth_offset)
2737 {
2738         struct crypto_testsuite_params *ts_params = &testsuite_params;
2739
2740         struct crypto_unittest_params *ut_params = &unittest_params;
2741
2742         /* Generate Crypto op data structure */
2743         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2744                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2745         TEST_ASSERT_NOT_NULL(ut_params->op,
2746                 "Failed to allocate pktmbuf offload");
2747
2748         /* Set crypto operation data parameters */
2749         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2750
2751         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2752
2753         /* set crypto operation source mbuf */
2754         sym_op->m_src = ut_params->ibuf;
2755
2756         /* iv */
2757         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2758                         iv, iv_len);
2759         /* digest */
2760         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2761                                         ut_params->ibuf, auth_tag_len);
2762
2763         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2764                                 "no room to append auth tag");
2765         ut_params->digest = sym_op->auth.digest.data;
2766         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2767                         ut_params->ibuf, data_pad_len);
2768         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2769                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2770         else
2771                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2772
2773         debug_hexdump(stdout, "digest:",
2774                 sym_op->auth.digest.data,
2775                 auth_tag_len);
2776
2777         sym_op->auth.data.length = auth_len;
2778         sym_op->auth.data.offset = auth_offset;
2779
2780         return 0;
2781 }
2782
2783 static int
2784 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2785         enum rte_crypto_auth_operation op)
2786 {
2787         struct crypto_testsuite_params *ts_params = &testsuite_params;
2788         struct crypto_unittest_params *ut_params = &unittest_params;
2789
2790         const uint8_t *auth_tag = tdata->digest.data;
2791         const unsigned int auth_tag_len = tdata->digest.len;
2792         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2793         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2794
2795         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2796         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2797         const uint8_t *auth_iv = tdata->auth_iv.data;
2798         const uint8_t auth_iv_len = tdata->auth_iv.len;
2799         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2800         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2801
2802         /* Generate Crypto op data structure */
2803         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2804                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2805         TEST_ASSERT_NOT_NULL(ut_params->op,
2806                         "Failed to allocate pktmbuf offload");
2807         /* Set crypto operation data parameters */
2808         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2809
2810         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2811
2812         /* set crypto operation source mbuf */
2813         sym_op->m_src = ut_params->ibuf;
2814
2815         /* digest */
2816         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2817                         ut_params->ibuf, auth_tag_len);
2818
2819         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2820                         "no room to append auth tag");
2821         ut_params->digest = sym_op->auth.digest.data;
2822         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2823                         ut_params->ibuf, data_pad_len);
2824         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2825                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2826         else
2827                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2828
2829         debug_hexdump(stdout, "digest:",
2830                 sym_op->auth.digest.data,
2831                 auth_tag_len);
2832
2833         /* Copy cipher and auth IVs at the end of the crypto operation */
2834         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2835                                                 IV_OFFSET);
2836         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2837         iv_ptr += cipher_iv_len;
2838         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2839
2840         sym_op->cipher.data.length = cipher_len;
2841         sym_op->cipher.data.offset = 0;
2842         sym_op->auth.data.length = auth_len;
2843         sym_op->auth.data.offset = 0;
2844
2845         return 0;
2846 }
2847
2848 static int
2849 create_zuc_cipher_hash_generate_operation(
2850                 const struct wireless_test_data *tdata)
2851 {
2852         return create_wireless_cipher_hash_operation(tdata,
2853                 RTE_CRYPTO_AUTH_OP_GENERATE);
2854 }
2855
2856 static int
2857 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2858                 const unsigned auth_tag_len,
2859                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2860                 unsigned data_pad_len,
2861                 enum rte_crypto_auth_operation op,
2862                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2863                 const unsigned cipher_len, const unsigned cipher_offset,
2864                 const unsigned auth_len, const unsigned auth_offset)
2865 {
2866         struct crypto_testsuite_params *ts_params = &testsuite_params;
2867         struct crypto_unittest_params *ut_params = &unittest_params;
2868
2869         enum rte_crypto_cipher_algorithm cipher_algo =
2870                         ut_params->cipher_xform.cipher.algo;
2871         enum rte_crypto_auth_algorithm auth_algo =
2872                         ut_params->auth_xform.auth.algo;
2873
2874         /* Generate Crypto op data structure */
2875         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2876                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2877         TEST_ASSERT_NOT_NULL(ut_params->op,
2878                         "Failed to allocate pktmbuf offload");
2879         /* Set crypto operation data parameters */
2880         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2881
2882         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2883
2884         /* set crypto operation source mbuf */
2885         sym_op->m_src = ut_params->ibuf;
2886
2887         /* digest */
2888         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2889                         ut_params->ibuf, auth_tag_len);
2890
2891         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2892                         "no room to append auth tag");
2893         ut_params->digest = sym_op->auth.digest.data;
2894
2895         if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2896                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2897                                 ut_params->ibuf, data_pad_len);
2898         } else {
2899                 struct rte_mbuf *m = ut_params->ibuf;
2900                 unsigned int offset = data_pad_len;
2901
2902                 while (offset > m->data_len && m->next != NULL) {
2903                         offset -= m->data_len;
2904                         m = m->next;
2905                 }
2906                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2907                         m, offset);
2908         }
2909
2910         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2911                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2912         else
2913                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2914
2915         debug_hexdump(stdout, "digest:",
2916                 sym_op->auth.digest.data,
2917                 auth_tag_len);
2918
2919         /* Copy cipher and auth IVs at the end of the crypto operation */
2920         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2921                                                 IV_OFFSET);
2922         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2923         iv_ptr += cipher_iv_len;
2924         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2925
2926         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2927                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2928                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2929                 sym_op->cipher.data.length = cipher_len;
2930                 sym_op->cipher.data.offset = cipher_offset;
2931         } else {
2932                 sym_op->cipher.data.length = cipher_len >> 3;
2933                 sym_op->cipher.data.offset = cipher_offset >> 3;
2934         }
2935
2936         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2937                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2938                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2939                 sym_op->auth.data.length = auth_len;
2940                 sym_op->auth.data.offset = auth_offset;
2941         } else {
2942                 sym_op->auth.data.length = auth_len >> 3;
2943                 sym_op->auth.data.offset = auth_offset >> 3;
2944         }
2945
2946         return 0;
2947 }
2948
2949 static int
2950 create_wireless_algo_auth_cipher_operation(
2951                 const uint8_t *auth_tag, unsigned int auth_tag_len,
2952                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2953                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2954                 unsigned int data_pad_len,
2955                 unsigned int cipher_len, unsigned int cipher_offset,
2956                 unsigned int auth_len, unsigned int auth_offset,
2957                 uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2958 {
2959         struct crypto_testsuite_params *ts_params = &testsuite_params;
2960         struct crypto_unittest_params *ut_params = &unittest_params;
2961
2962         enum rte_crypto_cipher_algorithm cipher_algo =
2963                         ut_params->cipher_xform.cipher.algo;
2964         enum rte_crypto_auth_algorithm auth_algo =
2965                         ut_params->auth_xform.auth.algo;
2966
2967         /* Generate Crypto op data structure */
2968         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2969                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2970         TEST_ASSERT_NOT_NULL(ut_params->op,
2971                         "Failed to allocate pktmbuf offload");
2972
2973         /* Set crypto operation data parameters */
2974         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2975
2976         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2977
2978         /* set crypto operation mbufs */
2979         sym_op->m_src = ut_params->ibuf;
2980         if (op_mode == OUT_OF_PLACE)
2981                 sym_op->m_dst = ut_params->obuf;
2982
2983         /* digest */
2984         if (!do_sgl) {
2985                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2986                         (op_mode == IN_PLACE ?
2987                                 ut_params->ibuf : ut_params->obuf),
2988                         uint8_t *, data_pad_len);
2989                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2990                         (op_mode == IN_PLACE ?
2991                                 ut_params->ibuf : ut_params->obuf),
2992                         data_pad_len);
2993                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2994         } else {
2995                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2996                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2997                                 sym_op->m_src : sym_op->m_dst);
2998                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2999                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
3000                         sgl_buf = sgl_buf->next;
3001                 }
3002                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
3003                                 uint8_t *, remaining_off);
3004                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
3005                                 remaining_off);
3006                 memset(sym_op->auth.digest.data, 0, remaining_off);
3007                 while (sgl_buf->next != NULL) {
3008                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
3009                                 0, rte_pktmbuf_data_len(sgl_buf));
3010                         sgl_buf = sgl_buf->next;
3011                 }
3012         }
3013
3014         /* Copy digest for the verification */
3015         if (verify)
3016                 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3017
3018         /* Copy cipher and auth IVs at the end of the crypto operation */
3019         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3020                         ut_params->op, uint8_t *, IV_OFFSET);
3021
3022         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3023         iv_ptr += cipher_iv_len;
3024         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3025
3026         /* Only copy over the offset data needed from src to dst in OOP,
3027          * if the auth and cipher offsets are not aligned
3028          */
3029         if (op_mode == OUT_OF_PLACE) {
3030                 if (cipher_offset > auth_offset)
3031                         rte_memcpy(
3032                                 rte_pktmbuf_mtod_offset(
3033                                         sym_op->m_dst,
3034                                         uint8_t *, auth_offset >> 3),
3035                                 rte_pktmbuf_mtod_offset(
3036                                         sym_op->m_src,
3037                                         uint8_t *, auth_offset >> 3),
3038                                 ((cipher_offset >> 3) - (auth_offset >> 3)));
3039         }
3040
3041         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3042                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3043                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3044                 sym_op->cipher.data.length = cipher_len;
3045                 sym_op->cipher.data.offset = cipher_offset;
3046         } else {
3047                 sym_op->cipher.data.length = cipher_len >> 3;
3048                 sym_op->cipher.data.offset = cipher_offset >> 3;
3049         }
3050
3051         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3052                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3053                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3054                 sym_op->auth.data.length = auth_len;
3055                 sym_op->auth.data.offset = auth_offset;
3056         } else {
3057                 sym_op->auth.data.length = auth_len >> 3;
3058                 sym_op->auth.data.offset = auth_offset >> 3;
3059         }
3060
3061         return 0;
3062 }
3063
3064 static int
3065 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3066 {
3067         struct crypto_testsuite_params *ts_params = &testsuite_params;
3068         struct crypto_unittest_params *ut_params = &unittest_params;
3069
3070         int retval;
3071         unsigned plaintext_pad_len;
3072         unsigned plaintext_len;
3073         uint8_t *plaintext;
3074         struct rte_cryptodev_info dev_info;
3075
3076         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3077         uint64_t feat_flags = dev_info.feature_flags;
3078
3079         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3080                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3081                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3082                 return TEST_SKIPPED;
3083         }
3084
3085         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3086                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3087                 printf("Device doesn't support RAW data-path APIs.\n");
3088                 return TEST_SKIPPED;
3089         }
3090
3091         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3092                 return TEST_SKIPPED;
3093
3094         /* Verify the capabilities */
3095         struct rte_cryptodev_sym_capability_idx cap_idx;
3096         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3097         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3098         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3099                         &cap_idx) == NULL)
3100                 return TEST_SKIPPED;
3101
3102         /* Create SNOW 3G session */
3103         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3104                         tdata->key.data, tdata->key.len,
3105                         tdata->auth_iv.len, tdata->digest.len,
3106                         RTE_CRYPTO_AUTH_OP_GENERATE,
3107                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3108         if (retval < 0)
3109                 return retval;
3110
3111         /* alloc mbuf and set payload */
3112         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3113
3114         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3115         rte_pktmbuf_tailroom(ut_params->ibuf));
3116
3117         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3118         /* Append data which is padded to a multiple of */
3119         /* the algorithms block size */
3120         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3121         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3122                                 plaintext_pad_len);
3123         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3124
3125         /* Create SNOW 3G operation */
3126         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3127                         tdata->auth_iv.data, tdata->auth_iv.len,
3128                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3129                         tdata->validAuthLenInBits.len,
3130                         0);
3131         if (retval < 0)
3132                 return retval;
3133
3134         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3135                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3136                                 ut_params->op, 0, 1, 1, 0);
3137         else
3138                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3139                                 ut_params->op);
3140         ut_params->obuf = ut_params->op->sym->m_src;
3141         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3142         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3143                         + plaintext_pad_len;
3144
3145         /* Validate obuf */
3146         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3147         ut_params->digest,
3148         tdata->digest.data,
3149         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3150         "SNOW 3G Generated auth tag not as expected");
3151
3152         return 0;
3153 }
3154
3155 static int
3156 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3157 {
3158         struct crypto_testsuite_params *ts_params = &testsuite_params;
3159         struct crypto_unittest_params *ut_params = &unittest_params;
3160
3161         int retval;
3162         unsigned plaintext_pad_len;
3163         unsigned plaintext_len;
3164         uint8_t *plaintext;
3165         struct rte_cryptodev_info dev_info;
3166
3167         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3168         uint64_t feat_flags = dev_info.feature_flags;
3169
3170         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3171                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3172                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3173                 return TEST_SKIPPED;
3174         }
3175
3176         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3177                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3178                 printf("Device doesn't support RAW data-path APIs.\n");
3179                 return TEST_SKIPPED;
3180         }
3181
3182         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3183                 return TEST_SKIPPED;
3184
3185         /* Verify the capabilities */
3186         struct rte_cryptodev_sym_capability_idx cap_idx;
3187         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3188         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3189         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3190                         &cap_idx) == NULL)
3191                 return TEST_SKIPPED;
3192
3193         /* Create SNOW 3G session */
3194         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3195                                 tdata->key.data, tdata->key.len,
3196                                 tdata->auth_iv.len, tdata->digest.len,
3197                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3198                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3199         if (retval < 0)
3200                 return retval;
3201         /* alloc mbuf and set payload */
3202         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3203
3204         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3205         rte_pktmbuf_tailroom(ut_params->ibuf));
3206
3207         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3208         /* Append data which is padded to a multiple of */
3209         /* the algorithms block size */
3210         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3211         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3212                                 plaintext_pad_len);
3213         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3214
3215         /* Create SNOW 3G operation */
3216         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3217                         tdata->digest.len,
3218                         tdata->auth_iv.data, tdata->auth_iv.len,
3219                         plaintext_pad_len,
3220                         RTE_CRYPTO_AUTH_OP_VERIFY,
3221                         tdata->validAuthLenInBits.len,
3222                         0);
3223         if (retval < 0)
3224                 return retval;
3225
3226         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3227                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3228                                 ut_params->op, 0, 1, 1, 0);
3229         else
3230                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3231                                 ut_params->op);
3232         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3233         ut_params->obuf = ut_params->op->sym->m_src;
3234         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3235                                 + plaintext_pad_len;
3236
3237         /* Validate obuf */
3238         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3239                 return 0;
3240         else
3241                 return -1;
3242
3243         return 0;
3244 }
3245
3246 static int
3247 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3248 {
3249         struct crypto_testsuite_params *ts_params = &testsuite_params;
3250         struct crypto_unittest_params *ut_params = &unittest_params;
3251
3252         int retval;
3253         unsigned plaintext_pad_len;
3254         unsigned plaintext_len;
3255         uint8_t *plaintext;
3256         struct rte_cryptodev_info dev_info;
3257
3258         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3259         uint64_t feat_flags = dev_info.feature_flags;
3260
3261         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3262                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3263                 printf("Device doesn't support RAW data-path APIs.\n");
3264                 return TEST_SKIPPED;
3265         }
3266
3267         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3268                 return TEST_SKIPPED;
3269
3270         /* Verify the capabilities */
3271         struct rte_cryptodev_sym_capability_idx cap_idx;
3272         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3273         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3274         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3275                         &cap_idx) == NULL)
3276                 return TEST_SKIPPED;
3277
3278         /* Create KASUMI session */
3279         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3280                         tdata->key.data, tdata->key.len,
3281                         0, tdata->digest.len,
3282                         RTE_CRYPTO_AUTH_OP_GENERATE,
3283                         RTE_CRYPTO_AUTH_KASUMI_F9);
3284         if (retval < 0)
3285                 return retval;
3286
3287         /* alloc mbuf and set payload */
3288         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3289
3290         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3291         rte_pktmbuf_tailroom(ut_params->ibuf));
3292
3293         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3294         /* Append data which is padded to a multiple of */
3295         /* the algorithms block size */
3296         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3297         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3298                                 plaintext_pad_len);
3299         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3300
3301         /* Create KASUMI operation */
3302         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3303                         NULL, 0,
3304                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3305                         tdata->plaintext.len,
3306                         0);
3307         if (retval < 0)
3308                 return retval;
3309
3310         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3311                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3312                         ut_params->op);
3313         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3314                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3315                                 ut_params->op, 0, 1, 1, 0);
3316         else
3317                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3318                         ut_params->op);
3319
3320         ut_params->obuf = ut_params->op->sym->m_src;
3321         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3322         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3323                         + plaintext_pad_len;
3324
3325         /* Validate obuf */
3326         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3327         ut_params->digest,
3328         tdata->digest.data,
3329         DIGEST_BYTE_LENGTH_KASUMI_F9,
3330         "KASUMI Generated auth tag not as expected");
3331
3332         return 0;
3333 }
3334
3335 static int
3336 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3337 {
3338         struct crypto_testsuite_params *ts_params = &testsuite_params;
3339         struct crypto_unittest_params *ut_params = &unittest_params;
3340
3341         int retval;
3342         unsigned plaintext_pad_len;
3343         unsigned plaintext_len;
3344         uint8_t *plaintext;
3345         struct rte_cryptodev_info dev_info;
3346
3347         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3348         uint64_t feat_flags = dev_info.feature_flags;
3349
3350         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3351                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3352                 printf("Device doesn't support RAW data-path APIs.\n");
3353                 return TEST_SKIPPED;
3354         }
3355
3356         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3357                 return TEST_SKIPPED;
3358
3359         /* Verify the capabilities */
3360         struct rte_cryptodev_sym_capability_idx cap_idx;
3361         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3362         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3363         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3364                         &cap_idx) == NULL)
3365                 return TEST_SKIPPED;
3366
3367         /* Create KASUMI session */
3368         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3369                                 tdata->key.data, tdata->key.len,
3370                                 0, tdata->digest.len,
3371                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3372                                 RTE_CRYPTO_AUTH_KASUMI_F9);
3373         if (retval < 0)
3374                 return retval;
3375         /* alloc mbuf and set payload */
3376         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3377
3378         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3379         rte_pktmbuf_tailroom(ut_params->ibuf));
3380
3381         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3382         /* Append data which is padded to a multiple */
3383         /* of the algorithms block size */
3384         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3385         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3386                                 plaintext_pad_len);
3387         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3388
3389         /* Create KASUMI operation */
3390         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3391                         tdata->digest.len,
3392                         NULL, 0,
3393                         plaintext_pad_len,
3394                         RTE_CRYPTO_AUTH_OP_VERIFY,
3395                         tdata->plaintext.len,
3396                         0);
3397         if (retval < 0)
3398                 return retval;
3399
3400         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3401                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3402                                 ut_params->op, 0, 1, 1, 0);
3403         else
3404                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3405                                 ut_params->op);
3406         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3407         ut_params->obuf = ut_params->op->sym->m_src;
3408         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3409                                 + plaintext_pad_len;
3410
3411         /* Validate obuf */
3412         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3413                 return 0;
3414         else
3415                 return -1;
3416
3417         return 0;
3418 }
3419
3420 static int
3421 test_snow3g_hash_generate_test_case_1(void)
3422 {
3423         return test_snow3g_authentication(&snow3g_hash_test_case_1);
3424 }
3425
3426 static int
3427 test_snow3g_hash_generate_test_case_2(void)
3428 {
3429         return test_snow3g_authentication(&snow3g_hash_test_case_2);
3430 }
3431
3432 static int
3433 test_snow3g_hash_generate_test_case_3(void)
3434 {
3435         return test_snow3g_authentication(&snow3g_hash_test_case_3);
3436 }
3437
3438 static int
3439 test_snow3g_hash_generate_test_case_4(void)
3440 {
3441         return test_snow3g_authentication(&snow3g_hash_test_case_4);
3442 }
3443
3444 static int
3445 test_snow3g_hash_generate_test_case_5(void)
3446 {
3447         return test_snow3g_authentication(&snow3g_hash_test_case_5);
3448 }
3449
3450 static int
3451 test_snow3g_hash_generate_test_case_6(void)
3452 {
3453         return test_snow3g_authentication(&snow3g_hash_test_case_6);
3454 }
3455
3456 static int
3457 test_snow3g_hash_verify_test_case_1(void)
3458 {
3459         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3460
3461 }
3462
3463 static int
3464 test_snow3g_hash_verify_test_case_2(void)
3465 {
3466         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3467 }
3468
3469 static int
3470 test_snow3g_hash_verify_test_case_3(void)
3471 {
3472         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3473 }
3474
3475 static int
3476 test_snow3g_hash_verify_test_case_4(void)
3477 {
3478         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3479 }
3480
3481 static int
3482 test_snow3g_hash_verify_test_case_5(void)
3483 {
3484         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3485 }
3486
3487 static int
3488 test_snow3g_hash_verify_test_case_6(void)
3489 {
3490         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3491 }
3492
3493 static int
3494 test_kasumi_hash_generate_test_case_1(void)
3495 {
3496         return test_kasumi_authentication(&kasumi_hash_test_case_1);
3497 }
3498
3499 static int
3500 test_kasumi_hash_generate_test_case_2(void)
3501 {
3502         return test_kasumi_authentication(&kasumi_hash_test_case_2);
3503 }
3504
3505 static int
3506 test_kasumi_hash_generate_test_case_3(void)
3507 {
3508         return test_kasumi_authentication(&kasumi_hash_test_case_3);
3509 }
3510
3511 static int
3512 test_kasumi_hash_generate_test_case_4(void)
3513 {
3514         return test_kasumi_authentication(&kasumi_hash_test_case_4);
3515 }
3516
3517 static int
3518 test_kasumi_hash_generate_test_case_5(void)
3519 {
3520         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3521 }
3522
3523 static int
3524 test_kasumi_hash_generate_test_case_6(void)
3525 {
3526         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3527 }
3528
3529 static int
3530 test_kasumi_hash_verify_test_case_1(void)
3531 {
3532         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3533 }
3534
3535 static int
3536 test_kasumi_hash_verify_test_case_2(void)
3537 {
3538         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3539 }
3540
3541 static int
3542 test_kasumi_hash_verify_test_case_3(void)
3543 {
3544         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3545 }
3546
3547 static int
3548 test_kasumi_hash_verify_test_case_4(void)
3549 {
3550         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3551 }
3552
3553 static int
3554 test_kasumi_hash_verify_test_case_5(void)
3555 {
3556         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3557 }
3558
3559 static int
3560 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3561 {
3562         struct crypto_testsuite_params *ts_params = &testsuite_params;
3563         struct crypto_unittest_params *ut_params = &unittest_params;
3564
3565         int retval;
3566         uint8_t *plaintext, *ciphertext;
3567         unsigned plaintext_pad_len;
3568         unsigned plaintext_len;
3569         struct rte_cryptodev_info dev_info;
3570
3571         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3572         uint64_t feat_flags = dev_info.feature_flags;
3573
3574         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3575                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3576                 printf("Device doesn't support RAW data-path APIs.\n");
3577                 return TEST_SKIPPED;
3578         }
3579
3580         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3581                 return TEST_SKIPPED;
3582
3583         /* Verify the capabilities */
3584         struct rte_cryptodev_sym_capability_idx cap_idx;
3585         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3586         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3587         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3588                         &cap_idx) == NULL)
3589                 return TEST_SKIPPED;
3590
3591         /* Create KASUMI session */
3592         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3593                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3594                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3595                                         tdata->key.data, tdata->key.len,
3596                                         tdata->cipher_iv.len);
3597         if (retval < 0)
3598                 return retval;
3599
3600         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3601
3602         /* Clear mbuf payload */
3603         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3604                rte_pktmbuf_tailroom(ut_params->ibuf));
3605
3606         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3607         /* Append data which is padded to a multiple */
3608         /* of the algorithms block size */
3609         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3610         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3611                                 plaintext_pad_len);
3612         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3613
3614         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3615
3616         /* Create KASUMI operation */
3617         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3618                                 tdata->cipher_iv.len,
3619                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3620                                 tdata->validCipherOffsetInBits.len);
3621         if (retval < 0)
3622                 return retval;
3623
3624         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3625                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3626                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3627         else
3628                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3629                                 ut_params->op);
3630         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3631
3632         ut_params->obuf = ut_params->op->sym->m_dst;
3633         if (ut_params->obuf)
3634                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3635         else
3636                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3637
3638         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3639
3640         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3641                                 (tdata->validCipherOffsetInBits.len >> 3);
3642         /* Validate obuf */
3643         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3644                 ciphertext,
3645                 reference_ciphertext,
3646                 tdata->validCipherLenInBits.len,
3647                 "KASUMI Ciphertext data not as expected");
3648         return 0;
3649 }
3650
3651 static int
3652 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3653 {
3654         struct crypto_testsuite_params *ts_params = &testsuite_params;
3655         struct crypto_unittest_params *ut_params = &unittest_params;
3656
3657         int retval;
3658
3659         unsigned int plaintext_pad_len;
3660         unsigned int plaintext_len;
3661
3662         uint8_t buffer[10000];
3663         const uint8_t *ciphertext;
3664
3665         struct rte_cryptodev_info dev_info;
3666
3667         /* Verify the capabilities */
3668         struct rte_cryptodev_sym_capability_idx cap_idx;
3669         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3670         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3671         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3672                         &cap_idx) == NULL)
3673                 return TEST_SKIPPED;
3674
3675         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3676
3677         uint64_t feat_flags = dev_info.feature_flags;
3678
3679         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3680                 printf("Device doesn't support in-place scatter-gather. "
3681                                 "Test Skipped.\n");
3682                 return TEST_SKIPPED;
3683         }
3684
3685         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3686                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3687                 printf("Device doesn't support RAW data-path APIs.\n");
3688                 return TEST_SKIPPED;
3689         }
3690
3691         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3692                 return TEST_SKIPPED;
3693
3694         /* Create KASUMI session */
3695         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3696                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3697                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3698                                         tdata->key.data, tdata->key.len,
3699                                         tdata->cipher_iv.len);
3700         if (retval < 0)
3701                 return retval;
3702
3703         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3704
3705
3706         /* Append data which is padded to a multiple */
3707         /* of the algorithms block size */
3708         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3709
3710         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3711                         plaintext_pad_len, 10, 0);
3712
3713         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3714
3715         /* Create KASUMI operation */
3716         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3717                                 tdata->cipher_iv.len,
3718                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3719                                 tdata->validCipherOffsetInBits.len);
3720         if (retval < 0)
3721                 return retval;
3722
3723         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3724                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3725                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3726         else
3727                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3728                                                 ut_params->op);
3729         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3730
3731         ut_params->obuf = ut_params->op->sym->m_dst;
3732
3733         if (ut_params->obuf)
3734                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3735                                 plaintext_len, buffer);
3736         else
3737                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3738                                 tdata->validCipherOffsetInBits.len >> 3,
3739                                 plaintext_len, buffer);
3740
3741         /* Validate obuf */
3742         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3743
3744         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3745                                 (tdata->validCipherOffsetInBits.len >> 3);
3746         /* Validate obuf */
3747         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3748                 ciphertext,
3749                 reference_ciphertext,
3750                 tdata->validCipherLenInBits.len,
3751                 "KASUMI Ciphertext data not as expected");
3752         return 0;
3753 }
3754
3755 static int
3756 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3757 {
3758         struct crypto_testsuite_params *ts_params = &testsuite_params;
3759         struct crypto_unittest_params *ut_params = &unittest_params;
3760
3761         int retval;
3762         uint8_t *plaintext, *ciphertext;
3763         unsigned plaintext_pad_len;
3764         unsigned plaintext_len;
3765
3766         /* Verify the capabilities */
3767         struct rte_cryptodev_sym_capability_idx cap_idx;
3768         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3769         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3770         /* Data-path service does not support OOP */
3771         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3772                         &cap_idx) == NULL)
3773                 return TEST_SKIPPED;
3774
3775         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3776                 return TEST_SKIPPED;
3777
3778         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3779                 return TEST_SKIPPED;
3780
3781         /* Create KASUMI session */
3782         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3783                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3784                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3785                                         tdata->key.data, tdata->key.len,
3786                                         tdata->cipher_iv.len);
3787         if (retval < 0)
3788                 return retval;
3789
3790         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3791         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3792
3793         /* Clear mbuf payload */
3794         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3795                rte_pktmbuf_tailroom(ut_params->ibuf));
3796
3797         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3798         /* Append data which is padded to a multiple */
3799         /* of the algorithms block size */
3800         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3801         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3802                                 plaintext_pad_len);
3803         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3804         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3805
3806         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3807
3808         /* Create KASUMI operation */
3809         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3810                                 tdata->cipher_iv.len,
3811                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3812                                 tdata->validCipherOffsetInBits.len);
3813         if (retval < 0)
3814                 return retval;
3815
3816         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3817                                                 ut_params->op);
3818         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3819
3820         ut_params->obuf = ut_params->op->sym->m_dst;
3821         if (ut_params->obuf)
3822                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3823         else
3824                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3825
3826         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3827
3828         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3829                                 (tdata->validCipherOffsetInBits.len >> 3);
3830         /* Validate obuf */
3831         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3832                 ciphertext,
3833                 reference_ciphertext,
3834                 tdata->validCipherLenInBits.len,
3835                 "KASUMI Ciphertext data not as expected");
3836         return 0;
3837 }
3838
3839 static int
3840 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3841 {
3842         struct crypto_testsuite_params *ts_params = &testsuite_params;
3843         struct crypto_unittest_params *ut_params = &unittest_params;
3844
3845         int retval;
3846         unsigned int plaintext_pad_len;
3847         unsigned int plaintext_len;
3848
3849         const uint8_t *ciphertext;
3850         uint8_t buffer[2048];
3851
3852         struct rte_cryptodev_info dev_info;
3853
3854         /* Verify the capabilities */
3855         struct rte_cryptodev_sym_capability_idx cap_idx;
3856         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3857         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3858         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3859                         &cap_idx) == NULL)
3860                 return TEST_SKIPPED;
3861
3862         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3863                 return TEST_SKIPPED;
3864
3865         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3866                 return TEST_SKIPPED;
3867
3868         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3869
3870         uint64_t feat_flags = dev_info.feature_flags;
3871         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3872                 printf("Device doesn't support out-of-place scatter-gather "
3873                                 "in both input and output mbufs. "
3874                                 "Test Skipped.\n");
3875                 return TEST_SKIPPED;
3876         }
3877
3878         /* Create KASUMI session */
3879         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3880                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3881                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3882                                         tdata->key.data, tdata->key.len,
3883                                         tdata->cipher_iv.len);
3884         if (retval < 0)
3885                 return retval;
3886
3887         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3888         /* Append data which is padded to a multiple */
3889         /* of the algorithms block size */
3890         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3891
3892         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3893                         plaintext_pad_len, 10, 0);
3894         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3895                         plaintext_pad_len, 3, 0);
3896
3897         /* Append data which is padded to a multiple */
3898         /* of the algorithms block size */
3899         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3900
3901         /* Create KASUMI operation */
3902         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3903                                 tdata->cipher_iv.len,
3904                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3905                                 tdata->validCipherOffsetInBits.len);
3906         if (retval < 0)
3907                 return retval;
3908
3909         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3910                                                 ut_params->op);
3911         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3912
3913         ut_params->obuf = ut_params->op->sym->m_dst;
3914         if (ut_params->obuf)
3915                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3916                                 plaintext_pad_len, buffer);
3917         else
3918                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3919                                 tdata->validCipherOffsetInBits.len >> 3,
3920                                 plaintext_pad_len, buffer);
3921
3922         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3923                                 (tdata->validCipherOffsetInBits.len >> 3);
3924         /* Validate obuf */
3925         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3926                 ciphertext,
3927                 reference_ciphertext,
3928                 tdata->validCipherLenInBits.len,
3929                 "KASUMI Ciphertext data not as expected");
3930         return 0;
3931 }
3932
3933
3934 static int
3935 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3936 {
3937         struct crypto_testsuite_params *ts_params = &testsuite_params;
3938         struct crypto_unittest_params *ut_params = &unittest_params;
3939
3940         int retval;
3941         uint8_t *ciphertext, *plaintext;
3942         unsigned ciphertext_pad_len;
3943         unsigned ciphertext_len;
3944
3945         /* Verify the capabilities */
3946         struct rte_cryptodev_sym_capability_idx cap_idx;
3947         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3948         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3949         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3950                         &cap_idx) == NULL)
3951                 return TEST_SKIPPED;
3952
3953         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3954                 return TEST_SKIPPED;
3955
3956         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3957                 return TEST_SKIPPED;
3958
3959         /* Create KASUMI session */
3960         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3961                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3962                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3963                                         tdata->key.data, tdata->key.len,
3964                                         tdata->cipher_iv.len);
3965         if (retval < 0)
3966                 return retval;
3967
3968         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3969         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3970
3971         /* Clear mbuf payload */
3972         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3973                rte_pktmbuf_tailroom(ut_params->ibuf));
3974
3975         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3976         /* Append data which is padded to a multiple */
3977         /* of the algorithms block size */
3978         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3979         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3980                                 ciphertext_pad_len);
3981         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3982         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3983
3984         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3985
3986         /* Create KASUMI operation */
3987         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3988                                 tdata->cipher_iv.len,
3989                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3990                                 tdata->validCipherOffsetInBits.len);
3991         if (retval < 0)
3992                 return retval;
3993
3994         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3995                                                 ut_params->op);
3996         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3997
3998         ut_params->obuf = ut_params->op->sym->m_dst;
3999         if (ut_params->obuf)
4000                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4001         else
4002                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4003
4004         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4005
4006         const uint8_t *reference_plaintext = tdata->plaintext.data +
4007                                 (tdata->validCipherOffsetInBits.len >> 3);
4008         /* Validate obuf */
4009         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4010                 plaintext,
4011                 reference_plaintext,
4012                 tdata->validCipherLenInBits.len,
4013                 "KASUMI Plaintext data not as expected");
4014         return 0;
4015 }
4016
4017 static int
4018 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4019 {
4020         struct crypto_testsuite_params *ts_params = &testsuite_params;
4021         struct crypto_unittest_params *ut_params = &unittest_params;
4022
4023         int retval;
4024         uint8_t *ciphertext, *plaintext;
4025         unsigned ciphertext_pad_len;
4026         unsigned ciphertext_len;
4027         struct rte_cryptodev_info dev_info;
4028
4029         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4030         uint64_t feat_flags = dev_info.feature_flags;
4031
4032         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4033                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4034                 printf("Device doesn't support RAW data-path APIs.\n");
4035                 return TEST_SKIPPED;
4036         }
4037
4038         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4039                 return TEST_SKIPPED;
4040
4041         /* Verify the capabilities */
4042         struct rte_cryptodev_sym_capability_idx cap_idx;
4043         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4044         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4045         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4046                         &cap_idx) == NULL)
4047                 return TEST_SKIPPED;
4048
4049         /* Create KASUMI session */
4050         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4051                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4052                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
4053                                         tdata->key.data, tdata->key.len,
4054                                         tdata->cipher_iv.len);
4055         if (retval < 0)
4056                 return retval;
4057
4058         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4059
4060         /* Clear mbuf payload */
4061         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4062                rte_pktmbuf_tailroom(ut_params->ibuf));
4063
4064         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4065         /* Append data which is padded to a multiple */
4066         /* of the algorithms block size */
4067         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4068         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4069                                 ciphertext_pad_len);
4070         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4071
4072         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4073
4074         /* Create KASUMI operation */
4075         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4076                                         tdata->cipher_iv.len,
4077                                         tdata->ciphertext.len,
4078                                         tdata->validCipherOffsetInBits.len);
4079         if (retval < 0)
4080                 return retval;
4081
4082         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4083                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4084                                 ut_params->op, 1, 0, 1, 0);
4085         else
4086                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4087                                                 ut_params->op);
4088         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4089
4090         ut_params->obuf = ut_params->op->sym->m_dst;
4091         if (ut_params->obuf)
4092                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4093         else
4094                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4095
4096         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4097
4098         const uint8_t *reference_plaintext = tdata->plaintext.data +
4099                                 (tdata->validCipherOffsetInBits.len >> 3);
4100         /* Validate obuf */
4101         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4102                 plaintext,
4103                 reference_plaintext,
4104                 tdata->validCipherLenInBits.len,
4105                 "KASUMI Plaintext data not as expected");
4106         return 0;
4107 }
4108
4109 static int
4110 test_snow3g_encryption(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         uint8_t *plaintext, *ciphertext;
4117         unsigned plaintext_pad_len;
4118         unsigned plaintext_len;
4119         struct rte_cryptodev_info dev_info;
4120
4121         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4122         uint64_t feat_flags = dev_info.feature_flags;
4123
4124         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4125                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4126                 printf("Device doesn't support RAW data-path APIs.\n");
4127                 return TEST_SKIPPED;
4128         }
4129
4130         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4131                 return TEST_SKIPPED;
4132
4133         /* Verify the capabilities */
4134         struct rte_cryptodev_sym_capability_idx cap_idx;
4135         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4136         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4137         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4138                         &cap_idx) == NULL)
4139                 return TEST_SKIPPED;
4140
4141         /* Create SNOW 3G session */
4142         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4143                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4144                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4145                                         tdata->key.data, tdata->key.len,
4146                                         tdata->cipher_iv.len);
4147         if (retval < 0)
4148                 return retval;
4149
4150         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4151
4152         /* Clear mbuf payload */
4153         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4154                rte_pktmbuf_tailroom(ut_params->ibuf));
4155
4156         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4157         /* Append data which is padded to a multiple of */
4158         /* the algorithms block size */
4159         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4160         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4161                                 plaintext_pad_len);
4162         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4163
4164         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4165
4166         /* Create SNOW 3G operation */
4167         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4168                                         tdata->cipher_iv.len,
4169                                         tdata->validCipherLenInBits.len,
4170                                         0);
4171         if (retval < 0)
4172                 return retval;
4173
4174         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4175                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4176                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4177         else
4178                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4179                                                 ut_params->op);
4180         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4181
4182         ut_params->obuf = ut_params->op->sym->m_dst;
4183         if (ut_params->obuf)
4184                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4185         else
4186                 ciphertext = plaintext;
4187
4188         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4189
4190         /* Validate obuf */
4191         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4192                 ciphertext,
4193                 tdata->ciphertext.data,
4194                 tdata->validDataLenInBits.len,
4195                 "SNOW 3G Ciphertext data not as expected");
4196         return 0;
4197 }
4198
4199
4200 static int
4201 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4202 {
4203         struct crypto_testsuite_params *ts_params = &testsuite_params;
4204         struct crypto_unittest_params *ut_params = &unittest_params;
4205         uint8_t *plaintext, *ciphertext;
4206
4207         int retval;
4208         unsigned plaintext_pad_len;
4209         unsigned plaintext_len;
4210
4211         /* Verify the capabilities */
4212         struct rte_cryptodev_sym_capability_idx cap_idx;
4213         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4214         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4215         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4216                         &cap_idx) == NULL)
4217                 return TEST_SKIPPED;
4218
4219         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4220                 return TEST_SKIPPED;
4221
4222         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4223                 return TEST_SKIPPED;
4224
4225         /* Create SNOW 3G session */
4226         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4227                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4228                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4229                                         tdata->key.data, tdata->key.len,
4230                                         tdata->cipher_iv.len);
4231         if (retval < 0)
4232                 return retval;
4233
4234         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4235         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4236
4237         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4238                         "Failed to allocate input buffer in mempool");
4239         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4240                         "Failed to allocate output buffer in mempool");
4241
4242         /* Clear mbuf payload */
4243         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4244                rte_pktmbuf_tailroom(ut_params->ibuf));
4245
4246         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4247         /* Append data which is padded to a multiple of */
4248         /* the algorithms block size */
4249         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4250         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4251                                 plaintext_pad_len);
4252         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4253         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4254
4255         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4256
4257         /* Create SNOW 3G operation */
4258         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4259                                         tdata->cipher_iv.len,
4260                                         tdata->validCipherLenInBits.len,
4261                                         0);
4262         if (retval < 0)
4263                 return retval;
4264
4265         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4266                                                 ut_params->op);
4267         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4268
4269         ut_params->obuf = ut_params->op->sym->m_dst;
4270         if (ut_params->obuf)
4271                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4272         else
4273                 ciphertext = plaintext;
4274
4275         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4276
4277         /* Validate obuf */
4278         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4279                 ciphertext,
4280                 tdata->ciphertext.data,
4281                 tdata->validDataLenInBits.len,
4282                 "SNOW 3G Ciphertext data not as expected");
4283         return 0;
4284 }
4285
4286 static int
4287 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4288 {
4289         struct crypto_testsuite_params *ts_params = &testsuite_params;
4290         struct crypto_unittest_params *ut_params = &unittest_params;
4291
4292         int retval;
4293         unsigned int plaintext_pad_len;
4294         unsigned int plaintext_len;
4295         uint8_t buffer[10000];
4296         const uint8_t *ciphertext;
4297
4298         struct rte_cryptodev_info dev_info;
4299
4300         /* Verify the capabilities */
4301         struct rte_cryptodev_sym_capability_idx cap_idx;
4302         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4303         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4304         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4305                         &cap_idx) == NULL)
4306                 return TEST_SKIPPED;
4307
4308         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4309                 return TEST_SKIPPED;
4310
4311         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4312                 return TEST_SKIPPED;
4313
4314         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4315
4316         uint64_t feat_flags = dev_info.feature_flags;
4317
4318         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4319                 printf("Device doesn't support out-of-place scatter-gather "
4320                                 "in both input and output mbufs. "
4321                                 "Test Skipped.\n");
4322                 return TEST_SKIPPED;
4323         }
4324
4325         /* Create SNOW 3G session */
4326         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4327                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4328                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4329                                         tdata->key.data, tdata->key.len,
4330                                         tdata->cipher_iv.len);
4331         if (retval < 0)
4332                 return retval;
4333
4334         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4335         /* Append data which is padded to a multiple of */
4336         /* the algorithms block size */
4337         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4338
4339         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4340                         plaintext_pad_len, 10, 0);
4341         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4342                         plaintext_pad_len, 3, 0);
4343
4344         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4345                         "Failed to allocate input buffer in mempool");
4346         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4347                         "Failed to allocate output buffer in mempool");
4348
4349         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4350
4351         /* Create SNOW 3G operation */
4352         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4353                                         tdata->cipher_iv.len,
4354                                         tdata->validCipherLenInBits.len,
4355                                         0);
4356         if (retval < 0)
4357                 return retval;
4358
4359         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4360                                                 ut_params->op);
4361         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4362
4363         ut_params->obuf = ut_params->op->sym->m_dst;
4364         if (ut_params->obuf)
4365                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4366                                 plaintext_len, buffer);
4367         else
4368                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4369                                 plaintext_len, buffer);
4370
4371         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4372
4373         /* Validate obuf */
4374         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4375                 ciphertext,
4376                 tdata->ciphertext.data,
4377                 tdata->validDataLenInBits.len,
4378                 "SNOW 3G Ciphertext data not as expected");
4379
4380         return 0;
4381 }
4382
4383 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4384 static void
4385 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4386 {
4387         uint8_t curr_byte, prev_byte;
4388         uint32_t length_in_bytes = ceil_byte_length(length + offset);
4389         uint8_t lower_byte_mask = (1 << offset) - 1;
4390         unsigned i;
4391
4392         prev_byte = buffer[0];
4393         buffer[0] >>= offset;
4394
4395         for (i = 1; i < length_in_bytes; i++) {
4396                 curr_byte = buffer[i];
4397                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4398                                 (curr_byte >> offset);
4399                 prev_byte = curr_byte;
4400         }
4401 }
4402
4403 static int
4404 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4405 {
4406         struct crypto_testsuite_params *ts_params = &testsuite_params;
4407         struct crypto_unittest_params *ut_params = &unittest_params;
4408         uint8_t *plaintext, *ciphertext;
4409         int retval;
4410         uint32_t plaintext_len;
4411         uint32_t plaintext_pad_len;
4412         uint8_t extra_offset = 4;
4413         uint8_t *expected_ciphertext_shifted;
4414         struct rte_cryptodev_info dev_info;
4415
4416         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4417         uint64_t feat_flags = dev_info.feature_flags;
4418
4419         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4420                         ((tdata->validDataLenInBits.len % 8) != 0)) {
4421                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4422                 return TEST_SKIPPED;
4423         }
4424
4425         /* Verify the capabilities */
4426         struct rte_cryptodev_sym_capability_idx cap_idx;
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 TEST_SKIPPED;
4432
4433         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4434                 return TEST_SKIPPED;
4435
4436         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4437                 return TEST_SKIPPED;
4438
4439         /* Create SNOW 3G session */
4440         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4441                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4442                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4443                                         tdata->key.data, tdata->key.len,
4444                                         tdata->cipher_iv.len);
4445         if (retval < 0)
4446                 return retval;
4447
4448         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4449         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4450
4451         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4452                         "Failed to allocate input buffer in mempool");
4453         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4454                         "Failed to allocate output buffer in mempool");
4455
4456         /* Clear mbuf payload */
4457         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4458                rte_pktmbuf_tailroom(ut_params->ibuf));
4459
4460         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4461         /*
4462          * Append data which is padded to a
4463          * multiple of the algorithms block size
4464          */
4465         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4466
4467         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4468                                                 plaintext_pad_len);
4469
4470         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4471
4472         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4473         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4474
4475 #ifdef RTE_APP_TEST_DEBUG
4476         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4477 #endif
4478         /* Create SNOW 3G operation */
4479         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4480                                         tdata->cipher_iv.len,
4481                                         tdata->validCipherLenInBits.len,
4482                                         extra_offset);
4483         if (retval < 0)
4484                 return retval;
4485
4486         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4487                                                 ut_params->op);
4488         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4489
4490         ut_params->obuf = ut_params->op->sym->m_dst;
4491         if (ut_params->obuf)
4492                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4493         else
4494                 ciphertext = plaintext;
4495
4496 #ifdef RTE_APP_TEST_DEBUG
4497         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4498 #endif
4499
4500         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4501
4502         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4503                         "failed to reserve memory for ciphertext shifted\n");
4504
4505         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4506                         ceil_byte_length(tdata->ciphertext.len));
4507         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4508                         extra_offset);
4509         /* Validate obuf */
4510         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4511                 ciphertext,
4512                 expected_ciphertext_shifted,
4513                 tdata->validDataLenInBits.len,
4514                 extra_offset,
4515                 "SNOW 3G Ciphertext data not as expected");
4516         return 0;
4517 }
4518
4519 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4520 {
4521         struct crypto_testsuite_params *ts_params = &testsuite_params;
4522         struct crypto_unittest_params *ut_params = &unittest_params;
4523
4524         int retval;
4525
4526         uint8_t *plaintext, *ciphertext;
4527         unsigned ciphertext_pad_len;
4528         unsigned ciphertext_len;
4529         struct rte_cryptodev_info dev_info;
4530
4531         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4532         uint64_t feat_flags = dev_info.feature_flags;
4533
4534         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4535                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4536                 printf("Device doesn't support RAW data-path APIs.\n");
4537                 return TEST_SKIPPED;
4538         }
4539
4540         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4541                 return TEST_SKIPPED;
4542
4543         /* Verify the capabilities */
4544         struct rte_cryptodev_sym_capability_idx cap_idx;
4545         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4546         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4547         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4548                         &cap_idx) == NULL)
4549                 return TEST_SKIPPED;
4550
4551         /* Create SNOW 3G session */
4552         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4553                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4554                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4555                                         tdata->key.data, tdata->key.len,
4556                                         tdata->cipher_iv.len);
4557         if (retval < 0)
4558                 return retval;
4559
4560         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4561
4562         /* Clear mbuf payload */
4563         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4564                rte_pktmbuf_tailroom(ut_params->ibuf));
4565
4566         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4567         /* Append data which is padded to a multiple of */
4568         /* the algorithms block size */
4569         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4570         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4571                                 ciphertext_pad_len);
4572         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4573
4574         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4575
4576         /* Create SNOW 3G operation */
4577         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4578                                         tdata->cipher_iv.len,
4579                                         tdata->validCipherLenInBits.len,
4580                                         tdata->cipher.offset_bits);
4581         if (retval < 0)
4582                 return retval;
4583
4584         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4585                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4586                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4587         else
4588                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4589                                                 ut_params->op);
4590         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4591         ut_params->obuf = ut_params->op->sym->m_dst;
4592         if (ut_params->obuf)
4593                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4594         else
4595                 plaintext = ciphertext;
4596
4597         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4598
4599         /* Validate obuf */
4600         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4601                                 tdata->plaintext.data,
4602                                 tdata->validDataLenInBits.len,
4603                                 "SNOW 3G Plaintext data not as expected");
4604         return 0;
4605 }
4606
4607 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4608 {
4609         struct crypto_testsuite_params *ts_params = &testsuite_params;
4610         struct crypto_unittest_params *ut_params = &unittest_params;
4611
4612         int retval;
4613
4614         uint8_t *plaintext, *ciphertext;
4615         unsigned ciphertext_pad_len;
4616         unsigned ciphertext_len;
4617
4618         /* Verify the capabilities */
4619         struct rte_cryptodev_sym_capability_idx cap_idx;
4620         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4621         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4622         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4623                         &cap_idx) == NULL)
4624                 return TEST_SKIPPED;
4625
4626         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4627                 return TEST_SKIPPED;
4628
4629         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4630                 return TEST_SKIPPED;
4631
4632         /* Create SNOW 3G session */
4633         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4634                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4635                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4636                                         tdata->key.data, tdata->key.len,
4637                                         tdata->cipher_iv.len);
4638         if (retval < 0)
4639                 return retval;
4640
4641         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4642         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4643
4644         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4645                         "Failed to allocate input buffer");
4646         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4647                         "Failed to allocate output buffer");
4648
4649         /* Clear mbuf payload */
4650         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4651                rte_pktmbuf_tailroom(ut_params->ibuf));
4652
4653         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4654                        rte_pktmbuf_tailroom(ut_params->obuf));
4655
4656         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4657         /* Append data which is padded to a multiple of */
4658         /* the algorithms block size */
4659         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4660         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4661                                 ciphertext_pad_len);
4662         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4663         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4664
4665         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4666
4667         /* Create SNOW 3G operation */
4668         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4669                                         tdata->cipher_iv.len,
4670                                         tdata->validCipherLenInBits.len,
4671                                         0);
4672         if (retval < 0)
4673                 return retval;
4674
4675         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4676                                                 ut_params->op);
4677         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4678         ut_params->obuf = ut_params->op->sym->m_dst;
4679         if (ut_params->obuf)
4680                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4681         else
4682                 plaintext = ciphertext;
4683
4684         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4685
4686         /* Validate obuf */
4687         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4688                                 tdata->plaintext.data,
4689                                 tdata->validDataLenInBits.len,
4690                                 "SNOW 3G Plaintext data not as expected");
4691         return 0;
4692 }
4693
4694 static int
4695 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4696 {
4697         struct crypto_testsuite_params *ts_params = &testsuite_params;
4698         struct crypto_unittest_params *ut_params = &unittest_params;
4699
4700         int retval;
4701
4702         uint8_t *plaintext, *ciphertext;
4703         unsigned int plaintext_pad_len;
4704         unsigned int plaintext_len;
4705
4706         struct rte_cryptodev_info dev_info;
4707         struct rte_cryptodev_sym_capability_idx cap_idx;
4708
4709         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4710         uint64_t feat_flags = dev_info.feature_flags;
4711
4712         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4713                         ((tdata->validAuthLenInBits.len % 8 != 0) ||
4714                         (tdata->validDataLenInBits.len % 8 != 0))) {
4715                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4716                 return TEST_SKIPPED;
4717         }
4718
4719         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4720                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4721                 printf("Device doesn't support RAW data-path APIs.\n");
4722                 return TEST_SKIPPED;
4723         }
4724
4725         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4726                 return TEST_SKIPPED;
4727
4728         /* Check if device supports ZUC EEA3 */
4729         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4730         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4731
4732         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4733                         &cap_idx) == NULL)
4734                 return TEST_SKIPPED;
4735
4736         /* Check if device supports ZUC EIA3 */
4737         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4738         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4739
4740         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4741                         &cap_idx) == NULL)
4742                 return TEST_SKIPPED;
4743
4744         /* Create ZUC session */
4745         retval = create_zuc_cipher_auth_encrypt_generate_session(
4746                         ts_params->valid_devs[0],
4747                         tdata);
4748         if (retval != 0)
4749                 return retval;
4750         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4751
4752         /* clear mbuf payload */
4753         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4754                         rte_pktmbuf_tailroom(ut_params->ibuf));
4755
4756         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4757         /* Append data which is padded to a multiple of */
4758         /* the algorithms block size */
4759         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4760         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4761                                 plaintext_pad_len);
4762         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4763
4764         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4765
4766         /* Create ZUC operation */
4767         retval = create_zuc_cipher_hash_generate_operation(tdata);
4768         if (retval < 0)
4769                 return retval;
4770
4771         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4772                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4773                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4774         else
4775                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4776                         ut_params->op);
4777         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4778         ut_params->obuf = ut_params->op->sym->m_src;
4779         if (ut_params->obuf)
4780                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4781         else
4782                 ciphertext = plaintext;
4783
4784         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4785         /* Validate obuf */
4786         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4787                         ciphertext,
4788                         tdata->ciphertext.data,
4789                         tdata->validDataLenInBits.len,
4790                         "ZUC Ciphertext data not as expected");
4791
4792         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4793             + plaintext_pad_len;
4794
4795         /* Validate obuf */
4796         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4797                         ut_params->digest,
4798                         tdata->digest.data,
4799                         4,
4800                         "ZUC Generated auth tag not as expected");
4801         return 0;
4802 }
4803
4804 static int
4805 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4806 {
4807         struct crypto_testsuite_params *ts_params = &testsuite_params;
4808         struct crypto_unittest_params *ut_params = &unittest_params;
4809
4810         int retval;
4811
4812         uint8_t *plaintext, *ciphertext;
4813         unsigned plaintext_pad_len;
4814         unsigned plaintext_len;
4815         struct rte_cryptodev_info dev_info;
4816
4817         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4818         uint64_t feat_flags = dev_info.feature_flags;
4819
4820         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4821                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4822                 printf("Device doesn't support RAW data-path APIs.\n");
4823                 return TEST_SKIPPED;
4824         }
4825
4826         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4827                 return TEST_SKIPPED;
4828
4829         /* Verify the capabilities */
4830         struct rte_cryptodev_sym_capability_idx cap_idx;
4831         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4832         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4833         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4834                         &cap_idx) == NULL)
4835                 return TEST_SKIPPED;
4836         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4837         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4838         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4839                         &cap_idx) == NULL)
4840                 return TEST_SKIPPED;
4841
4842         /* Create SNOW 3G session */
4843         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4844                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4845                         RTE_CRYPTO_AUTH_OP_GENERATE,
4846                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4847                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4848                         tdata->key.data, tdata->key.len,
4849                         tdata->auth_iv.len, tdata->digest.len,
4850                         tdata->cipher_iv.len);
4851         if (retval != 0)
4852                 return retval;
4853         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4854
4855         /* clear mbuf payload */
4856         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4857                         rte_pktmbuf_tailroom(ut_params->ibuf));
4858
4859         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4860         /* Append data which is padded to a multiple of */
4861         /* the algorithms block size */
4862         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4863         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4864                                 plaintext_pad_len);
4865         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4866
4867         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4868
4869         /* Create SNOW 3G operation */
4870         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4871                         tdata->digest.len, tdata->auth_iv.data,
4872                         tdata->auth_iv.len,
4873                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4874                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4875                         tdata->validCipherLenInBits.len,
4876                         0,
4877                         tdata->validAuthLenInBits.len,
4878                         0
4879                         );
4880         if (retval < 0)
4881                 return retval;
4882
4883         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4884                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4885                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4886         else
4887                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4888                         ut_params->op);
4889         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4890         ut_params->obuf = ut_params->op->sym->m_src;
4891         if (ut_params->obuf)
4892                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4893         else
4894                 ciphertext = plaintext;
4895
4896         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4897         /* Validate obuf */
4898         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4899                         ciphertext,
4900                         tdata->ciphertext.data,
4901                         tdata->validDataLenInBits.len,
4902                         "SNOW 3G Ciphertext data not as expected");
4903
4904         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4905             + plaintext_pad_len;
4906
4907         /* Validate obuf */
4908         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4909                         ut_params->digest,
4910                         tdata->digest.data,
4911                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4912                         "SNOW 3G Generated auth tag not as expected");
4913         return 0;
4914 }
4915
4916 static int
4917 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4918         uint8_t op_mode, uint8_t verify)
4919 {
4920         struct crypto_testsuite_params *ts_params = &testsuite_params;
4921         struct crypto_unittest_params *ut_params = &unittest_params;
4922
4923         int retval;
4924
4925         uint8_t *plaintext = NULL, *ciphertext = NULL;
4926         unsigned int plaintext_pad_len;
4927         unsigned int plaintext_len;
4928         unsigned int ciphertext_pad_len;
4929         unsigned int ciphertext_len;
4930
4931         struct rte_cryptodev_info dev_info;
4932
4933         /* Verify the capabilities */
4934         struct rte_cryptodev_sym_capability_idx cap_idx;
4935         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4936         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4937         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4938                         &cap_idx) == NULL)
4939                 return TEST_SKIPPED;
4940         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4941         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4942         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4943                         &cap_idx) == NULL)
4944                 return TEST_SKIPPED;
4945
4946         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4947                 return TEST_SKIPPED;
4948
4949         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4950
4951         uint64_t feat_flags = dev_info.feature_flags;
4952
4953         if (op_mode == OUT_OF_PLACE) {
4954                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4955                         printf("Device doesn't support digest encrypted.\n");
4956                         return TEST_SKIPPED;
4957                 }
4958                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4959                         return TEST_SKIPPED;
4960         }
4961
4962         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4963                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4964                 printf("Device doesn't support RAW data-path APIs.\n");
4965                 return TEST_SKIPPED;
4966         }
4967
4968         /* Create SNOW 3G session */
4969         retval = create_wireless_algo_auth_cipher_session(
4970                         ts_params->valid_devs[0],
4971                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4972                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4973                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4974                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4975                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4976                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4977                         tdata->key.data, tdata->key.len,
4978                         tdata->auth_iv.len, tdata->digest.len,
4979                         tdata->cipher_iv.len);
4980         if (retval != 0)
4981                 return retval;
4982
4983         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4984         if (op_mode == OUT_OF_PLACE)
4985                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4986
4987         /* clear mbuf payload */
4988         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4989                 rte_pktmbuf_tailroom(ut_params->ibuf));
4990         if (op_mode == OUT_OF_PLACE)
4991                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4992                         rte_pktmbuf_tailroom(ut_params->obuf));
4993
4994         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4995         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4996         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4997         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4998
4999         if (verify) {
5000                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5001                                         ciphertext_pad_len);
5002                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5003                 if (op_mode == OUT_OF_PLACE)
5004                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5005                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5006                         ciphertext_len);
5007         } else {
5008                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5009                                         plaintext_pad_len);
5010                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5011                 if (op_mode == OUT_OF_PLACE)
5012                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5013                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5014         }
5015
5016         /* Create SNOW 3G 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                 tdata->auth_iv.data, tdata->auth_iv.len,
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->cipher.offset_bits,
5026                 tdata->validAuthLenInBits.len,
5027                 tdata->auth.offset_bits,
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         if (verify) {
5046                 if (ut_params->obuf)
5047                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5048                                                         uint8_t *);
5049                 else
5050                         plaintext = ciphertext +
5051                                 (tdata->cipher.offset_bits >> 3);
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(ut_params->obuf, uint8_t *)
5071                         + (tdata->digest.offset_bytes == 0 ?
5072                 plaintext_pad_len : tdata->digest.offset_bytes);
5073
5074                 debug_hexdump(stdout, "digest:", ut_params->digest,
5075                         tdata->digest.len);
5076                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5077                                 tdata->digest.len);
5078         }
5079
5080         /* Validate obuf */
5081         if (verify) {
5082                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5083                         plaintext,
5084                         tdata->plaintext.data,
5085                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5086                          (tdata->digest.len << 3)),
5087                         tdata->cipher.offset_bits,
5088                         "SNOW 3G Plaintext data not as expected");
5089         } else {
5090                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5091                         ciphertext,
5092                         tdata->ciphertext.data,
5093                         (tdata->validDataLenInBits.len -
5094                          tdata->cipher.offset_bits),
5095                         tdata->cipher.offset_bits,
5096                         "SNOW 3G Ciphertext data not as expected");
5097
5098                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5099                         ut_params->digest,
5100                         tdata->digest.data,
5101                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5102                         "SNOW 3G Generated auth tag not as expected");
5103         }
5104         return 0;
5105 }
5106
5107 static int
5108 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5109         uint8_t op_mode, uint8_t verify)
5110 {
5111         struct crypto_testsuite_params *ts_params = &testsuite_params;
5112         struct crypto_unittest_params *ut_params = &unittest_params;
5113
5114         int retval;
5115
5116         const uint8_t *plaintext = NULL;
5117         const uint8_t *ciphertext = NULL;
5118         const uint8_t *digest = NULL;
5119         unsigned int plaintext_pad_len;
5120         unsigned int plaintext_len;
5121         unsigned int ciphertext_pad_len;
5122         unsigned int ciphertext_len;
5123         uint8_t buffer[10000];
5124         uint8_t digest_buffer[10000];
5125
5126         struct rte_cryptodev_info dev_info;
5127
5128         /* Verify the capabilities */
5129         struct rte_cryptodev_sym_capability_idx cap_idx;
5130         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5131         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5132         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5133                         &cap_idx) == NULL)
5134                 return TEST_SKIPPED;
5135         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5136         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5137         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5138                         &cap_idx) == NULL)
5139                 return TEST_SKIPPED;
5140
5141         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5142                 return TEST_SKIPPED;
5143
5144         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5145
5146         uint64_t feat_flags = dev_info.feature_flags;
5147
5148         if (op_mode == IN_PLACE) {
5149                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5150                         printf("Device doesn't support in-place scatter-gather "
5151                                         "in both input and output mbufs.\n");
5152                         return TEST_SKIPPED;
5153                 }
5154                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5155                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5156                         printf("Device doesn't support RAW data-path APIs.\n");
5157                         return TEST_SKIPPED;
5158                 }
5159         } else {
5160                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5161                         return TEST_SKIPPED;
5162                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5163                         printf("Device doesn't support out-of-place scatter-gather "
5164                                         "in both input and output mbufs.\n");
5165                         return TEST_SKIPPED;
5166                 }
5167                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5168                         printf("Device doesn't support digest encrypted.\n");
5169                         return TEST_SKIPPED;
5170                 }
5171         }
5172
5173         /* Create SNOW 3G session */
5174         retval = create_wireless_algo_auth_cipher_session(
5175                         ts_params->valid_devs[0],
5176                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5177                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5178                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5179                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5180                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5181                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5182                         tdata->key.data, tdata->key.len,
5183                         tdata->auth_iv.len, tdata->digest.len,
5184                         tdata->cipher_iv.len);
5185
5186         if (retval != 0)
5187                 return retval;
5188
5189         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5190         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5191         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5192         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5193
5194         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5195                         plaintext_pad_len, 15, 0);
5196         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5197                         "Failed to allocate input buffer in mempool");
5198
5199         if (op_mode == OUT_OF_PLACE) {
5200                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5201                                 plaintext_pad_len, 15, 0);
5202                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5203                                 "Failed to allocate output buffer in mempool");
5204         }
5205
5206         if (verify) {
5207                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5208                         tdata->ciphertext.data);
5209                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5210                                         ciphertext_len, buffer);
5211                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5212                         ciphertext_len);
5213         } else {
5214                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5215                         tdata->plaintext.data);
5216                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5217                                         plaintext_len, buffer);
5218                 debug_hexdump(stdout, "plaintext:", plaintext,
5219                         plaintext_len);
5220         }
5221         memset(buffer, 0, sizeof(buffer));
5222
5223         /* Create SNOW 3G operation */
5224         retval = create_wireless_algo_auth_cipher_operation(
5225                 tdata->digest.data, tdata->digest.len,
5226                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5227                 tdata->auth_iv.data, tdata->auth_iv.len,
5228                 (tdata->digest.offset_bytes == 0 ?
5229                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5230                         : tdata->digest.offset_bytes),
5231                 tdata->validCipherLenInBits.len,
5232                 tdata->cipher.offset_bits,
5233                 tdata->validAuthLenInBits.len,
5234                 tdata->auth.offset_bits,
5235                 op_mode, 1, verify);
5236
5237         if (retval < 0)
5238                 return retval;
5239
5240         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5241                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5242                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5243         else
5244                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5245                         ut_params->op);
5246
5247         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5248
5249         ut_params->obuf = (op_mode == IN_PLACE ?
5250                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5251
5252         if (verify) {
5253                 if (ut_params->obuf)
5254                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5255                                         plaintext_len, buffer);
5256                 else
5257                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5258                                         plaintext_len, buffer);
5259
5260                 debug_hexdump(stdout, "plaintext:", plaintext,
5261                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5262                 debug_hexdump(stdout, "plaintext expected:",
5263                         tdata->plaintext.data,
5264                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5265         } else {
5266                 if (ut_params->obuf)
5267                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5268                                         ciphertext_len, buffer);
5269                 else
5270                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5271                                         ciphertext_len, buffer);
5272
5273                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5274                         ciphertext_len);
5275                 debug_hexdump(stdout, "ciphertext expected:",
5276                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5277
5278                 if (ut_params->obuf)
5279                         digest = rte_pktmbuf_read(ut_params->obuf,
5280                                 (tdata->digest.offset_bytes == 0 ?
5281                                 plaintext_pad_len : tdata->digest.offset_bytes),
5282                                 tdata->digest.len, digest_buffer);
5283                 else
5284                         digest = rte_pktmbuf_read(ut_params->ibuf,
5285                                 (tdata->digest.offset_bytes == 0 ?
5286                                 plaintext_pad_len : tdata->digest.offset_bytes),
5287                                 tdata->digest.len, digest_buffer);
5288
5289                 debug_hexdump(stdout, "digest:", digest,
5290                         tdata->digest.len);
5291                 debug_hexdump(stdout, "digest expected:",
5292                         tdata->digest.data, tdata->digest.len);
5293         }
5294
5295         /* Validate obuf */
5296         if (verify) {
5297                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5298                         plaintext,
5299                         tdata->plaintext.data,
5300                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5301                          (tdata->digest.len << 3)),
5302                         tdata->cipher.offset_bits,
5303                         "SNOW 3G Plaintext data not as expected");
5304         } else {
5305                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5306                         ciphertext,
5307                         tdata->ciphertext.data,
5308                         (tdata->validDataLenInBits.len -
5309                          tdata->cipher.offset_bits),
5310                         tdata->cipher.offset_bits,
5311                         "SNOW 3G Ciphertext data not as expected");
5312
5313                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5314                         digest,
5315                         tdata->digest.data,
5316                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5317                         "SNOW 3G Generated auth tag not as expected");
5318         }
5319         return 0;
5320 }
5321
5322 static int
5323 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5324         uint8_t op_mode, uint8_t verify)
5325 {
5326         struct crypto_testsuite_params *ts_params = &testsuite_params;
5327         struct crypto_unittest_params *ut_params = &unittest_params;
5328
5329         int retval;
5330
5331         uint8_t *plaintext = NULL, *ciphertext = NULL;
5332         unsigned int plaintext_pad_len;
5333         unsigned int plaintext_len;
5334         unsigned int ciphertext_pad_len;
5335         unsigned int ciphertext_len;
5336
5337         struct rte_cryptodev_info dev_info;
5338
5339         /* Verify the capabilities */
5340         struct rte_cryptodev_sym_capability_idx cap_idx;
5341         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5342         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5343         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5344                         &cap_idx) == NULL)
5345                 return TEST_SKIPPED;
5346         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5347         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5348         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5349                         &cap_idx) == NULL)
5350                 return TEST_SKIPPED;
5351
5352         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5353
5354         uint64_t feat_flags = dev_info.feature_flags;
5355
5356         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5357                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5358                 printf("Device doesn't support RAW data-path APIs.\n");
5359                 return TEST_SKIPPED;
5360         }
5361
5362         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5363                 return TEST_SKIPPED;
5364
5365         if (op_mode == OUT_OF_PLACE) {
5366                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5367                         return TEST_SKIPPED;
5368                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5369                         printf("Device doesn't support digest encrypted.\n");
5370                         return TEST_SKIPPED;
5371                 }
5372         }
5373
5374         /* Create KASUMI session */
5375         retval = create_wireless_algo_auth_cipher_session(
5376                         ts_params->valid_devs[0],
5377                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5378                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5379                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5380                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5381                         RTE_CRYPTO_AUTH_KASUMI_F9,
5382                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5383                         tdata->key.data, tdata->key.len,
5384                         0, tdata->digest.len,
5385                         tdata->cipher_iv.len);
5386
5387         if (retval != 0)
5388                 return retval;
5389
5390         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5391         if (op_mode == OUT_OF_PLACE)
5392                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5393
5394         /* clear mbuf payload */
5395         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5396                 rte_pktmbuf_tailroom(ut_params->ibuf));
5397         if (op_mode == OUT_OF_PLACE)
5398                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5399                         rte_pktmbuf_tailroom(ut_params->obuf));
5400
5401         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5402         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5403         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5404         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5405
5406         if (verify) {
5407                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5408                                         ciphertext_pad_len);
5409                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5410                 if (op_mode == OUT_OF_PLACE)
5411                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5412                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5413                         ciphertext_len);
5414         } else {
5415                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5416                                         plaintext_pad_len);
5417                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5418                 if (op_mode == OUT_OF_PLACE)
5419                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5420                 debug_hexdump(stdout, "plaintext:", plaintext,
5421                         plaintext_len);
5422         }
5423
5424         /* Create KASUMI operation */
5425         retval = create_wireless_algo_auth_cipher_operation(
5426                 tdata->digest.data, tdata->digest.len,
5427                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5428                 NULL, 0,
5429                 (tdata->digest.offset_bytes == 0 ?
5430                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5431                         : tdata->digest.offset_bytes),
5432                 tdata->validCipherLenInBits.len,
5433                 tdata->validCipherOffsetInBits.len,
5434                 tdata->validAuthLenInBits.len,
5435                 0,
5436                 op_mode, 0, verify);
5437
5438         if (retval < 0)
5439                 return retval;
5440
5441         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5442                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5443                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5444         else
5445                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5446                         ut_params->op);
5447
5448         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5449
5450         ut_params->obuf = (op_mode == IN_PLACE ?
5451                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5452
5453
5454         if (verify) {
5455                 if (ut_params->obuf)
5456                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5457                                                         uint8_t *);
5458                 else
5459                         plaintext = ciphertext;
5460
5461                 debug_hexdump(stdout, "plaintext:", plaintext,
5462                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5463                 debug_hexdump(stdout, "plaintext expected:",
5464                         tdata->plaintext.data,
5465                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5466         } else {
5467                 if (ut_params->obuf)
5468                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5469                                                         uint8_t *);
5470                 else
5471                         ciphertext = plaintext;
5472
5473                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5474                         ciphertext_len);
5475                 debug_hexdump(stdout, "ciphertext expected:",
5476                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5477
5478                 ut_params->digest = rte_pktmbuf_mtod(
5479                         ut_params->obuf, uint8_t *) +
5480                         (tdata->digest.offset_bytes == 0 ?
5481                         plaintext_pad_len : tdata->digest.offset_bytes);
5482
5483                 debug_hexdump(stdout, "digest:", ut_params->digest,
5484                         tdata->digest.len);
5485                 debug_hexdump(stdout, "digest expected:",
5486                         tdata->digest.data, tdata->digest.len);
5487         }
5488
5489         /* Validate obuf */
5490         if (verify) {
5491                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5492                         plaintext,
5493                         tdata->plaintext.data,
5494                         tdata->plaintext.len >> 3,
5495                         "KASUMI Plaintext data not as expected");
5496         } else {
5497                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5498                         ciphertext,
5499                         tdata->ciphertext.data,
5500                         tdata->ciphertext.len >> 3,
5501                         "KASUMI Ciphertext data not as expected");
5502
5503                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5504                         ut_params->digest,
5505                         tdata->digest.data,
5506                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5507                         "KASUMI Generated auth tag not as expected");
5508         }
5509         return 0;
5510 }
5511
5512 static int
5513 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5514         uint8_t op_mode, uint8_t verify)
5515 {
5516         struct crypto_testsuite_params *ts_params = &testsuite_params;
5517         struct crypto_unittest_params *ut_params = &unittest_params;
5518
5519         int retval;
5520
5521         const uint8_t *plaintext = NULL;
5522         const uint8_t *ciphertext = NULL;
5523         const uint8_t *digest = NULL;
5524         unsigned int plaintext_pad_len;
5525         unsigned int plaintext_len;
5526         unsigned int ciphertext_pad_len;
5527         unsigned int ciphertext_len;
5528         uint8_t buffer[10000];
5529         uint8_t digest_buffer[10000];
5530
5531         struct rte_cryptodev_info dev_info;
5532
5533         /* Verify the capabilities */
5534         struct rte_cryptodev_sym_capability_idx cap_idx;
5535         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5536         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5537         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5538                         &cap_idx) == NULL)
5539                 return TEST_SKIPPED;
5540         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5541         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5542         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5543                         &cap_idx) == NULL)
5544                 return TEST_SKIPPED;
5545
5546         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5547                 return TEST_SKIPPED;
5548
5549         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5550
5551         uint64_t feat_flags = dev_info.feature_flags;
5552
5553         if (op_mode == IN_PLACE) {
5554                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5555                         printf("Device doesn't support in-place scatter-gather "
5556                                         "in both input and output mbufs.\n");
5557                         return TEST_SKIPPED;
5558                 }
5559                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5560                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5561                         printf("Device doesn't support RAW data-path APIs.\n");
5562                         return TEST_SKIPPED;
5563                 }
5564         } else {
5565                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5566                         return TEST_SKIPPED;
5567                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5568                         printf("Device doesn't support out-of-place scatter-gather "
5569                                         "in both input and output mbufs.\n");
5570                         return TEST_SKIPPED;
5571                 }
5572                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5573                         printf("Device doesn't support digest encrypted.\n");
5574                         return TEST_SKIPPED;
5575                 }
5576         }
5577
5578         /* Create KASUMI session */
5579         retval = create_wireless_algo_auth_cipher_session(
5580                         ts_params->valid_devs[0],
5581                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5582                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5583                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5584                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5585                         RTE_CRYPTO_AUTH_KASUMI_F9,
5586                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5587                         tdata->key.data, tdata->key.len,
5588                         0, tdata->digest.len,
5589                         tdata->cipher_iv.len);
5590
5591         if (retval != 0)
5592                 return retval;
5593
5594         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5595         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5596         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5597         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5598
5599         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5600                         plaintext_pad_len, 15, 0);
5601         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5602                         "Failed to allocate input buffer in mempool");
5603
5604         if (op_mode == OUT_OF_PLACE) {
5605                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5606                                 plaintext_pad_len, 15, 0);
5607                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5608                                 "Failed to allocate output buffer in mempool");
5609         }
5610
5611         if (verify) {
5612                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5613                         tdata->ciphertext.data);
5614                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5615                                         ciphertext_len, buffer);
5616                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5617                         ciphertext_len);
5618         } else {
5619                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5620                         tdata->plaintext.data);
5621                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5622                                         plaintext_len, buffer);
5623                 debug_hexdump(stdout, "plaintext:", plaintext,
5624                         plaintext_len);
5625         }
5626         memset(buffer, 0, sizeof(buffer));
5627
5628         /* Create KASUMI operation */
5629         retval = create_wireless_algo_auth_cipher_operation(
5630                 tdata->digest.data, tdata->digest.len,
5631                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5632                 NULL, 0,
5633                 (tdata->digest.offset_bytes == 0 ?
5634                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5635                         : tdata->digest.offset_bytes),
5636                 tdata->validCipherLenInBits.len,
5637                 tdata->validCipherOffsetInBits.len,
5638                 tdata->validAuthLenInBits.len,
5639                 0,
5640                 op_mode, 1, verify);
5641
5642         if (retval < 0)
5643                 return retval;
5644
5645         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5646                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5647                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5648         else
5649                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5650                         ut_params->op);
5651
5652         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5653
5654         ut_params->obuf = (op_mode == IN_PLACE ?
5655                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5656
5657         if (verify) {
5658                 if (ut_params->obuf)
5659                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5660                                         plaintext_len, buffer);
5661                 else
5662                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5663                                         plaintext_len, buffer);
5664
5665                 debug_hexdump(stdout, "plaintext:", plaintext,
5666                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5667                 debug_hexdump(stdout, "plaintext expected:",
5668                         tdata->plaintext.data,
5669                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5670         } else {
5671                 if (ut_params->obuf)
5672                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5673                                         ciphertext_len, buffer);
5674                 else
5675                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5676                                         ciphertext_len, buffer);
5677
5678                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5679                         ciphertext_len);
5680                 debug_hexdump(stdout, "ciphertext expected:",
5681                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5682
5683                 if (ut_params->obuf)
5684                         digest = rte_pktmbuf_read(ut_params->obuf,
5685                                 (tdata->digest.offset_bytes == 0 ?
5686                                 plaintext_pad_len : tdata->digest.offset_bytes),
5687                                 tdata->digest.len, digest_buffer);
5688                 else
5689                         digest = rte_pktmbuf_read(ut_params->ibuf,
5690                                 (tdata->digest.offset_bytes == 0 ?
5691                                 plaintext_pad_len : tdata->digest.offset_bytes),
5692                                 tdata->digest.len, digest_buffer);
5693
5694                 debug_hexdump(stdout, "digest:", digest,
5695                         tdata->digest.len);
5696                 debug_hexdump(stdout, "digest expected:",
5697                         tdata->digest.data, tdata->digest.len);
5698         }
5699
5700         /* Validate obuf */
5701         if (verify) {
5702                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5703                         plaintext,
5704                         tdata->plaintext.data,
5705                         tdata->plaintext.len >> 3,
5706                         "KASUMI Plaintext data not as expected");
5707         } else {
5708                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5709                         ciphertext,
5710                         tdata->ciphertext.data,
5711                         tdata->validDataLenInBits.len,
5712                         "KASUMI Ciphertext data not as expected");
5713
5714                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5715                         digest,
5716                         tdata->digest.data,
5717                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5718                         "KASUMI Generated auth tag not as expected");
5719         }
5720         return 0;
5721 }
5722
5723 static int
5724 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5725 {
5726         struct crypto_testsuite_params *ts_params = &testsuite_params;
5727         struct crypto_unittest_params *ut_params = &unittest_params;
5728
5729         int retval;
5730
5731         uint8_t *plaintext, *ciphertext;
5732         unsigned plaintext_pad_len;
5733         unsigned plaintext_len;
5734         struct rte_cryptodev_info dev_info;
5735
5736         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5737         uint64_t feat_flags = dev_info.feature_flags;
5738
5739         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5740                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5741                 printf("Device doesn't support RAW data-path APIs.\n");
5742                 return TEST_SKIPPED;
5743         }
5744
5745         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5746                 return TEST_SKIPPED;
5747
5748         /* Verify the capabilities */
5749         struct rte_cryptodev_sym_capability_idx cap_idx;
5750         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5751         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5752         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5753                         &cap_idx) == NULL)
5754                 return TEST_SKIPPED;
5755         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5756         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5757         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5758                         &cap_idx) == NULL)
5759                 return TEST_SKIPPED;
5760
5761         /* Create KASUMI session */
5762         retval = create_wireless_algo_cipher_auth_session(
5763                         ts_params->valid_devs[0],
5764                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5765                         RTE_CRYPTO_AUTH_OP_GENERATE,
5766                         RTE_CRYPTO_AUTH_KASUMI_F9,
5767                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5768                         tdata->key.data, tdata->key.len,
5769                         0, tdata->digest.len,
5770                         tdata->cipher_iv.len);
5771         if (retval != 0)
5772                 return retval;
5773
5774         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5775
5776         /* clear mbuf payload */
5777         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5778                         rte_pktmbuf_tailroom(ut_params->ibuf));
5779
5780         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5781         /* Append data which is padded to a multiple of */
5782         /* the algorithms block size */
5783         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5784         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5785                                 plaintext_pad_len);
5786         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5787
5788         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5789
5790         /* Create KASUMI operation */
5791         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5792                                 tdata->digest.len, NULL, 0,
5793                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5794                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5795                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5796                                 tdata->validCipherOffsetInBits.len,
5797                                 tdata->validAuthLenInBits.len,
5798                                 0
5799                                 );
5800         if (retval < 0)
5801                 return retval;
5802
5803         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5804                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5805                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5806         else
5807                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5808                         ut_params->op);
5809         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5810
5811         if (ut_params->op->sym->m_dst)
5812                 ut_params->obuf = ut_params->op->sym->m_dst;
5813         else
5814                 ut_params->obuf = ut_params->op->sym->m_src;
5815
5816         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5817                                 tdata->validCipherOffsetInBits.len >> 3);
5818
5819         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5820                         + plaintext_pad_len;
5821
5822         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5823                                 (tdata->validCipherOffsetInBits.len >> 3);
5824         /* Validate obuf */
5825         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5826                 ciphertext,
5827                 reference_ciphertext,
5828                 tdata->validCipherLenInBits.len,
5829                 "KASUMI Ciphertext data not as expected");
5830
5831         /* Validate obuf */
5832         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5833                 ut_params->digest,
5834                 tdata->digest.data,
5835                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5836                 "KASUMI Generated auth tag not as expected");
5837         return 0;
5838 }
5839
5840 static int
5841 test_zuc_encryption(const struct wireless_test_data *tdata)
5842 {
5843         struct crypto_testsuite_params *ts_params = &testsuite_params;
5844         struct crypto_unittest_params *ut_params = &unittest_params;
5845
5846         int retval;
5847         uint8_t *plaintext, *ciphertext;
5848         unsigned plaintext_pad_len;
5849         unsigned plaintext_len;
5850         struct rte_cryptodev_info dev_info;
5851
5852         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5853         uint64_t feat_flags = dev_info.feature_flags;
5854
5855         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5856                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5857                 printf("Device doesn't support RAW data-path APIs.\n");
5858                 return TEST_SKIPPED;
5859         }
5860
5861         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5862                 return TEST_SKIPPED;
5863
5864         struct rte_cryptodev_sym_capability_idx cap_idx;
5865
5866         /* Check if device supports ZUC EEA3 */
5867         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5868         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5869
5870         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5871                         &cap_idx) == NULL)
5872                 return TEST_SKIPPED;
5873
5874         /* Create ZUC session */
5875         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5876                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5877                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5878                                         tdata->key.data, tdata->key.len,
5879                                         tdata->cipher_iv.len);
5880         if (retval < 0)
5881                 return retval;
5882
5883         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5884
5885         /* Clear mbuf payload */
5886         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5887                rte_pktmbuf_tailroom(ut_params->ibuf));
5888
5889         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5890         /* Append data which is padded to a multiple */
5891         /* of the algorithms block size */
5892         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5893         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5894                                 plaintext_pad_len);
5895         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5896
5897         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5898
5899         /* Create ZUC operation */
5900         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5901                                         tdata->cipher_iv.len,
5902                                         tdata->plaintext.len,
5903                                         0);
5904         if (retval < 0)
5905                 return retval;
5906
5907         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5908                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5909                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5910         else
5911                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5912                                                 ut_params->op);
5913         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5914
5915         ut_params->obuf = ut_params->op->sym->m_dst;
5916         if (ut_params->obuf)
5917                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5918         else
5919                 ciphertext = plaintext;
5920
5921         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5922
5923         /* Validate obuf */
5924         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5925                 ciphertext,
5926                 tdata->ciphertext.data,
5927                 tdata->validCipherLenInBits.len,
5928                 "ZUC Ciphertext data not as expected");
5929         return 0;
5930 }
5931
5932 static int
5933 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5934 {
5935         struct crypto_testsuite_params *ts_params = &testsuite_params;
5936         struct crypto_unittest_params *ut_params = &unittest_params;
5937
5938         int retval;
5939
5940         unsigned int plaintext_pad_len;
5941         unsigned int plaintext_len;
5942         const uint8_t *ciphertext;
5943         uint8_t ciphertext_buffer[2048];
5944         struct rte_cryptodev_info dev_info;
5945
5946         struct rte_cryptodev_sym_capability_idx cap_idx;
5947
5948         /* Check if device supports ZUC EEA3 */
5949         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5950         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5951
5952         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5953                         &cap_idx) == NULL)
5954                 return TEST_SKIPPED;
5955
5956         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5957                 return TEST_SKIPPED;
5958
5959         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5960
5961         uint64_t feat_flags = dev_info.feature_flags;
5962
5963         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5964                 printf("Device doesn't support in-place scatter-gather. "
5965                                 "Test Skipped.\n");
5966                 return TEST_SKIPPED;
5967         }
5968
5969         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5970                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5971                 printf("Device doesn't support RAW data-path APIs.\n");
5972                 return TEST_SKIPPED;
5973         }
5974
5975         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5976
5977         /* Append data which is padded to a multiple */
5978         /* of the algorithms block size */
5979         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5980
5981         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5982                         plaintext_pad_len, 10, 0);
5983
5984         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5985                         tdata->plaintext.data);
5986
5987         /* Create ZUC session */
5988         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5989                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5990                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5991                         tdata->key.data, tdata->key.len,
5992                         tdata->cipher_iv.len);
5993         if (retval < 0)
5994                 return retval;
5995
5996         /* Clear mbuf payload */
5997
5998         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5999
6000         /* Create ZUC operation */
6001         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6002                         tdata->cipher_iv.len, tdata->plaintext.len,
6003                         0);
6004         if (retval < 0)
6005                 return retval;
6006
6007         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6008                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6009                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6010         else
6011                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6012                                                 ut_params->op);
6013         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6014
6015         ut_params->obuf = ut_params->op->sym->m_dst;
6016         if (ut_params->obuf)
6017                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
6018                         0, plaintext_len, ciphertext_buffer);
6019         else
6020                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6021                         0, plaintext_len, ciphertext_buffer);
6022
6023         /* Validate obuf */
6024         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6025
6026         /* Validate obuf */
6027         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6028                 ciphertext,
6029                 tdata->ciphertext.data,
6030                 tdata->validCipherLenInBits.len,
6031                 "ZUC Ciphertext data not as expected");
6032
6033         return 0;
6034 }
6035
6036 static int
6037 test_zuc_authentication(const struct wireless_test_data *tdata)
6038 {
6039         struct crypto_testsuite_params *ts_params = &testsuite_params;
6040         struct crypto_unittest_params *ut_params = &unittest_params;
6041
6042         int retval;
6043         unsigned plaintext_pad_len;
6044         unsigned plaintext_len;
6045         uint8_t *plaintext;
6046
6047         struct rte_cryptodev_sym_capability_idx cap_idx;
6048         struct rte_cryptodev_info dev_info;
6049
6050         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6051         uint64_t feat_flags = dev_info.feature_flags;
6052
6053         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6054                         (tdata->validAuthLenInBits.len % 8 != 0)) {
6055                 printf("Device doesn't support NON-Byte Aligned Data.\n");
6056                 return TEST_SKIPPED;
6057         }
6058
6059         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6060                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6061                 printf("Device doesn't support RAW data-path APIs.\n");
6062                 return TEST_SKIPPED;
6063         }
6064
6065         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6066                 return TEST_SKIPPED;
6067
6068         /* Check if device supports ZUC EIA3 */
6069         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6070         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6071
6072         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6073                         &cap_idx) == NULL)
6074                 return TEST_SKIPPED;
6075
6076         /* Create ZUC session */
6077         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6078                         tdata->key.data, tdata->key.len,
6079                         tdata->auth_iv.len, tdata->digest.len,
6080                         RTE_CRYPTO_AUTH_OP_GENERATE,
6081                         RTE_CRYPTO_AUTH_ZUC_EIA3);
6082         if (retval < 0)
6083                 return retval;
6084
6085         /* alloc mbuf and set payload */
6086         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6087
6088         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6089         rte_pktmbuf_tailroom(ut_params->ibuf));
6090
6091         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6092         /* Append data which is padded to a multiple of */
6093         /* the algorithms block size */
6094         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6095         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6096                                 plaintext_pad_len);
6097         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6098
6099         /* Create ZUC operation */
6100         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6101                         tdata->auth_iv.data, tdata->auth_iv.len,
6102                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6103                         tdata->validAuthLenInBits.len,
6104                         0);
6105         if (retval < 0)
6106                 return retval;
6107
6108         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6109                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6110                                 ut_params->op, 0, 1, 1, 0);
6111         else
6112                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6113                                 ut_params->op);
6114         ut_params->obuf = ut_params->op->sym->m_src;
6115         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6116         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6117                         + plaintext_pad_len;
6118
6119         /* Validate obuf */
6120         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6121         ut_params->digest,
6122         tdata->digest.data,
6123         tdata->digest.len,
6124         "ZUC Generated auth tag not as expected");
6125
6126         return 0;
6127 }
6128
6129 static int
6130 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6131         uint8_t op_mode, uint8_t verify)
6132 {
6133         struct crypto_testsuite_params *ts_params = &testsuite_params;
6134         struct crypto_unittest_params *ut_params = &unittest_params;
6135
6136         int retval;
6137
6138         uint8_t *plaintext = NULL, *ciphertext = NULL;
6139         unsigned int plaintext_pad_len;
6140         unsigned int plaintext_len;
6141         unsigned int ciphertext_pad_len;
6142         unsigned int ciphertext_len;
6143
6144         struct rte_cryptodev_info dev_info;
6145         struct rte_cryptodev_sym_capability_idx cap_idx;
6146
6147         /* Check if device supports ZUC EIA3 */
6148         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6149         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6150
6151         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6152                         &cap_idx) == NULL)
6153                 return TEST_SKIPPED;
6154
6155         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6156
6157         uint64_t feat_flags = dev_info.feature_flags;
6158
6159         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6160                 printf("Device doesn't support digest encrypted.\n");
6161                 return TEST_SKIPPED;
6162         }
6163         if (op_mode == IN_PLACE) {
6164                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6165                         printf("Device doesn't support in-place scatter-gather "
6166                                         "in both input and output mbufs.\n");
6167                         return TEST_SKIPPED;
6168                 }
6169
6170                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6171                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6172                         printf("Device doesn't support RAW data-path APIs.\n");
6173                         return TEST_SKIPPED;
6174                 }
6175         } else {
6176                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6177                         return TEST_SKIPPED;
6178                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6179                         printf("Device doesn't support out-of-place scatter-gather "
6180                                         "in both input and output mbufs.\n");
6181                         return TEST_SKIPPED;
6182                 }
6183         }
6184
6185         /* Create ZUC session */
6186         retval = create_wireless_algo_auth_cipher_session(
6187                         ts_params->valid_devs[0],
6188                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6189                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6190                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6191                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6192                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6193                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6194                         tdata->key.data, tdata->key.len,
6195                         tdata->auth_iv.len, tdata->digest.len,
6196                         tdata->cipher_iv.len);
6197
6198         if (retval != 0)
6199                 return retval;
6200
6201         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6202         if (op_mode == OUT_OF_PLACE)
6203                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6204
6205         /* clear mbuf payload */
6206         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6207                 rte_pktmbuf_tailroom(ut_params->ibuf));
6208         if (op_mode == OUT_OF_PLACE)
6209                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6210                         rte_pktmbuf_tailroom(ut_params->obuf));
6211
6212         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6213         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6214         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6215         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6216
6217         if (verify) {
6218                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6219                                         ciphertext_pad_len);
6220                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6221                 if (op_mode == OUT_OF_PLACE)
6222                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6223                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6224                         ciphertext_len);
6225         } else {
6226                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6227                                         plaintext_pad_len);
6228                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6229                 if (op_mode == OUT_OF_PLACE)
6230                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6231                 debug_hexdump(stdout, "plaintext:", plaintext,
6232                         plaintext_len);
6233         }
6234
6235         /* Create ZUC operation */
6236         retval = create_wireless_algo_auth_cipher_operation(
6237                 tdata->digest.data, tdata->digest.len,
6238                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6239                 tdata->auth_iv.data, tdata->auth_iv.len,
6240                 (tdata->digest.offset_bytes == 0 ?
6241                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6242                         : tdata->digest.offset_bytes),
6243                 tdata->validCipherLenInBits.len,
6244                 tdata->validCipherOffsetInBits.len,
6245                 tdata->validAuthLenInBits.len,
6246                 0,
6247                 op_mode, 0, verify);
6248
6249         if (retval < 0)
6250                 return retval;
6251
6252         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6253                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6254                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6255         else
6256                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6257                         ut_params->op);
6258
6259         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6260
6261         ut_params->obuf = (op_mode == IN_PLACE ?
6262                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6263
6264
6265         if (verify) {
6266                 if (ut_params->obuf)
6267                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6268                                                         uint8_t *);
6269                 else
6270                         plaintext = ciphertext;
6271
6272                 debug_hexdump(stdout, "plaintext:", plaintext,
6273                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6274                 debug_hexdump(stdout, "plaintext expected:",
6275                         tdata->plaintext.data,
6276                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6277         } else {
6278                 if (ut_params->obuf)
6279                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6280                                                         uint8_t *);
6281                 else
6282                         ciphertext = plaintext;
6283
6284                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6285                         ciphertext_len);
6286                 debug_hexdump(stdout, "ciphertext expected:",
6287                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6288
6289                 ut_params->digest = rte_pktmbuf_mtod(
6290                         ut_params->obuf, uint8_t *) +
6291                         (tdata->digest.offset_bytes == 0 ?
6292                         plaintext_pad_len : tdata->digest.offset_bytes);
6293
6294                 debug_hexdump(stdout, "digest:", ut_params->digest,
6295                         tdata->digest.len);
6296                 debug_hexdump(stdout, "digest expected:",
6297                         tdata->digest.data, tdata->digest.len);
6298         }
6299
6300         /* Validate obuf */
6301         if (verify) {
6302                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6303                         plaintext,
6304                         tdata->plaintext.data,
6305                         tdata->plaintext.len >> 3,
6306                         "ZUC Plaintext data not as expected");
6307         } else {
6308                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6309                         ciphertext,
6310                         tdata->ciphertext.data,
6311                         tdata->ciphertext.len >> 3,
6312                         "ZUC Ciphertext data not as expected");
6313
6314                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6315                         ut_params->digest,
6316                         tdata->digest.data,
6317                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6318                         "ZUC Generated auth tag not as expected");
6319         }
6320         return 0;
6321 }
6322
6323 static int
6324 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6325         uint8_t op_mode, uint8_t verify)
6326 {
6327         struct crypto_testsuite_params *ts_params = &testsuite_params;
6328         struct crypto_unittest_params *ut_params = &unittest_params;
6329
6330         int retval;
6331
6332         const uint8_t *plaintext = NULL;
6333         const uint8_t *ciphertext = NULL;
6334         const uint8_t *digest = NULL;
6335         unsigned int plaintext_pad_len;
6336         unsigned int plaintext_len;
6337         unsigned int ciphertext_pad_len;
6338         unsigned int ciphertext_len;
6339         uint8_t buffer[10000];
6340         uint8_t digest_buffer[10000];
6341
6342         struct rte_cryptodev_info dev_info;
6343         struct rte_cryptodev_sym_capability_idx cap_idx;
6344
6345         /* Check if device supports ZUC EIA3 */
6346         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6347         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6348
6349         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6350                         &cap_idx) == NULL)
6351                 return TEST_SKIPPED;
6352
6353         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6354
6355         uint64_t feat_flags = dev_info.feature_flags;
6356
6357         if (op_mode == IN_PLACE) {
6358                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6359                         printf("Device doesn't support in-place scatter-gather "
6360                                         "in both input and output mbufs.\n");
6361                         return TEST_SKIPPED;
6362                 }
6363
6364                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6365                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6366                         printf("Device doesn't support RAW data-path APIs.\n");
6367                         return TEST_SKIPPED;
6368                 }
6369         } else {
6370                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6371                         return TEST_SKIPPED;
6372                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6373                         printf("Device doesn't support out-of-place scatter-gather "
6374                                         "in both input and output mbufs.\n");
6375                         return TEST_SKIPPED;
6376                 }
6377                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6378                         printf("Device doesn't support digest encrypted.\n");
6379                         return TEST_SKIPPED;
6380                 }
6381         }
6382
6383         /* Create ZUC session */
6384         retval = create_wireless_algo_auth_cipher_session(
6385                         ts_params->valid_devs[0],
6386                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6387                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6388                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6389                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6390                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6391                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6392                         tdata->key.data, tdata->key.len,
6393                         tdata->auth_iv.len, tdata->digest.len,
6394                         tdata->cipher_iv.len);
6395
6396         if (retval != 0)
6397                 return retval;
6398
6399         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6400         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6401         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6402         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6403
6404         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6405                         plaintext_pad_len, 15, 0);
6406         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6407                         "Failed to allocate input buffer in mempool");
6408
6409         if (op_mode == OUT_OF_PLACE) {
6410                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6411                                 plaintext_pad_len, 15, 0);
6412                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6413                                 "Failed to allocate output buffer in mempool");
6414         }
6415
6416         if (verify) {
6417                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6418                         tdata->ciphertext.data);
6419                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6420                                         ciphertext_len, buffer);
6421                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6422                         ciphertext_len);
6423         } else {
6424                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6425                         tdata->plaintext.data);
6426                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6427                                         plaintext_len, buffer);
6428                 debug_hexdump(stdout, "plaintext:", plaintext,
6429                         plaintext_len);
6430         }
6431         memset(buffer, 0, sizeof(buffer));
6432
6433         /* Create ZUC operation */
6434         retval = create_wireless_algo_auth_cipher_operation(
6435                 tdata->digest.data, tdata->digest.len,
6436                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6437                 NULL, 0,
6438                 (tdata->digest.offset_bytes == 0 ?
6439                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6440                         : tdata->digest.offset_bytes),
6441                 tdata->validCipherLenInBits.len,
6442                 tdata->validCipherOffsetInBits.len,
6443                 tdata->validAuthLenInBits.len,
6444                 0,
6445                 op_mode, 1, verify);
6446
6447         if (retval < 0)
6448                 return retval;
6449
6450         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6451                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6452                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6453         else
6454                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6455                         ut_params->op);
6456
6457         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6458
6459         ut_params->obuf = (op_mode == IN_PLACE ?
6460                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6461
6462         if (verify) {
6463                 if (ut_params->obuf)
6464                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6465                                         plaintext_len, buffer);
6466                 else
6467                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6468                                         plaintext_len, buffer);
6469
6470                 debug_hexdump(stdout, "plaintext:", plaintext,
6471                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6472                 debug_hexdump(stdout, "plaintext expected:",
6473                         tdata->plaintext.data,
6474                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6475         } else {
6476                 if (ut_params->obuf)
6477                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6478                                         ciphertext_len, buffer);
6479                 else
6480                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6481                                         ciphertext_len, buffer);
6482
6483                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6484                         ciphertext_len);
6485                 debug_hexdump(stdout, "ciphertext expected:",
6486                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6487
6488                 if (ut_params->obuf)
6489                         digest = rte_pktmbuf_read(ut_params->obuf,
6490                                 (tdata->digest.offset_bytes == 0 ?
6491                                 plaintext_pad_len : tdata->digest.offset_bytes),
6492                                 tdata->digest.len, digest_buffer);
6493                 else
6494                         digest = rte_pktmbuf_read(ut_params->ibuf,
6495                                 (tdata->digest.offset_bytes == 0 ?
6496                                 plaintext_pad_len : tdata->digest.offset_bytes),
6497                                 tdata->digest.len, digest_buffer);
6498
6499                 debug_hexdump(stdout, "digest:", digest,
6500                         tdata->digest.len);
6501                 debug_hexdump(stdout, "digest expected:",
6502                         tdata->digest.data, tdata->digest.len);
6503         }
6504
6505         /* Validate obuf */
6506         if (verify) {
6507                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6508                         plaintext,
6509                         tdata->plaintext.data,
6510                         tdata->plaintext.len >> 3,
6511                         "ZUC Plaintext data not as expected");
6512         } else {
6513                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6514                         ciphertext,
6515                         tdata->ciphertext.data,
6516                         tdata->validDataLenInBits.len,
6517                         "ZUC Ciphertext data not as expected");
6518
6519                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6520                         digest,
6521                         tdata->digest.data,
6522                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6523                         "ZUC Generated auth tag not as expected");
6524         }
6525         return 0;
6526 }
6527
6528 static int
6529 test_kasumi_encryption_test_case_1(void)
6530 {
6531         return test_kasumi_encryption(&kasumi_test_case_1);
6532 }
6533
6534 static int
6535 test_kasumi_encryption_test_case_1_sgl(void)
6536 {
6537         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6538 }
6539
6540 static int
6541 test_kasumi_encryption_test_case_1_oop(void)
6542 {
6543         return test_kasumi_encryption_oop(&kasumi_test_case_1);
6544 }
6545
6546 static int
6547 test_kasumi_encryption_test_case_1_oop_sgl(void)
6548 {
6549         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6550 }
6551
6552 static int
6553 test_kasumi_encryption_test_case_2(void)
6554 {
6555         return test_kasumi_encryption(&kasumi_test_case_2);
6556 }
6557
6558 static int
6559 test_kasumi_encryption_test_case_3(void)
6560 {
6561         return test_kasumi_encryption(&kasumi_test_case_3);
6562 }
6563
6564 static int
6565 test_kasumi_encryption_test_case_4(void)
6566 {
6567         return test_kasumi_encryption(&kasumi_test_case_4);
6568 }
6569
6570 static int
6571 test_kasumi_encryption_test_case_5(void)
6572 {
6573         return test_kasumi_encryption(&kasumi_test_case_5);
6574 }
6575
6576 static int
6577 test_kasumi_decryption_test_case_1(void)
6578 {
6579         return test_kasumi_decryption(&kasumi_test_case_1);
6580 }
6581
6582 static int
6583 test_kasumi_decryption_test_case_1_oop(void)
6584 {
6585         return test_kasumi_decryption_oop(&kasumi_test_case_1);
6586 }
6587
6588 static int
6589 test_kasumi_decryption_test_case_2(void)
6590 {
6591         return test_kasumi_decryption(&kasumi_test_case_2);
6592 }
6593
6594 static int
6595 test_kasumi_decryption_test_case_3(void)
6596 {
6597         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6598         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6599                 return TEST_SKIPPED;
6600         return test_kasumi_decryption(&kasumi_test_case_3);
6601 }
6602
6603 static int
6604 test_kasumi_decryption_test_case_4(void)
6605 {
6606         return test_kasumi_decryption(&kasumi_test_case_4);
6607 }
6608
6609 static int
6610 test_kasumi_decryption_test_case_5(void)
6611 {
6612         return test_kasumi_decryption(&kasumi_test_case_5);
6613 }
6614 static int
6615 test_snow3g_encryption_test_case_1(void)
6616 {
6617         return test_snow3g_encryption(&snow3g_test_case_1);
6618 }
6619
6620 static int
6621 test_snow3g_encryption_test_case_1_oop(void)
6622 {
6623         return test_snow3g_encryption_oop(&snow3g_test_case_1);
6624 }
6625
6626 static int
6627 test_snow3g_encryption_test_case_1_oop_sgl(void)
6628 {
6629         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6630 }
6631
6632
6633 static int
6634 test_snow3g_encryption_test_case_1_offset_oop(void)
6635 {
6636         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6637 }
6638
6639 static int
6640 test_snow3g_encryption_test_case_2(void)
6641 {
6642         return test_snow3g_encryption(&snow3g_test_case_2);
6643 }
6644
6645 static int
6646 test_snow3g_encryption_test_case_3(void)
6647 {
6648         return test_snow3g_encryption(&snow3g_test_case_3);
6649 }
6650
6651 static int
6652 test_snow3g_encryption_test_case_4(void)
6653 {
6654         return test_snow3g_encryption(&snow3g_test_case_4);
6655 }
6656
6657 static int
6658 test_snow3g_encryption_test_case_5(void)
6659 {
6660         return test_snow3g_encryption(&snow3g_test_case_5);
6661 }
6662
6663 static int
6664 test_snow3g_decryption_test_case_1(void)
6665 {
6666         return test_snow3g_decryption(&snow3g_test_case_1);
6667 }
6668
6669 static int
6670 test_snow3g_decryption_test_case_1_oop(void)
6671 {
6672         return test_snow3g_decryption_oop(&snow3g_test_case_1);
6673 }
6674
6675 static int
6676 test_snow3g_decryption_test_case_2(void)
6677 {
6678         return test_snow3g_decryption(&snow3g_test_case_2);
6679 }
6680
6681 static int
6682 test_snow3g_decryption_test_case_3(void)
6683 {
6684         return test_snow3g_decryption(&snow3g_test_case_3);
6685 }
6686
6687 static int
6688 test_snow3g_decryption_test_case_4(void)
6689 {
6690         return test_snow3g_decryption(&snow3g_test_case_4);
6691 }
6692
6693 static int
6694 test_snow3g_decryption_test_case_5(void)
6695 {
6696         return test_snow3g_decryption(&snow3g_test_case_5);
6697 }
6698
6699 /*
6700  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6701  * Pattern digest from snow3g_test_data must be allocated as
6702  * 4 last bytes in plaintext.
6703  */
6704 static void
6705 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6706                 struct snow3g_hash_test_data *output)
6707 {
6708         if ((pattern != NULL) && (output != NULL)) {
6709                 output->key.len = pattern->key.len;
6710
6711                 memcpy(output->key.data,
6712                 pattern->key.data, pattern->key.len);
6713
6714                 output->auth_iv.len = pattern->auth_iv.len;
6715
6716                 memcpy(output->auth_iv.data,
6717                 pattern->auth_iv.data, pattern->auth_iv.len);
6718
6719                 output->plaintext.len = pattern->plaintext.len;
6720
6721                 memcpy(output->plaintext.data,
6722                 pattern->plaintext.data, pattern->plaintext.len >> 3);
6723
6724                 output->digest.len = pattern->digest.len;
6725
6726                 memcpy(output->digest.data,
6727                 &pattern->plaintext.data[pattern->digest.offset_bytes],
6728                 pattern->digest.len);
6729
6730                 output->validAuthLenInBits.len =
6731                 pattern->validAuthLenInBits.len;
6732         }
6733 }
6734
6735 /*
6736  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6737  */
6738 static int
6739 test_snow3g_decryption_with_digest_test_case_1(void)
6740 {
6741         struct snow3g_hash_test_data snow3g_hash_data;
6742         struct rte_cryptodev_info dev_info;
6743         struct crypto_testsuite_params *ts_params = &testsuite_params;
6744
6745         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6746         uint64_t feat_flags = dev_info.feature_flags;
6747
6748         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6749                 printf("Device doesn't support encrypted digest operations.\n");
6750                 return TEST_SKIPPED;
6751         }
6752
6753         /*
6754          * Function prepare data for hash veryfication test case.
6755          * Digest is allocated in 4 last bytes in plaintext, pattern.
6756          */
6757         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6758
6759         return test_snow3g_decryption(&snow3g_test_case_7) &
6760                         test_snow3g_authentication_verify(&snow3g_hash_data);
6761 }
6762
6763 static int
6764 test_snow3g_cipher_auth_test_case_1(void)
6765 {
6766         return test_snow3g_cipher_auth(&snow3g_test_case_3);
6767 }
6768
6769 static int
6770 test_snow3g_auth_cipher_test_case_1(void)
6771 {
6772         return test_snow3g_auth_cipher(
6773                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6774 }
6775
6776 static int
6777 test_snow3g_auth_cipher_test_case_2(void)
6778 {
6779         return test_snow3g_auth_cipher(
6780                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6781 }
6782
6783 static int
6784 test_snow3g_auth_cipher_test_case_2_oop(void)
6785 {
6786         return test_snow3g_auth_cipher(
6787                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6788 }
6789
6790 static int
6791 test_snow3g_auth_cipher_part_digest_enc(void)
6792 {
6793         return test_snow3g_auth_cipher(
6794                 &snow3g_auth_cipher_partial_digest_encryption,
6795                         IN_PLACE, 0);
6796 }
6797
6798 static int
6799 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6800 {
6801         return test_snow3g_auth_cipher(
6802                 &snow3g_auth_cipher_partial_digest_encryption,
6803                         OUT_OF_PLACE, 0);
6804 }
6805
6806 static int
6807 test_snow3g_auth_cipher_test_case_3_sgl(void)
6808 {
6809         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6810         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6811                 return TEST_SKIPPED;
6812         return test_snow3g_auth_cipher_sgl(
6813                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6814 }
6815
6816 static int
6817 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6818 {
6819         return test_snow3g_auth_cipher_sgl(
6820                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6821 }
6822
6823 static int
6824 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6825 {
6826         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6827         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6828                 return TEST_SKIPPED;
6829         return test_snow3g_auth_cipher_sgl(
6830                 &snow3g_auth_cipher_partial_digest_encryption,
6831                         IN_PLACE, 0);
6832 }
6833
6834 static int
6835 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6836 {
6837         return test_snow3g_auth_cipher_sgl(
6838                 &snow3g_auth_cipher_partial_digest_encryption,
6839                         OUT_OF_PLACE, 0);
6840 }
6841
6842 static int
6843 test_snow3g_auth_cipher_verify_test_case_1(void)
6844 {
6845         return test_snow3g_auth_cipher(
6846                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6847 }
6848
6849 static int
6850 test_snow3g_auth_cipher_verify_test_case_2(void)
6851 {
6852         return test_snow3g_auth_cipher(
6853                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6854 }
6855
6856 static int
6857 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6858 {
6859         return test_snow3g_auth_cipher(
6860                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6861 }
6862
6863 static int
6864 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6865 {
6866         return test_snow3g_auth_cipher(
6867                 &snow3g_auth_cipher_partial_digest_encryption,
6868                         IN_PLACE, 1);
6869 }
6870
6871 static int
6872 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6873 {
6874         return test_snow3g_auth_cipher(
6875                 &snow3g_auth_cipher_partial_digest_encryption,
6876                         OUT_OF_PLACE, 1);
6877 }
6878
6879 static int
6880 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6881 {
6882         return test_snow3g_auth_cipher_sgl(
6883                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6884 }
6885
6886 static int
6887 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6888 {
6889         return test_snow3g_auth_cipher_sgl(
6890                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6891 }
6892
6893 static int
6894 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6895 {
6896         return test_snow3g_auth_cipher_sgl(
6897                 &snow3g_auth_cipher_partial_digest_encryption,
6898                         IN_PLACE, 1);
6899 }
6900
6901 static int
6902 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6903 {
6904         return test_snow3g_auth_cipher_sgl(
6905                 &snow3g_auth_cipher_partial_digest_encryption,
6906                         OUT_OF_PLACE, 1);
6907 }
6908
6909 static int
6910 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6911 {
6912         return test_snow3g_auth_cipher(
6913                 &snow3g_test_case_7, IN_PLACE, 0);
6914 }
6915
6916 static int
6917 test_kasumi_auth_cipher_test_case_1(void)
6918 {
6919         return test_kasumi_auth_cipher(
6920                 &kasumi_test_case_3, IN_PLACE, 0);
6921 }
6922
6923 static int
6924 test_kasumi_auth_cipher_test_case_2(void)
6925 {
6926         return test_kasumi_auth_cipher(
6927                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6928 }
6929
6930 static int
6931 test_kasumi_auth_cipher_test_case_2_oop(void)
6932 {
6933         return test_kasumi_auth_cipher(
6934                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6935 }
6936
6937 static int
6938 test_kasumi_auth_cipher_test_case_2_sgl(void)
6939 {
6940         return test_kasumi_auth_cipher_sgl(
6941                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6942 }
6943
6944 static int
6945 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6946 {
6947         return test_kasumi_auth_cipher_sgl(
6948                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6949 }
6950
6951 static int
6952 test_kasumi_auth_cipher_verify_test_case_1(void)
6953 {
6954         return test_kasumi_auth_cipher(
6955                 &kasumi_test_case_3, IN_PLACE, 1);
6956 }
6957
6958 static int
6959 test_kasumi_auth_cipher_verify_test_case_2(void)
6960 {
6961         return test_kasumi_auth_cipher(
6962                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6963 }
6964
6965 static int
6966 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6967 {
6968         return test_kasumi_auth_cipher(
6969                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6970 }
6971
6972 static int
6973 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6974 {
6975         return test_kasumi_auth_cipher_sgl(
6976                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6977 }
6978
6979 static int
6980 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6981 {
6982         return test_kasumi_auth_cipher_sgl(
6983                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6984 }
6985
6986 static int
6987 test_kasumi_cipher_auth_test_case_1(void)
6988 {
6989         return test_kasumi_cipher_auth(&kasumi_test_case_6);
6990 }
6991
6992 static int
6993 test_zuc_encryption_test_case_1(void)
6994 {
6995         return test_zuc_encryption(&zuc_test_case_cipher_193b);
6996 }
6997
6998 static int
6999 test_zuc_encryption_test_case_2(void)
7000 {
7001         return test_zuc_encryption(&zuc_test_case_cipher_800b);
7002 }
7003
7004 static int
7005 test_zuc_encryption_test_case_3(void)
7006 {
7007         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
7008 }
7009
7010 static int
7011 test_zuc_encryption_test_case_4(void)
7012 {
7013         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
7014 }
7015
7016 static int
7017 test_zuc_encryption_test_case_5(void)
7018 {
7019         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7020 }
7021
7022 static int
7023 test_zuc_encryption_test_case_6_sgl(void)
7024 {
7025         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7026 }
7027
7028 static int
7029 test_zuc_hash_generate_test_case_1(void)
7030 {
7031         return test_zuc_authentication(&zuc_test_case_auth_1b);
7032 }
7033
7034 static int
7035 test_zuc_hash_generate_test_case_2(void)
7036 {
7037         return test_zuc_authentication(&zuc_test_case_auth_90b);
7038 }
7039
7040 static int
7041 test_zuc_hash_generate_test_case_3(void)
7042 {
7043         return test_zuc_authentication(&zuc_test_case_auth_577b);
7044 }
7045
7046 static int
7047 test_zuc_hash_generate_test_case_4(void)
7048 {
7049         return test_zuc_authentication(&zuc_test_case_auth_2079b);
7050 }
7051
7052 static int
7053 test_zuc_hash_generate_test_case_5(void)
7054 {
7055         return test_zuc_authentication(&zuc_test_auth_5670b);
7056 }
7057
7058 static int
7059 test_zuc_hash_generate_test_case_6(void)
7060 {
7061         return test_zuc_authentication(&zuc_test_case_auth_128b);
7062 }
7063
7064 static int
7065 test_zuc_hash_generate_test_case_7(void)
7066 {
7067         return test_zuc_authentication(&zuc_test_case_auth_2080b);
7068 }
7069
7070 static int
7071 test_zuc_hash_generate_test_case_8(void)
7072 {
7073         return test_zuc_authentication(&zuc_test_case_auth_584b);
7074 }
7075
7076 static int
7077 test_zuc_cipher_auth_test_case_1(void)
7078 {
7079         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7080 }
7081
7082 static int
7083 test_zuc_cipher_auth_test_case_2(void)
7084 {
7085         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7086 }
7087
7088 static int
7089 test_zuc_auth_cipher_test_case_1(void)
7090 {
7091         return test_zuc_auth_cipher(
7092                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7093 }
7094
7095 static int
7096 test_zuc_auth_cipher_test_case_1_oop(void)
7097 {
7098         return test_zuc_auth_cipher(
7099                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7100 }
7101
7102 static int
7103 test_zuc_auth_cipher_test_case_1_sgl(void)
7104 {
7105         return test_zuc_auth_cipher_sgl(
7106                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7107 }
7108
7109 static int
7110 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7111 {
7112         return test_zuc_auth_cipher_sgl(
7113                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7114 }
7115
7116 static int
7117 test_zuc_auth_cipher_verify_test_case_1(void)
7118 {
7119         return test_zuc_auth_cipher(
7120                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7121 }
7122
7123 static int
7124 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7125 {
7126         return test_zuc_auth_cipher(
7127                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7128 }
7129
7130 static int
7131 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7132 {
7133         return test_zuc_auth_cipher_sgl(
7134                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7135 }
7136
7137 static int
7138 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7139 {
7140         return test_zuc_auth_cipher_sgl(
7141                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7142 }
7143
7144 static int
7145 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7146 {
7147         uint8_t dev_id = testsuite_params.valid_devs[0];
7148
7149         struct rte_cryptodev_sym_capability_idx cap_idx;
7150
7151         /* Check if device supports particular cipher algorithm */
7152         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7153         cap_idx.algo.cipher = tdata->cipher_algo;
7154         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7155                 return TEST_SKIPPED;
7156
7157         /* Check if device supports particular hash algorithm */
7158         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7159         cap_idx.algo.auth = tdata->auth_algo;
7160         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7161                 return TEST_SKIPPED;
7162
7163         return 0;
7164 }
7165
7166 static int
7167 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7168         uint8_t op_mode, uint8_t verify)
7169 {
7170         struct crypto_testsuite_params *ts_params = &testsuite_params;
7171         struct crypto_unittest_params *ut_params = &unittest_params;
7172
7173         int retval;
7174
7175         uint8_t *plaintext = NULL, *ciphertext = NULL;
7176         unsigned int plaintext_pad_len;
7177         unsigned int plaintext_len;
7178         unsigned int ciphertext_pad_len;
7179         unsigned int ciphertext_len;
7180
7181         struct rte_cryptodev_info dev_info;
7182         struct rte_crypto_op *op;
7183
7184         /* Check if device supports particular algorithms separately */
7185         if (test_mixed_check_if_unsupported(tdata))
7186                 return TEST_SKIPPED;
7187         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7188                 return TEST_SKIPPED;
7189
7190         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7191
7192         uint64_t feat_flags = dev_info.feature_flags;
7193
7194         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7195                 printf("Device doesn't support digest encrypted.\n");
7196                 return TEST_SKIPPED;
7197         }
7198
7199         /* Create the session */
7200         if (verify)
7201                 retval = create_wireless_algo_cipher_auth_session(
7202                                 ts_params->valid_devs[0],
7203                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7204                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7205                                 tdata->auth_algo,
7206                                 tdata->cipher_algo,
7207                                 tdata->auth_key.data, tdata->auth_key.len,
7208                                 tdata->auth_iv.len, tdata->digest_enc.len,
7209                                 tdata->cipher_iv.len);
7210         else
7211                 retval = create_wireless_algo_auth_cipher_session(
7212                                 ts_params->valid_devs[0],
7213                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7214                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7215                                 tdata->auth_algo,
7216                                 tdata->cipher_algo,
7217                                 tdata->auth_key.data, tdata->auth_key.len,
7218                                 tdata->auth_iv.len, tdata->digest_enc.len,
7219                                 tdata->cipher_iv.len);
7220         if (retval != 0)
7221                 return retval;
7222
7223         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7224         if (op_mode == OUT_OF_PLACE)
7225                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7226
7227         /* clear mbuf payload */
7228         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7229                 rte_pktmbuf_tailroom(ut_params->ibuf));
7230         if (op_mode == OUT_OF_PLACE) {
7231
7232                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7233                                 rte_pktmbuf_tailroom(ut_params->obuf));
7234         }
7235
7236         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7237         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7238         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7239         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7240
7241         if (verify) {
7242                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7243                                 ciphertext_pad_len);
7244                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7245                 if (op_mode == OUT_OF_PLACE)
7246                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7247                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7248                                 ciphertext_len);
7249         } else {
7250                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7251                                 plaintext_pad_len);
7252                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7253                 if (op_mode == OUT_OF_PLACE)
7254                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7255                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7256         }
7257
7258         /* Create the operation */
7259         retval = create_wireless_algo_auth_cipher_operation(
7260                         tdata->digest_enc.data, tdata->digest_enc.len,
7261                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7262                         tdata->auth_iv.data, tdata->auth_iv.len,
7263                         (tdata->digest_enc.offset == 0 ?
7264                                 plaintext_pad_len
7265                                 : tdata->digest_enc.offset),
7266                         tdata->validCipherLen.len_bits,
7267                         tdata->cipher.offset_bits,
7268                         tdata->validAuthLen.len_bits,
7269                         tdata->auth.offset_bits,
7270                         op_mode, 0, verify);
7271
7272         if (retval < 0)
7273                 return retval;
7274
7275         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7276
7277         /* Check if the op failed because the device doesn't */
7278         /* support this particular combination of algorithms */
7279         if (op == NULL && ut_params->op->status ==
7280                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7281                 printf("Device doesn't support this mixed combination. "
7282                                 "Test Skipped.\n");
7283                 return TEST_SKIPPED;
7284         }
7285         ut_params->op = op;
7286
7287         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7288
7289         ut_params->obuf = (op_mode == IN_PLACE ?
7290                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7291
7292         if (verify) {
7293                 if (ut_params->obuf)
7294                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7295                                                         uint8_t *);
7296                 else
7297                         plaintext = ciphertext +
7298                                         (tdata->cipher.offset_bits >> 3);
7299
7300                 debug_hexdump(stdout, "plaintext:", plaintext,
7301                                 tdata->plaintext.len_bits >> 3);
7302                 debug_hexdump(stdout, "plaintext expected:",
7303                                 tdata->plaintext.data,
7304                                 tdata->plaintext.len_bits >> 3);
7305         } else {
7306                 if (ut_params->obuf)
7307                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7308                                         uint8_t *);
7309                 else
7310                         ciphertext = plaintext;
7311
7312                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7313                                 ciphertext_len);
7314                 debug_hexdump(stdout, "ciphertext expected:",
7315                                 tdata->ciphertext.data,
7316                                 tdata->ciphertext.len_bits >> 3);
7317
7318                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7319                                 + (tdata->digest_enc.offset == 0 ?
7320                 plaintext_pad_len : tdata->digest_enc.offset);
7321
7322                 debug_hexdump(stdout, "digest:", ut_params->digest,
7323                                 tdata->digest_enc.len);
7324                 debug_hexdump(stdout, "digest expected:",
7325                                 tdata->digest_enc.data,
7326                                 tdata->digest_enc.len);
7327         }
7328
7329         /* Validate obuf */
7330         if (verify) {
7331                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7332                                 plaintext,
7333                                 tdata->plaintext.data,
7334                                 tdata->plaintext.len_bits >> 3,
7335                                 "Plaintext data not as expected");
7336         } else {
7337                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7338                                 ciphertext,
7339                                 tdata->ciphertext.data,
7340                                 tdata->validDataLen.len_bits,
7341                                 "Ciphertext data not as expected");
7342
7343                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7344                                 ut_params->digest,
7345                                 tdata->digest_enc.data,
7346                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7347                                 "Generated auth tag not as expected");
7348         }
7349
7350         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7351                         "crypto op processing failed");
7352
7353         return 0;
7354 }
7355
7356 static int
7357 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7358         uint8_t op_mode, uint8_t verify)
7359 {
7360         struct crypto_testsuite_params *ts_params = &testsuite_params;
7361         struct crypto_unittest_params *ut_params = &unittest_params;
7362
7363         int retval;
7364
7365         const uint8_t *plaintext = NULL;
7366         const uint8_t *ciphertext = NULL;
7367         const uint8_t *digest = NULL;
7368         unsigned int plaintext_pad_len;
7369         unsigned int plaintext_len;
7370         unsigned int ciphertext_pad_len;
7371         unsigned int ciphertext_len;
7372         uint8_t buffer[10000];
7373         uint8_t digest_buffer[10000];
7374
7375         struct rte_cryptodev_info dev_info;
7376         struct rte_crypto_op *op;
7377
7378         /* Check if device supports particular algorithms */
7379         if (test_mixed_check_if_unsupported(tdata))
7380                 return TEST_SKIPPED;
7381         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7382                 return TEST_SKIPPED;
7383
7384         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7385
7386         uint64_t feat_flags = dev_info.feature_flags;
7387
7388         if (op_mode == IN_PLACE) {
7389                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7390                         printf("Device doesn't support in-place scatter-gather "
7391                                         "in both input and output mbufs.\n");
7392                         return TEST_SKIPPED;
7393                 }
7394         } else {
7395                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7396                         printf("Device doesn't support out-of-place scatter-gather "
7397                                         "in both input and output mbufs.\n");
7398                         return TEST_SKIPPED;
7399                 }
7400                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7401                         printf("Device doesn't support digest encrypted.\n");
7402                         return TEST_SKIPPED;
7403                 }
7404         }
7405
7406         /* Create the session */
7407         if (verify)
7408                 retval = create_wireless_algo_cipher_auth_session(
7409                                 ts_params->valid_devs[0],
7410                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7411                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7412                                 tdata->auth_algo,
7413                                 tdata->cipher_algo,
7414                                 tdata->auth_key.data, tdata->auth_key.len,
7415                                 tdata->auth_iv.len, tdata->digest_enc.len,
7416                                 tdata->cipher_iv.len);
7417         else
7418                 retval = create_wireless_algo_auth_cipher_session(
7419                                 ts_params->valid_devs[0],
7420                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7421                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7422                                 tdata->auth_algo,
7423                                 tdata->cipher_algo,
7424                                 tdata->auth_key.data, tdata->auth_key.len,
7425                                 tdata->auth_iv.len, tdata->digest_enc.len,
7426                                 tdata->cipher_iv.len);
7427         if (retval != 0)
7428                 return retval;
7429
7430         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7431         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7432         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7433         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7434
7435         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7436                         ciphertext_pad_len, 15, 0);
7437         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7438                         "Failed to allocate input buffer in mempool");
7439
7440         if (op_mode == OUT_OF_PLACE) {
7441                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7442                                 plaintext_pad_len, 15, 0);
7443                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
7444                                 "Failed to allocate output buffer in mempool");
7445         }
7446
7447         if (verify) {
7448                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7449                         tdata->ciphertext.data);
7450                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7451                                         ciphertext_len, buffer);
7452                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7453                         ciphertext_len);
7454         } else {
7455                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7456                         tdata->plaintext.data);
7457                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7458                                         plaintext_len, buffer);
7459                 debug_hexdump(stdout, "plaintext:", plaintext,
7460                         plaintext_len);
7461         }
7462         memset(buffer, 0, sizeof(buffer));
7463
7464         /* Create the operation */
7465         retval = create_wireless_algo_auth_cipher_operation(
7466                         tdata->digest_enc.data, tdata->digest_enc.len,
7467                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7468                         tdata->auth_iv.data, tdata->auth_iv.len,
7469                         (tdata->digest_enc.offset == 0 ?
7470                                 plaintext_pad_len
7471                                 : tdata->digest_enc.offset),
7472                         tdata->validCipherLen.len_bits,
7473                         tdata->cipher.offset_bits,
7474                         tdata->validAuthLen.len_bits,
7475                         tdata->auth.offset_bits,
7476                         op_mode, 1, verify);
7477
7478         if (retval < 0)
7479                 return retval;
7480
7481         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7482
7483         /* Check if the op failed because the device doesn't */
7484         /* support this particular combination of algorithms */
7485         if (op == NULL && ut_params->op->status ==
7486                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7487                 printf("Device doesn't support this mixed combination. "
7488                                 "Test Skipped.\n");
7489                 return TEST_SKIPPED;
7490         }
7491         ut_params->op = op;
7492
7493         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7494
7495         ut_params->obuf = (op_mode == IN_PLACE ?
7496                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7497
7498         if (verify) {
7499                 if (ut_params->obuf)
7500                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7501                                         plaintext_len, buffer);
7502                 else
7503                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7504                                         plaintext_len, buffer);
7505
7506                 debug_hexdump(stdout, "plaintext:", plaintext,
7507                                 (tdata->plaintext.len_bits >> 3) -
7508                                 tdata->digest_enc.len);
7509                 debug_hexdump(stdout, "plaintext expected:",
7510                                 tdata->plaintext.data,
7511                                 (tdata->plaintext.len_bits >> 3) -
7512                                 tdata->digest_enc.len);
7513         } else {
7514                 if (ut_params->obuf)
7515                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7516                                         ciphertext_len, buffer);
7517                 else
7518                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7519                                         ciphertext_len, buffer);
7520
7521                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7522                         ciphertext_len);
7523                 debug_hexdump(stdout, "ciphertext expected:",
7524                         tdata->ciphertext.data,
7525                         tdata->ciphertext.len_bits >> 3);
7526
7527                 if (ut_params->obuf)
7528                         digest = rte_pktmbuf_read(ut_params->obuf,
7529                                         (tdata->digest_enc.offset == 0 ?
7530                                                 plaintext_pad_len :
7531                                                 tdata->digest_enc.offset),
7532                                         tdata->digest_enc.len, digest_buffer);
7533                 else
7534                         digest = rte_pktmbuf_read(ut_params->ibuf,
7535                                         (tdata->digest_enc.offset == 0 ?
7536                                                 plaintext_pad_len :
7537                                                 tdata->digest_enc.offset),
7538                                         tdata->digest_enc.len, digest_buffer);
7539
7540                 debug_hexdump(stdout, "digest:", digest,
7541                                 tdata->digest_enc.len);
7542                 debug_hexdump(stdout, "digest expected:",
7543                                 tdata->digest_enc.data, tdata->digest_enc.len);
7544         }
7545
7546         /* Validate obuf */
7547         if (verify) {
7548                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7549                                 plaintext,
7550                                 tdata->plaintext.data,
7551                                 tdata->plaintext.len_bits >> 3,
7552                                 "Plaintext data not as expected");
7553         } else {
7554                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7555                                 ciphertext,
7556                                 tdata->ciphertext.data,
7557                                 tdata->validDataLen.len_bits,
7558                                 "Ciphertext data not as expected");
7559                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7560                                 digest,
7561                                 tdata->digest_enc.data,
7562                                 tdata->digest_enc.len,
7563                                 "Generated auth tag not as expected");
7564         }
7565
7566         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7567                         "crypto op processing failed");
7568
7569         return 0;
7570 }
7571
7572 /** AUTH AES CMAC + CIPHER AES CTR */
7573
7574 static int
7575 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7576 {
7577         return test_mixed_auth_cipher(
7578                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7579 }
7580
7581 static int
7582 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7583 {
7584         return test_mixed_auth_cipher(
7585                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7586 }
7587
7588 static int
7589 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7590 {
7591         return test_mixed_auth_cipher_sgl(
7592                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7593 }
7594
7595 static int
7596 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7597 {
7598         return test_mixed_auth_cipher_sgl(
7599                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7600 }
7601
7602 static int
7603 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7604 {
7605         return test_mixed_auth_cipher(
7606                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7607 }
7608
7609 static int
7610 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7611 {
7612         return test_mixed_auth_cipher(
7613                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7614 }
7615
7616 static int
7617 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7618 {
7619         return test_mixed_auth_cipher_sgl(
7620                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7621 }
7622
7623 static int
7624 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7625 {
7626         return test_mixed_auth_cipher_sgl(
7627                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7628 }
7629
7630 /** MIXED AUTH + CIPHER */
7631
7632 static int
7633 test_auth_zuc_cipher_snow_test_case_1(void)
7634 {
7635         return test_mixed_auth_cipher(
7636                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7637 }
7638
7639 static int
7640 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7641 {
7642         return test_mixed_auth_cipher(
7643                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7644 }
7645
7646 static int
7647 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7648 {
7649         return test_mixed_auth_cipher(
7650                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7651 }
7652
7653 static int
7654 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7655 {
7656         return test_mixed_auth_cipher(
7657                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7658 }
7659
7660 static int
7661 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7662 {
7663         return test_mixed_auth_cipher(
7664                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7665 }
7666
7667 static int
7668 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7669 {
7670         return test_mixed_auth_cipher(
7671                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7672 }
7673
7674 static int
7675 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7676 {
7677         return test_mixed_auth_cipher(
7678                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7679 }
7680
7681 static int
7682 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7683 {
7684         return test_mixed_auth_cipher(
7685                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7686 }
7687
7688 static int
7689 test_auth_snow_cipher_zuc_test_case_1(void)
7690 {
7691         return test_mixed_auth_cipher(
7692                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7693 }
7694
7695 static int
7696 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7697 {
7698         return test_mixed_auth_cipher(
7699                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7700 }
7701
7702 static int
7703 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7704 {
7705         return test_mixed_auth_cipher(
7706                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7707 }
7708
7709 static int
7710 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7711 {
7712         return test_mixed_auth_cipher(
7713                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7714 }
7715
7716 static int
7717 test_auth_null_cipher_snow_test_case_1(void)
7718 {
7719         return test_mixed_auth_cipher(
7720                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7721 }
7722
7723 static int
7724 test_verify_auth_null_cipher_snow_test_case_1(void)
7725 {
7726         return test_mixed_auth_cipher(
7727                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7728 }
7729
7730 static int
7731 test_auth_null_cipher_zuc_test_case_1(void)
7732 {
7733         return test_mixed_auth_cipher(
7734                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7735 }
7736
7737 static int
7738 test_verify_auth_null_cipher_zuc_test_case_1(void)
7739 {
7740         return test_mixed_auth_cipher(
7741                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7742 }
7743
7744 static int
7745 test_auth_snow_cipher_null_test_case_1(void)
7746 {
7747         return test_mixed_auth_cipher(
7748                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7749 }
7750
7751 static int
7752 test_verify_auth_snow_cipher_null_test_case_1(void)
7753 {
7754         return test_mixed_auth_cipher(
7755                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7756 }
7757
7758 static int
7759 test_auth_zuc_cipher_null_test_case_1(void)
7760 {
7761         return test_mixed_auth_cipher(
7762                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7763 }
7764
7765 static int
7766 test_verify_auth_zuc_cipher_null_test_case_1(void)
7767 {
7768         return test_mixed_auth_cipher(
7769                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7770 }
7771
7772 static int
7773 test_auth_null_cipher_aes_ctr_test_case_1(void)
7774 {
7775         return test_mixed_auth_cipher(
7776                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7777 }
7778
7779 static int
7780 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7781 {
7782         return test_mixed_auth_cipher(
7783                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7784 }
7785
7786 static int
7787 test_auth_aes_cmac_cipher_null_test_case_1(void)
7788 {
7789         return test_mixed_auth_cipher(
7790                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7791 }
7792
7793 static int
7794 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7795 {
7796         return test_mixed_auth_cipher(
7797                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7798 }
7799
7800 /* ***** AEAD algorithm Tests ***** */
7801
7802 static int
7803 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7804                 enum rte_crypto_aead_operation op,
7805                 const uint8_t *key, const uint8_t key_len,
7806                 const uint16_t aad_len, const uint8_t auth_len,
7807                 uint8_t iv_len)
7808 {
7809         uint8_t aead_key[key_len];
7810
7811         struct crypto_testsuite_params *ts_params = &testsuite_params;
7812         struct crypto_unittest_params *ut_params = &unittest_params;
7813
7814         memcpy(aead_key, key, key_len);
7815
7816         /* Setup AEAD Parameters */
7817         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7818         ut_params->aead_xform.next = NULL;
7819         ut_params->aead_xform.aead.algo = algo;
7820         ut_params->aead_xform.aead.op = op;
7821         ut_params->aead_xform.aead.key.data = aead_key;
7822         ut_params->aead_xform.aead.key.length = key_len;
7823         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7824         ut_params->aead_xform.aead.iv.length = iv_len;
7825         ut_params->aead_xform.aead.digest_length = auth_len;
7826         ut_params->aead_xform.aead.aad_length = aad_len;
7827
7828         debug_hexdump(stdout, "key:", key, key_len);
7829
7830         /* Create Crypto session*/
7831         ut_params->sess = rte_cryptodev_sym_session_create(
7832                         ts_params->session_mpool);
7833
7834         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7835                         &ut_params->aead_xform,
7836                         ts_params->session_priv_mpool);
7837
7838         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7839
7840         return 0;
7841 }
7842
7843 static int
7844 create_aead_xform(struct rte_crypto_op *op,
7845                 enum rte_crypto_aead_algorithm algo,
7846                 enum rte_crypto_aead_operation aead_op,
7847                 uint8_t *key, const uint8_t key_len,
7848                 const uint8_t aad_len, const uint8_t auth_len,
7849                 uint8_t iv_len)
7850 {
7851         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7852                         "failed to allocate space for crypto transform");
7853
7854         struct rte_crypto_sym_op *sym_op = op->sym;
7855
7856         /* Setup AEAD Parameters */
7857         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7858         sym_op->xform->next = NULL;
7859         sym_op->xform->aead.algo = algo;
7860         sym_op->xform->aead.op = aead_op;
7861         sym_op->xform->aead.key.data = key;
7862         sym_op->xform->aead.key.length = key_len;
7863         sym_op->xform->aead.iv.offset = IV_OFFSET;
7864         sym_op->xform->aead.iv.length = iv_len;
7865         sym_op->xform->aead.digest_length = auth_len;
7866         sym_op->xform->aead.aad_length = aad_len;
7867
7868         debug_hexdump(stdout, "key:", key, key_len);
7869
7870         return 0;
7871 }
7872
7873 static int
7874 create_aead_operation(enum rte_crypto_aead_operation op,
7875                 const struct aead_test_data *tdata)
7876 {
7877         struct crypto_testsuite_params *ts_params = &testsuite_params;
7878         struct crypto_unittest_params *ut_params = &unittest_params;
7879
7880         uint8_t *plaintext, *ciphertext;
7881         unsigned int aad_pad_len, plaintext_pad_len;
7882
7883         /* Generate Crypto op data structure */
7884         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7885                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7886         TEST_ASSERT_NOT_NULL(ut_params->op,
7887                         "Failed to allocate symmetric crypto operation struct");
7888
7889         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7890
7891         /* Append aad data */
7892         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7893                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7894                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7895                                 aad_pad_len);
7896                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7897                                 "no room to append aad");
7898
7899                 sym_op->aead.aad.phys_addr =
7900                                 rte_pktmbuf_iova(ut_params->ibuf);
7901                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
7902                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7903                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7904                         tdata->aad.len);
7905
7906                 /* Append IV at the end of the crypto operation*/
7907                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7908                                 uint8_t *, IV_OFFSET);
7909
7910                 /* Copy IV 1 byte after the IV pointer, according to the API */
7911                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7912                 debug_hexdump(stdout, "iv:", iv_ptr,
7913                         tdata->iv.len);
7914         } else {
7915                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7916                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7917                                 aad_pad_len);
7918                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7919                                 "no room to append aad");
7920
7921                 sym_op->aead.aad.phys_addr =
7922                                 rte_pktmbuf_iova(ut_params->ibuf);
7923                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7924                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7925                         tdata->aad.len);
7926
7927                 /* Append IV at the end of the crypto operation*/
7928                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7929                                 uint8_t *, IV_OFFSET);
7930
7931                 if (tdata->iv.len == 0) {
7932                         rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7933                         debug_hexdump(stdout, "iv:", iv_ptr,
7934                                 AES_GCM_J0_LENGTH);
7935                 } else {
7936                         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7937                         debug_hexdump(stdout, "iv:", iv_ptr,
7938                                 tdata->iv.len);
7939                 }
7940         }
7941
7942         /* Append plaintext/ciphertext */
7943         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7944                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7945                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7946                                 plaintext_pad_len);
7947                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7948
7949                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7950                 debug_hexdump(stdout, "plaintext:", plaintext,
7951                                 tdata->plaintext.len);
7952
7953                 if (ut_params->obuf) {
7954                         ciphertext = (uint8_t *)rte_pktmbuf_append(
7955                                         ut_params->obuf,
7956                                         plaintext_pad_len + aad_pad_len);
7957                         TEST_ASSERT_NOT_NULL(ciphertext,
7958                                         "no room to append ciphertext");
7959
7960                         memset(ciphertext + aad_pad_len, 0,
7961                                         tdata->ciphertext.len);
7962                 }
7963         } else {
7964                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7965                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7966                                 plaintext_pad_len);
7967                 TEST_ASSERT_NOT_NULL(ciphertext,
7968                                 "no room to append ciphertext");
7969
7970                 memcpy(ciphertext, tdata->ciphertext.data,
7971                                 tdata->ciphertext.len);
7972                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7973                                 tdata->ciphertext.len);
7974
7975                 if (ut_params->obuf) {
7976                         plaintext = (uint8_t *)rte_pktmbuf_append(
7977                                         ut_params->obuf,
7978                                         plaintext_pad_len + aad_pad_len);
7979                         TEST_ASSERT_NOT_NULL(plaintext,
7980                                         "no room to append plaintext");
7981
7982                         memset(plaintext + aad_pad_len, 0,
7983                                         tdata->plaintext.len);
7984                 }
7985         }
7986
7987         /* Append digest data */
7988         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7989                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7990                                 ut_params->obuf ? ut_params->obuf :
7991                                                 ut_params->ibuf,
7992                                                 tdata->auth_tag.len);
7993                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7994                                 "no room to append digest");
7995                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
7996                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7997                                 ut_params->obuf ? ut_params->obuf :
7998                                                 ut_params->ibuf,
7999                                                 plaintext_pad_len +
8000                                                 aad_pad_len);
8001         } else {
8002                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8003                                 ut_params->ibuf, tdata->auth_tag.len);
8004                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8005                                 "no room to append digest");
8006                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8007                                 ut_params->ibuf,
8008                                 plaintext_pad_len + aad_pad_len);
8009
8010                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8011                         tdata->auth_tag.len);
8012                 debug_hexdump(stdout, "digest:",
8013                         sym_op->aead.digest.data,
8014                         tdata->auth_tag.len);
8015         }
8016
8017         sym_op->aead.data.length = tdata->plaintext.len;
8018         sym_op->aead.data.offset = aad_pad_len;
8019
8020         return 0;
8021 }
8022
8023 static int
8024 test_authenticated_encryption(const struct aead_test_data *tdata)
8025 {
8026         struct crypto_testsuite_params *ts_params = &testsuite_params;
8027         struct crypto_unittest_params *ut_params = &unittest_params;
8028
8029         int retval;
8030         uint8_t *ciphertext, *auth_tag;
8031         uint16_t plaintext_pad_len;
8032         uint32_t i;
8033         struct rte_cryptodev_info dev_info;
8034
8035         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8036         uint64_t feat_flags = dev_info.feature_flags;
8037
8038         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8039                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8040                 printf("Device doesn't support RAW data-path APIs.\n");
8041                 return TEST_SKIPPED;
8042         }
8043
8044         /* Verify the capabilities */
8045         struct rte_cryptodev_sym_capability_idx cap_idx;
8046         const struct rte_cryptodev_symmetric_capability *capability;
8047         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8048         cap_idx.algo.aead = tdata->algo;
8049         capability = rte_cryptodev_sym_capability_get(
8050                         ts_params->valid_devs[0], &cap_idx);
8051         if (capability == NULL)
8052                 return TEST_SKIPPED;
8053         if (rte_cryptodev_sym_capability_check_aead(
8054                         capability, tdata->key.len, tdata->auth_tag.len,
8055                         tdata->aad.len, tdata->iv.len))
8056                 return TEST_SKIPPED;
8057
8058         /* Create AEAD session */
8059         retval = create_aead_session(ts_params->valid_devs[0],
8060                         tdata->algo,
8061                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
8062                         tdata->key.data, tdata->key.len,
8063                         tdata->aad.len, tdata->auth_tag.len,
8064                         tdata->iv.len);
8065         if (retval < 0)
8066                 return retval;
8067
8068         if (tdata->aad.len > MBUF_SIZE) {
8069                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8070                 /* Populate full size of add data */
8071                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8072                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8073         } else
8074                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8075
8076         /* clear mbuf payload */
8077         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8078                         rte_pktmbuf_tailroom(ut_params->ibuf));
8079
8080         /* Create AEAD operation */
8081         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8082         if (retval < 0)
8083                 return retval;
8084
8085         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8086
8087         ut_params->op->sym->m_src = ut_params->ibuf;
8088
8089         /* Process crypto operation */
8090         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8091                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8092         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8093                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8094                                 ut_params->op, 0, 0, 0, 0);
8095         else
8096                 TEST_ASSERT_NOT_NULL(
8097                         process_crypto_request(ts_params->valid_devs[0],
8098                         ut_params->op), "failed to process sym crypto op");
8099
8100         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8101                         "crypto op processing failed");
8102
8103         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8104
8105         if (ut_params->op->sym->m_dst) {
8106                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8107                                 uint8_t *);
8108                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8109                                 uint8_t *, plaintext_pad_len);
8110         } else {
8111                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8112                                 uint8_t *,
8113                                 ut_params->op->sym->cipher.data.offset);
8114                 auth_tag = ciphertext + plaintext_pad_len;
8115         }
8116
8117         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8118         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8119
8120         /* Validate obuf */
8121         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8122                         ciphertext,
8123                         tdata->ciphertext.data,
8124                         tdata->ciphertext.len,
8125                         "Ciphertext data not as expected");
8126
8127         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8128                         auth_tag,
8129                         tdata->auth_tag.data,
8130                         tdata->auth_tag.len,
8131                         "Generated auth tag not as expected");
8132
8133         return 0;
8134
8135 }
8136
8137 #ifdef RTE_LIB_SECURITY
8138 static int
8139 security_proto_supported(enum rte_security_session_action_type action,
8140         enum rte_security_session_protocol proto)
8141 {
8142         struct crypto_testsuite_params *ts_params = &testsuite_params;
8143
8144         const struct rte_security_capability *capabilities;
8145         const struct rte_security_capability *capability;
8146         uint16_t i = 0;
8147
8148         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8149                                 rte_cryptodev_get_sec_ctx(
8150                                 ts_params->valid_devs[0]);
8151
8152
8153         capabilities = rte_security_capabilities_get(ctx);
8154
8155         if (capabilities == NULL)
8156                 return -ENOTSUP;
8157
8158         while ((capability = &capabilities[i++])->action !=
8159                         RTE_SECURITY_ACTION_TYPE_NONE) {
8160                 if (capability->action == action &&
8161                                 capability->protocol == proto)
8162                         return 0;
8163         }
8164
8165         return -ENOTSUP;
8166 }
8167
8168 /* Basic algorithm run function for async inplace mode.
8169  * Creates a session from input parameters and runs one operation
8170  * on input_vec. Checks the output of the crypto operation against
8171  * output_vec.
8172  */
8173 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8174                            enum rte_crypto_auth_operation opa,
8175                            const uint8_t *input_vec, unsigned int input_vec_len,
8176                            const uint8_t *output_vec,
8177                            unsigned int output_vec_len,
8178                            enum rte_crypto_cipher_algorithm cipher_alg,
8179                            const uint8_t *cipher_key, uint32_t cipher_key_len,
8180                            enum rte_crypto_auth_algorithm auth_alg,
8181                            const uint8_t *auth_key, uint32_t auth_key_len,
8182                            uint8_t bearer, enum rte_security_pdcp_domain domain,
8183                            uint8_t packet_direction, uint8_t sn_size,
8184                            uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8185 {
8186         struct crypto_testsuite_params *ts_params = &testsuite_params;
8187         struct crypto_unittest_params *ut_params = &unittest_params;
8188         uint8_t *plaintext;
8189         int ret = TEST_SUCCESS;
8190         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8191                                 rte_cryptodev_get_sec_ctx(
8192                                 ts_params->valid_devs[0]);
8193
8194         /* Verify the capabilities */
8195         struct rte_security_capability_idx sec_cap_idx;
8196
8197         sec_cap_idx.action = ut_params->type;
8198         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8199         sec_cap_idx.pdcp.domain = domain;
8200         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8201                 return TEST_SKIPPED;
8202
8203         /* Generate test mbuf data */
8204         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8205
8206         /* clear mbuf payload */
8207         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8208                         rte_pktmbuf_tailroom(ut_params->ibuf));
8209
8210         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8211                                                   input_vec_len);
8212         memcpy(plaintext, input_vec, input_vec_len);
8213
8214         /* Out of place support */
8215         if (oop) {
8216                 /*
8217                  * For out-op-place we need to alloc another mbuf
8218                  */
8219                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8220                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8221         }
8222
8223         /* Setup Cipher Parameters */
8224         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8225         ut_params->cipher_xform.cipher.algo = cipher_alg;
8226         ut_params->cipher_xform.cipher.op = opc;
8227         ut_params->cipher_xform.cipher.key.data = cipher_key;
8228         ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8229         ut_params->cipher_xform.cipher.iv.length =
8230                                 packet_direction ? 4 : 0;
8231         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8232
8233         /* Setup HMAC Parameters if ICV header is required */
8234         if (auth_alg != 0) {
8235                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8236                 ut_params->auth_xform.next = NULL;
8237                 ut_params->auth_xform.auth.algo = auth_alg;
8238                 ut_params->auth_xform.auth.op = opa;
8239                 ut_params->auth_xform.auth.key.data = auth_key;
8240                 ut_params->auth_xform.auth.key.length = auth_key_len;
8241
8242                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8243         } else {
8244                 ut_params->cipher_xform.next = NULL;
8245         }
8246
8247         struct rte_security_session_conf sess_conf = {
8248                 .action_type = ut_params->type,
8249                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8250                 {.pdcp = {
8251                         .bearer = bearer,
8252                         .domain = domain,
8253                         .pkt_dir = packet_direction,
8254                         .sn_size = sn_size,
8255                         .hfn = packet_direction ? 0 : hfn,
8256                         /**
8257                          * hfn can be set as pdcp_test_hfn[i]
8258                          * if hfn_ovrd is not set. Here, PDCP
8259                          * packet direction is just used to
8260                          * run half of the cases with session
8261                          * HFN and other half with per packet
8262                          * HFN.
8263                          */
8264                         .hfn_threshold = hfn_threshold,
8265                         .hfn_ovrd = packet_direction ? 1 : 0,
8266                         .sdap_enabled = sdap,
8267                 } },
8268                 .crypto_xform = &ut_params->cipher_xform
8269         };
8270
8271         /* Create security session */
8272         ut_params->sec_session = rte_security_session_create(ctx,
8273                                 &sess_conf, ts_params->session_mpool,
8274                                 ts_params->session_priv_mpool);
8275
8276         if (!ut_params->sec_session) {
8277                 printf("TestCase %s()-%d line %d failed %s: ",
8278                         __func__, i, __LINE__, "Failed to allocate session");
8279                 ret = TEST_FAILED;
8280                 goto on_err;
8281         }
8282
8283         /* Generate crypto op data structure */
8284         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8285                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8286         if (!ut_params->op) {
8287                 printf("TestCase %s()-%d line %d failed %s: ",
8288                         __func__, i, __LINE__,
8289                         "Failed to allocate symmetric crypto operation struct");
8290                 ret = TEST_FAILED;
8291                 goto on_err;
8292         }
8293
8294         uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8295                                         uint32_t *, IV_OFFSET);
8296         *per_pkt_hfn = packet_direction ? hfn : 0;
8297
8298         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8299
8300         /* set crypto operation source mbuf */
8301         ut_params->op->sym->m_src = ut_params->ibuf;
8302         if (oop)
8303                 ut_params->op->sym->m_dst = ut_params->obuf;
8304
8305         /* Process crypto operation */
8306         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8307                 == NULL) {
8308                 printf("TestCase %s()-%d line %d failed %s: ",
8309                         __func__, i, __LINE__,
8310                         "failed to process sym crypto op");
8311                 ret = TEST_FAILED;
8312                 goto on_err;
8313         }
8314
8315         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8316                 printf("TestCase %s()-%d line %d failed %s: ",
8317                         __func__, i, __LINE__, "crypto op processing failed");
8318                 ret = TEST_FAILED;
8319                 goto on_err;
8320         }
8321
8322         /* Validate obuf */
8323         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8324                         uint8_t *);
8325         if (oop) {
8326                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8327                                 uint8_t *);
8328         }
8329
8330         if (memcmp(ciphertext, output_vec, output_vec_len)) {
8331                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8332                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8333                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8334                 ret = TEST_FAILED;
8335                 goto on_err;
8336         }
8337
8338 on_err:
8339         rte_crypto_op_free(ut_params->op);
8340         ut_params->op = NULL;
8341
8342         if (ut_params->sec_session)
8343                 rte_security_session_destroy(ctx, ut_params->sec_session);
8344         ut_params->sec_session = NULL;
8345
8346         rte_pktmbuf_free(ut_params->ibuf);
8347         ut_params->ibuf = NULL;
8348         if (oop) {
8349                 rte_pktmbuf_free(ut_params->obuf);
8350                 ut_params->obuf = NULL;
8351         }
8352
8353         return ret;
8354 }
8355
8356 static int
8357 test_pdcp_proto_SGL(int i, int oop,
8358         enum rte_crypto_cipher_operation opc,
8359         enum rte_crypto_auth_operation opa,
8360         uint8_t *input_vec,
8361         unsigned int input_vec_len,
8362         uint8_t *output_vec,
8363         unsigned int output_vec_len,
8364         uint32_t fragsz,
8365         uint32_t fragsz_oop)
8366 {
8367         struct crypto_testsuite_params *ts_params = &testsuite_params;
8368         struct crypto_unittest_params *ut_params = &unittest_params;
8369         uint8_t *plaintext;
8370         struct rte_mbuf *buf, *buf_oop = NULL;
8371         int ret = TEST_SUCCESS;
8372         int to_trn = 0;
8373         int to_trn_tbl[16];
8374         int segs = 1;
8375         unsigned int trn_data = 0;
8376         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8377                                 rte_cryptodev_get_sec_ctx(
8378                                 ts_params->valid_devs[0]);
8379
8380         /* Verify the capabilities */
8381         struct rte_security_capability_idx sec_cap_idx;
8382
8383         sec_cap_idx.action = ut_params->type;
8384         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8385         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8386         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8387                 return TEST_SKIPPED;
8388
8389         if (fragsz > input_vec_len)
8390                 fragsz = input_vec_len;
8391
8392         uint16_t plaintext_len = fragsz;
8393         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8394
8395         if (fragsz_oop > output_vec_len)
8396                 frag_size_oop = output_vec_len;
8397
8398         int ecx = 0;
8399         if (input_vec_len % fragsz != 0) {
8400                 if (input_vec_len / fragsz + 1 > 16)
8401                         return 1;
8402         } else if (input_vec_len / fragsz > 16)
8403                 return 1;
8404
8405         /* Out of place support */
8406         if (oop) {
8407                 /*
8408                  * For out-op-place we need to alloc another mbuf
8409                  */
8410                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8411                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8412                 buf_oop = ut_params->obuf;
8413         }
8414
8415         /* Generate test mbuf data */
8416         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8417
8418         /* clear mbuf payload */
8419         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8420                         rte_pktmbuf_tailroom(ut_params->ibuf));
8421
8422         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8423                                                   plaintext_len);
8424         memcpy(plaintext, input_vec, plaintext_len);
8425         trn_data += plaintext_len;
8426
8427         buf = ut_params->ibuf;
8428
8429         /*
8430          * Loop until no more fragments
8431          */
8432
8433         while (trn_data < input_vec_len) {
8434                 ++segs;
8435                 to_trn = (input_vec_len - trn_data < fragsz) ?
8436                                 (input_vec_len - trn_data) : fragsz;
8437
8438                 to_trn_tbl[ecx++] = to_trn;
8439
8440                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8441                 buf = buf->next;
8442
8443                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8444                                 rte_pktmbuf_tailroom(buf));
8445
8446                 /* OOP */
8447                 if (oop && !fragsz_oop) {
8448                         buf_oop->next =
8449                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8450                         buf_oop = buf_oop->next;
8451                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8452                                         0, rte_pktmbuf_tailroom(buf_oop));
8453                         rte_pktmbuf_append(buf_oop, to_trn);
8454                 }
8455
8456                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8457                                 to_trn);
8458
8459                 memcpy(plaintext, input_vec + trn_data, to_trn);
8460                 trn_data += to_trn;
8461         }
8462
8463         ut_params->ibuf->nb_segs = segs;
8464
8465         segs = 1;
8466         if (fragsz_oop && oop) {
8467                 to_trn = 0;
8468                 ecx = 0;
8469
8470                 trn_data = frag_size_oop;
8471                 while (trn_data < output_vec_len) {
8472                         ++segs;
8473                         to_trn =
8474                                 (output_vec_len - trn_data <
8475                                                 frag_size_oop) ?
8476                                 (output_vec_len - trn_data) :
8477                                                 frag_size_oop;
8478
8479                         to_trn_tbl[ecx++] = to_trn;
8480
8481                         buf_oop->next =
8482                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
8483                         buf_oop = buf_oop->next;
8484                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8485                                         0, rte_pktmbuf_tailroom(buf_oop));
8486                         rte_pktmbuf_append(buf_oop, to_trn);
8487
8488                         trn_data += to_trn;
8489                 }
8490                 ut_params->obuf->nb_segs = segs;
8491         }
8492
8493         /* Setup Cipher Parameters */
8494         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8495         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8496         ut_params->cipher_xform.cipher.op = opc;
8497         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8498         ut_params->cipher_xform.cipher.key.length =
8499                                         pdcp_test_params[i].cipher_key_len;
8500         ut_params->cipher_xform.cipher.iv.length = 0;
8501
8502         /* Setup HMAC Parameters if ICV header is required */
8503         if (pdcp_test_params[i].auth_alg != 0) {
8504                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8505                 ut_params->auth_xform.next = NULL;
8506                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8507                 ut_params->auth_xform.auth.op = opa;
8508                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8509                 ut_params->auth_xform.auth.key.length =
8510                                         pdcp_test_params[i].auth_key_len;
8511
8512                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8513         } else {
8514                 ut_params->cipher_xform.next = NULL;
8515         }
8516
8517         struct rte_security_session_conf sess_conf = {
8518                 .action_type = ut_params->type,
8519                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8520                 {.pdcp = {
8521                         .bearer = pdcp_test_bearer[i],
8522                         .domain = pdcp_test_params[i].domain,
8523                         .pkt_dir = pdcp_test_packet_direction[i],
8524                         .sn_size = pdcp_test_data_sn_size[i],
8525                         .hfn = pdcp_test_hfn[i],
8526                         .hfn_threshold = pdcp_test_hfn_threshold[i],
8527                         .hfn_ovrd = 0,
8528                 } },
8529                 .crypto_xform = &ut_params->cipher_xform
8530         };
8531
8532         /* Create security session */
8533         ut_params->sec_session = rte_security_session_create(ctx,
8534                                 &sess_conf, ts_params->session_mpool,
8535                                 ts_params->session_priv_mpool);
8536
8537         if (!ut_params->sec_session) {
8538                 printf("TestCase %s()-%d line %d failed %s: ",
8539                         __func__, i, __LINE__, "Failed to allocate session");
8540                 ret = TEST_FAILED;
8541                 goto on_err;
8542         }
8543
8544         /* Generate crypto op data structure */
8545         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8546                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8547         if (!ut_params->op) {
8548                 printf("TestCase %s()-%d line %d failed %s: ",
8549                         __func__, i, __LINE__,
8550                         "Failed to allocate symmetric crypto operation struct");
8551                 ret = TEST_FAILED;
8552                 goto on_err;
8553         }
8554
8555         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8556
8557         /* set crypto operation source mbuf */
8558         ut_params->op->sym->m_src = ut_params->ibuf;
8559         if (oop)
8560                 ut_params->op->sym->m_dst = ut_params->obuf;
8561
8562         /* Process crypto operation */
8563         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8564                 == NULL) {
8565                 printf("TestCase %s()-%d line %d failed %s: ",
8566                         __func__, i, __LINE__,
8567                         "failed to process sym crypto op");
8568                 ret = TEST_FAILED;
8569                 goto on_err;
8570         }
8571
8572         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8573                 printf("TestCase %s()-%d line %d failed %s: ",
8574                         __func__, i, __LINE__, "crypto op processing failed");
8575                 ret = TEST_FAILED;
8576                 goto on_err;
8577         }
8578
8579         /* Validate obuf */
8580         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8581                         uint8_t *);
8582         if (oop) {
8583                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8584                                 uint8_t *);
8585         }
8586         if (fragsz_oop)
8587                 fragsz = frag_size_oop;
8588         if (memcmp(ciphertext, output_vec, fragsz)) {
8589                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8590                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8591                 rte_hexdump(stdout, "reference", output_vec, fragsz);
8592                 ret = TEST_FAILED;
8593                 goto on_err;
8594         }
8595
8596         buf = ut_params->op->sym->m_src->next;
8597         if (oop)
8598                 buf = ut_params->op->sym->m_dst->next;
8599
8600         unsigned int off = fragsz;
8601
8602         ecx = 0;
8603         while (buf) {
8604                 ciphertext = rte_pktmbuf_mtod(buf,
8605                                 uint8_t *);
8606                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8607                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8608                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8609                         rte_hexdump(stdout, "reference", output_vec + off,
8610                                         to_trn_tbl[ecx]);
8611                         ret = TEST_FAILED;
8612                         goto on_err;
8613                 }
8614                 off += to_trn_tbl[ecx++];
8615                 buf = buf->next;
8616         }
8617 on_err:
8618         rte_crypto_op_free(ut_params->op);
8619         ut_params->op = NULL;
8620
8621         if (ut_params->sec_session)
8622                 rte_security_session_destroy(ctx, ut_params->sec_session);
8623         ut_params->sec_session = NULL;
8624
8625         rte_pktmbuf_free(ut_params->ibuf);
8626         ut_params->ibuf = NULL;
8627         if (oop) {
8628                 rte_pktmbuf_free(ut_params->obuf);
8629                 ut_params->obuf = NULL;
8630         }
8631
8632         return ret;
8633 }
8634
8635 int
8636 test_pdcp_proto_cplane_encap(int i)
8637 {
8638         return test_pdcp_proto(
8639                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8640                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8641                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8642                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8643                 pdcp_test_params[i].cipher_key_len,
8644                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8645                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8646                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8647                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8648                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8649 }
8650
8651 int
8652 test_pdcp_proto_uplane_encap(int i)
8653 {
8654         return test_pdcp_proto(
8655                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8656                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8657                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8658                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8659                 pdcp_test_params[i].cipher_key_len,
8660                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8661                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8662                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8663                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8664                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8665 }
8666
8667 int
8668 test_pdcp_proto_uplane_encap_with_int(int i)
8669 {
8670         return test_pdcp_proto(
8671                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8672                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8673                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8674                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8675                 pdcp_test_params[i].cipher_key_len,
8676                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8677                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8678                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8679                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8680                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8681 }
8682
8683 int
8684 test_pdcp_proto_cplane_decap(int i)
8685 {
8686         return test_pdcp_proto(
8687                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8688                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8689                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8690                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8691                 pdcp_test_params[i].cipher_key_len,
8692                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8693                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8694                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8695                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8696                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8697 }
8698
8699 int
8700 test_pdcp_proto_uplane_decap(int i)
8701 {
8702         return test_pdcp_proto(
8703                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8704                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8705                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8706                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8707                 pdcp_test_params[i].cipher_key_len,
8708                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8709                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8710                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8711                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8712                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8713 }
8714
8715 int
8716 test_pdcp_proto_uplane_decap_with_int(int i)
8717 {
8718         return test_pdcp_proto(
8719                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8720                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8721                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8722                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8723                 pdcp_test_params[i].cipher_key_len,
8724                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8725                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8726                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8727                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8728                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8729 }
8730
8731 static int
8732 test_PDCP_PROTO_SGL_in_place_32B(void)
8733 {
8734         /* i can be used for running any PDCP case
8735          * In this case it is uplane 12-bit AES-SNOW DL encap
8736          */
8737         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8738         return test_pdcp_proto_SGL(i, IN_PLACE,
8739                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8740                         RTE_CRYPTO_AUTH_OP_GENERATE,
8741                         pdcp_test_data_in[i],
8742                         pdcp_test_data_in_len[i],
8743                         pdcp_test_data_out[i],
8744                         pdcp_test_data_in_len[i]+4,
8745                         32, 0);
8746 }
8747 static int
8748 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8749 {
8750         /* i can be used for running any PDCP case
8751          * In this case it is uplane 18-bit NULL-NULL DL encap
8752          */
8753         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8754         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8755                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8756                         RTE_CRYPTO_AUTH_OP_GENERATE,
8757                         pdcp_test_data_in[i],
8758                         pdcp_test_data_in_len[i],
8759                         pdcp_test_data_out[i],
8760                         pdcp_test_data_in_len[i]+4,
8761                         32, 128);
8762 }
8763 static int
8764 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8765 {
8766         /* i can be used for running any PDCP case
8767          * In this case it is uplane 18-bit AES DL encap
8768          */
8769         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8770                         + DOWNLINK;
8771         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8772                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8773                         RTE_CRYPTO_AUTH_OP_GENERATE,
8774                         pdcp_test_data_in[i],
8775                         pdcp_test_data_in_len[i],
8776                         pdcp_test_data_out[i],
8777                         pdcp_test_data_in_len[i],
8778                         32, 40);
8779 }
8780 static int
8781 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8782 {
8783         /* i can be used for running any PDCP case
8784          * In this case it is cplane 12-bit AES-ZUC DL encap
8785          */
8786         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8787         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8788                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8789                         RTE_CRYPTO_AUTH_OP_GENERATE,
8790                         pdcp_test_data_in[i],
8791                         pdcp_test_data_in_len[i],
8792                         pdcp_test_data_out[i],
8793                         pdcp_test_data_in_len[i]+4,
8794                         128, 32);
8795 }
8796
8797 static int
8798 test_PDCP_SDAP_PROTO_encap_all(void)
8799 {
8800         int i = 0, size = 0;
8801         int err, all_err = TEST_SUCCESS;
8802         const struct pdcp_sdap_test *cur_test;
8803
8804         size = ARRAY_SIZE(list_pdcp_sdap_tests);
8805
8806         for (i = 0; i < size; i++) {
8807                 cur_test = &list_pdcp_sdap_tests[i];
8808                 err = test_pdcp_proto(
8809                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8810                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8811                         cur_test->in_len, cur_test->data_out,
8812                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8813                         cur_test->param.cipher_alg, cur_test->cipher_key,
8814                         cur_test->param.cipher_key_len,
8815                         cur_test->param.auth_alg,
8816                         cur_test->auth_key, cur_test->param.auth_key_len,
8817                         cur_test->bearer, cur_test->param.domain,
8818                         cur_test->packet_direction, cur_test->sn_size,
8819                         cur_test->hfn,
8820                         cur_test->hfn_threshold, SDAP_ENABLED);
8821                 if (err) {
8822                         printf("\t%d) %s: Encapsulation failed\n",
8823                                         cur_test->test_idx,
8824                                         cur_test->param.name);
8825                         err = TEST_FAILED;
8826                 } else {
8827                         printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8828                                         cur_test->param.name);
8829                         err = TEST_SUCCESS;
8830                 }
8831                 all_err += err;
8832         }
8833
8834         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8835
8836         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8837 }
8838
8839 static int
8840 test_PDCP_SDAP_PROTO_decap_all(void)
8841 {
8842         int i = 0, size = 0;
8843         int err, all_err = TEST_SUCCESS;
8844         const struct pdcp_sdap_test *cur_test;
8845
8846         size = ARRAY_SIZE(list_pdcp_sdap_tests);
8847
8848         for (i = 0; i < size; i++) {
8849                 cur_test = &list_pdcp_sdap_tests[i];
8850                 err = test_pdcp_proto(
8851                         i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8852                         RTE_CRYPTO_AUTH_OP_VERIFY,
8853                         cur_test->data_out,
8854                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8855                         cur_test->data_in, cur_test->in_len,
8856                         cur_test->param.cipher_alg,
8857                         cur_test->cipher_key, cur_test->param.cipher_key_len,
8858                         cur_test->param.auth_alg, cur_test->auth_key,
8859                         cur_test->param.auth_key_len, cur_test->bearer,
8860                         cur_test->param.domain, cur_test->packet_direction,
8861                         cur_test->sn_size, cur_test->hfn,
8862                         cur_test->hfn_threshold, SDAP_ENABLED);
8863                 if (err) {
8864                         printf("\t%d) %s: Decapsulation failed\n",
8865                                         cur_test->test_idx,
8866                                         cur_test->param.name);
8867                         err = TEST_FAILED;
8868                 } else {
8869                         printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8870                                         cur_test->param.name);
8871                         err = TEST_SUCCESS;
8872                 }
8873                 all_err += err;
8874         }
8875
8876         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8877
8878         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8879 }
8880
8881 static int
8882 test_PDCP_PROTO_all(void)
8883 {
8884         struct crypto_testsuite_params *ts_params = &testsuite_params;
8885         struct crypto_unittest_params *ut_params = &unittest_params;
8886         struct rte_cryptodev_info dev_info;
8887         int status;
8888
8889         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8890         uint64_t feat_flags = dev_info.feature_flags;
8891
8892         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8893                 return TEST_SKIPPED;
8894
8895         /* Set action type */
8896         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8897                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8898                 gbl_action_type;
8899
8900         if (security_proto_supported(ut_params->type,
8901                         RTE_SECURITY_PROTOCOL_PDCP) < 0)
8902                 return TEST_SKIPPED;
8903
8904         status = test_PDCP_PROTO_cplane_encap_all();
8905         status += test_PDCP_PROTO_cplane_decap_all();
8906         status += test_PDCP_PROTO_uplane_encap_all();
8907         status += test_PDCP_PROTO_uplane_decap_all();
8908         status += test_PDCP_PROTO_SGL_in_place_32B();
8909         status += test_PDCP_PROTO_SGL_oop_32B_128B();
8910         status += test_PDCP_PROTO_SGL_oop_32B_40B();
8911         status += test_PDCP_PROTO_SGL_oop_128B_32B();
8912         status += test_PDCP_SDAP_PROTO_encap_all();
8913         status += test_PDCP_SDAP_PROTO_decap_all();
8914
8915         if (status)
8916                 return TEST_FAILED;
8917         else
8918                 return TEST_SUCCESS;
8919 }
8920
8921 static int
8922 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
8923 {
8924         struct crypto_testsuite_params *ts_params = &testsuite_params;
8925         struct crypto_unittest_params *ut_params = &unittest_params;
8926         uint8_t *plaintext, *ciphertext;
8927         uint8_t *iv_ptr;
8928         int32_t cipher_len, crc_len;
8929         uint32_t crc_data_len;
8930         int ret = TEST_SUCCESS;
8931
8932         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8933                                         rte_cryptodev_get_sec_ctx(
8934                                                 ts_params->valid_devs[0]);
8935
8936         /* Verify the capabilities */
8937         struct rte_security_capability_idx sec_cap_idx;
8938         const struct rte_security_capability *sec_cap;
8939         const struct rte_cryptodev_capabilities *crypto_cap;
8940         const struct rte_cryptodev_symmetric_capability *sym_cap;
8941         int j = 0;
8942
8943         sec_cap_idx.action = ut_params->type;
8944         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8945         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
8946
8947         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8948         if (sec_cap == NULL)
8949                 return TEST_SKIPPED;
8950
8951         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8952                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8953                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8954                                 crypto_cap->sym.xform_type ==
8955                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
8956                                 crypto_cap->sym.cipher.algo ==
8957                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8958                         sym_cap = &crypto_cap->sym;
8959                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8960                                                 d_td->key.len,
8961                                                 d_td->iv.len) == 0)
8962                                 break;
8963                 }
8964         }
8965
8966         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8967                 return TEST_SKIPPED;
8968
8969         /* Setup source mbuf payload */
8970         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8971         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8972                         rte_pktmbuf_tailroom(ut_params->ibuf));
8973
8974         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8975                         d_td->ciphertext.len);
8976
8977         memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
8978
8979         /* Setup cipher session parameters */
8980         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8981         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8982         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
8983         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8984         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8985         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8986         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8987         ut_params->cipher_xform.next = NULL;
8988
8989         /* Setup DOCSIS session parameters */
8990         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
8991
8992         struct rte_security_session_conf sess_conf = {
8993                 .action_type = ut_params->type,
8994                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8995                 .docsis = ut_params->docsis_xform,
8996                 .crypto_xform = &ut_params->cipher_xform,
8997         };
8998
8999         /* Create security session */
9000         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9001                                         ts_params->session_mpool,
9002                                         ts_params->session_priv_mpool);
9003
9004         if (!ut_params->sec_session) {
9005                 printf("TestCase %s(%d) line %d: %s\n",
9006                         __func__, i, __LINE__, "failed to allocate session");
9007                 ret = TEST_FAILED;
9008                 goto on_err;
9009         }
9010
9011         /* Generate crypto op data structure */
9012         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9013                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9014         if (!ut_params->op) {
9015                 printf("TestCase %s(%d) line %d: %s\n",
9016                         __func__, i, __LINE__,
9017                         "failed to allocate symmetric crypto operation");
9018                 ret = TEST_FAILED;
9019                 goto on_err;
9020         }
9021
9022         /* Setup CRC operation parameters */
9023         crc_len = d_td->ciphertext.no_crc == false ?
9024                         (d_td->ciphertext.len -
9025                                 d_td->ciphertext.crc_offset -
9026                                 RTE_ETHER_CRC_LEN) :
9027                         0;
9028         crc_len = crc_len > 0 ? crc_len : 0;
9029         crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
9030         ut_params->op->sym->auth.data.length = crc_len;
9031         ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
9032
9033         /* Setup cipher operation parameters */
9034         cipher_len = d_td->ciphertext.no_cipher == false ?
9035                         (d_td->ciphertext.len -
9036                                 d_td->ciphertext.cipher_offset) :
9037                         0;
9038         cipher_len = cipher_len > 0 ? cipher_len : 0;
9039         ut_params->op->sym->cipher.data.length = cipher_len;
9040         ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
9041
9042         /* Setup cipher IV */
9043         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9044         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9045
9046         /* Attach session to operation */
9047         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9048
9049         /* Set crypto operation mbufs */
9050         ut_params->op->sym->m_src = ut_params->ibuf;
9051         ut_params->op->sym->m_dst = NULL;
9052
9053         /* Process crypto operation */
9054         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9055                         NULL) {
9056                 printf("TestCase %s(%d) line %d: %s\n",
9057                         __func__, i, __LINE__,
9058                         "failed to process security crypto op");
9059                 ret = TEST_FAILED;
9060                 goto on_err;
9061         }
9062
9063         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9064                 printf("TestCase %s(%d) line %d: %s\n",
9065                         __func__, i, __LINE__, "crypto op processing failed");
9066                 ret = TEST_FAILED;
9067                 goto on_err;
9068         }
9069
9070         /* Validate plaintext */
9071         plaintext = ciphertext;
9072
9073         if (memcmp(plaintext, d_td->plaintext.data,
9074                         d_td->plaintext.len - crc_data_len)) {
9075                 printf("TestCase %s(%d) line %d: %s\n",
9076                         __func__, i, __LINE__, "plaintext not as expected\n");
9077                 rte_hexdump(stdout, "expected", d_td->plaintext.data,
9078                                 d_td->plaintext.len);
9079                 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9080                 ret = TEST_FAILED;
9081                 goto on_err;
9082         }
9083
9084 on_err:
9085         rte_crypto_op_free(ut_params->op);
9086         ut_params->op = NULL;
9087
9088         if (ut_params->sec_session)
9089                 rte_security_session_destroy(ctx, ut_params->sec_session);
9090         ut_params->sec_session = NULL;
9091
9092         rte_pktmbuf_free(ut_params->ibuf);
9093         ut_params->ibuf = NULL;
9094
9095         return ret;
9096 }
9097
9098 static int
9099 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9100 {
9101         struct crypto_testsuite_params *ts_params = &testsuite_params;
9102         struct crypto_unittest_params *ut_params = &unittest_params;
9103         uint8_t *plaintext, *ciphertext;
9104         uint8_t *iv_ptr;
9105         int32_t cipher_len, crc_len;
9106         int ret = TEST_SUCCESS;
9107
9108         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9109                                         rte_cryptodev_get_sec_ctx(
9110                                                 ts_params->valid_devs[0]);
9111
9112         /* Verify the capabilities */
9113         struct rte_security_capability_idx sec_cap_idx;
9114         const struct rte_security_capability *sec_cap;
9115         const struct rte_cryptodev_capabilities *crypto_cap;
9116         const struct rte_cryptodev_symmetric_capability *sym_cap;
9117         int j = 0;
9118
9119         sec_cap_idx.action = ut_params->type;
9120         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9121         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9122
9123         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9124         if (sec_cap == NULL)
9125                 return TEST_SKIPPED;
9126
9127         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9128                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9129                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9130                                 crypto_cap->sym.xform_type ==
9131                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9132                                 crypto_cap->sym.cipher.algo ==
9133                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9134                         sym_cap = &crypto_cap->sym;
9135                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9136                                                 d_td->key.len,
9137                                                 d_td->iv.len) == 0)
9138                                 break;
9139                 }
9140         }
9141
9142         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9143                 return TEST_SKIPPED;
9144
9145         /* Setup source mbuf payload */
9146         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9147         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9148                         rte_pktmbuf_tailroom(ut_params->ibuf));
9149
9150         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9151                         d_td->plaintext.len);
9152
9153         memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9154
9155         /* Setup cipher session parameters */
9156         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9157         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9158         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9159         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9160         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9161         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9162         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9163         ut_params->cipher_xform.next = NULL;
9164
9165         /* Setup DOCSIS session parameters */
9166         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9167
9168         struct rte_security_session_conf sess_conf = {
9169                 .action_type = ut_params->type,
9170                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9171                 .docsis = ut_params->docsis_xform,
9172                 .crypto_xform = &ut_params->cipher_xform,
9173         };
9174
9175         /* Create security session */
9176         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9177                                         ts_params->session_mpool,
9178                                         ts_params->session_priv_mpool);
9179
9180         if (!ut_params->sec_session) {
9181                 printf("TestCase %s(%d) line %d: %s\n",
9182                         __func__, i, __LINE__, "failed to allocate session");
9183                 ret = TEST_FAILED;
9184                 goto on_err;
9185         }
9186
9187         /* Generate crypto op data structure */
9188         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9189                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9190         if (!ut_params->op) {
9191                 printf("TestCase %s(%d) line %d: %s\n",
9192                         __func__, i, __LINE__,
9193                         "failed to allocate security crypto operation");
9194                 ret = TEST_FAILED;
9195                 goto on_err;
9196         }
9197
9198         /* Setup CRC operation parameters */
9199         crc_len = d_td->plaintext.no_crc == false ?
9200                         (d_td->plaintext.len -
9201                                 d_td->plaintext.crc_offset -
9202                                 RTE_ETHER_CRC_LEN) :
9203                         0;
9204         crc_len = crc_len > 0 ? crc_len : 0;
9205         ut_params->op->sym->auth.data.length = crc_len;
9206         ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9207
9208         /* Setup cipher operation parameters */
9209         cipher_len = d_td->plaintext.no_cipher == false ?
9210                         (d_td->plaintext.len -
9211                                 d_td->plaintext.cipher_offset) :
9212                         0;
9213         cipher_len = cipher_len > 0 ? cipher_len : 0;
9214         ut_params->op->sym->cipher.data.length = cipher_len;
9215         ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9216
9217         /* Setup cipher IV */
9218         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9219         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9220
9221         /* Attach session to operation */
9222         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9223
9224         /* Set crypto operation mbufs */
9225         ut_params->op->sym->m_src = ut_params->ibuf;
9226         ut_params->op->sym->m_dst = NULL;
9227
9228         /* Process crypto operation */
9229         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9230                         NULL) {
9231                 printf("TestCase %s(%d) line %d: %s\n",
9232                         __func__, i, __LINE__,
9233                         "failed to process security crypto op");
9234                 ret = TEST_FAILED;
9235                 goto on_err;
9236         }
9237
9238         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9239                 printf("TestCase %s(%d) line %d: %s\n",
9240                         __func__, i, __LINE__, "crypto op processing failed");
9241                 ret = TEST_FAILED;
9242                 goto on_err;
9243         }
9244
9245         /* Validate ciphertext */
9246         ciphertext = plaintext;
9247
9248         if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9249                 printf("TestCase %s(%d) line %d: %s\n",
9250                         __func__, i, __LINE__, "ciphertext not as expected\n");
9251                 rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9252                                 d_td->ciphertext.len);
9253                 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9254                 ret = TEST_FAILED;
9255                 goto on_err;
9256         }
9257
9258 on_err:
9259         rte_crypto_op_free(ut_params->op);
9260         ut_params->op = NULL;
9261
9262         if (ut_params->sec_session)
9263                 rte_security_session_destroy(ctx, ut_params->sec_session);
9264         ut_params->sec_session = NULL;
9265
9266         rte_pktmbuf_free(ut_params->ibuf);
9267         ut_params->ibuf = NULL;
9268
9269         return ret;
9270 }
9271
9272 #define TEST_DOCSIS_COUNT(func) do {                    \
9273         int ret = func;                                 \
9274         if (ret == TEST_SUCCESS)  {                     \
9275                 printf("\t%2d)", n++);                  \
9276                 printf("+++++ PASSED:" #func"\n");      \
9277                 p++;                                    \
9278         } else if (ret == TEST_SKIPPED) {               \
9279                 printf("\t%2d)", n++);                  \
9280                 printf("~~~~~ SKIPPED:" #func"\n");     \
9281                 s++;                                    \
9282         } else {                                        \
9283                 printf("\t%2d)", n++);                  \
9284                 printf("----- FAILED:" #func"\n");      \
9285                 f++;                                    \
9286         }                                               \
9287 } while (0)
9288
9289 static int
9290 test_DOCSIS_PROTO_uplink_all(void)
9291 {
9292         int p = 0, s = 0, f = 0, n = 0;
9293
9294         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9295         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9296         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9297         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9298         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9299         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9300         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9301         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9302         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9303         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9304         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9305         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9306         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9307         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9308         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9309         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9310         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9311         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9312         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9313         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9314         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9315         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9316         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9317         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9318         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9319         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9320
9321         if (f)
9322                 printf("## %s: %d passed out of %d (%d skipped)\n",
9323                         __func__, p, n, s);
9324
9325         return f;
9326 };
9327
9328 static int
9329 test_DOCSIS_PROTO_downlink_all(void)
9330 {
9331         int p = 0, s = 0, f = 0, n = 0;
9332
9333         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9334         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9335         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9336         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9337         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9338         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9339         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9340         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9341         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9342         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9343         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9344         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9345         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9346         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9347         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9348         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9349         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9350         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9351         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9352         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9353         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9354         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9355         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9356         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9357         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9358         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9359
9360         if (f)
9361                 printf("## %s: %d passed out of %d (%d skipped)\n",
9362                         __func__, p, n, s);
9363
9364         return f;
9365 };
9366
9367 static int
9368 test_DOCSIS_PROTO_all(void)
9369 {
9370         struct crypto_testsuite_params *ts_params = &testsuite_params;
9371         struct crypto_unittest_params *ut_params = &unittest_params;
9372         struct rte_cryptodev_info dev_info;
9373         int status;
9374
9375         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9376         uint64_t feat_flags = dev_info.feature_flags;
9377
9378         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9379                 return TEST_SKIPPED;
9380
9381         /* Set action type */
9382         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9383                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9384                 gbl_action_type;
9385
9386         if (security_proto_supported(ut_params->type,
9387                         RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9388                 return TEST_SKIPPED;
9389
9390         status = test_DOCSIS_PROTO_uplink_all();
9391         status += test_DOCSIS_PROTO_downlink_all();
9392
9393         if (status)
9394                 return TEST_FAILED;
9395         else
9396                 return TEST_SUCCESS;
9397 }
9398 #endif
9399
9400 static int
9401 test_AES_GCM_authenticated_encryption_test_case_1(void)
9402 {
9403         return test_authenticated_encryption(&gcm_test_case_1);
9404 }
9405
9406 static int
9407 test_AES_GCM_authenticated_encryption_test_case_2(void)
9408 {
9409         return test_authenticated_encryption(&gcm_test_case_2);
9410 }
9411
9412 static int
9413 test_AES_GCM_authenticated_encryption_test_case_3(void)
9414 {
9415         return test_authenticated_encryption(&gcm_test_case_3);
9416 }
9417
9418 static int
9419 test_AES_GCM_authenticated_encryption_test_case_4(void)
9420 {
9421         return test_authenticated_encryption(&gcm_test_case_4);
9422 }
9423
9424 static int
9425 test_AES_GCM_authenticated_encryption_test_case_5(void)
9426 {
9427         return test_authenticated_encryption(&gcm_test_case_5);
9428 }
9429
9430 static int
9431 test_AES_GCM_authenticated_encryption_test_case_6(void)
9432 {
9433         return test_authenticated_encryption(&gcm_test_case_6);
9434 }
9435
9436 static int
9437 test_AES_GCM_authenticated_encryption_test_case_7(void)
9438 {
9439         return test_authenticated_encryption(&gcm_test_case_7);
9440 }
9441
9442 static int
9443 test_AES_GCM_authenticated_encryption_test_case_8(void)
9444 {
9445         return test_authenticated_encryption(&gcm_test_case_8);
9446 }
9447
9448 static int
9449 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9450 {
9451         return test_authenticated_encryption(&gcm_J0_test_case_1);
9452 }
9453
9454 static int
9455 test_AES_GCM_auth_encryption_test_case_192_1(void)
9456 {
9457         return test_authenticated_encryption(&gcm_test_case_192_1);
9458 }
9459
9460 static int
9461 test_AES_GCM_auth_encryption_test_case_192_2(void)
9462 {
9463         return test_authenticated_encryption(&gcm_test_case_192_2);
9464 }
9465
9466 static int
9467 test_AES_GCM_auth_encryption_test_case_192_3(void)
9468 {
9469         return test_authenticated_encryption(&gcm_test_case_192_3);
9470 }
9471
9472 static int
9473 test_AES_GCM_auth_encryption_test_case_192_4(void)
9474 {
9475         return test_authenticated_encryption(&gcm_test_case_192_4);
9476 }
9477
9478 static int
9479 test_AES_GCM_auth_encryption_test_case_192_5(void)
9480 {
9481         return test_authenticated_encryption(&gcm_test_case_192_5);
9482 }
9483
9484 static int
9485 test_AES_GCM_auth_encryption_test_case_192_6(void)
9486 {
9487         return test_authenticated_encryption(&gcm_test_case_192_6);
9488 }
9489
9490 static int
9491 test_AES_GCM_auth_encryption_test_case_192_7(void)
9492 {
9493         return test_authenticated_encryption(&gcm_test_case_192_7);
9494 }
9495
9496 static int
9497 test_AES_GCM_auth_encryption_test_case_256_1(void)
9498 {
9499         return test_authenticated_encryption(&gcm_test_case_256_1);
9500 }
9501
9502 static int
9503 test_AES_GCM_auth_encryption_test_case_256_2(void)
9504 {
9505         return test_authenticated_encryption(&gcm_test_case_256_2);
9506 }
9507
9508 static int
9509 test_AES_GCM_auth_encryption_test_case_256_3(void)
9510 {
9511         return test_authenticated_encryption(&gcm_test_case_256_3);
9512 }
9513
9514 static int
9515 test_AES_GCM_auth_encryption_test_case_256_4(void)
9516 {
9517         return test_authenticated_encryption(&gcm_test_case_256_4);
9518 }
9519
9520 static int
9521 test_AES_GCM_auth_encryption_test_case_256_5(void)
9522 {
9523         return test_authenticated_encryption(&gcm_test_case_256_5);
9524 }
9525
9526 static int
9527 test_AES_GCM_auth_encryption_test_case_256_6(void)
9528 {
9529         return test_authenticated_encryption(&gcm_test_case_256_6);
9530 }
9531
9532 static int
9533 test_AES_GCM_auth_encryption_test_case_256_7(void)
9534 {
9535         return test_authenticated_encryption(&gcm_test_case_256_7);
9536 }
9537
9538 static int
9539 test_AES_GCM_auth_encryption_test_case_aad_1(void)
9540 {
9541         return test_authenticated_encryption(&gcm_test_case_aad_1);
9542 }
9543
9544 static int
9545 test_AES_GCM_auth_encryption_test_case_aad_2(void)
9546 {
9547         return test_authenticated_encryption(&gcm_test_case_aad_2);
9548 }
9549
9550 static int
9551 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
9552 {
9553         struct aead_test_data tdata;
9554         int res;
9555
9556         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9557         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9558         tdata.iv.data[0] += 1;
9559         res = test_authenticated_encryption(&tdata);
9560         if (res == TEST_SKIPPED)
9561                 return res;
9562         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9563         return TEST_SUCCESS;
9564 }
9565
9566 static int
9567 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
9568 {
9569         struct aead_test_data tdata;
9570         int res;
9571
9572         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9573         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9574         tdata.plaintext.data[0] += 1;
9575         res = test_authenticated_encryption(&tdata);
9576         if (res == TEST_SKIPPED)
9577                 return res;
9578         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9579         return TEST_SUCCESS;
9580 }
9581
9582 static int
9583 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
9584 {
9585         struct aead_test_data tdata;
9586         int res;
9587
9588         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9589         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9590         tdata.ciphertext.data[0] += 1;
9591         res = test_authenticated_encryption(&tdata);
9592         if (res == TEST_SKIPPED)
9593                 return res;
9594         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9595         return TEST_SUCCESS;
9596 }
9597
9598 static int
9599 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
9600 {
9601         struct aead_test_data tdata;
9602         int res;
9603
9604         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9605         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9606         tdata.aad.len += 1;
9607         res = test_authenticated_encryption(&tdata);
9608         if (res == TEST_SKIPPED)
9609                 return res;
9610         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9611         return TEST_SUCCESS;
9612 }
9613
9614 static int
9615 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
9616 {
9617         struct aead_test_data tdata;
9618         uint8_t aad[gcm_test_case_7.aad.len];
9619         int res;
9620
9621         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9622         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9623         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9624         aad[0] += 1;
9625         tdata.aad.data = aad;
9626         res = test_authenticated_encryption(&tdata);
9627         if (res == TEST_SKIPPED)
9628                 return res;
9629         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9630         return TEST_SUCCESS;
9631 }
9632
9633 static int
9634 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
9635 {
9636         struct aead_test_data tdata;
9637         int res;
9638
9639         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9640         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9641         tdata.auth_tag.data[0] += 1;
9642         res = test_authenticated_encryption(&tdata);
9643         if (res == TEST_SKIPPED)
9644                 return res;
9645         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9646         return TEST_SUCCESS;
9647 }
9648
9649 static int
9650 test_authenticated_decryption(const struct aead_test_data *tdata)
9651 {
9652         struct crypto_testsuite_params *ts_params = &testsuite_params;
9653         struct crypto_unittest_params *ut_params = &unittest_params;
9654
9655         int retval;
9656         uint8_t *plaintext;
9657         uint32_t i;
9658         struct rte_cryptodev_info dev_info;
9659
9660         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9661         uint64_t feat_flags = dev_info.feature_flags;
9662
9663         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9664                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9665                 printf("Device doesn't support RAW data-path APIs.\n");
9666                 return TEST_SKIPPED;
9667         }
9668
9669         /* Verify the capabilities */
9670         struct rte_cryptodev_sym_capability_idx cap_idx;
9671         const struct rte_cryptodev_symmetric_capability *capability;
9672         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9673         cap_idx.algo.aead = tdata->algo;
9674         capability = rte_cryptodev_sym_capability_get(
9675                         ts_params->valid_devs[0], &cap_idx);
9676         if (capability == NULL)
9677                 return TEST_SKIPPED;
9678         if (rte_cryptodev_sym_capability_check_aead(
9679                         capability, tdata->key.len, tdata->auth_tag.len,
9680                         tdata->aad.len, tdata->iv.len))
9681                 return TEST_SKIPPED;
9682
9683         /* Create AEAD session */
9684         retval = create_aead_session(ts_params->valid_devs[0],
9685                         tdata->algo,
9686                         RTE_CRYPTO_AEAD_OP_DECRYPT,
9687                         tdata->key.data, tdata->key.len,
9688                         tdata->aad.len, tdata->auth_tag.len,
9689                         tdata->iv.len);
9690         if (retval < 0)
9691                 return retval;
9692
9693         /* alloc mbuf and set payload */
9694         if (tdata->aad.len > MBUF_SIZE) {
9695                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9696                 /* Populate full size of add data */
9697                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
9698                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
9699         } else
9700                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9701
9702         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9703                         rte_pktmbuf_tailroom(ut_params->ibuf));
9704
9705         /* Create AEAD operation */
9706         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9707         if (retval < 0)
9708                 return retval;
9709
9710         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9711
9712         ut_params->op->sym->m_src = ut_params->ibuf;
9713
9714         /* Process crypto operation */
9715         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9716                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
9717         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9718                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9719                                 ut_params->op, 0, 0, 0, 0);
9720         else
9721                 TEST_ASSERT_NOT_NULL(
9722                         process_crypto_request(ts_params->valid_devs[0],
9723                         ut_params->op), "failed to process sym crypto op");
9724
9725         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9726                         "crypto op processing failed");
9727
9728         if (ut_params->op->sym->m_dst)
9729                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9730                                 uint8_t *);
9731         else
9732                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
9733                                 uint8_t *,
9734                                 ut_params->op->sym->cipher.data.offset);
9735
9736         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9737
9738         /* Validate obuf */
9739         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9740                         plaintext,
9741                         tdata->plaintext.data,
9742                         tdata->plaintext.len,
9743                         "Plaintext data not as expected");
9744
9745         TEST_ASSERT_EQUAL(ut_params->op->status,
9746                         RTE_CRYPTO_OP_STATUS_SUCCESS,
9747                         "Authentication failed");
9748
9749         return 0;
9750 }
9751
9752 static int
9753 test_AES_GCM_authenticated_decryption_test_case_1(void)
9754 {
9755         return test_authenticated_decryption(&gcm_test_case_1);
9756 }
9757
9758 static int
9759 test_AES_GCM_authenticated_decryption_test_case_2(void)
9760 {
9761         return test_authenticated_decryption(&gcm_test_case_2);
9762 }
9763
9764 static int
9765 test_AES_GCM_authenticated_decryption_test_case_3(void)
9766 {
9767         return test_authenticated_decryption(&gcm_test_case_3);
9768 }
9769
9770 static int
9771 test_AES_GCM_authenticated_decryption_test_case_4(void)
9772 {
9773         return test_authenticated_decryption(&gcm_test_case_4);
9774 }
9775
9776 static int
9777 test_AES_GCM_authenticated_decryption_test_case_5(void)
9778 {
9779         return test_authenticated_decryption(&gcm_test_case_5);
9780 }
9781
9782 static int
9783 test_AES_GCM_authenticated_decryption_test_case_6(void)
9784 {
9785         return test_authenticated_decryption(&gcm_test_case_6);
9786 }
9787
9788 static int
9789 test_AES_GCM_authenticated_decryption_test_case_7(void)
9790 {
9791         return test_authenticated_decryption(&gcm_test_case_7);
9792 }
9793
9794 static int
9795 test_AES_GCM_authenticated_decryption_test_case_8(void)
9796 {
9797         return test_authenticated_decryption(&gcm_test_case_8);
9798 }
9799
9800 static int
9801 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
9802 {
9803         return test_authenticated_decryption(&gcm_J0_test_case_1);
9804 }
9805
9806 static int
9807 test_AES_GCM_auth_decryption_test_case_192_1(void)
9808 {
9809         return test_authenticated_decryption(&gcm_test_case_192_1);
9810 }
9811
9812 static int
9813 test_AES_GCM_auth_decryption_test_case_192_2(void)
9814 {
9815         return test_authenticated_decryption(&gcm_test_case_192_2);
9816 }
9817
9818 static int
9819 test_AES_GCM_auth_decryption_test_case_192_3(void)
9820 {
9821         return test_authenticated_decryption(&gcm_test_case_192_3);
9822 }
9823
9824 static int
9825 test_AES_GCM_auth_decryption_test_case_192_4(void)
9826 {
9827         return test_authenticated_decryption(&gcm_test_case_192_4);
9828 }
9829
9830 static int
9831 test_AES_GCM_auth_decryption_test_case_192_5(void)
9832 {
9833         return test_authenticated_decryption(&gcm_test_case_192_5);
9834 }
9835
9836 static int
9837 test_AES_GCM_auth_decryption_test_case_192_6(void)
9838 {
9839         return test_authenticated_decryption(&gcm_test_case_192_6);
9840 }
9841
9842 static int
9843 test_AES_GCM_auth_decryption_test_case_192_7(void)
9844 {
9845         return test_authenticated_decryption(&gcm_test_case_192_7);
9846 }
9847
9848 static int
9849 test_AES_GCM_auth_decryption_test_case_256_1(void)
9850 {
9851         return test_authenticated_decryption(&gcm_test_case_256_1);
9852 }
9853
9854 static int
9855 test_AES_GCM_auth_decryption_test_case_256_2(void)
9856 {
9857         return test_authenticated_decryption(&gcm_test_case_256_2);
9858 }
9859
9860 static int
9861 test_AES_GCM_auth_decryption_test_case_256_3(void)
9862 {
9863         return test_authenticated_decryption(&gcm_test_case_256_3);
9864 }
9865
9866 static int
9867 test_AES_GCM_auth_decryption_test_case_256_4(void)
9868 {
9869         return test_authenticated_decryption(&gcm_test_case_256_4);
9870 }
9871
9872 static int
9873 test_AES_GCM_auth_decryption_test_case_256_5(void)
9874 {
9875         return test_authenticated_decryption(&gcm_test_case_256_5);
9876 }
9877
9878 static int
9879 test_AES_GCM_auth_decryption_test_case_256_6(void)
9880 {
9881         return test_authenticated_decryption(&gcm_test_case_256_6);
9882 }
9883
9884 static int
9885 test_AES_GCM_auth_decryption_test_case_256_7(void)
9886 {
9887         return test_authenticated_decryption(&gcm_test_case_256_7);
9888 }
9889
9890 static int
9891 test_AES_GCM_auth_decryption_test_case_aad_1(void)
9892 {
9893         return test_authenticated_decryption(&gcm_test_case_aad_1);
9894 }
9895
9896 static int
9897 test_AES_GCM_auth_decryption_test_case_aad_2(void)
9898 {
9899         return test_authenticated_decryption(&gcm_test_case_aad_2);
9900 }
9901
9902 static int
9903 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
9904 {
9905         struct aead_test_data tdata;
9906         int res;
9907
9908         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9909         tdata.iv.data[0] += 1;
9910         res = test_authenticated_decryption(&tdata);
9911         if (res == TEST_SKIPPED)
9912                 return res;
9913         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9914         return TEST_SUCCESS;
9915 }
9916
9917 static int
9918 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
9919 {
9920         struct aead_test_data tdata;
9921         int res;
9922
9923         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9924         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9925         tdata.plaintext.data[0] += 1;
9926         res = test_authenticated_decryption(&tdata);
9927         if (res == TEST_SKIPPED)
9928                 return res;
9929         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9930         return TEST_SUCCESS;
9931 }
9932
9933 static int
9934 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
9935 {
9936         struct aead_test_data tdata;
9937         int res;
9938
9939         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9940         tdata.ciphertext.data[0] += 1;
9941         res = test_authenticated_decryption(&tdata);
9942         if (res == TEST_SKIPPED)
9943                 return res;
9944         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9945         return TEST_SUCCESS;
9946 }
9947
9948 static int
9949 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
9950 {
9951         struct aead_test_data tdata;
9952         int res;
9953
9954         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9955         tdata.aad.len += 1;
9956         res = test_authenticated_decryption(&tdata);
9957         if (res == TEST_SKIPPED)
9958                 return res;
9959         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9960         return TEST_SUCCESS;
9961 }
9962
9963 static int
9964 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
9965 {
9966         struct aead_test_data tdata;
9967         uint8_t aad[gcm_test_case_7.aad.len];
9968         int res;
9969
9970         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9971         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9972         aad[0] += 1;
9973         tdata.aad.data = aad;
9974         res = test_authenticated_decryption(&tdata);
9975         if (res == TEST_SKIPPED)
9976                 return res;
9977         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9978         return TEST_SUCCESS;
9979 }
9980
9981 static int
9982 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
9983 {
9984         struct aead_test_data tdata;
9985         int res;
9986
9987         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9988         tdata.auth_tag.data[0] += 1;
9989         res = test_authenticated_decryption(&tdata);
9990         if (res == TEST_SKIPPED)
9991                 return res;
9992         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
9993         return TEST_SUCCESS;
9994 }
9995
9996 static int
9997 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
9998 {
9999         struct crypto_testsuite_params *ts_params = &testsuite_params;
10000         struct crypto_unittest_params *ut_params = &unittest_params;
10001
10002         int retval;
10003         uint8_t *ciphertext, *auth_tag;
10004         uint16_t plaintext_pad_len;
10005
10006         /* Verify the capabilities */
10007         struct rte_cryptodev_sym_capability_idx cap_idx;
10008         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10009         cap_idx.algo.aead = tdata->algo;
10010         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10011                         &cap_idx) == NULL)
10012                 return TEST_SKIPPED;
10013
10014         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10015                 return TEST_SKIPPED;
10016
10017         /* not supported with CPU crypto */
10018         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10019                 return TEST_SKIPPED;
10020
10021         /* Create AEAD session */
10022         retval = create_aead_session(ts_params->valid_devs[0],
10023                         tdata->algo,
10024                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10025                         tdata->key.data, tdata->key.len,
10026                         tdata->aad.len, tdata->auth_tag.len,
10027                         tdata->iv.len);
10028         if (retval < 0)
10029                 return retval;
10030
10031         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10032         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10033
10034         /* clear mbuf payload */
10035         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10036                         rte_pktmbuf_tailroom(ut_params->ibuf));
10037         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10038                         rte_pktmbuf_tailroom(ut_params->obuf));
10039
10040         /* Create AEAD operation */
10041         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10042         if (retval < 0)
10043                 return retval;
10044
10045         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10046
10047         ut_params->op->sym->m_src = ut_params->ibuf;
10048         ut_params->op->sym->m_dst = ut_params->obuf;
10049
10050         /* Process crypto operation */
10051         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10052                         ut_params->op), "failed to process sym crypto op");
10053
10054         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10055                         "crypto op processing failed");
10056
10057         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10058
10059         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10060                         ut_params->op->sym->cipher.data.offset);
10061         auth_tag = ciphertext + plaintext_pad_len;
10062
10063         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10064         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10065
10066         /* Validate obuf */
10067         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10068                         ciphertext,
10069                         tdata->ciphertext.data,
10070                         tdata->ciphertext.len,
10071                         "Ciphertext data not as expected");
10072
10073         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10074                         auth_tag,
10075                         tdata->auth_tag.data,
10076                         tdata->auth_tag.len,
10077                         "Generated auth tag not as expected");
10078
10079         return 0;
10080
10081 }
10082
10083 static int
10084 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10085 {
10086         return test_authenticated_encryption_oop(&gcm_test_case_5);
10087 }
10088
10089 static int
10090 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10091 {
10092         struct crypto_testsuite_params *ts_params = &testsuite_params;
10093         struct crypto_unittest_params *ut_params = &unittest_params;
10094
10095         int retval;
10096         uint8_t *plaintext;
10097
10098         /* Verify the capabilities */
10099         struct rte_cryptodev_sym_capability_idx cap_idx;
10100         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10101         cap_idx.algo.aead = tdata->algo;
10102         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10103                         &cap_idx) == NULL)
10104                 return TEST_SKIPPED;
10105
10106         /* not supported with CPU crypto and raw data-path APIs*/
10107         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10108                         global_api_test_type == CRYPTODEV_RAW_API_TEST)
10109                 return TEST_SKIPPED;
10110
10111         /* Create AEAD session */
10112         retval = create_aead_session(ts_params->valid_devs[0],
10113                         tdata->algo,
10114                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10115                         tdata->key.data, tdata->key.len,
10116                         tdata->aad.len, tdata->auth_tag.len,
10117                         tdata->iv.len);
10118         if (retval < 0)
10119                 return retval;
10120
10121         /* alloc mbuf and set payload */
10122         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10123         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10124
10125         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10126                         rte_pktmbuf_tailroom(ut_params->ibuf));
10127         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10128                         rte_pktmbuf_tailroom(ut_params->obuf));
10129
10130         /* Create AEAD operation */
10131         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10132         if (retval < 0)
10133                 return retval;
10134
10135         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10136
10137         ut_params->op->sym->m_src = ut_params->ibuf;
10138         ut_params->op->sym->m_dst = ut_params->obuf;
10139
10140         /* Process crypto operation */
10141         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10142                         ut_params->op), "failed to process sym crypto op");
10143
10144         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10145                         "crypto op processing failed");
10146
10147         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10148                         ut_params->op->sym->cipher.data.offset);
10149
10150         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10151
10152         /* Validate obuf */
10153         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10154                         plaintext,
10155                         tdata->plaintext.data,
10156                         tdata->plaintext.len,
10157                         "Plaintext data not as expected");
10158
10159         TEST_ASSERT_EQUAL(ut_params->op->status,
10160                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10161                         "Authentication failed");
10162         return 0;
10163 }
10164
10165 static int
10166 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10167 {
10168         return test_authenticated_decryption_oop(&gcm_test_case_5);
10169 }
10170
10171 static int
10172 test_authenticated_encryption_sessionless(
10173                 const struct aead_test_data *tdata)
10174 {
10175         struct crypto_testsuite_params *ts_params = &testsuite_params;
10176         struct crypto_unittest_params *ut_params = &unittest_params;
10177
10178         int retval;
10179         uint8_t *ciphertext, *auth_tag;
10180         uint16_t plaintext_pad_len;
10181         uint8_t key[tdata->key.len + 1];
10182         struct rte_cryptodev_info dev_info;
10183
10184         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10185         uint64_t feat_flags = dev_info.feature_flags;
10186
10187         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10188                 printf("Device doesn't support Sessionless ops.\n");
10189                 return TEST_SKIPPED;
10190         }
10191
10192         /* not supported with CPU crypto */
10193         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10194                 return TEST_SKIPPED;
10195
10196         /* Verify the capabilities */
10197         struct rte_cryptodev_sym_capability_idx cap_idx;
10198         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10199         cap_idx.algo.aead = tdata->algo;
10200         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10201                         &cap_idx) == NULL)
10202                 return TEST_SKIPPED;
10203
10204         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10205
10206         /* clear mbuf payload */
10207         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10208                         rte_pktmbuf_tailroom(ut_params->ibuf));
10209
10210         /* Create AEAD operation */
10211         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10212         if (retval < 0)
10213                 return retval;
10214
10215         /* Create GCM xform */
10216         memcpy(key, tdata->key.data, tdata->key.len);
10217         retval = create_aead_xform(ut_params->op,
10218                         tdata->algo,
10219                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10220                         key, tdata->key.len,
10221                         tdata->aad.len, tdata->auth_tag.len,
10222                         tdata->iv.len);
10223         if (retval < 0)
10224                 return retval;
10225
10226         ut_params->op->sym->m_src = ut_params->ibuf;
10227
10228         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10229                         RTE_CRYPTO_OP_SESSIONLESS,
10230                         "crypto op session type not sessionless");
10231
10232         /* Process crypto operation */
10233         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10234                         ut_params->op), "failed to process sym crypto op");
10235
10236         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10237
10238         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10239                         "crypto op status not success");
10240
10241         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10242
10243         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10244                         ut_params->op->sym->cipher.data.offset);
10245         auth_tag = ciphertext + plaintext_pad_len;
10246
10247         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10248         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10249
10250         /* Validate obuf */
10251         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10252                         ciphertext,
10253                         tdata->ciphertext.data,
10254                         tdata->ciphertext.len,
10255                         "Ciphertext data not as expected");
10256
10257         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10258                         auth_tag,
10259                         tdata->auth_tag.data,
10260                         tdata->auth_tag.len,
10261                         "Generated auth tag not as expected");
10262
10263         return 0;
10264
10265 }
10266
10267 static int
10268 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10269 {
10270         return test_authenticated_encryption_sessionless(
10271                         &gcm_test_case_5);
10272 }
10273
10274 static int
10275 test_authenticated_decryption_sessionless(
10276                 const struct aead_test_data *tdata)
10277 {
10278         struct crypto_testsuite_params *ts_params = &testsuite_params;
10279         struct crypto_unittest_params *ut_params = &unittest_params;
10280
10281         int retval;
10282         uint8_t *plaintext;
10283         uint8_t key[tdata->key.len + 1];
10284         struct rte_cryptodev_info dev_info;
10285
10286         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10287         uint64_t feat_flags = dev_info.feature_flags;
10288
10289         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10290                 printf("Device doesn't support Sessionless ops.\n");
10291                 return TEST_SKIPPED;
10292         }
10293
10294         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10295                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10296                 printf("Device doesn't support RAW data-path APIs.\n");
10297                 return TEST_SKIPPED;
10298         }
10299
10300         /* not supported with CPU crypto */
10301         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10302                 return TEST_SKIPPED;
10303
10304         /* Verify the capabilities */
10305         struct rte_cryptodev_sym_capability_idx cap_idx;
10306         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10307         cap_idx.algo.aead = tdata->algo;
10308         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10309                         &cap_idx) == NULL)
10310                 return TEST_SKIPPED;
10311
10312         /* alloc mbuf and set payload */
10313         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10314
10315         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10316                         rte_pktmbuf_tailroom(ut_params->ibuf));
10317
10318         /* Create AEAD operation */
10319         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10320         if (retval < 0)
10321                 return retval;
10322
10323         /* Create AEAD xform */
10324         memcpy(key, tdata->key.data, tdata->key.len);
10325         retval = create_aead_xform(ut_params->op,
10326                         tdata->algo,
10327                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10328                         key, tdata->key.len,
10329                         tdata->aad.len, tdata->auth_tag.len,
10330                         tdata->iv.len);
10331         if (retval < 0)
10332                 return retval;
10333
10334         ut_params->op->sym->m_src = ut_params->ibuf;
10335
10336         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10337                         RTE_CRYPTO_OP_SESSIONLESS,
10338                         "crypto op session type not sessionless");
10339
10340         /* Process crypto operation */
10341         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10342                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10343                                 ut_params->op, 0, 0, 0, 0);
10344         else
10345                 TEST_ASSERT_NOT_NULL(process_crypto_request(
10346                         ts_params->valid_devs[0], ut_params->op),
10347                                 "failed to process sym crypto op");
10348
10349         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10350
10351         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10352                         "crypto op status not success");
10353
10354         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10355                         ut_params->op->sym->cipher.data.offset);
10356
10357         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10358
10359         /* Validate obuf */
10360         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10361                         plaintext,
10362                         tdata->plaintext.data,
10363                         tdata->plaintext.len,
10364                         "Plaintext data not as expected");
10365
10366         TEST_ASSERT_EQUAL(ut_params->op->status,
10367                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10368                         "Authentication failed");
10369         return 0;
10370 }
10371
10372 static int
10373 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
10374 {
10375         return test_authenticated_decryption_sessionless(
10376                         &gcm_test_case_5);
10377 }
10378
10379 static int
10380 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
10381 {
10382         return test_authenticated_encryption(&ccm_test_case_128_1);
10383 }
10384
10385 static int
10386 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
10387 {
10388         return test_authenticated_encryption(&ccm_test_case_128_2);
10389 }
10390
10391 static int
10392 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
10393 {
10394         return test_authenticated_encryption(&ccm_test_case_128_3);
10395 }
10396
10397 static int
10398 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
10399 {
10400         return test_authenticated_decryption(&ccm_test_case_128_1);
10401 }
10402
10403 static int
10404 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
10405 {
10406         return test_authenticated_decryption(&ccm_test_case_128_2);
10407 }
10408
10409 static int
10410 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10411 {
10412         return test_authenticated_decryption(&ccm_test_case_128_3);
10413 }
10414
10415 static int
10416 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10417 {
10418         return test_authenticated_encryption(&ccm_test_case_192_1);
10419 }
10420
10421 static int
10422 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10423 {
10424         return test_authenticated_encryption(&ccm_test_case_192_2);
10425 }
10426
10427 static int
10428 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10429 {
10430         return test_authenticated_encryption(&ccm_test_case_192_3);
10431 }
10432
10433 static int
10434 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10435 {
10436         return test_authenticated_decryption(&ccm_test_case_192_1);
10437 }
10438
10439 static int
10440 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10441 {
10442         return test_authenticated_decryption(&ccm_test_case_192_2);
10443 }
10444
10445 static int
10446 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10447 {
10448         return test_authenticated_decryption(&ccm_test_case_192_3);
10449 }
10450
10451 static int
10452 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
10453 {
10454         return test_authenticated_encryption(&ccm_test_case_256_1);
10455 }
10456
10457 static int
10458 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
10459 {
10460         return test_authenticated_encryption(&ccm_test_case_256_2);
10461 }
10462
10463 static int
10464 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
10465 {
10466         return test_authenticated_encryption(&ccm_test_case_256_3);
10467 }
10468
10469 static int
10470 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
10471 {
10472         return test_authenticated_decryption(&ccm_test_case_256_1);
10473 }
10474
10475 static int
10476 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
10477 {
10478         return test_authenticated_decryption(&ccm_test_case_256_2);
10479 }
10480
10481 static int
10482 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
10483 {
10484         return test_authenticated_decryption(&ccm_test_case_256_3);
10485 }
10486
10487 static int
10488 test_stats(void)
10489 {
10490         struct crypto_testsuite_params *ts_params = &testsuite_params;
10491         struct rte_cryptodev_stats stats;
10492
10493         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10494                 return TEST_SKIPPED;
10495
10496         /* Verify the capabilities */
10497         struct rte_cryptodev_sym_capability_idx cap_idx;
10498         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10499         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
10500         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10501                         &cap_idx) == NULL)
10502                 return TEST_SKIPPED;
10503         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10504         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10505         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10506                         &cap_idx) == NULL)
10507                 return TEST_SKIPPED;
10508
10509         if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
10510                         == -ENOTSUP)
10511                 return TEST_SKIPPED;
10512
10513         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10514         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
10515                         &stats) == -ENODEV),
10516                 "rte_cryptodev_stats_get invalid dev failed");
10517         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
10518                 "rte_cryptodev_stats_get invalid Param failed");
10519
10520         /* Test expected values */
10521         test_AES_CBC_HMAC_SHA1_encrypt_digest();
10522         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10523                         &stats),
10524                 "rte_cryptodev_stats_get failed");
10525         TEST_ASSERT((stats.enqueued_count == 1),
10526                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10527         TEST_ASSERT((stats.dequeued_count == 1),
10528                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10529         TEST_ASSERT((stats.enqueue_err_count == 0),
10530                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10531         TEST_ASSERT((stats.dequeue_err_count == 0),
10532                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10533
10534         /* invalid device but should ignore and not reset device stats*/
10535         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
10536         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10537                         &stats),
10538                 "rte_cryptodev_stats_get failed");
10539         TEST_ASSERT((stats.enqueued_count == 1),
10540                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10541
10542         /* check that a valid reset clears stats */
10543         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10544         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10545                         &stats),
10546                                           "rte_cryptodev_stats_get failed");
10547         TEST_ASSERT((stats.enqueued_count == 0),
10548                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10549         TEST_ASSERT((stats.dequeued_count == 0),
10550                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10551
10552         return TEST_SUCCESS;
10553 }
10554
10555 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
10556                                    struct crypto_unittest_params *ut_params,
10557                                    enum rte_crypto_auth_operation op,
10558                                    const struct HMAC_MD5_vector *test_case)
10559 {
10560         uint8_t key[64];
10561
10562         memcpy(key, test_case->key.data, test_case->key.len);
10563
10564         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10565         ut_params->auth_xform.next = NULL;
10566         ut_params->auth_xform.auth.op = op;
10567
10568         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
10569
10570         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
10571         ut_params->auth_xform.auth.key.length = test_case->key.len;
10572         ut_params->auth_xform.auth.key.data = key;
10573
10574         ut_params->sess = rte_cryptodev_sym_session_create(
10575                         ts_params->session_mpool);
10576
10577         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10578                         ut_params->sess, &ut_params->auth_xform,
10579                         ts_params->session_priv_mpool);
10580
10581         if (ut_params->sess == NULL)
10582                 return TEST_FAILED;
10583
10584         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10585
10586         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10587                         rte_pktmbuf_tailroom(ut_params->ibuf));
10588
10589         return 0;
10590 }
10591
10592 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
10593                               const struct HMAC_MD5_vector *test_case,
10594                               uint8_t **plaintext)
10595 {
10596         uint16_t plaintext_pad_len;
10597
10598         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10599
10600         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10601                                 16);
10602
10603         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10604                         plaintext_pad_len);
10605         memcpy(*plaintext, test_case->plaintext.data,
10606                         test_case->plaintext.len);
10607
10608         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10609                         ut_params->ibuf, MD5_DIGEST_LEN);
10610         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10611                         "no room to append digest");
10612         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10613                         ut_params->ibuf, plaintext_pad_len);
10614
10615         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10616                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
10617                            test_case->auth_tag.len);
10618         }
10619
10620         sym_op->auth.data.offset = 0;
10621         sym_op->auth.data.length = test_case->plaintext.len;
10622
10623         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10624         ut_params->op->sym->m_src = ut_params->ibuf;
10625
10626         return 0;
10627 }
10628
10629 static int
10630 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
10631 {
10632         uint16_t plaintext_pad_len;
10633         uint8_t *plaintext, *auth_tag;
10634
10635         struct crypto_testsuite_params *ts_params = &testsuite_params;
10636         struct crypto_unittest_params *ut_params = &unittest_params;
10637         struct rte_cryptodev_info dev_info;
10638
10639         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10640         uint64_t feat_flags = dev_info.feature_flags;
10641
10642         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10643                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10644                 printf("Device doesn't support RAW data-path APIs.\n");
10645                 return TEST_SKIPPED;
10646         }
10647
10648         /* Verify the capabilities */
10649         struct rte_cryptodev_sym_capability_idx cap_idx;
10650         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10651         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10652         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10653                         &cap_idx) == NULL)
10654                 return TEST_SKIPPED;
10655
10656         if (MD5_HMAC_create_session(ts_params, ut_params,
10657                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
10658                 return TEST_FAILED;
10659
10660         /* Generate Crypto op data structure */
10661         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10662                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10663         TEST_ASSERT_NOT_NULL(ut_params->op,
10664                         "Failed to allocate symmetric crypto operation struct");
10665
10666         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10667                                 16);
10668
10669         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10670                 return TEST_FAILED;
10671
10672         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10673                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10674                         ut_params->op);
10675         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10676                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10677                                 ut_params->op, 0, 1, 0, 0);
10678         else
10679                 TEST_ASSERT_NOT_NULL(
10680                         process_crypto_request(ts_params->valid_devs[0],
10681                                 ut_params->op),
10682                                 "failed to process sym crypto op");
10683
10684         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10685                         "crypto op processing failed");
10686
10687         if (ut_params->op->sym->m_dst) {
10688                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10689                                 uint8_t *, plaintext_pad_len);
10690         } else {
10691                 auth_tag = plaintext + plaintext_pad_len;
10692         }
10693
10694         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10695                         auth_tag,
10696                         test_case->auth_tag.data,
10697                         test_case->auth_tag.len,
10698                         "HMAC_MD5 generated tag not as expected");
10699
10700         return TEST_SUCCESS;
10701 }
10702
10703 static int
10704 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
10705 {
10706         uint8_t *plaintext;
10707
10708         struct crypto_testsuite_params *ts_params = &testsuite_params;
10709         struct crypto_unittest_params *ut_params = &unittest_params;
10710         struct rte_cryptodev_info dev_info;
10711
10712         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10713         uint64_t feat_flags = dev_info.feature_flags;
10714
10715         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10716                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10717                 printf("Device doesn't support RAW data-path APIs.\n");
10718                 return TEST_SKIPPED;
10719         }
10720
10721         /* Verify the capabilities */
10722         struct rte_cryptodev_sym_capability_idx cap_idx;
10723         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10724         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10725         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10726                         &cap_idx) == NULL)
10727                 return TEST_SKIPPED;
10728
10729         if (MD5_HMAC_create_session(ts_params, ut_params,
10730                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
10731                 return TEST_FAILED;
10732         }
10733
10734         /* Generate Crypto op data structure */
10735         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10736                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10737         TEST_ASSERT_NOT_NULL(ut_params->op,
10738                         "Failed to allocate symmetric crypto operation struct");
10739
10740         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10741                 return TEST_FAILED;
10742
10743         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10744                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10745                         ut_params->op);
10746         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10747                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10748                                 ut_params->op, 0, 1, 0, 0);
10749         else
10750                 TEST_ASSERT_NOT_NULL(
10751                         process_crypto_request(ts_params->valid_devs[0],
10752                                 ut_params->op),
10753                                 "failed to process sym crypto op");
10754
10755         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10756                         "HMAC_MD5 crypto op processing failed");
10757
10758         return TEST_SUCCESS;
10759 }
10760
10761 static int
10762 test_MD5_HMAC_generate_case_1(void)
10763 {
10764         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
10765 }
10766
10767 static int
10768 test_MD5_HMAC_verify_case_1(void)
10769 {
10770         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
10771 }
10772
10773 static int
10774 test_MD5_HMAC_generate_case_2(void)
10775 {
10776         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
10777 }
10778
10779 static int
10780 test_MD5_HMAC_verify_case_2(void)
10781 {
10782         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
10783 }
10784
10785 static int
10786 test_multi_session(void)
10787 {
10788         struct crypto_testsuite_params *ts_params = &testsuite_params;
10789         struct crypto_unittest_params *ut_params = &unittest_params;
10790
10791         struct rte_cryptodev_info dev_info;
10792         struct rte_cryptodev_sym_session **sessions;
10793
10794         uint16_t i;
10795
10796         /* Verify the capabilities */
10797         struct rte_cryptodev_sym_capability_idx cap_idx;
10798         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10799         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10800         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10801                         &cap_idx) == NULL)
10802                 return TEST_SKIPPED;
10803         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10804         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10805         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10806                         &cap_idx) == NULL)
10807                 return TEST_SKIPPED;
10808
10809         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
10810                         aes_cbc_key, hmac_sha512_key);
10811
10812
10813         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10814
10815         sessions = rte_malloc(NULL,
10816                         (sizeof(struct rte_cryptodev_sym_session *) *
10817                         MAX_NB_SESSIONS) + 1, 0);
10818
10819         /* Create multiple crypto sessions*/
10820         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10821
10822                 sessions[i] = rte_cryptodev_sym_session_create(
10823                                 ts_params->session_mpool);
10824
10825                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10826                                 sessions[i], &ut_params->auth_xform,
10827                                 ts_params->session_priv_mpool);
10828                 TEST_ASSERT_NOT_NULL(sessions[i],
10829                                 "Session creation failed at session number %u",
10830                                 i);
10831
10832                 /* Attempt to send a request on each session */
10833                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
10834                         sessions[i],
10835                         ut_params,
10836                         ts_params,
10837                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
10838                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
10839                         aes_cbc_iv),
10840                         "Failed to perform decrypt on request number %u.", i);
10841                 /* free crypto operation structure */
10842                 if (ut_params->op)
10843                         rte_crypto_op_free(ut_params->op);
10844
10845                 /*
10846                  * free mbuf - both obuf and ibuf are usually the same,
10847                  * so check if they point at the same address is necessary,
10848                  * to avoid freeing the mbuf twice.
10849                  */
10850                 if (ut_params->obuf) {
10851                         rte_pktmbuf_free(ut_params->obuf);
10852                         if (ut_params->ibuf == ut_params->obuf)
10853                                 ut_params->ibuf = 0;
10854                         ut_params->obuf = 0;
10855                 }
10856                 if (ut_params->ibuf) {
10857                         rte_pktmbuf_free(ut_params->ibuf);
10858                         ut_params->ibuf = 0;
10859                 }
10860         }
10861
10862         /* Next session create should fail */
10863         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10864                         sessions[i], &ut_params->auth_xform,
10865                         ts_params->session_priv_mpool);
10866         TEST_ASSERT_NULL(sessions[i],
10867                         "Session creation succeeded unexpectedly!");
10868
10869         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10870                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10871                                 sessions[i]);
10872                 rte_cryptodev_sym_session_free(sessions[i]);
10873         }
10874
10875         rte_free(sessions);
10876
10877         return TEST_SUCCESS;
10878 }
10879
10880 struct multi_session_params {
10881         struct crypto_unittest_params ut_params;
10882         uint8_t *cipher_key;
10883         uint8_t *hmac_key;
10884         const uint8_t *cipher;
10885         const uint8_t *digest;
10886         uint8_t *iv;
10887 };
10888
10889 #define MB_SESSION_NUMBER 3
10890
10891 static int
10892 test_multi_session_random_usage(void)
10893 {
10894         struct crypto_testsuite_params *ts_params = &testsuite_params;
10895         struct rte_cryptodev_info dev_info;
10896         struct rte_cryptodev_sym_session **sessions;
10897         uint32_t i, j;
10898         struct multi_session_params ut_paramz[] = {
10899
10900                 {
10901                         .cipher_key = ms_aes_cbc_key0,
10902                         .hmac_key = ms_hmac_key0,
10903                         .cipher = ms_aes_cbc_cipher0,
10904                         .digest = ms_hmac_digest0,
10905                         .iv = ms_aes_cbc_iv0
10906                 },
10907                 {
10908                         .cipher_key = ms_aes_cbc_key1,
10909                         .hmac_key = ms_hmac_key1,
10910                         .cipher = ms_aes_cbc_cipher1,
10911                         .digest = ms_hmac_digest1,
10912                         .iv = ms_aes_cbc_iv1
10913                 },
10914                 {
10915                         .cipher_key = ms_aes_cbc_key2,
10916                         .hmac_key = ms_hmac_key2,
10917                         .cipher = ms_aes_cbc_cipher2,
10918                         .digest = ms_hmac_digest2,
10919                         .iv = ms_aes_cbc_iv2
10920                 },
10921
10922         };
10923
10924         /* Verify the capabilities */
10925         struct rte_cryptodev_sym_capability_idx cap_idx;
10926         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10927         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10928         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10929                         &cap_idx) == NULL)
10930                 return TEST_SKIPPED;
10931         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10932         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10933         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10934                         &cap_idx) == NULL)
10935                 return TEST_SKIPPED;
10936
10937         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10938
10939         sessions = rte_malloc(NULL,
10940                         (sizeof(struct rte_cryptodev_sym_session *)
10941                                         * MAX_NB_SESSIONS) + 1, 0);
10942
10943         for (i = 0; i < MB_SESSION_NUMBER; i++) {
10944                 sessions[i] = rte_cryptodev_sym_session_create(
10945                                 ts_params->session_mpool);
10946
10947                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
10948                                 sizeof(struct crypto_unittest_params));
10949
10950                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
10951                                 &ut_paramz[i].ut_params,
10952                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
10953
10954                 /* Create multiple crypto sessions*/
10955                 rte_cryptodev_sym_session_init(
10956                                 ts_params->valid_devs[0],
10957                                 sessions[i],
10958                                 &ut_paramz[i].ut_params.auth_xform,
10959                                 ts_params->session_priv_mpool);
10960
10961                 TEST_ASSERT_NOT_NULL(sessions[i],
10962                                 "Session creation failed at session number %u",
10963                                 i);
10964
10965         }
10966
10967         srand(time(NULL));
10968         for (i = 0; i < 40000; i++) {
10969
10970                 j = rand() % MB_SESSION_NUMBER;
10971
10972                 TEST_ASSERT_SUCCESS(
10973                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
10974                                         sessions[j],
10975                                         &ut_paramz[j].ut_params,
10976                                         ts_params, ut_paramz[j].cipher,
10977                                         ut_paramz[j].digest,
10978                                         ut_paramz[j].iv),
10979                         "Failed to perform decrypt on request number %u.", i);
10980
10981                 if (ut_paramz[j].ut_params.op)
10982                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
10983
10984                 /*
10985                  * free mbuf - both obuf and ibuf are usually the same,
10986                  * so check if they point at the same address is necessary,
10987                  * to avoid freeing the mbuf twice.
10988                  */
10989                 if (ut_paramz[j].ut_params.obuf) {
10990                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
10991                         if (ut_paramz[j].ut_params.ibuf
10992                                         == ut_paramz[j].ut_params.obuf)
10993                                 ut_paramz[j].ut_params.ibuf = 0;
10994                         ut_paramz[j].ut_params.obuf = 0;
10995                 }
10996                 if (ut_paramz[j].ut_params.ibuf) {
10997                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
10998                         ut_paramz[j].ut_params.ibuf = 0;
10999                 }
11000         }
11001
11002         for (i = 0; i < MB_SESSION_NUMBER; i++) {
11003                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11004                                 sessions[i]);
11005                 rte_cryptodev_sym_session_free(sessions[i]);
11006         }
11007
11008         rte_free(sessions);
11009
11010         return TEST_SUCCESS;
11011 }
11012
11013 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
11014                         0xab, 0xab, 0xab, 0xab,
11015                         0xab, 0xab, 0xab, 0xab,
11016                         0xab, 0xab, 0xab, 0xab};
11017
11018 static int
11019 test_null_invalid_operation(void)
11020 {
11021         struct crypto_testsuite_params *ts_params = &testsuite_params;
11022         struct crypto_unittest_params *ut_params = &unittest_params;
11023         int ret;
11024
11025         /* This test is for NULL PMD only */
11026         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11027                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11028                 return TEST_SKIPPED;
11029
11030         /* Setup Cipher Parameters */
11031         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11032         ut_params->cipher_xform.next = NULL;
11033
11034         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
11035         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11036
11037         ut_params->sess = rte_cryptodev_sym_session_create(
11038                         ts_params->session_mpool);
11039
11040         /* Create Crypto session*/
11041         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11042                         ut_params->sess, &ut_params->cipher_xform,
11043                         ts_params->session_priv_mpool);
11044         TEST_ASSERT(ret < 0,
11045                         "Session creation succeeded unexpectedly");
11046
11047
11048         /* Setup HMAC Parameters */
11049         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11050         ut_params->auth_xform.next = NULL;
11051
11052         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
11053         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11054
11055         ut_params->sess = rte_cryptodev_sym_session_create(
11056                         ts_params->session_mpool);
11057
11058         /* Create Crypto session*/
11059         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11060                         ut_params->sess, &ut_params->auth_xform,
11061                         ts_params->session_priv_mpool);
11062         TEST_ASSERT(ret < 0,
11063                         "Session creation succeeded unexpectedly");
11064
11065         return TEST_SUCCESS;
11066 }
11067
11068
11069 #define NULL_BURST_LENGTH (32)
11070
11071 static int
11072 test_null_burst_operation(void)
11073 {
11074         struct crypto_testsuite_params *ts_params = &testsuite_params;
11075         struct crypto_unittest_params *ut_params = &unittest_params;
11076
11077         unsigned i, burst_len = NULL_BURST_LENGTH;
11078
11079         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11080         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11081
11082         /* This test is for NULL PMD only */
11083         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11084                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11085                 return TEST_SKIPPED;
11086
11087         /* Setup Cipher Parameters */
11088         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11089         ut_params->cipher_xform.next = &ut_params->auth_xform;
11090
11091         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11092         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11093
11094         /* Setup HMAC Parameters */
11095         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11096         ut_params->auth_xform.next = NULL;
11097
11098         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11099         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11100
11101         ut_params->sess = rte_cryptodev_sym_session_create(
11102                         ts_params->session_mpool);
11103
11104         /* Create Crypto session*/
11105         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11106                         ut_params->sess, &ut_params->cipher_xform,
11107                         ts_params->session_priv_mpool);
11108         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11109
11110         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11111                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11112                         burst_len, "failed to generate burst of crypto ops");
11113
11114         /* Generate an operation for each mbuf in burst */
11115         for (i = 0; i < burst_len; i++) {
11116                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11117
11118                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11119
11120                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11121                                 sizeof(unsigned));
11122                 *data = i;
11123
11124                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11125
11126                 burst[i]->sym->m_src = m;
11127         }
11128
11129         /* Process crypto operation */
11130         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11131                         0, burst, burst_len),
11132                         burst_len,
11133                         "Error enqueuing burst");
11134
11135         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11136                         0, burst_dequeued, burst_len),
11137                         burst_len,
11138                         "Error dequeuing burst");
11139
11140
11141         for (i = 0; i < burst_len; i++) {
11142                 TEST_ASSERT_EQUAL(
11143                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11144                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11145                                         uint32_t *),
11146                         "data not as expected");
11147
11148                 rte_pktmbuf_free(burst[i]->sym->m_src);
11149                 rte_crypto_op_free(burst[i]);
11150         }
11151
11152         return TEST_SUCCESS;
11153 }
11154
11155 static uint16_t
11156 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11157                   uint16_t nb_ops, void *user_param)
11158 {
11159         RTE_SET_USED(dev_id);
11160         RTE_SET_USED(qp_id);
11161         RTE_SET_USED(ops);
11162         RTE_SET_USED(user_param);
11163
11164         printf("crypto enqueue callback called\n");
11165         return nb_ops;
11166 }
11167
11168 static uint16_t
11169 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11170                   uint16_t nb_ops, void *user_param)
11171 {
11172         RTE_SET_USED(dev_id);
11173         RTE_SET_USED(qp_id);
11174         RTE_SET_USED(ops);
11175         RTE_SET_USED(user_param);
11176
11177         printf("crypto dequeue callback called\n");
11178         return nb_ops;
11179 }
11180
11181 /*
11182  * Thread using enqueue/dequeue callback with RCU.
11183  */
11184 static int
11185 test_enqdeq_callback_thread(void *arg)
11186 {
11187         RTE_SET_USED(arg);
11188         /* DP thread calls rte_cryptodev_enqueue_burst()/
11189          * rte_cryptodev_dequeue_burst() and invokes callback.
11190          */
11191         test_null_burst_operation();
11192         return 0;
11193 }
11194
11195 static int
11196 test_enq_callback_setup(void)
11197 {
11198         struct crypto_testsuite_params *ts_params = &testsuite_params;
11199         struct rte_cryptodev_info dev_info;
11200         struct rte_cryptodev_qp_conf qp_conf = {
11201                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11202         };
11203
11204         struct rte_cryptodev_cb *cb;
11205         uint16_t qp_id = 0;
11206
11207         /* Stop the device in case it's started so it can be configured */
11208         rte_cryptodev_stop(ts_params->valid_devs[0]);
11209
11210         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11211
11212         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11213                         &ts_params->conf),
11214                         "Failed to configure cryptodev %u",
11215                         ts_params->valid_devs[0]);
11216
11217         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11218         qp_conf.mp_session = ts_params->session_mpool;
11219         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11220
11221         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11222                         ts_params->valid_devs[0], qp_id, &qp_conf,
11223                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11224                         "Failed test for "
11225                         "rte_cryptodev_queue_pair_setup: num_inflights "
11226                         "%u on qp %u on cryptodev %u",
11227                         qp_conf.nb_descriptors, qp_id,
11228                         ts_params->valid_devs[0]);
11229
11230         /* Test with invalid crypto device */
11231         cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11232                         qp_id, test_enq_callback, NULL);
11233         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11234                         "cryptodev %u did not fail",
11235                         qp_id, RTE_CRYPTO_MAX_DEVS);
11236
11237         /* Test with invalid queue pair */
11238         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11239                         dev_info.max_nb_queue_pairs + 1,
11240                         test_enq_callback, NULL);
11241         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11242                         "cryptodev %u did not fail",
11243                         dev_info.max_nb_queue_pairs + 1,
11244                         ts_params->valid_devs[0]);
11245
11246         /* Test with NULL callback */
11247         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11248                         qp_id, NULL, NULL);
11249         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11250                         "cryptodev %u did not fail",
11251                         qp_id, ts_params->valid_devs[0]);
11252
11253         /* Test with valid configuration */
11254         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11255                         qp_id, test_enq_callback, NULL);
11256         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11257                         "qp %u on cryptodev %u",
11258                         qp_id, ts_params->valid_devs[0]);
11259
11260         rte_cryptodev_start(ts_params->valid_devs[0]);
11261
11262         /* Launch a thread */
11263         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11264                                 rte_get_next_lcore(-1, 1, 0));
11265
11266         /* Wait until reader exited. */
11267         rte_eal_mp_wait_lcore();
11268
11269         /* Test with invalid crypto device */
11270         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11271                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11272                         "Expected call to fail as crypto device is invalid");
11273
11274         /* Test with invalid queue pair */
11275         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11276                         ts_params->valid_devs[0],
11277                         dev_info.max_nb_queue_pairs + 1, cb),
11278                         "Expected call to fail as queue pair is invalid");
11279
11280         /* Test with NULL callback */
11281         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11282                         ts_params->valid_devs[0], qp_id, NULL),
11283                         "Expected call to fail as callback is NULL");
11284
11285         /* Test with valid configuration */
11286         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11287                         ts_params->valid_devs[0], qp_id, cb),
11288                         "Failed test to remove callback on "
11289                         "qp %u on cryptodev %u",
11290                         qp_id, ts_params->valid_devs[0]);
11291
11292         return TEST_SUCCESS;
11293 }
11294
11295 static int
11296 test_deq_callback_setup(void)
11297 {
11298         struct crypto_testsuite_params *ts_params = &testsuite_params;
11299         struct rte_cryptodev_info dev_info;
11300         struct rte_cryptodev_qp_conf qp_conf = {
11301                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11302         };
11303
11304         struct rte_cryptodev_cb *cb;
11305         uint16_t qp_id = 0;
11306
11307         /* Stop the device in case it's started so it can be configured */
11308         rte_cryptodev_stop(ts_params->valid_devs[0]);
11309
11310         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11311
11312         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11313                         &ts_params->conf),
11314                         "Failed to configure cryptodev %u",
11315                         ts_params->valid_devs[0]);
11316
11317         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11318         qp_conf.mp_session = ts_params->session_mpool;
11319         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11320
11321         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11322                         ts_params->valid_devs[0], qp_id, &qp_conf,
11323                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11324                         "Failed test for "
11325                         "rte_cryptodev_queue_pair_setup: num_inflights "
11326                         "%u on qp %u on cryptodev %u",
11327                         qp_conf.nb_descriptors, qp_id,
11328                         ts_params->valid_devs[0]);
11329
11330         /* Test with invalid crypto device */
11331         cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11332                         qp_id, test_deq_callback, NULL);
11333         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11334                         "cryptodev %u did not fail",
11335                         qp_id, RTE_CRYPTO_MAX_DEVS);
11336
11337         /* Test with invalid queue pair */
11338         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11339                         dev_info.max_nb_queue_pairs + 1,
11340                         test_deq_callback, NULL);
11341         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11342                         "cryptodev %u did not fail",
11343                         dev_info.max_nb_queue_pairs + 1,
11344                         ts_params->valid_devs[0]);
11345
11346         /* Test with NULL callback */
11347         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11348                         qp_id, NULL, NULL);
11349         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11350                         "cryptodev %u did not fail",
11351                         qp_id, ts_params->valid_devs[0]);
11352
11353         /* Test with valid configuration */
11354         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11355                         qp_id, test_deq_callback, NULL);
11356         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11357                         "qp %u on cryptodev %u",
11358                         qp_id, ts_params->valid_devs[0]);
11359
11360         rte_cryptodev_start(ts_params->valid_devs[0]);
11361
11362         /* Launch a thread */
11363         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11364                                 rte_get_next_lcore(-1, 1, 0));
11365
11366         /* Wait until reader exited. */
11367         rte_eal_mp_wait_lcore();
11368
11369         /* Test with invalid crypto device */
11370         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11371                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11372                         "Expected call to fail as crypto device is invalid");
11373
11374         /* Test with invalid queue pair */
11375         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11376                         ts_params->valid_devs[0],
11377                         dev_info.max_nb_queue_pairs + 1, cb),
11378                         "Expected call to fail as queue pair is invalid");
11379
11380         /* Test with NULL callback */
11381         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11382                         ts_params->valid_devs[0], qp_id, NULL),
11383                         "Expected call to fail as callback is NULL");
11384
11385         /* Test with valid configuration */
11386         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
11387                         ts_params->valid_devs[0], qp_id, cb),
11388                         "Failed test to remove callback on "
11389                         "qp %u on cryptodev %u",
11390                         qp_id, ts_params->valid_devs[0]);
11391
11392         return TEST_SUCCESS;
11393 }
11394
11395 static void
11396 generate_gmac_large_plaintext(uint8_t *data)
11397 {
11398         uint16_t i;
11399
11400         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
11401                 memcpy(&data[i], &data[0], 32);
11402 }
11403
11404 static int
11405 create_gmac_operation(enum rte_crypto_auth_operation op,
11406                 const struct gmac_test_data *tdata)
11407 {
11408         struct crypto_testsuite_params *ts_params = &testsuite_params;
11409         struct crypto_unittest_params *ut_params = &unittest_params;
11410         struct rte_crypto_sym_op *sym_op;
11411
11412         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11413
11414         /* Generate Crypto op data structure */
11415         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11416                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11417         TEST_ASSERT_NOT_NULL(ut_params->op,
11418                         "Failed to allocate symmetric crypto operation struct");
11419
11420         sym_op = ut_params->op->sym;
11421
11422         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11423                         ut_params->ibuf, tdata->gmac_tag.len);
11424         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11425                         "no room to append digest");
11426
11427         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11428                         ut_params->ibuf, plaintext_pad_len);
11429
11430         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11431                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11432                                 tdata->gmac_tag.len);
11433                 debug_hexdump(stdout, "digest:",
11434                                 sym_op->auth.digest.data,
11435                                 tdata->gmac_tag.len);
11436         }
11437
11438         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11439                         uint8_t *, IV_OFFSET);
11440
11441         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11442
11443         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11444
11445         sym_op->cipher.data.length = 0;
11446         sym_op->cipher.data.offset = 0;
11447
11448         sym_op->auth.data.offset = 0;
11449         sym_op->auth.data.length = tdata->plaintext.len;
11450
11451         return 0;
11452 }
11453
11454 static int
11455 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
11456                 const struct gmac_test_data *tdata,
11457                 void *digest_mem, uint64_t digest_phys)
11458 {
11459         struct crypto_testsuite_params *ts_params = &testsuite_params;
11460         struct crypto_unittest_params *ut_params = &unittest_params;
11461         struct rte_crypto_sym_op *sym_op;
11462
11463         /* Generate Crypto op data structure */
11464         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11465                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11466         TEST_ASSERT_NOT_NULL(ut_params->op,
11467                         "Failed to allocate symmetric crypto operation struct");
11468
11469         sym_op = ut_params->op->sym;
11470
11471         sym_op->auth.digest.data = digest_mem;
11472         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11473                         "no room to append digest");
11474
11475         sym_op->auth.digest.phys_addr = digest_phys;
11476
11477         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11478                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11479                                 tdata->gmac_tag.len);
11480                 debug_hexdump(stdout, "digest:",
11481                                 sym_op->auth.digest.data,
11482                                 tdata->gmac_tag.len);
11483         }
11484
11485         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11486                         uint8_t *, IV_OFFSET);
11487
11488         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11489
11490         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11491
11492         sym_op->cipher.data.length = 0;
11493         sym_op->cipher.data.offset = 0;
11494
11495         sym_op->auth.data.offset = 0;
11496         sym_op->auth.data.length = tdata->plaintext.len;
11497
11498         return 0;
11499 }
11500
11501 static int create_gmac_session(uint8_t dev_id,
11502                 const struct gmac_test_data *tdata,
11503                 enum rte_crypto_auth_operation auth_op)
11504 {
11505         uint8_t auth_key[tdata->key.len];
11506
11507         struct crypto_testsuite_params *ts_params = &testsuite_params;
11508         struct crypto_unittest_params *ut_params = &unittest_params;
11509
11510         memcpy(auth_key, tdata->key.data, tdata->key.len);
11511
11512         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11513         ut_params->auth_xform.next = NULL;
11514
11515         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
11516         ut_params->auth_xform.auth.op = auth_op;
11517         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
11518         ut_params->auth_xform.auth.key.length = tdata->key.len;
11519         ut_params->auth_xform.auth.key.data = auth_key;
11520         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11521         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
11522
11523
11524         ut_params->sess = rte_cryptodev_sym_session_create(
11525                         ts_params->session_mpool);
11526
11527         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11528                         &ut_params->auth_xform,
11529                         ts_params->session_priv_mpool);
11530
11531         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11532
11533         return 0;
11534 }
11535
11536 static int
11537 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
11538 {
11539         struct crypto_testsuite_params *ts_params = &testsuite_params;
11540         struct crypto_unittest_params *ut_params = &unittest_params;
11541         struct rte_cryptodev_info dev_info;
11542
11543         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11544         uint64_t feat_flags = dev_info.feature_flags;
11545
11546         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11547                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11548                 printf("Device doesn't support RAW data-path APIs.\n");
11549                 return TEST_SKIPPED;
11550         }
11551
11552         int retval;
11553
11554         uint8_t *auth_tag, *plaintext;
11555         uint16_t plaintext_pad_len;
11556
11557         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11558                               "No GMAC length in the source data");
11559
11560         /* Verify the capabilities */
11561         struct rte_cryptodev_sym_capability_idx cap_idx;
11562         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11563         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11564         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11565                         &cap_idx) == NULL)
11566                 return TEST_SKIPPED;
11567
11568         retval = create_gmac_session(ts_params->valid_devs[0],
11569                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11570
11571         if (retval < 0)
11572                 return retval;
11573
11574         if (tdata->plaintext.len > MBUF_SIZE)
11575                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11576         else
11577                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11578         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11579                         "Failed to allocate input buffer in mempool");
11580
11581         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11582                         rte_pktmbuf_tailroom(ut_params->ibuf));
11583
11584         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11585         /*
11586          * Runtime generate the large plain text instead of use hard code
11587          * plain text vector. It is done to avoid create huge source file
11588          * with the test vector.
11589          */
11590         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11591                 generate_gmac_large_plaintext(tdata->plaintext.data);
11592
11593         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11594                                 plaintext_pad_len);
11595         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11596
11597         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11598         debug_hexdump(stdout, "plaintext:", plaintext,
11599                         tdata->plaintext.len);
11600
11601         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
11602                         tdata);
11603
11604         if (retval < 0)
11605                 return retval;
11606
11607         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11608
11609         ut_params->op->sym->m_src = ut_params->ibuf;
11610
11611         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11612                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11613                         ut_params->op);
11614         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11615                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11616                                 ut_params->op, 0, 1, 0, 0);
11617         else
11618                 TEST_ASSERT_NOT_NULL(
11619                         process_crypto_request(ts_params->valid_devs[0],
11620                         ut_params->op), "failed to process sym crypto op");
11621
11622         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11623                         "crypto op processing failed");
11624
11625         if (ut_params->op->sym->m_dst) {
11626                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11627                                 uint8_t *, plaintext_pad_len);
11628         } else {
11629                 auth_tag = plaintext + plaintext_pad_len;
11630         }
11631
11632         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11633
11634         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11635                         auth_tag,
11636                         tdata->gmac_tag.data,
11637                         tdata->gmac_tag.len,
11638                         "GMAC Generated auth tag not as expected");
11639
11640         return 0;
11641 }
11642
11643 static int
11644 test_AES_GMAC_authentication_test_case_1(void)
11645 {
11646         return test_AES_GMAC_authentication(&gmac_test_case_1);
11647 }
11648
11649 static int
11650 test_AES_GMAC_authentication_test_case_2(void)
11651 {
11652         return test_AES_GMAC_authentication(&gmac_test_case_2);
11653 }
11654
11655 static int
11656 test_AES_GMAC_authentication_test_case_3(void)
11657 {
11658         return test_AES_GMAC_authentication(&gmac_test_case_3);
11659 }
11660
11661 static int
11662 test_AES_GMAC_authentication_test_case_4(void)
11663 {
11664         return test_AES_GMAC_authentication(&gmac_test_case_4);
11665 }
11666
11667 static int
11668 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
11669 {
11670         struct crypto_testsuite_params *ts_params = &testsuite_params;
11671         struct crypto_unittest_params *ut_params = &unittest_params;
11672         int retval;
11673         uint32_t plaintext_pad_len;
11674         uint8_t *plaintext;
11675         struct rte_cryptodev_info dev_info;
11676
11677         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11678         uint64_t feat_flags = dev_info.feature_flags;
11679
11680         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11681                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11682                 printf("Device doesn't support RAW data-path APIs.\n");
11683                 return TEST_SKIPPED;
11684         }
11685
11686         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11687                               "No GMAC length in the source data");
11688
11689         /* Verify the capabilities */
11690         struct rte_cryptodev_sym_capability_idx cap_idx;
11691         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11692         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11693         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11694                         &cap_idx) == NULL)
11695                 return TEST_SKIPPED;
11696
11697         retval = create_gmac_session(ts_params->valid_devs[0],
11698                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
11699
11700         if (retval < 0)
11701                 return retval;
11702
11703         if (tdata->plaintext.len > MBUF_SIZE)
11704                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11705         else
11706                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11707         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11708                         "Failed to allocate input buffer in mempool");
11709
11710         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11711                         rte_pktmbuf_tailroom(ut_params->ibuf));
11712
11713         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11714
11715         /*
11716          * Runtime generate the large plain text instead of use hard code
11717          * plain text vector. It is done to avoid create huge source file
11718          * with the test vector.
11719          */
11720         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11721                 generate_gmac_large_plaintext(tdata->plaintext.data);
11722
11723         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11724                                 plaintext_pad_len);
11725         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11726
11727         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11728         debug_hexdump(stdout, "plaintext:", plaintext,
11729                         tdata->plaintext.len);
11730
11731         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
11732                         tdata);
11733
11734         if (retval < 0)
11735                 return retval;
11736
11737         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11738
11739         ut_params->op->sym->m_src = ut_params->ibuf;
11740
11741         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11742                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11743                         ut_params->op);
11744         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11745                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11746                                 ut_params->op, 0, 1, 0, 0);
11747         else
11748                 TEST_ASSERT_NOT_NULL(
11749                         process_crypto_request(ts_params->valid_devs[0],
11750                         ut_params->op), "failed to process sym crypto op");
11751
11752         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11753                         "crypto op processing failed");
11754
11755         return 0;
11756
11757 }
11758
11759 static int
11760 test_AES_GMAC_authentication_verify_test_case_1(void)
11761 {
11762         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
11763 }
11764
11765 static int
11766 test_AES_GMAC_authentication_verify_test_case_2(void)
11767 {
11768         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
11769 }
11770
11771 static int
11772 test_AES_GMAC_authentication_verify_test_case_3(void)
11773 {
11774         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
11775 }
11776
11777 static int
11778 test_AES_GMAC_authentication_verify_test_case_4(void)
11779 {
11780         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
11781 }
11782
11783 static int
11784 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
11785                                 uint32_t fragsz)
11786 {
11787         struct crypto_testsuite_params *ts_params = &testsuite_params;
11788         struct crypto_unittest_params *ut_params = &unittest_params;
11789         struct rte_cryptodev_info dev_info;
11790         uint64_t feature_flags;
11791         unsigned int trn_data = 0;
11792         void *digest_mem = NULL;
11793         uint32_t segs = 1;
11794         unsigned int to_trn = 0;
11795         struct rte_mbuf *buf = NULL;
11796         uint8_t *auth_tag, *plaintext;
11797         int retval;
11798
11799         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11800                               "No GMAC length in the source data");
11801
11802         /* Verify the capabilities */
11803         struct rte_cryptodev_sym_capability_idx cap_idx;
11804         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11805         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11806         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11807                         &cap_idx) == NULL)
11808                 return TEST_SKIPPED;
11809
11810         /* Check for any input SGL support */
11811         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11812         feature_flags = dev_info.feature_flags;
11813
11814         if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
11815                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
11816                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
11817                 return TEST_SKIPPED;
11818
11819         if (fragsz > tdata->plaintext.len)
11820                 fragsz = tdata->plaintext.len;
11821
11822         uint16_t plaintext_len = fragsz;
11823
11824         retval = create_gmac_session(ts_params->valid_devs[0],
11825                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11826
11827         if (retval < 0)
11828                 return retval;
11829
11830         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11831         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11832                         "Failed to allocate input buffer in mempool");
11833
11834         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11835                         rte_pktmbuf_tailroom(ut_params->ibuf));
11836
11837         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11838                                 plaintext_len);
11839         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11840
11841         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
11842
11843         trn_data += plaintext_len;
11844
11845         buf = ut_params->ibuf;
11846
11847         /*
11848          * Loop until no more fragments
11849          */
11850
11851         while (trn_data < tdata->plaintext.len) {
11852                 ++segs;
11853                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
11854                                 (tdata->plaintext.len - trn_data) : fragsz;
11855
11856                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11857                 buf = buf->next;
11858
11859                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
11860                                 rte_pktmbuf_tailroom(buf));
11861
11862                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
11863                                 to_trn);
11864
11865                 memcpy(plaintext, tdata->plaintext.data + trn_data,
11866                                 to_trn);
11867                 trn_data += to_trn;
11868                 if (trn_data  == tdata->plaintext.len)
11869                         digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
11870                                         tdata->gmac_tag.len);
11871         }
11872         ut_params->ibuf->nb_segs = segs;
11873
11874         /*
11875          * Place digest at the end of the last buffer
11876          */
11877         uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11878
11879         if (!digest_mem) {
11880                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11881                                 + tdata->gmac_tag.len);
11882                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11883                                 tdata->plaintext.len);
11884         }
11885
11886         retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
11887                         tdata, digest_mem, digest_phys);
11888
11889         if (retval < 0)
11890                 return retval;
11891
11892         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11893
11894         ut_params->op->sym->m_src = ut_params->ibuf;
11895
11896         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11897                 return TEST_SKIPPED;
11898
11899         TEST_ASSERT_NOT_NULL(
11900                 process_crypto_request(ts_params->valid_devs[0],
11901                 ut_params->op), "failed to process sym crypto op");
11902
11903         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11904                         "crypto op processing failed");
11905
11906         auth_tag = digest_mem;
11907         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11908         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11909                         auth_tag,
11910                         tdata->gmac_tag.data,
11911                         tdata->gmac_tag.len,
11912                         "GMAC Generated auth tag not as expected");
11913
11914         return 0;
11915 }
11916
11917 /* Segment size not multiple of block size (16B) */
11918 static int
11919 test_AES_GMAC_authentication_SGL_40B(void)
11920 {
11921         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
11922 }
11923
11924 static int
11925 test_AES_GMAC_authentication_SGL_80B(void)
11926 {
11927         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
11928 }
11929
11930 static int
11931 test_AES_GMAC_authentication_SGL_2048B(void)
11932 {
11933         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
11934 }
11935
11936 /* Segment size not multiple of block size (16B) */
11937 static int
11938 test_AES_GMAC_authentication_SGL_2047B(void)
11939 {
11940         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
11941 }
11942
11943 struct test_crypto_vector {
11944         enum rte_crypto_cipher_algorithm crypto_algo;
11945         unsigned int cipher_offset;
11946         unsigned int cipher_len;
11947
11948         struct {
11949                 uint8_t data[64];
11950                 unsigned int len;
11951         } cipher_key;
11952
11953         struct {
11954                 uint8_t data[64];
11955                 unsigned int len;
11956         } iv;
11957
11958         struct {
11959                 const uint8_t *data;
11960                 unsigned int len;
11961         } plaintext;
11962
11963         struct {
11964                 const uint8_t *data;
11965                 unsigned int len;
11966         } ciphertext;
11967
11968         enum rte_crypto_auth_algorithm auth_algo;
11969         unsigned int auth_offset;
11970
11971         struct {
11972                 uint8_t data[128];
11973                 unsigned int len;
11974         } auth_key;
11975
11976         struct {
11977                 const uint8_t *data;
11978                 unsigned int len;
11979         } aad;
11980
11981         struct {
11982                 uint8_t data[128];
11983                 unsigned int len;
11984         } digest;
11985 };
11986
11987 static const struct test_crypto_vector
11988 hmac_sha1_test_crypto_vector = {
11989         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11990         .plaintext = {
11991                 .data = plaintext_hash,
11992                 .len = 512
11993         },
11994         .auth_key = {
11995                 .data = {
11996                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11997                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11998                         0xDE, 0xF4, 0xDE, 0xAD
11999                 },
12000                 .len = 20
12001         },
12002         .digest = {
12003                 .data = {
12004                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
12005                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
12006                         0x3F, 0x91, 0x64, 0x59
12007                 },
12008                 .len = 20
12009         }
12010 };
12011
12012 static const struct test_crypto_vector
12013 aes128_gmac_test_vector = {
12014         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
12015         .plaintext = {
12016                 .data = plaintext_hash,
12017                 .len = 512
12018         },
12019         .iv = {
12020                 .data = {
12021                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12022                         0x08, 0x09, 0x0A, 0x0B
12023                 },
12024                 .len = 12
12025         },
12026         .auth_key = {
12027                 .data = {
12028                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12029                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
12030                 },
12031                 .len = 16
12032         },
12033         .digest = {
12034                 .data = {
12035                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
12036                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
12037                 },
12038                 .len = 16
12039         }
12040 };
12041
12042 static const struct test_crypto_vector
12043 aes128cbc_hmac_sha1_test_vector = {
12044         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12045         .cipher_offset = 0,
12046         .cipher_len = 512,
12047         .cipher_key = {
12048                 .data = {
12049                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12050                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12051                 },
12052                 .len = 16
12053         },
12054         .iv = {
12055                 .data = {
12056                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12057                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12058                 },
12059                 .len = 16
12060         },
12061         .plaintext = {
12062                 .data = plaintext_hash,
12063                 .len = 512
12064         },
12065         .ciphertext = {
12066                 .data = ciphertext512_aes128cbc,
12067                 .len = 512
12068         },
12069         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12070         .auth_offset = 0,
12071         .auth_key = {
12072                 .data = {
12073                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12074                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12075                         0xDE, 0xF4, 0xDE, 0xAD
12076                 },
12077                 .len = 20
12078         },
12079         .digest = {
12080                 .data = {
12081                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12082                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12083                         0x18, 0x8C, 0x1D, 0x32
12084                 },
12085                 .len = 20
12086         }
12087 };
12088
12089 static const struct test_crypto_vector
12090 aes128cbc_hmac_sha1_aad_test_vector = {
12091         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12092         .cipher_offset = 8,
12093         .cipher_len = 496,
12094         .cipher_key = {
12095                 .data = {
12096                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12097                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12098                 },
12099                 .len = 16
12100         },
12101         .iv = {
12102                 .data = {
12103                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12104                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12105                 },
12106                 .len = 16
12107         },
12108         .plaintext = {
12109                 .data = plaintext_hash,
12110                 .len = 512
12111         },
12112         .ciphertext = {
12113                 .data = ciphertext512_aes128cbc_aad,
12114                 .len = 512
12115         },
12116         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12117         .auth_offset = 0,
12118         .auth_key = {
12119                 .data = {
12120                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12121                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12122                         0xDE, 0xF4, 0xDE, 0xAD
12123                 },
12124                 .len = 20
12125         },
12126         .digest = {
12127                 .data = {
12128                         0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12129                         0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12130                         0x62, 0x0F, 0xFB, 0x10
12131                 },
12132                 .len = 20
12133         }
12134 };
12135
12136 static void
12137 data_corruption(uint8_t *data)
12138 {
12139         data[0] += 1;
12140 }
12141
12142 static void
12143 tag_corruption(uint8_t *data, unsigned int tag_offset)
12144 {
12145         data[tag_offset] += 1;
12146 }
12147
12148 static int
12149 create_auth_session(struct crypto_unittest_params *ut_params,
12150                 uint8_t dev_id,
12151                 const struct test_crypto_vector *reference,
12152                 enum rte_crypto_auth_operation auth_op)
12153 {
12154         struct crypto_testsuite_params *ts_params = &testsuite_params;
12155         uint8_t auth_key[reference->auth_key.len + 1];
12156
12157         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12158
12159         /* Setup Authentication Parameters */
12160         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12161         ut_params->auth_xform.auth.op = auth_op;
12162         ut_params->auth_xform.next = NULL;
12163         ut_params->auth_xform.auth.algo = reference->auth_algo;
12164         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12165         ut_params->auth_xform.auth.key.data = auth_key;
12166         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12167
12168         /* Create Crypto session*/
12169         ut_params->sess = rte_cryptodev_sym_session_create(
12170                         ts_params->session_mpool);
12171
12172         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12173                                 &ut_params->auth_xform,
12174                                 ts_params->session_priv_mpool);
12175
12176         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12177
12178         return 0;
12179 }
12180
12181 static int
12182 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12183                 uint8_t dev_id,
12184                 const struct test_crypto_vector *reference,
12185                 enum rte_crypto_auth_operation auth_op,
12186                 enum rte_crypto_cipher_operation cipher_op)
12187 {
12188         struct crypto_testsuite_params *ts_params = &testsuite_params;
12189         uint8_t cipher_key[reference->cipher_key.len + 1];
12190         uint8_t auth_key[reference->auth_key.len + 1];
12191
12192         memcpy(cipher_key, reference->cipher_key.data,
12193                         reference->cipher_key.len);
12194         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12195
12196         /* Setup Authentication Parameters */
12197         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12198         ut_params->auth_xform.auth.op = auth_op;
12199         ut_params->auth_xform.auth.algo = reference->auth_algo;
12200         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12201         ut_params->auth_xform.auth.key.data = auth_key;
12202         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12203
12204         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12205                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12206                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
12207         } else {
12208                 ut_params->auth_xform.next = &ut_params->cipher_xform;
12209
12210                 /* Setup Cipher Parameters */
12211                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12212                 ut_params->cipher_xform.next = NULL;
12213                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12214                 ut_params->cipher_xform.cipher.op = cipher_op;
12215                 ut_params->cipher_xform.cipher.key.data = cipher_key;
12216                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12217                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12218                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12219         }
12220
12221         /* Create Crypto session*/
12222         ut_params->sess = rte_cryptodev_sym_session_create(
12223                         ts_params->session_mpool);
12224
12225         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12226                                 &ut_params->auth_xform,
12227                                 ts_params->session_priv_mpool);
12228
12229         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12230
12231         return 0;
12232 }
12233
12234 static int
12235 create_auth_operation(struct crypto_testsuite_params *ts_params,
12236                 struct crypto_unittest_params *ut_params,
12237                 const struct test_crypto_vector *reference,
12238                 unsigned int auth_generate)
12239 {
12240         /* Generate Crypto op data structure */
12241         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12242                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12243         TEST_ASSERT_NOT_NULL(ut_params->op,
12244                         "Failed to allocate pktmbuf offload");
12245
12246         /* Set crypto operation data parameters */
12247         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12248
12249         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12250
12251         /* set crypto operation source mbuf */
12252         sym_op->m_src = ut_params->ibuf;
12253
12254         /* digest */
12255         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12256                         ut_params->ibuf, reference->digest.len);
12257
12258         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12259                         "no room to append auth tag");
12260
12261         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12262                         ut_params->ibuf, reference->plaintext.len);
12263
12264         if (auth_generate)
12265                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12266         else
12267                 memcpy(sym_op->auth.digest.data,
12268                                 reference->digest.data,
12269                                 reference->digest.len);
12270
12271         debug_hexdump(stdout, "digest:",
12272                         sym_op->auth.digest.data,
12273                         reference->digest.len);
12274
12275         sym_op->auth.data.length = reference->plaintext.len;
12276         sym_op->auth.data.offset = 0;
12277
12278         return 0;
12279 }
12280
12281 static int
12282 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12283                 struct crypto_unittest_params *ut_params,
12284                 const struct test_crypto_vector *reference,
12285                 unsigned int auth_generate)
12286 {
12287         /* Generate Crypto op data structure */
12288         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12289                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12290         TEST_ASSERT_NOT_NULL(ut_params->op,
12291                         "Failed to allocate pktmbuf offload");
12292
12293         /* Set crypto operation data parameters */
12294         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12295
12296         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12297
12298         /* set crypto operation source mbuf */
12299         sym_op->m_src = ut_params->ibuf;
12300
12301         /* digest */
12302         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12303                         ut_params->ibuf, reference->digest.len);
12304
12305         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12306                         "no room to append auth tag");
12307
12308         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12309                         ut_params->ibuf, reference->ciphertext.len);
12310
12311         if (auth_generate)
12312                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12313         else
12314                 memcpy(sym_op->auth.digest.data,
12315                                 reference->digest.data,
12316                                 reference->digest.len);
12317
12318         debug_hexdump(stdout, "digest:",
12319                         sym_op->auth.digest.data,
12320                         reference->digest.len);
12321
12322         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12323                         reference->iv.data, reference->iv.len);
12324
12325         sym_op->cipher.data.length = 0;
12326         sym_op->cipher.data.offset = 0;
12327
12328         sym_op->auth.data.length = reference->plaintext.len;
12329         sym_op->auth.data.offset = 0;
12330
12331         return 0;
12332 }
12333
12334 static int
12335 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12336                 struct crypto_unittest_params *ut_params,
12337                 const struct test_crypto_vector *reference,
12338                 unsigned int auth_generate)
12339 {
12340         /* Generate Crypto op data structure */
12341         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12342                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12343         TEST_ASSERT_NOT_NULL(ut_params->op,
12344                         "Failed to allocate pktmbuf offload");
12345
12346         /* Set crypto operation data parameters */
12347         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12348
12349         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12350
12351         /* set crypto operation source mbuf */
12352         sym_op->m_src = ut_params->ibuf;
12353
12354         /* digest */
12355         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12356                         ut_params->ibuf, reference->digest.len);
12357
12358         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12359                         "no room to append auth tag");
12360
12361         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12362                         ut_params->ibuf, reference->ciphertext.len);
12363
12364         if (auth_generate)
12365                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12366         else
12367                 memcpy(sym_op->auth.digest.data,
12368                                 reference->digest.data,
12369                                 reference->digest.len);
12370
12371         debug_hexdump(stdout, "digest:",
12372                         sym_op->auth.digest.data,
12373                         reference->digest.len);
12374
12375         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12376                         reference->iv.data, reference->iv.len);
12377
12378         sym_op->cipher.data.length = reference->cipher_len;
12379         sym_op->cipher.data.offset = reference->cipher_offset;
12380
12381         sym_op->auth.data.length = reference->plaintext.len;
12382         sym_op->auth.data.offset = reference->auth_offset;
12383
12384         return 0;
12385 }
12386
12387 static int
12388 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12389                 struct crypto_unittest_params *ut_params,
12390                 const struct test_crypto_vector *reference)
12391 {
12392         return create_auth_operation(ts_params, ut_params, reference, 0);
12393 }
12394
12395 static int
12396 create_auth_verify_GMAC_operation(
12397                 struct crypto_testsuite_params *ts_params,
12398                 struct crypto_unittest_params *ut_params,
12399                 const struct test_crypto_vector *reference)
12400 {
12401         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
12402 }
12403
12404 static int
12405 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12406                 struct crypto_unittest_params *ut_params,
12407                 const struct test_crypto_vector *reference)
12408 {
12409         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12410 }
12411
12412 static int
12413 test_authentication_verify_fail_when_data_corruption(
12414                 struct crypto_testsuite_params *ts_params,
12415                 struct crypto_unittest_params *ut_params,
12416                 const struct test_crypto_vector *reference,
12417                 unsigned int data_corrupted)
12418 {
12419         int retval;
12420
12421         uint8_t *plaintext;
12422         struct rte_cryptodev_info dev_info;
12423
12424         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12425         uint64_t feat_flags = dev_info.feature_flags;
12426
12427         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12428                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12429                 printf("Device doesn't support RAW data-path APIs.\n");
12430                 return TEST_SKIPPED;
12431         }
12432
12433         /* Verify the capabilities */
12434         struct rte_cryptodev_sym_capability_idx cap_idx;
12435         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12436         cap_idx.algo.auth = reference->auth_algo;
12437         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12438                         &cap_idx) == NULL)
12439                 return TEST_SKIPPED;
12440
12441
12442         /* Create session */
12443         retval = create_auth_session(ut_params,
12444                         ts_params->valid_devs[0],
12445                         reference,
12446                         RTE_CRYPTO_AUTH_OP_VERIFY);
12447         if (retval < 0)
12448                 return retval;
12449
12450         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12451         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12452                         "Failed to allocate input buffer in mempool");
12453
12454         /* clear mbuf payload */
12455         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12456                         rte_pktmbuf_tailroom(ut_params->ibuf));
12457
12458         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12459                         reference->plaintext.len);
12460         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12461         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12462
12463         debug_hexdump(stdout, "plaintext:", plaintext,
12464                 reference->plaintext.len);
12465
12466         /* Create operation */
12467         retval = create_auth_verify_operation(ts_params, ut_params, reference);
12468
12469         if (retval < 0)
12470                 return retval;
12471
12472         if (data_corrupted)
12473                 data_corruption(plaintext);
12474         else
12475                 tag_corruption(plaintext, reference->plaintext.len);
12476
12477         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12478                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12479                         ut_params->op);
12480                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12481                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12482                         "authentication not failed");
12483         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12484                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12485                                 ut_params->op, 0, 1, 0, 0);
12486         else {
12487                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12488                         ut_params->op);
12489                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12490         }
12491
12492         return 0;
12493 }
12494
12495 static int
12496 test_authentication_verify_GMAC_fail_when_corruption(
12497                 struct crypto_testsuite_params *ts_params,
12498                 struct crypto_unittest_params *ut_params,
12499                 const struct test_crypto_vector *reference,
12500                 unsigned int data_corrupted)
12501 {
12502         int retval;
12503         uint8_t *plaintext;
12504         struct rte_cryptodev_info dev_info;
12505
12506         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12507         uint64_t feat_flags = dev_info.feature_flags;
12508
12509         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12510                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12511                 printf("Device doesn't support RAW data-path APIs.\n");
12512                 return TEST_SKIPPED;
12513         }
12514
12515         /* Verify the capabilities */
12516         struct rte_cryptodev_sym_capability_idx cap_idx;
12517         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12518         cap_idx.algo.auth = reference->auth_algo;
12519         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12520                         &cap_idx) == NULL)
12521                 return TEST_SKIPPED;
12522
12523         /* Create session */
12524         retval = create_auth_cipher_session(ut_params,
12525                         ts_params->valid_devs[0],
12526                         reference,
12527                         RTE_CRYPTO_AUTH_OP_VERIFY,
12528                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12529         if (retval < 0)
12530                 return retval;
12531
12532         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12533         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12534                         "Failed to allocate input buffer in mempool");
12535
12536         /* clear mbuf payload */
12537         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12538                         rte_pktmbuf_tailroom(ut_params->ibuf));
12539
12540         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12541                         reference->plaintext.len);
12542         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12543         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12544
12545         debug_hexdump(stdout, "plaintext:", plaintext,
12546                 reference->plaintext.len);
12547
12548         /* Create operation */
12549         retval = create_auth_verify_GMAC_operation(ts_params,
12550                         ut_params,
12551                         reference);
12552
12553         if (retval < 0)
12554                 return retval;
12555
12556         if (data_corrupted)
12557                 data_corruption(plaintext);
12558         else
12559                 tag_corruption(plaintext, reference->aad.len);
12560
12561         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12562                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12563                         ut_params->op);
12564                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12565                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12566                         "authentication not failed");
12567         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12568                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12569                                 ut_params->op, 0, 1, 0, 0);
12570         else {
12571                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12572                         ut_params->op);
12573                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12574         }
12575
12576         return 0;
12577 }
12578
12579 static int
12580 test_authenticated_decryption_fail_when_corruption(
12581                 struct crypto_testsuite_params *ts_params,
12582                 struct crypto_unittest_params *ut_params,
12583                 const struct test_crypto_vector *reference,
12584                 unsigned int data_corrupted)
12585 {
12586         int retval;
12587
12588         uint8_t *ciphertext;
12589         struct rte_cryptodev_info dev_info;
12590
12591         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12592         uint64_t feat_flags = dev_info.feature_flags;
12593
12594         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12595                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12596                 printf("Device doesn't support RAW data-path APIs.\n");
12597                 return TEST_SKIPPED;
12598         }
12599
12600         /* Verify the capabilities */
12601         struct rte_cryptodev_sym_capability_idx cap_idx;
12602         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12603         cap_idx.algo.auth = reference->auth_algo;
12604         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12605                         &cap_idx) == NULL)
12606                 return TEST_SKIPPED;
12607         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12608         cap_idx.algo.cipher = reference->crypto_algo;
12609         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12610                         &cap_idx) == NULL)
12611                 return TEST_SKIPPED;
12612
12613         /* Create session */
12614         retval = create_auth_cipher_session(ut_params,
12615                         ts_params->valid_devs[0],
12616                         reference,
12617                         RTE_CRYPTO_AUTH_OP_VERIFY,
12618                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12619         if (retval < 0)
12620                 return retval;
12621
12622         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12623         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12624                         "Failed to allocate input buffer in mempool");
12625
12626         /* clear mbuf payload */
12627         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12628                         rte_pktmbuf_tailroom(ut_params->ibuf));
12629
12630         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12631                         reference->ciphertext.len);
12632         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12633         memcpy(ciphertext, reference->ciphertext.data,
12634                         reference->ciphertext.len);
12635
12636         /* Create operation */
12637         retval = create_cipher_auth_verify_operation(ts_params,
12638                         ut_params,
12639                         reference);
12640
12641         if (retval < 0)
12642                 return retval;
12643
12644         if (data_corrupted)
12645                 data_corruption(ciphertext);
12646         else
12647                 tag_corruption(ciphertext, reference->ciphertext.len);
12648
12649         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12650                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12651                         ut_params->op);
12652                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12653                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12654                         "authentication not failed");
12655         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12656                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12657                                 ut_params->op, 1, 1, 0, 0);
12658         else {
12659                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12660                         ut_params->op);
12661                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12662         }
12663
12664         return 0;
12665 }
12666
12667 static int
12668 test_authenticated_encryt_with_esn(
12669                 struct crypto_testsuite_params *ts_params,
12670                 struct crypto_unittest_params *ut_params,
12671                 const struct test_crypto_vector *reference)
12672 {
12673         int retval;
12674
12675         uint8_t *authciphertext, *plaintext, *auth_tag;
12676         uint16_t plaintext_pad_len;
12677         uint8_t cipher_key[reference->cipher_key.len + 1];
12678         uint8_t auth_key[reference->auth_key.len + 1];
12679         struct rte_cryptodev_info dev_info;
12680
12681         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12682         uint64_t feat_flags = dev_info.feature_flags;
12683
12684         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12685                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12686                 printf("Device doesn't support RAW data-path APIs.\n");
12687                 return TEST_SKIPPED;
12688         }
12689
12690         /* Verify the capabilities */
12691         struct rte_cryptodev_sym_capability_idx cap_idx;
12692         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12693         cap_idx.algo.auth = reference->auth_algo;
12694         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12695                         &cap_idx) == NULL)
12696                 return TEST_SKIPPED;
12697         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12698         cap_idx.algo.cipher = reference->crypto_algo;
12699         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12700                         &cap_idx) == NULL)
12701                 return TEST_SKIPPED;
12702
12703         /* Create session */
12704         memcpy(cipher_key, reference->cipher_key.data,
12705                         reference->cipher_key.len);
12706         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12707
12708         /* Setup Cipher Parameters */
12709         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12710         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12711         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12712         ut_params->cipher_xform.cipher.key.data = cipher_key;
12713         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12714         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12715         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12716
12717         ut_params->cipher_xform.next = &ut_params->auth_xform;
12718
12719         /* Setup Authentication Parameters */
12720         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12721         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12722         ut_params->auth_xform.auth.algo = reference->auth_algo;
12723         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12724         ut_params->auth_xform.auth.key.data = auth_key;
12725         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12726         ut_params->auth_xform.next = NULL;
12727
12728         /* Create Crypto session*/
12729         ut_params->sess = rte_cryptodev_sym_session_create(
12730                         ts_params->session_mpool);
12731
12732         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12733                                 ut_params->sess,
12734                                 &ut_params->cipher_xform,
12735                                 ts_params->session_priv_mpool);
12736
12737         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12738
12739         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12740         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12741                         "Failed to allocate input buffer in mempool");
12742
12743         /* clear mbuf payload */
12744         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12745                         rte_pktmbuf_tailroom(ut_params->ibuf));
12746
12747         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12748                         reference->plaintext.len);
12749         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12750         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12751
12752         /* Create operation */
12753         retval = create_cipher_auth_operation(ts_params,
12754                         ut_params,
12755                         reference, 0);
12756
12757         if (retval < 0)
12758                 return retval;
12759
12760         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12761                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12762                         ut_params->op);
12763         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12764                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12765                                 ut_params->op, 1, 1, 0, 0);
12766         else
12767                 ut_params->op = process_crypto_request(
12768                         ts_params->valid_devs[0], ut_params->op);
12769
12770         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
12771
12772         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12773                         "crypto op processing failed");
12774
12775         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
12776
12777         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
12778                         ut_params->op->sym->auth.data.offset);
12779         auth_tag = authciphertext + plaintext_pad_len;
12780         debug_hexdump(stdout, "ciphertext:", authciphertext,
12781                         reference->ciphertext.len);
12782         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
12783
12784         /* Validate obuf */
12785         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12786                         authciphertext,
12787                         reference->ciphertext.data,
12788                         reference->ciphertext.len,
12789                         "Ciphertext data not as expected");
12790
12791         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12792                         auth_tag,
12793                         reference->digest.data,
12794                         reference->digest.len,
12795                         "Generated digest not as expected");
12796
12797         return TEST_SUCCESS;
12798
12799 }
12800
12801 static int
12802 test_authenticated_decrypt_with_esn(
12803                 struct crypto_testsuite_params *ts_params,
12804                 struct crypto_unittest_params *ut_params,
12805                 const struct test_crypto_vector *reference)
12806 {
12807         int retval;
12808
12809         uint8_t *ciphertext;
12810         uint8_t cipher_key[reference->cipher_key.len + 1];
12811         uint8_t auth_key[reference->auth_key.len + 1];
12812         struct rte_cryptodev_info dev_info;
12813
12814         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12815         uint64_t feat_flags = dev_info.feature_flags;
12816
12817         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12818                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12819                 printf("Device doesn't support RAW data-path APIs.\n");
12820                 return TEST_SKIPPED;
12821         }
12822
12823         /* Verify the capabilities */
12824         struct rte_cryptodev_sym_capability_idx cap_idx;
12825         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12826         cap_idx.algo.auth = reference->auth_algo;
12827         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12828                         &cap_idx) == NULL)
12829                 return TEST_SKIPPED;
12830         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12831         cap_idx.algo.cipher = reference->crypto_algo;
12832         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12833                         &cap_idx) == NULL)
12834                 return TEST_SKIPPED;
12835
12836         /* Create session */
12837         memcpy(cipher_key, reference->cipher_key.data,
12838                         reference->cipher_key.len);
12839         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12840
12841         /* Setup Authentication Parameters */
12842         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12843         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
12844         ut_params->auth_xform.auth.algo = reference->auth_algo;
12845         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12846         ut_params->auth_xform.auth.key.data = auth_key;
12847         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12848         ut_params->auth_xform.next = &ut_params->cipher_xform;
12849
12850         /* Setup Cipher Parameters */
12851         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12852         ut_params->cipher_xform.next = NULL;
12853         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12854         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
12855         ut_params->cipher_xform.cipher.key.data = cipher_key;
12856         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12857         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12858         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12859
12860         /* Create Crypto session*/
12861         ut_params->sess = rte_cryptodev_sym_session_create(
12862                         ts_params->session_mpool);
12863
12864         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12865                                 ut_params->sess,
12866                                 &ut_params->auth_xform,
12867                                 ts_params->session_priv_mpool);
12868
12869         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12870
12871         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12872         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12873                         "Failed to allocate input buffer in mempool");
12874
12875         /* clear mbuf payload */
12876         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12877                         rte_pktmbuf_tailroom(ut_params->ibuf));
12878
12879         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12880                         reference->ciphertext.len);
12881         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12882         memcpy(ciphertext, reference->ciphertext.data,
12883                         reference->ciphertext.len);
12884
12885         /* Create operation */
12886         retval = create_cipher_auth_verify_operation(ts_params,
12887                         ut_params,
12888                         reference);
12889
12890         if (retval < 0)
12891                 return retval;
12892
12893         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12894                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12895                         ut_params->op);
12896         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12897                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12898                                 ut_params->op, 1, 1, 0, 0);
12899         else
12900                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12901                         ut_params->op);
12902
12903         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
12904         TEST_ASSERT_EQUAL(ut_params->op->status,
12905                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12906                         "crypto op processing passed");
12907
12908         ut_params->obuf = ut_params->op->sym->m_src;
12909         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
12910
12911         return 0;
12912 }
12913
12914 static int
12915 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
12916                 const struct aead_test_data *tdata,
12917                 void *digest_mem, uint64_t digest_phys)
12918 {
12919         struct crypto_testsuite_params *ts_params = &testsuite_params;
12920         struct crypto_unittest_params *ut_params = &unittest_params;
12921
12922         const unsigned int auth_tag_len = tdata->auth_tag.len;
12923         const unsigned int iv_len = tdata->iv.len;
12924         unsigned int aad_len = tdata->aad.len;
12925         unsigned int aad_len_pad = 0;
12926
12927         /* Generate Crypto op data structure */
12928         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12929                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12930         TEST_ASSERT_NOT_NULL(ut_params->op,
12931                 "Failed to allocate symmetric crypto operation struct");
12932
12933         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12934
12935         sym_op->aead.digest.data = digest_mem;
12936
12937         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
12938                         "no room to append digest");
12939
12940         sym_op->aead.digest.phys_addr = digest_phys;
12941
12942         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
12943                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
12944                                 auth_tag_len);
12945                 debug_hexdump(stdout, "digest:",
12946                                 sym_op->aead.digest.data,
12947                                 auth_tag_len);
12948         }
12949
12950         /* Append aad data */
12951         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
12952                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12953                                 uint8_t *, IV_OFFSET);
12954
12955                 /* Copy IV 1 byte after the IV pointer, according to the API */
12956                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
12957
12958                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
12959
12960                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12961                                 ut_params->ibuf, aad_len);
12962                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12963                                 "no room to prepend aad");
12964                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12965                                 ut_params->ibuf);
12966
12967                 memset(sym_op->aead.aad.data, 0, aad_len);
12968                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
12969                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12970
12971                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12972                 debug_hexdump(stdout, "aad:",
12973                                 sym_op->aead.aad.data, aad_len);
12974         } else {
12975                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12976                                 uint8_t *, IV_OFFSET);
12977
12978                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
12979
12980                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
12981
12982                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12983                                 ut_params->ibuf, aad_len_pad);
12984                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12985                                 "no room to prepend aad");
12986                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12987                                 ut_params->ibuf);
12988
12989                 memset(sym_op->aead.aad.data, 0, aad_len);
12990                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12991
12992                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12993                 debug_hexdump(stdout, "aad:",
12994                                 sym_op->aead.aad.data, aad_len);
12995         }
12996
12997         sym_op->aead.data.length = tdata->plaintext.len;
12998         sym_op->aead.data.offset = aad_len_pad;
12999
13000         return 0;
13001 }
13002
13003 #define SGL_MAX_NO      16
13004
13005 static int
13006 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
13007                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
13008 {
13009         struct crypto_testsuite_params *ts_params = &testsuite_params;
13010         struct crypto_unittest_params *ut_params = &unittest_params;
13011         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
13012         int retval;
13013         int to_trn = 0;
13014         int to_trn_tbl[SGL_MAX_NO];
13015         int segs = 1;
13016         unsigned int trn_data = 0;
13017         uint8_t *plaintext, *ciphertext, *auth_tag;
13018         struct rte_cryptodev_info dev_info;
13019
13020         /* Verify the capabilities */
13021         struct rte_cryptodev_sym_capability_idx cap_idx;
13022         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13023         cap_idx.algo.aead = tdata->algo;
13024         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13025                         &cap_idx) == NULL)
13026                 return TEST_SKIPPED;
13027
13028         /* OOP not supported with CPU crypto */
13029         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13030                 return TEST_SKIPPED;
13031
13032         /* Detailed check for the particular SGL support flag */
13033         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13034         if (!oop) {
13035                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
13036                 if (sgl_in && (!(dev_info.feature_flags &
13037                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
13038                         return TEST_SKIPPED;
13039
13040                 uint64_t feat_flags = dev_info.feature_flags;
13041
13042                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13043                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13044                         printf("Device doesn't support RAW data-path APIs.\n");
13045                         return TEST_SKIPPED;
13046                 }
13047         } else {
13048                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
13049                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
13050                                 tdata->plaintext.len;
13051                 /* Raw data path API does not support OOP */
13052                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13053                         return TEST_SKIPPED;
13054                 if (sgl_in && !sgl_out) {
13055                         if (!(dev_info.feature_flags &
13056                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
13057                                 return TEST_SKIPPED;
13058                 } else if (!sgl_in && sgl_out) {
13059                         if (!(dev_info.feature_flags &
13060                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
13061                                 return TEST_SKIPPED;
13062                 } else if (sgl_in && sgl_out) {
13063                         if (!(dev_info.feature_flags &
13064                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13065                                 return TEST_SKIPPED;
13066                 }
13067         }
13068
13069         if (fragsz > tdata->plaintext.len)
13070                 fragsz = tdata->plaintext.len;
13071
13072         uint16_t plaintext_len = fragsz;
13073         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13074
13075         if (fragsz_oop > tdata->plaintext.len)
13076                 frag_size_oop = tdata->plaintext.len;
13077
13078         int ecx = 0;
13079         void *digest_mem = NULL;
13080
13081         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13082
13083         if (tdata->plaintext.len % fragsz != 0) {
13084                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13085                         return 1;
13086         }       else {
13087                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13088                         return 1;
13089         }
13090
13091         /*
13092          * For out-op-place we need to alloc another mbuf
13093          */
13094         if (oop) {
13095                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13096                 rte_pktmbuf_append(ut_params->obuf,
13097                                 frag_size_oop + prepend_len);
13098                 buf_oop = ut_params->obuf;
13099         }
13100
13101         /* Create AEAD session */
13102         retval = create_aead_session(ts_params->valid_devs[0],
13103                         tdata->algo,
13104                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
13105                         tdata->key.data, tdata->key.len,
13106                         tdata->aad.len, tdata->auth_tag.len,
13107                         tdata->iv.len);
13108         if (retval < 0)
13109                 return retval;
13110
13111         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13112
13113         /* clear mbuf payload */
13114         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13115                         rte_pktmbuf_tailroom(ut_params->ibuf));
13116
13117         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13118                         plaintext_len);
13119
13120         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13121
13122         trn_data += plaintext_len;
13123
13124         buf = ut_params->ibuf;
13125
13126         /*
13127          * Loop until no more fragments
13128          */
13129
13130         while (trn_data < tdata->plaintext.len) {
13131                 ++segs;
13132                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13133                                 (tdata->plaintext.len - trn_data) : fragsz;
13134
13135                 to_trn_tbl[ecx++] = to_trn;
13136
13137                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13138                 buf = buf->next;
13139
13140                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13141                                 rte_pktmbuf_tailroom(buf));
13142
13143                 /* OOP */
13144                 if (oop && !fragsz_oop) {
13145                         buf_last_oop = buf_oop->next =
13146                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13147                         buf_oop = buf_oop->next;
13148                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13149                                         0, rte_pktmbuf_tailroom(buf_oop));
13150                         rte_pktmbuf_append(buf_oop, to_trn);
13151                 }
13152
13153                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13154                                 to_trn);
13155
13156                 memcpy(plaintext, tdata->plaintext.data + trn_data,
13157                                 to_trn);
13158                 trn_data += to_trn;
13159                 if (trn_data  == tdata->plaintext.len) {
13160                         if (oop) {
13161                                 if (!fragsz_oop)
13162                                         digest_mem = rte_pktmbuf_append(buf_oop,
13163                                                 tdata->auth_tag.len);
13164                         } else
13165                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13166                                         tdata->auth_tag.len);
13167                 }
13168         }
13169
13170         uint64_t digest_phys = 0;
13171
13172         ut_params->ibuf->nb_segs = segs;
13173
13174         segs = 1;
13175         if (fragsz_oop && oop) {
13176                 to_trn = 0;
13177                 ecx = 0;
13178
13179                 if (frag_size_oop == tdata->plaintext.len) {
13180                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
13181                                 tdata->auth_tag.len);
13182
13183                         digest_phys = rte_pktmbuf_iova_offset(
13184                                         ut_params->obuf,
13185                                         tdata->plaintext.len + prepend_len);
13186                 }
13187
13188                 trn_data = frag_size_oop;
13189                 while (trn_data < tdata->plaintext.len) {
13190                         ++segs;
13191                         to_trn =
13192                                 (tdata->plaintext.len - trn_data <
13193                                                 frag_size_oop) ?
13194                                 (tdata->plaintext.len - trn_data) :
13195                                                 frag_size_oop;
13196
13197                         to_trn_tbl[ecx++] = to_trn;
13198
13199                         buf_last_oop = buf_oop->next =
13200                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13201                         buf_oop = buf_oop->next;
13202                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13203                                         0, rte_pktmbuf_tailroom(buf_oop));
13204                         rte_pktmbuf_append(buf_oop, to_trn);
13205
13206                         trn_data += to_trn;
13207
13208                         if (trn_data  == tdata->plaintext.len) {
13209                                 digest_mem = rte_pktmbuf_append(buf_oop,
13210                                         tdata->auth_tag.len);
13211                         }
13212                 }
13213
13214                 ut_params->obuf->nb_segs = segs;
13215         }
13216
13217         /*
13218          * Place digest at the end of the last buffer
13219          */
13220         if (!digest_phys)
13221                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13222         if (oop && buf_last_oop)
13223                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13224
13225         if (!digest_mem && !oop) {
13226                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13227                                 + tdata->auth_tag.len);
13228                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13229                                 tdata->plaintext.len);
13230         }
13231
13232         /* Create AEAD operation */
13233         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13234                         tdata, digest_mem, digest_phys);
13235
13236         if (retval < 0)
13237                 return retval;
13238
13239         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13240
13241         ut_params->op->sym->m_src = ut_params->ibuf;
13242         if (oop)
13243                 ut_params->op->sym->m_dst = ut_params->obuf;
13244
13245         /* Process crypto operation */
13246         if (oop == IN_PLACE &&
13247                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13248                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13249         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13250                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13251                                 ut_params->op, 0, 0, 0, 0);
13252         else
13253                 TEST_ASSERT_NOT_NULL(
13254                         process_crypto_request(ts_params->valid_devs[0],
13255                         ut_params->op), "failed to process sym crypto op");
13256
13257         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13258                         "crypto op processing failed");
13259
13260
13261         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13262                         uint8_t *, prepend_len);
13263         if (oop) {
13264                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13265                                 uint8_t *, prepend_len);
13266         }
13267
13268         if (fragsz_oop)
13269                 fragsz = fragsz_oop;
13270
13271         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13272                         ciphertext,
13273                         tdata->ciphertext.data,
13274                         fragsz,
13275                         "Ciphertext data not as expected");
13276
13277         buf = ut_params->op->sym->m_src->next;
13278         if (oop)
13279                 buf = ut_params->op->sym->m_dst->next;
13280
13281         unsigned int off = fragsz;
13282
13283         ecx = 0;
13284         while (buf) {
13285                 ciphertext = rte_pktmbuf_mtod(buf,
13286                                 uint8_t *);
13287
13288                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
13289                                 ciphertext,
13290                                 tdata->ciphertext.data + off,
13291                                 to_trn_tbl[ecx],
13292                                 "Ciphertext data not as expected");
13293
13294                 off += to_trn_tbl[ecx++];
13295                 buf = buf->next;
13296         }
13297
13298         auth_tag = digest_mem;
13299         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13300                         auth_tag,
13301                         tdata->auth_tag.data,
13302                         tdata->auth_tag.len,
13303                         "Generated auth tag not as expected");
13304
13305         return 0;
13306 }
13307
13308 static int
13309 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13310 {
13311         return test_authenticated_encryption_SGL(
13312                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13313 }
13314
13315 static int
13316 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13317 {
13318         return test_authenticated_encryption_SGL(
13319                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13320 }
13321
13322 static int
13323 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13324 {
13325         return test_authenticated_encryption_SGL(
13326                         &gcm_test_case_8, OUT_OF_PLACE, 400,
13327                         gcm_test_case_8.plaintext.len);
13328 }
13329
13330 static int
13331 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13332 {
13333         /* This test is not for OPENSSL PMD */
13334         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13335                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13336                 return TEST_SKIPPED;
13337
13338         return test_authenticated_encryption_SGL(
13339                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13340 }
13341
13342 static int
13343 test_authentication_verify_fail_when_data_corrupted(
13344                 struct crypto_testsuite_params *ts_params,
13345                 struct crypto_unittest_params *ut_params,
13346                 const struct test_crypto_vector *reference)
13347 {
13348         return test_authentication_verify_fail_when_data_corruption(
13349                         ts_params, ut_params, reference, 1);
13350 }
13351
13352 static int
13353 test_authentication_verify_fail_when_tag_corrupted(
13354                 struct crypto_testsuite_params *ts_params,
13355                 struct crypto_unittest_params *ut_params,
13356                 const struct test_crypto_vector *reference)
13357 {
13358         return test_authentication_verify_fail_when_data_corruption(
13359                         ts_params, ut_params, reference, 0);
13360 }
13361
13362 static int
13363 test_authentication_verify_GMAC_fail_when_data_corrupted(
13364                 struct crypto_testsuite_params *ts_params,
13365                 struct crypto_unittest_params *ut_params,
13366                 const struct test_crypto_vector *reference)
13367 {
13368         return test_authentication_verify_GMAC_fail_when_corruption(
13369                         ts_params, ut_params, reference, 1);
13370 }
13371
13372 static int
13373 test_authentication_verify_GMAC_fail_when_tag_corrupted(
13374                 struct crypto_testsuite_params *ts_params,
13375                 struct crypto_unittest_params *ut_params,
13376                 const struct test_crypto_vector *reference)
13377 {
13378         return test_authentication_verify_GMAC_fail_when_corruption(
13379                         ts_params, ut_params, reference, 0);
13380 }
13381
13382 static int
13383 test_authenticated_decryption_fail_when_data_corrupted(
13384                 struct crypto_testsuite_params *ts_params,
13385                 struct crypto_unittest_params *ut_params,
13386                 const struct test_crypto_vector *reference)
13387 {
13388         return test_authenticated_decryption_fail_when_corruption(
13389                         ts_params, ut_params, reference, 1);
13390 }
13391
13392 static int
13393 test_authenticated_decryption_fail_when_tag_corrupted(
13394                 struct crypto_testsuite_params *ts_params,
13395                 struct crypto_unittest_params *ut_params,
13396                 const struct test_crypto_vector *reference)
13397 {
13398         return test_authenticated_decryption_fail_when_corruption(
13399                         ts_params, ut_params, reference, 0);
13400 }
13401
13402 static int
13403 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
13404 {
13405         return test_authentication_verify_fail_when_data_corrupted(
13406                         &testsuite_params, &unittest_params,
13407                         &hmac_sha1_test_crypto_vector);
13408 }
13409
13410 static int
13411 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13412 {
13413         return test_authentication_verify_fail_when_tag_corrupted(
13414                         &testsuite_params, &unittest_params,
13415                         &hmac_sha1_test_crypto_vector);
13416 }
13417
13418 static int
13419 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
13420 {
13421         return test_authentication_verify_GMAC_fail_when_data_corrupted(
13422                         &testsuite_params, &unittest_params,
13423                         &aes128_gmac_test_vector);
13424 }
13425
13426 static int
13427 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
13428 {
13429         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
13430                         &testsuite_params, &unittest_params,
13431                         &aes128_gmac_test_vector);
13432 }
13433
13434 static int
13435 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
13436 {
13437         return test_authenticated_decryption_fail_when_data_corrupted(
13438                         &testsuite_params,
13439                         &unittest_params,
13440                         &aes128cbc_hmac_sha1_test_vector);
13441 }
13442
13443 static int
13444 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
13445 {
13446         return test_authenticated_decryption_fail_when_tag_corrupted(
13447                         &testsuite_params,
13448                         &unittest_params,
13449                         &aes128cbc_hmac_sha1_test_vector);
13450 }
13451
13452 static int
13453 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13454 {
13455         return test_authenticated_encryt_with_esn(
13456                         &testsuite_params,
13457                         &unittest_params,
13458                         &aes128cbc_hmac_sha1_aad_test_vector);
13459 }
13460
13461 static int
13462 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13463 {
13464         return test_authenticated_decrypt_with_esn(
13465                         &testsuite_params,
13466                         &unittest_params,
13467                         &aes128cbc_hmac_sha1_aad_test_vector);
13468 }
13469
13470 static int
13471 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
13472 {
13473         return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
13474 }
13475
13476 static int
13477 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
13478 {
13479         return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
13480 }
13481
13482 #ifdef RTE_CRYPTO_SCHEDULER
13483
13484 /* global AESNI worker IDs for the scheduler test */
13485 uint8_t aesni_ids[2];
13486
13487 static int
13488 scheduler_testsuite_setup(void)
13489 {
13490         uint32_t i = 0;
13491         int32_t nb_devs, ret;
13492         char vdev_args[VDEV_ARGS_SIZE] = {""};
13493         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
13494                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
13495         uint16_t worker_core_count = 0;
13496         uint16_t socket_id = 0;
13497
13498         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13499                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
13500
13501                 /* Identify the Worker Cores
13502                  * Use 2 worker cores for the device args
13503                  */
13504                 RTE_LCORE_FOREACH_WORKER(i) {
13505                         if (worker_core_count > 1)
13506                                 break;
13507                         snprintf(vdev_args, sizeof(vdev_args),
13508                                         "%s%d", temp_str, i);
13509                         strcpy(temp_str, vdev_args);
13510                         strlcat(temp_str, ";", sizeof(temp_str));
13511                         worker_core_count++;
13512                         socket_id = rte_lcore_to_socket_id(i);
13513                 }
13514                 if (worker_core_count != 2) {
13515                         RTE_LOG(ERR, USER1,
13516                                 "Cryptodev scheduler test require at least "
13517                                 "two worker cores to run. "
13518                                 "Please use the correct coremask.\n");
13519                         return TEST_FAILED;
13520                 }
13521                 strcpy(temp_str, vdev_args);
13522                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
13523                                 temp_str, socket_id);
13524                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
13525                 nb_devs = rte_cryptodev_device_count_by_driver(
13526                                 rte_cryptodev_driver_id_get(
13527                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
13528                 if (nb_devs < 1) {
13529                         ret = rte_vdev_init(
13530                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
13531                                         vdev_args);
13532                         TEST_ASSERT(ret == 0,
13533                                 "Failed to create instance %u of pmd : %s",
13534                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13535                 }
13536         }
13537         return testsuite_setup();
13538 }
13539
13540 static int
13541 test_scheduler_attach_slave_op(void)
13542 {
13543         struct crypto_testsuite_params *ts_params = &testsuite_params;
13544         uint8_t sched_id = ts_params->valid_devs[0];
13545         uint32_t nb_devs, i, nb_devs_attached = 0;
13546         int ret;
13547         char vdev_name[32];
13548
13549         /* create 2 AESNI_MB if necessary */
13550         nb_devs = rte_cryptodev_device_count_by_driver(
13551                         rte_cryptodev_driver_id_get(
13552                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
13553         if (nb_devs < 2) {
13554                 for (i = nb_devs; i < 2; i++) {
13555                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
13556                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
13557                                         i);
13558                         ret = rte_vdev_init(vdev_name, NULL);
13559
13560                         TEST_ASSERT(ret == 0,
13561                                 "Failed to create instance %u of"
13562                                 " pmd : %s",
13563                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13564                 }
13565         }
13566
13567         /* attach 2 AESNI_MB cdevs */
13568         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
13569                         i++) {
13570                 struct rte_cryptodev_info info;
13571                 unsigned int session_size;
13572
13573                 rte_cryptodev_info_get(i, &info);
13574                 if (info.driver_id != rte_cryptodev_driver_id_get(
13575                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
13576                         continue;
13577
13578                 session_size = rte_cryptodev_sym_get_private_session_size(i);
13579                 /*
13580                  * Create the session mempool again, since now there are new devices
13581                  * to use the mempool.
13582                  */
13583                 if (ts_params->session_mpool) {
13584                         rte_mempool_free(ts_params->session_mpool);
13585                         ts_params->session_mpool = NULL;
13586                 }
13587                 if (ts_params->session_priv_mpool) {
13588                         rte_mempool_free(ts_params->session_priv_mpool);
13589                         ts_params->session_priv_mpool = NULL;
13590                 }
13591
13592                 if (info.sym.max_nb_sessions != 0 &&
13593                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
13594                         RTE_LOG(ERR, USER1,
13595                                         "Device does not support "
13596                                         "at least %u sessions\n",
13597                                         MAX_NB_SESSIONS);
13598                         return TEST_FAILED;
13599                 }
13600                 /*
13601                  * Create mempool with maximum number of sessions,
13602                  * to include the session headers
13603                  */
13604                 if (ts_params->session_mpool == NULL) {
13605                         ts_params->session_mpool =
13606                                 rte_cryptodev_sym_session_pool_create(
13607                                                 "test_sess_mp",
13608                                                 MAX_NB_SESSIONS, 0, 0, 0,
13609                                                 SOCKET_ID_ANY);
13610                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
13611                                         "session mempool allocation failed");
13612                 }
13613
13614                 /*
13615                  * Create mempool with maximum number of sessions,
13616                  * to include device specific session private data
13617                  */
13618                 if (ts_params->session_priv_mpool == NULL) {
13619                         ts_params->session_priv_mpool = rte_mempool_create(
13620                                         "test_sess_mp_priv",
13621                                         MAX_NB_SESSIONS,
13622                                         session_size,
13623                                         0, 0, NULL, NULL, NULL,
13624                                         NULL, SOCKET_ID_ANY,
13625                                         0);
13626
13627                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
13628                                         "session mempool allocation failed");
13629                 }
13630
13631                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
13632                 ts_params->qp_conf.mp_session_private =
13633                                 ts_params->session_priv_mpool;
13634
13635                 ret = rte_cryptodev_scheduler_worker_attach(sched_id,
13636                                 (uint8_t)i);
13637
13638                 TEST_ASSERT(ret == 0,
13639                         "Failed to attach device %u of pmd : %s", i,
13640                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13641
13642                 aesni_ids[nb_devs_attached] = (uint8_t)i;
13643
13644                 nb_devs_attached++;
13645         }
13646
13647         return 0;
13648 }
13649
13650 static int
13651 test_scheduler_detach_slave_op(void)
13652 {
13653         struct crypto_testsuite_params *ts_params = &testsuite_params;
13654         uint8_t sched_id = ts_params->valid_devs[0];
13655         uint32_t i;
13656         int ret;
13657
13658         for (i = 0; i < 2; i++) {
13659                 ret = rte_cryptodev_scheduler_worker_detach(sched_id,
13660                                 aesni_ids[i]);
13661                 TEST_ASSERT(ret == 0,
13662                         "Failed to detach device %u", aesni_ids[i]);
13663         }
13664
13665         return 0;
13666 }
13667
13668 static int
13669 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
13670 {
13671         struct crypto_testsuite_params *ts_params = &testsuite_params;
13672         uint8_t sched_id = ts_params->valid_devs[0];
13673         /* set mode */
13674         return rte_cryptodev_scheduler_mode_set(sched_id,
13675                 scheduler_mode);
13676 }
13677
13678 static int
13679 test_scheduler_mode_roundrobin_op(void)
13680 {
13681         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
13682                         0, "Failed to set roundrobin mode");
13683         return 0;
13684
13685 }
13686
13687 static int
13688 test_scheduler_mode_multicore_op(void)
13689 {
13690         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
13691                         0, "Failed to set multicore mode");
13692
13693         return 0;
13694 }
13695
13696 static int
13697 test_scheduler_mode_failover_op(void)
13698 {
13699         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
13700                         0, "Failed to set failover mode");
13701
13702         return 0;
13703 }
13704
13705 static int
13706 test_scheduler_mode_pkt_size_distr_op(void)
13707 {
13708         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
13709                         0, "Failed to set pktsize mode");
13710
13711         return 0;
13712 }
13713
13714 static int
13715 scheduler_multicore_testsuite_setup(void)
13716 {
13717         if (test_scheduler_attach_slave_op() < 0)
13718                 return TEST_SKIPPED;
13719         if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
13720                 return TEST_SKIPPED;
13721         return 0;
13722 }
13723
13724 static int
13725 scheduler_roundrobin_testsuite_setup(void)
13726 {
13727         if (test_scheduler_attach_slave_op() < 0)
13728                 return TEST_SKIPPED;
13729         if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
13730                 return TEST_SKIPPED;
13731         return 0;
13732 }
13733
13734 static int
13735 scheduler_failover_testsuite_setup(void)
13736 {
13737         if (test_scheduler_attach_slave_op() < 0)
13738                 return TEST_SKIPPED;
13739         if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
13740                 return TEST_SKIPPED;
13741         return 0;
13742 }
13743
13744 static int
13745 scheduler_pkt_size_distr_testsuite_setup(void)
13746 {
13747         if (test_scheduler_attach_slave_op() < 0)
13748                 return TEST_SKIPPED;
13749         if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
13750                 return TEST_SKIPPED;
13751         return 0;
13752 }
13753
13754 static void
13755 scheduler_mode_testsuite_teardown(void)
13756 {
13757         test_scheduler_detach_slave_op();
13758 }
13759
13760 #endif /* RTE_CRYPTO_SCHEDULER */
13761
13762 static struct unit_test_suite end_testsuite = {
13763         .suite_name = NULL,
13764         .setup = NULL,
13765         .teardown = NULL,
13766         .unit_test_suites = NULL
13767 };
13768
13769 #ifdef RTE_LIB_SECURITY
13770 static struct unit_test_suite pdcp_proto_testsuite  = {
13771         .suite_name = "PDCP Proto Unit Test Suite",
13772         .setup = pdcp_proto_testsuite_setup,
13773         .unit_test_cases = {
13774                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13775                         test_PDCP_PROTO_all),
13776                 TEST_CASES_END() /**< NULL terminate unit test array */
13777         }
13778 };
13779
13780 static struct unit_test_suite docsis_proto_testsuite  = {
13781         .suite_name = "Docsis Proto Unit Test Suite",
13782         .setup = docsis_proto_testsuite_setup,
13783         .unit_test_cases = {
13784                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13785                         test_DOCSIS_PROTO_all),
13786                 TEST_CASES_END() /**< NULL terminate unit test array */
13787         }
13788 };
13789 #endif
13790
13791 static struct unit_test_suite cryptodev_gen_testsuite  = {
13792         .suite_name = "Crypto General Unit Test Suite",
13793         .setup = crypto_gen_testsuite_setup,
13794         .unit_test_cases = {
13795                 TEST_CASE_ST(ut_setup, ut_teardown,
13796                                 test_device_configure_invalid_dev_id),
13797                 TEST_CASE_ST(ut_setup, ut_teardown,
13798                                 test_queue_pair_descriptor_setup),
13799                 TEST_CASE_ST(ut_setup, ut_teardown,
13800                                 test_device_configure_invalid_queue_pair_ids),
13801                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13802                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13803                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13804                 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13805                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all),
13806                 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all),
13807                 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all),
13808                 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13809                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
13810                 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
13811                 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
13812                 TEST_CASES_END() /**< NULL terminate unit test array */
13813         }
13814 };
13815
13816 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
13817         .suite_name = "Negative HMAC SHA1 Unit Test Suite",
13818         .setup = negative_hmac_sha1_testsuite_setup,
13819         .unit_test_cases = {
13820                 /** Negative tests */
13821                 TEST_CASE_ST(ut_setup, ut_teardown,
13822                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13823                 TEST_CASE_ST(ut_setup, ut_teardown,
13824                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13825                 TEST_CASE_ST(ut_setup, ut_teardown,
13826                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13827                 TEST_CASE_ST(ut_setup, ut_teardown,
13828                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13829
13830                 TEST_CASES_END() /**< NULL terminate unit test array */
13831         }
13832 };
13833
13834 static struct unit_test_suite cryptodev_multi_session_testsuite = {
13835         .suite_name = "Multi Session Unit Test Suite",
13836         .setup = multi_session_testsuite_setup,
13837         .unit_test_cases = {
13838                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13839                 TEST_CASE_ST(ut_setup, ut_teardown,
13840                                 test_multi_session_random_usage),
13841
13842                 TEST_CASES_END() /**< NULL terminate unit test array */
13843         }
13844 };
13845
13846 static struct unit_test_suite cryptodev_null_testsuite  = {
13847         .suite_name = "NULL Test Suite",
13848         .setup = null_testsuite_setup,
13849         .unit_test_cases = {
13850                 TEST_CASE_ST(ut_setup, ut_teardown,
13851                         test_null_invalid_operation),
13852                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
13853                 TEST_CASES_END()
13854         }
13855 };
13856
13857 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
13858         .suite_name = "AES CCM Authenticated Test Suite",
13859         .setup = aes_ccm_auth_testsuite_setup,
13860         .unit_test_cases = {
13861                 /** AES CCM Authenticated Encryption 128 bits key*/
13862                 TEST_CASE_ST(ut_setup, ut_teardown,
13863                         test_AES_CCM_authenticated_encryption_test_case_128_1),
13864                 TEST_CASE_ST(ut_setup, ut_teardown,
13865                         test_AES_CCM_authenticated_encryption_test_case_128_2),
13866                 TEST_CASE_ST(ut_setup, ut_teardown,
13867                         test_AES_CCM_authenticated_encryption_test_case_128_3),
13868
13869                 /** AES CCM Authenticated Decryption 128 bits key*/
13870                 TEST_CASE_ST(ut_setup, ut_teardown,
13871                         test_AES_CCM_authenticated_decryption_test_case_128_1),
13872                 TEST_CASE_ST(ut_setup, ut_teardown,
13873                         test_AES_CCM_authenticated_decryption_test_case_128_2),
13874                 TEST_CASE_ST(ut_setup, ut_teardown,
13875                         test_AES_CCM_authenticated_decryption_test_case_128_3),
13876
13877                 /** AES CCM Authenticated Encryption 192 bits key */
13878                 TEST_CASE_ST(ut_setup, ut_teardown,
13879                         test_AES_CCM_authenticated_encryption_test_case_192_1),
13880                 TEST_CASE_ST(ut_setup, ut_teardown,
13881                         test_AES_CCM_authenticated_encryption_test_case_192_2),
13882                 TEST_CASE_ST(ut_setup, ut_teardown,
13883                         test_AES_CCM_authenticated_encryption_test_case_192_3),
13884
13885                 /** AES CCM Authenticated Decryption 192 bits key*/
13886                 TEST_CASE_ST(ut_setup, ut_teardown,
13887                         test_AES_CCM_authenticated_decryption_test_case_192_1),
13888                 TEST_CASE_ST(ut_setup, ut_teardown,
13889                         test_AES_CCM_authenticated_decryption_test_case_192_2),
13890                 TEST_CASE_ST(ut_setup, ut_teardown,
13891                         test_AES_CCM_authenticated_decryption_test_case_192_3),
13892
13893                 /** AES CCM Authenticated Encryption 256 bits key */
13894                 TEST_CASE_ST(ut_setup, ut_teardown,
13895                         test_AES_CCM_authenticated_encryption_test_case_256_1),
13896                 TEST_CASE_ST(ut_setup, ut_teardown,
13897                         test_AES_CCM_authenticated_encryption_test_case_256_2),
13898                 TEST_CASE_ST(ut_setup, ut_teardown,
13899                         test_AES_CCM_authenticated_encryption_test_case_256_3),
13900
13901                 /** AES CCM Authenticated Decryption 256 bits key*/
13902                 TEST_CASE_ST(ut_setup, ut_teardown,
13903                         test_AES_CCM_authenticated_decryption_test_case_256_1),
13904                 TEST_CASE_ST(ut_setup, ut_teardown,
13905                         test_AES_CCM_authenticated_decryption_test_case_256_2),
13906                 TEST_CASE_ST(ut_setup, ut_teardown,
13907                         test_AES_CCM_authenticated_decryption_test_case_256_3),
13908                 TEST_CASES_END()
13909         }
13910 };
13911
13912 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
13913         .suite_name = "AES GCM Authenticated Test Suite",
13914         .setup = aes_gcm_auth_testsuite_setup,
13915         .unit_test_cases = {
13916                 /** AES GCM Authenticated Encryption */
13917                 TEST_CASE_ST(ut_setup, ut_teardown,
13918                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
13919                 TEST_CASE_ST(ut_setup, ut_teardown,
13920                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
13921                 TEST_CASE_ST(ut_setup, ut_teardown,
13922                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
13923                 TEST_CASE_ST(ut_setup, ut_teardown,
13924                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
13925                 TEST_CASE_ST(ut_setup, ut_teardown,
13926                         test_AES_GCM_authenticated_encryption_test_case_1),
13927                 TEST_CASE_ST(ut_setup, ut_teardown,
13928                         test_AES_GCM_authenticated_encryption_test_case_2),
13929                 TEST_CASE_ST(ut_setup, ut_teardown,
13930                         test_AES_GCM_authenticated_encryption_test_case_3),
13931                 TEST_CASE_ST(ut_setup, ut_teardown,
13932                         test_AES_GCM_authenticated_encryption_test_case_4),
13933                 TEST_CASE_ST(ut_setup, ut_teardown,
13934                         test_AES_GCM_authenticated_encryption_test_case_5),
13935                 TEST_CASE_ST(ut_setup, ut_teardown,
13936                         test_AES_GCM_authenticated_encryption_test_case_6),
13937                 TEST_CASE_ST(ut_setup, ut_teardown,
13938                         test_AES_GCM_authenticated_encryption_test_case_7),
13939                 TEST_CASE_ST(ut_setup, ut_teardown,
13940                         test_AES_GCM_authenticated_encryption_test_case_8),
13941                 TEST_CASE_ST(ut_setup, ut_teardown,
13942                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
13943
13944                 /** AES GCM Authenticated Decryption */
13945                 TEST_CASE_ST(ut_setup, ut_teardown,
13946                         test_AES_GCM_authenticated_decryption_test_case_1),
13947                 TEST_CASE_ST(ut_setup, ut_teardown,
13948                         test_AES_GCM_authenticated_decryption_test_case_2),
13949                 TEST_CASE_ST(ut_setup, ut_teardown,
13950                         test_AES_GCM_authenticated_decryption_test_case_3),
13951                 TEST_CASE_ST(ut_setup, ut_teardown,
13952                         test_AES_GCM_authenticated_decryption_test_case_4),
13953                 TEST_CASE_ST(ut_setup, ut_teardown,
13954                         test_AES_GCM_authenticated_decryption_test_case_5),
13955                 TEST_CASE_ST(ut_setup, ut_teardown,
13956                         test_AES_GCM_authenticated_decryption_test_case_6),
13957                 TEST_CASE_ST(ut_setup, ut_teardown,
13958                         test_AES_GCM_authenticated_decryption_test_case_7),
13959                 TEST_CASE_ST(ut_setup, ut_teardown,
13960                         test_AES_GCM_authenticated_decryption_test_case_8),
13961                 TEST_CASE_ST(ut_setup, ut_teardown,
13962                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
13963
13964                 /** AES GCM Authenticated Encryption 192 bits key */
13965                 TEST_CASE_ST(ut_setup, ut_teardown,
13966                         test_AES_GCM_auth_encryption_test_case_192_1),
13967                 TEST_CASE_ST(ut_setup, ut_teardown,
13968                         test_AES_GCM_auth_encryption_test_case_192_2),
13969                 TEST_CASE_ST(ut_setup, ut_teardown,
13970                         test_AES_GCM_auth_encryption_test_case_192_3),
13971                 TEST_CASE_ST(ut_setup, ut_teardown,
13972                         test_AES_GCM_auth_encryption_test_case_192_4),
13973                 TEST_CASE_ST(ut_setup, ut_teardown,
13974                         test_AES_GCM_auth_encryption_test_case_192_5),
13975                 TEST_CASE_ST(ut_setup, ut_teardown,
13976                         test_AES_GCM_auth_encryption_test_case_192_6),
13977                 TEST_CASE_ST(ut_setup, ut_teardown,
13978                         test_AES_GCM_auth_encryption_test_case_192_7),
13979
13980                 /** AES GCM Authenticated Decryption 192 bits key */
13981                 TEST_CASE_ST(ut_setup, ut_teardown,
13982                         test_AES_GCM_auth_decryption_test_case_192_1),
13983                 TEST_CASE_ST(ut_setup, ut_teardown,
13984                         test_AES_GCM_auth_decryption_test_case_192_2),
13985                 TEST_CASE_ST(ut_setup, ut_teardown,
13986                         test_AES_GCM_auth_decryption_test_case_192_3),
13987                 TEST_CASE_ST(ut_setup, ut_teardown,
13988                         test_AES_GCM_auth_decryption_test_case_192_4),
13989                 TEST_CASE_ST(ut_setup, ut_teardown,
13990                         test_AES_GCM_auth_decryption_test_case_192_5),
13991                 TEST_CASE_ST(ut_setup, ut_teardown,
13992                         test_AES_GCM_auth_decryption_test_case_192_6),
13993                 TEST_CASE_ST(ut_setup, ut_teardown,
13994                         test_AES_GCM_auth_decryption_test_case_192_7),
13995
13996                 /** AES GCM Authenticated Encryption 256 bits key */
13997                 TEST_CASE_ST(ut_setup, ut_teardown,
13998                         test_AES_GCM_auth_encryption_test_case_256_1),
13999                 TEST_CASE_ST(ut_setup, ut_teardown,
14000                         test_AES_GCM_auth_encryption_test_case_256_2),
14001                 TEST_CASE_ST(ut_setup, ut_teardown,
14002                         test_AES_GCM_auth_encryption_test_case_256_3),
14003                 TEST_CASE_ST(ut_setup, ut_teardown,
14004                         test_AES_GCM_auth_encryption_test_case_256_4),
14005                 TEST_CASE_ST(ut_setup, ut_teardown,
14006                         test_AES_GCM_auth_encryption_test_case_256_5),
14007                 TEST_CASE_ST(ut_setup, ut_teardown,
14008                         test_AES_GCM_auth_encryption_test_case_256_6),
14009                 TEST_CASE_ST(ut_setup, ut_teardown,
14010                         test_AES_GCM_auth_encryption_test_case_256_7),
14011
14012                 /** AES GCM Authenticated Decryption 256 bits key */
14013                 TEST_CASE_ST(ut_setup, ut_teardown,
14014                         test_AES_GCM_auth_decryption_test_case_256_1),
14015                 TEST_CASE_ST(ut_setup, ut_teardown,
14016                         test_AES_GCM_auth_decryption_test_case_256_2),
14017                 TEST_CASE_ST(ut_setup, ut_teardown,
14018                         test_AES_GCM_auth_decryption_test_case_256_3),
14019                 TEST_CASE_ST(ut_setup, ut_teardown,
14020                         test_AES_GCM_auth_decryption_test_case_256_4),
14021                 TEST_CASE_ST(ut_setup, ut_teardown,
14022                         test_AES_GCM_auth_decryption_test_case_256_5),
14023                 TEST_CASE_ST(ut_setup, ut_teardown,
14024                         test_AES_GCM_auth_decryption_test_case_256_6),
14025                 TEST_CASE_ST(ut_setup, ut_teardown,
14026                         test_AES_GCM_auth_decryption_test_case_256_7),
14027
14028                 /** AES GCM Authenticated Encryption big aad size */
14029                 TEST_CASE_ST(ut_setup, ut_teardown,
14030                         test_AES_GCM_auth_encryption_test_case_aad_1),
14031                 TEST_CASE_ST(ut_setup, ut_teardown,
14032                         test_AES_GCM_auth_encryption_test_case_aad_2),
14033
14034                 /** AES GCM Authenticated Decryption big aad size */
14035                 TEST_CASE_ST(ut_setup, ut_teardown,
14036                         test_AES_GCM_auth_decryption_test_case_aad_1),
14037                 TEST_CASE_ST(ut_setup, ut_teardown,
14038                         test_AES_GCM_auth_decryption_test_case_aad_2),
14039
14040                 /** Out of place tests */
14041                 TEST_CASE_ST(ut_setup, ut_teardown,
14042                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
14043                 TEST_CASE_ST(ut_setup, ut_teardown,
14044                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
14045
14046                 /** Session-less tests */
14047                 TEST_CASE_ST(ut_setup, ut_teardown,
14048                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
14049                 TEST_CASE_ST(ut_setup, ut_teardown,
14050                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
14051
14052                 TEST_CASES_END()
14053         }
14054 };
14055
14056 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
14057         .suite_name = "AES GMAC Authentication Test Suite",
14058         .setup = aes_gmac_auth_testsuite_setup,
14059         .unit_test_cases = {
14060                 TEST_CASE_ST(ut_setup, ut_teardown,
14061                         test_AES_GMAC_authentication_test_case_1),
14062                 TEST_CASE_ST(ut_setup, ut_teardown,
14063                         test_AES_GMAC_authentication_verify_test_case_1),
14064                 TEST_CASE_ST(ut_setup, ut_teardown,
14065                         test_AES_GMAC_authentication_test_case_2),
14066                 TEST_CASE_ST(ut_setup, ut_teardown,
14067                         test_AES_GMAC_authentication_verify_test_case_2),
14068                 TEST_CASE_ST(ut_setup, ut_teardown,
14069                         test_AES_GMAC_authentication_test_case_3),
14070                 TEST_CASE_ST(ut_setup, ut_teardown,
14071                         test_AES_GMAC_authentication_verify_test_case_3),
14072                 TEST_CASE_ST(ut_setup, ut_teardown,
14073                         test_AES_GMAC_authentication_test_case_4),
14074                 TEST_CASE_ST(ut_setup, ut_teardown,
14075                         test_AES_GMAC_authentication_verify_test_case_4),
14076                 TEST_CASE_ST(ut_setup, ut_teardown,
14077                         test_AES_GMAC_authentication_SGL_40B),
14078                 TEST_CASE_ST(ut_setup, ut_teardown,
14079                         test_AES_GMAC_authentication_SGL_80B),
14080                 TEST_CASE_ST(ut_setup, ut_teardown,
14081                         test_AES_GMAC_authentication_SGL_2048B),
14082                 TEST_CASE_ST(ut_setup, ut_teardown,
14083                         test_AES_GMAC_authentication_SGL_2047B),
14084
14085                 TEST_CASES_END()
14086         }
14087 };
14088
14089 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14090         .suite_name = "Chacha20-Poly1305 Test Suite",
14091         .setup = chacha20_poly1305_testsuite_setup,
14092         .unit_test_cases = {
14093                 TEST_CASE_ST(ut_setup, ut_teardown,
14094                         test_chacha20_poly1305_encrypt_test_case_rfc8439),
14095                 TEST_CASE_ST(ut_setup, ut_teardown,
14096                         test_chacha20_poly1305_decrypt_test_case_rfc8439),
14097                 TEST_CASES_END()
14098         }
14099 };
14100
14101 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14102         .suite_name = "SNOW 3G Test Suite",
14103         .setup = snow3g_testsuite_setup,
14104         .unit_test_cases = {
14105                 /** SNOW 3G encrypt only (UEA2) */
14106                 TEST_CASE_ST(ut_setup, ut_teardown,
14107                         test_snow3g_encryption_test_case_1),
14108                 TEST_CASE_ST(ut_setup, ut_teardown,
14109                         test_snow3g_encryption_test_case_2),
14110                 TEST_CASE_ST(ut_setup, ut_teardown,
14111                         test_snow3g_encryption_test_case_3),
14112                 TEST_CASE_ST(ut_setup, ut_teardown,
14113                         test_snow3g_encryption_test_case_4),
14114                 TEST_CASE_ST(ut_setup, ut_teardown,
14115                         test_snow3g_encryption_test_case_5),
14116
14117                 TEST_CASE_ST(ut_setup, ut_teardown,
14118                         test_snow3g_encryption_test_case_1_oop),
14119                 TEST_CASE_ST(ut_setup, ut_teardown,
14120                         test_snow3g_encryption_test_case_1_oop_sgl),
14121                 TEST_CASE_ST(ut_setup, ut_teardown,
14122                         test_snow3g_encryption_test_case_1_offset_oop),
14123                 TEST_CASE_ST(ut_setup, ut_teardown,
14124                         test_snow3g_decryption_test_case_1_oop),
14125
14126                 /** SNOW 3G generate auth, then encrypt (UEA2) */
14127                 TEST_CASE_ST(ut_setup, ut_teardown,
14128                         test_snow3g_auth_cipher_test_case_1),
14129                 TEST_CASE_ST(ut_setup, ut_teardown,
14130                         test_snow3g_auth_cipher_test_case_2),
14131                 TEST_CASE_ST(ut_setup, ut_teardown,
14132                         test_snow3g_auth_cipher_test_case_2_oop),
14133                 TEST_CASE_ST(ut_setup, ut_teardown,
14134                         test_snow3g_auth_cipher_part_digest_enc),
14135                 TEST_CASE_ST(ut_setup, ut_teardown,
14136                         test_snow3g_auth_cipher_part_digest_enc_oop),
14137                 TEST_CASE_ST(ut_setup, ut_teardown,
14138                         test_snow3g_auth_cipher_test_case_3_sgl),
14139                 TEST_CASE_ST(ut_setup, ut_teardown,
14140                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
14141                 TEST_CASE_ST(ut_setup, ut_teardown,
14142                         test_snow3g_auth_cipher_part_digest_enc_sgl),
14143                 TEST_CASE_ST(ut_setup, ut_teardown,
14144                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14145
14146                 /** SNOW 3G decrypt (UEA2), then verify auth */
14147                 TEST_CASE_ST(ut_setup, ut_teardown,
14148                         test_snow3g_auth_cipher_verify_test_case_1),
14149                 TEST_CASE_ST(ut_setup, ut_teardown,
14150                         test_snow3g_auth_cipher_verify_test_case_2),
14151                 TEST_CASE_ST(ut_setup, ut_teardown,
14152                         test_snow3g_auth_cipher_verify_test_case_2_oop),
14153                 TEST_CASE_ST(ut_setup, ut_teardown,
14154                         test_snow3g_auth_cipher_verify_part_digest_enc),
14155                 TEST_CASE_ST(ut_setup, ut_teardown,
14156                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14157                 TEST_CASE_ST(ut_setup, ut_teardown,
14158                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
14159                 TEST_CASE_ST(ut_setup, ut_teardown,
14160                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14161                 TEST_CASE_ST(ut_setup, ut_teardown,
14162                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14163                 TEST_CASE_ST(ut_setup, ut_teardown,
14164                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14165
14166                 /** SNOW 3G decrypt only (UEA2) */
14167                 TEST_CASE_ST(ut_setup, ut_teardown,
14168                         test_snow3g_decryption_test_case_1),
14169                 TEST_CASE_ST(ut_setup, ut_teardown,
14170                         test_snow3g_decryption_test_case_2),
14171                 TEST_CASE_ST(ut_setup, ut_teardown,
14172                         test_snow3g_decryption_test_case_3),
14173                 TEST_CASE_ST(ut_setup, ut_teardown,
14174                         test_snow3g_decryption_test_case_4),
14175                 TEST_CASE_ST(ut_setup, ut_teardown,
14176                         test_snow3g_decryption_test_case_5),
14177                 TEST_CASE_ST(ut_setup, ut_teardown,
14178                         test_snow3g_decryption_with_digest_test_case_1),
14179                 TEST_CASE_ST(ut_setup, ut_teardown,
14180                         test_snow3g_hash_generate_test_case_1),
14181                 TEST_CASE_ST(ut_setup, ut_teardown,
14182                         test_snow3g_hash_generate_test_case_2),
14183                 TEST_CASE_ST(ut_setup, ut_teardown,
14184                         test_snow3g_hash_generate_test_case_3),
14185
14186                 /* Tests with buffers which length is not byte-aligned */
14187                 TEST_CASE_ST(ut_setup, ut_teardown,
14188                         test_snow3g_hash_generate_test_case_4),
14189                 TEST_CASE_ST(ut_setup, ut_teardown,
14190                         test_snow3g_hash_generate_test_case_5),
14191                 TEST_CASE_ST(ut_setup, ut_teardown,
14192                         test_snow3g_hash_generate_test_case_6),
14193                 TEST_CASE_ST(ut_setup, ut_teardown,
14194                         test_snow3g_hash_verify_test_case_1),
14195                 TEST_CASE_ST(ut_setup, ut_teardown,
14196                         test_snow3g_hash_verify_test_case_2),
14197                 TEST_CASE_ST(ut_setup, ut_teardown,
14198                         test_snow3g_hash_verify_test_case_3),
14199
14200                 /* Tests with buffers which length is not byte-aligned */
14201                 TEST_CASE_ST(ut_setup, ut_teardown,
14202                         test_snow3g_hash_verify_test_case_4),
14203                 TEST_CASE_ST(ut_setup, ut_teardown,
14204                         test_snow3g_hash_verify_test_case_5),
14205                 TEST_CASE_ST(ut_setup, ut_teardown,
14206                         test_snow3g_hash_verify_test_case_6),
14207                 TEST_CASE_ST(ut_setup, ut_teardown,
14208                         test_snow3g_cipher_auth_test_case_1),
14209                 TEST_CASE_ST(ut_setup, ut_teardown,
14210                         test_snow3g_auth_cipher_with_digest_test_case_1),
14211                 TEST_CASES_END()
14212         }
14213 };
14214
14215 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14216         .suite_name = "ZUC Test Suite",
14217         .setup = zuc_testsuite_setup,
14218         .unit_test_cases = {
14219                 /** ZUC encrypt only (EEA3) */
14220                 TEST_CASE_ST(ut_setup, ut_teardown,
14221                         test_zuc_encryption_test_case_1),
14222                 TEST_CASE_ST(ut_setup, ut_teardown,
14223                         test_zuc_encryption_test_case_2),
14224                 TEST_CASE_ST(ut_setup, ut_teardown,
14225                         test_zuc_encryption_test_case_3),
14226                 TEST_CASE_ST(ut_setup, ut_teardown,
14227                         test_zuc_encryption_test_case_4),
14228                 TEST_CASE_ST(ut_setup, ut_teardown,
14229                         test_zuc_encryption_test_case_5),
14230                 TEST_CASE_ST(ut_setup, ut_teardown,
14231                         test_zuc_encryption_test_case_6_sgl),
14232
14233                 /** ZUC authenticate (EIA3) */
14234                 TEST_CASE_ST(ut_setup, ut_teardown,
14235                         test_zuc_hash_generate_test_case_1),
14236                 TEST_CASE_ST(ut_setup, ut_teardown,
14237                         test_zuc_hash_generate_test_case_2),
14238                 TEST_CASE_ST(ut_setup, ut_teardown,
14239                         test_zuc_hash_generate_test_case_3),
14240                 TEST_CASE_ST(ut_setup, ut_teardown,
14241                         test_zuc_hash_generate_test_case_4),
14242                 TEST_CASE_ST(ut_setup, ut_teardown,
14243                         test_zuc_hash_generate_test_case_5),
14244                 TEST_CASE_ST(ut_setup, ut_teardown,
14245                         test_zuc_hash_generate_test_case_6),
14246                 TEST_CASE_ST(ut_setup, ut_teardown,
14247                         test_zuc_hash_generate_test_case_7),
14248                 TEST_CASE_ST(ut_setup, ut_teardown,
14249                         test_zuc_hash_generate_test_case_8),
14250
14251                 /** ZUC alg-chain (EEA3/EIA3) */
14252                 TEST_CASE_ST(ut_setup, ut_teardown,
14253                         test_zuc_cipher_auth_test_case_1),
14254                 TEST_CASE_ST(ut_setup, ut_teardown,
14255                         test_zuc_cipher_auth_test_case_2),
14256
14257                 /** ZUC generate auth, then encrypt (EEA3) */
14258                 TEST_CASE_ST(ut_setup, ut_teardown,
14259                         test_zuc_auth_cipher_test_case_1),
14260                 TEST_CASE_ST(ut_setup, ut_teardown,
14261                         test_zuc_auth_cipher_test_case_1_oop),
14262                 TEST_CASE_ST(ut_setup, ut_teardown,
14263                         test_zuc_auth_cipher_test_case_1_sgl),
14264                 TEST_CASE_ST(ut_setup, ut_teardown,
14265                         test_zuc_auth_cipher_test_case_1_oop_sgl),
14266
14267                 /** ZUC decrypt (EEA3), then verify auth */
14268                 TEST_CASE_ST(ut_setup, ut_teardown,
14269                         test_zuc_auth_cipher_verify_test_case_1),
14270                 TEST_CASE_ST(ut_setup, ut_teardown,
14271                         test_zuc_auth_cipher_verify_test_case_1_oop),
14272                 TEST_CASE_ST(ut_setup, ut_teardown,
14273                         test_zuc_auth_cipher_verify_test_case_1_sgl),
14274                 TEST_CASE_ST(ut_setup, ut_teardown,
14275                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
14276                 TEST_CASES_END()
14277         }
14278 };
14279
14280 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
14281         .suite_name = "HMAC_MD5 Authentication Test Suite",
14282         .setup = hmac_md5_auth_testsuite_setup,
14283         .unit_test_cases = {
14284                 TEST_CASE_ST(ut_setup, ut_teardown,
14285                         test_MD5_HMAC_generate_case_1),
14286                 TEST_CASE_ST(ut_setup, ut_teardown,
14287                         test_MD5_HMAC_verify_case_1),
14288                 TEST_CASE_ST(ut_setup, ut_teardown,
14289                         test_MD5_HMAC_generate_case_2),
14290                 TEST_CASE_ST(ut_setup, ut_teardown,
14291                         test_MD5_HMAC_verify_case_2),
14292                 TEST_CASES_END()
14293         }
14294 };
14295
14296 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
14297         .suite_name = "Kasumi Test Suite",
14298         .setup = kasumi_testsuite_setup,
14299         .unit_test_cases = {
14300                 /** KASUMI hash only (UIA1) */
14301                 TEST_CASE_ST(ut_setup, ut_teardown,
14302                         test_kasumi_hash_generate_test_case_1),
14303                 TEST_CASE_ST(ut_setup, ut_teardown,
14304                         test_kasumi_hash_generate_test_case_2),
14305                 TEST_CASE_ST(ut_setup, ut_teardown,
14306                         test_kasumi_hash_generate_test_case_3),
14307                 TEST_CASE_ST(ut_setup, ut_teardown,
14308                         test_kasumi_hash_generate_test_case_4),
14309                 TEST_CASE_ST(ut_setup, ut_teardown,
14310                         test_kasumi_hash_generate_test_case_5),
14311                 TEST_CASE_ST(ut_setup, ut_teardown,
14312                         test_kasumi_hash_generate_test_case_6),
14313
14314                 TEST_CASE_ST(ut_setup, ut_teardown,
14315                         test_kasumi_hash_verify_test_case_1),
14316                 TEST_CASE_ST(ut_setup, ut_teardown,
14317                         test_kasumi_hash_verify_test_case_2),
14318                 TEST_CASE_ST(ut_setup, ut_teardown,
14319                         test_kasumi_hash_verify_test_case_3),
14320                 TEST_CASE_ST(ut_setup, ut_teardown,
14321                         test_kasumi_hash_verify_test_case_4),
14322                 TEST_CASE_ST(ut_setup, ut_teardown,
14323                         test_kasumi_hash_verify_test_case_5),
14324
14325                 /** KASUMI encrypt only (UEA1) */
14326                 TEST_CASE_ST(ut_setup, ut_teardown,
14327                         test_kasumi_encryption_test_case_1),
14328                 TEST_CASE_ST(ut_setup, ut_teardown,
14329                         test_kasumi_encryption_test_case_1_sgl),
14330                 TEST_CASE_ST(ut_setup, ut_teardown,
14331                         test_kasumi_encryption_test_case_1_oop),
14332                 TEST_CASE_ST(ut_setup, ut_teardown,
14333                         test_kasumi_encryption_test_case_1_oop_sgl),
14334                 TEST_CASE_ST(ut_setup, ut_teardown,
14335                         test_kasumi_encryption_test_case_2),
14336                 TEST_CASE_ST(ut_setup, ut_teardown,
14337                         test_kasumi_encryption_test_case_3),
14338                 TEST_CASE_ST(ut_setup, ut_teardown,
14339                         test_kasumi_encryption_test_case_4),
14340                 TEST_CASE_ST(ut_setup, ut_teardown,
14341                         test_kasumi_encryption_test_case_5),
14342
14343                 /** KASUMI decrypt only (UEA1) */
14344                 TEST_CASE_ST(ut_setup, ut_teardown,
14345                         test_kasumi_decryption_test_case_1),
14346                 TEST_CASE_ST(ut_setup, ut_teardown,
14347                         test_kasumi_decryption_test_case_2),
14348                 TEST_CASE_ST(ut_setup, ut_teardown,
14349                         test_kasumi_decryption_test_case_3),
14350                 TEST_CASE_ST(ut_setup, ut_teardown,
14351                         test_kasumi_decryption_test_case_4),
14352                 TEST_CASE_ST(ut_setup, ut_teardown,
14353                         test_kasumi_decryption_test_case_5),
14354                 TEST_CASE_ST(ut_setup, ut_teardown,
14355                         test_kasumi_decryption_test_case_1_oop),
14356
14357                 TEST_CASE_ST(ut_setup, ut_teardown,
14358                         test_kasumi_cipher_auth_test_case_1),
14359
14360                 /** KASUMI generate auth, then encrypt (F8) */
14361                 TEST_CASE_ST(ut_setup, ut_teardown,
14362                         test_kasumi_auth_cipher_test_case_1),
14363                 TEST_CASE_ST(ut_setup, ut_teardown,
14364                         test_kasumi_auth_cipher_test_case_2),
14365                 TEST_CASE_ST(ut_setup, ut_teardown,
14366                         test_kasumi_auth_cipher_test_case_2_oop),
14367                 TEST_CASE_ST(ut_setup, ut_teardown,
14368                         test_kasumi_auth_cipher_test_case_2_sgl),
14369                 TEST_CASE_ST(ut_setup, ut_teardown,
14370                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
14371
14372                 /** KASUMI decrypt (F8), then verify auth */
14373                 TEST_CASE_ST(ut_setup, ut_teardown,
14374                         test_kasumi_auth_cipher_verify_test_case_1),
14375                 TEST_CASE_ST(ut_setup, ut_teardown,
14376                         test_kasumi_auth_cipher_verify_test_case_2),
14377                 TEST_CASE_ST(ut_setup, ut_teardown,
14378                         test_kasumi_auth_cipher_verify_test_case_2_oop),
14379                 TEST_CASE_ST(ut_setup, ut_teardown,
14380                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
14381                 TEST_CASE_ST(ut_setup, ut_teardown,
14382                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
14383
14384                 TEST_CASES_END()
14385         }
14386 };
14387
14388 static struct unit_test_suite cryptodev_esn_testsuite  = {
14389         .suite_name = "ESN Test Suite",
14390         .setup = esn_testsuite_setup,
14391         .unit_test_cases = {
14392                 TEST_CASE_ST(ut_setup, ut_teardown,
14393                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
14394                 TEST_CASE_ST(ut_setup, ut_teardown,
14395                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
14396                 TEST_CASES_END()
14397         }
14398 };
14399
14400 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
14401         .suite_name = "Negative AES GCM Test Suite",
14402         .setup = negative_aes_gcm_testsuite_setup,
14403         .unit_test_cases = {
14404                 TEST_CASE_ST(ut_setup, ut_teardown,
14405                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
14406                 TEST_CASE_ST(ut_setup, ut_teardown,
14407                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
14408                 TEST_CASE_ST(ut_setup, ut_teardown,
14409                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
14410                 TEST_CASE_ST(ut_setup, ut_teardown,
14411                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
14412                 TEST_CASE_ST(ut_setup, ut_teardown,
14413                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
14414                 TEST_CASE_ST(ut_setup, ut_teardown,
14415                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
14416                 TEST_CASE_ST(ut_setup, ut_teardown,
14417                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
14418                 TEST_CASE_ST(ut_setup, ut_teardown,
14419                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
14420                 TEST_CASE_ST(ut_setup, ut_teardown,
14421                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
14422                 TEST_CASE_ST(ut_setup, ut_teardown,
14423                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
14424                 TEST_CASE_ST(ut_setup, ut_teardown,
14425                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
14426                 TEST_CASE_ST(ut_setup, ut_teardown,
14427                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
14428
14429                 TEST_CASES_END()
14430         }
14431 };
14432
14433 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
14434         .suite_name = "Negative AES GMAC Test Suite",
14435         .setup = negative_aes_gmac_testsuite_setup,
14436         .unit_test_cases = {
14437                 TEST_CASE_ST(ut_setup, ut_teardown,
14438                         authentication_verify_AES128_GMAC_fail_data_corrupt),
14439                 TEST_CASE_ST(ut_setup, ut_teardown,
14440                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
14441
14442                 TEST_CASES_END()
14443         }
14444 };
14445
14446 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
14447         .suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
14448         .setup = mixed_cipher_hash_testsuite_setup,
14449         .unit_test_cases = {
14450                 /** AUTH AES CMAC + CIPHER AES CTR */
14451                 TEST_CASE_ST(ut_setup, ut_teardown,
14452                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
14453                 TEST_CASE_ST(ut_setup, ut_teardown,
14454                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14455                 TEST_CASE_ST(ut_setup, ut_teardown,
14456                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14457                 TEST_CASE_ST(ut_setup, ut_teardown,
14458                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14459                 TEST_CASE_ST(ut_setup, ut_teardown,
14460                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
14461                 TEST_CASE_ST(ut_setup, ut_teardown,
14462                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14463                 TEST_CASE_ST(ut_setup, ut_teardown,
14464                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14465                 TEST_CASE_ST(ut_setup, ut_teardown,
14466                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14467
14468                 /** AUTH ZUC + CIPHER SNOW3G */
14469                 TEST_CASE_ST(ut_setup, ut_teardown,
14470                         test_auth_zuc_cipher_snow_test_case_1),
14471                 TEST_CASE_ST(ut_setup, ut_teardown,
14472                         test_verify_auth_zuc_cipher_snow_test_case_1),
14473                 /** AUTH AES CMAC + CIPHER SNOW3G */
14474                 TEST_CASE_ST(ut_setup, ut_teardown,
14475                         test_auth_aes_cmac_cipher_snow_test_case_1),
14476                 TEST_CASE_ST(ut_setup, ut_teardown,
14477                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
14478                 /** AUTH ZUC + CIPHER AES CTR */
14479                 TEST_CASE_ST(ut_setup, ut_teardown,
14480                         test_auth_zuc_cipher_aes_ctr_test_case_1),
14481                 TEST_CASE_ST(ut_setup, ut_teardown,
14482                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
14483                 /** AUTH SNOW3G + CIPHER AES CTR */
14484                 TEST_CASE_ST(ut_setup, ut_teardown,
14485                         test_auth_snow_cipher_aes_ctr_test_case_1),
14486                 TEST_CASE_ST(ut_setup, ut_teardown,
14487                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
14488                 /** AUTH SNOW3G + CIPHER ZUC */
14489                 TEST_CASE_ST(ut_setup, ut_teardown,
14490                         test_auth_snow_cipher_zuc_test_case_1),
14491                 TEST_CASE_ST(ut_setup, ut_teardown,
14492                         test_verify_auth_snow_cipher_zuc_test_case_1),
14493                 /** AUTH AES CMAC + CIPHER ZUC */
14494                 TEST_CASE_ST(ut_setup, ut_teardown,
14495                         test_auth_aes_cmac_cipher_zuc_test_case_1),
14496                 TEST_CASE_ST(ut_setup, ut_teardown,
14497                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
14498
14499                 /** AUTH NULL + CIPHER SNOW3G */
14500                 TEST_CASE_ST(ut_setup, ut_teardown,
14501                         test_auth_null_cipher_snow_test_case_1),
14502                 TEST_CASE_ST(ut_setup, ut_teardown,
14503                         test_verify_auth_null_cipher_snow_test_case_1),
14504                 /** AUTH NULL + CIPHER ZUC */
14505                 TEST_CASE_ST(ut_setup, ut_teardown,
14506                         test_auth_null_cipher_zuc_test_case_1),
14507                 TEST_CASE_ST(ut_setup, ut_teardown,
14508                         test_verify_auth_null_cipher_zuc_test_case_1),
14509                 /** AUTH SNOW3G + CIPHER NULL */
14510                 TEST_CASE_ST(ut_setup, ut_teardown,
14511                         test_auth_snow_cipher_null_test_case_1),
14512                 TEST_CASE_ST(ut_setup, ut_teardown,
14513                         test_verify_auth_snow_cipher_null_test_case_1),
14514                 /** AUTH ZUC + CIPHER NULL */
14515                 TEST_CASE_ST(ut_setup, ut_teardown,
14516                         test_auth_zuc_cipher_null_test_case_1),
14517                 TEST_CASE_ST(ut_setup, ut_teardown,
14518                         test_verify_auth_zuc_cipher_null_test_case_1),
14519                 /** AUTH NULL + CIPHER AES CTR */
14520                 TEST_CASE_ST(ut_setup, ut_teardown,
14521                         test_auth_null_cipher_aes_ctr_test_case_1),
14522                 TEST_CASE_ST(ut_setup, ut_teardown,
14523                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
14524                 /** AUTH AES CMAC + CIPHER NULL */
14525                 TEST_CASE_ST(ut_setup, ut_teardown,
14526                         test_auth_aes_cmac_cipher_null_test_case_1),
14527                 TEST_CASE_ST(ut_setup, ut_teardown,
14528                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
14529                 TEST_CASES_END()
14530         }
14531 };
14532
14533 static int
14534 run_cryptodev_testsuite(const char *pmd_name)
14535 {
14536         uint8_t ret, j, i = 0;
14537         struct unit_test_suite *static_suites[] = {
14538                 &cryptodev_multi_session_testsuite,
14539                 &cryptodev_null_testsuite,
14540                 &cryptodev_aes_ccm_auth_testsuite,
14541                 &cryptodev_aes_gcm_auth_testsuite,
14542                 &cryptodev_aes_gmac_auth_testsuite,
14543                 &cryptodev_snow3g_testsuite,
14544                 &cryptodev_chacha20_poly1305_testsuite,
14545                 &cryptodev_zuc_testsuite,
14546                 &cryptodev_hmac_md5_auth_testsuite,
14547                 &cryptodev_kasumi_testsuite,
14548                 &cryptodev_esn_testsuite,
14549                 &cryptodev_negative_aes_gcm_testsuite,
14550                 &cryptodev_negative_aes_gmac_testsuite,
14551                 &cryptodev_mixed_cipher_hash_testsuite,
14552                 &cryptodev_negative_hmac_sha1_testsuite,
14553                 &cryptodev_gen_testsuite,
14554 #ifdef RTE_LIB_SECURITY
14555                 &pdcp_proto_testsuite,
14556                 &docsis_proto_testsuite,
14557 #endif
14558                 &end_testsuite
14559         };
14560         static struct unit_test_suite ts = {
14561                 .suite_name = "Cryptodev Unit Test Suite",
14562                 .setup = testsuite_setup,
14563                 .teardown = testsuite_teardown,
14564                 .unit_test_cases = {TEST_CASES_END()}
14565         };
14566
14567         gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
14568
14569         if (gbl_driver_id == -1) {
14570                 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
14571                 return TEST_FAILED;
14572         }
14573
14574         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
14575                         RTE_DIM(static_suites));
14576
14577         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
14578         ret = unit_test_suite_runner(&ts);
14579
14580         free(ts.unit_test_suites);
14581         return ret;
14582 }
14583
14584 static int
14585 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
14586 {
14587         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14588 }
14589
14590 static int
14591 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
14592 {
14593         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
14594 }
14595
14596 static int
14597 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
14598 {
14599         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14600 }
14601
14602 static int
14603 test_cryptodev_cpu_aesni_mb(void)
14604 {
14605         int32_t rc;
14606         enum rte_security_session_action_type at = gbl_action_type;
14607         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14608         rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14609         gbl_action_type = at;
14610         return rc;
14611 }
14612
14613 static int
14614 test_cryptodev_openssl(void)
14615 {
14616         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
14617 }
14618
14619 static int
14620 test_cryptodev_aesni_gcm(void)
14621 {
14622         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14623 }
14624
14625 static int
14626 test_cryptodev_cpu_aesni_gcm(void)
14627 {
14628         int32_t rc;
14629         enum rte_security_session_action_type at = gbl_action_type;
14630         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14631         rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14632         gbl_action_type = at;
14633         return rc;
14634 }
14635
14636 static int
14637 test_cryptodev_null(void)
14638 {
14639         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
14640 }
14641
14642 static int
14643 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
14644 {
14645         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
14646 }
14647
14648 static int
14649 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
14650 {
14651         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
14652 }
14653
14654 static int
14655 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
14656 {
14657         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
14658 }
14659
14660 static int
14661 test_cryptodev_armv8(void)
14662 {
14663         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
14664 }
14665
14666 static int
14667 test_cryptodev_mrvl(void)
14668 {
14669         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
14670 }
14671
14672 #ifdef RTE_CRYPTO_SCHEDULER
14673
14674 static int
14675 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
14676 {
14677         uint8_t ret, j, i = 0;
14678         static struct unit_test_suite scheduler_multicore = {
14679                 .suite_name = "Scheduler Multicore Unit Test Suite",
14680                 .setup = scheduler_multicore_testsuite_setup,
14681                 .teardown = scheduler_mode_testsuite_teardown,
14682                 .unit_test_cases = {
14683                         TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
14684                         TEST_CASE_ST(ut_setup, ut_teardown,
14685                                         test_AES_cipheronly_all),
14686                         TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
14687                         TEST_CASES_END()
14688                 }
14689         };
14690         static struct unit_test_suite scheduler_round_robin = {
14691                 .suite_name = "Scheduler Round Robin Unit Test Suite",
14692                 .setup = scheduler_roundrobin_testsuite_setup,
14693                 .teardown = scheduler_mode_testsuite_teardown,
14694                 .unit_test_cases = {
14695                         TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
14696                         TEST_CASE_ST(ut_setup, ut_teardown,
14697                                         test_AES_cipheronly_all),
14698                         TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
14699                         TEST_CASES_END()
14700                 }
14701         };
14702         static struct unit_test_suite scheduler_failover = {
14703                 .suite_name = "Scheduler Failover Unit Test Suite",
14704                 .setup = scheduler_failover_testsuite_setup,
14705                 .teardown = scheduler_mode_testsuite_teardown,
14706                 .unit_test_cases = {
14707                         TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
14708                         TEST_CASE_ST(ut_setup, ut_teardown,
14709                                         test_AES_cipheronly_all),
14710                         TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
14711                         TEST_CASES_END()
14712                 }
14713         };
14714         static struct unit_test_suite scheduler_pkt_size_distr = {
14715                 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
14716                 .setup = scheduler_pkt_size_distr_testsuite_setup,
14717                 .teardown = scheduler_mode_testsuite_teardown,
14718                 .unit_test_cases = {
14719                         TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
14720                         TEST_CASE_ST(ut_setup, ut_teardown,
14721                                         test_AES_cipheronly_all),
14722                         TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
14723                         TEST_CASES_END()
14724                 }
14725         };
14726         struct unit_test_suite *sched_mode_suites[] = {
14727                 &scheduler_multicore,
14728                 &scheduler_round_robin,
14729                 &scheduler_failover,
14730                 &scheduler_pkt_size_distr
14731         };
14732         static struct unit_test_suite scheduler_config = {
14733                 .suite_name = "Crypto Device Scheduler Config Unit Test Suite",
14734                 .unit_test_cases = {
14735                         TEST_CASE(test_scheduler_attach_slave_op),
14736                         TEST_CASE(test_scheduler_mode_multicore_op),
14737                         TEST_CASE(test_scheduler_mode_roundrobin_op),
14738                         TEST_CASE(test_scheduler_mode_failover_op),
14739                         TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
14740                         TEST_CASE(test_scheduler_detach_slave_op),
14741
14742                         TEST_CASES_END() /**< NULL terminate array */
14743                 }
14744         };
14745         struct unit_test_suite *static_suites[] = {
14746                 &scheduler_config,
14747                 &end_testsuite
14748         };
14749         static struct unit_test_suite ts = {
14750                 .suite_name = "Scheduler Unit Test Suite",
14751                 .setup = scheduler_testsuite_setup,
14752                 .teardown = testsuite_teardown,
14753                 .unit_test_cases = {TEST_CASES_END()}
14754         };
14755
14756         gbl_driver_id = rte_cryptodev_driver_id_get(
14757                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14758
14759         if (gbl_driver_id == -1) {
14760                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
14761                 return TEST_SKIPPED;
14762         }
14763
14764         if (rte_cryptodev_driver_id_get(
14765                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
14766                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
14767                 return TEST_SKIPPED;
14768         }
14769
14770         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
14771                         (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
14772         ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
14773                         RTE_DIM(sched_mode_suites));
14774         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
14775         ret = unit_test_suite_runner(&ts);
14776
14777         free(ts.unit_test_suites);
14778         return ret;
14779 }
14780
14781 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
14782
14783 #endif
14784
14785 static int
14786 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
14787 {
14788         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
14789 }
14790
14791 static int
14792 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
14793 {
14794         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
14795 }
14796
14797 static int
14798 test_cryptodev_ccp(void)
14799 {
14800         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
14801 }
14802
14803 static int
14804 test_cryptodev_octeontx(void)
14805 {
14806         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
14807 }
14808
14809 static int
14810 test_cryptodev_octeontx2(void)
14811 {
14812         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
14813 }
14814
14815 static int
14816 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/)
14817 {
14818         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
14819 }
14820
14821 static int
14822 test_cryptodev_nitrox(void)
14823 {
14824         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
14825 }
14826
14827 static int
14828 test_cryptodev_bcmfs(void)
14829 {
14830         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
14831 }
14832
14833 static int
14834 test_cryptodev_qat_raw_api(void /*argv __rte_unused, int argc __rte_unused*/)
14835 {
14836         int ret;
14837
14838         global_api_test_type = CRYPTODEV_RAW_API_TEST;
14839         ret = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14840         global_api_test_type = CRYPTODEV_API_TEST;
14841
14842         return ret;
14843 }
14844
14845 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
14846                 test_cryptodev_qat_raw_api);
14847 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
14848 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
14849 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
14850         test_cryptodev_cpu_aesni_mb);
14851 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
14852 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
14853 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
14854         test_cryptodev_cpu_aesni_gcm);
14855 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
14856 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
14857 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
14858 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
14859 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
14860 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
14861 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
14862 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
14863 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
14864 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
14865 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
14866 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
14867 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
14868 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
14869 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);