ead8c6e3dc8112def2632a947426ca3ca3934d80
[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 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)   \
107         for (j = 0; j < num_blk_types; index++, j++)                            \
108                 parent_ts.unit_test_suites[index] =                             \
109                                 build_blockcipher_test_suite(blk_types[j])
110
111 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)             \
112         for (j = index; j < index + num_blk_types; j++)                         \
113                 free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
114
115 /*
116  * Forward declarations.
117  */
118 static int
119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
120                 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
121                 uint8_t *hmac_key);
122
123 static int
124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
125                 struct crypto_unittest_params *ut_params,
126                 struct crypto_testsuite_params *ts_param,
127                 const uint8_t *cipher,
128                 const uint8_t *digest,
129                 const uint8_t *iv);
130
131 static struct rte_mbuf *
132 setup_test_string(struct rte_mempool *mpool,
133                 const char *string, size_t len, uint8_t blocksize)
134 {
135         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
136         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
137
138         memset(m->buf_addr, 0, m->buf_len);
139         if (m) {
140                 char *dst = rte_pktmbuf_append(m, t_len);
141
142                 if (!dst) {
143                         rte_pktmbuf_free(m);
144                         return NULL;
145                 }
146                 if (string != NULL)
147                         rte_memcpy(dst, string, t_len);
148                 else
149                         memset(dst, 0, t_len);
150         }
151
152         return m;
153 }
154
155 /* Get number of bytes in X bits (rounding up) */
156 static uint32_t
157 ceil_byte_length(uint32_t num_bits)
158 {
159         if (num_bits % 8)
160                 return ((num_bits >> 3) + 1);
161         else
162                 return (num_bits >> 3);
163 }
164
165 static void
166 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused,
167                 uint8_t is_op_success)
168 {
169         struct rte_crypto_op *op = user_data;
170         op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
171                         RTE_CRYPTO_OP_STATUS_ERROR;
172 }
173
174 void
175 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
176                 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
177                 uint8_t len_in_bits, uint8_t cipher_iv_len)
178 {
179         struct rte_crypto_sym_op *sop = op->sym;
180         struct rte_crypto_op *ret_op = NULL;
181         struct rte_crypto_vec data_vec[UINT8_MAX];
182         struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
183         union rte_crypto_sym_ofs ofs;
184         struct rte_crypto_sym_vec vec;
185         struct rte_crypto_sgl sgl;
186         uint32_t max_len;
187         union rte_cryptodev_session_ctx sess;
188         uint32_t count = 0;
189         struct rte_crypto_raw_dp_ctx *ctx;
190         uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
191                         auth_len = 0;
192         int32_t n;
193         uint32_t n_success;
194         int ctx_service_size;
195         int32_t status = 0;
196         int enqueue_status, dequeue_status;
197
198         ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
199         if (ctx_service_size < 0) {
200                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
201                 return;
202         }
203
204         ctx = malloc(ctx_service_size);
205         if (!ctx) {
206                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
207                 return;
208         }
209
210         /* Both are enums, setting crypto_sess will suit any session type */
211         sess.crypto_sess = op->sym->session;
212
213         if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
214                         op->sess_type, sess, 0) < 0) {
215                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
216                 goto exit;
217         }
218
219         cipher_iv.iova = 0;
220         cipher_iv.va = NULL;
221         aad_auth_iv.iova = 0;
222         aad_auth_iv.va = NULL;
223         digest.iova = 0;
224         digest.va = NULL;
225         sgl.vec = data_vec;
226         vec.num = 1;
227         vec.sgl = &sgl;
228         vec.iv = &cipher_iv;
229         vec.digest = &digest;
230         vec.aad = &aad_auth_iv;
231         vec.status = &status;
232
233         ofs.raw = 0;
234
235         if (is_cipher && is_auth) {
236                 cipher_offset = sop->cipher.data.offset;
237                 cipher_len = sop->cipher.data.length;
238                 auth_offset = sop->auth.data.offset;
239                 auth_len = sop->auth.data.length;
240                 max_len = RTE_MAX(cipher_offset + cipher_len,
241                                 auth_offset + auth_len);
242                 if (len_in_bits) {
243                         max_len = max_len >> 3;
244                         cipher_offset = cipher_offset >> 3;
245                         auth_offset = auth_offset >> 3;
246                         cipher_len = cipher_len >> 3;
247                         auth_len = auth_len >> 3;
248                 }
249                 ofs.ofs.cipher.head = cipher_offset;
250                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
251                 ofs.ofs.auth.head = auth_offset;
252                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
253                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
254                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
255                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
256                                 op, void *, IV_OFFSET + cipher_iv_len);
257                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
258                                 cipher_iv_len);
259                 digest.va = (void *)sop->auth.digest.data;
260                 digest.iova = sop->auth.digest.phys_addr;
261
262         } else if (is_cipher) {
263                 cipher_offset = sop->cipher.data.offset;
264                 cipher_len = sop->cipher.data.length;
265                 max_len = cipher_len + cipher_offset;
266                 if (len_in_bits) {
267                         max_len = max_len >> 3;
268                         cipher_offset = cipher_offset >> 3;
269                         cipher_len = cipher_len >> 3;
270                 }
271                 ofs.ofs.cipher.head = cipher_offset;
272                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
273                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
274                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
275
276         } else if (is_auth) {
277                 auth_offset = sop->auth.data.offset;
278                 auth_len = sop->auth.data.length;
279                 max_len = auth_len + auth_offset;
280                 if (len_in_bits) {
281                         max_len = max_len >> 3;
282                         auth_offset = auth_offset >> 3;
283                         auth_len = auth_len >> 3;
284                 }
285                 ofs.ofs.auth.head = auth_offset;
286                 ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
287                 aad_auth_iv.va = rte_crypto_op_ctod_offset(
288                                 op, void *, IV_OFFSET + cipher_iv_len);
289                 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
290                                 cipher_iv_len);
291                 digest.va = (void *)sop->auth.digest.data;
292                 digest.iova = sop->auth.digest.phys_addr;
293
294         } else { /* aead */
295                 cipher_offset = sop->aead.data.offset;
296                 cipher_len = sop->aead.data.length;
297                 max_len = cipher_len + cipher_offset;
298                 if (len_in_bits) {
299                         max_len = max_len >> 3;
300                         cipher_offset = cipher_offset >> 3;
301                         cipher_len = cipher_len >> 3;
302                 }
303                 ofs.ofs.cipher.head = cipher_offset;
304                 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
305                 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
306                 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
307                 aad_auth_iv.va = (void *)sop->aead.aad.data;
308                 aad_auth_iv.iova = sop->aead.aad.phys_addr;
309                 digest.va = (void *)sop->aead.digest.data;
310                 digest.iova = sop->aead.digest.phys_addr;
311         }
312
313         n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
314                         data_vec, RTE_DIM(data_vec));
315         if (n < 0 || n > sop->m_src->nb_segs) {
316                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
317                 goto exit;
318         }
319
320         sgl.num = n;
321
322         if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
323                         &enqueue_status) < 1) {
324                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
325                 goto exit;
326         }
327
328         if (enqueue_status == 0) {
329                 status = rte_cryptodev_raw_enqueue_done(ctx, 1);
330                 if (status < 0) {
331                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
332                         goto exit;
333                 }
334         } else if (enqueue_status < 0) {
335                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
336                 goto exit;
337         }
338
339         n = n_success = 0;
340         while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
341                 n = rte_cryptodev_raw_dequeue_burst(ctx,
342                         NULL, 1, post_process_raw_dp_op,
343                                 (void **)&ret_op, 0, &n_success,
344                                 &dequeue_status);
345                 if (dequeue_status < 0) {
346                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
347                         goto exit;
348                 }
349                 if (n == 0)
350                         rte_pause();
351         }
352
353         if (n == 1 && dequeue_status == 0) {
354                 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
355                         op->status = RTE_CRYPTO_OP_STATUS_ERROR;
356                         goto exit;
357                 }
358         }
359
360         op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
361                         n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
362                                         RTE_CRYPTO_OP_STATUS_SUCCESS;
363
364 exit:
365         free(ctx);
366 }
367
368 static void
369 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
370 {
371         int32_t n, st;
372         struct rte_crypto_sym_op *sop;
373         union rte_crypto_sym_ofs ofs;
374         struct rte_crypto_sgl sgl;
375         struct rte_crypto_sym_vec symvec;
376         struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
377         struct rte_crypto_vec vec[UINT8_MAX];
378
379         sop = op->sym;
380
381         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
382                 sop->aead.data.length, vec, RTE_DIM(vec));
383
384         if (n < 0 || n != sop->m_src->nb_segs) {
385                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
386                 return;
387         }
388
389         sgl.vec = vec;
390         sgl.num = n;
391         symvec.sgl = &sgl;
392         symvec.iv = &iv_ptr;
393         symvec.digest = &digest_ptr;
394         symvec.aad = &aad_ptr;
395         symvec.status = &st;
396         symvec.num = 1;
397
398         /* for CPU crypto the IOVA address is not required */
399         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
400         digest_ptr.va = (void *)sop->aead.digest.data;
401         aad_ptr.va = (void *)sop->aead.aad.data;
402
403         ofs.raw = 0;
404
405         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
406                 &symvec);
407
408         if (n != 1)
409                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
410         else
411                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
412 }
413
414 static void
415 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
416 {
417         int32_t n, st;
418         struct rte_crypto_sym_op *sop;
419         union rte_crypto_sym_ofs ofs;
420         struct rte_crypto_sgl sgl;
421         struct rte_crypto_sym_vec symvec;
422         struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
423         struct rte_crypto_vec vec[UINT8_MAX];
424
425         sop = op->sym;
426
427         n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
428                 sop->auth.data.length, vec, RTE_DIM(vec));
429
430         if (n < 0 || n != sop->m_src->nb_segs) {
431                 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
432                 return;
433         }
434
435         sgl.vec = vec;
436         sgl.num = n;
437         symvec.sgl = &sgl;
438         symvec.iv = &iv_ptr;
439         symvec.digest = &digest_ptr;
440         symvec.status = &st;
441         symvec.num = 1;
442
443         iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
444         digest_ptr.va = (void *)sop->auth.digest.data;
445
446         ofs.raw = 0;
447         ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
448         ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
449                 (sop->cipher.data.offset + sop->cipher.data.length);
450
451         n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
452                 &symvec);
453
454         if (n != 1)
455                 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
456         else
457                 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
458 }
459
460 static struct rte_crypto_op *
461 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
462 {
463
464         RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
465
466         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
467                 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
468                 return NULL;
469         }
470
471         op = NULL;
472
473         while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
474                 rte_pause();
475
476         if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
477                 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
478                 return NULL;
479         }
480
481         return op;
482 }
483
484 static struct crypto_testsuite_params testsuite_params = { NULL };
485 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
486 static struct crypto_unittest_params unittest_params;
487
488 static int
489 testsuite_setup(void)
490 {
491         struct crypto_testsuite_params *ts_params = &testsuite_params;
492         struct rte_cryptodev_info info;
493         uint32_t i = 0, nb_devs, dev_id;
494         uint16_t qp_id;
495
496         memset(ts_params, 0, sizeof(*ts_params));
497
498         ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
499         if (ts_params->mbuf_pool == NULL) {
500                 /* Not already created so create */
501                 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
502                                 "CRYPTO_MBUFPOOL",
503                                 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
504                                 rte_socket_id());
505                 if (ts_params->mbuf_pool == NULL) {
506                         RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
507                         return TEST_FAILED;
508                 }
509         }
510
511         ts_params->large_mbuf_pool = rte_mempool_lookup(
512                         "CRYPTO_LARGE_MBUFPOOL");
513         if (ts_params->large_mbuf_pool == NULL) {
514                 /* Not already created so create */
515                 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
516                                 "CRYPTO_LARGE_MBUFPOOL",
517                                 1, 0, 0, UINT16_MAX,
518                                 rte_socket_id());
519                 if (ts_params->large_mbuf_pool == NULL) {
520                         RTE_LOG(ERR, USER1,
521                                 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
522                         return TEST_FAILED;
523                 }
524         }
525
526         ts_params->op_mpool = rte_crypto_op_pool_create(
527                         "MBUF_CRYPTO_SYM_OP_POOL",
528                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
529                         NUM_MBUFS, MBUF_CACHE_SIZE,
530                         DEFAULT_NUM_XFORMS *
531                         sizeof(struct rte_crypto_sym_xform) +
532                         MAXIMUM_IV_LENGTH,
533                         rte_socket_id());
534         if (ts_params->op_mpool == NULL) {
535                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
536                 return TEST_FAILED;
537         }
538
539         nb_devs = rte_cryptodev_count();
540         if (nb_devs < 1) {
541                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
542                 return TEST_SKIPPED;
543         }
544
545         if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
546                 RTE_LOG(WARNING, USER1, "No %s devices found?\n",
547                                 rte_cryptodev_driver_name_get(gbl_driver_id));
548                 return TEST_SKIPPED;
549         }
550
551         /* Create list of valid crypto devs */
552         for (i = 0; i < nb_devs; i++) {
553                 rte_cryptodev_info_get(i, &info);
554                 if (info.driver_id == gbl_driver_id)
555                         ts_params->valid_devs[ts_params->valid_dev_count++] = i;
556         }
557
558         if (ts_params->valid_dev_count < 1)
559                 return TEST_FAILED;
560
561         /* Set up all the qps on the first of the valid devices found */
562
563         dev_id = ts_params->valid_devs[0];
564
565         rte_cryptodev_info_get(dev_id, &info);
566
567         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
568         ts_params->conf.socket_id = SOCKET_ID_ANY;
569         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
570
571         unsigned int session_size =
572                 rte_cryptodev_sym_get_private_session_size(dev_id);
573
574 #ifdef RTE_LIB_SECURITY
575         unsigned int security_session_size = rte_security_session_get_size(
576                         rte_cryptodev_get_sec_ctx(dev_id));
577
578         if (session_size < security_session_size)
579                 session_size = security_session_size;
580 #endif
581         /*
582          * Create mempool with maximum number of sessions.
583          */
584         if (info.sym.max_nb_sessions != 0 &&
585                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
586                 RTE_LOG(ERR, USER1, "Device does not support "
587                                 "at least %u sessions\n",
588                                 MAX_NB_SESSIONS);
589                 return TEST_FAILED;
590         }
591
592         ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
593                         "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
594                         SOCKET_ID_ANY);
595         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
596                         "session mempool allocation failed");
597
598         ts_params->session_priv_mpool = rte_mempool_create(
599                         "test_sess_mp_priv",
600                         MAX_NB_SESSIONS,
601                         session_size,
602                         0, 0, NULL, NULL, NULL,
603                         NULL, SOCKET_ID_ANY,
604                         0);
605         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
606                         "session mempool allocation failed");
607
608
609
610         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
611                         &ts_params->conf),
612                         "Failed to configure cryptodev %u with %u qps",
613                         dev_id, ts_params->conf.nb_queue_pairs);
614
615         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
616         ts_params->qp_conf.mp_session = ts_params->session_mpool;
617         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
618
619         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
620                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
621                         dev_id, qp_id, &ts_params->qp_conf,
622                         rte_cryptodev_socket_id(dev_id)),
623                         "Failed to setup queue pair %u on cryptodev %u",
624                         qp_id, dev_id);
625         }
626
627         return TEST_SUCCESS;
628 }
629
630 static void
631 testsuite_teardown(void)
632 {
633         struct crypto_testsuite_params *ts_params = &testsuite_params;
634         int res;
635
636         if (ts_params->mbuf_pool != NULL) {
637                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
638                 rte_mempool_avail_count(ts_params->mbuf_pool));
639         }
640
641         if (ts_params->op_mpool != NULL) {
642                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
643                 rte_mempool_avail_count(ts_params->op_mpool));
644         }
645
646         /* Free session mempools */
647         if (ts_params->session_priv_mpool != NULL) {
648                 rte_mempool_free(ts_params->session_priv_mpool);
649                 ts_params->session_priv_mpool = NULL;
650         }
651
652         if (ts_params->session_mpool != NULL) {
653                 rte_mempool_free(ts_params->session_mpool);
654                 ts_params->session_mpool = NULL;
655         }
656
657         res = rte_cryptodev_close(ts_params->valid_devs[0]);
658         if (res)
659                 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
660 }
661
662 static int
663 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
664                 const int *algs, uint16_t num_algs)
665 {
666         uint8_t dev_id = testsuite_params.valid_devs[0];
667         bool some_alg_supported = FALSE;
668         uint16_t i;
669
670         for (i = 0; i < num_algs && !some_alg_supported; i++) {
671                 struct rte_cryptodev_sym_capability_idx alg = {
672                         type, {algs[i]}
673                 };
674                 if (rte_cryptodev_sym_capability_get(dev_id,
675                                 &alg) != NULL)
676                         some_alg_supported = TRUE;
677         }
678         if (!some_alg_supported)
679                 return TEST_SKIPPED;
680
681         return 0;
682 }
683
684 int
685 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
686                 uint16_t num_ciphers)
687 {
688         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
689                         (const int *) ciphers, num_ciphers);
690 }
691
692 int
693 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
694                 uint16_t num_auths)
695 {
696         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
697                         (const int *) auths, num_auths);
698 }
699
700 int
701 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
702                 uint16_t num_aeads)
703 {
704         return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
705                         (const int *) aeads, num_aeads);
706 }
707
708 static int
709 null_testsuite_setup(void)
710 {
711         struct crypto_testsuite_params *ts_params = &testsuite_params;
712         uint8_t dev_id = ts_params->valid_devs[0];
713         struct rte_cryptodev_info dev_info;
714         const enum rte_crypto_cipher_algorithm ciphers[] = {
715                 RTE_CRYPTO_CIPHER_NULL
716         };
717         const enum rte_crypto_auth_algorithm auths[] = {
718                 RTE_CRYPTO_AUTH_NULL
719         };
720
721         rte_cryptodev_info_get(dev_id, &dev_info);
722
723         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
724                 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
725                                 "testsuite not met\n");
726                 return TEST_SKIPPED;
727         }
728
729         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
730                         && check_auth_capabilities_supported(auths,
731                         RTE_DIM(auths)) != 0) {
732                 RTE_LOG(INFO, USER1, "Capability requirements for NULL "
733                                 "testsuite not met\n");
734                 return TEST_SKIPPED;
735         }
736
737         return 0;
738 }
739
740 static int
741 crypto_gen_testsuite_setup(void)
742 {
743         struct crypto_testsuite_params *ts_params = &testsuite_params;
744         uint8_t dev_id = ts_params->valid_devs[0];
745         struct rte_cryptodev_info dev_info;
746
747         rte_cryptodev_info_get(dev_id, &dev_info);
748
749         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
750                 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
751                                 "testsuite not met\n");
752                 return TEST_SKIPPED;
753         }
754
755         return 0;
756 }
757
758 #ifdef RTE_LIB_SECURITY
759 static int
760 pdcp_proto_testsuite_setup(void)
761 {
762         struct crypto_testsuite_params *ts_params = &testsuite_params;
763         uint8_t dev_id = ts_params->valid_devs[0];
764         struct rte_cryptodev_info dev_info;
765         const enum rte_crypto_cipher_algorithm ciphers[] = {
766                 RTE_CRYPTO_CIPHER_NULL,
767                 RTE_CRYPTO_CIPHER_AES_CTR,
768                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
769                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
770         };
771         const enum rte_crypto_auth_algorithm auths[] = {
772                 RTE_CRYPTO_AUTH_NULL,
773                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
774                 RTE_CRYPTO_AUTH_AES_CMAC,
775                 RTE_CRYPTO_AUTH_ZUC_EIA3
776         };
777
778         rte_cryptodev_info_get(dev_id, &dev_info);
779
780         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
781                         !(dev_info.feature_flags &
782                         RTE_CRYPTODEV_FF_SECURITY)) {
783                 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
784                                 "testsuite not met\n");
785                 return TEST_SKIPPED;
786         }
787
788         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
789                         && check_auth_capabilities_supported(auths,
790                         RTE_DIM(auths)) != 0) {
791                 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
792                                 "testsuite not met\n");
793                 return TEST_SKIPPED;
794         }
795
796         return 0;
797 }
798
799 static int
800 docsis_proto_testsuite_setup(void)
801 {
802         struct crypto_testsuite_params *ts_params = &testsuite_params;
803         uint8_t dev_id = ts_params->valid_devs[0];
804         struct rte_cryptodev_info dev_info;
805         const enum rte_crypto_cipher_algorithm ciphers[] = {
806                 RTE_CRYPTO_CIPHER_AES_DOCSISBPI
807         };
808
809         rte_cryptodev_info_get(dev_id, &dev_info);
810
811         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
812                         !(dev_info.feature_flags &
813                         RTE_CRYPTODEV_FF_SECURITY)) {
814                 RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis "
815                                 "Proto testsuite not met\n");
816                 return TEST_SKIPPED;
817         }
818
819         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
820                 RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto "
821                                 "testsuite not met\n");
822                 return TEST_SKIPPED;
823         }
824
825         return 0;
826 }
827 #endif
828
829 static int
830 aes_ccm_auth_testsuite_setup(void)
831 {
832         struct crypto_testsuite_params *ts_params = &testsuite_params;
833         uint8_t dev_id = ts_params->valid_devs[0];
834         struct rte_cryptodev_info dev_info;
835         const enum rte_crypto_aead_algorithm aeads[] = {
836                 RTE_CRYPTO_AEAD_AES_CCM
837         };
838
839         rte_cryptodev_info_get(dev_id, &dev_info);
840
841         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
842                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
843                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
844                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
845                                 "testsuite not met\n");
846                 return TEST_SKIPPED;
847         }
848
849         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
850                 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
851                                 "testsuite not met\n");
852                 return TEST_SKIPPED;
853         }
854
855         return 0;
856 }
857
858 static int
859 aes_gcm_auth_testsuite_setup(void)
860 {
861         struct crypto_testsuite_params *ts_params = &testsuite_params;
862         uint8_t dev_id = ts_params->valid_devs[0];
863         struct rte_cryptodev_info dev_info;
864         const enum rte_crypto_aead_algorithm aeads[] = {
865                 RTE_CRYPTO_AEAD_AES_GCM
866         };
867
868         rte_cryptodev_info_get(dev_id, &dev_info);
869
870         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
871                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
872                                 "testsuite not met\n");
873                 return TEST_SKIPPED;
874         }
875
876         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
877                 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
878                                 "testsuite not met\n");
879                 return TEST_SKIPPED;
880         }
881
882         return 0;
883 }
884
885 static int
886 aes_gmac_auth_testsuite_setup(void)
887 {
888         struct crypto_testsuite_params *ts_params = &testsuite_params;
889         uint8_t dev_id = ts_params->valid_devs[0];
890         struct rte_cryptodev_info dev_info;
891         const enum rte_crypto_auth_algorithm auths[] = {
892                 RTE_CRYPTO_AUTH_AES_GMAC
893         };
894
895         rte_cryptodev_info_get(dev_id, &dev_info);
896
897         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
898                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
899                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
900                 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
901                                 "testsuite not met\n");
902                 return TEST_SKIPPED;
903         }
904
905         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
906                 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
907                                 "testsuite not met\n");
908                 return TEST_SKIPPED;
909         }
910
911         return 0;
912 }
913
914 static int
915 chacha20_poly1305_testsuite_setup(void)
916 {
917         struct crypto_testsuite_params *ts_params = &testsuite_params;
918         uint8_t dev_id = ts_params->valid_devs[0];
919         struct rte_cryptodev_info dev_info;
920         const enum rte_crypto_aead_algorithm aeads[] = {
921                 RTE_CRYPTO_AEAD_CHACHA20_POLY1305
922         };
923
924         rte_cryptodev_info_get(dev_id, &dev_info);
925
926         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
927                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
928                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
929                 RTE_LOG(INFO, USER1, "Feature flag requirements for "
930                                 "Chacha20-Poly1305 testsuite not met\n");
931                 return TEST_SKIPPED;
932         }
933
934         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
935                 RTE_LOG(INFO, USER1, "Capability requirements for "
936                                 "Chacha20-Poly1305 testsuite not met\n");
937                 return TEST_SKIPPED;
938         }
939
940         return 0;
941 }
942
943 static int
944 snow3g_testsuite_setup(void)
945 {
946         struct crypto_testsuite_params *ts_params = &testsuite_params;
947         uint8_t dev_id = ts_params->valid_devs[0];
948         struct rte_cryptodev_info dev_info;
949         const enum rte_crypto_cipher_algorithm ciphers[] = {
950                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
951
952         };
953         const enum rte_crypto_auth_algorithm auths[] = {
954                 RTE_CRYPTO_AUTH_SNOW3G_UIA2
955         };
956
957         rte_cryptodev_info_get(dev_id, &dev_info);
958
959         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
960                 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
961                                 "testsuite not met\n");
962                 return TEST_SKIPPED;
963         }
964
965         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
966                         && check_auth_capabilities_supported(auths,
967                         RTE_DIM(auths)) != 0) {
968                 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
969                                 "testsuite not met\n");
970                 return TEST_SKIPPED;
971         }
972
973         return 0;
974 }
975
976 static int
977 zuc_testsuite_setup(void)
978 {
979         struct crypto_testsuite_params *ts_params = &testsuite_params;
980         uint8_t dev_id = ts_params->valid_devs[0];
981         struct rte_cryptodev_info dev_info;
982         const enum rte_crypto_cipher_algorithm ciphers[] = {
983                 RTE_CRYPTO_CIPHER_ZUC_EEA3
984         };
985         const enum rte_crypto_auth_algorithm auths[] = {
986                 RTE_CRYPTO_AUTH_ZUC_EIA3
987         };
988
989         rte_cryptodev_info_get(dev_id, &dev_info);
990
991         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
992                 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
993                                 "testsuite not met\n");
994                 return TEST_SKIPPED;
995         }
996
997         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
998                         && check_auth_capabilities_supported(auths,
999                         RTE_DIM(auths)) != 0) {
1000                 RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1001                                 "testsuite not met\n");
1002                 return TEST_SKIPPED;
1003         }
1004
1005         return 0;
1006 }
1007
1008 static int
1009 hmac_md5_auth_testsuite_setup(void)
1010 {
1011         struct crypto_testsuite_params *ts_params = &testsuite_params;
1012         uint8_t dev_id = ts_params->valid_devs[0];
1013         struct rte_cryptodev_info dev_info;
1014         const enum rte_crypto_auth_algorithm auths[] = {
1015                 RTE_CRYPTO_AUTH_MD5_HMAC
1016         };
1017
1018         rte_cryptodev_info_get(dev_id, &dev_info);
1019
1020         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1021                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1022                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1023                 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1024                                 "Auth testsuite not met\n");
1025                 return TEST_SKIPPED;
1026         }
1027
1028         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1029                 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1030                                 "testsuite not met\n");
1031                 return TEST_SKIPPED;
1032         }
1033
1034         return 0;
1035 }
1036
1037 static int
1038 kasumi_testsuite_setup(void)
1039 {
1040         struct crypto_testsuite_params *ts_params = &testsuite_params;
1041         uint8_t dev_id = ts_params->valid_devs[0];
1042         struct rte_cryptodev_info dev_info;
1043         const enum rte_crypto_cipher_algorithm ciphers[] = {
1044                 RTE_CRYPTO_CIPHER_KASUMI_F8
1045         };
1046         const enum rte_crypto_auth_algorithm auths[] = {
1047                 RTE_CRYPTO_AUTH_KASUMI_F9
1048         };
1049
1050         rte_cryptodev_info_get(dev_id, &dev_info);
1051
1052         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1053                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1054                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1055                 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1056                                 "testsuite not met\n");
1057                 return TEST_SKIPPED;
1058         }
1059
1060         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1061                         && check_auth_capabilities_supported(auths,
1062                         RTE_DIM(auths)) != 0) {
1063                 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1064                                 "testsuite not met\n");
1065                 return TEST_SKIPPED;
1066         }
1067
1068         return 0;
1069 }
1070
1071 static int
1072 negative_aes_gcm_testsuite_setup(void)
1073 {
1074         struct crypto_testsuite_params *ts_params = &testsuite_params;
1075         uint8_t dev_id = ts_params->valid_devs[0];
1076         struct rte_cryptodev_info dev_info;
1077         const enum rte_crypto_aead_algorithm aeads[] = {
1078                 RTE_CRYPTO_AEAD_AES_GCM
1079         };
1080
1081         rte_cryptodev_info_get(dev_id, &dev_info);
1082
1083         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1084                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1085                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1086                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1087                                 "AES GCM testsuite not met\n");
1088                 return TEST_SKIPPED;
1089         }
1090
1091         if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1092                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1093                                 "AES GCM testsuite not met\n");
1094                 return TEST_SKIPPED;
1095         }
1096
1097         return 0;
1098 }
1099
1100 static int
1101 negative_aes_gmac_testsuite_setup(void)
1102 {
1103         struct crypto_testsuite_params *ts_params = &testsuite_params;
1104         uint8_t dev_id = ts_params->valid_devs[0];
1105         struct rte_cryptodev_info dev_info;
1106         const enum rte_crypto_auth_algorithm auths[] = {
1107                 RTE_CRYPTO_AUTH_AES_GMAC
1108         };
1109
1110         rte_cryptodev_info_get(dev_id, &dev_info);
1111
1112         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1113                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1114                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1115                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1116                                 "AES GMAC testsuite not met\n");
1117                 return TEST_SKIPPED;
1118         }
1119
1120         if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1121                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1122                                 "AES GMAC testsuite not met\n");
1123                 return TEST_SKIPPED;
1124         }
1125
1126         return 0;
1127 }
1128
1129 static int
1130 mixed_cipher_hash_testsuite_setup(void)
1131 {
1132         struct crypto_testsuite_params *ts_params = &testsuite_params;
1133         uint8_t dev_id = ts_params->valid_devs[0];
1134         struct rte_cryptodev_info dev_info;
1135         uint64_t feat_flags;
1136         const enum rte_crypto_cipher_algorithm ciphers[] = {
1137                 RTE_CRYPTO_CIPHER_NULL,
1138                 RTE_CRYPTO_CIPHER_AES_CTR,
1139                 RTE_CRYPTO_CIPHER_ZUC_EEA3,
1140                 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1141         };
1142         const enum rte_crypto_auth_algorithm auths[] = {
1143                 RTE_CRYPTO_AUTH_NULL,
1144                 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1145                 RTE_CRYPTO_AUTH_AES_CMAC,
1146                 RTE_CRYPTO_AUTH_ZUC_EIA3
1147         };
1148
1149         rte_cryptodev_info_get(dev_id, &dev_info);
1150         feat_flags = dev_info.feature_flags;
1151
1152         if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1153                         (global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1154                 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1155                                 "Cipher Hash testsuite not met\n");
1156                 return TEST_SKIPPED;
1157         }
1158
1159         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1160                         && check_auth_capabilities_supported(auths,
1161                         RTE_DIM(auths)) != 0) {
1162                 RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1163                                 "Cipher Hash testsuite not met\n");
1164                 return TEST_SKIPPED;
1165         }
1166
1167         return 0;
1168 }
1169
1170 static int
1171 esn_testsuite_setup(void)
1172 {
1173         struct crypto_testsuite_params *ts_params = &testsuite_params;
1174         uint8_t dev_id = ts_params->valid_devs[0];
1175         struct rte_cryptodev_info dev_info;
1176         const enum rte_crypto_cipher_algorithm ciphers[] = {
1177                 RTE_CRYPTO_CIPHER_AES_CBC
1178         };
1179         const enum rte_crypto_auth_algorithm auths[] = {
1180                 RTE_CRYPTO_AUTH_SHA1_HMAC
1181         };
1182
1183         rte_cryptodev_info_get(dev_id, &dev_info);
1184
1185         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1186                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1187                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1188                 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1189                                 "testsuite not met\n");
1190                 return TEST_SKIPPED;
1191         }
1192
1193         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1194                         && check_auth_capabilities_supported(auths,
1195                         RTE_DIM(auths)) != 0) {
1196                 RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1197                                 "testsuite not met\n");
1198                 return TEST_SKIPPED;
1199         }
1200
1201         return 0;
1202 }
1203
1204 static int
1205 multi_session_testsuite_setup(void)
1206 {
1207         struct crypto_testsuite_params *ts_params = &testsuite_params;
1208         uint8_t dev_id = ts_params->valid_devs[0];
1209         struct rte_cryptodev_info dev_info;
1210         const enum rte_crypto_cipher_algorithm ciphers[] = {
1211                 RTE_CRYPTO_CIPHER_AES_CBC
1212         };
1213         const enum rte_crypto_auth_algorithm auths[] = {
1214                 RTE_CRYPTO_AUTH_SHA512_HMAC
1215         };
1216
1217         rte_cryptodev_info_get(dev_id, &dev_info);
1218
1219         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1220                 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1221                                 "Session testsuite not met\n");
1222                 return TEST_SKIPPED;
1223         }
1224
1225         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1226                         && check_auth_capabilities_supported(auths,
1227                         RTE_DIM(auths)) != 0) {
1228                 RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1229                                 "Session testsuite not met\n");
1230                 return TEST_SKIPPED;
1231         }
1232
1233         return 0;
1234 }
1235
1236 static int
1237 negative_hmac_sha1_testsuite_setup(void)
1238 {
1239         struct crypto_testsuite_params *ts_params = &testsuite_params;
1240         uint8_t dev_id = ts_params->valid_devs[0];
1241         struct rte_cryptodev_info dev_info;
1242         const enum rte_crypto_cipher_algorithm ciphers[] = {
1243                 RTE_CRYPTO_CIPHER_AES_CBC
1244         };
1245         const enum rte_crypto_auth_algorithm auths[] = {
1246                 RTE_CRYPTO_AUTH_SHA1_HMAC
1247         };
1248
1249         rte_cryptodev_info_get(dev_id, &dev_info);
1250
1251         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1252                         ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1253                         !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1254                 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1255                                 "HMAC SHA1 testsuite not met\n");
1256                 return TEST_SKIPPED;
1257         }
1258
1259         if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1260                         && check_auth_capabilities_supported(auths,
1261                         RTE_DIM(auths)) != 0) {
1262                 RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1263                                 "HMAC SHA1 testsuite not met\n");
1264                 return TEST_SKIPPED;
1265         }
1266
1267         return 0;
1268 }
1269
1270 static int
1271 dev_configure_and_start(uint64_t ff_disable)
1272 {
1273         struct crypto_testsuite_params *ts_params = &testsuite_params;
1274         struct crypto_unittest_params *ut_params = &unittest_params;
1275
1276         uint16_t qp_id;
1277
1278         /* Clear unit test parameters before running test */
1279         memset(ut_params, 0, sizeof(*ut_params));
1280
1281         /* Reconfigure device to default parameters */
1282         ts_params->conf.socket_id = SOCKET_ID_ANY;
1283         ts_params->conf.ff_disable = ff_disable;
1284         ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1285         ts_params->qp_conf.mp_session = ts_params->session_mpool;
1286         ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1287
1288         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1289                         &ts_params->conf),
1290                         "Failed to configure cryptodev %u",
1291                         ts_params->valid_devs[0]);
1292
1293         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1294                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1295                         ts_params->valid_devs[0], qp_id,
1296                         &ts_params->qp_conf,
1297                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1298                         "Failed to setup queue pair %u on cryptodev %u",
1299                         qp_id, ts_params->valid_devs[0]);
1300         }
1301
1302
1303         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1304
1305         /* Start the device */
1306         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1307                         "Failed to start cryptodev %u",
1308                         ts_params->valid_devs[0]);
1309
1310         return TEST_SUCCESS;
1311 }
1312
1313 int
1314 ut_setup(void)
1315 {
1316         /* Configure and start the device with security feature disabled */
1317         return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1318 }
1319
1320 static int
1321 ut_setup_security(void)
1322 {
1323         /* Configure and start the device with no features disabled */
1324         return dev_configure_and_start(0);
1325 }
1326
1327 void
1328 ut_teardown(void)
1329 {
1330         struct crypto_testsuite_params *ts_params = &testsuite_params;
1331         struct crypto_unittest_params *ut_params = &unittest_params;
1332         struct rte_cryptodev_stats stats;
1333
1334         /* free crypto session structure */
1335 #ifdef RTE_LIB_SECURITY
1336         if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1337                 if (ut_params->sec_session) {
1338                         rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1339                                                 (ts_params->valid_devs[0]),
1340                                                 ut_params->sec_session);
1341                         ut_params->sec_session = NULL;
1342                 }
1343         } else
1344 #endif
1345         {
1346                 if (ut_params->sess) {
1347                         rte_cryptodev_sym_session_clear(
1348                                         ts_params->valid_devs[0],
1349                                         ut_params->sess);
1350                         rte_cryptodev_sym_session_free(ut_params->sess);
1351                         ut_params->sess = NULL;
1352                 }
1353         }
1354
1355         /* free crypto operation structure */
1356         if (ut_params->op)
1357                 rte_crypto_op_free(ut_params->op);
1358
1359         /*
1360          * free mbuf - both obuf and ibuf are usually the same,
1361          * so check if they point at the same address is necessary,
1362          * to avoid freeing the mbuf twice.
1363          */
1364         if (ut_params->obuf) {
1365                 rte_pktmbuf_free(ut_params->obuf);
1366                 if (ut_params->ibuf == ut_params->obuf)
1367                         ut_params->ibuf = 0;
1368                 ut_params->obuf = 0;
1369         }
1370         if (ut_params->ibuf) {
1371                 rte_pktmbuf_free(ut_params->ibuf);
1372                 ut_params->ibuf = 0;
1373         }
1374
1375         if (ts_params->mbuf_pool != NULL)
1376                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1377                         rte_mempool_avail_count(ts_params->mbuf_pool));
1378
1379         rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1380
1381         /* Stop the device */
1382         rte_cryptodev_stop(ts_params->valid_devs[0]);
1383 }
1384
1385 static int
1386 test_device_configure_invalid_dev_id(void)
1387 {
1388         struct crypto_testsuite_params *ts_params = &testsuite_params;
1389         uint16_t dev_id, num_devs = 0;
1390
1391         TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1392                         "Need at least %d devices for test", 1);
1393
1394         /* valid dev_id values */
1395         dev_id = ts_params->valid_devs[0];
1396
1397         /* Stop the device in case it's started so it can be configured */
1398         rte_cryptodev_stop(dev_id);
1399
1400         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1401                         "Failed test for rte_cryptodev_configure: "
1402                         "invalid dev_num %u", dev_id);
1403
1404         /* invalid dev_id values */
1405         dev_id = num_devs;
1406
1407         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1408                         "Failed test for rte_cryptodev_configure: "
1409                         "invalid dev_num %u", dev_id);
1410
1411         dev_id = 0xff;
1412
1413         TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1414                         "Failed test for rte_cryptodev_configure:"
1415                         "invalid dev_num %u", dev_id);
1416
1417         return TEST_SUCCESS;
1418 }
1419
1420 static int
1421 test_device_configure_invalid_queue_pair_ids(void)
1422 {
1423         struct crypto_testsuite_params *ts_params = &testsuite_params;
1424         uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1425
1426         /* Stop the device in case it's started so it can be configured */
1427         rte_cryptodev_stop(ts_params->valid_devs[0]);
1428
1429         /* valid - max value queue pairs */
1430         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1431
1432         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1433                         &ts_params->conf),
1434                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1435                         ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1436
1437         /* valid - one queue pairs */
1438         ts_params->conf.nb_queue_pairs = 1;
1439
1440         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1441                         &ts_params->conf),
1442                         "Failed to configure cryptodev: dev_id %u, qp_id %u",
1443                         ts_params->valid_devs[0],
1444                         ts_params->conf.nb_queue_pairs);
1445
1446
1447         /* invalid - zero queue pairs */
1448         ts_params->conf.nb_queue_pairs = 0;
1449
1450         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1451                         &ts_params->conf),
1452                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1453                         " invalid qps: %u",
1454                         ts_params->valid_devs[0],
1455                         ts_params->conf.nb_queue_pairs);
1456
1457
1458         /* invalid - max value supported by field queue pairs */
1459         ts_params->conf.nb_queue_pairs = UINT16_MAX;
1460
1461         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1462                         &ts_params->conf),
1463                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1464                         " invalid qps: %u",
1465                         ts_params->valid_devs[0],
1466                         ts_params->conf.nb_queue_pairs);
1467
1468
1469         /* invalid - max value + 1 queue pairs */
1470         ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1471
1472         TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1473                         &ts_params->conf),
1474                         "Failed test for rte_cryptodev_configure, dev_id %u,"
1475                         " invalid qps: %u",
1476                         ts_params->valid_devs[0],
1477                         ts_params->conf.nb_queue_pairs);
1478
1479         /* revert to original testsuite value */
1480         ts_params->conf.nb_queue_pairs = orig_nb_qps;
1481
1482         return TEST_SUCCESS;
1483 }
1484
1485 static int
1486 test_queue_pair_descriptor_setup(void)
1487 {
1488         struct crypto_testsuite_params *ts_params = &testsuite_params;
1489         struct rte_cryptodev_qp_conf qp_conf = {
1490                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
1491         };
1492         uint16_t qp_id;
1493
1494         /* Stop the device in case it's started so it can be configured */
1495         rte_cryptodev_stop(ts_params->valid_devs[0]);
1496
1497         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1498                         &ts_params->conf),
1499                         "Failed to configure cryptodev %u",
1500                         ts_params->valid_devs[0]);
1501
1502         /*
1503          * Test various ring sizes on this device. memzones can't be
1504          * freed so are re-used if ring is released and re-created.
1505          */
1506         qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1507         qp_conf.mp_session = ts_params->session_mpool;
1508         qp_conf.mp_session_private = ts_params->session_priv_mpool;
1509
1510         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1511                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1512                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1513                                 rte_cryptodev_socket_id(
1514                                                 ts_params->valid_devs[0])),
1515                                 "Failed test for "
1516                                 "rte_cryptodev_queue_pair_setup: num_inflights "
1517                                 "%u on qp %u on cryptodev %u",
1518                                 qp_conf.nb_descriptors, qp_id,
1519                                 ts_params->valid_devs[0]);
1520         }
1521
1522         qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1523
1524         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1525                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1526                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1527                                 rte_cryptodev_socket_id(
1528                                                 ts_params->valid_devs[0])),
1529                                 "Failed test for"
1530                                 " rte_cryptodev_queue_pair_setup: num_inflights"
1531                                 " %u on qp %u on cryptodev %u",
1532                                 qp_conf.nb_descriptors, qp_id,
1533                                 ts_params->valid_devs[0]);
1534         }
1535
1536         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1537
1538         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1539                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1540                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1541                                 rte_cryptodev_socket_id(
1542                                                 ts_params->valid_devs[0])),
1543                                 "Failed test for "
1544                                 "rte_cryptodev_queue_pair_setup: num_inflights"
1545                                 " %u on qp %u on cryptodev %u",
1546                                 qp_conf.nb_descriptors, qp_id,
1547                                 ts_params->valid_devs[0]);
1548         }
1549
1550         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1551
1552         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1553                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1554                                 ts_params->valid_devs[0], qp_id, &qp_conf,
1555                                 rte_cryptodev_socket_id(
1556                                                 ts_params->valid_devs[0])),
1557                                 "Failed test for"
1558                                 " rte_cryptodev_queue_pair_setup:"
1559                                 "num_inflights %u on qp %u on cryptodev %u",
1560                                 qp_conf.nb_descriptors, qp_id,
1561                                 ts_params->valid_devs[0]);
1562         }
1563
1564         /* test invalid queue pair id */
1565         qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;      /*valid */
1566
1567         qp_id = ts_params->conf.nb_queue_pairs;         /*invalid */
1568
1569         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1570                         ts_params->valid_devs[0],
1571                         qp_id, &qp_conf,
1572                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1573                         "Failed test for rte_cryptodev_queue_pair_setup:"
1574                         "invalid qp %u on cryptodev %u",
1575                         qp_id, ts_params->valid_devs[0]);
1576
1577         qp_id = 0xffff; /*invalid*/
1578
1579         TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1580                         ts_params->valid_devs[0],
1581                         qp_id, &qp_conf,
1582                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1583                         "Failed test for rte_cryptodev_queue_pair_setup:"
1584                         "invalid qp %u on cryptodev %u",
1585                         qp_id, ts_params->valid_devs[0]);
1586
1587         return TEST_SUCCESS;
1588 }
1589
1590 /* ***** Plaintext data for tests ***** */
1591
1592 const char catch_22_quote_1[] =
1593                 "There was only one catch and that was Catch-22, which "
1594                 "specified that a concern for one's safety in the face of "
1595                 "dangers that were real and immediate was the process of a "
1596                 "rational mind. Orr was crazy and could be grounded. All he "
1597                 "had to do was ask; and as soon as he did, he would no longer "
1598                 "be crazy and would have to fly more missions. Orr would be "
1599                 "crazy to fly more missions and sane if he didn't, but if he "
1600                 "was sane he had to fly them. If he flew them he was crazy "
1601                 "and didn't have to; but if he didn't want to he was sane and "
1602                 "had to. Yossarian was moved very deeply by the absolute "
1603                 "simplicity of this clause of Catch-22 and let out a "
1604                 "respectful whistle. \"That's some catch, that Catch-22\", he "
1605                 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
1606
1607 const char catch_22_quote[] =
1608                 "What a lousy earth! He wondered how many people were "
1609                 "destitute that same night even in his own prosperous country, "
1610                 "how many homes were shanties, how many husbands were drunk "
1611                 "and wives socked, and how many children were bullied, abused, "
1612                 "or abandoned. How many families hungered for food they could "
1613                 "not afford to buy? How many hearts were broken? How many "
1614                 "suicides would take place that same night, how many people "
1615                 "would go insane? How many cockroaches and landlords would "
1616                 "triumph? How many winners were losers, successes failures, "
1617                 "and rich men poor men? How many wise guys were stupid? How "
1618                 "many happy endings were unhappy endings? How many honest men "
1619                 "were liars, brave men cowards, loyal men traitors, how many "
1620                 "sainted men were corrupt, how many people in positions of "
1621                 "trust had sold their souls to bodyguards, how many had never "
1622                 "had souls? How many straight-and-narrow paths were crooked "
1623                 "paths? How many best families were worst families and how "
1624                 "many good people were bad people? When you added them all up "
1625                 "and then subtracted, you might be left with only the children, "
1626                 "and perhaps with Albert Einstein and an old violinist or "
1627                 "sculptor somewhere.";
1628
1629 #define QUOTE_480_BYTES         (480)
1630 #define QUOTE_512_BYTES         (512)
1631 #define QUOTE_768_BYTES         (768)
1632 #define QUOTE_1024_BYTES        (1024)
1633
1634
1635
1636 /* ***** SHA1 Hash Tests ***** */
1637
1638 #define HMAC_KEY_LENGTH_SHA1    (DIGEST_BYTE_LENGTH_SHA1)
1639
1640 static uint8_t hmac_sha1_key[] = {
1641         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1642         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1643         0xDE, 0xF4, 0xDE, 0xAD };
1644
1645 /* ***** SHA224 Hash Tests ***** */
1646
1647 #define HMAC_KEY_LENGTH_SHA224  (DIGEST_BYTE_LENGTH_SHA224)
1648
1649
1650 /* ***** AES-CBC Cipher Tests ***** */
1651
1652 #define CIPHER_KEY_LENGTH_AES_CBC       (16)
1653 #define CIPHER_IV_LENGTH_AES_CBC        (CIPHER_KEY_LENGTH_AES_CBC)
1654
1655 static uint8_t aes_cbc_key[] = {
1656         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1657         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1658
1659 static uint8_t aes_cbc_iv[] = {
1660         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1661         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1662
1663
1664 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1665
1666 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1667         0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1668         0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1669         0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1670         0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1671         0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1672         0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1673         0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1674         0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1675         0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1676         0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1677         0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1678         0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1679         0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1680         0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1681         0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1682         0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1683         0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1684         0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1685         0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1686         0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1687         0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1688         0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1689         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1690         0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1691         0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1692         0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1693         0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1694         0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1695         0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1696         0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1697         0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1698         0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1699         0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1700         0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1701         0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1702         0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1703         0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1704         0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1705         0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1706         0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1707         0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1708         0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1709         0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1710         0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1711         0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1712         0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1713         0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1714         0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1715         0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1716         0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1717         0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1718         0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1719         0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1720         0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1721         0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1722         0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1723         0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1724         0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1725         0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1726         0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1727         0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1728         0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1729         0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1730         0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1731 };
1732
1733 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1734         0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1735         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1736         0x18, 0x8c, 0x1d, 0x32
1737 };
1738
1739
1740 /* Multisession Vector context Test */
1741 /*Begin Session 0 */
1742 static uint8_t ms_aes_cbc_key0[] = {
1743         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1744         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1745 };
1746
1747 static uint8_t ms_aes_cbc_iv0[] = {
1748         0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1749         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1750 };
1751
1752 static const uint8_t ms_aes_cbc_cipher0[] = {
1753                 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1754                 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1755                 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1756                 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1757                 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1758                 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1759                 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1760                 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1761                 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1762                 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1763                 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1764                 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1765                 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1766                 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1767                 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1768                 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1769                 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1770                 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1771                 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1772                 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1773                 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1774                 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1775                 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1776                 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1777                 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1778                 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1779                 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1780                 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1781                 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1782                 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1783                 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1784                 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1785                 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1786                 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1787                 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1788                 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1789                 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1790                 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1791                 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1792                 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1793                 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1794                 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1795                 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1796                 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1797                 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1798                 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1799                 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1800                 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1801                 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1802                 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1803                 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1804                 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1805                 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1806                 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1807                 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1808                 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1809                 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1810                 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1811                 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1812                 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1813                 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1814                 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1815                 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1816                 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1817 };
1818
1819
1820 static  uint8_t ms_hmac_key0[] = {
1821                 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1822                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1823                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1824                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1825                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1826                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1827                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1828                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1829 };
1830
1831 static const uint8_t ms_hmac_digest0[] = {
1832                 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1833                 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1834                 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1835                 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1836                 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1837                 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1838                 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1839                 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1840                 };
1841
1842 /* End Session 0 */
1843 /* Begin session 1 */
1844
1845 static  uint8_t ms_aes_cbc_key1[] = {
1846                 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1847                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1848 };
1849
1850 static  uint8_t ms_aes_cbc_iv1[] = {
1851         0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1852         0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1853 };
1854
1855 static const uint8_t ms_aes_cbc_cipher1[] = {
1856                 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1857                 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1858                 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1859                 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1860                 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1861                 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1862                 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1863                 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1864                 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1865                 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1866                 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1867                 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1868                 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1869                 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1870                 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1871                 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1872                 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1873                 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1874                 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1875                 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1876                 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1877                 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1878                 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1879                 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1880                 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1881                 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1882                 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1883                 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1884                 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1885                 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1886                 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1887                 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1888                 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1889                 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1890                 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1891                 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1892                 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1893                 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1894                 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1895                 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1896                 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1897                 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1898                 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1899                 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1900                 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1901                 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1902                 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1903                 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1904                 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1905                 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1906                 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1907                 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1908                 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1909                 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1910                 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1911                 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1912                 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1913                 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1914                 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1915                 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1916                 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1917                 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1918                 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1919                 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1920
1921 };
1922
1923 static uint8_t ms_hmac_key1[] = {
1924                 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1925                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1926                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1927                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1928                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1929                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1930                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1931                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1932 };
1933
1934 static const uint8_t ms_hmac_digest1[] = {
1935                 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1936                 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1937                 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1938                 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1939                 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1940                 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1941                 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1942                 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1943 };
1944 /* End Session 1  */
1945 /* Begin Session 2 */
1946 static  uint8_t ms_aes_cbc_key2[] = {
1947                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1948                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1949 };
1950
1951 static  uint8_t ms_aes_cbc_iv2[] = {
1952                 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1953                 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1954 };
1955
1956 static const uint8_t ms_aes_cbc_cipher2[] = {
1957                 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1958                 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1959                 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1960                 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1961                 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1962                 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1963                 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1964                 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1965                 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1966                 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1967                 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1968                 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1969                 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1970                 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1971                 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1972                 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1973                 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1974                 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1975                 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1976                 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1977                 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1978                 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1979                 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1980                 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1981                 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1982                 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1983                 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1984                 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1985                 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1986                 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1987                 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1988                 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1989                 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1990                 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1991                 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1992                 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1993                 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1994                 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1995                 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1996                 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1997                 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1998                 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1999                 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2000                 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2001                 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2002                 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2003                 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2004                 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2005                 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2006                 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2007                 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2008                 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2009                 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2010                 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2011                 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2012                 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2013                 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2014                 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2015                 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2016                 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2017                 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2018                 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2019                 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2020                 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2021 };
2022
2023 static  uint8_t ms_hmac_key2[] = {
2024                 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2025                 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2026                 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2027                 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2028                 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2029                 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2030                 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2031                 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2032 };
2033
2034 static const uint8_t ms_hmac_digest2[] = {
2035                 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2036                 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2037                 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2038                 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2039                 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2040                 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2041                 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2042                 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2043 };
2044
2045 /* End Session 2 */
2046
2047
2048 static int
2049 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2050 {
2051         struct crypto_testsuite_params *ts_params = &testsuite_params;
2052         struct crypto_unittest_params *ut_params = &unittest_params;
2053
2054         /* Verify the capabilities */
2055         struct rte_cryptodev_sym_capability_idx cap_idx;
2056         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2057         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2058         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2059                         &cap_idx) == NULL)
2060                 return TEST_SKIPPED;
2061         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2062         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2063         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2064                         &cap_idx) == NULL)
2065                 return TEST_SKIPPED;
2066
2067         /* Generate test mbuf data and space for digest */
2068         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2069                         catch_22_quote, QUOTE_512_BYTES, 0);
2070
2071         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2072                         DIGEST_BYTE_LENGTH_SHA1);
2073         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2074
2075         /* Setup Cipher Parameters */
2076         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2077         ut_params->cipher_xform.next = &ut_params->auth_xform;
2078
2079         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2080         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2081         ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2082         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2083         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2084         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2085
2086         /* Setup HMAC Parameters */
2087         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2088
2089         ut_params->auth_xform.next = NULL;
2090
2091         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2092         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2093         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2094         ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2095         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2096
2097         ut_params->sess = rte_cryptodev_sym_session_create(
2098                         ts_params->session_mpool);
2099
2100         /* Create crypto session*/
2101         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2102                         ut_params->sess, &ut_params->cipher_xform,
2103                         ts_params->session_priv_mpool);
2104         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2105
2106         /* Generate crypto op data structure */
2107         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2108                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2109         TEST_ASSERT_NOT_NULL(ut_params->op,
2110                         "Failed to allocate symmetric crypto operation struct");
2111
2112         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2113
2114         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2115
2116         /* set crypto operation source mbuf */
2117         sym_op->m_src = ut_params->ibuf;
2118
2119         /* Set crypto operation authentication parameters */
2120         sym_op->auth.digest.data = ut_params->digest;
2121         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2122                         ut_params->ibuf, QUOTE_512_BYTES);
2123
2124         sym_op->auth.data.offset = 0;
2125         sym_op->auth.data.length = QUOTE_512_BYTES;
2126
2127         /* Copy IV at the end of the crypto operation */
2128         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2129                         aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2130
2131         /* Set crypto operation cipher parameters */
2132         sym_op->cipher.data.offset = 0;
2133         sym_op->cipher.data.length = QUOTE_512_BYTES;
2134
2135         /* Process crypto operation */
2136         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2137                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2138                         ut_params->op);
2139         else
2140                 TEST_ASSERT_NOT_NULL(
2141                         process_crypto_request(ts_params->valid_devs[0],
2142                                 ut_params->op),
2143                                 "failed to process sym crypto op");
2144
2145         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2146                         "crypto op processing failed");
2147
2148         /* Validate obuf */
2149         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2150                         uint8_t *);
2151
2152         TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2153                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2154                         QUOTE_512_BYTES,
2155                         "ciphertext data not as expected");
2156
2157         uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2158
2159         TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2160                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2161                         gbl_driver_id == rte_cryptodev_driver_id_get(
2162                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2163                                         TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2164                                         DIGEST_BYTE_LENGTH_SHA1,
2165                         "Generated digest data not as expected");
2166
2167         return TEST_SUCCESS;
2168 }
2169
2170 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2171
2172 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2173
2174 static uint8_t hmac_sha512_key[] = {
2175         0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2176         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2177         0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2178         0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2179         0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2180         0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2181         0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2182         0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2183
2184 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2185         0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2186         0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2187         0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2188         0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2189         0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2190         0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2191         0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2192         0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2193
2194
2195
2196 static int
2197 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2198                 struct crypto_unittest_params *ut_params,
2199                 uint8_t *cipher_key,
2200                 uint8_t *hmac_key);
2201
2202 static int
2203 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2204                 struct crypto_unittest_params *ut_params,
2205                 struct crypto_testsuite_params *ts_params,
2206                 const uint8_t *cipher,
2207                 const uint8_t *digest,
2208                 const uint8_t *iv);
2209
2210
2211 static int
2212 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2213                 struct crypto_unittest_params *ut_params,
2214                 uint8_t *cipher_key,
2215                 uint8_t *hmac_key)
2216 {
2217
2218         /* Setup Cipher Parameters */
2219         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2220         ut_params->cipher_xform.next = NULL;
2221
2222         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2223         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2224         ut_params->cipher_xform.cipher.key.data = cipher_key;
2225         ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2226         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2227         ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2228
2229         /* Setup HMAC Parameters */
2230         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2231         ut_params->auth_xform.next = &ut_params->cipher_xform;
2232
2233         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2234         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2235         ut_params->auth_xform.auth.key.data = hmac_key;
2236         ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2237         ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2238
2239         return TEST_SUCCESS;
2240 }
2241
2242
2243 static int
2244 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2245                 struct crypto_unittest_params *ut_params,
2246                 struct crypto_testsuite_params *ts_params,
2247                 const uint8_t *cipher,
2248                 const uint8_t *digest,
2249                 const uint8_t *iv)
2250 {
2251         /* Generate test mbuf data and digest */
2252         ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2253                         (const char *)
2254                         cipher,
2255                         QUOTE_512_BYTES, 0);
2256
2257         ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2258                         DIGEST_BYTE_LENGTH_SHA512);
2259         TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2260
2261         rte_memcpy(ut_params->digest,
2262                         digest,
2263                         DIGEST_BYTE_LENGTH_SHA512);
2264
2265         /* Generate Crypto op data structure */
2266         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2267                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2268         TEST_ASSERT_NOT_NULL(ut_params->op,
2269                         "Failed to allocate symmetric crypto operation struct");
2270
2271         rte_crypto_op_attach_sym_session(ut_params->op, sess);
2272
2273         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2274
2275         /* set crypto operation source mbuf */
2276         sym_op->m_src = ut_params->ibuf;
2277
2278         sym_op->auth.digest.data = ut_params->digest;
2279         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2280                         ut_params->ibuf, QUOTE_512_BYTES);
2281
2282         sym_op->auth.data.offset = 0;
2283         sym_op->auth.data.length = QUOTE_512_BYTES;
2284
2285         /* Copy IV at the end of the crypto operation */
2286         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2287                         iv, CIPHER_IV_LENGTH_AES_CBC);
2288
2289         sym_op->cipher.data.offset = 0;
2290         sym_op->cipher.data.length = QUOTE_512_BYTES;
2291
2292         /* Process crypto operation */
2293         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2294                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2295                         ut_params->op);
2296         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2297                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2298                                 ut_params->op, 1, 1, 0, 0);
2299         else
2300                 TEST_ASSERT_NOT_NULL(
2301                                 process_crypto_request(ts_params->valid_devs[0],
2302                                         ut_params->op),
2303                                         "failed to process sym crypto op");
2304
2305         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2306                         "crypto op processing failed");
2307
2308         ut_params->obuf = ut_params->op->sym->m_src;
2309
2310         /* Validate obuf */
2311         TEST_ASSERT_BUFFERS_ARE_EQUAL(
2312                         rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2313                         catch_22_quote,
2314                         QUOTE_512_BYTES,
2315                         "Plaintext data not as expected");
2316
2317         /* Validate obuf */
2318         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2319                         "Digest verification failed");
2320
2321         return TEST_SUCCESS;
2322 }
2323
2324 /* ***** SNOW 3G Tests ***** */
2325 static int
2326 create_wireless_algo_hash_session(uint8_t dev_id,
2327         const uint8_t *key, const uint8_t key_len,
2328         const uint8_t iv_len, const uint8_t auth_len,
2329         enum rte_crypto_auth_operation op,
2330         enum rte_crypto_auth_algorithm algo)
2331 {
2332         uint8_t hash_key[key_len];
2333         int status;
2334
2335         struct crypto_testsuite_params *ts_params = &testsuite_params;
2336         struct crypto_unittest_params *ut_params = &unittest_params;
2337
2338         memcpy(hash_key, key, key_len);
2339
2340         debug_hexdump(stdout, "key:", key, key_len);
2341
2342         /* Setup Authentication Parameters */
2343         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2344         ut_params->auth_xform.next = NULL;
2345
2346         ut_params->auth_xform.auth.op = op;
2347         ut_params->auth_xform.auth.algo = algo;
2348         ut_params->auth_xform.auth.key.length = key_len;
2349         ut_params->auth_xform.auth.key.data = hash_key;
2350         ut_params->auth_xform.auth.digest_length = auth_len;
2351         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2352         ut_params->auth_xform.auth.iv.length = iv_len;
2353         ut_params->sess = rte_cryptodev_sym_session_create(
2354                         ts_params->session_mpool);
2355
2356         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2357                         &ut_params->auth_xform,
2358                         ts_params->session_priv_mpool);
2359         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2360         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2361         return 0;
2362 }
2363
2364 static int
2365 create_wireless_algo_cipher_session(uint8_t dev_id,
2366                         enum rte_crypto_cipher_operation op,
2367                         enum rte_crypto_cipher_algorithm algo,
2368                         const uint8_t *key, const uint8_t key_len,
2369                         uint8_t iv_len)
2370 {
2371         uint8_t cipher_key[key_len];
2372         int status;
2373         struct crypto_testsuite_params *ts_params = &testsuite_params;
2374         struct crypto_unittest_params *ut_params = &unittest_params;
2375
2376         memcpy(cipher_key, key, key_len);
2377
2378         /* Setup Cipher Parameters */
2379         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2380         ut_params->cipher_xform.next = NULL;
2381
2382         ut_params->cipher_xform.cipher.algo = algo;
2383         ut_params->cipher_xform.cipher.op = op;
2384         ut_params->cipher_xform.cipher.key.data = cipher_key;
2385         ut_params->cipher_xform.cipher.key.length = key_len;
2386         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2387         ut_params->cipher_xform.cipher.iv.length = iv_len;
2388
2389         debug_hexdump(stdout, "key:", key, key_len);
2390
2391         /* Create Crypto session */
2392         ut_params->sess = rte_cryptodev_sym_session_create(
2393                         ts_params->session_mpool);
2394
2395         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2396                         &ut_params->cipher_xform,
2397                         ts_params->session_priv_mpool);
2398         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2399         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2400         return 0;
2401 }
2402
2403 static int
2404 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2405                         unsigned int cipher_len,
2406                         unsigned int cipher_offset)
2407 {
2408         struct crypto_testsuite_params *ts_params = &testsuite_params;
2409         struct crypto_unittest_params *ut_params = &unittest_params;
2410
2411         /* Generate Crypto op data structure */
2412         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2413                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2414         TEST_ASSERT_NOT_NULL(ut_params->op,
2415                                 "Failed to allocate pktmbuf offload");
2416
2417         /* Set crypto operation data parameters */
2418         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2419
2420         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2421
2422         /* set crypto operation source mbuf */
2423         sym_op->m_src = ut_params->ibuf;
2424
2425         /* iv */
2426         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2427                         iv, iv_len);
2428         sym_op->cipher.data.length = cipher_len;
2429         sym_op->cipher.data.offset = cipher_offset;
2430         return 0;
2431 }
2432
2433 static int
2434 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2435                         unsigned int cipher_len,
2436                         unsigned int cipher_offset)
2437 {
2438         struct crypto_testsuite_params *ts_params = &testsuite_params;
2439         struct crypto_unittest_params *ut_params = &unittest_params;
2440
2441         /* Generate Crypto op data structure */
2442         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2443                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2444         TEST_ASSERT_NOT_NULL(ut_params->op,
2445                                 "Failed to allocate pktmbuf offload");
2446
2447         /* Set crypto operation data parameters */
2448         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2449
2450         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2451
2452         /* set crypto operation source mbuf */
2453         sym_op->m_src = ut_params->ibuf;
2454         sym_op->m_dst = ut_params->obuf;
2455
2456         /* iv */
2457         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2458                         iv, iv_len);
2459         sym_op->cipher.data.length = cipher_len;
2460         sym_op->cipher.data.offset = cipher_offset;
2461         return 0;
2462 }
2463
2464 static int
2465 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2466                 enum rte_crypto_cipher_operation cipher_op,
2467                 enum rte_crypto_auth_operation auth_op,
2468                 enum rte_crypto_auth_algorithm auth_algo,
2469                 enum rte_crypto_cipher_algorithm cipher_algo,
2470                 const uint8_t *key, uint8_t key_len,
2471                 uint8_t auth_iv_len, uint8_t auth_len,
2472                 uint8_t cipher_iv_len)
2473
2474 {
2475         uint8_t cipher_auth_key[key_len];
2476         int status;
2477
2478         struct crypto_testsuite_params *ts_params = &testsuite_params;
2479         struct crypto_unittest_params *ut_params = &unittest_params;
2480
2481         memcpy(cipher_auth_key, key, key_len);
2482
2483         /* Setup Authentication Parameters */
2484         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2485         ut_params->auth_xform.next = NULL;
2486
2487         ut_params->auth_xform.auth.op = auth_op;
2488         ut_params->auth_xform.auth.algo = auth_algo;
2489         ut_params->auth_xform.auth.key.length = key_len;
2490         /* Hash key = cipher key */
2491         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2492         ut_params->auth_xform.auth.digest_length = auth_len;
2493         /* Auth IV will be after cipher IV */
2494         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2495         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2496
2497         /* Setup Cipher Parameters */
2498         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2499         ut_params->cipher_xform.next = &ut_params->auth_xform;
2500
2501         ut_params->cipher_xform.cipher.algo = cipher_algo;
2502         ut_params->cipher_xform.cipher.op = cipher_op;
2503         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2504         ut_params->cipher_xform.cipher.key.length = key_len;
2505         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2506         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2507
2508         debug_hexdump(stdout, "key:", key, key_len);
2509
2510         /* Create Crypto session*/
2511         ut_params->sess = rte_cryptodev_sym_session_create(
2512                         ts_params->session_mpool);
2513         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2514
2515         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2516                         &ut_params->cipher_xform,
2517                         ts_params->session_priv_mpool);
2518         if (status == -ENOTSUP)
2519                 return TEST_SKIPPED;
2520
2521         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2522         return 0;
2523 }
2524
2525 static int
2526 create_wireless_cipher_auth_session(uint8_t dev_id,
2527                 enum rte_crypto_cipher_operation cipher_op,
2528                 enum rte_crypto_auth_operation auth_op,
2529                 enum rte_crypto_auth_algorithm auth_algo,
2530                 enum rte_crypto_cipher_algorithm cipher_algo,
2531                 const struct wireless_test_data *tdata)
2532 {
2533         const uint8_t key_len = tdata->key.len;
2534         uint8_t cipher_auth_key[key_len];
2535         int status;
2536
2537         struct crypto_testsuite_params *ts_params = &testsuite_params;
2538         struct crypto_unittest_params *ut_params = &unittest_params;
2539         const uint8_t *key = tdata->key.data;
2540         const uint8_t auth_len = tdata->digest.len;
2541         uint8_t cipher_iv_len = tdata->cipher_iv.len;
2542         uint8_t auth_iv_len = tdata->auth_iv.len;
2543
2544         memcpy(cipher_auth_key, key, key_len);
2545
2546         /* Setup Authentication Parameters */
2547         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2548         ut_params->auth_xform.next = NULL;
2549
2550         ut_params->auth_xform.auth.op = auth_op;
2551         ut_params->auth_xform.auth.algo = auth_algo;
2552         ut_params->auth_xform.auth.key.length = key_len;
2553         /* Hash key = cipher key */
2554         ut_params->auth_xform.auth.key.data = cipher_auth_key;
2555         ut_params->auth_xform.auth.digest_length = auth_len;
2556         /* Auth IV will be after cipher IV */
2557         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2558         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2559
2560         /* Setup Cipher Parameters */
2561         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2562         ut_params->cipher_xform.next = &ut_params->auth_xform;
2563
2564         ut_params->cipher_xform.cipher.algo = cipher_algo;
2565         ut_params->cipher_xform.cipher.op = cipher_op;
2566         ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2567         ut_params->cipher_xform.cipher.key.length = key_len;
2568         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2569         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2570
2571
2572         debug_hexdump(stdout, "key:", key, key_len);
2573
2574         /* Create Crypto session*/
2575         ut_params->sess = rte_cryptodev_sym_session_create(
2576                         ts_params->session_mpool);
2577
2578         status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2579                         &ut_params->cipher_xform,
2580                         ts_params->session_priv_mpool);
2581         if (status == -ENOTSUP)
2582                 return TEST_SKIPPED;
2583
2584         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2585         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2586         return 0;
2587 }
2588
2589 static int
2590 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2591                 const struct wireless_test_data *tdata)
2592 {
2593         return create_wireless_cipher_auth_session(dev_id,
2594                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2595                 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2596                 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2597 }
2598
2599 static int
2600 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2601                 enum rte_crypto_cipher_operation cipher_op,
2602                 enum rte_crypto_auth_operation auth_op,
2603                 enum rte_crypto_auth_algorithm auth_algo,
2604                 enum rte_crypto_cipher_algorithm cipher_algo,
2605                 const uint8_t *key, const uint8_t key_len,
2606                 uint8_t auth_iv_len, uint8_t auth_len,
2607                 uint8_t cipher_iv_len)
2608 {
2609         uint8_t auth_cipher_key[key_len];
2610         int status;
2611         struct crypto_testsuite_params *ts_params = &testsuite_params;
2612         struct crypto_unittest_params *ut_params = &unittest_params;
2613
2614         memcpy(auth_cipher_key, key, key_len);
2615
2616         /* Setup Authentication Parameters */
2617         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2618         ut_params->auth_xform.auth.op = auth_op;
2619         ut_params->auth_xform.next = &ut_params->cipher_xform;
2620         ut_params->auth_xform.auth.algo = auth_algo;
2621         ut_params->auth_xform.auth.key.length = key_len;
2622         ut_params->auth_xform.auth.key.data = auth_cipher_key;
2623         ut_params->auth_xform.auth.digest_length = auth_len;
2624         /* Auth IV will be after cipher IV */
2625         ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2626         ut_params->auth_xform.auth.iv.length = auth_iv_len;
2627
2628         /* Setup Cipher Parameters */
2629         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2630         ut_params->cipher_xform.next = NULL;
2631         ut_params->cipher_xform.cipher.algo = cipher_algo;
2632         ut_params->cipher_xform.cipher.op = cipher_op;
2633         ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2634         ut_params->cipher_xform.cipher.key.length = key_len;
2635         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2636         ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2637
2638         debug_hexdump(stdout, "key:", key, key_len);
2639
2640         /* Create Crypto session*/
2641         ut_params->sess = rte_cryptodev_sym_session_create(
2642                         ts_params->session_mpool);
2643         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2644
2645         if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2646                 ut_params->auth_xform.next = NULL;
2647                 ut_params->cipher_xform.next = &ut_params->auth_xform;
2648                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2649                                 &ut_params->cipher_xform,
2650                                 ts_params->session_priv_mpool);
2651
2652         } else
2653                 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2654                                 &ut_params->auth_xform,
2655                                 ts_params->session_priv_mpool);
2656
2657         if (status == -ENOTSUP)
2658                 return TEST_SKIPPED;
2659
2660         TEST_ASSERT_EQUAL(status, 0, "session init failed");
2661
2662         return 0;
2663 }
2664
2665 static int
2666 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2667                 unsigned int auth_tag_len,
2668                 const uint8_t *iv, unsigned int iv_len,
2669                 unsigned int data_pad_len,
2670                 enum rte_crypto_auth_operation op,
2671                 unsigned int auth_len, unsigned int auth_offset)
2672 {
2673         struct crypto_testsuite_params *ts_params = &testsuite_params;
2674
2675         struct crypto_unittest_params *ut_params = &unittest_params;
2676
2677         /* Generate Crypto op data structure */
2678         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2679                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2680         TEST_ASSERT_NOT_NULL(ut_params->op,
2681                 "Failed to allocate pktmbuf offload");
2682
2683         /* Set crypto operation data parameters */
2684         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2685
2686         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2687
2688         /* set crypto operation source mbuf */
2689         sym_op->m_src = ut_params->ibuf;
2690
2691         /* iv */
2692         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2693                         iv, iv_len);
2694         /* digest */
2695         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2696                                         ut_params->ibuf, auth_tag_len);
2697
2698         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2699                                 "no room to append auth tag");
2700         ut_params->digest = sym_op->auth.digest.data;
2701         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2702                         ut_params->ibuf, data_pad_len);
2703         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2704                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2705         else
2706                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2707
2708         debug_hexdump(stdout, "digest:",
2709                 sym_op->auth.digest.data,
2710                 auth_tag_len);
2711
2712         sym_op->auth.data.length = auth_len;
2713         sym_op->auth.data.offset = auth_offset;
2714
2715         return 0;
2716 }
2717
2718 static int
2719 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2720         enum rte_crypto_auth_operation op)
2721 {
2722         struct crypto_testsuite_params *ts_params = &testsuite_params;
2723         struct crypto_unittest_params *ut_params = &unittest_params;
2724
2725         const uint8_t *auth_tag = tdata->digest.data;
2726         const unsigned int auth_tag_len = tdata->digest.len;
2727         unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2728         unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2729
2730         const uint8_t *cipher_iv = tdata->cipher_iv.data;
2731         const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2732         const uint8_t *auth_iv = tdata->auth_iv.data;
2733         const uint8_t auth_iv_len = tdata->auth_iv.len;
2734         const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2735         const unsigned int auth_len = tdata->validAuthLenInBits.len;
2736
2737         /* Generate Crypto op data structure */
2738         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2739                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2740         TEST_ASSERT_NOT_NULL(ut_params->op,
2741                         "Failed to allocate pktmbuf offload");
2742         /* Set crypto operation data parameters */
2743         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2744
2745         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2746
2747         /* set crypto operation source mbuf */
2748         sym_op->m_src = ut_params->ibuf;
2749
2750         /* digest */
2751         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2752                         ut_params->ibuf, auth_tag_len);
2753
2754         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2755                         "no room to append auth tag");
2756         ut_params->digest = sym_op->auth.digest.data;
2757         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2758                         ut_params->ibuf, data_pad_len);
2759         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2760                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2761         else
2762                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2763
2764         debug_hexdump(stdout, "digest:",
2765                 sym_op->auth.digest.data,
2766                 auth_tag_len);
2767
2768         /* Copy cipher and auth IVs at the end of the crypto operation */
2769         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2770                                                 IV_OFFSET);
2771         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2772         iv_ptr += cipher_iv_len;
2773         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2774
2775         sym_op->cipher.data.length = cipher_len;
2776         sym_op->cipher.data.offset = 0;
2777         sym_op->auth.data.length = auth_len;
2778         sym_op->auth.data.offset = 0;
2779
2780         return 0;
2781 }
2782
2783 static int
2784 create_zuc_cipher_hash_generate_operation(
2785                 const struct wireless_test_data *tdata)
2786 {
2787         return create_wireless_cipher_hash_operation(tdata,
2788                 RTE_CRYPTO_AUTH_OP_GENERATE);
2789 }
2790
2791 static int
2792 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2793                 const unsigned auth_tag_len,
2794                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2795                 unsigned data_pad_len,
2796                 enum rte_crypto_auth_operation op,
2797                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2798                 const unsigned cipher_len, const unsigned cipher_offset,
2799                 const unsigned auth_len, const unsigned auth_offset)
2800 {
2801         struct crypto_testsuite_params *ts_params = &testsuite_params;
2802         struct crypto_unittest_params *ut_params = &unittest_params;
2803
2804         enum rte_crypto_cipher_algorithm cipher_algo =
2805                         ut_params->cipher_xform.cipher.algo;
2806         enum rte_crypto_auth_algorithm auth_algo =
2807                         ut_params->auth_xform.auth.algo;
2808
2809         /* Generate Crypto op data structure */
2810         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2811                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2812         TEST_ASSERT_NOT_NULL(ut_params->op,
2813                         "Failed to allocate pktmbuf offload");
2814         /* Set crypto operation data parameters */
2815         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2816
2817         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2818
2819         /* set crypto operation source mbuf */
2820         sym_op->m_src = ut_params->ibuf;
2821
2822         /* digest */
2823         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2824                         ut_params->ibuf, auth_tag_len);
2825
2826         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2827                         "no room to append auth tag");
2828         ut_params->digest = sym_op->auth.digest.data;
2829
2830         if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2831                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2832                                 ut_params->ibuf, data_pad_len);
2833         } else {
2834                 struct rte_mbuf *m = ut_params->ibuf;
2835                 unsigned int offset = data_pad_len;
2836
2837                 while (offset > m->data_len && m->next != NULL) {
2838                         offset -= m->data_len;
2839                         m = m->next;
2840                 }
2841                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2842                         m, offset);
2843         }
2844
2845         if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2846                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2847         else
2848                 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2849
2850         debug_hexdump(stdout, "digest:",
2851                 sym_op->auth.digest.data,
2852                 auth_tag_len);
2853
2854         /* Copy cipher and auth IVs at the end of the crypto operation */
2855         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2856                                                 IV_OFFSET);
2857         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2858         iv_ptr += cipher_iv_len;
2859         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2860
2861         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2862                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2863                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2864                 sym_op->cipher.data.length = cipher_len;
2865                 sym_op->cipher.data.offset = cipher_offset;
2866         } else {
2867                 sym_op->cipher.data.length = cipher_len >> 3;
2868                 sym_op->cipher.data.offset = cipher_offset >> 3;
2869         }
2870
2871         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2872                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2873                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2874                 sym_op->auth.data.length = auth_len;
2875                 sym_op->auth.data.offset = auth_offset;
2876         } else {
2877                 sym_op->auth.data.length = auth_len >> 3;
2878                 sym_op->auth.data.offset = auth_offset >> 3;
2879         }
2880
2881         return 0;
2882 }
2883
2884 static int
2885 create_wireless_algo_auth_cipher_operation(
2886                 const uint8_t *auth_tag, unsigned int auth_tag_len,
2887                 const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2888                 const uint8_t *auth_iv, uint8_t auth_iv_len,
2889                 unsigned int data_pad_len,
2890                 unsigned int cipher_len, unsigned int cipher_offset,
2891                 unsigned int auth_len, unsigned int auth_offset,
2892                 uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2893 {
2894         struct crypto_testsuite_params *ts_params = &testsuite_params;
2895         struct crypto_unittest_params *ut_params = &unittest_params;
2896
2897         enum rte_crypto_cipher_algorithm cipher_algo =
2898                         ut_params->cipher_xform.cipher.algo;
2899         enum rte_crypto_auth_algorithm auth_algo =
2900                         ut_params->auth_xform.auth.algo;
2901
2902         /* Generate Crypto op data structure */
2903         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2904                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2905         TEST_ASSERT_NOT_NULL(ut_params->op,
2906                         "Failed to allocate pktmbuf offload");
2907
2908         /* Set crypto operation data parameters */
2909         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2910
2911         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2912
2913         /* set crypto operation mbufs */
2914         sym_op->m_src = ut_params->ibuf;
2915         if (op_mode == OUT_OF_PLACE)
2916                 sym_op->m_dst = ut_params->obuf;
2917
2918         /* digest */
2919         if (!do_sgl) {
2920                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2921                         (op_mode == IN_PLACE ?
2922                                 ut_params->ibuf : ut_params->obuf),
2923                         uint8_t *, data_pad_len);
2924                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2925                         (op_mode == IN_PLACE ?
2926                                 ut_params->ibuf : ut_params->obuf),
2927                         data_pad_len);
2928                 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2929         } else {
2930                 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2931                 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2932                                 sym_op->m_src : sym_op->m_dst);
2933                 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2934                         remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2935                         sgl_buf = sgl_buf->next;
2936                 }
2937                 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2938                                 uint8_t *, remaining_off);
2939                 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2940                                 remaining_off);
2941                 memset(sym_op->auth.digest.data, 0, remaining_off);
2942                 while (sgl_buf->next != NULL) {
2943                         memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2944                                 0, rte_pktmbuf_data_len(sgl_buf));
2945                         sgl_buf = sgl_buf->next;
2946                 }
2947         }
2948
2949         /* Copy digest for the verification */
2950         if (verify)
2951                 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2952
2953         /* Copy cipher and auth IVs at the end of the crypto operation */
2954         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
2955                         ut_params->op, uint8_t *, IV_OFFSET);
2956
2957         rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2958         iv_ptr += cipher_iv_len;
2959         rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2960
2961         /* Only copy over the offset data needed from src to dst in OOP,
2962          * if the auth and cipher offsets are not aligned
2963          */
2964         if (op_mode == OUT_OF_PLACE) {
2965                 if (cipher_offset > auth_offset)
2966                         rte_memcpy(
2967                                 rte_pktmbuf_mtod_offset(
2968                                         sym_op->m_dst,
2969                                         uint8_t *, auth_offset >> 3),
2970                                 rte_pktmbuf_mtod_offset(
2971                                         sym_op->m_src,
2972                                         uint8_t *, auth_offset >> 3),
2973                                 ((cipher_offset >> 3) - (auth_offset >> 3)));
2974         }
2975
2976         if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2977                 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2978                 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2979                 sym_op->cipher.data.length = cipher_len;
2980                 sym_op->cipher.data.offset = cipher_offset;
2981         } else {
2982                 sym_op->cipher.data.length = cipher_len >> 3;
2983                 sym_op->cipher.data.offset = cipher_offset >> 3;
2984         }
2985
2986         if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2987                 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2988                 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2989                 sym_op->auth.data.length = auth_len;
2990                 sym_op->auth.data.offset = auth_offset;
2991         } else {
2992                 sym_op->auth.data.length = auth_len >> 3;
2993                 sym_op->auth.data.offset = auth_offset >> 3;
2994         }
2995
2996         return 0;
2997 }
2998
2999 static int
3000 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3001 {
3002         struct crypto_testsuite_params *ts_params = &testsuite_params;
3003         struct crypto_unittest_params *ut_params = &unittest_params;
3004
3005         int retval;
3006         unsigned plaintext_pad_len;
3007         unsigned plaintext_len;
3008         uint8_t *plaintext;
3009         struct rte_cryptodev_info dev_info;
3010
3011         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3012         uint64_t feat_flags = dev_info.feature_flags;
3013
3014         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3015                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3016                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3017                 return TEST_SKIPPED;
3018         }
3019
3020         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3021                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3022                 printf("Device doesn't support RAW data-path APIs.\n");
3023                 return TEST_SKIPPED;
3024         }
3025
3026         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3027                 return TEST_SKIPPED;
3028
3029         /* Verify the capabilities */
3030         struct rte_cryptodev_sym_capability_idx cap_idx;
3031         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3032         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3033         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3034                         &cap_idx) == NULL)
3035                 return TEST_SKIPPED;
3036
3037         /* Create SNOW 3G session */
3038         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3039                         tdata->key.data, tdata->key.len,
3040                         tdata->auth_iv.len, tdata->digest.len,
3041                         RTE_CRYPTO_AUTH_OP_GENERATE,
3042                         RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3043         if (retval < 0)
3044                 return retval;
3045
3046         /* alloc mbuf and set payload */
3047         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3048
3049         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3050         rte_pktmbuf_tailroom(ut_params->ibuf));
3051
3052         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3053         /* Append data which is padded to a multiple of */
3054         /* the algorithms block size */
3055         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3056         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3057                                 plaintext_pad_len);
3058         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3059
3060         /* Create SNOW 3G operation */
3061         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3062                         tdata->auth_iv.data, tdata->auth_iv.len,
3063                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3064                         tdata->validAuthLenInBits.len,
3065                         0);
3066         if (retval < 0)
3067                 return retval;
3068
3069         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3070                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3071                                 ut_params->op, 0, 1, 1, 0);
3072         else
3073                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3074                                 ut_params->op);
3075         ut_params->obuf = ut_params->op->sym->m_src;
3076         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3077         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3078                         + plaintext_pad_len;
3079
3080         /* Validate obuf */
3081         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3082         ut_params->digest,
3083         tdata->digest.data,
3084         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3085         "SNOW 3G Generated auth tag not as expected");
3086
3087         return 0;
3088 }
3089
3090 static int
3091 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3092 {
3093         struct crypto_testsuite_params *ts_params = &testsuite_params;
3094         struct crypto_unittest_params *ut_params = &unittest_params;
3095
3096         int retval;
3097         unsigned plaintext_pad_len;
3098         unsigned plaintext_len;
3099         uint8_t *plaintext;
3100         struct rte_cryptodev_info dev_info;
3101
3102         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3103         uint64_t feat_flags = dev_info.feature_flags;
3104
3105         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3106                         ((tdata->validAuthLenInBits.len % 8) != 0)) {
3107                 printf("Device doesn't support NON-Byte Aligned Data.\n");
3108                 return TEST_SKIPPED;
3109         }
3110
3111         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3112                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3113                 printf("Device doesn't support RAW data-path APIs.\n");
3114                 return TEST_SKIPPED;
3115         }
3116
3117         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3118                 return TEST_SKIPPED;
3119
3120         /* Verify the capabilities */
3121         struct rte_cryptodev_sym_capability_idx cap_idx;
3122         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3123         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3124         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3125                         &cap_idx) == NULL)
3126                 return TEST_SKIPPED;
3127
3128         /* Create SNOW 3G session */
3129         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3130                                 tdata->key.data, tdata->key.len,
3131                                 tdata->auth_iv.len, tdata->digest.len,
3132                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3133                                 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3134         if (retval < 0)
3135                 return retval;
3136         /* alloc mbuf and set payload */
3137         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3138
3139         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3140         rte_pktmbuf_tailroom(ut_params->ibuf));
3141
3142         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3143         /* Append data which is padded to a multiple of */
3144         /* the algorithms block size */
3145         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3146         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3147                                 plaintext_pad_len);
3148         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3149
3150         /* Create SNOW 3G operation */
3151         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3152                         tdata->digest.len,
3153                         tdata->auth_iv.data, tdata->auth_iv.len,
3154                         plaintext_pad_len,
3155                         RTE_CRYPTO_AUTH_OP_VERIFY,
3156                         tdata->validAuthLenInBits.len,
3157                         0);
3158         if (retval < 0)
3159                 return retval;
3160
3161         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3162                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3163                                 ut_params->op, 0, 1, 1, 0);
3164         else
3165                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3166                                 ut_params->op);
3167         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3168         ut_params->obuf = ut_params->op->sym->m_src;
3169         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3170                                 + plaintext_pad_len;
3171
3172         /* Validate obuf */
3173         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3174                 return 0;
3175         else
3176                 return -1;
3177
3178         return 0;
3179 }
3180
3181 static int
3182 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3183 {
3184         struct crypto_testsuite_params *ts_params = &testsuite_params;
3185         struct crypto_unittest_params *ut_params = &unittest_params;
3186
3187         int retval;
3188         unsigned plaintext_pad_len;
3189         unsigned plaintext_len;
3190         uint8_t *plaintext;
3191         struct rte_cryptodev_info dev_info;
3192
3193         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3194         uint64_t feat_flags = dev_info.feature_flags;
3195
3196         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3197                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3198                 printf("Device doesn't support RAW data-path APIs.\n");
3199                 return TEST_SKIPPED;
3200         }
3201
3202         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3203                 return TEST_SKIPPED;
3204
3205         /* Verify the capabilities */
3206         struct rte_cryptodev_sym_capability_idx cap_idx;
3207         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3208         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3209         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3210                         &cap_idx) == NULL)
3211                 return TEST_SKIPPED;
3212
3213         /* Create KASUMI session */
3214         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3215                         tdata->key.data, tdata->key.len,
3216                         0, tdata->digest.len,
3217                         RTE_CRYPTO_AUTH_OP_GENERATE,
3218                         RTE_CRYPTO_AUTH_KASUMI_F9);
3219         if (retval < 0)
3220                 return retval;
3221
3222         /* alloc mbuf and set payload */
3223         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3224
3225         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3226         rte_pktmbuf_tailroom(ut_params->ibuf));
3227
3228         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3229         /* Append data which is padded to a multiple of */
3230         /* the algorithms block size */
3231         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3232         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3233                                 plaintext_pad_len);
3234         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3235
3236         /* Create KASUMI operation */
3237         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3238                         NULL, 0,
3239                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3240                         tdata->plaintext.len,
3241                         0);
3242         if (retval < 0)
3243                 return retval;
3244
3245         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3246                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3247                         ut_params->op);
3248         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3249                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3250                                 ut_params->op, 0, 1, 1, 0);
3251         else
3252                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3253                         ut_params->op);
3254
3255         ut_params->obuf = ut_params->op->sym->m_src;
3256         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3257         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3258                         + plaintext_pad_len;
3259
3260         /* Validate obuf */
3261         TEST_ASSERT_BUFFERS_ARE_EQUAL(
3262         ut_params->digest,
3263         tdata->digest.data,
3264         DIGEST_BYTE_LENGTH_KASUMI_F9,
3265         "KASUMI Generated auth tag not as expected");
3266
3267         return 0;
3268 }
3269
3270 static int
3271 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3272 {
3273         struct crypto_testsuite_params *ts_params = &testsuite_params;
3274         struct crypto_unittest_params *ut_params = &unittest_params;
3275
3276         int retval;
3277         unsigned plaintext_pad_len;
3278         unsigned plaintext_len;
3279         uint8_t *plaintext;
3280         struct rte_cryptodev_info dev_info;
3281
3282         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3283         uint64_t feat_flags = dev_info.feature_flags;
3284
3285         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3286                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3287                 printf("Device doesn't support RAW data-path APIs.\n");
3288                 return TEST_SKIPPED;
3289         }
3290
3291         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3292                 return TEST_SKIPPED;
3293
3294         /* Verify the capabilities */
3295         struct rte_cryptodev_sym_capability_idx cap_idx;
3296         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3297         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3298         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3299                         &cap_idx) == NULL)
3300                 return TEST_SKIPPED;
3301
3302         /* Create KASUMI session */
3303         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3304                                 tdata->key.data, tdata->key.len,
3305                                 0, tdata->digest.len,
3306                                 RTE_CRYPTO_AUTH_OP_VERIFY,
3307                                 RTE_CRYPTO_AUTH_KASUMI_F9);
3308         if (retval < 0)
3309                 return retval;
3310         /* alloc mbuf and set payload */
3311         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3312
3313         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3314         rte_pktmbuf_tailroom(ut_params->ibuf));
3315
3316         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3317         /* Append data which is padded to a multiple */
3318         /* of the algorithms block size */
3319         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3320         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3321                                 plaintext_pad_len);
3322         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3323
3324         /* Create KASUMI operation */
3325         retval = create_wireless_algo_hash_operation(tdata->digest.data,
3326                         tdata->digest.len,
3327                         NULL, 0,
3328                         plaintext_pad_len,
3329                         RTE_CRYPTO_AUTH_OP_VERIFY,
3330                         tdata->plaintext.len,
3331                         0);
3332         if (retval < 0)
3333                 return retval;
3334
3335         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3336                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3337                                 ut_params->op, 0, 1, 1, 0);
3338         else
3339                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3340                                 ut_params->op);
3341         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3342         ut_params->obuf = ut_params->op->sym->m_src;
3343         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3344                                 + plaintext_pad_len;
3345
3346         /* Validate obuf */
3347         if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3348                 return 0;
3349         else
3350                 return -1;
3351
3352         return 0;
3353 }
3354
3355 static int
3356 test_snow3g_hash_generate_test_case_1(void)
3357 {
3358         return test_snow3g_authentication(&snow3g_hash_test_case_1);
3359 }
3360
3361 static int
3362 test_snow3g_hash_generate_test_case_2(void)
3363 {
3364         return test_snow3g_authentication(&snow3g_hash_test_case_2);
3365 }
3366
3367 static int
3368 test_snow3g_hash_generate_test_case_3(void)
3369 {
3370         return test_snow3g_authentication(&snow3g_hash_test_case_3);
3371 }
3372
3373 static int
3374 test_snow3g_hash_generate_test_case_4(void)
3375 {
3376         return test_snow3g_authentication(&snow3g_hash_test_case_4);
3377 }
3378
3379 static int
3380 test_snow3g_hash_generate_test_case_5(void)
3381 {
3382         return test_snow3g_authentication(&snow3g_hash_test_case_5);
3383 }
3384
3385 static int
3386 test_snow3g_hash_generate_test_case_6(void)
3387 {
3388         return test_snow3g_authentication(&snow3g_hash_test_case_6);
3389 }
3390
3391 static int
3392 test_snow3g_hash_verify_test_case_1(void)
3393 {
3394         return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3395
3396 }
3397
3398 static int
3399 test_snow3g_hash_verify_test_case_2(void)
3400 {
3401         return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3402 }
3403
3404 static int
3405 test_snow3g_hash_verify_test_case_3(void)
3406 {
3407         return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3408 }
3409
3410 static int
3411 test_snow3g_hash_verify_test_case_4(void)
3412 {
3413         return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3414 }
3415
3416 static int
3417 test_snow3g_hash_verify_test_case_5(void)
3418 {
3419         return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3420 }
3421
3422 static int
3423 test_snow3g_hash_verify_test_case_6(void)
3424 {
3425         return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3426 }
3427
3428 static int
3429 test_kasumi_hash_generate_test_case_1(void)
3430 {
3431         return test_kasumi_authentication(&kasumi_hash_test_case_1);
3432 }
3433
3434 static int
3435 test_kasumi_hash_generate_test_case_2(void)
3436 {
3437         return test_kasumi_authentication(&kasumi_hash_test_case_2);
3438 }
3439
3440 static int
3441 test_kasumi_hash_generate_test_case_3(void)
3442 {
3443         return test_kasumi_authentication(&kasumi_hash_test_case_3);
3444 }
3445
3446 static int
3447 test_kasumi_hash_generate_test_case_4(void)
3448 {
3449         return test_kasumi_authentication(&kasumi_hash_test_case_4);
3450 }
3451
3452 static int
3453 test_kasumi_hash_generate_test_case_5(void)
3454 {
3455         return test_kasumi_authentication(&kasumi_hash_test_case_5);
3456 }
3457
3458 static int
3459 test_kasumi_hash_generate_test_case_6(void)
3460 {
3461         return test_kasumi_authentication(&kasumi_hash_test_case_6);
3462 }
3463
3464 static int
3465 test_kasumi_hash_verify_test_case_1(void)
3466 {
3467         return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3468 }
3469
3470 static int
3471 test_kasumi_hash_verify_test_case_2(void)
3472 {
3473         return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3474 }
3475
3476 static int
3477 test_kasumi_hash_verify_test_case_3(void)
3478 {
3479         return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3480 }
3481
3482 static int
3483 test_kasumi_hash_verify_test_case_4(void)
3484 {
3485         return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3486 }
3487
3488 static int
3489 test_kasumi_hash_verify_test_case_5(void)
3490 {
3491         return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3492 }
3493
3494 static int
3495 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3496 {
3497         struct crypto_testsuite_params *ts_params = &testsuite_params;
3498         struct crypto_unittest_params *ut_params = &unittest_params;
3499
3500         int retval;
3501         uint8_t *plaintext, *ciphertext;
3502         unsigned plaintext_pad_len;
3503         unsigned plaintext_len;
3504         struct rte_cryptodev_info dev_info;
3505
3506         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3507         uint64_t feat_flags = dev_info.feature_flags;
3508
3509         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3510                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3511                 printf("Device doesn't support RAW data-path APIs.\n");
3512                 return TEST_SKIPPED;
3513         }
3514
3515         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3516                 return TEST_SKIPPED;
3517
3518         /* Verify the capabilities */
3519         struct rte_cryptodev_sym_capability_idx cap_idx;
3520         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3521         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3522         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3523                         &cap_idx) == NULL)
3524                 return TEST_SKIPPED;
3525
3526         /* Create KASUMI session */
3527         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3528                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3529                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3530                                         tdata->key.data, tdata->key.len,
3531                                         tdata->cipher_iv.len);
3532         if (retval < 0)
3533                 return retval;
3534
3535         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3536
3537         /* Clear mbuf payload */
3538         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3539                rte_pktmbuf_tailroom(ut_params->ibuf));
3540
3541         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3542         /* Append data which is padded to a multiple */
3543         /* of the algorithms block size */
3544         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3545         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3546                                 plaintext_pad_len);
3547         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3548
3549         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3550
3551         /* Create KASUMI operation */
3552         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3553                                 tdata->cipher_iv.len,
3554                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3555                                 tdata->validCipherOffsetInBits.len);
3556         if (retval < 0)
3557                 return retval;
3558
3559         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3560                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3561                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3562         else
3563                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3564                                 ut_params->op);
3565         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3566
3567         ut_params->obuf = ut_params->op->sym->m_dst;
3568         if (ut_params->obuf)
3569                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3570         else
3571                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3572
3573         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3574
3575         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3576                                 (tdata->validCipherOffsetInBits.len >> 3);
3577         /* Validate obuf */
3578         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3579                 ciphertext,
3580                 reference_ciphertext,
3581                 tdata->validCipherLenInBits.len,
3582                 "KASUMI Ciphertext data not as expected");
3583         return 0;
3584 }
3585
3586 static int
3587 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3588 {
3589         struct crypto_testsuite_params *ts_params = &testsuite_params;
3590         struct crypto_unittest_params *ut_params = &unittest_params;
3591
3592         int retval;
3593
3594         unsigned int plaintext_pad_len;
3595         unsigned int plaintext_len;
3596
3597         uint8_t buffer[10000];
3598         const uint8_t *ciphertext;
3599
3600         struct rte_cryptodev_info dev_info;
3601
3602         /* Verify the capabilities */
3603         struct rte_cryptodev_sym_capability_idx cap_idx;
3604         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3605         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3606         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3607                         &cap_idx) == NULL)
3608                 return TEST_SKIPPED;
3609
3610         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3611
3612         uint64_t feat_flags = dev_info.feature_flags;
3613
3614         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3615                 printf("Device doesn't support in-place scatter-gather. "
3616                                 "Test Skipped.\n");
3617                 return TEST_SKIPPED;
3618         }
3619
3620         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3621                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3622                 printf("Device doesn't support RAW data-path APIs.\n");
3623                 return TEST_SKIPPED;
3624         }
3625
3626         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3627                 return TEST_SKIPPED;
3628
3629         /* Create KASUMI session */
3630         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3631                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3632                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3633                                         tdata->key.data, tdata->key.len,
3634                                         tdata->cipher_iv.len);
3635         if (retval < 0)
3636                 return retval;
3637
3638         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3639
3640
3641         /* Append data which is padded to a multiple */
3642         /* of the algorithms block size */
3643         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3644
3645         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3646                         plaintext_pad_len, 10, 0);
3647
3648         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3649
3650         /* Create KASUMI operation */
3651         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3652                                 tdata->cipher_iv.len,
3653                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3654                                 tdata->validCipherOffsetInBits.len);
3655         if (retval < 0)
3656                 return retval;
3657
3658         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3659                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3660                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3661         else
3662                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3663                                                 ut_params->op);
3664         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3665
3666         ut_params->obuf = ut_params->op->sym->m_dst;
3667
3668         if (ut_params->obuf)
3669                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3670                                 plaintext_len, buffer);
3671         else
3672                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3673                                 tdata->validCipherOffsetInBits.len >> 3,
3674                                 plaintext_len, buffer);
3675
3676         /* Validate obuf */
3677         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3678
3679         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3680                                 (tdata->validCipherOffsetInBits.len >> 3);
3681         /* Validate obuf */
3682         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3683                 ciphertext,
3684                 reference_ciphertext,
3685                 tdata->validCipherLenInBits.len,
3686                 "KASUMI Ciphertext data not as expected");
3687         return 0;
3688 }
3689
3690 static int
3691 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3692 {
3693         struct crypto_testsuite_params *ts_params = &testsuite_params;
3694         struct crypto_unittest_params *ut_params = &unittest_params;
3695
3696         int retval;
3697         uint8_t *plaintext, *ciphertext;
3698         unsigned plaintext_pad_len;
3699         unsigned plaintext_len;
3700
3701         /* Verify the capabilities */
3702         struct rte_cryptodev_sym_capability_idx cap_idx;
3703         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3704         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3705         /* Data-path service does not support OOP */
3706         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3707                         &cap_idx) == NULL)
3708                 return TEST_SKIPPED;
3709
3710         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3711                 return TEST_SKIPPED;
3712
3713         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3714                 return TEST_SKIPPED;
3715
3716         /* Create KASUMI session */
3717         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3718                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3719                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3720                                         tdata->key.data, tdata->key.len,
3721                                         tdata->cipher_iv.len);
3722         if (retval < 0)
3723                 return retval;
3724
3725         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3726         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3727
3728         /* Clear mbuf payload */
3729         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3730                rte_pktmbuf_tailroom(ut_params->ibuf));
3731
3732         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3733         /* Append data which is padded to a multiple */
3734         /* of the algorithms block size */
3735         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3736         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3737                                 plaintext_pad_len);
3738         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3739         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3740
3741         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3742
3743         /* Create KASUMI operation */
3744         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3745                                 tdata->cipher_iv.len,
3746                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3747                                 tdata->validCipherOffsetInBits.len);
3748         if (retval < 0)
3749                 return retval;
3750
3751         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3752                                                 ut_params->op);
3753         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3754
3755         ut_params->obuf = ut_params->op->sym->m_dst;
3756         if (ut_params->obuf)
3757                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3758         else
3759                 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3760
3761         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3762
3763         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3764                                 (tdata->validCipherOffsetInBits.len >> 3);
3765         /* Validate obuf */
3766         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3767                 ciphertext,
3768                 reference_ciphertext,
3769                 tdata->validCipherLenInBits.len,
3770                 "KASUMI Ciphertext data not as expected");
3771         return 0;
3772 }
3773
3774 static int
3775 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3776 {
3777         struct crypto_testsuite_params *ts_params = &testsuite_params;
3778         struct crypto_unittest_params *ut_params = &unittest_params;
3779
3780         int retval;
3781         unsigned int plaintext_pad_len;
3782         unsigned int plaintext_len;
3783
3784         const uint8_t *ciphertext;
3785         uint8_t buffer[2048];
3786
3787         struct rte_cryptodev_info dev_info;
3788
3789         /* Verify the capabilities */
3790         struct rte_cryptodev_sym_capability_idx cap_idx;
3791         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3792         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3793         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3794                         &cap_idx) == NULL)
3795                 return TEST_SKIPPED;
3796
3797         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3798                 return TEST_SKIPPED;
3799
3800         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3801                 return TEST_SKIPPED;
3802
3803         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3804
3805         uint64_t feat_flags = dev_info.feature_flags;
3806         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3807                 printf("Device doesn't support out-of-place scatter-gather "
3808                                 "in both input and output mbufs. "
3809                                 "Test Skipped.\n");
3810                 return TEST_SKIPPED;
3811         }
3812
3813         /* Create KASUMI session */
3814         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3815                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3816                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3817                                         tdata->key.data, tdata->key.len,
3818                                         tdata->cipher_iv.len);
3819         if (retval < 0)
3820                 return retval;
3821
3822         plaintext_len = ceil_byte_length(tdata->plaintext.len);
3823         /* Append data which is padded to a multiple */
3824         /* of the algorithms block size */
3825         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3826
3827         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3828                         plaintext_pad_len, 10, 0);
3829         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3830                         plaintext_pad_len, 3, 0);
3831
3832         /* Append data which is padded to a multiple */
3833         /* of the algorithms block size */
3834         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3835
3836         /* Create KASUMI operation */
3837         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3838                                 tdata->cipher_iv.len,
3839                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3840                                 tdata->validCipherOffsetInBits.len);
3841         if (retval < 0)
3842                 return retval;
3843
3844         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3845                                                 ut_params->op);
3846         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3847
3848         ut_params->obuf = ut_params->op->sym->m_dst;
3849         if (ut_params->obuf)
3850                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3851                                 plaintext_pad_len, buffer);
3852         else
3853                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3854                                 tdata->validCipherOffsetInBits.len >> 3,
3855                                 plaintext_pad_len, buffer);
3856
3857         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3858                                 (tdata->validCipherOffsetInBits.len >> 3);
3859         /* Validate obuf */
3860         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3861                 ciphertext,
3862                 reference_ciphertext,
3863                 tdata->validCipherLenInBits.len,
3864                 "KASUMI Ciphertext data not as expected");
3865         return 0;
3866 }
3867
3868
3869 static int
3870 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3871 {
3872         struct crypto_testsuite_params *ts_params = &testsuite_params;
3873         struct crypto_unittest_params *ut_params = &unittest_params;
3874
3875         int retval;
3876         uint8_t *ciphertext, *plaintext;
3877         unsigned ciphertext_pad_len;
3878         unsigned ciphertext_len;
3879
3880         /* Verify the capabilities */
3881         struct rte_cryptodev_sym_capability_idx cap_idx;
3882         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3883         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3884         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3885                         &cap_idx) == NULL)
3886                 return TEST_SKIPPED;
3887
3888         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3889                 return TEST_SKIPPED;
3890
3891         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3892                 return TEST_SKIPPED;
3893
3894         /* Create KASUMI session */
3895         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3896                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3897                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3898                                         tdata->key.data, tdata->key.len,
3899                                         tdata->cipher_iv.len);
3900         if (retval < 0)
3901                 return retval;
3902
3903         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3904         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3905
3906         /* Clear mbuf payload */
3907         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3908                rte_pktmbuf_tailroom(ut_params->ibuf));
3909
3910         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3911         /* Append data which is padded to a multiple */
3912         /* of the algorithms block size */
3913         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3914         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3915                                 ciphertext_pad_len);
3916         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3917         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3918
3919         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3920
3921         /* Create KASUMI operation */
3922         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3923                                 tdata->cipher_iv.len,
3924                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3925                                 tdata->validCipherOffsetInBits.len);
3926         if (retval < 0)
3927                 return retval;
3928
3929         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3930                                                 ut_params->op);
3931         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3932
3933         ut_params->obuf = ut_params->op->sym->m_dst;
3934         if (ut_params->obuf)
3935                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3936         else
3937                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3938
3939         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3940
3941         const uint8_t *reference_plaintext = tdata->plaintext.data +
3942                                 (tdata->validCipherOffsetInBits.len >> 3);
3943         /* Validate obuf */
3944         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3945                 plaintext,
3946                 reference_plaintext,
3947                 tdata->validCipherLenInBits.len,
3948                 "KASUMI Plaintext data not as expected");
3949         return 0;
3950 }
3951
3952 static int
3953 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3954 {
3955         struct crypto_testsuite_params *ts_params = &testsuite_params;
3956         struct crypto_unittest_params *ut_params = &unittest_params;
3957
3958         int retval;
3959         uint8_t *ciphertext, *plaintext;
3960         unsigned ciphertext_pad_len;
3961         unsigned ciphertext_len;
3962         struct rte_cryptodev_info dev_info;
3963
3964         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3965         uint64_t feat_flags = dev_info.feature_flags;
3966
3967         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3968                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3969                 printf("Device doesn't support RAW data-path APIs.\n");
3970                 return TEST_SKIPPED;
3971         }
3972
3973         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3974                 return TEST_SKIPPED;
3975
3976         /* Verify the capabilities */
3977         struct rte_cryptodev_sym_capability_idx cap_idx;
3978         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3979         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3980         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3981                         &cap_idx) == NULL)
3982                 return TEST_SKIPPED;
3983
3984         /* Create KASUMI session */
3985         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3986                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
3987                                         RTE_CRYPTO_CIPHER_KASUMI_F8,
3988                                         tdata->key.data, tdata->key.len,
3989                                         tdata->cipher_iv.len);
3990         if (retval < 0)
3991                 return retval;
3992
3993         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3994
3995         /* Clear mbuf payload */
3996         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3997                rte_pktmbuf_tailroom(ut_params->ibuf));
3998
3999         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4000         /* Append data which is padded to a multiple */
4001         /* of the algorithms block size */
4002         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4003         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4004                                 ciphertext_pad_len);
4005         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4006
4007         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4008
4009         /* Create KASUMI operation */
4010         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4011                                         tdata->cipher_iv.len,
4012                                         tdata->ciphertext.len,
4013                                         tdata->validCipherOffsetInBits.len);
4014         if (retval < 0)
4015                 return retval;
4016
4017         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4018                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4019                                 ut_params->op, 1, 0, 1, 0);
4020         else
4021                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4022                                                 ut_params->op);
4023         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4024
4025         ut_params->obuf = ut_params->op->sym->m_dst;
4026         if (ut_params->obuf)
4027                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4028         else
4029                 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4030
4031         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4032
4033         const uint8_t *reference_plaintext = tdata->plaintext.data +
4034                                 (tdata->validCipherOffsetInBits.len >> 3);
4035         /* Validate obuf */
4036         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4037                 plaintext,
4038                 reference_plaintext,
4039                 tdata->validCipherLenInBits.len,
4040                 "KASUMI Plaintext data not as expected");
4041         return 0;
4042 }
4043
4044 static int
4045 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4046 {
4047         struct crypto_testsuite_params *ts_params = &testsuite_params;
4048         struct crypto_unittest_params *ut_params = &unittest_params;
4049
4050         int retval;
4051         uint8_t *plaintext, *ciphertext;
4052         unsigned plaintext_pad_len;
4053         unsigned plaintext_len;
4054         struct rte_cryptodev_info dev_info;
4055
4056         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4057         uint64_t feat_flags = dev_info.feature_flags;
4058
4059         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4060                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4061                 printf("Device doesn't support RAW data-path APIs.\n");
4062                 return TEST_SKIPPED;
4063         }
4064
4065         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4066                 return TEST_SKIPPED;
4067
4068         /* Verify the capabilities */
4069         struct rte_cryptodev_sym_capability_idx cap_idx;
4070         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4071         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4072         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4073                         &cap_idx) == NULL)
4074                 return TEST_SKIPPED;
4075
4076         /* Create SNOW 3G session */
4077         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4078                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4079                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4080                                         tdata->key.data, tdata->key.len,
4081                                         tdata->cipher_iv.len);
4082         if (retval < 0)
4083                 return retval;
4084
4085         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4086
4087         /* Clear mbuf payload */
4088         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4089                rte_pktmbuf_tailroom(ut_params->ibuf));
4090
4091         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4092         /* Append data which is padded to a multiple of */
4093         /* the algorithms block size */
4094         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4095         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4096                                 plaintext_pad_len);
4097         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4098
4099         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4100
4101         /* Create SNOW 3G operation */
4102         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4103                                         tdata->cipher_iv.len,
4104                                         tdata->validCipherLenInBits.len,
4105                                         0);
4106         if (retval < 0)
4107                 return retval;
4108
4109         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4110                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4111                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4112         else
4113                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4114                                                 ut_params->op);
4115         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4116
4117         ut_params->obuf = ut_params->op->sym->m_dst;
4118         if (ut_params->obuf)
4119                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4120         else
4121                 ciphertext = plaintext;
4122
4123         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4124
4125         /* Validate obuf */
4126         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4127                 ciphertext,
4128                 tdata->ciphertext.data,
4129                 tdata->validDataLenInBits.len,
4130                 "SNOW 3G Ciphertext data not as expected");
4131         return 0;
4132 }
4133
4134
4135 static int
4136 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4137 {
4138         struct crypto_testsuite_params *ts_params = &testsuite_params;
4139         struct crypto_unittest_params *ut_params = &unittest_params;
4140         uint8_t *plaintext, *ciphertext;
4141
4142         int retval;
4143         unsigned plaintext_pad_len;
4144         unsigned plaintext_len;
4145
4146         /* Verify the capabilities */
4147         struct rte_cryptodev_sym_capability_idx cap_idx;
4148         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4149         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4150         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4151                         &cap_idx) == NULL)
4152                 return TEST_SKIPPED;
4153
4154         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4155                 return TEST_SKIPPED;
4156
4157         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4158                 return TEST_SKIPPED;
4159
4160         /* Create SNOW 3G session */
4161         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4162                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4163                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4164                                         tdata->key.data, tdata->key.len,
4165                                         tdata->cipher_iv.len);
4166         if (retval < 0)
4167                 return retval;
4168
4169         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4170         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4171
4172         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4173                         "Failed to allocate input buffer in mempool");
4174         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4175                         "Failed to allocate output buffer in mempool");
4176
4177         /* Clear mbuf payload */
4178         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4179                rte_pktmbuf_tailroom(ut_params->ibuf));
4180
4181         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4182         /* Append data which is padded to a multiple of */
4183         /* the algorithms block size */
4184         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4185         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4186                                 plaintext_pad_len);
4187         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4188         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4189
4190         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4191
4192         /* Create SNOW 3G operation */
4193         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4194                                         tdata->cipher_iv.len,
4195                                         tdata->validCipherLenInBits.len,
4196                                         0);
4197         if (retval < 0)
4198                 return retval;
4199
4200         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4201                                                 ut_params->op);
4202         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4203
4204         ut_params->obuf = ut_params->op->sym->m_dst;
4205         if (ut_params->obuf)
4206                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4207         else
4208                 ciphertext = plaintext;
4209
4210         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4211
4212         /* Validate obuf */
4213         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4214                 ciphertext,
4215                 tdata->ciphertext.data,
4216                 tdata->validDataLenInBits.len,
4217                 "SNOW 3G Ciphertext data not as expected");
4218         return 0;
4219 }
4220
4221 static int
4222 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4223 {
4224         struct crypto_testsuite_params *ts_params = &testsuite_params;
4225         struct crypto_unittest_params *ut_params = &unittest_params;
4226
4227         int retval;
4228         unsigned int plaintext_pad_len;
4229         unsigned int plaintext_len;
4230         uint8_t buffer[10000];
4231         const uint8_t *ciphertext;
4232
4233         struct rte_cryptodev_info dev_info;
4234
4235         /* Verify the capabilities */
4236         struct rte_cryptodev_sym_capability_idx cap_idx;
4237         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4238         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4239         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4240                         &cap_idx) == NULL)
4241                 return TEST_SKIPPED;
4242
4243         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4244                 return TEST_SKIPPED;
4245
4246         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4247                 return TEST_SKIPPED;
4248
4249         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4250
4251         uint64_t feat_flags = dev_info.feature_flags;
4252
4253         if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4254                 printf("Device doesn't support out-of-place scatter-gather "
4255                                 "in both input and output mbufs. "
4256                                 "Test Skipped.\n");
4257                 return TEST_SKIPPED;
4258         }
4259
4260         /* Create SNOW 3G session */
4261         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4262                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4263                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4264                                         tdata->key.data, tdata->key.len,
4265                                         tdata->cipher_iv.len);
4266         if (retval < 0)
4267                 return retval;
4268
4269         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4270         /* Append data which is padded to a multiple of */
4271         /* the algorithms block size */
4272         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4273
4274         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4275                         plaintext_pad_len, 10, 0);
4276         ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4277                         plaintext_pad_len, 3, 0);
4278
4279         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4280                         "Failed to allocate input buffer in mempool");
4281         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4282                         "Failed to allocate output buffer in mempool");
4283
4284         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4285
4286         /* Create SNOW 3G operation */
4287         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4288                                         tdata->cipher_iv.len,
4289                                         tdata->validCipherLenInBits.len,
4290                                         0);
4291         if (retval < 0)
4292                 return retval;
4293
4294         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4295                                                 ut_params->op);
4296         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4297
4298         ut_params->obuf = ut_params->op->sym->m_dst;
4299         if (ut_params->obuf)
4300                 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4301                                 plaintext_len, buffer);
4302         else
4303                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4304                                 plaintext_len, buffer);
4305
4306         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4307
4308         /* Validate obuf */
4309         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4310                 ciphertext,
4311                 tdata->ciphertext.data,
4312                 tdata->validDataLenInBits.len,
4313                 "SNOW 3G Ciphertext data not as expected");
4314
4315         return 0;
4316 }
4317
4318 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4319 static void
4320 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4321 {
4322         uint8_t curr_byte, prev_byte;
4323         uint32_t length_in_bytes = ceil_byte_length(length + offset);
4324         uint8_t lower_byte_mask = (1 << offset) - 1;
4325         unsigned i;
4326
4327         prev_byte = buffer[0];
4328         buffer[0] >>= offset;
4329
4330         for (i = 1; i < length_in_bytes; i++) {
4331                 curr_byte = buffer[i];
4332                 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4333                                 (curr_byte >> offset);
4334                 prev_byte = curr_byte;
4335         }
4336 }
4337
4338 static int
4339 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4340 {
4341         struct crypto_testsuite_params *ts_params = &testsuite_params;
4342         struct crypto_unittest_params *ut_params = &unittest_params;
4343         uint8_t *plaintext, *ciphertext;
4344         int retval;
4345         uint32_t plaintext_len;
4346         uint32_t plaintext_pad_len;
4347         uint8_t extra_offset = 4;
4348         uint8_t *expected_ciphertext_shifted;
4349         struct rte_cryptodev_info dev_info;
4350
4351         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4352         uint64_t feat_flags = dev_info.feature_flags;
4353
4354         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4355                         ((tdata->validDataLenInBits.len % 8) != 0)) {
4356                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4357                 return TEST_SKIPPED;
4358         }
4359
4360         /* Verify the capabilities */
4361         struct rte_cryptodev_sym_capability_idx cap_idx;
4362         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4363         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4364         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4365                         &cap_idx) == NULL)
4366                 return TEST_SKIPPED;
4367
4368         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4369                 return TEST_SKIPPED;
4370
4371         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4372                 return TEST_SKIPPED;
4373
4374         /* Create SNOW 3G session */
4375         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4376                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4377                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4378                                         tdata->key.data, tdata->key.len,
4379                                         tdata->cipher_iv.len);
4380         if (retval < 0)
4381                 return retval;
4382
4383         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4384         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4385
4386         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4387                         "Failed to allocate input buffer in mempool");
4388         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4389                         "Failed to allocate output buffer in mempool");
4390
4391         /* Clear mbuf payload */
4392         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4393                rte_pktmbuf_tailroom(ut_params->ibuf));
4394
4395         plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4396         /*
4397          * Append data which is padded to a
4398          * multiple of the algorithms block size
4399          */
4400         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4401
4402         plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4403                                                 plaintext_pad_len);
4404
4405         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4406
4407         memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4408         buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4409
4410 #ifdef RTE_APP_TEST_DEBUG
4411         rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4412 #endif
4413         /* Create SNOW 3G operation */
4414         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4415                                         tdata->cipher_iv.len,
4416                                         tdata->validCipherLenInBits.len,
4417                                         extra_offset);
4418         if (retval < 0)
4419                 return retval;
4420
4421         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4422                                                 ut_params->op);
4423         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4424
4425         ut_params->obuf = ut_params->op->sym->m_dst;
4426         if (ut_params->obuf)
4427                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4428         else
4429                 ciphertext = plaintext;
4430
4431 #ifdef RTE_APP_TEST_DEBUG
4432         rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4433 #endif
4434
4435         expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4436
4437         TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4438                         "failed to reserve memory for ciphertext shifted\n");
4439
4440         memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4441                         ceil_byte_length(tdata->ciphertext.len));
4442         buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4443                         extra_offset);
4444         /* Validate obuf */
4445         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4446                 ciphertext,
4447                 expected_ciphertext_shifted,
4448                 tdata->validDataLenInBits.len,
4449                 extra_offset,
4450                 "SNOW 3G Ciphertext data not as expected");
4451         return 0;
4452 }
4453
4454 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4455 {
4456         struct crypto_testsuite_params *ts_params = &testsuite_params;
4457         struct crypto_unittest_params *ut_params = &unittest_params;
4458
4459         int retval;
4460
4461         uint8_t *plaintext, *ciphertext;
4462         unsigned ciphertext_pad_len;
4463         unsigned ciphertext_len;
4464         struct rte_cryptodev_info dev_info;
4465
4466         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4467         uint64_t feat_flags = dev_info.feature_flags;
4468
4469         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4470                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4471                 printf("Device doesn't support RAW data-path APIs.\n");
4472                 return TEST_SKIPPED;
4473         }
4474
4475         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4476                 return TEST_SKIPPED;
4477
4478         /* Verify the capabilities */
4479         struct rte_cryptodev_sym_capability_idx cap_idx;
4480         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4481         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4482         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4483                         &cap_idx) == NULL)
4484                 return TEST_SKIPPED;
4485
4486         /* Create SNOW 3G session */
4487         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4488                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4489                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4490                                         tdata->key.data, tdata->key.len,
4491                                         tdata->cipher_iv.len);
4492         if (retval < 0)
4493                 return retval;
4494
4495         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4496
4497         /* Clear mbuf payload */
4498         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4499                rte_pktmbuf_tailroom(ut_params->ibuf));
4500
4501         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4502         /* Append data which is padded to a multiple of */
4503         /* the algorithms block size */
4504         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4505         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4506                                 ciphertext_pad_len);
4507         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4508
4509         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4510
4511         /* Create SNOW 3G operation */
4512         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4513                                         tdata->cipher_iv.len,
4514                                         tdata->validCipherLenInBits.len,
4515                                         tdata->cipher.offset_bits);
4516         if (retval < 0)
4517                 return retval;
4518
4519         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4520                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4521                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4522         else
4523                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4524                                                 ut_params->op);
4525         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4526         ut_params->obuf = ut_params->op->sym->m_dst;
4527         if (ut_params->obuf)
4528                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4529         else
4530                 plaintext = ciphertext;
4531
4532         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4533
4534         /* Validate obuf */
4535         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4536                                 tdata->plaintext.data,
4537                                 tdata->validDataLenInBits.len,
4538                                 "SNOW 3G Plaintext data not as expected");
4539         return 0;
4540 }
4541
4542 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4543 {
4544         struct crypto_testsuite_params *ts_params = &testsuite_params;
4545         struct crypto_unittest_params *ut_params = &unittest_params;
4546
4547         int retval;
4548
4549         uint8_t *plaintext, *ciphertext;
4550         unsigned ciphertext_pad_len;
4551         unsigned ciphertext_len;
4552
4553         /* Verify the capabilities */
4554         struct rte_cryptodev_sym_capability_idx cap_idx;
4555         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4556         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4557         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4558                         &cap_idx) == NULL)
4559                 return TEST_SKIPPED;
4560
4561         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4562                 return TEST_SKIPPED;
4563
4564         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4565                 return TEST_SKIPPED;
4566
4567         /* Create SNOW 3G session */
4568         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4569                                         RTE_CRYPTO_CIPHER_OP_DECRYPT,
4570                                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4571                                         tdata->key.data, tdata->key.len,
4572                                         tdata->cipher_iv.len);
4573         if (retval < 0)
4574                 return retval;
4575
4576         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4577         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4578
4579         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4580                         "Failed to allocate input buffer");
4581         TEST_ASSERT_NOT_NULL(ut_params->obuf,
4582                         "Failed to allocate output buffer");
4583
4584         /* Clear mbuf payload */
4585         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4586                rte_pktmbuf_tailroom(ut_params->ibuf));
4587
4588         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4589                        rte_pktmbuf_tailroom(ut_params->obuf));
4590
4591         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4592         /* Append data which is padded to a multiple of */
4593         /* the algorithms block size */
4594         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4595         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4596                                 ciphertext_pad_len);
4597         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4598         memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4599
4600         debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4601
4602         /* Create SNOW 3G operation */
4603         retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4604                                         tdata->cipher_iv.len,
4605                                         tdata->validCipherLenInBits.len,
4606                                         0);
4607         if (retval < 0)
4608                 return retval;
4609
4610         ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4611                                                 ut_params->op);
4612         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4613         ut_params->obuf = ut_params->op->sym->m_dst;
4614         if (ut_params->obuf)
4615                 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4616         else
4617                 plaintext = ciphertext;
4618
4619         debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4620
4621         /* Validate obuf */
4622         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4623                                 tdata->plaintext.data,
4624                                 tdata->validDataLenInBits.len,
4625                                 "SNOW 3G Plaintext data not as expected");
4626         return 0;
4627 }
4628
4629 static int
4630 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4631 {
4632         struct crypto_testsuite_params *ts_params = &testsuite_params;
4633         struct crypto_unittest_params *ut_params = &unittest_params;
4634
4635         int retval;
4636
4637         uint8_t *plaintext, *ciphertext;
4638         unsigned int plaintext_pad_len;
4639         unsigned int plaintext_len;
4640
4641         struct rte_cryptodev_info dev_info;
4642         struct rte_cryptodev_sym_capability_idx cap_idx;
4643
4644         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4645         uint64_t feat_flags = dev_info.feature_flags;
4646
4647         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4648                         ((tdata->validAuthLenInBits.len % 8 != 0) ||
4649                         (tdata->validDataLenInBits.len % 8 != 0))) {
4650                 printf("Device doesn't support NON-Byte Aligned Data.\n");
4651                 return TEST_SKIPPED;
4652         }
4653
4654         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4655                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4656                 printf("Device doesn't support RAW data-path APIs.\n");
4657                 return TEST_SKIPPED;
4658         }
4659
4660         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4661                 return TEST_SKIPPED;
4662
4663         /* Check if device supports ZUC EEA3 */
4664         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4665         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4666
4667         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4668                         &cap_idx) == NULL)
4669                 return TEST_SKIPPED;
4670
4671         /* Check if device supports ZUC EIA3 */
4672         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4673         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4674
4675         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4676                         &cap_idx) == NULL)
4677                 return TEST_SKIPPED;
4678
4679         /* Create ZUC session */
4680         retval = create_zuc_cipher_auth_encrypt_generate_session(
4681                         ts_params->valid_devs[0],
4682                         tdata);
4683         if (retval != 0)
4684                 return retval;
4685         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4686
4687         /* clear mbuf payload */
4688         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4689                         rte_pktmbuf_tailroom(ut_params->ibuf));
4690
4691         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4692         /* Append data which is padded to a multiple of */
4693         /* the algorithms block size */
4694         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4695         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4696                                 plaintext_pad_len);
4697         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4698
4699         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4700
4701         /* Create ZUC operation */
4702         retval = create_zuc_cipher_hash_generate_operation(tdata);
4703         if (retval < 0)
4704                 return retval;
4705
4706         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4707                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4708                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4709         else
4710                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4711                         ut_params->op);
4712         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4713         ut_params->obuf = ut_params->op->sym->m_src;
4714         if (ut_params->obuf)
4715                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4716         else
4717                 ciphertext = plaintext;
4718
4719         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4720         /* Validate obuf */
4721         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4722                         ciphertext,
4723                         tdata->ciphertext.data,
4724                         tdata->validDataLenInBits.len,
4725                         "ZUC Ciphertext data not as expected");
4726
4727         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4728             + plaintext_pad_len;
4729
4730         /* Validate obuf */
4731         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4732                         ut_params->digest,
4733                         tdata->digest.data,
4734                         4,
4735                         "ZUC Generated auth tag not as expected");
4736         return 0;
4737 }
4738
4739 static int
4740 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4741 {
4742         struct crypto_testsuite_params *ts_params = &testsuite_params;
4743         struct crypto_unittest_params *ut_params = &unittest_params;
4744
4745         int retval;
4746
4747         uint8_t *plaintext, *ciphertext;
4748         unsigned plaintext_pad_len;
4749         unsigned plaintext_len;
4750         struct rte_cryptodev_info dev_info;
4751
4752         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4753         uint64_t feat_flags = dev_info.feature_flags;
4754
4755         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4756                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4757                 printf("Device doesn't support RAW data-path APIs.\n");
4758                 return TEST_SKIPPED;
4759         }
4760
4761         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4762                 return TEST_SKIPPED;
4763
4764         /* Verify the capabilities */
4765         struct rte_cryptodev_sym_capability_idx cap_idx;
4766         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4767         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4768         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4769                         &cap_idx) == NULL)
4770                 return TEST_SKIPPED;
4771         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4772         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4773         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4774                         &cap_idx) == NULL)
4775                 return TEST_SKIPPED;
4776
4777         /* Create SNOW 3G session */
4778         retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4779                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4780                         RTE_CRYPTO_AUTH_OP_GENERATE,
4781                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4782                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4783                         tdata->key.data, tdata->key.len,
4784                         tdata->auth_iv.len, tdata->digest.len,
4785                         tdata->cipher_iv.len);
4786         if (retval != 0)
4787                 return retval;
4788         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4789
4790         /* clear mbuf payload */
4791         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4792                         rte_pktmbuf_tailroom(ut_params->ibuf));
4793
4794         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4795         /* Append data which is padded to a multiple of */
4796         /* the algorithms block size */
4797         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4798         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4799                                 plaintext_pad_len);
4800         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4801
4802         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4803
4804         /* Create SNOW 3G operation */
4805         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4806                         tdata->digest.len, tdata->auth_iv.data,
4807                         tdata->auth_iv.len,
4808                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4809                         tdata->cipher_iv.data, tdata->cipher_iv.len,
4810                         tdata->validCipherLenInBits.len,
4811                         0,
4812                         tdata->validAuthLenInBits.len,
4813                         0
4814                         );
4815         if (retval < 0)
4816                 return retval;
4817
4818         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4819                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4820                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4821         else
4822                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4823                         ut_params->op);
4824         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4825         ut_params->obuf = ut_params->op->sym->m_src;
4826         if (ut_params->obuf)
4827                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4828         else
4829                 ciphertext = plaintext;
4830
4831         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4832         /* Validate obuf */
4833         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4834                         ciphertext,
4835                         tdata->ciphertext.data,
4836                         tdata->validDataLenInBits.len,
4837                         "SNOW 3G Ciphertext data not as expected");
4838
4839         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4840             + plaintext_pad_len;
4841
4842         /* Validate obuf */
4843         TEST_ASSERT_BUFFERS_ARE_EQUAL(
4844                         ut_params->digest,
4845                         tdata->digest.data,
4846                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4847                         "SNOW 3G Generated auth tag not as expected");
4848         return 0;
4849 }
4850
4851 static int
4852 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4853         uint8_t op_mode, uint8_t verify)
4854 {
4855         struct crypto_testsuite_params *ts_params = &testsuite_params;
4856         struct crypto_unittest_params *ut_params = &unittest_params;
4857
4858         int retval;
4859
4860         uint8_t *plaintext = NULL, *ciphertext = NULL;
4861         unsigned int plaintext_pad_len;
4862         unsigned int plaintext_len;
4863         unsigned int ciphertext_pad_len;
4864         unsigned int ciphertext_len;
4865
4866         struct rte_cryptodev_info dev_info;
4867
4868         /* Verify the capabilities */
4869         struct rte_cryptodev_sym_capability_idx cap_idx;
4870         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4871         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4872         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4873                         &cap_idx) == NULL)
4874                 return TEST_SKIPPED;
4875         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4876         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4877         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4878                         &cap_idx) == NULL)
4879                 return TEST_SKIPPED;
4880
4881         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4882                 return TEST_SKIPPED;
4883
4884         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4885
4886         uint64_t feat_flags = dev_info.feature_flags;
4887
4888         if (op_mode == OUT_OF_PLACE) {
4889                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4890                         printf("Device doesn't support digest encrypted.\n");
4891                         return TEST_SKIPPED;
4892                 }
4893                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4894                         return TEST_SKIPPED;
4895         }
4896
4897         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4898                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4899                 printf("Device doesn't support RAW data-path APIs.\n");
4900                 return TEST_SKIPPED;
4901         }
4902
4903         /* Create SNOW 3G session */
4904         retval = create_wireless_algo_auth_cipher_session(
4905                         ts_params->valid_devs[0],
4906                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4907                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4908                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4909                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
4910                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4911                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4912                         tdata->key.data, tdata->key.len,
4913                         tdata->auth_iv.len, tdata->digest.len,
4914                         tdata->cipher_iv.len);
4915         if (retval != 0)
4916                 return retval;
4917
4918         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4919         if (op_mode == OUT_OF_PLACE)
4920                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4921
4922         /* clear mbuf payload */
4923         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4924                 rte_pktmbuf_tailroom(ut_params->ibuf));
4925         if (op_mode == OUT_OF_PLACE)
4926                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4927                         rte_pktmbuf_tailroom(ut_params->obuf));
4928
4929         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4930         plaintext_len = ceil_byte_length(tdata->plaintext.len);
4931         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4932         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4933
4934         if (verify) {
4935                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4936                                         ciphertext_pad_len);
4937                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4938                 if (op_mode == OUT_OF_PLACE)
4939                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4940                 debug_hexdump(stdout, "ciphertext:", ciphertext,
4941                         ciphertext_len);
4942         } else {
4943                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4944                                         plaintext_pad_len);
4945                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4946                 if (op_mode == OUT_OF_PLACE)
4947                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4948                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4949         }
4950
4951         /* Create SNOW 3G operation */
4952         retval = create_wireless_algo_auth_cipher_operation(
4953                 tdata->digest.data, tdata->digest.len,
4954                 tdata->cipher_iv.data, tdata->cipher_iv.len,
4955                 tdata->auth_iv.data, tdata->auth_iv.len,
4956                 (tdata->digest.offset_bytes == 0 ?
4957                 (verify ? ciphertext_pad_len : plaintext_pad_len)
4958                         : tdata->digest.offset_bytes),
4959                 tdata->validCipherLenInBits.len,
4960                 tdata->cipher.offset_bits,
4961                 tdata->validAuthLenInBits.len,
4962                 tdata->auth.offset_bits,
4963                 op_mode, 0, verify);
4964
4965         if (retval < 0)
4966                 return retval;
4967
4968         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4969                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4970                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4971         else
4972                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4973                         ut_params->op);
4974
4975         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4976
4977         ut_params->obuf = (op_mode == IN_PLACE ?
4978                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4979
4980         if (verify) {
4981                 if (ut_params->obuf)
4982                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4983                                                         uint8_t *);
4984                 else
4985                         plaintext = ciphertext +
4986                                 (tdata->cipher.offset_bits >> 3);
4987
4988                 debug_hexdump(stdout, "plaintext:", plaintext,
4989                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4990                 debug_hexdump(stdout, "plaintext expected:",
4991                         tdata->plaintext.data,
4992                         (tdata->plaintext.len >> 3) - tdata->digest.len);
4993         } else {
4994                 if (ut_params->obuf)
4995                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4996                                                         uint8_t *);
4997                 else
4998                         ciphertext = plaintext;
4999
5000                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5001                         ciphertext_len);
5002                 debug_hexdump(stdout, "ciphertext expected:",
5003                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5004
5005                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5006                         + (tdata->digest.offset_bytes == 0 ?
5007                 plaintext_pad_len : tdata->digest.offset_bytes);
5008
5009                 debug_hexdump(stdout, "digest:", ut_params->digest,
5010                         tdata->digest.len);
5011                 debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5012                                 tdata->digest.len);
5013         }
5014
5015         /* Validate obuf */
5016         if (verify) {
5017                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5018                         plaintext,
5019                         tdata->plaintext.data,
5020                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5021                          (tdata->digest.len << 3)),
5022                         tdata->cipher.offset_bits,
5023                         "SNOW 3G Plaintext data not as expected");
5024         } else {
5025                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5026                         ciphertext,
5027                         tdata->ciphertext.data,
5028                         (tdata->validDataLenInBits.len -
5029                          tdata->cipher.offset_bits),
5030                         tdata->cipher.offset_bits,
5031                         "SNOW 3G Ciphertext data not as expected");
5032
5033                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5034                         ut_params->digest,
5035                         tdata->digest.data,
5036                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5037                         "SNOW 3G Generated auth tag not as expected");
5038         }
5039         return 0;
5040 }
5041
5042 static int
5043 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5044         uint8_t op_mode, uint8_t verify)
5045 {
5046         struct crypto_testsuite_params *ts_params = &testsuite_params;
5047         struct crypto_unittest_params *ut_params = &unittest_params;
5048
5049         int retval;
5050
5051         const uint8_t *plaintext = NULL;
5052         const uint8_t *ciphertext = NULL;
5053         const uint8_t *digest = NULL;
5054         unsigned int plaintext_pad_len;
5055         unsigned int plaintext_len;
5056         unsigned int ciphertext_pad_len;
5057         unsigned int ciphertext_len;
5058         uint8_t buffer[10000];
5059         uint8_t digest_buffer[10000];
5060
5061         struct rte_cryptodev_info dev_info;
5062
5063         /* Verify the capabilities */
5064         struct rte_cryptodev_sym_capability_idx cap_idx;
5065         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5066         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5067         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5068                         &cap_idx) == NULL)
5069                 return TEST_SKIPPED;
5070         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5071         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5072         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5073                         &cap_idx) == NULL)
5074                 return TEST_SKIPPED;
5075
5076         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5077                 return TEST_SKIPPED;
5078
5079         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5080
5081         uint64_t feat_flags = dev_info.feature_flags;
5082
5083         if (op_mode == IN_PLACE) {
5084                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5085                         printf("Device doesn't support in-place scatter-gather "
5086                                         "in both input and output mbufs.\n");
5087                         return TEST_SKIPPED;
5088                 }
5089                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5090                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5091                         printf("Device doesn't support RAW data-path APIs.\n");
5092                         return TEST_SKIPPED;
5093                 }
5094         } else {
5095                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5096                         return TEST_SKIPPED;
5097                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5098                         printf("Device doesn't support out-of-place scatter-gather "
5099                                         "in both input and output mbufs.\n");
5100                         return TEST_SKIPPED;
5101                 }
5102                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5103                         printf("Device doesn't support digest encrypted.\n");
5104                         return TEST_SKIPPED;
5105                 }
5106         }
5107
5108         /* Create SNOW 3G session */
5109         retval = create_wireless_algo_auth_cipher_session(
5110                         ts_params->valid_devs[0],
5111                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5112                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5113                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5114                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5115                         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5116                         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5117                         tdata->key.data, tdata->key.len,
5118                         tdata->auth_iv.len, tdata->digest.len,
5119                         tdata->cipher_iv.len);
5120
5121         if (retval != 0)
5122                 return retval;
5123
5124         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5125         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5126         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5127         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5128
5129         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5130                         plaintext_pad_len, 15, 0);
5131         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5132                         "Failed to allocate input buffer in mempool");
5133
5134         if (op_mode == OUT_OF_PLACE) {
5135                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5136                                 plaintext_pad_len, 15, 0);
5137                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5138                                 "Failed to allocate output buffer in mempool");
5139         }
5140
5141         if (verify) {
5142                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5143                         tdata->ciphertext.data);
5144                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5145                                         ciphertext_len, buffer);
5146                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5147                         ciphertext_len);
5148         } else {
5149                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5150                         tdata->plaintext.data);
5151                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5152                                         plaintext_len, buffer);
5153                 debug_hexdump(stdout, "plaintext:", plaintext,
5154                         plaintext_len);
5155         }
5156         memset(buffer, 0, sizeof(buffer));
5157
5158         /* Create SNOW 3G operation */
5159         retval = create_wireless_algo_auth_cipher_operation(
5160                 tdata->digest.data, tdata->digest.len,
5161                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5162                 tdata->auth_iv.data, tdata->auth_iv.len,
5163                 (tdata->digest.offset_bytes == 0 ?
5164                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5165                         : tdata->digest.offset_bytes),
5166                 tdata->validCipherLenInBits.len,
5167                 tdata->cipher.offset_bits,
5168                 tdata->validAuthLenInBits.len,
5169                 tdata->auth.offset_bits,
5170                 op_mode, 1, verify);
5171
5172         if (retval < 0)
5173                 return retval;
5174
5175         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5176                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5177                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5178         else
5179                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5180                         ut_params->op);
5181
5182         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5183
5184         ut_params->obuf = (op_mode == IN_PLACE ?
5185                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5186
5187         if (verify) {
5188                 if (ut_params->obuf)
5189                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5190                                         plaintext_len, buffer);
5191                 else
5192                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5193                                         plaintext_len, buffer);
5194
5195                 debug_hexdump(stdout, "plaintext:", plaintext,
5196                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5197                 debug_hexdump(stdout, "plaintext expected:",
5198                         tdata->plaintext.data,
5199                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5200         } else {
5201                 if (ut_params->obuf)
5202                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5203                                         ciphertext_len, buffer);
5204                 else
5205                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5206                                         ciphertext_len, buffer);
5207
5208                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5209                         ciphertext_len);
5210                 debug_hexdump(stdout, "ciphertext expected:",
5211                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5212
5213                 if (ut_params->obuf)
5214                         digest = rte_pktmbuf_read(ut_params->obuf,
5215                                 (tdata->digest.offset_bytes == 0 ?
5216                                 plaintext_pad_len : tdata->digest.offset_bytes),
5217                                 tdata->digest.len, digest_buffer);
5218                 else
5219                         digest = rte_pktmbuf_read(ut_params->ibuf,
5220                                 (tdata->digest.offset_bytes == 0 ?
5221                                 plaintext_pad_len : tdata->digest.offset_bytes),
5222                                 tdata->digest.len, digest_buffer);
5223
5224                 debug_hexdump(stdout, "digest:", digest,
5225                         tdata->digest.len);
5226                 debug_hexdump(stdout, "digest expected:",
5227                         tdata->digest.data, tdata->digest.len);
5228         }
5229
5230         /* Validate obuf */
5231         if (verify) {
5232                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5233                         plaintext,
5234                         tdata->plaintext.data,
5235                         (tdata->plaintext.len - tdata->cipher.offset_bits -
5236                          (tdata->digest.len << 3)),
5237                         tdata->cipher.offset_bits,
5238                         "SNOW 3G Plaintext data not as expected");
5239         } else {
5240                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5241                         ciphertext,
5242                         tdata->ciphertext.data,
5243                         (tdata->validDataLenInBits.len -
5244                          tdata->cipher.offset_bits),
5245                         tdata->cipher.offset_bits,
5246                         "SNOW 3G Ciphertext data not as expected");
5247
5248                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5249                         digest,
5250                         tdata->digest.data,
5251                         DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5252                         "SNOW 3G Generated auth tag not as expected");
5253         }
5254         return 0;
5255 }
5256
5257 static int
5258 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5259         uint8_t op_mode, uint8_t verify)
5260 {
5261         struct crypto_testsuite_params *ts_params = &testsuite_params;
5262         struct crypto_unittest_params *ut_params = &unittest_params;
5263
5264         int retval;
5265
5266         uint8_t *plaintext = NULL, *ciphertext = NULL;
5267         unsigned int plaintext_pad_len;
5268         unsigned int plaintext_len;
5269         unsigned int ciphertext_pad_len;
5270         unsigned int ciphertext_len;
5271
5272         struct rte_cryptodev_info dev_info;
5273
5274         /* Verify the capabilities */
5275         struct rte_cryptodev_sym_capability_idx cap_idx;
5276         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5277         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5278         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5279                         &cap_idx) == NULL)
5280                 return TEST_SKIPPED;
5281         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5282         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5283         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5284                         &cap_idx) == NULL)
5285                 return TEST_SKIPPED;
5286
5287         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5288
5289         uint64_t feat_flags = dev_info.feature_flags;
5290
5291         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5292                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5293                 printf("Device doesn't support RAW data-path APIs.\n");
5294                 return TEST_SKIPPED;
5295         }
5296
5297         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5298                 return TEST_SKIPPED;
5299
5300         if (op_mode == OUT_OF_PLACE) {
5301                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5302                         return TEST_SKIPPED;
5303                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5304                         printf("Device doesn't support digest encrypted.\n");
5305                         return TEST_SKIPPED;
5306                 }
5307         }
5308
5309         /* Create KASUMI session */
5310         retval = create_wireless_algo_auth_cipher_session(
5311                         ts_params->valid_devs[0],
5312                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5313                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5314                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5315                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5316                         RTE_CRYPTO_AUTH_KASUMI_F9,
5317                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5318                         tdata->key.data, tdata->key.len,
5319                         0, tdata->digest.len,
5320                         tdata->cipher_iv.len);
5321
5322         if (retval != 0)
5323                 return retval;
5324
5325         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5326         if (op_mode == OUT_OF_PLACE)
5327                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5328
5329         /* clear mbuf payload */
5330         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5331                 rte_pktmbuf_tailroom(ut_params->ibuf));
5332         if (op_mode == OUT_OF_PLACE)
5333                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5334                         rte_pktmbuf_tailroom(ut_params->obuf));
5335
5336         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5337         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5338         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5339         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5340
5341         if (verify) {
5342                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5343                                         ciphertext_pad_len);
5344                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5345                 if (op_mode == OUT_OF_PLACE)
5346                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5347                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5348                         ciphertext_len);
5349         } else {
5350                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5351                                         plaintext_pad_len);
5352                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5353                 if (op_mode == OUT_OF_PLACE)
5354                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5355                 debug_hexdump(stdout, "plaintext:", plaintext,
5356                         plaintext_len);
5357         }
5358
5359         /* Create KASUMI operation */
5360         retval = create_wireless_algo_auth_cipher_operation(
5361                 tdata->digest.data, tdata->digest.len,
5362                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5363                 NULL, 0,
5364                 (tdata->digest.offset_bytes == 0 ?
5365                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5366                         : tdata->digest.offset_bytes),
5367                 tdata->validCipherLenInBits.len,
5368                 tdata->validCipherOffsetInBits.len,
5369                 tdata->validAuthLenInBits.len,
5370                 0,
5371                 op_mode, 0, verify);
5372
5373         if (retval < 0)
5374                 return retval;
5375
5376         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5377                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5378                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5379         else
5380                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5381                         ut_params->op);
5382
5383         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5384
5385         ut_params->obuf = (op_mode == IN_PLACE ?
5386                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5387
5388
5389         if (verify) {
5390                 if (ut_params->obuf)
5391                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5392                                                         uint8_t *);
5393                 else
5394                         plaintext = ciphertext;
5395
5396                 debug_hexdump(stdout, "plaintext:", plaintext,
5397                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5398                 debug_hexdump(stdout, "plaintext expected:",
5399                         tdata->plaintext.data,
5400                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5401         } else {
5402                 if (ut_params->obuf)
5403                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5404                                                         uint8_t *);
5405                 else
5406                         ciphertext = plaintext;
5407
5408                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5409                         ciphertext_len);
5410                 debug_hexdump(stdout, "ciphertext expected:",
5411                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5412
5413                 ut_params->digest = rte_pktmbuf_mtod(
5414                         ut_params->obuf, uint8_t *) +
5415                         (tdata->digest.offset_bytes == 0 ?
5416                         plaintext_pad_len : tdata->digest.offset_bytes);
5417
5418                 debug_hexdump(stdout, "digest:", ut_params->digest,
5419                         tdata->digest.len);
5420                 debug_hexdump(stdout, "digest expected:",
5421                         tdata->digest.data, tdata->digest.len);
5422         }
5423
5424         /* Validate obuf */
5425         if (verify) {
5426                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5427                         plaintext,
5428                         tdata->plaintext.data,
5429                         tdata->plaintext.len >> 3,
5430                         "KASUMI Plaintext data not as expected");
5431         } else {
5432                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5433                         ciphertext,
5434                         tdata->ciphertext.data,
5435                         tdata->ciphertext.len >> 3,
5436                         "KASUMI Ciphertext data not as expected");
5437
5438                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5439                         ut_params->digest,
5440                         tdata->digest.data,
5441                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5442                         "KASUMI Generated auth tag not as expected");
5443         }
5444         return 0;
5445 }
5446
5447 static int
5448 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5449         uint8_t op_mode, uint8_t verify)
5450 {
5451         struct crypto_testsuite_params *ts_params = &testsuite_params;
5452         struct crypto_unittest_params *ut_params = &unittest_params;
5453
5454         int retval;
5455
5456         const uint8_t *plaintext = NULL;
5457         const uint8_t *ciphertext = NULL;
5458         const uint8_t *digest = NULL;
5459         unsigned int plaintext_pad_len;
5460         unsigned int plaintext_len;
5461         unsigned int ciphertext_pad_len;
5462         unsigned int ciphertext_len;
5463         uint8_t buffer[10000];
5464         uint8_t digest_buffer[10000];
5465
5466         struct rte_cryptodev_info dev_info;
5467
5468         /* Verify the capabilities */
5469         struct rte_cryptodev_sym_capability_idx cap_idx;
5470         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5471         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5472         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5473                         &cap_idx) == NULL)
5474                 return TEST_SKIPPED;
5475         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5476         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5477         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5478                         &cap_idx) == NULL)
5479                 return TEST_SKIPPED;
5480
5481         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5482                 return TEST_SKIPPED;
5483
5484         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5485
5486         uint64_t feat_flags = dev_info.feature_flags;
5487
5488         if (op_mode == IN_PLACE) {
5489                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5490                         printf("Device doesn't support in-place scatter-gather "
5491                                         "in both input and output mbufs.\n");
5492                         return TEST_SKIPPED;
5493                 }
5494                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5495                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5496                         printf("Device doesn't support RAW data-path APIs.\n");
5497                         return TEST_SKIPPED;
5498                 }
5499         } else {
5500                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5501                         return TEST_SKIPPED;
5502                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5503                         printf("Device doesn't support out-of-place scatter-gather "
5504                                         "in both input and output mbufs.\n");
5505                         return TEST_SKIPPED;
5506                 }
5507                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5508                         printf("Device doesn't support digest encrypted.\n");
5509                         return TEST_SKIPPED;
5510                 }
5511         }
5512
5513         /* Create KASUMI session */
5514         retval = create_wireless_algo_auth_cipher_session(
5515                         ts_params->valid_devs[0],
5516                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5517                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5518                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5519                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
5520                         RTE_CRYPTO_AUTH_KASUMI_F9,
5521                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5522                         tdata->key.data, tdata->key.len,
5523                         0, tdata->digest.len,
5524                         tdata->cipher_iv.len);
5525
5526         if (retval != 0)
5527                 return retval;
5528
5529         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5530         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5531         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5532         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5533
5534         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5535                         plaintext_pad_len, 15, 0);
5536         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5537                         "Failed to allocate input buffer in mempool");
5538
5539         if (op_mode == OUT_OF_PLACE) {
5540                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5541                                 plaintext_pad_len, 15, 0);
5542                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
5543                                 "Failed to allocate output buffer in mempool");
5544         }
5545
5546         if (verify) {
5547                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5548                         tdata->ciphertext.data);
5549                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5550                                         ciphertext_len, buffer);
5551                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5552                         ciphertext_len);
5553         } else {
5554                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5555                         tdata->plaintext.data);
5556                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5557                                         plaintext_len, buffer);
5558                 debug_hexdump(stdout, "plaintext:", plaintext,
5559                         plaintext_len);
5560         }
5561         memset(buffer, 0, sizeof(buffer));
5562
5563         /* Create KASUMI operation */
5564         retval = create_wireless_algo_auth_cipher_operation(
5565                 tdata->digest.data, tdata->digest.len,
5566                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5567                 NULL, 0,
5568                 (tdata->digest.offset_bytes == 0 ?
5569                 (verify ? ciphertext_pad_len : plaintext_pad_len)
5570                         : tdata->digest.offset_bytes),
5571                 tdata->validCipherLenInBits.len,
5572                 tdata->validCipherOffsetInBits.len,
5573                 tdata->validAuthLenInBits.len,
5574                 0,
5575                 op_mode, 1, verify);
5576
5577         if (retval < 0)
5578                 return retval;
5579
5580         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5581                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5582                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5583         else
5584                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5585                         ut_params->op);
5586
5587         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5588
5589         ut_params->obuf = (op_mode == IN_PLACE ?
5590                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5591
5592         if (verify) {
5593                 if (ut_params->obuf)
5594                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5595                                         plaintext_len, buffer);
5596                 else
5597                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5598                                         plaintext_len, buffer);
5599
5600                 debug_hexdump(stdout, "plaintext:", plaintext,
5601                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5602                 debug_hexdump(stdout, "plaintext expected:",
5603                         tdata->plaintext.data,
5604                         (tdata->plaintext.len >> 3) - tdata->digest.len);
5605         } else {
5606                 if (ut_params->obuf)
5607                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5608                                         ciphertext_len, buffer);
5609                 else
5610                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5611                                         ciphertext_len, buffer);
5612
5613                 debug_hexdump(stdout, "ciphertext:", ciphertext,
5614                         ciphertext_len);
5615                 debug_hexdump(stdout, "ciphertext expected:",
5616                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5617
5618                 if (ut_params->obuf)
5619                         digest = rte_pktmbuf_read(ut_params->obuf,
5620                                 (tdata->digest.offset_bytes == 0 ?
5621                                 plaintext_pad_len : tdata->digest.offset_bytes),
5622                                 tdata->digest.len, digest_buffer);
5623                 else
5624                         digest = rte_pktmbuf_read(ut_params->ibuf,
5625                                 (tdata->digest.offset_bytes == 0 ?
5626                                 plaintext_pad_len : tdata->digest.offset_bytes),
5627                                 tdata->digest.len, digest_buffer);
5628
5629                 debug_hexdump(stdout, "digest:", digest,
5630                         tdata->digest.len);
5631                 debug_hexdump(stdout, "digest expected:",
5632                         tdata->digest.data, tdata->digest.len);
5633         }
5634
5635         /* Validate obuf */
5636         if (verify) {
5637                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5638                         plaintext,
5639                         tdata->plaintext.data,
5640                         tdata->plaintext.len >> 3,
5641                         "KASUMI Plaintext data not as expected");
5642         } else {
5643                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5644                         ciphertext,
5645                         tdata->ciphertext.data,
5646                         tdata->validDataLenInBits.len,
5647                         "KASUMI Ciphertext data not as expected");
5648
5649                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5650                         digest,
5651                         tdata->digest.data,
5652                         DIGEST_BYTE_LENGTH_KASUMI_F9,
5653                         "KASUMI Generated auth tag not as expected");
5654         }
5655         return 0;
5656 }
5657
5658 static int
5659 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5660 {
5661         struct crypto_testsuite_params *ts_params = &testsuite_params;
5662         struct crypto_unittest_params *ut_params = &unittest_params;
5663
5664         int retval;
5665
5666         uint8_t *plaintext, *ciphertext;
5667         unsigned plaintext_pad_len;
5668         unsigned plaintext_len;
5669         struct rte_cryptodev_info dev_info;
5670
5671         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5672         uint64_t feat_flags = dev_info.feature_flags;
5673
5674         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5675                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5676                 printf("Device doesn't support RAW data-path APIs.\n");
5677                 return TEST_SKIPPED;
5678         }
5679
5680         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5681                 return TEST_SKIPPED;
5682
5683         /* Verify the capabilities */
5684         struct rte_cryptodev_sym_capability_idx cap_idx;
5685         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5686         cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5687         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5688                         &cap_idx) == NULL)
5689                 return TEST_SKIPPED;
5690         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5691         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5692         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5693                         &cap_idx) == NULL)
5694                 return TEST_SKIPPED;
5695
5696         /* Create KASUMI session */
5697         retval = create_wireless_algo_cipher_auth_session(
5698                         ts_params->valid_devs[0],
5699                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5700                         RTE_CRYPTO_AUTH_OP_GENERATE,
5701                         RTE_CRYPTO_AUTH_KASUMI_F9,
5702                         RTE_CRYPTO_CIPHER_KASUMI_F8,
5703                         tdata->key.data, tdata->key.len,
5704                         0, tdata->digest.len,
5705                         tdata->cipher_iv.len);
5706         if (retval != 0)
5707                 return retval;
5708
5709         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5710
5711         /* clear mbuf payload */
5712         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5713                         rte_pktmbuf_tailroom(ut_params->ibuf));
5714
5715         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5716         /* Append data which is padded to a multiple of */
5717         /* the algorithms block size */
5718         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5719         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5720                                 plaintext_pad_len);
5721         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5722
5723         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5724
5725         /* Create KASUMI operation */
5726         retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5727                                 tdata->digest.len, NULL, 0,
5728                                 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5729                                 tdata->cipher_iv.data, tdata->cipher_iv.len,
5730                                 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5731                                 tdata->validCipherOffsetInBits.len,
5732                                 tdata->validAuthLenInBits.len,
5733                                 0
5734                                 );
5735         if (retval < 0)
5736                 return retval;
5737
5738         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5739                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5740                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5741         else
5742                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5743                         ut_params->op);
5744         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5745
5746         if (ut_params->op->sym->m_dst)
5747                 ut_params->obuf = ut_params->op->sym->m_dst;
5748         else
5749                 ut_params->obuf = ut_params->op->sym->m_src;
5750
5751         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5752                                 tdata->validCipherOffsetInBits.len >> 3);
5753
5754         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5755                         + plaintext_pad_len;
5756
5757         const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5758                                 (tdata->validCipherOffsetInBits.len >> 3);
5759         /* Validate obuf */
5760         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5761                 ciphertext,
5762                 reference_ciphertext,
5763                 tdata->validCipherLenInBits.len,
5764                 "KASUMI Ciphertext data not as expected");
5765
5766         /* Validate obuf */
5767         TEST_ASSERT_BUFFERS_ARE_EQUAL(
5768                 ut_params->digest,
5769                 tdata->digest.data,
5770                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5771                 "KASUMI Generated auth tag not as expected");
5772         return 0;
5773 }
5774
5775 static int
5776 test_zuc_encryption(const struct wireless_test_data *tdata)
5777 {
5778         struct crypto_testsuite_params *ts_params = &testsuite_params;
5779         struct crypto_unittest_params *ut_params = &unittest_params;
5780
5781         int retval;
5782         uint8_t *plaintext, *ciphertext;
5783         unsigned plaintext_pad_len;
5784         unsigned plaintext_len;
5785         struct rte_cryptodev_info dev_info;
5786
5787         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5788         uint64_t feat_flags = dev_info.feature_flags;
5789
5790         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5791                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5792                 printf("Device doesn't support RAW data-path APIs.\n");
5793                 return TEST_SKIPPED;
5794         }
5795
5796         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5797                 return TEST_SKIPPED;
5798
5799         struct rte_cryptodev_sym_capability_idx cap_idx;
5800
5801         /* Check if device supports ZUC EEA3 */
5802         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5803         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5804
5805         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5806                         &cap_idx) == NULL)
5807                 return TEST_SKIPPED;
5808
5809         /* Create ZUC session */
5810         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5811                                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5812                                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5813                                         tdata->key.data, tdata->key.len,
5814                                         tdata->cipher_iv.len);
5815         if (retval < 0)
5816                 return retval;
5817
5818         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5819
5820         /* Clear mbuf payload */
5821         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5822                rte_pktmbuf_tailroom(ut_params->ibuf));
5823
5824         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5825         /* Append data which is padded to a multiple */
5826         /* of the algorithms block size */
5827         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5828         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5829                                 plaintext_pad_len);
5830         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5831
5832         debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5833
5834         /* Create ZUC operation */
5835         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5836                                         tdata->cipher_iv.len,
5837                                         tdata->plaintext.len,
5838                                         0);
5839         if (retval < 0)
5840                 return retval;
5841
5842         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5843                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5844                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5845         else
5846                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5847                                                 ut_params->op);
5848         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5849
5850         ut_params->obuf = ut_params->op->sym->m_dst;
5851         if (ut_params->obuf)
5852                 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5853         else
5854                 ciphertext = plaintext;
5855
5856         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5857
5858         /* Validate obuf */
5859         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5860                 ciphertext,
5861                 tdata->ciphertext.data,
5862                 tdata->validCipherLenInBits.len,
5863                 "ZUC Ciphertext data not as expected");
5864         return 0;
5865 }
5866
5867 static int
5868 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5869 {
5870         struct crypto_testsuite_params *ts_params = &testsuite_params;
5871         struct crypto_unittest_params *ut_params = &unittest_params;
5872
5873         int retval;
5874
5875         unsigned int plaintext_pad_len;
5876         unsigned int plaintext_len;
5877         const uint8_t *ciphertext;
5878         uint8_t ciphertext_buffer[2048];
5879         struct rte_cryptodev_info dev_info;
5880
5881         struct rte_cryptodev_sym_capability_idx cap_idx;
5882
5883         /* Check if device supports ZUC EEA3 */
5884         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5885         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5886
5887         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5888                         &cap_idx) == NULL)
5889                 return TEST_SKIPPED;
5890
5891         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5892                 return TEST_SKIPPED;
5893
5894         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5895
5896         uint64_t feat_flags = dev_info.feature_flags;
5897
5898         if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5899                 printf("Device doesn't support in-place scatter-gather. "
5900                                 "Test Skipped.\n");
5901                 return TEST_SKIPPED;
5902         }
5903
5904         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5905                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5906                 printf("Device doesn't support RAW data-path APIs.\n");
5907                 return TEST_SKIPPED;
5908         }
5909
5910         plaintext_len = ceil_byte_length(tdata->plaintext.len);
5911
5912         /* Append data which is padded to a multiple */
5913         /* of the algorithms block size */
5914         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5915
5916         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5917                         plaintext_pad_len, 10, 0);
5918
5919         pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5920                         tdata->plaintext.data);
5921
5922         /* Create ZUC session */
5923         retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5924                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5925                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
5926                         tdata->key.data, tdata->key.len,
5927                         tdata->cipher_iv.len);
5928         if (retval < 0)
5929                 return retval;
5930
5931         /* Clear mbuf payload */
5932
5933         pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5934
5935         /* Create ZUC operation */
5936         retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5937                         tdata->cipher_iv.len, tdata->plaintext.len,
5938                         0);
5939         if (retval < 0)
5940                 return retval;
5941
5942         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5943                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5944                                 ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5945         else
5946                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5947                                                 ut_params->op);
5948         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5949
5950         ut_params->obuf = ut_params->op->sym->m_dst;
5951         if (ut_params->obuf)
5952                 ciphertext = rte_pktmbuf_read(ut_params->obuf,
5953                         0, plaintext_len, ciphertext_buffer);
5954         else
5955                 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
5956                         0, plaintext_len, ciphertext_buffer);
5957
5958         /* Validate obuf */
5959         debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5960
5961         /* Validate obuf */
5962         TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5963                 ciphertext,
5964                 tdata->ciphertext.data,
5965                 tdata->validCipherLenInBits.len,
5966                 "ZUC Ciphertext data not as expected");
5967
5968         return 0;
5969 }
5970
5971 static int
5972 test_zuc_authentication(const struct wireless_test_data *tdata)
5973 {
5974         struct crypto_testsuite_params *ts_params = &testsuite_params;
5975         struct crypto_unittest_params *ut_params = &unittest_params;
5976
5977         int retval;
5978         unsigned plaintext_pad_len;
5979         unsigned plaintext_len;
5980         uint8_t *plaintext;
5981
5982         struct rte_cryptodev_sym_capability_idx cap_idx;
5983         struct rte_cryptodev_info dev_info;
5984
5985         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5986         uint64_t feat_flags = dev_info.feature_flags;
5987
5988         if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
5989                         (tdata->validAuthLenInBits.len % 8 != 0)) {
5990                 printf("Device doesn't support NON-Byte Aligned Data.\n");
5991                 return TEST_SKIPPED;
5992         }
5993
5994         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5995                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5996                 printf("Device doesn't support RAW data-path APIs.\n");
5997                 return TEST_SKIPPED;
5998         }
5999
6000         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6001                 return TEST_SKIPPED;
6002
6003         /* Check if device supports ZUC EIA3 */
6004         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6005         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6006
6007         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6008                         &cap_idx) == NULL)
6009                 return TEST_SKIPPED;
6010
6011         /* Create ZUC session */
6012         retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6013                         tdata->key.data, tdata->key.len,
6014                         tdata->auth_iv.len, tdata->digest.len,
6015                         RTE_CRYPTO_AUTH_OP_GENERATE,
6016                         RTE_CRYPTO_AUTH_ZUC_EIA3);
6017         if (retval < 0)
6018                 return retval;
6019
6020         /* alloc mbuf and set payload */
6021         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6022
6023         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6024         rte_pktmbuf_tailroom(ut_params->ibuf));
6025
6026         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6027         /* Append data which is padded to a multiple of */
6028         /* the algorithms block size */
6029         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6030         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6031                                 plaintext_pad_len);
6032         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6033
6034         /* Create ZUC operation */
6035         retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6036                         tdata->auth_iv.data, tdata->auth_iv.len,
6037                         plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6038                         tdata->validAuthLenInBits.len,
6039                         0);
6040         if (retval < 0)
6041                 return retval;
6042
6043         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6044                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6045                                 ut_params->op, 0, 1, 1, 0);
6046         else
6047                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6048                                 ut_params->op);
6049         ut_params->obuf = ut_params->op->sym->m_src;
6050         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6051         ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6052                         + plaintext_pad_len;
6053
6054         /* Validate obuf */
6055         TEST_ASSERT_BUFFERS_ARE_EQUAL(
6056         ut_params->digest,
6057         tdata->digest.data,
6058         tdata->digest.len,
6059         "ZUC Generated auth tag not as expected");
6060
6061         return 0;
6062 }
6063
6064 static int
6065 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6066         uint8_t op_mode, uint8_t verify)
6067 {
6068         struct crypto_testsuite_params *ts_params = &testsuite_params;
6069         struct crypto_unittest_params *ut_params = &unittest_params;
6070
6071         int retval;
6072
6073         uint8_t *plaintext = NULL, *ciphertext = NULL;
6074         unsigned int plaintext_pad_len;
6075         unsigned int plaintext_len;
6076         unsigned int ciphertext_pad_len;
6077         unsigned int ciphertext_len;
6078
6079         struct rte_cryptodev_info dev_info;
6080         struct rte_cryptodev_sym_capability_idx cap_idx;
6081
6082         /* Check if device supports ZUC EIA3 */
6083         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6084         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6085
6086         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6087                         &cap_idx) == NULL)
6088                 return TEST_SKIPPED;
6089
6090         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6091
6092         uint64_t feat_flags = dev_info.feature_flags;
6093
6094         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6095                 printf("Device doesn't support digest encrypted.\n");
6096                 return TEST_SKIPPED;
6097         }
6098         if (op_mode == IN_PLACE) {
6099                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6100                         printf("Device doesn't support in-place scatter-gather "
6101                                         "in both input and output mbufs.\n");
6102                         return TEST_SKIPPED;
6103                 }
6104
6105                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6106                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6107                         printf("Device doesn't support RAW data-path APIs.\n");
6108                         return TEST_SKIPPED;
6109                 }
6110         } else {
6111                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6112                         return TEST_SKIPPED;
6113                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6114                         printf("Device doesn't support out-of-place scatter-gather "
6115                                         "in both input and output mbufs.\n");
6116                         return TEST_SKIPPED;
6117                 }
6118         }
6119
6120         /* Create ZUC session */
6121         retval = create_wireless_algo_auth_cipher_session(
6122                         ts_params->valid_devs[0],
6123                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6124                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6125                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6126                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6127                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6128                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6129                         tdata->key.data, tdata->key.len,
6130                         tdata->auth_iv.len, tdata->digest.len,
6131                         tdata->cipher_iv.len);
6132
6133         if (retval != 0)
6134                 return retval;
6135
6136         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6137         if (op_mode == OUT_OF_PLACE)
6138                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6139
6140         /* clear mbuf payload */
6141         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6142                 rte_pktmbuf_tailroom(ut_params->ibuf));
6143         if (op_mode == OUT_OF_PLACE)
6144                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6145                         rte_pktmbuf_tailroom(ut_params->obuf));
6146
6147         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6148         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6149         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6150         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6151
6152         if (verify) {
6153                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6154                                         ciphertext_pad_len);
6155                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6156                 if (op_mode == OUT_OF_PLACE)
6157                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6158                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6159                         ciphertext_len);
6160         } else {
6161                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6162                                         plaintext_pad_len);
6163                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6164                 if (op_mode == OUT_OF_PLACE)
6165                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6166                 debug_hexdump(stdout, "plaintext:", plaintext,
6167                         plaintext_len);
6168         }
6169
6170         /* Create ZUC operation */
6171         retval = create_wireless_algo_auth_cipher_operation(
6172                 tdata->digest.data, tdata->digest.len,
6173                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6174                 tdata->auth_iv.data, tdata->auth_iv.len,
6175                 (tdata->digest.offset_bytes == 0 ?
6176                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6177                         : tdata->digest.offset_bytes),
6178                 tdata->validCipherLenInBits.len,
6179                 tdata->validCipherOffsetInBits.len,
6180                 tdata->validAuthLenInBits.len,
6181                 0,
6182                 op_mode, 0, verify);
6183
6184         if (retval < 0)
6185                 return retval;
6186
6187         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6188                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6189                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6190         else
6191                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6192                         ut_params->op);
6193
6194         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6195
6196         ut_params->obuf = (op_mode == IN_PLACE ?
6197                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6198
6199
6200         if (verify) {
6201                 if (ut_params->obuf)
6202                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6203                                                         uint8_t *);
6204                 else
6205                         plaintext = ciphertext;
6206
6207                 debug_hexdump(stdout, "plaintext:", plaintext,
6208                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6209                 debug_hexdump(stdout, "plaintext expected:",
6210                         tdata->plaintext.data,
6211                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6212         } else {
6213                 if (ut_params->obuf)
6214                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6215                                                         uint8_t *);
6216                 else
6217                         ciphertext = plaintext;
6218
6219                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6220                         ciphertext_len);
6221                 debug_hexdump(stdout, "ciphertext expected:",
6222                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6223
6224                 ut_params->digest = rte_pktmbuf_mtod(
6225                         ut_params->obuf, uint8_t *) +
6226                         (tdata->digest.offset_bytes == 0 ?
6227                         plaintext_pad_len : tdata->digest.offset_bytes);
6228
6229                 debug_hexdump(stdout, "digest:", ut_params->digest,
6230                         tdata->digest.len);
6231                 debug_hexdump(stdout, "digest expected:",
6232                         tdata->digest.data, tdata->digest.len);
6233         }
6234
6235         /* Validate obuf */
6236         if (verify) {
6237                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6238                         plaintext,
6239                         tdata->plaintext.data,
6240                         tdata->plaintext.len >> 3,
6241                         "ZUC Plaintext data not as expected");
6242         } else {
6243                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6244                         ciphertext,
6245                         tdata->ciphertext.data,
6246                         tdata->ciphertext.len >> 3,
6247                         "ZUC Ciphertext data not as expected");
6248
6249                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6250                         ut_params->digest,
6251                         tdata->digest.data,
6252                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6253                         "ZUC Generated auth tag not as expected");
6254         }
6255         return 0;
6256 }
6257
6258 static int
6259 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6260         uint8_t op_mode, uint8_t verify)
6261 {
6262         struct crypto_testsuite_params *ts_params = &testsuite_params;
6263         struct crypto_unittest_params *ut_params = &unittest_params;
6264
6265         int retval;
6266
6267         const uint8_t *plaintext = NULL;
6268         const uint8_t *ciphertext = NULL;
6269         const uint8_t *digest = NULL;
6270         unsigned int plaintext_pad_len;
6271         unsigned int plaintext_len;
6272         unsigned int ciphertext_pad_len;
6273         unsigned int ciphertext_len;
6274         uint8_t buffer[10000];
6275         uint8_t digest_buffer[10000];
6276
6277         struct rte_cryptodev_info dev_info;
6278         struct rte_cryptodev_sym_capability_idx cap_idx;
6279
6280         /* Check if device supports ZUC EIA3 */
6281         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6282         cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6283
6284         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6285                         &cap_idx) == NULL)
6286                 return TEST_SKIPPED;
6287
6288         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6289
6290         uint64_t feat_flags = dev_info.feature_flags;
6291
6292         if (op_mode == IN_PLACE) {
6293                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6294                         printf("Device doesn't support in-place scatter-gather "
6295                                         "in both input and output mbufs.\n");
6296                         return TEST_SKIPPED;
6297                 }
6298
6299                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6300                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6301                         printf("Device doesn't support RAW data-path APIs.\n");
6302                         return TEST_SKIPPED;
6303                 }
6304         } else {
6305                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6306                         return TEST_SKIPPED;
6307                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6308                         printf("Device doesn't support out-of-place scatter-gather "
6309                                         "in both input and output mbufs.\n");
6310                         return TEST_SKIPPED;
6311                 }
6312                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6313                         printf("Device doesn't support digest encrypted.\n");
6314                         return TEST_SKIPPED;
6315                 }
6316         }
6317
6318         /* Create ZUC session */
6319         retval = create_wireless_algo_auth_cipher_session(
6320                         ts_params->valid_devs[0],
6321                         (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6322                                         : RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6323                         (verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6324                                         : RTE_CRYPTO_AUTH_OP_GENERATE),
6325                         RTE_CRYPTO_AUTH_ZUC_EIA3,
6326                         RTE_CRYPTO_CIPHER_ZUC_EEA3,
6327                         tdata->key.data, tdata->key.len,
6328                         tdata->auth_iv.len, tdata->digest.len,
6329                         tdata->cipher_iv.len);
6330
6331         if (retval != 0)
6332                 return retval;
6333
6334         ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6335         plaintext_len = ceil_byte_length(tdata->plaintext.len);
6336         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6337         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6338
6339         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6340                         plaintext_pad_len, 15, 0);
6341         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6342                         "Failed to allocate input buffer in mempool");
6343
6344         if (op_mode == OUT_OF_PLACE) {
6345                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6346                                 plaintext_pad_len, 15, 0);
6347                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
6348                                 "Failed to allocate output buffer in mempool");
6349         }
6350
6351         if (verify) {
6352                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6353                         tdata->ciphertext.data);
6354                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6355                                         ciphertext_len, buffer);
6356                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6357                         ciphertext_len);
6358         } else {
6359                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6360                         tdata->plaintext.data);
6361                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6362                                         plaintext_len, buffer);
6363                 debug_hexdump(stdout, "plaintext:", plaintext,
6364                         plaintext_len);
6365         }
6366         memset(buffer, 0, sizeof(buffer));
6367
6368         /* Create ZUC operation */
6369         retval = create_wireless_algo_auth_cipher_operation(
6370                 tdata->digest.data, tdata->digest.len,
6371                 tdata->cipher_iv.data, tdata->cipher_iv.len,
6372                 NULL, 0,
6373                 (tdata->digest.offset_bytes == 0 ?
6374                 (verify ? ciphertext_pad_len : plaintext_pad_len)
6375                         : tdata->digest.offset_bytes),
6376                 tdata->validCipherLenInBits.len,
6377                 tdata->validCipherOffsetInBits.len,
6378                 tdata->validAuthLenInBits.len,
6379                 0,
6380                 op_mode, 1, verify);
6381
6382         if (retval < 0)
6383                 return retval;
6384
6385         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6386                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6387                                 ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6388         else
6389                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6390                         ut_params->op);
6391
6392         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6393
6394         ut_params->obuf = (op_mode == IN_PLACE ?
6395                 ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6396
6397         if (verify) {
6398                 if (ut_params->obuf)
6399                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6400                                         plaintext_len, buffer);
6401                 else
6402                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6403                                         plaintext_len, buffer);
6404
6405                 debug_hexdump(stdout, "plaintext:", plaintext,
6406                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6407                 debug_hexdump(stdout, "plaintext expected:",
6408                         tdata->plaintext.data,
6409                         (tdata->plaintext.len >> 3) - tdata->digest.len);
6410         } else {
6411                 if (ut_params->obuf)
6412                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6413                                         ciphertext_len, buffer);
6414                 else
6415                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6416                                         ciphertext_len, buffer);
6417
6418                 debug_hexdump(stdout, "ciphertext:", ciphertext,
6419                         ciphertext_len);
6420                 debug_hexdump(stdout, "ciphertext expected:",
6421                         tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6422
6423                 if (ut_params->obuf)
6424                         digest = rte_pktmbuf_read(ut_params->obuf,
6425                                 (tdata->digest.offset_bytes == 0 ?
6426                                 plaintext_pad_len : tdata->digest.offset_bytes),
6427                                 tdata->digest.len, digest_buffer);
6428                 else
6429                         digest = rte_pktmbuf_read(ut_params->ibuf,
6430                                 (tdata->digest.offset_bytes == 0 ?
6431                                 plaintext_pad_len : tdata->digest.offset_bytes),
6432                                 tdata->digest.len, digest_buffer);
6433
6434                 debug_hexdump(stdout, "digest:", digest,
6435                         tdata->digest.len);
6436                 debug_hexdump(stdout, "digest expected:",
6437                         tdata->digest.data, tdata->digest.len);
6438         }
6439
6440         /* Validate obuf */
6441         if (verify) {
6442                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6443                         plaintext,
6444                         tdata->plaintext.data,
6445                         tdata->plaintext.len >> 3,
6446                         "ZUC Plaintext data not as expected");
6447         } else {
6448                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6449                         ciphertext,
6450                         tdata->ciphertext.data,
6451                         tdata->validDataLenInBits.len,
6452                         "ZUC Ciphertext data not as expected");
6453
6454                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6455                         digest,
6456                         tdata->digest.data,
6457                         DIGEST_BYTE_LENGTH_KASUMI_F9,
6458                         "ZUC Generated auth tag not as expected");
6459         }
6460         return 0;
6461 }
6462
6463 static int
6464 test_kasumi_encryption_test_case_1(void)
6465 {
6466         return test_kasumi_encryption(&kasumi_test_case_1);
6467 }
6468
6469 static int
6470 test_kasumi_encryption_test_case_1_sgl(void)
6471 {
6472         return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6473 }
6474
6475 static int
6476 test_kasumi_encryption_test_case_1_oop(void)
6477 {
6478         return test_kasumi_encryption_oop(&kasumi_test_case_1);
6479 }
6480
6481 static int
6482 test_kasumi_encryption_test_case_1_oop_sgl(void)
6483 {
6484         return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6485 }
6486
6487 static int
6488 test_kasumi_encryption_test_case_2(void)
6489 {
6490         return test_kasumi_encryption(&kasumi_test_case_2);
6491 }
6492
6493 static int
6494 test_kasumi_encryption_test_case_3(void)
6495 {
6496         return test_kasumi_encryption(&kasumi_test_case_3);
6497 }
6498
6499 static int
6500 test_kasumi_encryption_test_case_4(void)
6501 {
6502         return test_kasumi_encryption(&kasumi_test_case_4);
6503 }
6504
6505 static int
6506 test_kasumi_encryption_test_case_5(void)
6507 {
6508         return test_kasumi_encryption(&kasumi_test_case_5);
6509 }
6510
6511 static int
6512 test_kasumi_decryption_test_case_1(void)
6513 {
6514         return test_kasumi_decryption(&kasumi_test_case_1);
6515 }
6516
6517 static int
6518 test_kasumi_decryption_test_case_1_oop(void)
6519 {
6520         return test_kasumi_decryption_oop(&kasumi_test_case_1);
6521 }
6522
6523 static int
6524 test_kasumi_decryption_test_case_2(void)
6525 {
6526         return test_kasumi_decryption(&kasumi_test_case_2);
6527 }
6528
6529 static int
6530 test_kasumi_decryption_test_case_3(void)
6531 {
6532         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6533         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6534                 return TEST_SKIPPED;
6535         return test_kasumi_decryption(&kasumi_test_case_3);
6536 }
6537
6538 static int
6539 test_kasumi_decryption_test_case_4(void)
6540 {
6541         return test_kasumi_decryption(&kasumi_test_case_4);
6542 }
6543
6544 static int
6545 test_kasumi_decryption_test_case_5(void)
6546 {
6547         return test_kasumi_decryption(&kasumi_test_case_5);
6548 }
6549 static int
6550 test_snow3g_encryption_test_case_1(void)
6551 {
6552         return test_snow3g_encryption(&snow3g_test_case_1);
6553 }
6554
6555 static int
6556 test_snow3g_encryption_test_case_1_oop(void)
6557 {
6558         return test_snow3g_encryption_oop(&snow3g_test_case_1);
6559 }
6560
6561 static int
6562 test_snow3g_encryption_test_case_1_oop_sgl(void)
6563 {
6564         return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6565 }
6566
6567
6568 static int
6569 test_snow3g_encryption_test_case_1_offset_oop(void)
6570 {
6571         return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6572 }
6573
6574 static int
6575 test_snow3g_encryption_test_case_2(void)
6576 {
6577         return test_snow3g_encryption(&snow3g_test_case_2);
6578 }
6579
6580 static int
6581 test_snow3g_encryption_test_case_3(void)
6582 {
6583         return test_snow3g_encryption(&snow3g_test_case_3);
6584 }
6585
6586 static int
6587 test_snow3g_encryption_test_case_4(void)
6588 {
6589         return test_snow3g_encryption(&snow3g_test_case_4);
6590 }
6591
6592 static int
6593 test_snow3g_encryption_test_case_5(void)
6594 {
6595         return test_snow3g_encryption(&snow3g_test_case_5);
6596 }
6597
6598 static int
6599 test_snow3g_decryption_test_case_1(void)
6600 {
6601         return test_snow3g_decryption(&snow3g_test_case_1);
6602 }
6603
6604 static int
6605 test_snow3g_decryption_test_case_1_oop(void)
6606 {
6607         return test_snow3g_decryption_oop(&snow3g_test_case_1);
6608 }
6609
6610 static int
6611 test_snow3g_decryption_test_case_2(void)
6612 {
6613         return test_snow3g_decryption(&snow3g_test_case_2);
6614 }
6615
6616 static int
6617 test_snow3g_decryption_test_case_3(void)
6618 {
6619         return test_snow3g_decryption(&snow3g_test_case_3);
6620 }
6621
6622 static int
6623 test_snow3g_decryption_test_case_4(void)
6624 {
6625         return test_snow3g_decryption(&snow3g_test_case_4);
6626 }
6627
6628 static int
6629 test_snow3g_decryption_test_case_5(void)
6630 {
6631         return test_snow3g_decryption(&snow3g_test_case_5);
6632 }
6633
6634 /*
6635  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6636  * Pattern digest from snow3g_test_data must be allocated as
6637  * 4 last bytes in plaintext.
6638  */
6639 static void
6640 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6641                 struct snow3g_hash_test_data *output)
6642 {
6643         if ((pattern != NULL) && (output != NULL)) {
6644                 output->key.len = pattern->key.len;
6645
6646                 memcpy(output->key.data,
6647                 pattern->key.data, pattern->key.len);
6648
6649                 output->auth_iv.len = pattern->auth_iv.len;
6650
6651                 memcpy(output->auth_iv.data,
6652                 pattern->auth_iv.data, pattern->auth_iv.len);
6653
6654                 output->plaintext.len = pattern->plaintext.len;
6655
6656                 memcpy(output->plaintext.data,
6657                 pattern->plaintext.data, pattern->plaintext.len >> 3);
6658
6659                 output->digest.len = pattern->digest.len;
6660
6661                 memcpy(output->digest.data,
6662                 &pattern->plaintext.data[pattern->digest.offset_bytes],
6663                 pattern->digest.len);
6664
6665                 output->validAuthLenInBits.len =
6666                 pattern->validAuthLenInBits.len;
6667         }
6668 }
6669
6670 /*
6671  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6672  */
6673 static int
6674 test_snow3g_decryption_with_digest_test_case_1(void)
6675 {
6676         struct snow3g_hash_test_data snow3g_hash_data;
6677         struct rte_cryptodev_info dev_info;
6678         struct crypto_testsuite_params *ts_params = &testsuite_params;
6679
6680         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6681         uint64_t feat_flags = dev_info.feature_flags;
6682
6683         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6684                 printf("Device doesn't support encrypted digest operations.\n");
6685                 return TEST_SKIPPED;
6686         }
6687
6688         /*
6689          * Function prepare data for hash veryfication test case.
6690          * Digest is allocated in 4 last bytes in plaintext, pattern.
6691          */
6692         snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6693
6694         return test_snow3g_decryption(&snow3g_test_case_7) &
6695                         test_snow3g_authentication_verify(&snow3g_hash_data);
6696 }
6697
6698 static int
6699 test_snow3g_cipher_auth_test_case_1(void)
6700 {
6701         return test_snow3g_cipher_auth(&snow3g_test_case_3);
6702 }
6703
6704 static int
6705 test_snow3g_auth_cipher_test_case_1(void)
6706 {
6707         return test_snow3g_auth_cipher(
6708                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6709 }
6710
6711 static int
6712 test_snow3g_auth_cipher_test_case_2(void)
6713 {
6714         return test_snow3g_auth_cipher(
6715                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6716 }
6717
6718 static int
6719 test_snow3g_auth_cipher_test_case_2_oop(void)
6720 {
6721         return test_snow3g_auth_cipher(
6722                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6723 }
6724
6725 static int
6726 test_snow3g_auth_cipher_part_digest_enc(void)
6727 {
6728         return test_snow3g_auth_cipher(
6729                 &snow3g_auth_cipher_partial_digest_encryption,
6730                         IN_PLACE, 0);
6731 }
6732
6733 static int
6734 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6735 {
6736         return test_snow3g_auth_cipher(
6737                 &snow3g_auth_cipher_partial_digest_encryption,
6738                         OUT_OF_PLACE, 0);
6739 }
6740
6741 static int
6742 test_snow3g_auth_cipher_test_case_3_sgl(void)
6743 {
6744         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6745         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6746                 return TEST_SKIPPED;
6747         return test_snow3g_auth_cipher_sgl(
6748                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6749 }
6750
6751 static int
6752 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6753 {
6754         return test_snow3g_auth_cipher_sgl(
6755                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6756 }
6757
6758 static int
6759 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6760 {
6761         /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6762         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6763                 return TEST_SKIPPED;
6764         return test_snow3g_auth_cipher_sgl(
6765                 &snow3g_auth_cipher_partial_digest_encryption,
6766                         IN_PLACE, 0);
6767 }
6768
6769 static int
6770 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6771 {
6772         return test_snow3g_auth_cipher_sgl(
6773                 &snow3g_auth_cipher_partial_digest_encryption,
6774                         OUT_OF_PLACE, 0);
6775 }
6776
6777 static int
6778 test_snow3g_auth_cipher_verify_test_case_1(void)
6779 {
6780         return test_snow3g_auth_cipher(
6781                 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6782 }
6783
6784 static int
6785 test_snow3g_auth_cipher_verify_test_case_2(void)
6786 {
6787         return test_snow3g_auth_cipher(
6788                 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6789 }
6790
6791 static int
6792 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6793 {
6794         return test_snow3g_auth_cipher(
6795                 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6796 }
6797
6798 static int
6799 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6800 {
6801         return test_snow3g_auth_cipher(
6802                 &snow3g_auth_cipher_partial_digest_encryption,
6803                         IN_PLACE, 1);
6804 }
6805
6806 static int
6807 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6808 {
6809         return test_snow3g_auth_cipher(
6810                 &snow3g_auth_cipher_partial_digest_encryption,
6811                         OUT_OF_PLACE, 1);
6812 }
6813
6814 static int
6815 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6816 {
6817         return test_snow3g_auth_cipher_sgl(
6818                 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6819 }
6820
6821 static int
6822 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6823 {
6824         return test_snow3g_auth_cipher_sgl(
6825                 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6826 }
6827
6828 static int
6829 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6830 {
6831         return test_snow3g_auth_cipher_sgl(
6832                 &snow3g_auth_cipher_partial_digest_encryption,
6833                         IN_PLACE, 1);
6834 }
6835
6836 static int
6837 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6838 {
6839         return test_snow3g_auth_cipher_sgl(
6840                 &snow3g_auth_cipher_partial_digest_encryption,
6841                         OUT_OF_PLACE, 1);
6842 }
6843
6844 static int
6845 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6846 {
6847         return test_snow3g_auth_cipher(
6848                 &snow3g_test_case_7, IN_PLACE, 0);
6849 }
6850
6851 static int
6852 test_kasumi_auth_cipher_test_case_1(void)
6853 {
6854         return test_kasumi_auth_cipher(
6855                 &kasumi_test_case_3, IN_PLACE, 0);
6856 }
6857
6858 static int
6859 test_kasumi_auth_cipher_test_case_2(void)
6860 {
6861         return test_kasumi_auth_cipher(
6862                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6863 }
6864
6865 static int
6866 test_kasumi_auth_cipher_test_case_2_oop(void)
6867 {
6868         return test_kasumi_auth_cipher(
6869                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6870 }
6871
6872 static int
6873 test_kasumi_auth_cipher_test_case_2_sgl(void)
6874 {
6875         return test_kasumi_auth_cipher_sgl(
6876                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6877 }
6878
6879 static int
6880 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6881 {
6882         return test_kasumi_auth_cipher_sgl(
6883                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6884 }
6885
6886 static int
6887 test_kasumi_auth_cipher_verify_test_case_1(void)
6888 {
6889         return test_kasumi_auth_cipher(
6890                 &kasumi_test_case_3, IN_PLACE, 1);
6891 }
6892
6893 static int
6894 test_kasumi_auth_cipher_verify_test_case_2(void)
6895 {
6896         return test_kasumi_auth_cipher(
6897                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6898 }
6899
6900 static int
6901 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6902 {
6903         return test_kasumi_auth_cipher(
6904                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6905 }
6906
6907 static int
6908 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6909 {
6910         return test_kasumi_auth_cipher_sgl(
6911                 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6912 }
6913
6914 static int
6915 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6916 {
6917         return test_kasumi_auth_cipher_sgl(
6918                 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6919 }
6920
6921 static int
6922 test_kasumi_cipher_auth_test_case_1(void)
6923 {
6924         return test_kasumi_cipher_auth(&kasumi_test_case_6);
6925 }
6926
6927 static int
6928 test_zuc_encryption_test_case_1(void)
6929 {
6930         return test_zuc_encryption(&zuc_test_case_cipher_193b);
6931 }
6932
6933 static int
6934 test_zuc_encryption_test_case_2(void)
6935 {
6936         return test_zuc_encryption(&zuc_test_case_cipher_800b);
6937 }
6938
6939 static int
6940 test_zuc_encryption_test_case_3(void)
6941 {
6942         return test_zuc_encryption(&zuc_test_case_cipher_1570b);
6943 }
6944
6945 static int
6946 test_zuc_encryption_test_case_4(void)
6947 {
6948         return test_zuc_encryption(&zuc_test_case_cipher_2798b);
6949 }
6950
6951 static int
6952 test_zuc_encryption_test_case_5(void)
6953 {
6954         return test_zuc_encryption(&zuc_test_case_cipher_4019b);
6955 }
6956
6957 static int
6958 test_zuc_encryption_test_case_6_sgl(void)
6959 {
6960         return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
6961 }
6962
6963 static int
6964 test_zuc_hash_generate_test_case_1(void)
6965 {
6966         return test_zuc_authentication(&zuc_test_case_auth_1b);
6967 }
6968
6969 static int
6970 test_zuc_hash_generate_test_case_2(void)
6971 {
6972         return test_zuc_authentication(&zuc_test_case_auth_90b);
6973 }
6974
6975 static int
6976 test_zuc_hash_generate_test_case_3(void)
6977 {
6978         return test_zuc_authentication(&zuc_test_case_auth_577b);
6979 }
6980
6981 static int
6982 test_zuc_hash_generate_test_case_4(void)
6983 {
6984         return test_zuc_authentication(&zuc_test_case_auth_2079b);
6985 }
6986
6987 static int
6988 test_zuc_hash_generate_test_case_5(void)
6989 {
6990         return test_zuc_authentication(&zuc_test_auth_5670b);
6991 }
6992
6993 static int
6994 test_zuc_hash_generate_test_case_6(void)
6995 {
6996         return test_zuc_authentication(&zuc_test_case_auth_128b);
6997 }
6998
6999 static int
7000 test_zuc_hash_generate_test_case_7(void)
7001 {
7002         return test_zuc_authentication(&zuc_test_case_auth_2080b);
7003 }
7004
7005 static int
7006 test_zuc_hash_generate_test_case_8(void)
7007 {
7008         return test_zuc_authentication(&zuc_test_case_auth_584b);
7009 }
7010
7011 static int
7012 test_zuc_cipher_auth_test_case_1(void)
7013 {
7014         return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7015 }
7016
7017 static int
7018 test_zuc_cipher_auth_test_case_2(void)
7019 {
7020         return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7021 }
7022
7023 static int
7024 test_zuc_auth_cipher_test_case_1(void)
7025 {
7026         return test_zuc_auth_cipher(
7027                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7028 }
7029
7030 static int
7031 test_zuc_auth_cipher_test_case_1_oop(void)
7032 {
7033         return test_zuc_auth_cipher(
7034                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7035 }
7036
7037 static int
7038 test_zuc_auth_cipher_test_case_1_sgl(void)
7039 {
7040         return test_zuc_auth_cipher_sgl(
7041                 &zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7042 }
7043
7044 static int
7045 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7046 {
7047         return test_zuc_auth_cipher_sgl(
7048                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7049 }
7050
7051 static int
7052 test_zuc_auth_cipher_verify_test_case_1(void)
7053 {
7054         return test_zuc_auth_cipher(
7055                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7056 }
7057
7058 static int
7059 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7060 {
7061         return test_zuc_auth_cipher(
7062                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7063 }
7064
7065 static int
7066 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7067 {
7068         return test_zuc_auth_cipher_sgl(
7069                 &zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7070 }
7071
7072 static int
7073 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7074 {
7075         return test_zuc_auth_cipher_sgl(
7076                 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7077 }
7078
7079 static int
7080 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7081 {
7082         uint8_t dev_id = testsuite_params.valid_devs[0];
7083
7084         struct rte_cryptodev_sym_capability_idx cap_idx;
7085
7086         /* Check if device supports particular cipher algorithm */
7087         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7088         cap_idx.algo.cipher = tdata->cipher_algo;
7089         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7090                 return TEST_SKIPPED;
7091
7092         /* Check if device supports particular hash algorithm */
7093         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7094         cap_idx.algo.auth = tdata->auth_algo;
7095         if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7096                 return TEST_SKIPPED;
7097
7098         return 0;
7099 }
7100
7101 static int
7102 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7103         uint8_t op_mode, uint8_t verify)
7104 {
7105         struct crypto_testsuite_params *ts_params = &testsuite_params;
7106         struct crypto_unittest_params *ut_params = &unittest_params;
7107
7108         int retval;
7109
7110         uint8_t *plaintext = NULL, *ciphertext = NULL;
7111         unsigned int plaintext_pad_len;
7112         unsigned int plaintext_len;
7113         unsigned int ciphertext_pad_len;
7114         unsigned int ciphertext_len;
7115
7116         struct rte_cryptodev_info dev_info;
7117         struct rte_crypto_op *op;
7118
7119         /* Check if device supports particular algorithms separately */
7120         if (test_mixed_check_if_unsupported(tdata))
7121                 return TEST_SKIPPED;
7122         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7123                 return TEST_SKIPPED;
7124
7125         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7126
7127         uint64_t feat_flags = dev_info.feature_flags;
7128
7129         if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7130                 printf("Device doesn't support digest encrypted.\n");
7131                 return TEST_SKIPPED;
7132         }
7133
7134         /* Create the session */
7135         if (verify)
7136                 retval = create_wireless_algo_cipher_auth_session(
7137                                 ts_params->valid_devs[0],
7138                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7139                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7140                                 tdata->auth_algo,
7141                                 tdata->cipher_algo,
7142                                 tdata->auth_key.data, tdata->auth_key.len,
7143                                 tdata->auth_iv.len, tdata->digest_enc.len,
7144                                 tdata->cipher_iv.len);
7145         else
7146                 retval = create_wireless_algo_auth_cipher_session(
7147                                 ts_params->valid_devs[0],
7148                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7149                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7150                                 tdata->auth_algo,
7151                                 tdata->cipher_algo,
7152                                 tdata->auth_key.data, tdata->auth_key.len,
7153                                 tdata->auth_iv.len, tdata->digest_enc.len,
7154                                 tdata->cipher_iv.len);
7155         if (retval != 0)
7156                 return retval;
7157
7158         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7159         if (op_mode == OUT_OF_PLACE)
7160                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7161
7162         /* clear mbuf payload */
7163         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7164                 rte_pktmbuf_tailroom(ut_params->ibuf));
7165         if (op_mode == OUT_OF_PLACE) {
7166
7167                 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7168                                 rte_pktmbuf_tailroom(ut_params->obuf));
7169         }
7170
7171         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7172         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7173         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7174         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7175
7176         if (verify) {
7177                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7178                                 ciphertext_pad_len);
7179                 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7180                 if (op_mode == OUT_OF_PLACE)
7181                         rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7182                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7183                                 ciphertext_len);
7184         } else {
7185                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7186                                 plaintext_pad_len);
7187                 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7188                 if (op_mode == OUT_OF_PLACE)
7189                         rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7190                 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7191         }
7192
7193         /* Create the operation */
7194         retval = create_wireless_algo_auth_cipher_operation(
7195                         tdata->digest_enc.data, tdata->digest_enc.len,
7196                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7197                         tdata->auth_iv.data, tdata->auth_iv.len,
7198                         (tdata->digest_enc.offset == 0 ?
7199                                 plaintext_pad_len
7200                                 : tdata->digest_enc.offset),
7201                         tdata->validCipherLen.len_bits,
7202                         tdata->cipher.offset_bits,
7203                         tdata->validAuthLen.len_bits,
7204                         tdata->auth.offset_bits,
7205                         op_mode, 0, verify);
7206
7207         if (retval < 0)
7208                 return retval;
7209
7210         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7211
7212         /* Check if the op failed because the device doesn't */
7213         /* support this particular combination of algorithms */
7214         if (op == NULL && ut_params->op->status ==
7215                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7216                 printf("Device doesn't support this mixed combination. "
7217                                 "Test Skipped.\n");
7218                 return TEST_SKIPPED;
7219         }
7220         ut_params->op = op;
7221
7222         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7223
7224         ut_params->obuf = (op_mode == IN_PLACE ?
7225                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7226
7227         if (verify) {
7228                 if (ut_params->obuf)
7229                         plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7230                                                         uint8_t *);
7231                 else
7232                         plaintext = ciphertext +
7233                                         (tdata->cipher.offset_bits >> 3);
7234
7235                 debug_hexdump(stdout, "plaintext:", plaintext,
7236                                 tdata->plaintext.len_bits >> 3);
7237                 debug_hexdump(stdout, "plaintext expected:",
7238                                 tdata->plaintext.data,
7239                                 tdata->plaintext.len_bits >> 3);
7240         } else {
7241                 if (ut_params->obuf)
7242                         ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7243                                         uint8_t *);
7244                 else
7245                         ciphertext = plaintext;
7246
7247                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7248                                 ciphertext_len);
7249                 debug_hexdump(stdout, "ciphertext expected:",
7250                                 tdata->ciphertext.data,
7251                                 tdata->ciphertext.len_bits >> 3);
7252
7253                 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7254                                 + (tdata->digest_enc.offset == 0 ?
7255                 plaintext_pad_len : tdata->digest_enc.offset);
7256
7257                 debug_hexdump(stdout, "digest:", ut_params->digest,
7258                                 tdata->digest_enc.len);
7259                 debug_hexdump(stdout, "digest expected:",
7260                                 tdata->digest_enc.data,
7261                                 tdata->digest_enc.len);
7262         }
7263
7264         /* Validate obuf */
7265         if (verify) {
7266                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7267                                 plaintext,
7268                                 tdata->plaintext.data,
7269                                 tdata->plaintext.len_bits >> 3,
7270                                 "Plaintext data not as expected");
7271         } else {
7272                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7273                                 ciphertext,
7274                                 tdata->ciphertext.data,
7275                                 tdata->validDataLen.len_bits,
7276                                 "Ciphertext data not as expected");
7277
7278                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7279                                 ut_params->digest,
7280                                 tdata->digest_enc.data,
7281                                 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7282                                 "Generated auth tag not as expected");
7283         }
7284
7285         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7286                         "crypto op processing failed");
7287
7288         return 0;
7289 }
7290
7291 static int
7292 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7293         uint8_t op_mode, uint8_t verify)
7294 {
7295         struct crypto_testsuite_params *ts_params = &testsuite_params;
7296         struct crypto_unittest_params *ut_params = &unittest_params;
7297
7298         int retval;
7299
7300         const uint8_t *plaintext = NULL;
7301         const uint8_t *ciphertext = NULL;
7302         const uint8_t *digest = NULL;
7303         unsigned int plaintext_pad_len;
7304         unsigned int plaintext_len;
7305         unsigned int ciphertext_pad_len;
7306         unsigned int ciphertext_len;
7307         uint8_t buffer[10000];
7308         uint8_t digest_buffer[10000];
7309
7310         struct rte_cryptodev_info dev_info;
7311         struct rte_crypto_op *op;
7312
7313         /* Check if device supports particular algorithms */
7314         if (test_mixed_check_if_unsupported(tdata))
7315                 return TEST_SKIPPED;
7316         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7317                 return TEST_SKIPPED;
7318
7319         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7320
7321         uint64_t feat_flags = dev_info.feature_flags;
7322
7323         if (op_mode == IN_PLACE) {
7324                 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7325                         printf("Device doesn't support in-place scatter-gather "
7326                                         "in both input and output mbufs.\n");
7327                         return TEST_SKIPPED;
7328                 }
7329         } else {
7330                 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7331                         printf("Device doesn't support out-of-place scatter-gather "
7332                                         "in both input and output mbufs.\n");
7333                         return TEST_SKIPPED;
7334                 }
7335                 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7336                         printf("Device doesn't support digest encrypted.\n");
7337                         return TEST_SKIPPED;
7338                 }
7339         }
7340
7341         /* Create the session */
7342         if (verify)
7343                 retval = create_wireless_algo_cipher_auth_session(
7344                                 ts_params->valid_devs[0],
7345                                 RTE_CRYPTO_CIPHER_OP_DECRYPT,
7346                                 RTE_CRYPTO_AUTH_OP_VERIFY,
7347                                 tdata->auth_algo,
7348                                 tdata->cipher_algo,
7349                                 tdata->auth_key.data, tdata->auth_key.len,
7350                                 tdata->auth_iv.len, tdata->digest_enc.len,
7351                                 tdata->cipher_iv.len);
7352         else
7353                 retval = create_wireless_algo_auth_cipher_session(
7354                                 ts_params->valid_devs[0],
7355                                 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7356                                 RTE_CRYPTO_AUTH_OP_GENERATE,
7357                                 tdata->auth_algo,
7358                                 tdata->cipher_algo,
7359                                 tdata->auth_key.data, tdata->auth_key.len,
7360                                 tdata->auth_iv.len, tdata->digest_enc.len,
7361                                 tdata->cipher_iv.len);
7362         if (retval != 0)
7363                 return retval;
7364
7365         ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7366         plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7367         ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7368         plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7369
7370         ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7371                         ciphertext_pad_len, 15, 0);
7372         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7373                         "Failed to allocate input buffer in mempool");
7374
7375         if (op_mode == OUT_OF_PLACE) {
7376                 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7377                                 plaintext_pad_len, 15, 0);
7378                 TEST_ASSERT_NOT_NULL(ut_params->obuf,
7379                                 "Failed to allocate output buffer in mempool");
7380         }
7381
7382         if (verify) {
7383                 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7384                         tdata->ciphertext.data);
7385                 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7386                                         ciphertext_len, buffer);
7387                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7388                         ciphertext_len);
7389         } else {
7390                 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7391                         tdata->plaintext.data);
7392                 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7393                                         plaintext_len, buffer);
7394                 debug_hexdump(stdout, "plaintext:", plaintext,
7395                         plaintext_len);
7396         }
7397         memset(buffer, 0, sizeof(buffer));
7398
7399         /* Create the operation */
7400         retval = create_wireless_algo_auth_cipher_operation(
7401                         tdata->digest_enc.data, tdata->digest_enc.len,
7402                         tdata->cipher_iv.data, tdata->cipher_iv.len,
7403                         tdata->auth_iv.data, tdata->auth_iv.len,
7404                         (tdata->digest_enc.offset == 0 ?
7405                                 plaintext_pad_len
7406                                 : tdata->digest_enc.offset),
7407                         tdata->validCipherLen.len_bits,
7408                         tdata->cipher.offset_bits,
7409                         tdata->validAuthLen.len_bits,
7410                         tdata->auth.offset_bits,
7411                         op_mode, 1, verify);
7412
7413         if (retval < 0)
7414                 return retval;
7415
7416         op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7417
7418         /* Check if the op failed because the device doesn't */
7419         /* support this particular combination of algorithms */
7420         if (op == NULL && ut_params->op->status ==
7421                         RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7422                 printf("Device doesn't support this mixed combination. "
7423                                 "Test Skipped.\n");
7424                 return TEST_SKIPPED;
7425         }
7426         ut_params->op = op;
7427
7428         TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7429
7430         ut_params->obuf = (op_mode == IN_PLACE ?
7431                         ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7432
7433         if (verify) {
7434                 if (ut_params->obuf)
7435                         plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7436                                         plaintext_len, buffer);
7437                 else
7438                         plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7439                                         plaintext_len, buffer);
7440
7441                 debug_hexdump(stdout, "plaintext:", plaintext,
7442                                 (tdata->plaintext.len_bits >> 3) -
7443                                 tdata->digest_enc.len);
7444                 debug_hexdump(stdout, "plaintext expected:",
7445                                 tdata->plaintext.data,
7446                                 (tdata->plaintext.len_bits >> 3) -
7447                                 tdata->digest_enc.len);
7448         } else {
7449                 if (ut_params->obuf)
7450                         ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7451                                         ciphertext_len, buffer);
7452                 else
7453                         ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7454                                         ciphertext_len, buffer);
7455
7456                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7457                         ciphertext_len);
7458                 debug_hexdump(stdout, "ciphertext expected:",
7459                         tdata->ciphertext.data,
7460                         tdata->ciphertext.len_bits >> 3);
7461
7462                 if (ut_params->obuf)
7463                         digest = rte_pktmbuf_read(ut_params->obuf,
7464                                         (tdata->digest_enc.offset == 0 ?
7465                                                 plaintext_pad_len :
7466                                                 tdata->digest_enc.offset),
7467                                         tdata->digest_enc.len, digest_buffer);
7468                 else
7469                         digest = rte_pktmbuf_read(ut_params->ibuf,
7470                                         (tdata->digest_enc.offset == 0 ?
7471                                                 plaintext_pad_len :
7472                                                 tdata->digest_enc.offset),
7473                                         tdata->digest_enc.len, digest_buffer);
7474
7475                 debug_hexdump(stdout, "digest:", digest,
7476                                 tdata->digest_enc.len);
7477                 debug_hexdump(stdout, "digest expected:",
7478                                 tdata->digest_enc.data, tdata->digest_enc.len);
7479         }
7480
7481         /* Validate obuf */
7482         if (verify) {
7483                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7484                                 plaintext,
7485                                 tdata->plaintext.data,
7486                                 tdata->plaintext.len_bits >> 3,
7487                                 "Plaintext data not as expected");
7488         } else {
7489                 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7490                                 ciphertext,
7491                                 tdata->ciphertext.data,
7492                                 tdata->validDataLen.len_bits,
7493                                 "Ciphertext data not as expected");
7494                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7495                                 digest,
7496                                 tdata->digest_enc.data,
7497                                 tdata->digest_enc.len,
7498                                 "Generated auth tag not as expected");
7499         }
7500
7501         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7502                         "crypto op processing failed");
7503
7504         return 0;
7505 }
7506
7507 /** AUTH AES CMAC + CIPHER AES CTR */
7508
7509 static int
7510 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7511 {
7512         return test_mixed_auth_cipher(
7513                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7514 }
7515
7516 static int
7517 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7518 {
7519         return test_mixed_auth_cipher(
7520                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7521 }
7522
7523 static int
7524 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7525 {
7526         return test_mixed_auth_cipher_sgl(
7527                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7528 }
7529
7530 static int
7531 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7532 {
7533         return test_mixed_auth_cipher_sgl(
7534                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7535 }
7536
7537 static int
7538 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7539 {
7540         return test_mixed_auth_cipher(
7541                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7542 }
7543
7544 static int
7545 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7546 {
7547         return test_mixed_auth_cipher(
7548                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7549 }
7550
7551 static int
7552 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7553 {
7554         return test_mixed_auth_cipher_sgl(
7555                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7556 }
7557
7558 static int
7559 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7560 {
7561         return test_mixed_auth_cipher_sgl(
7562                 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7563 }
7564
7565 /** MIXED AUTH + CIPHER */
7566
7567 static int
7568 test_auth_zuc_cipher_snow_test_case_1(void)
7569 {
7570         return test_mixed_auth_cipher(
7571                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7572 }
7573
7574 static int
7575 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7576 {
7577         return test_mixed_auth_cipher(
7578                 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7579 }
7580
7581 static int
7582 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7583 {
7584         return test_mixed_auth_cipher(
7585                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7586 }
7587
7588 static int
7589 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7590 {
7591         return test_mixed_auth_cipher(
7592                 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7593 }
7594
7595 static int
7596 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7597 {
7598         return test_mixed_auth_cipher(
7599                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7600 }
7601
7602 static int
7603 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7604 {
7605         return test_mixed_auth_cipher(
7606                 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7607 }
7608
7609 static int
7610 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7611 {
7612         return test_mixed_auth_cipher(
7613                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7614 }
7615
7616 static int
7617 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7618 {
7619         return test_mixed_auth_cipher(
7620                 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7621 }
7622
7623 static int
7624 test_auth_snow_cipher_zuc_test_case_1(void)
7625 {
7626         return test_mixed_auth_cipher(
7627                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7628 }
7629
7630 static int
7631 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7632 {
7633         return test_mixed_auth_cipher(
7634                 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7635 }
7636
7637 static int
7638 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7639 {
7640         return test_mixed_auth_cipher(
7641                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7642 }
7643
7644 static int
7645 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7646 {
7647         return test_mixed_auth_cipher(
7648                 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7649 }
7650
7651 static int
7652 test_auth_null_cipher_snow_test_case_1(void)
7653 {
7654         return test_mixed_auth_cipher(
7655                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7656 }
7657
7658 static int
7659 test_verify_auth_null_cipher_snow_test_case_1(void)
7660 {
7661         return test_mixed_auth_cipher(
7662                 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7663 }
7664
7665 static int
7666 test_auth_null_cipher_zuc_test_case_1(void)
7667 {
7668         return test_mixed_auth_cipher(
7669                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7670 }
7671
7672 static int
7673 test_verify_auth_null_cipher_zuc_test_case_1(void)
7674 {
7675         return test_mixed_auth_cipher(
7676                 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7677 }
7678
7679 static int
7680 test_auth_snow_cipher_null_test_case_1(void)
7681 {
7682         return test_mixed_auth_cipher(
7683                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7684 }
7685
7686 static int
7687 test_verify_auth_snow_cipher_null_test_case_1(void)
7688 {
7689         return test_mixed_auth_cipher(
7690                 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7691 }
7692
7693 static int
7694 test_auth_zuc_cipher_null_test_case_1(void)
7695 {
7696         return test_mixed_auth_cipher(
7697                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7698 }
7699
7700 static int
7701 test_verify_auth_zuc_cipher_null_test_case_1(void)
7702 {
7703         return test_mixed_auth_cipher(
7704                 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7705 }
7706
7707 static int
7708 test_auth_null_cipher_aes_ctr_test_case_1(void)
7709 {
7710         return test_mixed_auth_cipher(
7711                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7712 }
7713
7714 static int
7715 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7716 {
7717         return test_mixed_auth_cipher(
7718                 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7719 }
7720
7721 static int
7722 test_auth_aes_cmac_cipher_null_test_case_1(void)
7723 {
7724         return test_mixed_auth_cipher(
7725                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7726 }
7727
7728 static int
7729 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7730 {
7731         return test_mixed_auth_cipher(
7732                 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7733 }
7734
7735 /* ***** AEAD algorithm Tests ***** */
7736
7737 static int
7738 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7739                 enum rte_crypto_aead_operation op,
7740                 const uint8_t *key, const uint8_t key_len,
7741                 const uint16_t aad_len, const uint8_t auth_len,
7742                 uint8_t iv_len)
7743 {
7744         uint8_t aead_key[key_len];
7745
7746         struct crypto_testsuite_params *ts_params = &testsuite_params;
7747         struct crypto_unittest_params *ut_params = &unittest_params;
7748
7749         memcpy(aead_key, key, key_len);
7750
7751         /* Setup AEAD Parameters */
7752         ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7753         ut_params->aead_xform.next = NULL;
7754         ut_params->aead_xform.aead.algo = algo;
7755         ut_params->aead_xform.aead.op = op;
7756         ut_params->aead_xform.aead.key.data = aead_key;
7757         ut_params->aead_xform.aead.key.length = key_len;
7758         ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7759         ut_params->aead_xform.aead.iv.length = iv_len;
7760         ut_params->aead_xform.aead.digest_length = auth_len;
7761         ut_params->aead_xform.aead.aad_length = aad_len;
7762
7763         debug_hexdump(stdout, "key:", key, key_len);
7764
7765         /* Create Crypto session*/
7766         ut_params->sess = rte_cryptodev_sym_session_create(
7767                         ts_params->session_mpool);
7768
7769         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7770                         &ut_params->aead_xform,
7771                         ts_params->session_priv_mpool);
7772
7773         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7774
7775         return 0;
7776 }
7777
7778 static int
7779 create_aead_xform(struct rte_crypto_op *op,
7780                 enum rte_crypto_aead_algorithm algo,
7781                 enum rte_crypto_aead_operation aead_op,
7782                 uint8_t *key, const uint8_t key_len,
7783                 const uint8_t aad_len, const uint8_t auth_len,
7784                 uint8_t iv_len)
7785 {
7786         TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7787                         "failed to allocate space for crypto transform");
7788
7789         struct rte_crypto_sym_op *sym_op = op->sym;
7790
7791         /* Setup AEAD Parameters */
7792         sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7793         sym_op->xform->next = NULL;
7794         sym_op->xform->aead.algo = algo;
7795         sym_op->xform->aead.op = aead_op;
7796         sym_op->xform->aead.key.data = key;
7797         sym_op->xform->aead.key.length = key_len;
7798         sym_op->xform->aead.iv.offset = IV_OFFSET;
7799         sym_op->xform->aead.iv.length = iv_len;
7800         sym_op->xform->aead.digest_length = auth_len;
7801         sym_op->xform->aead.aad_length = aad_len;
7802
7803         debug_hexdump(stdout, "key:", key, key_len);
7804
7805         return 0;
7806 }
7807
7808 static int
7809 create_aead_operation(enum rte_crypto_aead_operation op,
7810                 const struct aead_test_data *tdata)
7811 {
7812         struct crypto_testsuite_params *ts_params = &testsuite_params;
7813         struct crypto_unittest_params *ut_params = &unittest_params;
7814
7815         uint8_t *plaintext, *ciphertext;
7816         unsigned int aad_pad_len, plaintext_pad_len;
7817
7818         /* Generate Crypto op data structure */
7819         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7820                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7821         TEST_ASSERT_NOT_NULL(ut_params->op,
7822                         "Failed to allocate symmetric crypto operation struct");
7823
7824         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7825
7826         /* Append aad data */
7827         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7828                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7829                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7830                                 aad_pad_len);
7831                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7832                                 "no room to append aad");
7833
7834                 sym_op->aead.aad.phys_addr =
7835                                 rte_pktmbuf_iova(ut_params->ibuf);
7836                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
7837                 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7838                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7839                         tdata->aad.len);
7840
7841                 /* Append IV at the end of the crypto operation*/
7842                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7843                                 uint8_t *, IV_OFFSET);
7844
7845                 /* Copy IV 1 byte after the IV pointer, according to the API */
7846                 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7847                 debug_hexdump(stdout, "iv:", iv_ptr,
7848                         tdata->iv.len);
7849         } else {
7850                 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7851                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7852                                 aad_pad_len);
7853                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7854                                 "no room to append aad");
7855
7856                 sym_op->aead.aad.phys_addr =
7857                                 rte_pktmbuf_iova(ut_params->ibuf);
7858                 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7859                 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7860                         tdata->aad.len);
7861
7862                 /* Append IV at the end of the crypto operation*/
7863                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7864                                 uint8_t *, IV_OFFSET);
7865
7866                 if (tdata->iv.len == 0) {
7867                         rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7868                         debug_hexdump(stdout, "iv:", iv_ptr,
7869                                 AES_GCM_J0_LENGTH);
7870                 } else {
7871                         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7872                         debug_hexdump(stdout, "iv:", iv_ptr,
7873                                 tdata->iv.len);
7874                 }
7875         }
7876
7877         /* Append plaintext/ciphertext */
7878         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7879                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7880                 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7881                                 plaintext_pad_len);
7882                 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7883
7884                 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7885                 debug_hexdump(stdout, "plaintext:", plaintext,
7886                                 tdata->plaintext.len);
7887
7888                 if (ut_params->obuf) {
7889                         ciphertext = (uint8_t *)rte_pktmbuf_append(
7890                                         ut_params->obuf,
7891                                         plaintext_pad_len + aad_pad_len);
7892                         TEST_ASSERT_NOT_NULL(ciphertext,
7893                                         "no room to append ciphertext");
7894
7895                         memset(ciphertext + aad_pad_len, 0,
7896                                         tdata->ciphertext.len);
7897                 }
7898         } else {
7899                 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7900                 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7901                                 plaintext_pad_len);
7902                 TEST_ASSERT_NOT_NULL(ciphertext,
7903                                 "no room to append ciphertext");
7904
7905                 memcpy(ciphertext, tdata->ciphertext.data,
7906                                 tdata->ciphertext.len);
7907                 debug_hexdump(stdout, "ciphertext:", ciphertext,
7908                                 tdata->ciphertext.len);
7909
7910                 if (ut_params->obuf) {
7911                         plaintext = (uint8_t *)rte_pktmbuf_append(
7912                                         ut_params->obuf,
7913                                         plaintext_pad_len + aad_pad_len);
7914                         TEST_ASSERT_NOT_NULL(plaintext,
7915                                         "no room to append plaintext");
7916
7917                         memset(plaintext + aad_pad_len, 0,
7918                                         tdata->plaintext.len);
7919                 }
7920         }
7921
7922         /* Append digest data */
7923         if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7924                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7925                                 ut_params->obuf ? ut_params->obuf :
7926                                                 ut_params->ibuf,
7927                                                 tdata->auth_tag.len);
7928                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7929                                 "no room to append digest");
7930                 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
7931                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7932                                 ut_params->obuf ? ut_params->obuf :
7933                                                 ut_params->ibuf,
7934                                                 plaintext_pad_len +
7935                                                 aad_pad_len);
7936         } else {
7937                 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7938                                 ut_params->ibuf, tdata->auth_tag.len);
7939                 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7940                                 "no room to append digest");
7941                 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7942                                 ut_params->ibuf,
7943                                 plaintext_pad_len + aad_pad_len);
7944
7945                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
7946                         tdata->auth_tag.len);
7947                 debug_hexdump(stdout, "digest:",
7948                         sym_op->aead.digest.data,
7949                         tdata->auth_tag.len);
7950         }
7951
7952         sym_op->aead.data.length = tdata->plaintext.len;
7953         sym_op->aead.data.offset = aad_pad_len;
7954
7955         return 0;
7956 }
7957
7958 static int
7959 test_authenticated_encryption(const struct aead_test_data *tdata)
7960 {
7961         struct crypto_testsuite_params *ts_params = &testsuite_params;
7962         struct crypto_unittest_params *ut_params = &unittest_params;
7963
7964         int retval;
7965         uint8_t *ciphertext, *auth_tag;
7966         uint16_t plaintext_pad_len;
7967         uint32_t i;
7968         struct rte_cryptodev_info dev_info;
7969
7970         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7971         uint64_t feat_flags = dev_info.feature_flags;
7972
7973         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
7974                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
7975                 printf("Device doesn't support RAW data-path APIs.\n");
7976                 return TEST_SKIPPED;
7977         }
7978
7979         /* Verify the capabilities */
7980         struct rte_cryptodev_sym_capability_idx cap_idx;
7981         const struct rte_cryptodev_symmetric_capability *capability;
7982         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7983         cap_idx.algo.aead = tdata->algo;
7984         capability = rte_cryptodev_sym_capability_get(
7985                         ts_params->valid_devs[0], &cap_idx);
7986         if (capability == NULL)
7987                 return TEST_SKIPPED;
7988         if (rte_cryptodev_sym_capability_check_aead(
7989                         capability, tdata->key.len, tdata->auth_tag.len,
7990                         tdata->aad.len, tdata->iv.len))
7991                 return TEST_SKIPPED;
7992
7993         /* Create AEAD session */
7994         retval = create_aead_session(ts_params->valid_devs[0],
7995                         tdata->algo,
7996                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
7997                         tdata->key.data, tdata->key.len,
7998                         tdata->aad.len, tdata->auth_tag.len,
7999                         tdata->iv.len);
8000         if (retval < 0)
8001                 return retval;
8002
8003         if (tdata->aad.len > MBUF_SIZE) {
8004                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8005                 /* Populate full size of add data */
8006                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8007                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8008         } else
8009                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8010
8011         /* clear mbuf payload */
8012         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8013                         rte_pktmbuf_tailroom(ut_params->ibuf));
8014
8015         /* Create AEAD operation */
8016         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8017         if (retval < 0)
8018                 return retval;
8019
8020         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8021
8022         ut_params->op->sym->m_src = ut_params->ibuf;
8023
8024         /* Process crypto operation */
8025         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8026                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8027         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8028                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8029                                 ut_params->op, 0, 0, 0, 0);
8030         else
8031                 TEST_ASSERT_NOT_NULL(
8032                         process_crypto_request(ts_params->valid_devs[0],
8033                         ut_params->op), "failed to process sym crypto op");
8034
8035         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8036                         "crypto op processing failed");
8037
8038         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8039
8040         if (ut_params->op->sym->m_dst) {
8041                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8042                                 uint8_t *);
8043                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8044                                 uint8_t *, plaintext_pad_len);
8045         } else {
8046                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8047                                 uint8_t *,
8048                                 ut_params->op->sym->cipher.data.offset);
8049                 auth_tag = ciphertext + plaintext_pad_len;
8050         }
8051
8052         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8053         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8054
8055         /* Validate obuf */
8056         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8057                         ciphertext,
8058                         tdata->ciphertext.data,
8059                         tdata->ciphertext.len,
8060                         "Ciphertext data not as expected");
8061
8062         TEST_ASSERT_BUFFERS_ARE_EQUAL(
8063                         auth_tag,
8064                         tdata->auth_tag.data,
8065                         tdata->auth_tag.len,
8066                         "Generated auth tag not as expected");
8067
8068         return 0;
8069
8070 }
8071
8072 #ifdef RTE_LIB_SECURITY
8073 static int
8074 security_proto_supported(enum rte_security_session_action_type action,
8075         enum rte_security_session_protocol proto)
8076 {
8077         struct crypto_testsuite_params *ts_params = &testsuite_params;
8078
8079         const struct rte_security_capability *capabilities;
8080         const struct rte_security_capability *capability;
8081         uint16_t i = 0;
8082
8083         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8084                                 rte_cryptodev_get_sec_ctx(
8085                                 ts_params->valid_devs[0]);
8086
8087
8088         capabilities = rte_security_capabilities_get(ctx);
8089
8090         if (capabilities == NULL)
8091                 return -ENOTSUP;
8092
8093         while ((capability = &capabilities[i++])->action !=
8094                         RTE_SECURITY_ACTION_TYPE_NONE) {
8095                 if (capability->action == action &&
8096                                 capability->protocol == proto)
8097                         return 0;
8098         }
8099
8100         return -ENOTSUP;
8101 }
8102
8103 /* Basic algorithm run function for async inplace mode.
8104  * Creates a session from input parameters and runs one operation
8105  * on input_vec. Checks the output of the crypto operation against
8106  * output_vec.
8107  */
8108 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8109                            enum rte_crypto_auth_operation opa,
8110                            const uint8_t *input_vec, unsigned int input_vec_len,
8111                            const uint8_t *output_vec,
8112                            unsigned int output_vec_len,
8113                            enum rte_crypto_cipher_algorithm cipher_alg,
8114                            const uint8_t *cipher_key, uint32_t cipher_key_len,
8115                            enum rte_crypto_auth_algorithm auth_alg,
8116                            const uint8_t *auth_key, uint32_t auth_key_len,
8117                            uint8_t bearer, enum rte_security_pdcp_domain domain,
8118                            uint8_t packet_direction, uint8_t sn_size,
8119                            uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8120 {
8121         struct crypto_testsuite_params *ts_params = &testsuite_params;
8122         struct crypto_unittest_params *ut_params = &unittest_params;
8123         uint8_t *plaintext;
8124         int ret = TEST_SUCCESS;
8125         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8126                                 rte_cryptodev_get_sec_ctx(
8127                                 ts_params->valid_devs[0]);
8128
8129         /* Verify the capabilities */
8130         struct rte_security_capability_idx sec_cap_idx;
8131
8132         sec_cap_idx.action = ut_params->type;
8133         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8134         sec_cap_idx.pdcp.domain = domain;
8135         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8136                 return TEST_SKIPPED;
8137
8138         /* Generate test mbuf data */
8139         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8140
8141         /* clear mbuf payload */
8142         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8143                         rte_pktmbuf_tailroom(ut_params->ibuf));
8144
8145         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8146                                                   input_vec_len);
8147         memcpy(plaintext, input_vec, input_vec_len);
8148
8149         /* Out of place support */
8150         if (oop) {
8151                 /*
8152                  * For out-op-place we need to alloc another mbuf
8153                  */
8154                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8155                 rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8156         }
8157
8158         /* Setup Cipher Parameters */
8159         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8160         ut_params->cipher_xform.cipher.algo = cipher_alg;
8161         ut_params->cipher_xform.cipher.op = opc;
8162         ut_params->cipher_xform.cipher.key.data = cipher_key;
8163         ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8164         ut_params->cipher_xform.cipher.iv.length =
8165                                 packet_direction ? 4 : 0;
8166         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8167
8168         /* Setup HMAC Parameters if ICV header is required */
8169         if (auth_alg != 0) {
8170                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8171                 ut_params->auth_xform.next = NULL;
8172                 ut_params->auth_xform.auth.algo = auth_alg;
8173                 ut_params->auth_xform.auth.op = opa;
8174                 ut_params->auth_xform.auth.key.data = auth_key;
8175                 ut_params->auth_xform.auth.key.length = auth_key_len;
8176
8177                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8178         } else {
8179                 ut_params->cipher_xform.next = NULL;
8180         }
8181
8182         struct rte_security_session_conf sess_conf = {
8183                 .action_type = ut_params->type,
8184                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8185                 {.pdcp = {
8186                         .bearer = bearer,
8187                         .domain = domain,
8188                         .pkt_dir = packet_direction,
8189                         .sn_size = sn_size,
8190                         .hfn = packet_direction ? 0 : hfn,
8191                         /**
8192                          * hfn can be set as pdcp_test_hfn[i]
8193                          * if hfn_ovrd is not set. Here, PDCP
8194                          * packet direction is just used to
8195                          * run half of the cases with session
8196                          * HFN and other half with per packet
8197                          * HFN.
8198                          */
8199                         .hfn_threshold = hfn_threshold,
8200                         .hfn_ovrd = packet_direction ? 1 : 0,
8201                         .sdap_enabled = sdap,
8202                 } },
8203                 .crypto_xform = &ut_params->cipher_xform
8204         };
8205
8206         /* Create security session */
8207         ut_params->sec_session = rte_security_session_create(ctx,
8208                                 &sess_conf, ts_params->session_mpool,
8209                                 ts_params->session_priv_mpool);
8210
8211         if (!ut_params->sec_session) {
8212                 printf("TestCase %s()-%d line %d failed %s: ",
8213                         __func__, i, __LINE__, "Failed to allocate session");
8214                 ret = TEST_FAILED;
8215                 goto on_err;
8216         }
8217
8218         /* Generate crypto op data structure */
8219         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8220                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8221         if (!ut_params->op) {
8222                 printf("TestCase %s()-%d line %d failed %s: ",
8223                         __func__, i, __LINE__,
8224                         "Failed to allocate symmetric crypto operation struct");
8225                 ret = TEST_FAILED;
8226                 goto on_err;
8227         }
8228
8229         uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8230                                         uint32_t *, IV_OFFSET);
8231         *per_pkt_hfn = packet_direction ? hfn : 0;
8232
8233         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8234
8235         /* set crypto operation source mbuf */
8236         ut_params->op->sym->m_src = ut_params->ibuf;
8237         if (oop)
8238                 ut_params->op->sym->m_dst = ut_params->obuf;
8239
8240         /* Process crypto operation */
8241         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8242                 == NULL) {
8243                 printf("TestCase %s()-%d line %d failed %s: ",
8244                         __func__, i, __LINE__,
8245                         "failed to process sym crypto op");
8246                 ret = TEST_FAILED;
8247                 goto on_err;
8248         }
8249
8250         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8251                 printf("TestCase %s()-%d line %d failed %s: ",
8252                         __func__, i, __LINE__, "crypto op processing failed");
8253                 ret = TEST_FAILED;
8254                 goto on_err;
8255         }
8256
8257         /* Validate obuf */
8258         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8259                         uint8_t *);
8260         if (oop) {
8261                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8262                                 uint8_t *);
8263         }
8264
8265         if (memcmp(ciphertext, output_vec, output_vec_len)) {
8266                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8267                 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8268                 rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8269                 ret = TEST_FAILED;
8270                 goto on_err;
8271         }
8272
8273 on_err:
8274         rte_crypto_op_free(ut_params->op);
8275         ut_params->op = NULL;
8276
8277         if (ut_params->sec_session)
8278                 rte_security_session_destroy(ctx, ut_params->sec_session);
8279         ut_params->sec_session = NULL;
8280
8281         rte_pktmbuf_free(ut_params->ibuf);
8282         ut_params->ibuf = NULL;
8283         if (oop) {
8284                 rte_pktmbuf_free(ut_params->obuf);
8285                 ut_params->obuf = NULL;
8286         }
8287
8288         return ret;
8289 }
8290
8291 static int
8292 test_pdcp_proto_SGL(int i, int oop,
8293         enum rte_crypto_cipher_operation opc,
8294         enum rte_crypto_auth_operation opa,
8295         uint8_t *input_vec,
8296         unsigned int input_vec_len,
8297         uint8_t *output_vec,
8298         unsigned int output_vec_len,
8299         uint32_t fragsz,
8300         uint32_t fragsz_oop)
8301 {
8302         struct crypto_testsuite_params *ts_params = &testsuite_params;
8303         struct crypto_unittest_params *ut_params = &unittest_params;
8304         uint8_t *plaintext;
8305         struct rte_mbuf *buf, *buf_oop = NULL;
8306         int ret = TEST_SUCCESS;
8307         int to_trn = 0;
8308         int to_trn_tbl[16];
8309         int segs = 1;
8310         unsigned int trn_data = 0;
8311         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8312                                 rte_cryptodev_get_sec_ctx(
8313                                 ts_params->valid_devs[0]);
8314
8315         /* Verify the capabilities */
8316         struct rte_security_capability_idx sec_cap_idx;
8317
8318         sec_cap_idx.action = ut_params->type;
8319         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8320         sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8321         if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8322                 return TEST_SKIPPED;
8323
8324         if (fragsz > input_vec_len)
8325                 fragsz = input_vec_len;
8326
8327         uint16_t plaintext_len = fragsz;
8328         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8329
8330         if (fragsz_oop > output_vec_len)
8331                 frag_size_oop = output_vec_len;
8332
8333         int ecx = 0;
8334         if (input_vec_len % fragsz != 0) {
8335                 if (input_vec_len / fragsz + 1 > 16)
8336                         return 1;
8337         } else if (input_vec_len / fragsz > 16)
8338                 return 1;
8339
8340         /* Out of place support */
8341         if (oop) {
8342                 /*
8343                  * For out-op-place we need to alloc another mbuf
8344                  */
8345                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8346                 rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8347                 buf_oop = ut_params->obuf;
8348         }
8349
8350         /* Generate test mbuf data */
8351         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8352
8353         /* clear mbuf payload */
8354         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8355                         rte_pktmbuf_tailroom(ut_params->ibuf));
8356
8357         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8358                                                   plaintext_len);
8359         memcpy(plaintext, input_vec, plaintext_len);
8360         trn_data += plaintext_len;
8361
8362         buf = ut_params->ibuf;
8363
8364         /*
8365          * Loop until no more fragments
8366          */
8367
8368         while (trn_data < input_vec_len) {
8369                 ++segs;
8370                 to_trn = (input_vec_len - trn_data < fragsz) ?
8371                                 (input_vec_len - trn_data) : fragsz;
8372
8373                 to_trn_tbl[ecx++] = to_trn;
8374
8375                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8376                 buf = buf->next;
8377
8378                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8379                                 rte_pktmbuf_tailroom(buf));
8380
8381                 /* OOP */
8382                 if (oop && !fragsz_oop) {
8383                         buf_oop->next =
8384                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
8385                         buf_oop = buf_oop->next;
8386                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8387                                         0, rte_pktmbuf_tailroom(buf_oop));
8388                         rte_pktmbuf_append(buf_oop, to_trn);
8389                 }
8390
8391                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8392                                 to_trn);
8393
8394                 memcpy(plaintext, input_vec + trn_data, to_trn);
8395                 trn_data += to_trn;
8396         }
8397
8398         ut_params->ibuf->nb_segs = segs;
8399
8400         segs = 1;
8401         if (fragsz_oop && oop) {
8402                 to_trn = 0;
8403                 ecx = 0;
8404
8405                 trn_data = frag_size_oop;
8406                 while (trn_data < output_vec_len) {
8407                         ++segs;
8408                         to_trn =
8409                                 (output_vec_len - trn_data <
8410                                                 frag_size_oop) ?
8411                                 (output_vec_len - trn_data) :
8412                                                 frag_size_oop;
8413
8414                         to_trn_tbl[ecx++] = to_trn;
8415
8416                         buf_oop->next =
8417                                 rte_pktmbuf_alloc(ts_params->mbuf_pool);
8418                         buf_oop = buf_oop->next;
8419                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8420                                         0, rte_pktmbuf_tailroom(buf_oop));
8421                         rte_pktmbuf_append(buf_oop, to_trn);
8422
8423                         trn_data += to_trn;
8424                 }
8425                 ut_params->obuf->nb_segs = segs;
8426         }
8427
8428         /* Setup Cipher Parameters */
8429         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8430         ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8431         ut_params->cipher_xform.cipher.op = opc;
8432         ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8433         ut_params->cipher_xform.cipher.key.length =
8434                                         pdcp_test_params[i].cipher_key_len;
8435         ut_params->cipher_xform.cipher.iv.length = 0;
8436
8437         /* Setup HMAC Parameters if ICV header is required */
8438         if (pdcp_test_params[i].auth_alg != 0) {
8439                 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8440                 ut_params->auth_xform.next = NULL;
8441                 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8442                 ut_params->auth_xform.auth.op = opa;
8443                 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8444                 ut_params->auth_xform.auth.key.length =
8445                                         pdcp_test_params[i].auth_key_len;
8446
8447                 ut_params->cipher_xform.next = &ut_params->auth_xform;
8448         } else {
8449                 ut_params->cipher_xform.next = NULL;
8450         }
8451
8452         struct rte_security_session_conf sess_conf = {
8453                 .action_type = ut_params->type,
8454                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
8455                 {.pdcp = {
8456                         .bearer = pdcp_test_bearer[i],
8457                         .domain = pdcp_test_params[i].domain,
8458                         .pkt_dir = pdcp_test_packet_direction[i],
8459                         .sn_size = pdcp_test_data_sn_size[i],
8460                         .hfn = pdcp_test_hfn[i],
8461                         .hfn_threshold = pdcp_test_hfn_threshold[i],
8462                         .hfn_ovrd = 0,
8463                 } },
8464                 .crypto_xform = &ut_params->cipher_xform
8465         };
8466
8467         /* Create security session */
8468         ut_params->sec_session = rte_security_session_create(ctx,
8469                                 &sess_conf, ts_params->session_mpool,
8470                                 ts_params->session_priv_mpool);
8471
8472         if (!ut_params->sec_session) {
8473                 printf("TestCase %s()-%d line %d failed %s: ",
8474                         __func__, i, __LINE__, "Failed to allocate session");
8475                 ret = TEST_FAILED;
8476                 goto on_err;
8477         }
8478
8479         /* Generate crypto op data structure */
8480         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8481                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8482         if (!ut_params->op) {
8483                 printf("TestCase %s()-%d line %d failed %s: ",
8484                         __func__, i, __LINE__,
8485                         "Failed to allocate symmetric crypto operation struct");
8486                 ret = TEST_FAILED;
8487                 goto on_err;
8488         }
8489
8490         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8491
8492         /* set crypto operation source mbuf */
8493         ut_params->op->sym->m_src = ut_params->ibuf;
8494         if (oop)
8495                 ut_params->op->sym->m_dst = ut_params->obuf;
8496
8497         /* Process crypto operation */
8498         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8499                 == NULL) {
8500                 printf("TestCase %s()-%d line %d failed %s: ",
8501                         __func__, i, __LINE__,
8502                         "failed to process sym crypto op");
8503                 ret = TEST_FAILED;
8504                 goto on_err;
8505         }
8506
8507         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8508                 printf("TestCase %s()-%d line %d failed %s: ",
8509                         __func__, i, __LINE__, "crypto op processing failed");
8510                 ret = TEST_FAILED;
8511                 goto on_err;
8512         }
8513
8514         /* Validate obuf */
8515         uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8516                         uint8_t *);
8517         if (oop) {
8518                 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8519                                 uint8_t *);
8520         }
8521         if (fragsz_oop)
8522                 fragsz = frag_size_oop;
8523         if (memcmp(ciphertext, output_vec, fragsz)) {
8524                 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8525                 rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8526                 rte_hexdump(stdout, "reference", output_vec, fragsz);
8527                 ret = TEST_FAILED;
8528                 goto on_err;
8529         }
8530
8531         buf = ut_params->op->sym->m_src->next;
8532         if (oop)
8533                 buf = ut_params->op->sym->m_dst->next;
8534
8535         unsigned int off = fragsz;
8536
8537         ecx = 0;
8538         while (buf) {
8539                 ciphertext = rte_pktmbuf_mtod(buf,
8540                                 uint8_t *);
8541                 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8542                         printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8543                         rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8544                         rte_hexdump(stdout, "reference", output_vec + off,
8545                                         to_trn_tbl[ecx]);
8546                         ret = TEST_FAILED;
8547                         goto on_err;
8548                 }
8549                 off += to_trn_tbl[ecx++];
8550                 buf = buf->next;
8551         }
8552 on_err:
8553         rte_crypto_op_free(ut_params->op);
8554         ut_params->op = NULL;
8555
8556         if (ut_params->sec_session)
8557                 rte_security_session_destroy(ctx, ut_params->sec_session);
8558         ut_params->sec_session = NULL;
8559
8560         rte_pktmbuf_free(ut_params->ibuf);
8561         ut_params->ibuf = NULL;
8562         if (oop) {
8563                 rte_pktmbuf_free(ut_params->obuf);
8564                 ut_params->obuf = NULL;
8565         }
8566
8567         return ret;
8568 }
8569
8570 int
8571 test_pdcp_proto_cplane_encap(int i)
8572 {
8573         return test_pdcp_proto(
8574                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8575                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8576                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8577                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8578                 pdcp_test_params[i].cipher_key_len,
8579                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8580                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8581                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8582                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8583                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8584 }
8585
8586 int
8587 test_pdcp_proto_uplane_encap(int i)
8588 {
8589         return test_pdcp_proto(
8590                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8591                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8592                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8593                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8594                 pdcp_test_params[i].cipher_key_len,
8595                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8596                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8597                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8598                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8599                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8600 }
8601
8602 int
8603 test_pdcp_proto_uplane_encap_with_int(int i)
8604 {
8605         return test_pdcp_proto(
8606                 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8607                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8608                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8609                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8610                 pdcp_test_params[i].cipher_key_len,
8611                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8612                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8613                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8614                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8615                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8616 }
8617
8618 int
8619 test_pdcp_proto_cplane_decap(int i)
8620 {
8621         return test_pdcp_proto(
8622                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8623                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8624                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8625                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8626                 pdcp_test_params[i].cipher_key_len,
8627                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8628                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8629                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8630                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8631                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8632 }
8633
8634 int
8635 test_pdcp_proto_uplane_decap(int i)
8636 {
8637         return test_pdcp_proto(
8638                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8639                 pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8640                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8641                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8642                 pdcp_test_params[i].cipher_key_len,
8643                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8644                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8645                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8646                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8647                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8648 }
8649
8650 int
8651 test_pdcp_proto_uplane_decap_with_int(int i)
8652 {
8653         return test_pdcp_proto(
8654                 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8655                 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8656                 pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8657                 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8658                 pdcp_test_params[i].cipher_key_len,
8659                 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8660                 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8661                 pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8662                 pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8663                 pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8664 }
8665
8666 static int
8667 test_PDCP_PROTO_SGL_in_place_32B(void)
8668 {
8669         /* i can be used for running any PDCP case
8670          * In this case it is uplane 12-bit AES-SNOW DL encap
8671          */
8672         int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8673         return test_pdcp_proto_SGL(i, IN_PLACE,
8674                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8675                         RTE_CRYPTO_AUTH_OP_GENERATE,
8676                         pdcp_test_data_in[i],
8677                         pdcp_test_data_in_len[i],
8678                         pdcp_test_data_out[i],
8679                         pdcp_test_data_in_len[i]+4,
8680                         32, 0);
8681 }
8682 static int
8683 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8684 {
8685         /* i can be used for running any PDCP case
8686          * In this case it is uplane 18-bit NULL-NULL DL encap
8687          */
8688         int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8689         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8690                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8691                         RTE_CRYPTO_AUTH_OP_GENERATE,
8692                         pdcp_test_data_in[i],
8693                         pdcp_test_data_in_len[i],
8694                         pdcp_test_data_out[i],
8695                         pdcp_test_data_in_len[i]+4,
8696                         32, 128);
8697 }
8698 static int
8699 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8700 {
8701         /* i can be used for running any PDCP case
8702          * In this case it is uplane 18-bit AES DL encap
8703          */
8704         int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8705                         + DOWNLINK;
8706         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8707                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8708                         RTE_CRYPTO_AUTH_OP_GENERATE,
8709                         pdcp_test_data_in[i],
8710                         pdcp_test_data_in_len[i],
8711                         pdcp_test_data_out[i],
8712                         pdcp_test_data_in_len[i],
8713                         32, 40);
8714 }
8715 static int
8716 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8717 {
8718         /* i can be used for running any PDCP case
8719          * In this case it is cplane 12-bit AES-ZUC DL encap
8720          */
8721         int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8722         return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8723                         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8724                         RTE_CRYPTO_AUTH_OP_GENERATE,
8725                         pdcp_test_data_in[i],
8726                         pdcp_test_data_in_len[i],
8727                         pdcp_test_data_out[i],
8728                         pdcp_test_data_in_len[i]+4,
8729                         128, 32);
8730 }
8731
8732 static int
8733 test_PDCP_SDAP_PROTO_encap_all(void)
8734 {
8735         int i = 0, size = 0;
8736         int err, all_err = TEST_SUCCESS;
8737         const struct pdcp_sdap_test *cur_test;
8738
8739         size = ARRAY_SIZE(list_pdcp_sdap_tests);
8740
8741         for (i = 0; i < size; i++) {
8742                 cur_test = &list_pdcp_sdap_tests[i];
8743                 err = test_pdcp_proto(
8744                         i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8745                         RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8746                         cur_test->in_len, cur_test->data_out,
8747                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8748                         cur_test->param.cipher_alg, cur_test->cipher_key,
8749                         cur_test->param.cipher_key_len,
8750                         cur_test->param.auth_alg,
8751                         cur_test->auth_key, cur_test->param.auth_key_len,
8752                         cur_test->bearer, cur_test->param.domain,
8753                         cur_test->packet_direction, cur_test->sn_size,
8754                         cur_test->hfn,
8755                         cur_test->hfn_threshold, SDAP_ENABLED);
8756                 if (err) {
8757                         printf("\t%d) %s: Encapsulation failed\n",
8758                                         cur_test->test_idx,
8759                                         cur_test->param.name);
8760                         err = TEST_FAILED;
8761                 } else {
8762                         printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8763                                         cur_test->param.name);
8764                         err = TEST_SUCCESS;
8765                 }
8766                 all_err += err;
8767         }
8768
8769         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8770
8771         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8772 }
8773
8774 static int
8775 test_PDCP_SDAP_PROTO_decap_all(void)
8776 {
8777         int i = 0, size = 0;
8778         int err, all_err = TEST_SUCCESS;
8779         const struct pdcp_sdap_test *cur_test;
8780
8781         size = ARRAY_SIZE(list_pdcp_sdap_tests);
8782
8783         for (i = 0; i < size; i++) {
8784                 cur_test = &list_pdcp_sdap_tests[i];
8785                 err = test_pdcp_proto(
8786                         i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8787                         RTE_CRYPTO_AUTH_OP_VERIFY,
8788                         cur_test->data_out,
8789                         cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8790                         cur_test->data_in, cur_test->in_len,
8791                         cur_test->param.cipher_alg,
8792                         cur_test->cipher_key, cur_test->param.cipher_key_len,
8793                         cur_test->param.auth_alg, cur_test->auth_key,
8794                         cur_test->param.auth_key_len, cur_test->bearer,
8795                         cur_test->param.domain, cur_test->packet_direction,
8796                         cur_test->sn_size, cur_test->hfn,
8797                         cur_test->hfn_threshold, SDAP_ENABLED);
8798                 if (err) {
8799                         printf("\t%d) %s: Decapsulation failed\n",
8800                                         cur_test->test_idx,
8801                                         cur_test->param.name);
8802                         err = TEST_FAILED;
8803                 } else {
8804                         printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8805                                         cur_test->param.name);
8806                         err = TEST_SUCCESS;
8807                 }
8808                 all_err += err;
8809         }
8810
8811         printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8812
8813         return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8814 }
8815
8816 static int
8817 test_PDCP_PROTO_all(void)
8818 {
8819         struct crypto_testsuite_params *ts_params = &testsuite_params;
8820         struct crypto_unittest_params *ut_params = &unittest_params;
8821         struct rte_cryptodev_info dev_info;
8822         int status;
8823
8824         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8825         uint64_t feat_flags = dev_info.feature_flags;
8826
8827         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8828                 return TEST_SKIPPED;
8829
8830         /* Set action type */
8831         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8832                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8833                 gbl_action_type;
8834
8835         if (security_proto_supported(ut_params->type,
8836                         RTE_SECURITY_PROTOCOL_PDCP) < 0)
8837                 return TEST_SKIPPED;
8838
8839         status = test_PDCP_PROTO_cplane_encap_all();
8840         status += test_PDCP_PROTO_cplane_decap_all();
8841         status += test_PDCP_PROTO_uplane_encap_all();
8842         status += test_PDCP_PROTO_uplane_decap_all();
8843         status += test_PDCP_PROTO_SGL_in_place_32B();
8844         status += test_PDCP_PROTO_SGL_oop_32B_128B();
8845         status += test_PDCP_PROTO_SGL_oop_32B_40B();
8846         status += test_PDCP_PROTO_SGL_oop_128B_32B();
8847         status += test_PDCP_SDAP_PROTO_encap_all();
8848         status += test_PDCP_SDAP_PROTO_decap_all();
8849
8850         if (status)
8851                 return TEST_FAILED;
8852         else
8853                 return TEST_SUCCESS;
8854 }
8855
8856 static int
8857 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
8858 {
8859         struct crypto_testsuite_params *ts_params = &testsuite_params;
8860         struct crypto_unittest_params *ut_params = &unittest_params;
8861         uint8_t *plaintext, *ciphertext;
8862         uint8_t *iv_ptr;
8863         int32_t cipher_len, crc_len;
8864         uint32_t crc_data_len;
8865         int ret = TEST_SUCCESS;
8866
8867         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8868                                         rte_cryptodev_get_sec_ctx(
8869                                                 ts_params->valid_devs[0]);
8870
8871         /* Verify the capabilities */
8872         struct rte_security_capability_idx sec_cap_idx;
8873         const struct rte_security_capability *sec_cap;
8874         const struct rte_cryptodev_capabilities *crypto_cap;
8875         const struct rte_cryptodev_symmetric_capability *sym_cap;
8876         int j = 0;
8877
8878         sec_cap_idx.action = ut_params->type;
8879         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8880         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
8881
8882         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8883         if (sec_cap == NULL)
8884                 return TEST_SKIPPED;
8885
8886         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8887                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8888                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8889                                 crypto_cap->sym.xform_type ==
8890                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
8891                                 crypto_cap->sym.cipher.algo ==
8892                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8893                         sym_cap = &crypto_cap->sym;
8894                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8895                                                 d_td->key.len,
8896                                                 d_td->iv.len) == 0)
8897                                 break;
8898                 }
8899         }
8900
8901         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8902                 return TEST_SKIPPED;
8903
8904         /* Setup source mbuf payload */
8905         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8906         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8907                         rte_pktmbuf_tailroom(ut_params->ibuf));
8908
8909         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8910                         d_td->ciphertext.len);
8911
8912         memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
8913
8914         /* Setup cipher session parameters */
8915         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8916         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8917         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
8918         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8919         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8920         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8921         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8922         ut_params->cipher_xform.next = NULL;
8923
8924         /* Setup DOCSIS session parameters */
8925         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
8926
8927         struct rte_security_session_conf sess_conf = {
8928                 .action_type = ut_params->type,
8929                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8930                 .docsis = ut_params->docsis_xform,
8931                 .crypto_xform = &ut_params->cipher_xform,
8932         };
8933
8934         /* Create security session */
8935         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
8936                                         ts_params->session_mpool,
8937                                         ts_params->session_priv_mpool);
8938
8939         if (!ut_params->sec_session) {
8940                 printf("TestCase %s(%d) line %d: %s\n",
8941                         __func__, i, __LINE__, "failed to allocate session");
8942                 ret = TEST_FAILED;
8943                 goto on_err;
8944         }
8945
8946         /* Generate crypto op data structure */
8947         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8948                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8949         if (!ut_params->op) {
8950                 printf("TestCase %s(%d) line %d: %s\n",
8951                         __func__, i, __LINE__,
8952                         "failed to allocate symmetric crypto operation");
8953                 ret = TEST_FAILED;
8954                 goto on_err;
8955         }
8956
8957         /* Setup CRC operation parameters */
8958         crc_len = d_td->ciphertext.no_crc == false ?
8959                         (d_td->ciphertext.len -
8960                                 d_td->ciphertext.crc_offset -
8961                                 RTE_ETHER_CRC_LEN) :
8962                         0;
8963         crc_len = crc_len > 0 ? crc_len : 0;
8964         crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
8965         ut_params->op->sym->auth.data.length = crc_len;
8966         ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
8967
8968         /* Setup cipher operation parameters */
8969         cipher_len = d_td->ciphertext.no_cipher == false ?
8970                         (d_td->ciphertext.len -
8971                                 d_td->ciphertext.cipher_offset) :
8972                         0;
8973         cipher_len = cipher_len > 0 ? cipher_len : 0;
8974         ut_params->op->sym->cipher.data.length = cipher_len;
8975         ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
8976
8977         /* Setup cipher IV */
8978         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
8979         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
8980
8981         /* Attach session to operation */
8982         rte_security_attach_session(ut_params->op, ut_params->sec_session);
8983
8984         /* Set crypto operation mbufs */
8985         ut_params->op->sym->m_src = ut_params->ibuf;
8986         ut_params->op->sym->m_dst = NULL;
8987
8988         /* Process crypto operation */
8989         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
8990                         NULL) {
8991                 printf("TestCase %s(%d) line %d: %s\n",
8992                         __func__, i, __LINE__,
8993                         "failed to process security crypto op");
8994                 ret = TEST_FAILED;
8995                 goto on_err;
8996         }
8997
8998         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8999                 printf("TestCase %s(%d) line %d: %s\n",
9000                         __func__, i, __LINE__, "crypto op processing failed");
9001                 ret = TEST_FAILED;
9002                 goto on_err;
9003         }
9004
9005         /* Validate plaintext */
9006         plaintext = ciphertext;
9007
9008         if (memcmp(plaintext, d_td->plaintext.data,
9009                         d_td->plaintext.len - crc_data_len)) {
9010                 printf("TestCase %s(%d) line %d: %s\n",
9011                         __func__, i, __LINE__, "plaintext not as expected\n");
9012                 rte_hexdump(stdout, "expected", d_td->plaintext.data,
9013                                 d_td->plaintext.len);
9014                 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9015                 ret = TEST_FAILED;
9016                 goto on_err;
9017         }
9018
9019 on_err:
9020         rte_crypto_op_free(ut_params->op);
9021         ut_params->op = NULL;
9022
9023         if (ut_params->sec_session)
9024                 rte_security_session_destroy(ctx, ut_params->sec_session);
9025         ut_params->sec_session = NULL;
9026
9027         rte_pktmbuf_free(ut_params->ibuf);
9028         ut_params->ibuf = NULL;
9029
9030         return ret;
9031 }
9032
9033 static int
9034 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9035 {
9036         struct crypto_testsuite_params *ts_params = &testsuite_params;
9037         struct crypto_unittest_params *ut_params = &unittest_params;
9038         uint8_t *plaintext, *ciphertext;
9039         uint8_t *iv_ptr;
9040         int32_t cipher_len, crc_len;
9041         int ret = TEST_SUCCESS;
9042
9043         struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9044                                         rte_cryptodev_get_sec_ctx(
9045                                                 ts_params->valid_devs[0]);
9046
9047         /* Verify the capabilities */
9048         struct rte_security_capability_idx sec_cap_idx;
9049         const struct rte_security_capability *sec_cap;
9050         const struct rte_cryptodev_capabilities *crypto_cap;
9051         const struct rte_cryptodev_symmetric_capability *sym_cap;
9052         int j = 0;
9053
9054         sec_cap_idx.action = ut_params->type;
9055         sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9056         sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9057
9058         sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9059         if (sec_cap == NULL)
9060                 return TEST_SKIPPED;
9061
9062         while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9063                         RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9064                 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9065                                 crypto_cap->sym.xform_type ==
9066                                         RTE_CRYPTO_SYM_XFORM_CIPHER &&
9067                                 crypto_cap->sym.cipher.algo ==
9068                                         RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9069                         sym_cap = &crypto_cap->sym;
9070                         if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9071                                                 d_td->key.len,
9072                                                 d_td->iv.len) == 0)
9073                                 break;
9074                 }
9075         }
9076
9077         if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9078                 return TEST_SKIPPED;
9079
9080         /* Setup source mbuf payload */
9081         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9082         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9083                         rte_pktmbuf_tailroom(ut_params->ibuf));
9084
9085         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9086                         d_td->plaintext.len);
9087
9088         memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9089
9090         /* Setup cipher session parameters */
9091         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9092         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9093         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9094         ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9095         ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9096         ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9097         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9098         ut_params->cipher_xform.next = NULL;
9099
9100         /* Setup DOCSIS session parameters */
9101         ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9102
9103         struct rte_security_session_conf sess_conf = {
9104                 .action_type = ut_params->type,
9105                 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9106                 .docsis = ut_params->docsis_xform,
9107                 .crypto_xform = &ut_params->cipher_xform,
9108         };
9109
9110         /* Create security session */
9111         ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9112                                         ts_params->session_mpool,
9113                                         ts_params->session_priv_mpool);
9114
9115         if (!ut_params->sec_session) {
9116                 printf("TestCase %s(%d) line %d: %s\n",
9117                         __func__, i, __LINE__, "failed to allocate session");
9118                 ret = TEST_FAILED;
9119                 goto on_err;
9120         }
9121
9122         /* Generate crypto op data structure */
9123         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9124                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9125         if (!ut_params->op) {
9126                 printf("TestCase %s(%d) line %d: %s\n",
9127                         __func__, i, __LINE__,
9128                         "failed to allocate security crypto operation");
9129                 ret = TEST_FAILED;
9130                 goto on_err;
9131         }
9132
9133         /* Setup CRC operation parameters */
9134         crc_len = d_td->plaintext.no_crc == false ?
9135                         (d_td->plaintext.len -
9136                                 d_td->plaintext.crc_offset -
9137                                 RTE_ETHER_CRC_LEN) :
9138                         0;
9139         crc_len = crc_len > 0 ? crc_len : 0;
9140         ut_params->op->sym->auth.data.length = crc_len;
9141         ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9142
9143         /* Setup cipher operation parameters */
9144         cipher_len = d_td->plaintext.no_cipher == false ?
9145                         (d_td->plaintext.len -
9146                                 d_td->plaintext.cipher_offset) :
9147                         0;
9148         cipher_len = cipher_len > 0 ? cipher_len : 0;
9149         ut_params->op->sym->cipher.data.length = cipher_len;
9150         ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9151
9152         /* Setup cipher IV */
9153         iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9154         rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9155
9156         /* Attach session to operation */
9157         rte_security_attach_session(ut_params->op, ut_params->sec_session);
9158
9159         /* Set crypto operation mbufs */
9160         ut_params->op->sym->m_src = ut_params->ibuf;
9161         ut_params->op->sym->m_dst = NULL;
9162
9163         /* Process crypto operation */
9164         if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9165                         NULL) {
9166                 printf("TestCase %s(%d) line %d: %s\n",
9167                         __func__, i, __LINE__,
9168                         "failed to process security crypto op");
9169                 ret = TEST_FAILED;
9170                 goto on_err;
9171         }
9172
9173         if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9174                 printf("TestCase %s(%d) line %d: %s\n",
9175                         __func__, i, __LINE__, "crypto op processing failed");
9176                 ret = TEST_FAILED;
9177                 goto on_err;
9178         }
9179
9180         /* Validate ciphertext */
9181         ciphertext = plaintext;
9182
9183         if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9184                 printf("TestCase %s(%d) line %d: %s\n",
9185                         __func__, i, __LINE__, "ciphertext not as expected\n");
9186                 rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9187                                 d_td->ciphertext.len);
9188                 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9189                 ret = TEST_FAILED;
9190                 goto on_err;
9191         }
9192
9193 on_err:
9194         rte_crypto_op_free(ut_params->op);
9195         ut_params->op = NULL;
9196
9197         if (ut_params->sec_session)
9198                 rte_security_session_destroy(ctx, ut_params->sec_session);
9199         ut_params->sec_session = NULL;
9200
9201         rte_pktmbuf_free(ut_params->ibuf);
9202         ut_params->ibuf = NULL;
9203
9204         return ret;
9205 }
9206
9207 #define TEST_DOCSIS_COUNT(func) do {                    \
9208         int ret = func;                                 \
9209         if (ret == TEST_SUCCESS)  {                     \
9210                 printf("\t%2d)", n++);                  \
9211                 printf("+++++ PASSED:" #func"\n");      \
9212                 p++;                                    \
9213         } else if (ret == TEST_SKIPPED) {               \
9214                 printf("\t%2d)", n++);                  \
9215                 printf("~~~~~ SKIPPED:" #func"\n");     \
9216                 s++;                                    \
9217         } else {                                        \
9218                 printf("\t%2d)", n++);                  \
9219                 printf("----- FAILED:" #func"\n");      \
9220                 f++;                                    \
9221         }                                               \
9222 } while (0)
9223
9224 static int
9225 test_DOCSIS_PROTO_uplink_all(void)
9226 {
9227         int p = 0, s = 0, f = 0, n = 0;
9228
9229         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9230         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9231         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9232         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9233         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9234         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9235         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9236         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9237         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9238         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9239         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9240         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9241         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9242         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9243         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9244         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9245         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9246         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9247         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9248         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9249         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9250         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9251         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9252         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9253         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9254         TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9255
9256         if (f)
9257                 printf("## %s: %d passed out of %d (%d skipped)\n",
9258                         __func__, p, n, s);
9259
9260         return f;
9261 };
9262
9263 static int
9264 test_DOCSIS_PROTO_downlink_all(void)
9265 {
9266         int p = 0, s = 0, f = 0, n = 0;
9267
9268         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9269         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9270         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9271         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9272         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9273         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9274         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9275         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9276         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9277         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9278         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9279         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9280         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9281         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9282         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9283         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9284         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9285         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9286         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9287         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9288         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9289         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9290         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9291         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9292         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9293         TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9294
9295         if (f)
9296                 printf("## %s: %d passed out of %d (%d skipped)\n",
9297                         __func__, p, n, s);
9298
9299         return f;
9300 };
9301
9302 static int
9303 test_DOCSIS_PROTO_all(void)
9304 {
9305         struct crypto_testsuite_params *ts_params = &testsuite_params;
9306         struct crypto_unittest_params *ut_params = &unittest_params;
9307         struct rte_cryptodev_info dev_info;
9308         int status;
9309
9310         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9311         uint64_t feat_flags = dev_info.feature_flags;
9312
9313         if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9314                 return TEST_SKIPPED;
9315
9316         /* Set action type */
9317         ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9318                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9319                 gbl_action_type;
9320
9321         if (security_proto_supported(ut_params->type,
9322                         RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9323                 return TEST_SKIPPED;
9324
9325         status = test_DOCSIS_PROTO_uplink_all();
9326         status += test_DOCSIS_PROTO_downlink_all();
9327
9328         if (status)
9329                 return TEST_FAILED;
9330         else
9331                 return TEST_SUCCESS;
9332 }
9333 #endif
9334
9335 static int
9336 test_AES_GCM_authenticated_encryption_test_case_1(void)
9337 {
9338         return test_authenticated_encryption(&gcm_test_case_1);
9339 }
9340
9341 static int
9342 test_AES_GCM_authenticated_encryption_test_case_2(void)
9343 {
9344         return test_authenticated_encryption(&gcm_test_case_2);
9345 }
9346
9347 static int
9348 test_AES_GCM_authenticated_encryption_test_case_3(void)
9349 {
9350         return test_authenticated_encryption(&gcm_test_case_3);
9351 }
9352
9353 static int
9354 test_AES_GCM_authenticated_encryption_test_case_4(void)
9355 {
9356         return test_authenticated_encryption(&gcm_test_case_4);
9357 }
9358
9359 static int
9360 test_AES_GCM_authenticated_encryption_test_case_5(void)
9361 {
9362         return test_authenticated_encryption(&gcm_test_case_5);
9363 }
9364
9365 static int
9366 test_AES_GCM_authenticated_encryption_test_case_6(void)
9367 {
9368         return test_authenticated_encryption(&gcm_test_case_6);
9369 }
9370
9371 static int
9372 test_AES_GCM_authenticated_encryption_test_case_7(void)
9373 {
9374         return test_authenticated_encryption(&gcm_test_case_7);
9375 }
9376
9377 static int
9378 test_AES_GCM_authenticated_encryption_test_case_8(void)
9379 {
9380         return test_authenticated_encryption(&gcm_test_case_8);
9381 }
9382
9383 static int
9384 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9385 {
9386         return test_authenticated_encryption(&gcm_J0_test_case_1);
9387 }
9388
9389 static int
9390 test_AES_GCM_auth_encryption_test_case_192_1(void)
9391 {
9392         return test_authenticated_encryption(&gcm_test_case_192_1);
9393 }
9394
9395 static int
9396 test_AES_GCM_auth_encryption_test_case_192_2(void)
9397 {
9398         return test_authenticated_encryption(&gcm_test_case_192_2);
9399 }
9400
9401 static int
9402 test_AES_GCM_auth_encryption_test_case_192_3(void)
9403 {
9404         return test_authenticated_encryption(&gcm_test_case_192_3);
9405 }
9406
9407 static int
9408 test_AES_GCM_auth_encryption_test_case_192_4(void)
9409 {
9410         return test_authenticated_encryption(&gcm_test_case_192_4);
9411 }
9412
9413 static int
9414 test_AES_GCM_auth_encryption_test_case_192_5(void)
9415 {
9416         return test_authenticated_encryption(&gcm_test_case_192_5);
9417 }
9418
9419 static int
9420 test_AES_GCM_auth_encryption_test_case_192_6(void)
9421 {
9422         return test_authenticated_encryption(&gcm_test_case_192_6);
9423 }
9424
9425 static int
9426 test_AES_GCM_auth_encryption_test_case_192_7(void)
9427 {
9428         return test_authenticated_encryption(&gcm_test_case_192_7);
9429 }
9430
9431 static int
9432 test_AES_GCM_auth_encryption_test_case_256_1(void)
9433 {
9434         return test_authenticated_encryption(&gcm_test_case_256_1);
9435 }
9436
9437 static int
9438 test_AES_GCM_auth_encryption_test_case_256_2(void)
9439 {
9440         return test_authenticated_encryption(&gcm_test_case_256_2);
9441 }
9442
9443 static int
9444 test_AES_GCM_auth_encryption_test_case_256_3(void)
9445 {
9446         return test_authenticated_encryption(&gcm_test_case_256_3);
9447 }
9448
9449 static int
9450 test_AES_GCM_auth_encryption_test_case_256_4(void)
9451 {
9452         return test_authenticated_encryption(&gcm_test_case_256_4);
9453 }
9454
9455 static int
9456 test_AES_GCM_auth_encryption_test_case_256_5(void)
9457 {
9458         return test_authenticated_encryption(&gcm_test_case_256_5);
9459 }
9460
9461 static int
9462 test_AES_GCM_auth_encryption_test_case_256_6(void)
9463 {
9464         return test_authenticated_encryption(&gcm_test_case_256_6);
9465 }
9466
9467 static int
9468 test_AES_GCM_auth_encryption_test_case_256_7(void)
9469 {
9470         return test_authenticated_encryption(&gcm_test_case_256_7);
9471 }
9472
9473 static int
9474 test_AES_GCM_auth_encryption_test_case_aad_1(void)
9475 {
9476         return test_authenticated_encryption(&gcm_test_case_aad_1);
9477 }
9478
9479 static int
9480 test_AES_GCM_auth_encryption_test_case_aad_2(void)
9481 {
9482         return test_authenticated_encryption(&gcm_test_case_aad_2);
9483 }
9484
9485 static int
9486 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
9487 {
9488         struct aead_test_data tdata;
9489         int res;
9490
9491         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9492         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9493         tdata.iv.data[0] += 1;
9494         res = test_authenticated_encryption(&tdata);
9495         if (res == TEST_SKIPPED)
9496                 return res;
9497         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9498         return TEST_SUCCESS;
9499 }
9500
9501 static int
9502 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
9503 {
9504         struct aead_test_data tdata;
9505         int res;
9506
9507         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9508         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9509         tdata.plaintext.data[0] += 1;
9510         res = test_authenticated_encryption(&tdata);
9511         if (res == TEST_SKIPPED)
9512                 return res;
9513         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9514         return TEST_SUCCESS;
9515 }
9516
9517 static int
9518 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
9519 {
9520         struct aead_test_data tdata;
9521         int res;
9522
9523         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9524         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9525         tdata.ciphertext.data[0] += 1;
9526         res = test_authenticated_encryption(&tdata);
9527         if (res == TEST_SKIPPED)
9528                 return res;
9529         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9530         return TEST_SUCCESS;
9531 }
9532
9533 static int
9534 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
9535 {
9536         struct aead_test_data tdata;
9537         int res;
9538
9539         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9540         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9541         tdata.aad.len += 1;
9542         res = test_authenticated_encryption(&tdata);
9543         if (res == TEST_SKIPPED)
9544                 return res;
9545         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9546         return TEST_SUCCESS;
9547 }
9548
9549 static int
9550 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
9551 {
9552         struct aead_test_data tdata;
9553         uint8_t aad[gcm_test_case_7.aad.len];
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         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9559         aad[0] += 1;
9560         tdata.aad.data = aad;
9561         res = test_authenticated_encryption(&tdata);
9562         if (res == TEST_SKIPPED)
9563                 return res;
9564         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9565         return TEST_SUCCESS;
9566 }
9567
9568 static int
9569 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
9570 {
9571         struct aead_test_data tdata;
9572         int res;
9573
9574         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9575         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9576         tdata.auth_tag.data[0] += 1;
9577         res = test_authenticated_encryption(&tdata);
9578         if (res == TEST_SKIPPED)
9579                 return res;
9580         TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9581         return TEST_SUCCESS;
9582 }
9583
9584 static int
9585 test_authenticated_decryption(const struct aead_test_data *tdata)
9586 {
9587         struct crypto_testsuite_params *ts_params = &testsuite_params;
9588         struct crypto_unittest_params *ut_params = &unittest_params;
9589
9590         int retval;
9591         uint8_t *plaintext;
9592         uint32_t i;
9593         struct rte_cryptodev_info dev_info;
9594
9595         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9596         uint64_t feat_flags = dev_info.feature_flags;
9597
9598         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9599                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9600                 printf("Device doesn't support RAW data-path APIs.\n");
9601                 return TEST_SKIPPED;
9602         }
9603
9604         /* Verify the capabilities */
9605         struct rte_cryptodev_sym_capability_idx cap_idx;
9606         const struct rte_cryptodev_symmetric_capability *capability;
9607         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9608         cap_idx.algo.aead = tdata->algo;
9609         capability = rte_cryptodev_sym_capability_get(
9610                         ts_params->valid_devs[0], &cap_idx);
9611         if (capability == NULL)
9612                 return TEST_SKIPPED;
9613         if (rte_cryptodev_sym_capability_check_aead(
9614                         capability, tdata->key.len, tdata->auth_tag.len,
9615                         tdata->aad.len, tdata->iv.len))
9616                 return TEST_SKIPPED;
9617
9618         /* Create AEAD session */
9619         retval = create_aead_session(ts_params->valid_devs[0],
9620                         tdata->algo,
9621                         RTE_CRYPTO_AEAD_OP_DECRYPT,
9622                         tdata->key.data, tdata->key.len,
9623                         tdata->aad.len, tdata->auth_tag.len,
9624                         tdata->iv.len);
9625         if (retval < 0)
9626                 return retval;
9627
9628         /* alloc mbuf and set payload */
9629         if (tdata->aad.len > MBUF_SIZE) {
9630                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9631                 /* Populate full size of add data */
9632                 for (i = 32; i < MAX_AAD_LENGTH; i += 32)
9633                         memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
9634         } else
9635                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9636
9637         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9638                         rte_pktmbuf_tailroom(ut_params->ibuf));
9639
9640         /* Create AEAD operation */
9641         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9642         if (retval < 0)
9643                 return retval;
9644
9645         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9646
9647         ut_params->op->sym->m_src = ut_params->ibuf;
9648
9649         /* Process crypto operation */
9650         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9651                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
9652         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9653                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9654                                 ut_params->op, 0, 0, 0, 0);
9655         else
9656                 TEST_ASSERT_NOT_NULL(
9657                         process_crypto_request(ts_params->valid_devs[0],
9658                         ut_params->op), "failed to process sym crypto op");
9659
9660         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9661                         "crypto op processing failed");
9662
9663         if (ut_params->op->sym->m_dst)
9664                 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9665                                 uint8_t *);
9666         else
9667                 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
9668                                 uint8_t *,
9669                                 ut_params->op->sym->cipher.data.offset);
9670
9671         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9672
9673         /* Validate obuf */
9674         TEST_ASSERT_BUFFERS_ARE_EQUAL(
9675                         plaintext,
9676                         tdata->plaintext.data,
9677                         tdata->plaintext.len,
9678                         "Plaintext data not as expected");
9679
9680         TEST_ASSERT_EQUAL(ut_params->op->status,
9681                         RTE_CRYPTO_OP_STATUS_SUCCESS,
9682                         "Authentication failed");
9683
9684         return 0;
9685 }
9686
9687 static int
9688 test_AES_GCM_authenticated_decryption_test_case_1(void)
9689 {
9690         return test_authenticated_decryption(&gcm_test_case_1);
9691 }
9692
9693 static int
9694 test_AES_GCM_authenticated_decryption_test_case_2(void)
9695 {
9696         return test_authenticated_decryption(&gcm_test_case_2);
9697 }
9698
9699 static int
9700 test_AES_GCM_authenticated_decryption_test_case_3(void)
9701 {
9702         return test_authenticated_decryption(&gcm_test_case_3);
9703 }
9704
9705 static int
9706 test_AES_GCM_authenticated_decryption_test_case_4(void)
9707 {
9708         return test_authenticated_decryption(&gcm_test_case_4);
9709 }
9710
9711 static int
9712 test_AES_GCM_authenticated_decryption_test_case_5(void)
9713 {
9714         return test_authenticated_decryption(&gcm_test_case_5);
9715 }
9716
9717 static int
9718 test_AES_GCM_authenticated_decryption_test_case_6(void)
9719 {
9720         return test_authenticated_decryption(&gcm_test_case_6);
9721 }
9722
9723 static int
9724 test_AES_GCM_authenticated_decryption_test_case_7(void)
9725 {
9726         return test_authenticated_decryption(&gcm_test_case_7);
9727 }
9728
9729 static int
9730 test_AES_GCM_authenticated_decryption_test_case_8(void)
9731 {
9732         return test_authenticated_decryption(&gcm_test_case_8);
9733 }
9734
9735 static int
9736 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
9737 {
9738         return test_authenticated_decryption(&gcm_J0_test_case_1);
9739 }
9740
9741 static int
9742 test_AES_GCM_auth_decryption_test_case_192_1(void)
9743 {
9744         return test_authenticated_decryption(&gcm_test_case_192_1);
9745 }
9746
9747 static int
9748 test_AES_GCM_auth_decryption_test_case_192_2(void)
9749 {
9750         return test_authenticated_decryption(&gcm_test_case_192_2);
9751 }
9752
9753 static int
9754 test_AES_GCM_auth_decryption_test_case_192_3(void)
9755 {
9756         return test_authenticated_decryption(&gcm_test_case_192_3);
9757 }
9758
9759 static int
9760 test_AES_GCM_auth_decryption_test_case_192_4(void)
9761 {
9762         return test_authenticated_decryption(&gcm_test_case_192_4);
9763 }
9764
9765 static int
9766 test_AES_GCM_auth_decryption_test_case_192_5(void)
9767 {
9768         return test_authenticated_decryption(&gcm_test_case_192_5);
9769 }
9770
9771 static int
9772 test_AES_GCM_auth_decryption_test_case_192_6(void)
9773 {
9774         return test_authenticated_decryption(&gcm_test_case_192_6);
9775 }
9776
9777 static int
9778 test_AES_GCM_auth_decryption_test_case_192_7(void)
9779 {
9780         return test_authenticated_decryption(&gcm_test_case_192_7);
9781 }
9782
9783 static int
9784 test_AES_GCM_auth_decryption_test_case_256_1(void)
9785 {
9786         return test_authenticated_decryption(&gcm_test_case_256_1);
9787 }
9788
9789 static int
9790 test_AES_GCM_auth_decryption_test_case_256_2(void)
9791 {
9792         return test_authenticated_decryption(&gcm_test_case_256_2);
9793 }
9794
9795 static int
9796 test_AES_GCM_auth_decryption_test_case_256_3(void)
9797 {
9798         return test_authenticated_decryption(&gcm_test_case_256_3);
9799 }
9800
9801 static int
9802 test_AES_GCM_auth_decryption_test_case_256_4(void)
9803 {
9804         return test_authenticated_decryption(&gcm_test_case_256_4);
9805 }
9806
9807 static int
9808 test_AES_GCM_auth_decryption_test_case_256_5(void)
9809 {
9810         return test_authenticated_decryption(&gcm_test_case_256_5);
9811 }
9812
9813 static int
9814 test_AES_GCM_auth_decryption_test_case_256_6(void)
9815 {
9816         return test_authenticated_decryption(&gcm_test_case_256_6);
9817 }
9818
9819 static int
9820 test_AES_GCM_auth_decryption_test_case_256_7(void)
9821 {
9822         return test_authenticated_decryption(&gcm_test_case_256_7);
9823 }
9824
9825 static int
9826 test_AES_GCM_auth_decryption_test_case_aad_1(void)
9827 {
9828         return test_authenticated_decryption(&gcm_test_case_aad_1);
9829 }
9830
9831 static int
9832 test_AES_GCM_auth_decryption_test_case_aad_2(void)
9833 {
9834         return test_authenticated_decryption(&gcm_test_case_aad_2);
9835 }
9836
9837 static int
9838 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
9839 {
9840         struct aead_test_data tdata;
9841         int res;
9842
9843         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9844         tdata.iv.data[0] += 1;
9845         res = test_authenticated_decryption(&tdata);
9846         if (res == TEST_SKIPPED)
9847                 return res;
9848         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9849         return TEST_SUCCESS;
9850 }
9851
9852 static int
9853 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
9854 {
9855         struct aead_test_data tdata;
9856         int res;
9857
9858         RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9859         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9860         tdata.plaintext.data[0] += 1;
9861         res = test_authenticated_decryption(&tdata);
9862         if (res == TEST_SKIPPED)
9863                 return res;
9864         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9865         return TEST_SUCCESS;
9866 }
9867
9868 static int
9869 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
9870 {
9871         struct aead_test_data tdata;
9872         int res;
9873
9874         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9875         tdata.ciphertext.data[0] += 1;
9876         res = test_authenticated_decryption(&tdata);
9877         if (res == TEST_SKIPPED)
9878                 return res;
9879         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9880         return TEST_SUCCESS;
9881 }
9882
9883 static int
9884 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
9885 {
9886         struct aead_test_data tdata;
9887         int res;
9888
9889         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9890         tdata.aad.len += 1;
9891         res = test_authenticated_decryption(&tdata);
9892         if (res == TEST_SKIPPED)
9893                 return res;
9894         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9895         return TEST_SUCCESS;
9896 }
9897
9898 static int
9899 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
9900 {
9901         struct aead_test_data tdata;
9902         uint8_t aad[gcm_test_case_7.aad.len];
9903         int res;
9904
9905         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9906         memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9907         aad[0] += 1;
9908         tdata.aad.data = aad;
9909         res = test_authenticated_decryption(&tdata);
9910         if (res == TEST_SKIPPED)
9911                 return res;
9912         TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9913         return TEST_SUCCESS;
9914 }
9915
9916 static int
9917 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
9918 {
9919         struct aead_test_data tdata;
9920         int res;
9921
9922         memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9923         tdata.auth_tag.data[0] += 1;
9924         res = test_authenticated_decryption(&tdata);
9925         if (res == TEST_SKIPPED)
9926                 return res;
9927         TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
9928         return TEST_SUCCESS;
9929 }
9930
9931 static int
9932 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
9933 {
9934         struct crypto_testsuite_params *ts_params = &testsuite_params;
9935         struct crypto_unittest_params *ut_params = &unittest_params;
9936
9937         int retval;
9938         uint8_t *ciphertext, *auth_tag;
9939         uint16_t plaintext_pad_len;
9940
9941         /* Verify the capabilities */
9942         struct rte_cryptodev_sym_capability_idx cap_idx;
9943         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9944         cap_idx.algo.aead = tdata->algo;
9945         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9946                         &cap_idx) == NULL)
9947                 return TEST_SKIPPED;
9948
9949         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9950                 return TEST_SKIPPED;
9951
9952         /* not supported with CPU crypto */
9953         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9954                 return TEST_SKIPPED;
9955
9956         /* Create AEAD session */
9957         retval = create_aead_session(ts_params->valid_devs[0],
9958                         tdata->algo,
9959                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
9960                         tdata->key.data, tdata->key.len,
9961                         tdata->aad.len, tdata->auth_tag.len,
9962                         tdata->iv.len);
9963         if (retval < 0)
9964                 return retval;
9965
9966         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9967         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9968
9969         /* clear mbuf payload */
9970         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9971                         rte_pktmbuf_tailroom(ut_params->ibuf));
9972         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
9973                         rte_pktmbuf_tailroom(ut_params->obuf));
9974
9975         /* Create AEAD operation */
9976         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
9977         if (retval < 0)
9978                 return retval;
9979
9980         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9981
9982         ut_params->op->sym->m_src = ut_params->ibuf;
9983         ut_params->op->sym->m_dst = ut_params->obuf;
9984
9985         /* Process crypto operation */
9986         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9987                         ut_params->op), "failed to process sym crypto op");
9988
9989         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9990                         "crypto op processing failed");
9991
9992         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9993
9994         ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
9995                         ut_params->op->sym->cipher.data.offset);
9996         auth_tag = ciphertext + plaintext_pad_len;
9997
9998         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
9999         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10000
10001         /* Validate obuf */
10002         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10003                         ciphertext,
10004                         tdata->ciphertext.data,
10005                         tdata->ciphertext.len,
10006                         "Ciphertext data not as expected");
10007
10008         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10009                         auth_tag,
10010                         tdata->auth_tag.data,
10011                         tdata->auth_tag.len,
10012                         "Generated auth tag not as expected");
10013
10014         return 0;
10015
10016 }
10017
10018 static int
10019 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10020 {
10021         return test_authenticated_encryption_oop(&gcm_test_case_5);
10022 }
10023
10024 static int
10025 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10026 {
10027         struct crypto_testsuite_params *ts_params = &testsuite_params;
10028         struct crypto_unittest_params *ut_params = &unittest_params;
10029
10030         int retval;
10031         uint8_t *plaintext;
10032
10033         /* Verify the capabilities */
10034         struct rte_cryptodev_sym_capability_idx cap_idx;
10035         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10036         cap_idx.algo.aead = tdata->algo;
10037         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10038                         &cap_idx) == NULL)
10039                 return TEST_SKIPPED;
10040
10041         /* not supported with CPU crypto and raw data-path APIs*/
10042         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10043                         global_api_test_type == CRYPTODEV_RAW_API_TEST)
10044                 return TEST_SKIPPED;
10045
10046         /* Create AEAD session */
10047         retval = create_aead_session(ts_params->valid_devs[0],
10048                         tdata->algo,
10049                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10050                         tdata->key.data, tdata->key.len,
10051                         tdata->aad.len, tdata->auth_tag.len,
10052                         tdata->iv.len);
10053         if (retval < 0)
10054                 return retval;
10055
10056         /* alloc mbuf and set payload */
10057         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10058         ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10059
10060         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10061                         rte_pktmbuf_tailroom(ut_params->ibuf));
10062         memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10063                         rte_pktmbuf_tailroom(ut_params->obuf));
10064
10065         /* Create AEAD operation */
10066         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10067         if (retval < 0)
10068                 return retval;
10069
10070         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10071
10072         ut_params->op->sym->m_src = ut_params->ibuf;
10073         ut_params->op->sym->m_dst = ut_params->obuf;
10074
10075         /* Process crypto operation */
10076         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10077                         ut_params->op), "failed to process sym crypto op");
10078
10079         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10080                         "crypto op processing failed");
10081
10082         plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10083                         ut_params->op->sym->cipher.data.offset);
10084
10085         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10086
10087         /* Validate obuf */
10088         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10089                         plaintext,
10090                         tdata->plaintext.data,
10091                         tdata->plaintext.len,
10092                         "Plaintext data not as expected");
10093
10094         TEST_ASSERT_EQUAL(ut_params->op->status,
10095                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10096                         "Authentication failed");
10097         return 0;
10098 }
10099
10100 static int
10101 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10102 {
10103         return test_authenticated_decryption_oop(&gcm_test_case_5);
10104 }
10105
10106 static int
10107 test_authenticated_encryption_sessionless(
10108                 const struct aead_test_data *tdata)
10109 {
10110         struct crypto_testsuite_params *ts_params = &testsuite_params;
10111         struct crypto_unittest_params *ut_params = &unittest_params;
10112
10113         int retval;
10114         uint8_t *ciphertext, *auth_tag;
10115         uint16_t plaintext_pad_len;
10116         uint8_t key[tdata->key.len + 1];
10117         struct rte_cryptodev_info dev_info;
10118
10119         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10120         uint64_t feat_flags = dev_info.feature_flags;
10121
10122         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10123                 printf("Device doesn't support Sessionless ops.\n");
10124                 return TEST_SKIPPED;
10125         }
10126
10127         /* not supported with CPU crypto */
10128         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10129                 return TEST_SKIPPED;
10130
10131         /* Verify the capabilities */
10132         struct rte_cryptodev_sym_capability_idx cap_idx;
10133         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10134         cap_idx.algo.aead = tdata->algo;
10135         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10136                         &cap_idx) == NULL)
10137                 return TEST_SKIPPED;
10138
10139         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10140
10141         /* clear mbuf payload */
10142         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10143                         rte_pktmbuf_tailroom(ut_params->ibuf));
10144
10145         /* Create AEAD operation */
10146         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10147         if (retval < 0)
10148                 return retval;
10149
10150         /* Create GCM xform */
10151         memcpy(key, tdata->key.data, tdata->key.len);
10152         retval = create_aead_xform(ut_params->op,
10153                         tdata->algo,
10154                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
10155                         key, tdata->key.len,
10156                         tdata->aad.len, tdata->auth_tag.len,
10157                         tdata->iv.len);
10158         if (retval < 0)
10159                 return retval;
10160
10161         ut_params->op->sym->m_src = ut_params->ibuf;
10162
10163         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10164                         RTE_CRYPTO_OP_SESSIONLESS,
10165                         "crypto op session type not sessionless");
10166
10167         /* Process crypto operation */
10168         TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10169                         ut_params->op), "failed to process sym crypto op");
10170
10171         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10172
10173         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10174                         "crypto op status not success");
10175
10176         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10177
10178         ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10179                         ut_params->op->sym->cipher.data.offset);
10180         auth_tag = ciphertext + plaintext_pad_len;
10181
10182         debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10183         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10184
10185         /* Validate obuf */
10186         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10187                         ciphertext,
10188                         tdata->ciphertext.data,
10189                         tdata->ciphertext.len,
10190                         "Ciphertext data not as expected");
10191
10192         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10193                         auth_tag,
10194                         tdata->auth_tag.data,
10195                         tdata->auth_tag.len,
10196                         "Generated auth tag not as expected");
10197
10198         return 0;
10199
10200 }
10201
10202 static int
10203 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10204 {
10205         return test_authenticated_encryption_sessionless(
10206                         &gcm_test_case_5);
10207 }
10208
10209 static int
10210 test_authenticated_decryption_sessionless(
10211                 const struct aead_test_data *tdata)
10212 {
10213         struct crypto_testsuite_params *ts_params = &testsuite_params;
10214         struct crypto_unittest_params *ut_params = &unittest_params;
10215
10216         int retval;
10217         uint8_t *plaintext;
10218         uint8_t key[tdata->key.len + 1];
10219         struct rte_cryptodev_info dev_info;
10220
10221         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10222         uint64_t feat_flags = dev_info.feature_flags;
10223
10224         if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10225                 printf("Device doesn't support Sessionless ops.\n");
10226                 return TEST_SKIPPED;
10227         }
10228
10229         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10230                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10231                 printf("Device doesn't support RAW data-path APIs.\n");
10232                 return TEST_SKIPPED;
10233         }
10234
10235         /* not supported with CPU crypto */
10236         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10237                 return TEST_SKIPPED;
10238
10239         /* Verify the capabilities */
10240         struct rte_cryptodev_sym_capability_idx cap_idx;
10241         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10242         cap_idx.algo.aead = tdata->algo;
10243         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10244                         &cap_idx) == NULL)
10245                 return TEST_SKIPPED;
10246
10247         /* alloc mbuf and set payload */
10248         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10249
10250         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10251                         rte_pktmbuf_tailroom(ut_params->ibuf));
10252
10253         /* Create AEAD operation */
10254         retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10255         if (retval < 0)
10256                 return retval;
10257
10258         /* Create AEAD xform */
10259         memcpy(key, tdata->key.data, tdata->key.len);
10260         retval = create_aead_xform(ut_params->op,
10261                         tdata->algo,
10262                         RTE_CRYPTO_AEAD_OP_DECRYPT,
10263                         key, tdata->key.len,
10264                         tdata->aad.len, tdata->auth_tag.len,
10265                         tdata->iv.len);
10266         if (retval < 0)
10267                 return retval;
10268
10269         ut_params->op->sym->m_src = ut_params->ibuf;
10270
10271         TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10272                         RTE_CRYPTO_OP_SESSIONLESS,
10273                         "crypto op session type not sessionless");
10274
10275         /* Process crypto operation */
10276         if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10277                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10278                                 ut_params->op, 0, 0, 0, 0);
10279         else
10280                 TEST_ASSERT_NOT_NULL(process_crypto_request(
10281                         ts_params->valid_devs[0], ut_params->op),
10282                                 "failed to process sym crypto op");
10283
10284         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10285
10286         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10287                         "crypto op status not success");
10288
10289         plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10290                         ut_params->op->sym->cipher.data.offset);
10291
10292         debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10293
10294         /* Validate obuf */
10295         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10296                         plaintext,
10297                         tdata->plaintext.data,
10298                         tdata->plaintext.len,
10299                         "Plaintext data not as expected");
10300
10301         TEST_ASSERT_EQUAL(ut_params->op->status,
10302                         RTE_CRYPTO_OP_STATUS_SUCCESS,
10303                         "Authentication failed");
10304         return 0;
10305 }
10306
10307 static int
10308 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
10309 {
10310         return test_authenticated_decryption_sessionless(
10311                         &gcm_test_case_5);
10312 }
10313
10314 static int
10315 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
10316 {
10317         return test_authenticated_encryption(&ccm_test_case_128_1);
10318 }
10319
10320 static int
10321 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
10322 {
10323         return test_authenticated_encryption(&ccm_test_case_128_2);
10324 }
10325
10326 static int
10327 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
10328 {
10329         return test_authenticated_encryption(&ccm_test_case_128_3);
10330 }
10331
10332 static int
10333 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
10334 {
10335         return test_authenticated_decryption(&ccm_test_case_128_1);
10336 }
10337
10338 static int
10339 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
10340 {
10341         return test_authenticated_decryption(&ccm_test_case_128_2);
10342 }
10343
10344 static int
10345 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10346 {
10347         return test_authenticated_decryption(&ccm_test_case_128_3);
10348 }
10349
10350 static int
10351 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10352 {
10353         return test_authenticated_encryption(&ccm_test_case_192_1);
10354 }
10355
10356 static int
10357 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10358 {
10359         return test_authenticated_encryption(&ccm_test_case_192_2);
10360 }
10361
10362 static int
10363 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10364 {
10365         return test_authenticated_encryption(&ccm_test_case_192_3);
10366 }
10367
10368 static int
10369 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10370 {
10371         return test_authenticated_decryption(&ccm_test_case_192_1);
10372 }
10373
10374 static int
10375 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10376 {
10377         return test_authenticated_decryption(&ccm_test_case_192_2);
10378 }
10379
10380 static int
10381 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10382 {
10383         return test_authenticated_decryption(&ccm_test_case_192_3);
10384 }
10385
10386 static int
10387 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
10388 {
10389         return test_authenticated_encryption(&ccm_test_case_256_1);
10390 }
10391
10392 static int
10393 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
10394 {
10395         return test_authenticated_encryption(&ccm_test_case_256_2);
10396 }
10397
10398 static int
10399 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
10400 {
10401         return test_authenticated_encryption(&ccm_test_case_256_3);
10402 }
10403
10404 static int
10405 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
10406 {
10407         return test_authenticated_decryption(&ccm_test_case_256_1);
10408 }
10409
10410 static int
10411 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
10412 {
10413         return test_authenticated_decryption(&ccm_test_case_256_2);
10414 }
10415
10416 static int
10417 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
10418 {
10419         return test_authenticated_decryption(&ccm_test_case_256_3);
10420 }
10421
10422 static int
10423 test_stats(void)
10424 {
10425         struct crypto_testsuite_params *ts_params = &testsuite_params;
10426         struct rte_cryptodev_stats stats;
10427
10428         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10429                 return TEST_SKIPPED;
10430
10431         /* Verify the capabilities */
10432         struct rte_cryptodev_sym_capability_idx cap_idx;
10433         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10434         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
10435         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10436                         &cap_idx) == NULL)
10437                 return TEST_SKIPPED;
10438         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10439         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10440         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10441                         &cap_idx) == NULL)
10442                 return TEST_SKIPPED;
10443
10444         if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
10445                         == -ENOTSUP)
10446                 return TEST_SKIPPED;
10447
10448         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10449         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
10450                         &stats) == -ENODEV),
10451                 "rte_cryptodev_stats_get invalid dev failed");
10452         TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
10453                 "rte_cryptodev_stats_get invalid Param failed");
10454
10455         /* Test expected values */
10456         test_AES_CBC_HMAC_SHA1_encrypt_digest();
10457         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10458                         &stats),
10459                 "rte_cryptodev_stats_get failed");
10460         TEST_ASSERT((stats.enqueued_count == 1),
10461                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10462         TEST_ASSERT((stats.dequeued_count == 1),
10463                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10464         TEST_ASSERT((stats.enqueue_err_count == 0),
10465                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10466         TEST_ASSERT((stats.dequeue_err_count == 0),
10467                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10468
10469         /* invalid device but should ignore and not reset device stats*/
10470         rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
10471         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10472                         &stats),
10473                 "rte_cryptodev_stats_get failed");
10474         TEST_ASSERT((stats.enqueued_count == 1),
10475                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10476
10477         /* check that a valid reset clears stats */
10478         rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10479         TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10480                         &stats),
10481                                           "rte_cryptodev_stats_get failed");
10482         TEST_ASSERT((stats.enqueued_count == 0),
10483                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10484         TEST_ASSERT((stats.dequeued_count == 0),
10485                 "rte_cryptodev_stats_get returned unexpected enqueued stat");
10486
10487         return TEST_SUCCESS;
10488 }
10489
10490 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
10491                                    struct crypto_unittest_params *ut_params,
10492                                    enum rte_crypto_auth_operation op,
10493                                    const struct HMAC_MD5_vector *test_case)
10494 {
10495         uint8_t key[64];
10496
10497         memcpy(key, test_case->key.data, test_case->key.len);
10498
10499         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10500         ut_params->auth_xform.next = NULL;
10501         ut_params->auth_xform.auth.op = op;
10502
10503         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
10504
10505         ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
10506         ut_params->auth_xform.auth.key.length = test_case->key.len;
10507         ut_params->auth_xform.auth.key.data = key;
10508
10509         ut_params->sess = rte_cryptodev_sym_session_create(
10510                         ts_params->session_mpool);
10511
10512         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10513                         ut_params->sess, &ut_params->auth_xform,
10514                         ts_params->session_priv_mpool);
10515
10516         if (ut_params->sess == NULL)
10517                 return TEST_FAILED;
10518
10519         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10520
10521         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10522                         rte_pktmbuf_tailroom(ut_params->ibuf));
10523
10524         return 0;
10525 }
10526
10527 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
10528                               const struct HMAC_MD5_vector *test_case,
10529                               uint8_t **plaintext)
10530 {
10531         uint16_t plaintext_pad_len;
10532
10533         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10534
10535         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10536                                 16);
10537
10538         *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10539                         plaintext_pad_len);
10540         memcpy(*plaintext, test_case->plaintext.data,
10541                         test_case->plaintext.len);
10542
10543         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10544                         ut_params->ibuf, MD5_DIGEST_LEN);
10545         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10546                         "no room to append digest");
10547         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10548                         ut_params->ibuf, plaintext_pad_len);
10549
10550         if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10551                 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
10552                            test_case->auth_tag.len);
10553         }
10554
10555         sym_op->auth.data.offset = 0;
10556         sym_op->auth.data.length = test_case->plaintext.len;
10557
10558         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10559         ut_params->op->sym->m_src = ut_params->ibuf;
10560
10561         return 0;
10562 }
10563
10564 static int
10565 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
10566 {
10567         uint16_t plaintext_pad_len;
10568         uint8_t *plaintext, *auth_tag;
10569
10570         struct crypto_testsuite_params *ts_params = &testsuite_params;
10571         struct crypto_unittest_params *ut_params = &unittest_params;
10572         struct rte_cryptodev_info dev_info;
10573
10574         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10575         uint64_t feat_flags = dev_info.feature_flags;
10576
10577         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10578                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10579                 printf("Device doesn't support RAW data-path APIs.\n");
10580                 return TEST_SKIPPED;
10581         }
10582
10583         /* Verify the capabilities */
10584         struct rte_cryptodev_sym_capability_idx cap_idx;
10585         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10586         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10587         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10588                         &cap_idx) == NULL)
10589                 return TEST_SKIPPED;
10590
10591         if (MD5_HMAC_create_session(ts_params, ut_params,
10592                         RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
10593                 return TEST_FAILED;
10594
10595         /* Generate Crypto op data structure */
10596         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10597                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10598         TEST_ASSERT_NOT_NULL(ut_params->op,
10599                         "Failed to allocate symmetric crypto operation struct");
10600
10601         plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10602                                 16);
10603
10604         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10605                 return TEST_FAILED;
10606
10607         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10608                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10609                         ut_params->op);
10610         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10611                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10612                                 ut_params->op, 0, 1, 0, 0);
10613         else
10614                 TEST_ASSERT_NOT_NULL(
10615                         process_crypto_request(ts_params->valid_devs[0],
10616                                 ut_params->op),
10617                                 "failed to process sym crypto op");
10618
10619         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10620                         "crypto op processing failed");
10621
10622         if (ut_params->op->sym->m_dst) {
10623                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10624                                 uint8_t *, plaintext_pad_len);
10625         } else {
10626                 auth_tag = plaintext + plaintext_pad_len;
10627         }
10628
10629         TEST_ASSERT_BUFFERS_ARE_EQUAL(
10630                         auth_tag,
10631                         test_case->auth_tag.data,
10632                         test_case->auth_tag.len,
10633                         "HMAC_MD5 generated tag not as expected");
10634
10635         return TEST_SUCCESS;
10636 }
10637
10638 static int
10639 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
10640 {
10641         uint8_t *plaintext;
10642
10643         struct crypto_testsuite_params *ts_params = &testsuite_params;
10644         struct crypto_unittest_params *ut_params = &unittest_params;
10645         struct rte_cryptodev_info dev_info;
10646
10647         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10648         uint64_t feat_flags = dev_info.feature_flags;
10649
10650         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10651                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10652                 printf("Device doesn't support RAW data-path APIs.\n");
10653                 return TEST_SKIPPED;
10654         }
10655
10656         /* Verify the capabilities */
10657         struct rte_cryptodev_sym_capability_idx cap_idx;
10658         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10659         cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10660         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10661                         &cap_idx) == NULL)
10662                 return TEST_SKIPPED;
10663
10664         if (MD5_HMAC_create_session(ts_params, ut_params,
10665                         RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
10666                 return TEST_FAILED;
10667         }
10668
10669         /* Generate Crypto op data structure */
10670         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10671                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10672         TEST_ASSERT_NOT_NULL(ut_params->op,
10673                         "Failed to allocate symmetric crypto operation struct");
10674
10675         if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10676                 return TEST_FAILED;
10677
10678         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10679                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10680                         ut_params->op);
10681         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10682                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10683                                 ut_params->op, 0, 1, 0, 0);
10684         else
10685                 TEST_ASSERT_NOT_NULL(
10686                         process_crypto_request(ts_params->valid_devs[0],
10687                                 ut_params->op),
10688                                 "failed to process sym crypto op");
10689
10690         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10691                         "HMAC_MD5 crypto op processing failed");
10692
10693         return TEST_SUCCESS;
10694 }
10695
10696 static int
10697 test_MD5_HMAC_generate_case_1(void)
10698 {
10699         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
10700 }
10701
10702 static int
10703 test_MD5_HMAC_verify_case_1(void)
10704 {
10705         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
10706 }
10707
10708 static int
10709 test_MD5_HMAC_generate_case_2(void)
10710 {
10711         return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
10712 }
10713
10714 static int
10715 test_MD5_HMAC_verify_case_2(void)
10716 {
10717         return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
10718 }
10719
10720 static int
10721 test_multi_session(void)
10722 {
10723         struct crypto_testsuite_params *ts_params = &testsuite_params;
10724         struct crypto_unittest_params *ut_params = &unittest_params;
10725
10726         struct rte_cryptodev_info dev_info;
10727         struct rte_cryptodev_sym_session **sessions;
10728
10729         uint16_t i;
10730
10731         /* Verify the capabilities */
10732         struct rte_cryptodev_sym_capability_idx cap_idx;
10733         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10734         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10735         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10736                         &cap_idx) == NULL)
10737                 return TEST_SKIPPED;
10738         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10739         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10740         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10741                         &cap_idx) == NULL)
10742                 return TEST_SKIPPED;
10743
10744         test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
10745                         aes_cbc_key, hmac_sha512_key);
10746
10747
10748         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10749
10750         sessions = rte_malloc(NULL,
10751                         sizeof(struct rte_cryptodev_sym_session *) *
10752                         (MAX_NB_SESSIONS + 1), 0);
10753
10754         /* Create multiple crypto sessions*/
10755         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10756
10757                 sessions[i] = rte_cryptodev_sym_session_create(
10758                                 ts_params->session_mpool);
10759
10760                 rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10761                                 sessions[i], &ut_params->auth_xform,
10762                                 ts_params->session_priv_mpool);
10763                 TEST_ASSERT_NOT_NULL(sessions[i],
10764                                 "Session creation failed at session number %u",
10765                                 i);
10766
10767                 /* Attempt to send a request on each session */
10768                 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
10769                         sessions[i],
10770                         ut_params,
10771                         ts_params,
10772                         catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
10773                         catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
10774                         aes_cbc_iv),
10775                         "Failed to perform decrypt on request number %u.", i);
10776                 /* free crypto operation structure */
10777                 if (ut_params->op)
10778                         rte_crypto_op_free(ut_params->op);
10779
10780                 /*
10781                  * free mbuf - both obuf and ibuf are usually the same,
10782                  * so check if they point at the same address is necessary,
10783                  * to avoid freeing the mbuf twice.
10784                  */
10785                 if (ut_params->obuf) {
10786                         rte_pktmbuf_free(ut_params->obuf);
10787                         if (ut_params->ibuf == ut_params->obuf)
10788                                 ut_params->ibuf = 0;
10789                         ut_params->obuf = 0;
10790                 }
10791                 if (ut_params->ibuf) {
10792                         rte_pktmbuf_free(ut_params->ibuf);
10793                         ut_params->ibuf = 0;
10794                 }
10795         }
10796
10797         sessions[i] = NULL;
10798         /* Next session create should fail */
10799         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10800                         sessions[i], &ut_params->auth_xform,
10801                         ts_params->session_priv_mpool);
10802         TEST_ASSERT_NULL(sessions[i],
10803                         "Session creation succeeded unexpectedly!");
10804
10805         for (i = 0; i < MAX_NB_SESSIONS; i++) {
10806                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10807                                 sessions[i]);
10808                 rte_cryptodev_sym_session_free(sessions[i]);
10809         }
10810
10811         rte_free(sessions);
10812
10813         return TEST_SUCCESS;
10814 }
10815
10816 struct multi_session_params {
10817         struct crypto_unittest_params ut_params;
10818         uint8_t *cipher_key;
10819         uint8_t *hmac_key;
10820         const uint8_t *cipher;
10821         const uint8_t *digest;
10822         uint8_t *iv;
10823 };
10824
10825 #define MB_SESSION_NUMBER 3
10826
10827 static int
10828 test_multi_session_random_usage(void)
10829 {
10830         struct crypto_testsuite_params *ts_params = &testsuite_params;
10831         struct rte_cryptodev_info dev_info;
10832         struct rte_cryptodev_sym_session **sessions;
10833         uint32_t i, j;
10834         struct multi_session_params ut_paramz[] = {
10835
10836                 {
10837                         .cipher_key = ms_aes_cbc_key0,
10838                         .hmac_key = ms_hmac_key0,
10839                         .cipher = ms_aes_cbc_cipher0,
10840                         .digest = ms_hmac_digest0,
10841                         .iv = ms_aes_cbc_iv0
10842                 },
10843                 {
10844                         .cipher_key = ms_aes_cbc_key1,
10845                         .hmac_key = ms_hmac_key1,
10846                         .cipher = ms_aes_cbc_cipher1,
10847                         .digest = ms_hmac_digest1,
10848                         .iv = ms_aes_cbc_iv1
10849                 },
10850                 {
10851                         .cipher_key = ms_aes_cbc_key2,
10852                         .hmac_key = ms_hmac_key2,
10853                         .cipher = ms_aes_cbc_cipher2,
10854                         .digest = ms_hmac_digest2,
10855                         .iv = ms_aes_cbc_iv2
10856                 },
10857
10858         };
10859
10860         /* Verify the capabilities */
10861         struct rte_cryptodev_sym_capability_idx cap_idx;
10862         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10863         cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10864         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10865                         &cap_idx) == NULL)
10866                 return TEST_SKIPPED;
10867         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10868         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10869         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10870                         &cap_idx) == NULL)
10871                 return TEST_SKIPPED;
10872
10873         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10874
10875         sessions = rte_malloc(NULL,
10876                         (sizeof(struct rte_cryptodev_sym_session *)
10877                                         * MAX_NB_SESSIONS) + 1, 0);
10878
10879         for (i = 0; i < MB_SESSION_NUMBER; i++) {
10880                 sessions[i] = rte_cryptodev_sym_session_create(
10881                                 ts_params->session_mpool);
10882
10883                 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
10884                                 sizeof(struct crypto_unittest_params));
10885
10886                 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
10887                                 &ut_paramz[i].ut_params,
10888                                 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
10889
10890                 /* Create multiple crypto sessions*/
10891                 rte_cryptodev_sym_session_init(
10892                                 ts_params->valid_devs[0],
10893                                 sessions[i],
10894                                 &ut_paramz[i].ut_params.auth_xform,
10895                                 ts_params->session_priv_mpool);
10896
10897                 TEST_ASSERT_NOT_NULL(sessions[i],
10898                                 "Session creation failed at session number %u",
10899                                 i);
10900
10901         }
10902
10903         srand(time(NULL));
10904         for (i = 0; i < 40000; i++) {
10905
10906                 j = rand() % MB_SESSION_NUMBER;
10907
10908                 TEST_ASSERT_SUCCESS(
10909                         test_AES_CBC_HMAC_SHA512_decrypt_perform(
10910                                         sessions[j],
10911                                         &ut_paramz[j].ut_params,
10912                                         ts_params, ut_paramz[j].cipher,
10913                                         ut_paramz[j].digest,
10914                                         ut_paramz[j].iv),
10915                         "Failed to perform decrypt on request number %u.", i);
10916
10917                 if (ut_paramz[j].ut_params.op)
10918                         rte_crypto_op_free(ut_paramz[j].ut_params.op);
10919
10920                 /*
10921                  * free mbuf - both obuf and ibuf are usually the same,
10922                  * so check if they point at the same address is necessary,
10923                  * to avoid freeing the mbuf twice.
10924                  */
10925                 if (ut_paramz[j].ut_params.obuf) {
10926                         rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
10927                         if (ut_paramz[j].ut_params.ibuf
10928                                         == ut_paramz[j].ut_params.obuf)
10929                                 ut_paramz[j].ut_params.ibuf = 0;
10930                         ut_paramz[j].ut_params.obuf = 0;
10931                 }
10932                 if (ut_paramz[j].ut_params.ibuf) {
10933                         rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
10934                         ut_paramz[j].ut_params.ibuf = 0;
10935                 }
10936         }
10937
10938         for (i = 0; i < MB_SESSION_NUMBER; i++) {
10939                 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10940                                 sessions[i]);
10941                 rte_cryptodev_sym_session_free(sessions[i]);
10942         }
10943
10944         rte_free(sessions);
10945
10946         return TEST_SUCCESS;
10947 }
10948
10949 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
10950                         0xab, 0xab, 0xab, 0xab,
10951                         0xab, 0xab, 0xab, 0xab,
10952                         0xab, 0xab, 0xab, 0xab};
10953
10954 static int
10955 test_null_invalid_operation(void)
10956 {
10957         struct crypto_testsuite_params *ts_params = &testsuite_params;
10958         struct crypto_unittest_params *ut_params = &unittest_params;
10959         int ret;
10960
10961         /* This test is for NULL PMD only */
10962         if (gbl_driver_id != rte_cryptodev_driver_id_get(
10963                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
10964                 return TEST_SKIPPED;
10965
10966         /* Setup Cipher Parameters */
10967         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10968         ut_params->cipher_xform.next = NULL;
10969
10970         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
10971         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10972
10973         ut_params->sess = rte_cryptodev_sym_session_create(
10974                         ts_params->session_mpool);
10975
10976         /* Create Crypto session*/
10977         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10978                         ut_params->sess, &ut_params->cipher_xform,
10979                         ts_params->session_priv_mpool);
10980         TEST_ASSERT(ret < 0,
10981                         "Session creation succeeded unexpectedly");
10982
10983
10984         /* Setup HMAC Parameters */
10985         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10986         ut_params->auth_xform.next = NULL;
10987
10988         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
10989         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10990
10991         ut_params->sess = rte_cryptodev_sym_session_create(
10992                         ts_params->session_mpool);
10993
10994         /* Create Crypto session*/
10995         ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10996                         ut_params->sess, &ut_params->auth_xform,
10997                         ts_params->session_priv_mpool);
10998         TEST_ASSERT(ret < 0,
10999                         "Session creation succeeded unexpectedly");
11000
11001         return TEST_SUCCESS;
11002 }
11003
11004
11005 #define NULL_BURST_LENGTH (32)
11006
11007 static int
11008 test_null_burst_operation(void)
11009 {
11010         struct crypto_testsuite_params *ts_params = &testsuite_params;
11011         struct crypto_unittest_params *ut_params = &unittest_params;
11012
11013         unsigned i, burst_len = NULL_BURST_LENGTH;
11014
11015         struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11016         struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11017
11018         /* This test is for NULL PMD only */
11019         if (gbl_driver_id != rte_cryptodev_driver_id_get(
11020                         RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11021                 return TEST_SKIPPED;
11022
11023         /* Setup Cipher Parameters */
11024         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11025         ut_params->cipher_xform.next = &ut_params->auth_xform;
11026
11027         ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11028         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11029
11030         /* Setup HMAC Parameters */
11031         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11032         ut_params->auth_xform.next = NULL;
11033
11034         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11035         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11036
11037         ut_params->sess = rte_cryptodev_sym_session_create(
11038                         ts_params->session_mpool);
11039
11040         /* Create Crypto session*/
11041         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_NOT_NULL(ut_params->sess, "Session creation failed");
11045
11046         TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11047                         RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11048                         burst_len, "failed to generate burst of crypto ops");
11049
11050         /* Generate an operation for each mbuf in burst */
11051         for (i = 0; i < burst_len; i++) {
11052                 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11053
11054                 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11055
11056                 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11057                                 sizeof(unsigned));
11058                 *data = i;
11059
11060                 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11061
11062                 burst[i]->sym->m_src = m;
11063         }
11064
11065         /* Process crypto operation */
11066         TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11067                         0, burst, burst_len),
11068                         burst_len,
11069                         "Error enqueuing burst");
11070
11071         TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11072                         0, burst_dequeued, burst_len),
11073                         burst_len,
11074                         "Error dequeuing burst");
11075
11076
11077         for (i = 0; i < burst_len; i++) {
11078                 TEST_ASSERT_EQUAL(
11079                         *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11080                         *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11081                                         uint32_t *),
11082                         "data not as expected");
11083
11084                 rte_pktmbuf_free(burst[i]->sym->m_src);
11085                 rte_crypto_op_free(burst[i]);
11086         }
11087
11088         return TEST_SUCCESS;
11089 }
11090
11091 static uint16_t
11092 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11093                   uint16_t nb_ops, void *user_param)
11094 {
11095         RTE_SET_USED(dev_id);
11096         RTE_SET_USED(qp_id);
11097         RTE_SET_USED(ops);
11098         RTE_SET_USED(user_param);
11099
11100         printf("crypto enqueue callback called\n");
11101         return nb_ops;
11102 }
11103
11104 static uint16_t
11105 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11106                   uint16_t nb_ops, void *user_param)
11107 {
11108         RTE_SET_USED(dev_id);
11109         RTE_SET_USED(qp_id);
11110         RTE_SET_USED(ops);
11111         RTE_SET_USED(user_param);
11112
11113         printf("crypto dequeue callback called\n");
11114         return nb_ops;
11115 }
11116
11117 /*
11118  * Thread using enqueue/dequeue callback with RCU.
11119  */
11120 static int
11121 test_enqdeq_callback_thread(void *arg)
11122 {
11123         RTE_SET_USED(arg);
11124         /* DP thread calls rte_cryptodev_enqueue_burst()/
11125          * rte_cryptodev_dequeue_burst() and invokes callback.
11126          */
11127         test_null_burst_operation();
11128         return 0;
11129 }
11130
11131 static int
11132 test_enq_callback_setup(void)
11133 {
11134         struct crypto_testsuite_params *ts_params = &testsuite_params;
11135         struct rte_cryptodev_info dev_info;
11136         struct rte_cryptodev_qp_conf qp_conf = {
11137                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11138         };
11139
11140         struct rte_cryptodev_cb *cb;
11141         uint16_t qp_id = 0;
11142
11143         /* Stop the device in case it's started so it can be configured */
11144         rte_cryptodev_stop(ts_params->valid_devs[0]);
11145
11146         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11147
11148         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11149                         &ts_params->conf),
11150                         "Failed to configure cryptodev %u",
11151                         ts_params->valid_devs[0]);
11152
11153         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11154         qp_conf.mp_session = ts_params->session_mpool;
11155         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11156
11157         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11158                         ts_params->valid_devs[0], qp_id, &qp_conf,
11159                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11160                         "Failed test for "
11161                         "rte_cryptodev_queue_pair_setup: num_inflights "
11162                         "%u on qp %u on cryptodev %u",
11163                         qp_conf.nb_descriptors, qp_id,
11164                         ts_params->valid_devs[0]);
11165
11166         /* Test with invalid crypto device */
11167         cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11168                         qp_id, test_enq_callback, NULL);
11169         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11170                         "cryptodev %u did not fail",
11171                         qp_id, RTE_CRYPTO_MAX_DEVS);
11172
11173         /* Test with invalid queue pair */
11174         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11175                         dev_info.max_nb_queue_pairs + 1,
11176                         test_enq_callback, NULL);
11177         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11178                         "cryptodev %u did not fail",
11179                         dev_info.max_nb_queue_pairs + 1,
11180                         ts_params->valid_devs[0]);
11181
11182         /* Test with NULL callback */
11183         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11184                         qp_id, NULL, NULL);
11185         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11186                         "cryptodev %u did not fail",
11187                         qp_id, ts_params->valid_devs[0]);
11188
11189         /* Test with valid configuration */
11190         cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11191                         qp_id, test_enq_callback, NULL);
11192         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11193                         "qp %u on cryptodev %u",
11194                         qp_id, ts_params->valid_devs[0]);
11195
11196         rte_cryptodev_start(ts_params->valid_devs[0]);
11197
11198         /* Launch a thread */
11199         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11200                                 rte_get_next_lcore(-1, 1, 0));
11201
11202         /* Wait until reader exited. */
11203         rte_eal_mp_wait_lcore();
11204
11205         /* Test with invalid crypto device */
11206         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11207                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11208                         "Expected call to fail as crypto device is invalid");
11209
11210         /* Test with invalid queue pair */
11211         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11212                         ts_params->valid_devs[0],
11213                         dev_info.max_nb_queue_pairs + 1, cb),
11214                         "Expected call to fail as queue pair is invalid");
11215
11216         /* Test with NULL callback */
11217         TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11218                         ts_params->valid_devs[0], qp_id, NULL),
11219                         "Expected call to fail as callback is NULL");
11220
11221         /* Test with valid configuration */
11222         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11223                         ts_params->valid_devs[0], qp_id, cb),
11224                         "Failed test to remove callback on "
11225                         "qp %u on cryptodev %u",
11226                         qp_id, ts_params->valid_devs[0]);
11227
11228         return TEST_SUCCESS;
11229 }
11230
11231 static int
11232 test_deq_callback_setup(void)
11233 {
11234         struct crypto_testsuite_params *ts_params = &testsuite_params;
11235         struct rte_cryptodev_info dev_info;
11236         struct rte_cryptodev_qp_conf qp_conf = {
11237                 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
11238         };
11239
11240         struct rte_cryptodev_cb *cb;
11241         uint16_t qp_id = 0;
11242
11243         /* Stop the device in case it's started so it can be configured */
11244         rte_cryptodev_stop(ts_params->valid_devs[0]);
11245
11246         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11247
11248         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11249                         &ts_params->conf),
11250                         "Failed to configure cryptodev %u",
11251                         ts_params->valid_devs[0]);
11252
11253         qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11254         qp_conf.mp_session = ts_params->session_mpool;
11255         qp_conf.mp_session_private = ts_params->session_priv_mpool;
11256
11257         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11258                         ts_params->valid_devs[0], qp_id, &qp_conf,
11259                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11260                         "Failed test for "
11261                         "rte_cryptodev_queue_pair_setup: num_inflights "
11262                         "%u on qp %u on cryptodev %u",
11263                         qp_conf.nb_descriptors, qp_id,
11264                         ts_params->valid_devs[0]);
11265
11266         /* Test with invalid crypto device */
11267         cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11268                         qp_id, test_deq_callback, NULL);
11269         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11270                         "cryptodev %u did not fail",
11271                         qp_id, RTE_CRYPTO_MAX_DEVS);
11272
11273         /* Test with invalid queue pair */
11274         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11275                         dev_info.max_nb_queue_pairs + 1,
11276                         test_deq_callback, NULL);
11277         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11278                         "cryptodev %u did not fail",
11279                         dev_info.max_nb_queue_pairs + 1,
11280                         ts_params->valid_devs[0]);
11281
11282         /* Test with NULL callback */
11283         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11284                         qp_id, NULL, NULL);
11285         TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11286                         "cryptodev %u did not fail",
11287                         qp_id, ts_params->valid_devs[0]);
11288
11289         /* Test with valid configuration */
11290         cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11291                         qp_id, test_deq_callback, NULL);
11292         TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11293                         "qp %u on cryptodev %u",
11294                         qp_id, ts_params->valid_devs[0]);
11295
11296         rte_cryptodev_start(ts_params->valid_devs[0]);
11297
11298         /* Launch a thread */
11299         rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11300                                 rte_get_next_lcore(-1, 1, 0));
11301
11302         /* Wait until reader exited. */
11303         rte_eal_mp_wait_lcore();
11304
11305         /* Test with invalid crypto device */
11306         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11307                         RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11308                         "Expected call to fail as crypto device is invalid");
11309
11310         /* Test with invalid queue pair */
11311         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11312                         ts_params->valid_devs[0],
11313                         dev_info.max_nb_queue_pairs + 1, cb),
11314                         "Expected call to fail as queue pair is invalid");
11315
11316         /* Test with NULL callback */
11317         TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11318                         ts_params->valid_devs[0], qp_id, NULL),
11319                         "Expected call to fail as callback is NULL");
11320
11321         /* Test with valid configuration */
11322         TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
11323                         ts_params->valid_devs[0], qp_id, cb),
11324                         "Failed test to remove callback on "
11325                         "qp %u on cryptodev %u",
11326                         qp_id, ts_params->valid_devs[0]);
11327
11328         return TEST_SUCCESS;
11329 }
11330
11331 static void
11332 generate_gmac_large_plaintext(uint8_t *data)
11333 {
11334         uint16_t i;
11335
11336         for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
11337                 memcpy(&data[i], &data[0], 32);
11338 }
11339
11340 static int
11341 create_gmac_operation(enum rte_crypto_auth_operation op,
11342                 const struct gmac_test_data *tdata)
11343 {
11344         struct crypto_testsuite_params *ts_params = &testsuite_params;
11345         struct crypto_unittest_params *ut_params = &unittest_params;
11346         struct rte_crypto_sym_op *sym_op;
11347
11348         uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11349
11350         /* Generate Crypto op data structure */
11351         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11352                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11353         TEST_ASSERT_NOT_NULL(ut_params->op,
11354                         "Failed to allocate symmetric crypto operation struct");
11355
11356         sym_op = ut_params->op->sym;
11357
11358         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11359                         ut_params->ibuf, tdata->gmac_tag.len);
11360         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11361                         "no room to append digest");
11362
11363         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11364                         ut_params->ibuf, plaintext_pad_len);
11365
11366         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11367                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11368                                 tdata->gmac_tag.len);
11369                 debug_hexdump(stdout, "digest:",
11370                                 sym_op->auth.digest.data,
11371                                 tdata->gmac_tag.len);
11372         }
11373
11374         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11375                         uint8_t *, IV_OFFSET);
11376
11377         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11378
11379         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11380
11381         sym_op->cipher.data.length = 0;
11382         sym_op->cipher.data.offset = 0;
11383
11384         sym_op->auth.data.offset = 0;
11385         sym_op->auth.data.length = tdata->plaintext.len;
11386
11387         return 0;
11388 }
11389
11390 static int
11391 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
11392                 const struct gmac_test_data *tdata,
11393                 void *digest_mem, uint64_t digest_phys)
11394 {
11395         struct crypto_testsuite_params *ts_params = &testsuite_params;
11396         struct crypto_unittest_params *ut_params = &unittest_params;
11397         struct rte_crypto_sym_op *sym_op;
11398
11399         /* Generate Crypto op data structure */
11400         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11401                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11402         TEST_ASSERT_NOT_NULL(ut_params->op,
11403                         "Failed to allocate symmetric crypto operation struct");
11404
11405         sym_op = ut_params->op->sym;
11406
11407         sym_op->auth.digest.data = digest_mem;
11408         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11409                         "no room to append digest");
11410
11411         sym_op->auth.digest.phys_addr = digest_phys;
11412
11413         if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11414                 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11415                                 tdata->gmac_tag.len);
11416                 debug_hexdump(stdout, "digest:",
11417                                 sym_op->auth.digest.data,
11418                                 tdata->gmac_tag.len);
11419         }
11420
11421         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11422                         uint8_t *, IV_OFFSET);
11423
11424         rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11425
11426         debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11427
11428         sym_op->cipher.data.length = 0;
11429         sym_op->cipher.data.offset = 0;
11430
11431         sym_op->auth.data.offset = 0;
11432         sym_op->auth.data.length = tdata->plaintext.len;
11433
11434         return 0;
11435 }
11436
11437 static int create_gmac_session(uint8_t dev_id,
11438                 const struct gmac_test_data *tdata,
11439                 enum rte_crypto_auth_operation auth_op)
11440 {
11441         uint8_t auth_key[tdata->key.len];
11442
11443         struct crypto_testsuite_params *ts_params = &testsuite_params;
11444         struct crypto_unittest_params *ut_params = &unittest_params;
11445
11446         memcpy(auth_key, tdata->key.data, tdata->key.len);
11447
11448         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11449         ut_params->auth_xform.next = NULL;
11450
11451         ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
11452         ut_params->auth_xform.auth.op = auth_op;
11453         ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
11454         ut_params->auth_xform.auth.key.length = tdata->key.len;
11455         ut_params->auth_xform.auth.key.data = auth_key;
11456         ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11457         ut_params->auth_xform.auth.iv.length = tdata->iv.len;
11458
11459
11460         ut_params->sess = rte_cryptodev_sym_session_create(
11461                         ts_params->session_mpool);
11462
11463         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11464                         &ut_params->auth_xform,
11465                         ts_params->session_priv_mpool);
11466
11467         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11468
11469         return 0;
11470 }
11471
11472 static int
11473 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
11474 {
11475         struct crypto_testsuite_params *ts_params = &testsuite_params;
11476         struct crypto_unittest_params *ut_params = &unittest_params;
11477         struct rte_cryptodev_info dev_info;
11478
11479         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11480         uint64_t feat_flags = dev_info.feature_flags;
11481
11482         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11483                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11484                 printf("Device doesn't support RAW data-path APIs.\n");
11485                 return TEST_SKIPPED;
11486         }
11487
11488         int retval;
11489
11490         uint8_t *auth_tag, *plaintext;
11491         uint16_t plaintext_pad_len;
11492
11493         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11494                               "No GMAC length in the source data");
11495
11496         /* Verify the capabilities */
11497         struct rte_cryptodev_sym_capability_idx cap_idx;
11498         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11499         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11500         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11501                         &cap_idx) == NULL)
11502                 return TEST_SKIPPED;
11503
11504         retval = create_gmac_session(ts_params->valid_devs[0],
11505                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11506
11507         if (retval < 0)
11508                 return retval;
11509
11510         if (tdata->plaintext.len > MBUF_SIZE)
11511                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11512         else
11513                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11514         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11515                         "Failed to allocate input buffer in mempool");
11516
11517         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11518                         rte_pktmbuf_tailroom(ut_params->ibuf));
11519
11520         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11521         /*
11522          * Runtime generate the large plain text instead of use hard code
11523          * plain text vector. It is done to avoid create huge source file
11524          * with the test vector.
11525          */
11526         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11527                 generate_gmac_large_plaintext(tdata->plaintext.data);
11528
11529         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11530                                 plaintext_pad_len);
11531         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11532
11533         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11534         debug_hexdump(stdout, "plaintext:", plaintext,
11535                         tdata->plaintext.len);
11536
11537         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
11538                         tdata);
11539
11540         if (retval < 0)
11541                 return retval;
11542
11543         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11544
11545         ut_params->op->sym->m_src = ut_params->ibuf;
11546
11547         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11548                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11549                         ut_params->op);
11550         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11551                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11552                                 ut_params->op, 0, 1, 0, 0);
11553         else
11554                 TEST_ASSERT_NOT_NULL(
11555                         process_crypto_request(ts_params->valid_devs[0],
11556                         ut_params->op), "failed to process sym crypto op");
11557
11558         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11559                         "crypto op processing failed");
11560
11561         if (ut_params->op->sym->m_dst) {
11562                 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11563                                 uint8_t *, plaintext_pad_len);
11564         } else {
11565                 auth_tag = plaintext + plaintext_pad_len;
11566         }
11567
11568         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11569
11570         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11571                         auth_tag,
11572                         tdata->gmac_tag.data,
11573                         tdata->gmac_tag.len,
11574                         "GMAC Generated auth tag not as expected");
11575
11576         return 0;
11577 }
11578
11579 static int
11580 test_AES_GMAC_authentication_test_case_1(void)
11581 {
11582         return test_AES_GMAC_authentication(&gmac_test_case_1);
11583 }
11584
11585 static int
11586 test_AES_GMAC_authentication_test_case_2(void)
11587 {
11588         return test_AES_GMAC_authentication(&gmac_test_case_2);
11589 }
11590
11591 static int
11592 test_AES_GMAC_authentication_test_case_3(void)
11593 {
11594         return test_AES_GMAC_authentication(&gmac_test_case_3);
11595 }
11596
11597 static int
11598 test_AES_GMAC_authentication_test_case_4(void)
11599 {
11600         return test_AES_GMAC_authentication(&gmac_test_case_4);
11601 }
11602
11603 static int
11604 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
11605 {
11606         struct crypto_testsuite_params *ts_params = &testsuite_params;
11607         struct crypto_unittest_params *ut_params = &unittest_params;
11608         int retval;
11609         uint32_t plaintext_pad_len;
11610         uint8_t *plaintext;
11611         struct rte_cryptodev_info dev_info;
11612
11613         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11614         uint64_t feat_flags = dev_info.feature_flags;
11615
11616         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11617                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11618                 printf("Device doesn't support RAW data-path APIs.\n");
11619                 return TEST_SKIPPED;
11620         }
11621
11622         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11623                               "No GMAC length in the source data");
11624
11625         /* Verify the capabilities */
11626         struct rte_cryptodev_sym_capability_idx cap_idx;
11627         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11628         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11629         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11630                         &cap_idx) == NULL)
11631                 return TEST_SKIPPED;
11632
11633         retval = create_gmac_session(ts_params->valid_devs[0],
11634                         tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
11635
11636         if (retval < 0)
11637                 return retval;
11638
11639         if (tdata->plaintext.len > MBUF_SIZE)
11640                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11641         else
11642                 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11643         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11644                         "Failed to allocate input buffer in mempool");
11645
11646         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11647                         rte_pktmbuf_tailroom(ut_params->ibuf));
11648
11649         plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11650
11651         /*
11652          * Runtime generate the large plain text instead of use hard code
11653          * plain text vector. It is done to avoid create huge source file
11654          * with the test vector.
11655          */
11656         if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11657                 generate_gmac_large_plaintext(tdata->plaintext.data);
11658
11659         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11660                                 plaintext_pad_len);
11661         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11662
11663         memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11664         debug_hexdump(stdout, "plaintext:", plaintext,
11665                         tdata->plaintext.len);
11666
11667         retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
11668                         tdata);
11669
11670         if (retval < 0)
11671                 return retval;
11672
11673         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11674
11675         ut_params->op->sym->m_src = ut_params->ibuf;
11676
11677         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11678                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11679                         ut_params->op);
11680         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11681                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11682                                 ut_params->op, 0, 1, 0, 0);
11683         else
11684                 TEST_ASSERT_NOT_NULL(
11685                         process_crypto_request(ts_params->valid_devs[0],
11686                         ut_params->op), "failed to process sym crypto op");
11687
11688         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11689                         "crypto op processing failed");
11690
11691         return 0;
11692
11693 }
11694
11695 static int
11696 test_AES_GMAC_authentication_verify_test_case_1(void)
11697 {
11698         return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
11699 }
11700
11701 static int
11702 test_AES_GMAC_authentication_verify_test_case_2(void)
11703 {
11704         return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
11705 }
11706
11707 static int
11708 test_AES_GMAC_authentication_verify_test_case_3(void)
11709 {
11710         return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
11711 }
11712
11713 static int
11714 test_AES_GMAC_authentication_verify_test_case_4(void)
11715 {
11716         return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
11717 }
11718
11719 static int
11720 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
11721                                 uint32_t fragsz)
11722 {
11723         struct crypto_testsuite_params *ts_params = &testsuite_params;
11724         struct crypto_unittest_params *ut_params = &unittest_params;
11725         struct rte_cryptodev_info dev_info;
11726         uint64_t feature_flags;
11727         unsigned int trn_data = 0;
11728         void *digest_mem = NULL;
11729         uint32_t segs = 1;
11730         unsigned int to_trn = 0;
11731         struct rte_mbuf *buf = NULL;
11732         uint8_t *auth_tag, *plaintext;
11733         int retval;
11734
11735         TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11736                               "No GMAC length in the source data");
11737
11738         /* Verify the capabilities */
11739         struct rte_cryptodev_sym_capability_idx cap_idx;
11740         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11741         cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11742         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11743                         &cap_idx) == NULL)
11744                 return TEST_SKIPPED;
11745
11746         /* Check for any input SGL support */
11747         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11748         feature_flags = dev_info.feature_flags;
11749
11750         if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
11751                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
11752                         (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
11753                 return TEST_SKIPPED;
11754
11755         if (fragsz > tdata->plaintext.len)
11756                 fragsz = tdata->plaintext.len;
11757
11758         uint16_t plaintext_len = fragsz;
11759
11760         retval = create_gmac_session(ts_params->valid_devs[0],
11761                         tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11762
11763         if (retval < 0)
11764                 return retval;
11765
11766         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11767         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11768                         "Failed to allocate input buffer in mempool");
11769
11770         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11771                         rte_pktmbuf_tailroom(ut_params->ibuf));
11772
11773         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11774                                 plaintext_len);
11775         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11776
11777         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
11778
11779         trn_data += plaintext_len;
11780
11781         buf = ut_params->ibuf;
11782
11783         /*
11784          * Loop until no more fragments
11785          */
11786
11787         while (trn_data < tdata->plaintext.len) {
11788                 ++segs;
11789                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
11790                                 (tdata->plaintext.len - trn_data) : fragsz;
11791
11792                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11793                 buf = buf->next;
11794
11795                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
11796                                 rte_pktmbuf_tailroom(buf));
11797
11798                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
11799                                 to_trn);
11800
11801                 memcpy(plaintext, tdata->plaintext.data + trn_data,
11802                                 to_trn);
11803                 trn_data += to_trn;
11804                 if (trn_data  == tdata->plaintext.len)
11805                         digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
11806                                         tdata->gmac_tag.len);
11807         }
11808         ut_params->ibuf->nb_segs = segs;
11809
11810         /*
11811          * Place digest at the end of the last buffer
11812          */
11813         uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11814
11815         if (!digest_mem) {
11816                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11817                                 + tdata->gmac_tag.len);
11818                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11819                                 tdata->plaintext.len);
11820         }
11821
11822         retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
11823                         tdata, digest_mem, digest_phys);
11824
11825         if (retval < 0)
11826                 return retval;
11827
11828         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11829
11830         ut_params->op->sym->m_src = ut_params->ibuf;
11831
11832         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11833                 return TEST_SKIPPED;
11834
11835         TEST_ASSERT_NOT_NULL(
11836                 process_crypto_request(ts_params->valid_devs[0],
11837                 ut_params->op), "failed to process sym crypto op");
11838
11839         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11840                         "crypto op processing failed");
11841
11842         auth_tag = digest_mem;
11843         debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11844         TEST_ASSERT_BUFFERS_ARE_EQUAL(
11845                         auth_tag,
11846                         tdata->gmac_tag.data,
11847                         tdata->gmac_tag.len,
11848                         "GMAC Generated auth tag not as expected");
11849
11850         return 0;
11851 }
11852
11853 /* Segment size not multiple of block size (16B) */
11854 static int
11855 test_AES_GMAC_authentication_SGL_40B(void)
11856 {
11857         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
11858 }
11859
11860 static int
11861 test_AES_GMAC_authentication_SGL_80B(void)
11862 {
11863         return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
11864 }
11865
11866 static int
11867 test_AES_GMAC_authentication_SGL_2048B(void)
11868 {
11869         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
11870 }
11871
11872 /* Segment size not multiple of block size (16B) */
11873 static int
11874 test_AES_GMAC_authentication_SGL_2047B(void)
11875 {
11876         return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
11877 }
11878
11879 struct test_crypto_vector {
11880         enum rte_crypto_cipher_algorithm crypto_algo;
11881         unsigned int cipher_offset;
11882         unsigned int cipher_len;
11883
11884         struct {
11885                 uint8_t data[64];
11886                 unsigned int len;
11887         } cipher_key;
11888
11889         struct {
11890                 uint8_t data[64];
11891                 unsigned int len;
11892         } iv;
11893
11894         struct {
11895                 const uint8_t *data;
11896                 unsigned int len;
11897         } plaintext;
11898
11899         struct {
11900                 const uint8_t *data;
11901                 unsigned int len;
11902         } ciphertext;
11903
11904         enum rte_crypto_auth_algorithm auth_algo;
11905         unsigned int auth_offset;
11906
11907         struct {
11908                 uint8_t data[128];
11909                 unsigned int len;
11910         } auth_key;
11911
11912         struct {
11913                 const uint8_t *data;
11914                 unsigned int len;
11915         } aad;
11916
11917         struct {
11918                 uint8_t data[128];
11919                 unsigned int len;
11920         } digest;
11921 };
11922
11923 static const struct test_crypto_vector
11924 hmac_sha1_test_crypto_vector = {
11925         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11926         .plaintext = {
11927                 .data = plaintext_hash,
11928                 .len = 512
11929         },
11930         .auth_key = {
11931                 .data = {
11932                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11933                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11934                         0xDE, 0xF4, 0xDE, 0xAD
11935                 },
11936                 .len = 20
11937         },
11938         .digest = {
11939                 .data = {
11940                         0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
11941                         0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
11942                         0x3F, 0x91, 0x64, 0x59
11943                 },
11944                 .len = 20
11945         }
11946 };
11947
11948 static const struct test_crypto_vector
11949 aes128_gmac_test_vector = {
11950         .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
11951         .plaintext = {
11952                 .data = plaintext_hash,
11953                 .len = 512
11954         },
11955         .iv = {
11956                 .data = {
11957                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11958                         0x08, 0x09, 0x0A, 0x0B
11959                 },
11960                 .len = 12
11961         },
11962         .auth_key = {
11963                 .data = {
11964                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
11965                         0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
11966                 },
11967                 .len = 16
11968         },
11969         .digest = {
11970                 .data = {
11971                         0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
11972                         0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
11973                 },
11974                 .len = 16
11975         }
11976 };
11977
11978 static const struct test_crypto_vector
11979 aes128cbc_hmac_sha1_test_vector = {
11980         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
11981         .cipher_offset = 0,
11982         .cipher_len = 512,
11983         .cipher_key = {
11984                 .data = {
11985                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
11986                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
11987                 },
11988                 .len = 16
11989         },
11990         .iv = {
11991                 .data = {
11992                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11993                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
11994                 },
11995                 .len = 16
11996         },
11997         .plaintext = {
11998                 .data = plaintext_hash,
11999                 .len = 512
12000         },
12001         .ciphertext = {
12002                 .data = ciphertext512_aes128cbc,
12003                 .len = 512
12004         },
12005         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12006         .auth_offset = 0,
12007         .auth_key = {
12008                 .data = {
12009                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12010                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12011                         0xDE, 0xF4, 0xDE, 0xAD
12012                 },
12013                 .len = 20
12014         },
12015         .digest = {
12016                 .data = {
12017                         0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12018                         0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12019                         0x18, 0x8C, 0x1D, 0x32
12020                 },
12021                 .len = 20
12022         }
12023 };
12024
12025 static const struct test_crypto_vector
12026 aes128cbc_hmac_sha1_aad_test_vector = {
12027         .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12028         .cipher_offset = 8,
12029         .cipher_len = 496,
12030         .cipher_key = {
12031                 .data = {
12032                         0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12033                         0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12034                 },
12035                 .len = 16
12036         },
12037         .iv = {
12038                 .data = {
12039                         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12040                         0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12041                 },
12042                 .len = 16
12043         },
12044         .plaintext = {
12045                 .data = plaintext_hash,
12046                 .len = 512
12047         },
12048         .ciphertext = {
12049                 .data = ciphertext512_aes128cbc_aad,
12050                 .len = 512
12051         },
12052         .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12053         .auth_offset = 0,
12054         .auth_key = {
12055                 .data = {
12056                         0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12057                         0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12058                         0xDE, 0xF4, 0xDE, 0xAD
12059                 },
12060                 .len = 20
12061         },
12062         .digest = {
12063                 .data = {
12064                         0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12065                         0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12066                         0x62, 0x0F, 0xFB, 0x10
12067                 },
12068                 .len = 20
12069         }
12070 };
12071
12072 static void
12073 data_corruption(uint8_t *data)
12074 {
12075         data[0] += 1;
12076 }
12077
12078 static void
12079 tag_corruption(uint8_t *data, unsigned int tag_offset)
12080 {
12081         data[tag_offset] += 1;
12082 }
12083
12084 static int
12085 create_auth_session(struct crypto_unittest_params *ut_params,
12086                 uint8_t dev_id,
12087                 const struct test_crypto_vector *reference,
12088                 enum rte_crypto_auth_operation auth_op)
12089 {
12090         struct crypto_testsuite_params *ts_params = &testsuite_params;
12091         uint8_t auth_key[reference->auth_key.len + 1];
12092
12093         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12094
12095         /* Setup Authentication Parameters */
12096         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12097         ut_params->auth_xform.auth.op = auth_op;
12098         ut_params->auth_xform.next = NULL;
12099         ut_params->auth_xform.auth.algo = reference->auth_algo;
12100         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12101         ut_params->auth_xform.auth.key.data = auth_key;
12102         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12103
12104         /* Create Crypto session*/
12105         ut_params->sess = rte_cryptodev_sym_session_create(
12106                         ts_params->session_mpool);
12107
12108         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12109                                 &ut_params->auth_xform,
12110                                 ts_params->session_priv_mpool);
12111
12112         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12113
12114         return 0;
12115 }
12116
12117 static int
12118 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12119                 uint8_t dev_id,
12120                 const struct test_crypto_vector *reference,
12121                 enum rte_crypto_auth_operation auth_op,
12122                 enum rte_crypto_cipher_operation cipher_op)
12123 {
12124         struct crypto_testsuite_params *ts_params = &testsuite_params;
12125         uint8_t cipher_key[reference->cipher_key.len + 1];
12126         uint8_t auth_key[reference->auth_key.len + 1];
12127
12128         memcpy(cipher_key, reference->cipher_key.data,
12129                         reference->cipher_key.len);
12130         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12131
12132         /* Setup Authentication Parameters */
12133         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12134         ut_params->auth_xform.auth.op = auth_op;
12135         ut_params->auth_xform.auth.algo = reference->auth_algo;
12136         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12137         ut_params->auth_xform.auth.key.data = auth_key;
12138         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12139
12140         if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12141                 ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12142                 ut_params->auth_xform.auth.iv.length = reference->iv.len;
12143         } else {
12144                 ut_params->auth_xform.next = &ut_params->cipher_xform;
12145
12146                 /* Setup Cipher Parameters */
12147                 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12148                 ut_params->cipher_xform.next = NULL;
12149                 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12150                 ut_params->cipher_xform.cipher.op = cipher_op;
12151                 ut_params->cipher_xform.cipher.key.data = cipher_key;
12152                 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12153                 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12154                 ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12155         }
12156
12157         /* Create Crypto session*/
12158         ut_params->sess = rte_cryptodev_sym_session_create(
12159                         ts_params->session_mpool);
12160
12161         rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12162                                 &ut_params->auth_xform,
12163                                 ts_params->session_priv_mpool);
12164
12165         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12166
12167         return 0;
12168 }
12169
12170 static int
12171 create_auth_operation(struct crypto_testsuite_params *ts_params,
12172                 struct crypto_unittest_params *ut_params,
12173                 const struct test_crypto_vector *reference,
12174                 unsigned int auth_generate)
12175 {
12176         /* Generate Crypto op data structure */
12177         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12178                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12179         TEST_ASSERT_NOT_NULL(ut_params->op,
12180                         "Failed to allocate pktmbuf offload");
12181
12182         /* Set crypto operation data parameters */
12183         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12184
12185         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12186
12187         /* set crypto operation source mbuf */
12188         sym_op->m_src = ut_params->ibuf;
12189
12190         /* digest */
12191         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12192                         ut_params->ibuf, reference->digest.len);
12193
12194         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12195                         "no room to append auth tag");
12196
12197         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12198                         ut_params->ibuf, reference->plaintext.len);
12199
12200         if (auth_generate)
12201                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12202         else
12203                 memcpy(sym_op->auth.digest.data,
12204                                 reference->digest.data,
12205                                 reference->digest.len);
12206
12207         debug_hexdump(stdout, "digest:",
12208                         sym_op->auth.digest.data,
12209                         reference->digest.len);
12210
12211         sym_op->auth.data.length = reference->plaintext.len;
12212         sym_op->auth.data.offset = 0;
12213
12214         return 0;
12215 }
12216
12217 static int
12218 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12219                 struct crypto_unittest_params *ut_params,
12220                 const struct test_crypto_vector *reference,
12221                 unsigned int auth_generate)
12222 {
12223         /* Generate Crypto op data structure */
12224         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12225                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12226         TEST_ASSERT_NOT_NULL(ut_params->op,
12227                         "Failed to allocate pktmbuf offload");
12228
12229         /* Set crypto operation data parameters */
12230         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12231
12232         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12233
12234         /* set crypto operation source mbuf */
12235         sym_op->m_src = ut_params->ibuf;
12236
12237         /* digest */
12238         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12239                         ut_params->ibuf, reference->digest.len);
12240
12241         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12242                         "no room to append auth tag");
12243
12244         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12245                         ut_params->ibuf, reference->ciphertext.len);
12246
12247         if (auth_generate)
12248                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12249         else
12250                 memcpy(sym_op->auth.digest.data,
12251                                 reference->digest.data,
12252                                 reference->digest.len);
12253
12254         debug_hexdump(stdout, "digest:",
12255                         sym_op->auth.digest.data,
12256                         reference->digest.len);
12257
12258         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12259                         reference->iv.data, reference->iv.len);
12260
12261         sym_op->cipher.data.length = 0;
12262         sym_op->cipher.data.offset = 0;
12263
12264         sym_op->auth.data.length = reference->plaintext.len;
12265         sym_op->auth.data.offset = 0;
12266
12267         return 0;
12268 }
12269
12270 static int
12271 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12272                 struct crypto_unittest_params *ut_params,
12273                 const struct test_crypto_vector *reference,
12274                 unsigned int auth_generate)
12275 {
12276         /* Generate Crypto op data structure */
12277         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12278                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12279         TEST_ASSERT_NOT_NULL(ut_params->op,
12280                         "Failed to allocate pktmbuf offload");
12281
12282         /* Set crypto operation data parameters */
12283         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12284
12285         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12286
12287         /* set crypto operation source mbuf */
12288         sym_op->m_src = ut_params->ibuf;
12289
12290         /* digest */
12291         sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12292                         ut_params->ibuf, reference->digest.len);
12293
12294         TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12295                         "no room to append auth tag");
12296
12297         sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12298                         ut_params->ibuf, reference->ciphertext.len);
12299
12300         if (auth_generate)
12301                 memset(sym_op->auth.digest.data, 0, reference->digest.len);
12302         else
12303                 memcpy(sym_op->auth.digest.data,
12304                                 reference->digest.data,
12305                                 reference->digest.len);
12306
12307         debug_hexdump(stdout, "digest:",
12308                         sym_op->auth.digest.data,
12309                         reference->digest.len);
12310
12311         rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12312                         reference->iv.data, reference->iv.len);
12313
12314         sym_op->cipher.data.length = reference->cipher_len;
12315         sym_op->cipher.data.offset = reference->cipher_offset;
12316
12317         sym_op->auth.data.length = reference->plaintext.len;
12318         sym_op->auth.data.offset = reference->auth_offset;
12319
12320         return 0;
12321 }
12322
12323 static int
12324 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12325                 struct crypto_unittest_params *ut_params,
12326                 const struct test_crypto_vector *reference)
12327 {
12328         return create_auth_operation(ts_params, ut_params, reference, 0);
12329 }
12330
12331 static int
12332 create_auth_verify_GMAC_operation(
12333                 struct crypto_testsuite_params *ts_params,
12334                 struct crypto_unittest_params *ut_params,
12335                 const struct test_crypto_vector *reference)
12336 {
12337         return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
12338 }
12339
12340 static int
12341 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12342                 struct crypto_unittest_params *ut_params,
12343                 const struct test_crypto_vector *reference)
12344 {
12345         return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12346 }
12347
12348 static int
12349 test_authentication_verify_fail_when_data_corruption(
12350                 struct crypto_testsuite_params *ts_params,
12351                 struct crypto_unittest_params *ut_params,
12352                 const struct test_crypto_vector *reference,
12353                 unsigned int data_corrupted)
12354 {
12355         int retval;
12356
12357         uint8_t *plaintext;
12358         struct rte_cryptodev_info dev_info;
12359
12360         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12361         uint64_t feat_flags = dev_info.feature_flags;
12362
12363         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12364                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12365                 printf("Device doesn't support RAW data-path APIs.\n");
12366                 return TEST_SKIPPED;
12367         }
12368
12369         /* Verify the capabilities */
12370         struct rte_cryptodev_sym_capability_idx cap_idx;
12371         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12372         cap_idx.algo.auth = reference->auth_algo;
12373         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12374                         &cap_idx) == NULL)
12375                 return TEST_SKIPPED;
12376
12377
12378         /* Create session */
12379         retval = create_auth_session(ut_params,
12380                         ts_params->valid_devs[0],
12381                         reference,
12382                         RTE_CRYPTO_AUTH_OP_VERIFY);
12383         if (retval < 0)
12384                 return retval;
12385
12386         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12387         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12388                         "Failed to allocate input buffer in mempool");
12389
12390         /* clear mbuf payload */
12391         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12392                         rte_pktmbuf_tailroom(ut_params->ibuf));
12393
12394         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12395                         reference->plaintext.len);
12396         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12397         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12398
12399         debug_hexdump(stdout, "plaintext:", plaintext,
12400                 reference->plaintext.len);
12401
12402         /* Create operation */
12403         retval = create_auth_verify_operation(ts_params, ut_params, reference);
12404
12405         if (retval < 0)
12406                 return retval;
12407
12408         if (data_corrupted)
12409                 data_corruption(plaintext);
12410         else
12411                 tag_corruption(plaintext, reference->plaintext.len);
12412
12413         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12414                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12415                         ut_params->op);
12416                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12417                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12418                         "authentication not failed");
12419         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12420                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12421                                 ut_params->op, 0, 1, 0, 0);
12422         else {
12423                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12424                         ut_params->op);
12425                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12426         }
12427
12428         return 0;
12429 }
12430
12431 static int
12432 test_authentication_verify_GMAC_fail_when_corruption(
12433                 struct crypto_testsuite_params *ts_params,
12434                 struct crypto_unittest_params *ut_params,
12435                 const struct test_crypto_vector *reference,
12436                 unsigned int data_corrupted)
12437 {
12438         int retval;
12439         uint8_t *plaintext;
12440         struct rte_cryptodev_info dev_info;
12441
12442         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12443         uint64_t feat_flags = dev_info.feature_flags;
12444
12445         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12446                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12447                 printf("Device doesn't support RAW data-path APIs.\n");
12448                 return TEST_SKIPPED;
12449         }
12450
12451         /* Verify the capabilities */
12452         struct rte_cryptodev_sym_capability_idx cap_idx;
12453         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12454         cap_idx.algo.auth = reference->auth_algo;
12455         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12456                         &cap_idx) == NULL)
12457                 return TEST_SKIPPED;
12458
12459         /* Create session */
12460         retval = create_auth_cipher_session(ut_params,
12461                         ts_params->valid_devs[0],
12462                         reference,
12463                         RTE_CRYPTO_AUTH_OP_VERIFY,
12464                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12465         if (retval < 0)
12466                 return retval;
12467
12468         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12469         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12470                         "Failed to allocate input buffer in mempool");
12471
12472         /* clear mbuf payload */
12473         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12474                         rte_pktmbuf_tailroom(ut_params->ibuf));
12475
12476         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12477                         reference->plaintext.len);
12478         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12479         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12480
12481         debug_hexdump(stdout, "plaintext:", plaintext,
12482                 reference->plaintext.len);
12483
12484         /* Create operation */
12485         retval = create_auth_verify_GMAC_operation(ts_params,
12486                         ut_params,
12487                         reference);
12488
12489         if (retval < 0)
12490                 return retval;
12491
12492         if (data_corrupted)
12493                 data_corruption(plaintext);
12494         else
12495                 tag_corruption(plaintext, reference->aad.len);
12496
12497         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12498                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12499                         ut_params->op);
12500                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12501                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12502                         "authentication not failed");
12503         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12504                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12505                                 ut_params->op, 0, 1, 0, 0);
12506         else {
12507                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12508                         ut_params->op);
12509                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12510         }
12511
12512         return 0;
12513 }
12514
12515 static int
12516 test_authenticated_decryption_fail_when_corruption(
12517                 struct crypto_testsuite_params *ts_params,
12518                 struct crypto_unittest_params *ut_params,
12519                 const struct test_crypto_vector *reference,
12520                 unsigned int data_corrupted)
12521 {
12522         int retval;
12523
12524         uint8_t *ciphertext;
12525         struct rte_cryptodev_info dev_info;
12526
12527         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12528         uint64_t feat_flags = dev_info.feature_flags;
12529
12530         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12531                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12532                 printf("Device doesn't support RAW data-path APIs.\n");
12533                 return TEST_SKIPPED;
12534         }
12535
12536         /* Verify the capabilities */
12537         struct rte_cryptodev_sym_capability_idx cap_idx;
12538         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12539         cap_idx.algo.auth = reference->auth_algo;
12540         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12541                         &cap_idx) == NULL)
12542                 return TEST_SKIPPED;
12543         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12544         cap_idx.algo.cipher = reference->crypto_algo;
12545         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12546                         &cap_idx) == NULL)
12547                 return TEST_SKIPPED;
12548
12549         /* Create session */
12550         retval = create_auth_cipher_session(ut_params,
12551                         ts_params->valid_devs[0],
12552                         reference,
12553                         RTE_CRYPTO_AUTH_OP_VERIFY,
12554                         RTE_CRYPTO_CIPHER_OP_DECRYPT);
12555         if (retval < 0)
12556                 return retval;
12557
12558         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12559         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12560                         "Failed to allocate input buffer in mempool");
12561
12562         /* clear mbuf payload */
12563         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12564                         rte_pktmbuf_tailroom(ut_params->ibuf));
12565
12566         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12567                         reference->ciphertext.len);
12568         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12569         memcpy(ciphertext, reference->ciphertext.data,
12570                         reference->ciphertext.len);
12571
12572         /* Create operation */
12573         retval = create_cipher_auth_verify_operation(ts_params,
12574                         ut_params,
12575                         reference);
12576
12577         if (retval < 0)
12578                 return retval;
12579
12580         if (data_corrupted)
12581                 data_corruption(ciphertext);
12582         else
12583                 tag_corruption(ciphertext, reference->ciphertext.len);
12584
12585         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12586                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12587                         ut_params->op);
12588                 TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12589                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12590                         "authentication not failed");
12591         } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12592                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12593                                 ut_params->op, 1, 1, 0, 0);
12594         else {
12595                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12596                         ut_params->op);
12597                 TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12598         }
12599
12600         return 0;
12601 }
12602
12603 static int
12604 test_authenticated_encryt_with_esn(
12605                 struct crypto_testsuite_params *ts_params,
12606                 struct crypto_unittest_params *ut_params,
12607                 const struct test_crypto_vector *reference)
12608 {
12609         int retval;
12610
12611         uint8_t *authciphertext, *plaintext, *auth_tag;
12612         uint16_t plaintext_pad_len;
12613         uint8_t cipher_key[reference->cipher_key.len + 1];
12614         uint8_t auth_key[reference->auth_key.len + 1];
12615         struct rte_cryptodev_info dev_info;
12616
12617         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12618         uint64_t feat_flags = dev_info.feature_flags;
12619
12620         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12621                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12622                 printf("Device doesn't support RAW data-path APIs.\n");
12623                 return TEST_SKIPPED;
12624         }
12625
12626         /* Verify the capabilities */
12627         struct rte_cryptodev_sym_capability_idx cap_idx;
12628         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12629         cap_idx.algo.auth = reference->auth_algo;
12630         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12631                         &cap_idx) == NULL)
12632                 return TEST_SKIPPED;
12633         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12634         cap_idx.algo.cipher = reference->crypto_algo;
12635         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12636                         &cap_idx) == NULL)
12637                 return TEST_SKIPPED;
12638
12639         /* Create session */
12640         memcpy(cipher_key, reference->cipher_key.data,
12641                         reference->cipher_key.len);
12642         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12643
12644         /* Setup Cipher Parameters */
12645         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12646         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12647         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12648         ut_params->cipher_xform.cipher.key.data = cipher_key;
12649         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12650         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12651         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12652
12653         ut_params->cipher_xform.next = &ut_params->auth_xform;
12654
12655         /* Setup Authentication Parameters */
12656         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12657         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12658         ut_params->auth_xform.auth.algo = reference->auth_algo;
12659         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12660         ut_params->auth_xform.auth.key.data = auth_key;
12661         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12662         ut_params->auth_xform.next = NULL;
12663
12664         /* Create Crypto session*/
12665         ut_params->sess = rte_cryptodev_sym_session_create(
12666                         ts_params->session_mpool);
12667
12668         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12669                                 ut_params->sess,
12670                                 &ut_params->cipher_xform,
12671                                 ts_params->session_priv_mpool);
12672
12673         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12674
12675         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12676         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12677                         "Failed to allocate input buffer in mempool");
12678
12679         /* clear mbuf payload */
12680         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12681                         rte_pktmbuf_tailroom(ut_params->ibuf));
12682
12683         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12684                         reference->plaintext.len);
12685         TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12686         memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12687
12688         /* Create operation */
12689         retval = create_cipher_auth_operation(ts_params,
12690                         ut_params,
12691                         reference, 0);
12692
12693         if (retval < 0)
12694                 return retval;
12695
12696         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12697                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12698                         ut_params->op);
12699         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12700                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12701                                 ut_params->op, 1, 1, 0, 0);
12702         else
12703                 ut_params->op = process_crypto_request(
12704                         ts_params->valid_devs[0], ut_params->op);
12705
12706         TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
12707
12708         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12709                         "crypto op processing failed");
12710
12711         plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
12712
12713         authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
12714                         ut_params->op->sym->auth.data.offset);
12715         auth_tag = authciphertext + plaintext_pad_len;
12716         debug_hexdump(stdout, "ciphertext:", authciphertext,
12717                         reference->ciphertext.len);
12718         debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
12719
12720         /* Validate obuf */
12721         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12722                         authciphertext,
12723                         reference->ciphertext.data,
12724                         reference->ciphertext.len,
12725                         "Ciphertext data not as expected");
12726
12727         TEST_ASSERT_BUFFERS_ARE_EQUAL(
12728                         auth_tag,
12729                         reference->digest.data,
12730                         reference->digest.len,
12731                         "Generated digest not as expected");
12732
12733         return TEST_SUCCESS;
12734
12735 }
12736
12737 static int
12738 test_authenticated_decrypt_with_esn(
12739                 struct crypto_testsuite_params *ts_params,
12740                 struct crypto_unittest_params *ut_params,
12741                 const struct test_crypto_vector *reference)
12742 {
12743         int retval;
12744
12745         uint8_t *ciphertext;
12746         uint8_t cipher_key[reference->cipher_key.len + 1];
12747         uint8_t auth_key[reference->auth_key.len + 1];
12748         struct rte_cryptodev_info dev_info;
12749
12750         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12751         uint64_t feat_flags = dev_info.feature_flags;
12752
12753         if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12754                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12755                 printf("Device doesn't support RAW data-path APIs.\n");
12756                 return TEST_SKIPPED;
12757         }
12758
12759         /* Verify the capabilities */
12760         struct rte_cryptodev_sym_capability_idx cap_idx;
12761         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12762         cap_idx.algo.auth = reference->auth_algo;
12763         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12764                         &cap_idx) == NULL)
12765                 return TEST_SKIPPED;
12766         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12767         cap_idx.algo.cipher = reference->crypto_algo;
12768         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12769                         &cap_idx) == NULL)
12770                 return TEST_SKIPPED;
12771
12772         /* Create session */
12773         memcpy(cipher_key, reference->cipher_key.data,
12774                         reference->cipher_key.len);
12775         memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12776
12777         /* Setup Authentication Parameters */
12778         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12779         ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
12780         ut_params->auth_xform.auth.algo = reference->auth_algo;
12781         ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12782         ut_params->auth_xform.auth.key.data = auth_key;
12783         ut_params->auth_xform.auth.digest_length = reference->digest.len;
12784         ut_params->auth_xform.next = &ut_params->cipher_xform;
12785
12786         /* Setup Cipher Parameters */
12787         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12788         ut_params->cipher_xform.next = NULL;
12789         ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12790         ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
12791         ut_params->cipher_xform.cipher.key.data = cipher_key;
12792         ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12793         ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12794         ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12795
12796         /* Create Crypto session*/
12797         ut_params->sess = rte_cryptodev_sym_session_create(
12798                         ts_params->session_mpool);
12799
12800         rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12801                                 ut_params->sess,
12802                                 &ut_params->auth_xform,
12803                                 ts_params->session_priv_mpool);
12804
12805         TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12806
12807         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12808         TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12809                         "Failed to allocate input buffer in mempool");
12810
12811         /* clear mbuf payload */
12812         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12813                         rte_pktmbuf_tailroom(ut_params->ibuf));
12814
12815         ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12816                         reference->ciphertext.len);
12817         TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12818         memcpy(ciphertext, reference->ciphertext.data,
12819                         reference->ciphertext.len);
12820
12821         /* Create operation */
12822         retval = create_cipher_auth_verify_operation(ts_params,
12823                         ut_params,
12824                         reference);
12825
12826         if (retval < 0)
12827                 return retval;
12828
12829         if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12830                 process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12831                         ut_params->op);
12832         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12833                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12834                                 ut_params->op, 1, 1, 0, 0);
12835         else
12836                 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12837                         ut_params->op);
12838
12839         TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
12840         TEST_ASSERT_EQUAL(ut_params->op->status,
12841                         RTE_CRYPTO_OP_STATUS_SUCCESS,
12842                         "crypto op processing passed");
12843
12844         ut_params->obuf = ut_params->op->sym->m_src;
12845         TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
12846
12847         return 0;
12848 }
12849
12850 static int
12851 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
12852                 const struct aead_test_data *tdata,
12853                 void *digest_mem, uint64_t digest_phys)
12854 {
12855         struct crypto_testsuite_params *ts_params = &testsuite_params;
12856         struct crypto_unittest_params *ut_params = &unittest_params;
12857
12858         const unsigned int auth_tag_len = tdata->auth_tag.len;
12859         const unsigned int iv_len = tdata->iv.len;
12860         unsigned int aad_len = tdata->aad.len;
12861         unsigned int aad_len_pad = 0;
12862
12863         /* Generate Crypto op data structure */
12864         ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12865                         RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12866         TEST_ASSERT_NOT_NULL(ut_params->op,
12867                 "Failed to allocate symmetric crypto operation struct");
12868
12869         struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12870
12871         sym_op->aead.digest.data = digest_mem;
12872
12873         TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
12874                         "no room to append digest");
12875
12876         sym_op->aead.digest.phys_addr = digest_phys;
12877
12878         if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
12879                 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
12880                                 auth_tag_len);
12881                 debug_hexdump(stdout, "digest:",
12882                                 sym_op->aead.digest.data,
12883                                 auth_tag_len);
12884         }
12885
12886         /* Append aad data */
12887         if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
12888                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12889                                 uint8_t *, IV_OFFSET);
12890
12891                 /* Copy IV 1 byte after the IV pointer, according to the API */
12892                 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
12893
12894                 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
12895
12896                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12897                                 ut_params->ibuf, aad_len);
12898                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12899                                 "no room to prepend aad");
12900                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12901                                 ut_params->ibuf);
12902
12903                 memset(sym_op->aead.aad.data, 0, aad_len);
12904                 /* Copy AAD 18 bytes after the AAD pointer, according to the API */
12905                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12906
12907                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12908                 debug_hexdump(stdout, "aad:",
12909                                 sym_op->aead.aad.data, aad_len);
12910         } else {
12911                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12912                                 uint8_t *, IV_OFFSET);
12913
12914                 rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
12915
12916                 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
12917
12918                 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12919                                 ut_params->ibuf, aad_len_pad);
12920                 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12921                                 "no room to prepend aad");
12922                 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12923                                 ut_params->ibuf);
12924
12925                 memset(sym_op->aead.aad.data, 0, aad_len);
12926                 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12927
12928                 debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12929                 debug_hexdump(stdout, "aad:",
12930                                 sym_op->aead.aad.data, aad_len);
12931         }
12932
12933         sym_op->aead.data.length = tdata->plaintext.len;
12934         sym_op->aead.data.offset = aad_len_pad;
12935
12936         return 0;
12937 }
12938
12939 #define SGL_MAX_NO      16
12940
12941 static int
12942 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
12943                 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
12944 {
12945         struct crypto_testsuite_params *ts_params = &testsuite_params;
12946         struct crypto_unittest_params *ut_params = &unittest_params;
12947         struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
12948         int retval;
12949         int to_trn = 0;
12950         int to_trn_tbl[SGL_MAX_NO];
12951         int segs = 1;
12952         unsigned int trn_data = 0;
12953         uint8_t *plaintext, *ciphertext, *auth_tag;
12954         struct rte_cryptodev_info dev_info;
12955
12956         /* Verify the capabilities */
12957         struct rte_cryptodev_sym_capability_idx cap_idx;
12958         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
12959         cap_idx.algo.aead = tdata->algo;
12960         if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12961                         &cap_idx) == NULL)
12962                 return TEST_SKIPPED;
12963
12964         /* OOP not supported with CPU crypto */
12965         if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12966                 return TEST_SKIPPED;
12967
12968         /* Detailed check for the particular SGL support flag */
12969         rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12970         if (!oop) {
12971                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
12972                 if (sgl_in && (!(dev_info.feature_flags &
12973                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
12974                         return TEST_SKIPPED;
12975
12976                 uint64_t feat_flags = dev_info.feature_flags;
12977
12978                 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12979                         (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12980                         printf("Device doesn't support RAW data-path APIs.\n");
12981                         return TEST_SKIPPED;
12982                 }
12983         } else {
12984                 unsigned int sgl_in = fragsz < tdata->plaintext.len;
12985                 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
12986                                 tdata->plaintext.len;
12987                 /* Raw data path API does not support OOP */
12988                 if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12989                         return TEST_SKIPPED;
12990                 if (sgl_in && !sgl_out) {
12991                         if (!(dev_info.feature_flags &
12992                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
12993                                 return TEST_SKIPPED;
12994                 } else if (!sgl_in && sgl_out) {
12995                         if (!(dev_info.feature_flags &
12996                                         RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
12997                                 return TEST_SKIPPED;
12998                 } else if (sgl_in && sgl_out) {
12999                         if (!(dev_info.feature_flags &
13000                                         RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13001                                 return TEST_SKIPPED;
13002                 }
13003         }
13004
13005         if (fragsz > tdata->plaintext.len)
13006                 fragsz = tdata->plaintext.len;
13007
13008         uint16_t plaintext_len = fragsz;
13009         uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13010
13011         if (fragsz_oop > tdata->plaintext.len)
13012                 frag_size_oop = tdata->plaintext.len;
13013
13014         int ecx = 0;
13015         void *digest_mem = NULL;
13016
13017         uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13018
13019         if (tdata->plaintext.len % fragsz != 0) {
13020                 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13021                         return 1;
13022         }       else {
13023                 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13024                         return 1;
13025         }
13026
13027         /*
13028          * For out-op-place we need to alloc another mbuf
13029          */
13030         if (oop) {
13031                 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13032                 rte_pktmbuf_append(ut_params->obuf,
13033                                 frag_size_oop + prepend_len);
13034                 buf_oop = ut_params->obuf;
13035         }
13036
13037         /* Create AEAD session */
13038         retval = create_aead_session(ts_params->valid_devs[0],
13039                         tdata->algo,
13040                         RTE_CRYPTO_AEAD_OP_ENCRYPT,
13041                         tdata->key.data, tdata->key.len,
13042                         tdata->aad.len, tdata->auth_tag.len,
13043                         tdata->iv.len);
13044         if (retval < 0)
13045                 return retval;
13046
13047         ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13048
13049         /* clear mbuf payload */
13050         memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13051                         rte_pktmbuf_tailroom(ut_params->ibuf));
13052
13053         plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13054                         plaintext_len);
13055
13056         memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13057
13058         trn_data += plaintext_len;
13059
13060         buf = ut_params->ibuf;
13061
13062         /*
13063          * Loop until no more fragments
13064          */
13065
13066         while (trn_data < tdata->plaintext.len) {
13067                 ++segs;
13068                 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13069                                 (tdata->plaintext.len - trn_data) : fragsz;
13070
13071                 to_trn_tbl[ecx++] = to_trn;
13072
13073                 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13074                 buf = buf->next;
13075
13076                 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13077                                 rte_pktmbuf_tailroom(buf));
13078
13079                 /* OOP */
13080                 if (oop && !fragsz_oop) {
13081                         buf_last_oop = buf_oop->next =
13082                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13083                         buf_oop = buf_oop->next;
13084                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13085                                         0, rte_pktmbuf_tailroom(buf_oop));
13086                         rte_pktmbuf_append(buf_oop, to_trn);
13087                 }
13088
13089                 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13090                                 to_trn);
13091
13092                 memcpy(plaintext, tdata->plaintext.data + trn_data,
13093                                 to_trn);
13094                 trn_data += to_trn;
13095                 if (trn_data  == tdata->plaintext.len) {
13096                         if (oop) {
13097                                 if (!fragsz_oop)
13098                                         digest_mem = rte_pktmbuf_append(buf_oop,
13099                                                 tdata->auth_tag.len);
13100                         } else
13101                                 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13102                                         tdata->auth_tag.len);
13103                 }
13104         }
13105
13106         uint64_t digest_phys = 0;
13107
13108         ut_params->ibuf->nb_segs = segs;
13109
13110         segs = 1;
13111         if (fragsz_oop && oop) {
13112                 to_trn = 0;
13113                 ecx = 0;
13114
13115                 if (frag_size_oop == tdata->plaintext.len) {
13116                         digest_mem = rte_pktmbuf_append(ut_params->obuf,
13117                                 tdata->auth_tag.len);
13118
13119                         digest_phys = rte_pktmbuf_iova_offset(
13120                                         ut_params->obuf,
13121                                         tdata->plaintext.len + prepend_len);
13122                 }
13123
13124                 trn_data = frag_size_oop;
13125                 while (trn_data < tdata->plaintext.len) {
13126                         ++segs;
13127                         to_trn =
13128                                 (tdata->plaintext.len - trn_data <
13129                                                 frag_size_oop) ?
13130                                 (tdata->plaintext.len - trn_data) :
13131                                                 frag_size_oop;
13132
13133                         to_trn_tbl[ecx++] = to_trn;
13134
13135                         buf_last_oop = buf_oop->next =
13136                                         rte_pktmbuf_alloc(ts_params->mbuf_pool);
13137                         buf_oop = buf_oop->next;
13138                         memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13139                                         0, rte_pktmbuf_tailroom(buf_oop));
13140                         rte_pktmbuf_append(buf_oop, to_trn);
13141
13142                         trn_data += to_trn;
13143
13144                         if (trn_data  == tdata->plaintext.len) {
13145                                 digest_mem = rte_pktmbuf_append(buf_oop,
13146                                         tdata->auth_tag.len);
13147                         }
13148                 }
13149
13150                 ut_params->obuf->nb_segs = segs;
13151         }
13152
13153         /*
13154          * Place digest at the end of the last buffer
13155          */
13156         if (!digest_phys)
13157                 digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13158         if (oop && buf_last_oop)
13159                 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13160
13161         if (!digest_mem && !oop) {
13162                 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13163                                 + tdata->auth_tag.len);
13164                 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13165                                 tdata->plaintext.len);
13166         }
13167
13168         /* Create AEAD operation */
13169         retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13170                         tdata, digest_mem, digest_phys);
13171
13172         if (retval < 0)
13173                 return retval;
13174
13175         rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13176
13177         ut_params->op->sym->m_src = ut_params->ibuf;
13178         if (oop)
13179                 ut_params->op->sym->m_dst = ut_params->obuf;
13180
13181         /* Process crypto operation */
13182         if (oop == IN_PLACE &&
13183                         gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13184                 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13185         else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13186                 process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13187                                 ut_params->op, 0, 0, 0, 0);
13188         else
13189                 TEST_ASSERT_NOT_NULL(
13190                         process_crypto_request(ts_params->valid_devs[0],
13191                         ut_params->op), "failed to process sym crypto op");
13192
13193         TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13194                         "crypto op processing failed");
13195
13196
13197         ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13198                         uint8_t *, prepend_len);
13199         if (oop) {
13200                 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13201                                 uint8_t *, prepend_len);
13202         }
13203
13204         if (fragsz_oop)
13205                 fragsz = fragsz_oop;
13206
13207         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13208                         ciphertext,
13209                         tdata->ciphertext.data,
13210                         fragsz,
13211                         "Ciphertext data not as expected");
13212
13213         buf = ut_params->op->sym->m_src->next;
13214         if (oop)
13215                 buf = ut_params->op->sym->m_dst->next;
13216
13217         unsigned int off = fragsz;
13218
13219         ecx = 0;
13220         while (buf) {
13221                 ciphertext = rte_pktmbuf_mtod(buf,
13222                                 uint8_t *);
13223
13224                 TEST_ASSERT_BUFFERS_ARE_EQUAL(
13225                                 ciphertext,
13226                                 tdata->ciphertext.data + off,
13227                                 to_trn_tbl[ecx],
13228                                 "Ciphertext data not as expected");
13229
13230                 off += to_trn_tbl[ecx++];
13231                 buf = buf->next;
13232         }
13233
13234         auth_tag = digest_mem;
13235         TEST_ASSERT_BUFFERS_ARE_EQUAL(
13236                         auth_tag,
13237                         tdata->auth_tag.data,
13238                         tdata->auth_tag.len,
13239                         "Generated auth tag not as expected");
13240
13241         return 0;
13242 }
13243
13244 static int
13245 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13246 {
13247         return test_authenticated_encryption_SGL(
13248                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13249 }
13250
13251 static int
13252 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13253 {
13254         return test_authenticated_encryption_SGL(
13255                         &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13256 }
13257
13258 static int
13259 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13260 {
13261         return test_authenticated_encryption_SGL(
13262                         &gcm_test_case_8, OUT_OF_PLACE, 400,
13263                         gcm_test_case_8.plaintext.len);
13264 }
13265
13266 static int
13267 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13268 {
13269         /* This test is not for OPENSSL PMD */
13270         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13271                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13272                 return TEST_SKIPPED;
13273
13274         return test_authenticated_encryption_SGL(
13275                         &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13276 }
13277
13278 static int
13279 test_authentication_verify_fail_when_data_corrupted(
13280                 struct crypto_testsuite_params *ts_params,
13281                 struct crypto_unittest_params *ut_params,
13282                 const struct test_crypto_vector *reference)
13283 {
13284         return test_authentication_verify_fail_when_data_corruption(
13285                         ts_params, ut_params, reference, 1);
13286 }
13287
13288 static int
13289 test_authentication_verify_fail_when_tag_corrupted(
13290                 struct crypto_testsuite_params *ts_params,
13291                 struct crypto_unittest_params *ut_params,
13292                 const struct test_crypto_vector *reference)
13293 {
13294         return test_authentication_verify_fail_when_data_corruption(
13295                         ts_params, ut_params, reference, 0);
13296 }
13297
13298 static int
13299 test_authentication_verify_GMAC_fail_when_data_corrupted(
13300                 struct crypto_testsuite_params *ts_params,
13301                 struct crypto_unittest_params *ut_params,
13302                 const struct test_crypto_vector *reference)
13303 {
13304         return test_authentication_verify_GMAC_fail_when_corruption(
13305                         ts_params, ut_params, reference, 1);
13306 }
13307
13308 static int
13309 test_authentication_verify_GMAC_fail_when_tag_corrupted(
13310                 struct crypto_testsuite_params *ts_params,
13311                 struct crypto_unittest_params *ut_params,
13312                 const struct test_crypto_vector *reference)
13313 {
13314         return test_authentication_verify_GMAC_fail_when_corruption(
13315                         ts_params, ut_params, reference, 0);
13316 }
13317
13318 static int
13319 test_authenticated_decryption_fail_when_data_corrupted(
13320                 struct crypto_testsuite_params *ts_params,
13321                 struct crypto_unittest_params *ut_params,
13322                 const struct test_crypto_vector *reference)
13323 {
13324         return test_authenticated_decryption_fail_when_corruption(
13325                         ts_params, ut_params, reference, 1);
13326 }
13327
13328 static int
13329 test_authenticated_decryption_fail_when_tag_corrupted(
13330                 struct crypto_testsuite_params *ts_params,
13331                 struct crypto_unittest_params *ut_params,
13332                 const struct test_crypto_vector *reference)
13333 {
13334         return test_authenticated_decryption_fail_when_corruption(
13335                         ts_params, ut_params, reference, 0);
13336 }
13337
13338 static int
13339 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
13340 {
13341         return test_authentication_verify_fail_when_data_corrupted(
13342                         &testsuite_params, &unittest_params,
13343                         &hmac_sha1_test_crypto_vector);
13344 }
13345
13346 static int
13347 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13348 {
13349         return test_authentication_verify_fail_when_tag_corrupted(
13350                         &testsuite_params, &unittest_params,
13351                         &hmac_sha1_test_crypto_vector);
13352 }
13353
13354 static int
13355 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
13356 {
13357         return test_authentication_verify_GMAC_fail_when_data_corrupted(
13358                         &testsuite_params, &unittest_params,
13359                         &aes128_gmac_test_vector);
13360 }
13361
13362 static int
13363 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
13364 {
13365         return test_authentication_verify_GMAC_fail_when_tag_corrupted(
13366                         &testsuite_params, &unittest_params,
13367                         &aes128_gmac_test_vector);
13368 }
13369
13370 static int
13371 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
13372 {
13373         return test_authenticated_decryption_fail_when_data_corrupted(
13374                         &testsuite_params,
13375                         &unittest_params,
13376                         &aes128cbc_hmac_sha1_test_vector);
13377 }
13378
13379 static int
13380 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
13381 {
13382         return test_authenticated_decryption_fail_when_tag_corrupted(
13383                         &testsuite_params,
13384                         &unittest_params,
13385                         &aes128cbc_hmac_sha1_test_vector);
13386 }
13387
13388 static int
13389 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13390 {
13391         return test_authenticated_encryt_with_esn(
13392                         &testsuite_params,
13393                         &unittest_params,
13394                         &aes128cbc_hmac_sha1_aad_test_vector);
13395 }
13396
13397 static int
13398 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13399 {
13400         return test_authenticated_decrypt_with_esn(
13401                         &testsuite_params,
13402                         &unittest_params,
13403                         &aes128cbc_hmac_sha1_aad_test_vector);
13404 }
13405
13406 static int
13407 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
13408 {
13409         return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
13410 }
13411
13412 static int
13413 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
13414 {
13415         return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
13416 }
13417
13418 #ifdef RTE_CRYPTO_SCHEDULER
13419
13420 /* global AESNI worker IDs for the scheduler test */
13421 uint8_t aesni_ids[2];
13422
13423 static int
13424 scheduler_testsuite_setup(void)
13425 {
13426         uint32_t i = 0;
13427         int32_t nb_devs, ret;
13428         char vdev_args[VDEV_ARGS_SIZE] = {""};
13429         char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
13430                 "ordering=enable,name=cryptodev_test_scheduler,corelist="};
13431         uint16_t worker_core_count = 0;
13432         uint16_t socket_id = 0;
13433
13434         if (gbl_driver_id == rte_cryptodev_driver_id_get(
13435                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
13436
13437                 /* Identify the Worker Cores
13438                  * Use 2 worker cores for the device args
13439                  */
13440                 RTE_LCORE_FOREACH_WORKER(i) {
13441                         if (worker_core_count > 1)
13442                                 break;
13443                         snprintf(vdev_args, sizeof(vdev_args),
13444                                         "%s%d", temp_str, i);
13445                         strcpy(temp_str, vdev_args);
13446                         strlcat(temp_str, ";", sizeof(temp_str));
13447                         worker_core_count++;
13448                         socket_id = rte_lcore_to_socket_id(i);
13449                 }
13450                 if (worker_core_count != 2) {
13451                         RTE_LOG(ERR, USER1,
13452                                 "Cryptodev scheduler test require at least "
13453                                 "two worker cores to run. "
13454                                 "Please use the correct coremask.\n");
13455                         return TEST_FAILED;
13456                 }
13457                 strcpy(temp_str, vdev_args);
13458                 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
13459                                 temp_str, socket_id);
13460                 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
13461                 nb_devs = rte_cryptodev_device_count_by_driver(
13462                                 rte_cryptodev_driver_id_get(
13463                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
13464                 if (nb_devs < 1) {
13465                         ret = rte_vdev_init(
13466                                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
13467                                         vdev_args);
13468                         TEST_ASSERT(ret == 0,
13469                                 "Failed to create instance %u of pmd : %s",
13470                                 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13471                 }
13472         }
13473         return testsuite_setup();
13474 }
13475
13476 static int
13477 test_scheduler_attach_slave_op(void)
13478 {
13479         struct crypto_testsuite_params *ts_params = &testsuite_params;
13480         uint8_t sched_id = ts_params->valid_devs[0];
13481         uint32_t nb_devs, i, nb_devs_attached = 0;
13482         int ret;
13483         char vdev_name[32];
13484
13485         /* create 2 AESNI_MB if necessary */
13486         nb_devs = rte_cryptodev_device_count_by_driver(
13487                         rte_cryptodev_driver_id_get(
13488                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
13489         if (nb_devs < 2) {
13490                 for (i = nb_devs; i < 2; i++) {
13491                         snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
13492                                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
13493                                         i);
13494                         ret = rte_vdev_init(vdev_name, NULL);
13495
13496                         TEST_ASSERT(ret == 0,
13497                                 "Failed to create instance %u of"
13498                                 " pmd : %s",
13499                                 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13500                 }
13501         }
13502
13503         /* attach 2 AESNI_MB cdevs */
13504         for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
13505                         i++) {
13506                 struct rte_cryptodev_info info;
13507                 unsigned int session_size;
13508
13509                 rte_cryptodev_info_get(i, &info);
13510                 if (info.driver_id != rte_cryptodev_driver_id_get(
13511                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
13512                         continue;
13513
13514                 session_size = rte_cryptodev_sym_get_private_session_size(i);
13515                 /*
13516                  * Create the session mempool again, since now there are new devices
13517                  * to use the mempool.
13518                  */
13519                 if (ts_params->session_mpool) {
13520                         rte_mempool_free(ts_params->session_mpool);
13521                         ts_params->session_mpool = NULL;
13522                 }
13523                 if (ts_params->session_priv_mpool) {
13524                         rte_mempool_free(ts_params->session_priv_mpool);
13525                         ts_params->session_priv_mpool = NULL;
13526                 }
13527
13528                 if (info.sym.max_nb_sessions != 0 &&
13529                                 info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
13530                         RTE_LOG(ERR, USER1,
13531                                         "Device does not support "
13532                                         "at least %u sessions\n",
13533                                         MAX_NB_SESSIONS);
13534                         return TEST_FAILED;
13535                 }
13536                 /*
13537                  * Create mempool with maximum number of sessions,
13538                  * to include the session headers
13539                  */
13540                 if (ts_params->session_mpool == NULL) {
13541                         ts_params->session_mpool =
13542                                 rte_cryptodev_sym_session_pool_create(
13543                                                 "test_sess_mp",
13544                                                 MAX_NB_SESSIONS, 0, 0, 0,
13545                                                 SOCKET_ID_ANY);
13546                         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
13547                                         "session mempool allocation failed");
13548                 }
13549
13550                 /*
13551                  * Create mempool with maximum number of sessions,
13552                  * to include device specific session private data
13553                  */
13554                 if (ts_params->session_priv_mpool == NULL) {
13555                         ts_params->session_priv_mpool = rte_mempool_create(
13556                                         "test_sess_mp_priv",
13557                                         MAX_NB_SESSIONS,
13558                                         session_size,
13559                                         0, 0, NULL, NULL, NULL,
13560                                         NULL, SOCKET_ID_ANY,
13561                                         0);
13562
13563                         TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
13564                                         "session mempool allocation failed");
13565                 }
13566
13567                 ts_params->qp_conf.mp_session = ts_params->session_mpool;
13568                 ts_params->qp_conf.mp_session_private =
13569                                 ts_params->session_priv_mpool;
13570
13571                 ret = rte_cryptodev_scheduler_worker_attach(sched_id,
13572                                 (uint8_t)i);
13573
13574                 TEST_ASSERT(ret == 0,
13575                         "Failed to attach device %u of pmd : %s", i,
13576                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13577
13578                 aesni_ids[nb_devs_attached] = (uint8_t)i;
13579
13580                 nb_devs_attached++;
13581         }
13582
13583         return 0;
13584 }
13585
13586 static int
13587 test_scheduler_detach_slave_op(void)
13588 {
13589         struct crypto_testsuite_params *ts_params = &testsuite_params;
13590         uint8_t sched_id = ts_params->valid_devs[0];
13591         uint32_t i;
13592         int ret;
13593
13594         for (i = 0; i < 2; i++) {
13595                 ret = rte_cryptodev_scheduler_worker_detach(sched_id,
13596                                 aesni_ids[i]);
13597                 TEST_ASSERT(ret == 0,
13598                         "Failed to detach device %u", aesni_ids[i]);
13599         }
13600
13601         return 0;
13602 }
13603
13604 static int
13605 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
13606 {
13607         struct crypto_testsuite_params *ts_params = &testsuite_params;
13608         uint8_t sched_id = ts_params->valid_devs[0];
13609         /* set mode */
13610         return rte_cryptodev_scheduler_mode_set(sched_id,
13611                 scheduler_mode);
13612 }
13613
13614 static int
13615 test_scheduler_mode_roundrobin_op(void)
13616 {
13617         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
13618                         0, "Failed to set roundrobin mode");
13619         return 0;
13620
13621 }
13622
13623 static int
13624 test_scheduler_mode_multicore_op(void)
13625 {
13626         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
13627                         0, "Failed to set multicore mode");
13628
13629         return 0;
13630 }
13631
13632 static int
13633 test_scheduler_mode_failover_op(void)
13634 {
13635         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
13636                         0, "Failed to set failover mode");
13637
13638         return 0;
13639 }
13640
13641 static int
13642 test_scheduler_mode_pkt_size_distr_op(void)
13643 {
13644         TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
13645                         0, "Failed to set pktsize mode");
13646
13647         return 0;
13648 }
13649
13650 static int
13651 scheduler_multicore_testsuite_setup(void)
13652 {
13653         if (test_scheduler_attach_slave_op() < 0)
13654                 return TEST_SKIPPED;
13655         if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
13656                 return TEST_SKIPPED;
13657         return 0;
13658 }
13659
13660 static int
13661 scheduler_roundrobin_testsuite_setup(void)
13662 {
13663         if (test_scheduler_attach_slave_op() < 0)
13664                 return TEST_SKIPPED;
13665         if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
13666                 return TEST_SKIPPED;
13667         return 0;
13668 }
13669
13670 static int
13671 scheduler_failover_testsuite_setup(void)
13672 {
13673         if (test_scheduler_attach_slave_op() < 0)
13674                 return TEST_SKIPPED;
13675         if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
13676                 return TEST_SKIPPED;
13677         return 0;
13678 }
13679
13680 static int
13681 scheduler_pkt_size_distr_testsuite_setup(void)
13682 {
13683         if (test_scheduler_attach_slave_op() < 0)
13684                 return TEST_SKIPPED;
13685         if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
13686                 return TEST_SKIPPED;
13687         return 0;
13688 }
13689
13690 static void
13691 scheduler_mode_testsuite_teardown(void)
13692 {
13693         test_scheduler_detach_slave_op();
13694 }
13695
13696 #endif /* RTE_CRYPTO_SCHEDULER */
13697
13698 static struct unit_test_suite end_testsuite = {
13699         .suite_name = NULL,
13700         .setup = NULL,
13701         .teardown = NULL,
13702         .unit_test_suites = NULL
13703 };
13704
13705 #ifdef RTE_LIB_SECURITY
13706 static struct unit_test_suite pdcp_proto_testsuite  = {
13707         .suite_name = "PDCP Proto Unit Test Suite",
13708         .setup = pdcp_proto_testsuite_setup,
13709         .unit_test_cases = {
13710                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13711                         test_PDCP_PROTO_all),
13712                 TEST_CASES_END() /**< NULL terminate unit test array */
13713         }
13714 };
13715
13716 static struct unit_test_suite docsis_proto_testsuite  = {
13717         .suite_name = "Docsis Proto Unit Test Suite",
13718         .setup = docsis_proto_testsuite_setup,
13719         .unit_test_cases = {
13720                 TEST_CASE_ST(ut_setup_security, ut_teardown,
13721                         test_DOCSIS_PROTO_all),
13722                 TEST_CASES_END() /**< NULL terminate unit test array */
13723         }
13724 };
13725 #endif
13726
13727 static struct unit_test_suite cryptodev_gen_testsuite  = {
13728         .suite_name = "Crypto General Unit Test Suite",
13729         .setup = crypto_gen_testsuite_setup,
13730         .unit_test_cases = {
13731                 TEST_CASE_ST(ut_setup, ut_teardown,
13732                                 test_device_configure_invalid_dev_id),
13733                 TEST_CASE_ST(ut_setup, ut_teardown,
13734                                 test_queue_pair_descriptor_setup),
13735                 TEST_CASE_ST(ut_setup, ut_teardown,
13736                                 test_device_configure_invalid_queue_pair_ids),
13737                 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
13738                 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
13739                 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
13740                 TEST_CASES_END() /**< NULL terminate unit test array */
13741         }
13742 };
13743
13744 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
13745         .suite_name = "Negative HMAC SHA1 Unit Test Suite",
13746         .setup = negative_hmac_sha1_testsuite_setup,
13747         .unit_test_cases = {
13748                 /** Negative tests */
13749                 TEST_CASE_ST(ut_setup, ut_teardown,
13750                         authentication_verify_HMAC_SHA1_fail_data_corrupt),
13751                 TEST_CASE_ST(ut_setup, ut_teardown,
13752                         authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13753                 TEST_CASE_ST(ut_setup, ut_teardown,
13754                         auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13755                 TEST_CASE_ST(ut_setup, ut_teardown,
13756                         auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13757
13758                 TEST_CASES_END() /**< NULL terminate unit test array */
13759         }
13760 };
13761
13762 static struct unit_test_suite cryptodev_multi_session_testsuite = {
13763         .suite_name = "Multi Session Unit Test Suite",
13764         .setup = multi_session_testsuite_setup,
13765         .unit_test_cases = {
13766                 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13767                 TEST_CASE_ST(ut_setup, ut_teardown,
13768                                 test_multi_session_random_usage),
13769
13770                 TEST_CASES_END() /**< NULL terminate unit test array */
13771         }
13772 };
13773
13774 static struct unit_test_suite cryptodev_null_testsuite  = {
13775         .suite_name = "NULL Test Suite",
13776         .setup = null_testsuite_setup,
13777         .unit_test_cases = {
13778                 TEST_CASE_ST(ut_setup, ut_teardown,
13779                         test_null_invalid_operation),
13780                 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
13781                 TEST_CASES_END()
13782         }
13783 };
13784
13785 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
13786         .suite_name = "AES CCM Authenticated Test Suite",
13787         .setup = aes_ccm_auth_testsuite_setup,
13788         .unit_test_cases = {
13789                 /** AES CCM Authenticated Encryption 128 bits key*/
13790                 TEST_CASE_ST(ut_setup, ut_teardown,
13791                         test_AES_CCM_authenticated_encryption_test_case_128_1),
13792                 TEST_CASE_ST(ut_setup, ut_teardown,
13793                         test_AES_CCM_authenticated_encryption_test_case_128_2),
13794                 TEST_CASE_ST(ut_setup, ut_teardown,
13795                         test_AES_CCM_authenticated_encryption_test_case_128_3),
13796
13797                 /** AES CCM Authenticated Decryption 128 bits key*/
13798                 TEST_CASE_ST(ut_setup, ut_teardown,
13799                         test_AES_CCM_authenticated_decryption_test_case_128_1),
13800                 TEST_CASE_ST(ut_setup, ut_teardown,
13801                         test_AES_CCM_authenticated_decryption_test_case_128_2),
13802                 TEST_CASE_ST(ut_setup, ut_teardown,
13803                         test_AES_CCM_authenticated_decryption_test_case_128_3),
13804
13805                 /** AES CCM Authenticated Encryption 192 bits key */
13806                 TEST_CASE_ST(ut_setup, ut_teardown,
13807                         test_AES_CCM_authenticated_encryption_test_case_192_1),
13808                 TEST_CASE_ST(ut_setup, ut_teardown,
13809                         test_AES_CCM_authenticated_encryption_test_case_192_2),
13810                 TEST_CASE_ST(ut_setup, ut_teardown,
13811                         test_AES_CCM_authenticated_encryption_test_case_192_3),
13812
13813                 /** AES CCM Authenticated Decryption 192 bits key*/
13814                 TEST_CASE_ST(ut_setup, ut_teardown,
13815                         test_AES_CCM_authenticated_decryption_test_case_192_1),
13816                 TEST_CASE_ST(ut_setup, ut_teardown,
13817                         test_AES_CCM_authenticated_decryption_test_case_192_2),
13818                 TEST_CASE_ST(ut_setup, ut_teardown,
13819                         test_AES_CCM_authenticated_decryption_test_case_192_3),
13820
13821                 /** AES CCM Authenticated Encryption 256 bits key */
13822                 TEST_CASE_ST(ut_setup, ut_teardown,
13823                         test_AES_CCM_authenticated_encryption_test_case_256_1),
13824                 TEST_CASE_ST(ut_setup, ut_teardown,
13825                         test_AES_CCM_authenticated_encryption_test_case_256_2),
13826                 TEST_CASE_ST(ut_setup, ut_teardown,
13827                         test_AES_CCM_authenticated_encryption_test_case_256_3),
13828
13829                 /** AES CCM Authenticated Decryption 256 bits key*/
13830                 TEST_CASE_ST(ut_setup, ut_teardown,
13831                         test_AES_CCM_authenticated_decryption_test_case_256_1),
13832                 TEST_CASE_ST(ut_setup, ut_teardown,
13833                         test_AES_CCM_authenticated_decryption_test_case_256_2),
13834                 TEST_CASE_ST(ut_setup, ut_teardown,
13835                         test_AES_CCM_authenticated_decryption_test_case_256_3),
13836                 TEST_CASES_END()
13837         }
13838 };
13839
13840 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
13841         .suite_name = "AES GCM Authenticated Test Suite",
13842         .setup = aes_gcm_auth_testsuite_setup,
13843         .unit_test_cases = {
13844                 /** AES GCM Authenticated Encryption */
13845                 TEST_CASE_ST(ut_setup, ut_teardown,
13846                         test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
13847                 TEST_CASE_ST(ut_setup, ut_teardown,
13848                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
13849                 TEST_CASE_ST(ut_setup, ut_teardown,
13850                         test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
13851                 TEST_CASE_ST(ut_setup, ut_teardown,
13852                         test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
13853                 TEST_CASE_ST(ut_setup, ut_teardown,
13854                         test_AES_GCM_authenticated_encryption_test_case_1),
13855                 TEST_CASE_ST(ut_setup, ut_teardown,
13856                         test_AES_GCM_authenticated_encryption_test_case_2),
13857                 TEST_CASE_ST(ut_setup, ut_teardown,
13858                         test_AES_GCM_authenticated_encryption_test_case_3),
13859                 TEST_CASE_ST(ut_setup, ut_teardown,
13860                         test_AES_GCM_authenticated_encryption_test_case_4),
13861                 TEST_CASE_ST(ut_setup, ut_teardown,
13862                         test_AES_GCM_authenticated_encryption_test_case_5),
13863                 TEST_CASE_ST(ut_setup, ut_teardown,
13864                         test_AES_GCM_authenticated_encryption_test_case_6),
13865                 TEST_CASE_ST(ut_setup, ut_teardown,
13866                         test_AES_GCM_authenticated_encryption_test_case_7),
13867                 TEST_CASE_ST(ut_setup, ut_teardown,
13868                         test_AES_GCM_authenticated_encryption_test_case_8),
13869                 TEST_CASE_ST(ut_setup, ut_teardown,
13870                         test_AES_GCM_J0_authenticated_encryption_test_case_1),
13871
13872                 /** AES GCM Authenticated Decryption */
13873                 TEST_CASE_ST(ut_setup, ut_teardown,
13874                         test_AES_GCM_authenticated_decryption_test_case_1),
13875                 TEST_CASE_ST(ut_setup, ut_teardown,
13876                         test_AES_GCM_authenticated_decryption_test_case_2),
13877                 TEST_CASE_ST(ut_setup, ut_teardown,
13878                         test_AES_GCM_authenticated_decryption_test_case_3),
13879                 TEST_CASE_ST(ut_setup, ut_teardown,
13880                         test_AES_GCM_authenticated_decryption_test_case_4),
13881                 TEST_CASE_ST(ut_setup, ut_teardown,
13882                         test_AES_GCM_authenticated_decryption_test_case_5),
13883                 TEST_CASE_ST(ut_setup, ut_teardown,
13884                         test_AES_GCM_authenticated_decryption_test_case_6),
13885                 TEST_CASE_ST(ut_setup, ut_teardown,
13886                         test_AES_GCM_authenticated_decryption_test_case_7),
13887                 TEST_CASE_ST(ut_setup, ut_teardown,
13888                         test_AES_GCM_authenticated_decryption_test_case_8),
13889                 TEST_CASE_ST(ut_setup, ut_teardown,
13890                         test_AES_GCM_J0_authenticated_decryption_test_case_1),
13891
13892                 /** AES GCM Authenticated Encryption 192 bits key */
13893                 TEST_CASE_ST(ut_setup, ut_teardown,
13894                         test_AES_GCM_auth_encryption_test_case_192_1),
13895                 TEST_CASE_ST(ut_setup, ut_teardown,
13896                         test_AES_GCM_auth_encryption_test_case_192_2),
13897                 TEST_CASE_ST(ut_setup, ut_teardown,
13898                         test_AES_GCM_auth_encryption_test_case_192_3),
13899                 TEST_CASE_ST(ut_setup, ut_teardown,
13900                         test_AES_GCM_auth_encryption_test_case_192_4),
13901                 TEST_CASE_ST(ut_setup, ut_teardown,
13902                         test_AES_GCM_auth_encryption_test_case_192_5),
13903                 TEST_CASE_ST(ut_setup, ut_teardown,
13904                         test_AES_GCM_auth_encryption_test_case_192_6),
13905                 TEST_CASE_ST(ut_setup, ut_teardown,
13906                         test_AES_GCM_auth_encryption_test_case_192_7),
13907
13908                 /** AES GCM Authenticated Decryption 192 bits key */
13909                 TEST_CASE_ST(ut_setup, ut_teardown,
13910                         test_AES_GCM_auth_decryption_test_case_192_1),
13911                 TEST_CASE_ST(ut_setup, ut_teardown,
13912                         test_AES_GCM_auth_decryption_test_case_192_2),
13913                 TEST_CASE_ST(ut_setup, ut_teardown,
13914                         test_AES_GCM_auth_decryption_test_case_192_3),
13915                 TEST_CASE_ST(ut_setup, ut_teardown,
13916                         test_AES_GCM_auth_decryption_test_case_192_4),
13917                 TEST_CASE_ST(ut_setup, ut_teardown,
13918                         test_AES_GCM_auth_decryption_test_case_192_5),
13919                 TEST_CASE_ST(ut_setup, ut_teardown,
13920                         test_AES_GCM_auth_decryption_test_case_192_6),
13921                 TEST_CASE_ST(ut_setup, ut_teardown,
13922                         test_AES_GCM_auth_decryption_test_case_192_7),
13923
13924                 /** AES GCM Authenticated Encryption 256 bits key */
13925                 TEST_CASE_ST(ut_setup, ut_teardown,
13926                         test_AES_GCM_auth_encryption_test_case_256_1),
13927                 TEST_CASE_ST(ut_setup, ut_teardown,
13928                         test_AES_GCM_auth_encryption_test_case_256_2),
13929                 TEST_CASE_ST(ut_setup, ut_teardown,
13930                         test_AES_GCM_auth_encryption_test_case_256_3),
13931                 TEST_CASE_ST(ut_setup, ut_teardown,
13932                         test_AES_GCM_auth_encryption_test_case_256_4),
13933                 TEST_CASE_ST(ut_setup, ut_teardown,
13934                         test_AES_GCM_auth_encryption_test_case_256_5),
13935                 TEST_CASE_ST(ut_setup, ut_teardown,
13936                         test_AES_GCM_auth_encryption_test_case_256_6),
13937                 TEST_CASE_ST(ut_setup, ut_teardown,
13938                         test_AES_GCM_auth_encryption_test_case_256_7),
13939
13940                 /** AES GCM Authenticated Decryption 256 bits key */
13941                 TEST_CASE_ST(ut_setup, ut_teardown,
13942                         test_AES_GCM_auth_decryption_test_case_256_1),
13943                 TEST_CASE_ST(ut_setup, ut_teardown,
13944                         test_AES_GCM_auth_decryption_test_case_256_2),
13945                 TEST_CASE_ST(ut_setup, ut_teardown,
13946                         test_AES_GCM_auth_decryption_test_case_256_3),
13947                 TEST_CASE_ST(ut_setup, ut_teardown,
13948                         test_AES_GCM_auth_decryption_test_case_256_4),
13949                 TEST_CASE_ST(ut_setup, ut_teardown,
13950                         test_AES_GCM_auth_decryption_test_case_256_5),
13951                 TEST_CASE_ST(ut_setup, ut_teardown,
13952                         test_AES_GCM_auth_decryption_test_case_256_6),
13953                 TEST_CASE_ST(ut_setup, ut_teardown,
13954                         test_AES_GCM_auth_decryption_test_case_256_7),
13955
13956                 /** AES GCM Authenticated Encryption big aad size */
13957                 TEST_CASE_ST(ut_setup, ut_teardown,
13958                         test_AES_GCM_auth_encryption_test_case_aad_1),
13959                 TEST_CASE_ST(ut_setup, ut_teardown,
13960                         test_AES_GCM_auth_encryption_test_case_aad_2),
13961
13962                 /** AES GCM Authenticated Decryption big aad size */
13963                 TEST_CASE_ST(ut_setup, ut_teardown,
13964                         test_AES_GCM_auth_decryption_test_case_aad_1),
13965                 TEST_CASE_ST(ut_setup, ut_teardown,
13966                         test_AES_GCM_auth_decryption_test_case_aad_2),
13967
13968                 /** Out of place tests */
13969                 TEST_CASE_ST(ut_setup, ut_teardown,
13970                         test_AES_GCM_authenticated_encryption_oop_test_case_1),
13971                 TEST_CASE_ST(ut_setup, ut_teardown,
13972                         test_AES_GCM_authenticated_decryption_oop_test_case_1),
13973
13974                 /** Session-less tests */
13975                 TEST_CASE_ST(ut_setup, ut_teardown,
13976                         test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
13977                 TEST_CASE_ST(ut_setup, ut_teardown,
13978                         test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
13979
13980                 TEST_CASES_END()
13981         }
13982 };
13983
13984 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
13985         .suite_name = "AES GMAC Authentication Test Suite",
13986         .setup = aes_gmac_auth_testsuite_setup,
13987         .unit_test_cases = {
13988                 TEST_CASE_ST(ut_setup, ut_teardown,
13989                         test_AES_GMAC_authentication_test_case_1),
13990                 TEST_CASE_ST(ut_setup, ut_teardown,
13991                         test_AES_GMAC_authentication_verify_test_case_1),
13992                 TEST_CASE_ST(ut_setup, ut_teardown,
13993                         test_AES_GMAC_authentication_test_case_2),
13994                 TEST_CASE_ST(ut_setup, ut_teardown,
13995                         test_AES_GMAC_authentication_verify_test_case_2),
13996                 TEST_CASE_ST(ut_setup, ut_teardown,
13997                         test_AES_GMAC_authentication_test_case_3),
13998                 TEST_CASE_ST(ut_setup, ut_teardown,
13999                         test_AES_GMAC_authentication_verify_test_case_3),
14000                 TEST_CASE_ST(ut_setup, ut_teardown,
14001                         test_AES_GMAC_authentication_test_case_4),
14002                 TEST_CASE_ST(ut_setup, ut_teardown,
14003                         test_AES_GMAC_authentication_verify_test_case_4),
14004                 TEST_CASE_ST(ut_setup, ut_teardown,
14005                         test_AES_GMAC_authentication_SGL_40B),
14006                 TEST_CASE_ST(ut_setup, ut_teardown,
14007                         test_AES_GMAC_authentication_SGL_80B),
14008                 TEST_CASE_ST(ut_setup, ut_teardown,
14009                         test_AES_GMAC_authentication_SGL_2048B),
14010                 TEST_CASE_ST(ut_setup, ut_teardown,
14011                         test_AES_GMAC_authentication_SGL_2047B),
14012
14013                 TEST_CASES_END()
14014         }
14015 };
14016
14017 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14018         .suite_name = "Chacha20-Poly1305 Test Suite",
14019         .setup = chacha20_poly1305_testsuite_setup,
14020         .unit_test_cases = {
14021                 TEST_CASE_ST(ut_setup, ut_teardown,
14022                         test_chacha20_poly1305_encrypt_test_case_rfc8439),
14023                 TEST_CASE_ST(ut_setup, ut_teardown,
14024                         test_chacha20_poly1305_decrypt_test_case_rfc8439),
14025                 TEST_CASES_END()
14026         }
14027 };
14028
14029 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14030         .suite_name = "SNOW 3G Test Suite",
14031         .setup = snow3g_testsuite_setup,
14032         .unit_test_cases = {
14033                 /** SNOW 3G encrypt only (UEA2) */
14034                 TEST_CASE_ST(ut_setup, ut_teardown,
14035                         test_snow3g_encryption_test_case_1),
14036                 TEST_CASE_ST(ut_setup, ut_teardown,
14037                         test_snow3g_encryption_test_case_2),
14038                 TEST_CASE_ST(ut_setup, ut_teardown,
14039                         test_snow3g_encryption_test_case_3),
14040                 TEST_CASE_ST(ut_setup, ut_teardown,
14041                         test_snow3g_encryption_test_case_4),
14042                 TEST_CASE_ST(ut_setup, ut_teardown,
14043                         test_snow3g_encryption_test_case_5),
14044
14045                 TEST_CASE_ST(ut_setup, ut_teardown,
14046                         test_snow3g_encryption_test_case_1_oop),
14047                 TEST_CASE_ST(ut_setup, ut_teardown,
14048                         test_snow3g_encryption_test_case_1_oop_sgl),
14049                 TEST_CASE_ST(ut_setup, ut_teardown,
14050                         test_snow3g_encryption_test_case_1_offset_oop),
14051                 TEST_CASE_ST(ut_setup, ut_teardown,
14052                         test_snow3g_decryption_test_case_1_oop),
14053
14054                 /** SNOW 3G generate auth, then encrypt (UEA2) */
14055                 TEST_CASE_ST(ut_setup, ut_teardown,
14056                         test_snow3g_auth_cipher_test_case_1),
14057                 TEST_CASE_ST(ut_setup, ut_teardown,
14058                         test_snow3g_auth_cipher_test_case_2),
14059                 TEST_CASE_ST(ut_setup, ut_teardown,
14060                         test_snow3g_auth_cipher_test_case_2_oop),
14061                 TEST_CASE_ST(ut_setup, ut_teardown,
14062                         test_snow3g_auth_cipher_part_digest_enc),
14063                 TEST_CASE_ST(ut_setup, ut_teardown,
14064                         test_snow3g_auth_cipher_part_digest_enc_oop),
14065                 TEST_CASE_ST(ut_setup, ut_teardown,
14066                         test_snow3g_auth_cipher_test_case_3_sgl),
14067                 TEST_CASE_ST(ut_setup, ut_teardown,
14068                         test_snow3g_auth_cipher_test_case_3_oop_sgl),
14069                 TEST_CASE_ST(ut_setup, ut_teardown,
14070                         test_snow3g_auth_cipher_part_digest_enc_sgl),
14071                 TEST_CASE_ST(ut_setup, ut_teardown,
14072                         test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14073
14074                 /** SNOW 3G decrypt (UEA2), then verify auth */
14075                 TEST_CASE_ST(ut_setup, ut_teardown,
14076                         test_snow3g_auth_cipher_verify_test_case_1),
14077                 TEST_CASE_ST(ut_setup, ut_teardown,
14078                         test_snow3g_auth_cipher_verify_test_case_2),
14079                 TEST_CASE_ST(ut_setup, ut_teardown,
14080                         test_snow3g_auth_cipher_verify_test_case_2_oop),
14081                 TEST_CASE_ST(ut_setup, ut_teardown,
14082                         test_snow3g_auth_cipher_verify_part_digest_enc),
14083                 TEST_CASE_ST(ut_setup, ut_teardown,
14084                         test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14085                 TEST_CASE_ST(ut_setup, ut_teardown,
14086                         test_snow3g_auth_cipher_verify_test_case_3_sgl),
14087                 TEST_CASE_ST(ut_setup, ut_teardown,
14088                         test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14089                 TEST_CASE_ST(ut_setup, ut_teardown,
14090                         test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14091                 TEST_CASE_ST(ut_setup, ut_teardown,
14092                         test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14093
14094                 /** SNOW 3G decrypt only (UEA2) */
14095                 TEST_CASE_ST(ut_setup, ut_teardown,
14096                         test_snow3g_decryption_test_case_1),
14097                 TEST_CASE_ST(ut_setup, ut_teardown,
14098                         test_snow3g_decryption_test_case_2),
14099                 TEST_CASE_ST(ut_setup, ut_teardown,
14100                         test_snow3g_decryption_test_case_3),
14101                 TEST_CASE_ST(ut_setup, ut_teardown,
14102                         test_snow3g_decryption_test_case_4),
14103                 TEST_CASE_ST(ut_setup, ut_teardown,
14104                         test_snow3g_decryption_test_case_5),
14105                 TEST_CASE_ST(ut_setup, ut_teardown,
14106                         test_snow3g_decryption_with_digest_test_case_1),
14107                 TEST_CASE_ST(ut_setup, ut_teardown,
14108                         test_snow3g_hash_generate_test_case_1),
14109                 TEST_CASE_ST(ut_setup, ut_teardown,
14110                         test_snow3g_hash_generate_test_case_2),
14111                 TEST_CASE_ST(ut_setup, ut_teardown,
14112                         test_snow3g_hash_generate_test_case_3),
14113
14114                 /* Tests with buffers which length is not byte-aligned */
14115                 TEST_CASE_ST(ut_setup, ut_teardown,
14116                         test_snow3g_hash_generate_test_case_4),
14117                 TEST_CASE_ST(ut_setup, ut_teardown,
14118                         test_snow3g_hash_generate_test_case_5),
14119                 TEST_CASE_ST(ut_setup, ut_teardown,
14120                         test_snow3g_hash_generate_test_case_6),
14121                 TEST_CASE_ST(ut_setup, ut_teardown,
14122                         test_snow3g_hash_verify_test_case_1),
14123                 TEST_CASE_ST(ut_setup, ut_teardown,
14124                         test_snow3g_hash_verify_test_case_2),
14125                 TEST_CASE_ST(ut_setup, ut_teardown,
14126                         test_snow3g_hash_verify_test_case_3),
14127
14128                 /* Tests with buffers which length is not byte-aligned */
14129                 TEST_CASE_ST(ut_setup, ut_teardown,
14130                         test_snow3g_hash_verify_test_case_4),
14131                 TEST_CASE_ST(ut_setup, ut_teardown,
14132                         test_snow3g_hash_verify_test_case_5),
14133                 TEST_CASE_ST(ut_setup, ut_teardown,
14134                         test_snow3g_hash_verify_test_case_6),
14135                 TEST_CASE_ST(ut_setup, ut_teardown,
14136                         test_snow3g_cipher_auth_test_case_1),
14137                 TEST_CASE_ST(ut_setup, ut_teardown,
14138                         test_snow3g_auth_cipher_with_digest_test_case_1),
14139                 TEST_CASES_END()
14140         }
14141 };
14142
14143 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14144         .suite_name = "ZUC Test Suite",
14145         .setup = zuc_testsuite_setup,
14146         .unit_test_cases = {
14147                 /** ZUC encrypt only (EEA3) */
14148                 TEST_CASE_ST(ut_setup, ut_teardown,
14149                         test_zuc_encryption_test_case_1),
14150                 TEST_CASE_ST(ut_setup, ut_teardown,
14151                         test_zuc_encryption_test_case_2),
14152                 TEST_CASE_ST(ut_setup, ut_teardown,
14153                         test_zuc_encryption_test_case_3),
14154                 TEST_CASE_ST(ut_setup, ut_teardown,
14155                         test_zuc_encryption_test_case_4),
14156                 TEST_CASE_ST(ut_setup, ut_teardown,
14157                         test_zuc_encryption_test_case_5),
14158                 TEST_CASE_ST(ut_setup, ut_teardown,
14159                         test_zuc_encryption_test_case_6_sgl),
14160
14161                 /** ZUC authenticate (EIA3) */
14162                 TEST_CASE_ST(ut_setup, ut_teardown,
14163                         test_zuc_hash_generate_test_case_1),
14164                 TEST_CASE_ST(ut_setup, ut_teardown,
14165                         test_zuc_hash_generate_test_case_2),
14166                 TEST_CASE_ST(ut_setup, ut_teardown,
14167                         test_zuc_hash_generate_test_case_3),
14168                 TEST_CASE_ST(ut_setup, ut_teardown,
14169                         test_zuc_hash_generate_test_case_4),
14170                 TEST_CASE_ST(ut_setup, ut_teardown,
14171                         test_zuc_hash_generate_test_case_5),
14172                 TEST_CASE_ST(ut_setup, ut_teardown,
14173                         test_zuc_hash_generate_test_case_6),
14174                 TEST_CASE_ST(ut_setup, ut_teardown,
14175                         test_zuc_hash_generate_test_case_7),
14176                 TEST_CASE_ST(ut_setup, ut_teardown,
14177                         test_zuc_hash_generate_test_case_8),
14178
14179                 /** ZUC alg-chain (EEA3/EIA3) */
14180                 TEST_CASE_ST(ut_setup, ut_teardown,
14181                         test_zuc_cipher_auth_test_case_1),
14182                 TEST_CASE_ST(ut_setup, ut_teardown,
14183                         test_zuc_cipher_auth_test_case_2),
14184
14185                 /** ZUC generate auth, then encrypt (EEA3) */
14186                 TEST_CASE_ST(ut_setup, ut_teardown,
14187                         test_zuc_auth_cipher_test_case_1),
14188                 TEST_CASE_ST(ut_setup, ut_teardown,
14189                         test_zuc_auth_cipher_test_case_1_oop),
14190                 TEST_CASE_ST(ut_setup, ut_teardown,
14191                         test_zuc_auth_cipher_test_case_1_sgl),
14192                 TEST_CASE_ST(ut_setup, ut_teardown,
14193                         test_zuc_auth_cipher_test_case_1_oop_sgl),
14194
14195                 /** ZUC decrypt (EEA3), then verify auth */
14196                 TEST_CASE_ST(ut_setup, ut_teardown,
14197                         test_zuc_auth_cipher_verify_test_case_1),
14198                 TEST_CASE_ST(ut_setup, ut_teardown,
14199                         test_zuc_auth_cipher_verify_test_case_1_oop),
14200                 TEST_CASE_ST(ut_setup, ut_teardown,
14201                         test_zuc_auth_cipher_verify_test_case_1_sgl),
14202                 TEST_CASE_ST(ut_setup, ut_teardown,
14203                         test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
14204                 TEST_CASES_END()
14205         }
14206 };
14207
14208 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
14209         .suite_name = "HMAC_MD5 Authentication Test Suite",
14210         .setup = hmac_md5_auth_testsuite_setup,
14211         .unit_test_cases = {
14212                 TEST_CASE_ST(ut_setup, ut_teardown,
14213                         test_MD5_HMAC_generate_case_1),
14214                 TEST_CASE_ST(ut_setup, ut_teardown,
14215                         test_MD5_HMAC_verify_case_1),
14216                 TEST_CASE_ST(ut_setup, ut_teardown,
14217                         test_MD5_HMAC_generate_case_2),
14218                 TEST_CASE_ST(ut_setup, ut_teardown,
14219                         test_MD5_HMAC_verify_case_2),
14220                 TEST_CASES_END()
14221         }
14222 };
14223
14224 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
14225         .suite_name = "Kasumi Test Suite",
14226         .setup = kasumi_testsuite_setup,
14227         .unit_test_cases = {
14228                 /** KASUMI hash only (UIA1) */
14229                 TEST_CASE_ST(ut_setup, ut_teardown,
14230                         test_kasumi_hash_generate_test_case_1),
14231                 TEST_CASE_ST(ut_setup, ut_teardown,
14232                         test_kasumi_hash_generate_test_case_2),
14233                 TEST_CASE_ST(ut_setup, ut_teardown,
14234                         test_kasumi_hash_generate_test_case_3),
14235                 TEST_CASE_ST(ut_setup, ut_teardown,
14236                         test_kasumi_hash_generate_test_case_4),
14237                 TEST_CASE_ST(ut_setup, ut_teardown,
14238                         test_kasumi_hash_generate_test_case_5),
14239                 TEST_CASE_ST(ut_setup, ut_teardown,
14240                         test_kasumi_hash_generate_test_case_6),
14241
14242                 TEST_CASE_ST(ut_setup, ut_teardown,
14243                         test_kasumi_hash_verify_test_case_1),
14244                 TEST_CASE_ST(ut_setup, ut_teardown,
14245                         test_kasumi_hash_verify_test_case_2),
14246                 TEST_CASE_ST(ut_setup, ut_teardown,
14247                         test_kasumi_hash_verify_test_case_3),
14248                 TEST_CASE_ST(ut_setup, ut_teardown,
14249                         test_kasumi_hash_verify_test_case_4),
14250                 TEST_CASE_ST(ut_setup, ut_teardown,
14251                         test_kasumi_hash_verify_test_case_5),
14252
14253                 /** KASUMI encrypt only (UEA1) */
14254                 TEST_CASE_ST(ut_setup, ut_teardown,
14255                         test_kasumi_encryption_test_case_1),
14256                 TEST_CASE_ST(ut_setup, ut_teardown,
14257                         test_kasumi_encryption_test_case_1_sgl),
14258                 TEST_CASE_ST(ut_setup, ut_teardown,
14259                         test_kasumi_encryption_test_case_1_oop),
14260                 TEST_CASE_ST(ut_setup, ut_teardown,
14261                         test_kasumi_encryption_test_case_1_oop_sgl),
14262                 TEST_CASE_ST(ut_setup, ut_teardown,
14263                         test_kasumi_encryption_test_case_2),
14264                 TEST_CASE_ST(ut_setup, ut_teardown,
14265                         test_kasumi_encryption_test_case_3),
14266                 TEST_CASE_ST(ut_setup, ut_teardown,
14267                         test_kasumi_encryption_test_case_4),
14268                 TEST_CASE_ST(ut_setup, ut_teardown,
14269                         test_kasumi_encryption_test_case_5),
14270
14271                 /** KASUMI decrypt only (UEA1) */
14272                 TEST_CASE_ST(ut_setup, ut_teardown,
14273                         test_kasumi_decryption_test_case_1),
14274                 TEST_CASE_ST(ut_setup, ut_teardown,
14275                         test_kasumi_decryption_test_case_2),
14276                 TEST_CASE_ST(ut_setup, ut_teardown,
14277                         test_kasumi_decryption_test_case_3),
14278                 TEST_CASE_ST(ut_setup, ut_teardown,
14279                         test_kasumi_decryption_test_case_4),
14280                 TEST_CASE_ST(ut_setup, ut_teardown,
14281                         test_kasumi_decryption_test_case_5),
14282                 TEST_CASE_ST(ut_setup, ut_teardown,
14283                         test_kasumi_decryption_test_case_1_oop),
14284
14285                 TEST_CASE_ST(ut_setup, ut_teardown,
14286                         test_kasumi_cipher_auth_test_case_1),
14287
14288                 /** KASUMI generate auth, then encrypt (F8) */
14289                 TEST_CASE_ST(ut_setup, ut_teardown,
14290                         test_kasumi_auth_cipher_test_case_1),
14291                 TEST_CASE_ST(ut_setup, ut_teardown,
14292                         test_kasumi_auth_cipher_test_case_2),
14293                 TEST_CASE_ST(ut_setup, ut_teardown,
14294                         test_kasumi_auth_cipher_test_case_2_oop),
14295                 TEST_CASE_ST(ut_setup, ut_teardown,
14296                         test_kasumi_auth_cipher_test_case_2_sgl),
14297                 TEST_CASE_ST(ut_setup, ut_teardown,
14298                         test_kasumi_auth_cipher_test_case_2_oop_sgl),
14299
14300                 /** KASUMI decrypt (F8), then verify auth */
14301                 TEST_CASE_ST(ut_setup, ut_teardown,
14302                         test_kasumi_auth_cipher_verify_test_case_1),
14303                 TEST_CASE_ST(ut_setup, ut_teardown,
14304                         test_kasumi_auth_cipher_verify_test_case_2),
14305                 TEST_CASE_ST(ut_setup, ut_teardown,
14306                         test_kasumi_auth_cipher_verify_test_case_2_oop),
14307                 TEST_CASE_ST(ut_setup, ut_teardown,
14308                         test_kasumi_auth_cipher_verify_test_case_2_sgl),
14309                 TEST_CASE_ST(ut_setup, ut_teardown,
14310                         test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
14311
14312                 TEST_CASES_END()
14313         }
14314 };
14315
14316 static struct unit_test_suite cryptodev_esn_testsuite  = {
14317         .suite_name = "ESN Test Suite",
14318         .setup = esn_testsuite_setup,
14319         .unit_test_cases = {
14320                 TEST_CASE_ST(ut_setup, ut_teardown,
14321                         auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
14322                 TEST_CASE_ST(ut_setup, ut_teardown,
14323                         auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
14324                 TEST_CASES_END()
14325         }
14326 };
14327
14328 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
14329         .suite_name = "Negative AES GCM Test Suite",
14330         .setup = negative_aes_gcm_testsuite_setup,
14331         .unit_test_cases = {
14332                 TEST_CASE_ST(ut_setup, ut_teardown,
14333                         test_AES_GCM_auth_encryption_fail_iv_corrupt),
14334                 TEST_CASE_ST(ut_setup, ut_teardown,
14335                         test_AES_GCM_auth_encryption_fail_in_data_corrupt),
14336                 TEST_CASE_ST(ut_setup, ut_teardown,
14337                         test_AES_GCM_auth_encryption_fail_out_data_corrupt),
14338                 TEST_CASE_ST(ut_setup, ut_teardown,
14339                         test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
14340                 TEST_CASE_ST(ut_setup, ut_teardown,
14341                         test_AES_GCM_auth_encryption_fail_aad_corrupt),
14342                 TEST_CASE_ST(ut_setup, ut_teardown,
14343                         test_AES_GCM_auth_encryption_fail_tag_corrupt),
14344                 TEST_CASE_ST(ut_setup, ut_teardown,
14345                         test_AES_GCM_auth_decryption_fail_iv_corrupt),
14346                 TEST_CASE_ST(ut_setup, ut_teardown,
14347                         test_AES_GCM_auth_decryption_fail_in_data_corrupt),
14348                 TEST_CASE_ST(ut_setup, ut_teardown,
14349                         test_AES_GCM_auth_decryption_fail_out_data_corrupt),
14350                 TEST_CASE_ST(ut_setup, ut_teardown,
14351                         test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
14352                 TEST_CASE_ST(ut_setup, ut_teardown,
14353                         test_AES_GCM_auth_decryption_fail_aad_corrupt),
14354                 TEST_CASE_ST(ut_setup, ut_teardown,
14355                         test_AES_GCM_auth_decryption_fail_tag_corrupt),
14356
14357                 TEST_CASES_END()
14358         }
14359 };
14360
14361 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
14362         .suite_name = "Negative AES GMAC Test Suite",
14363         .setup = negative_aes_gmac_testsuite_setup,
14364         .unit_test_cases = {
14365                 TEST_CASE_ST(ut_setup, ut_teardown,
14366                         authentication_verify_AES128_GMAC_fail_data_corrupt),
14367                 TEST_CASE_ST(ut_setup, ut_teardown,
14368                         authentication_verify_AES128_GMAC_fail_tag_corrupt),
14369
14370                 TEST_CASES_END()
14371         }
14372 };
14373
14374 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
14375         .suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
14376         .setup = mixed_cipher_hash_testsuite_setup,
14377         .unit_test_cases = {
14378                 /** AUTH AES CMAC + CIPHER AES CTR */
14379                 TEST_CASE_ST(ut_setup, ut_teardown,
14380                         test_aes_cmac_aes_ctr_digest_enc_test_case_1),
14381                 TEST_CASE_ST(ut_setup, ut_teardown,
14382                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14383                 TEST_CASE_ST(ut_setup, ut_teardown,
14384                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14385                 TEST_CASE_ST(ut_setup, ut_teardown,
14386                         test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14387                 TEST_CASE_ST(ut_setup, ut_teardown,
14388                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
14389                 TEST_CASE_ST(ut_setup, ut_teardown,
14390                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14391                 TEST_CASE_ST(ut_setup, ut_teardown,
14392                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14393                 TEST_CASE_ST(ut_setup, ut_teardown,
14394                         test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14395
14396                 /** AUTH ZUC + CIPHER SNOW3G */
14397                 TEST_CASE_ST(ut_setup, ut_teardown,
14398                         test_auth_zuc_cipher_snow_test_case_1),
14399                 TEST_CASE_ST(ut_setup, ut_teardown,
14400                         test_verify_auth_zuc_cipher_snow_test_case_1),
14401                 /** AUTH AES CMAC + CIPHER SNOW3G */
14402                 TEST_CASE_ST(ut_setup, ut_teardown,
14403                         test_auth_aes_cmac_cipher_snow_test_case_1),
14404                 TEST_CASE_ST(ut_setup, ut_teardown,
14405                         test_verify_auth_aes_cmac_cipher_snow_test_case_1),
14406                 /** AUTH ZUC + CIPHER AES CTR */
14407                 TEST_CASE_ST(ut_setup, ut_teardown,
14408                         test_auth_zuc_cipher_aes_ctr_test_case_1),
14409                 TEST_CASE_ST(ut_setup, ut_teardown,
14410                         test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
14411                 /** AUTH SNOW3G + CIPHER AES CTR */
14412                 TEST_CASE_ST(ut_setup, ut_teardown,
14413                         test_auth_snow_cipher_aes_ctr_test_case_1),
14414                 TEST_CASE_ST(ut_setup, ut_teardown,
14415                         test_verify_auth_snow_cipher_aes_ctr_test_case_1),
14416                 /** AUTH SNOW3G + CIPHER ZUC */
14417                 TEST_CASE_ST(ut_setup, ut_teardown,
14418                         test_auth_snow_cipher_zuc_test_case_1),
14419                 TEST_CASE_ST(ut_setup, ut_teardown,
14420                         test_verify_auth_snow_cipher_zuc_test_case_1),
14421                 /** AUTH AES CMAC + CIPHER ZUC */
14422                 TEST_CASE_ST(ut_setup, ut_teardown,
14423                         test_auth_aes_cmac_cipher_zuc_test_case_1),
14424                 TEST_CASE_ST(ut_setup, ut_teardown,
14425                         test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
14426
14427                 /** AUTH NULL + CIPHER SNOW3G */
14428                 TEST_CASE_ST(ut_setup, ut_teardown,
14429                         test_auth_null_cipher_snow_test_case_1),
14430                 TEST_CASE_ST(ut_setup, ut_teardown,
14431                         test_verify_auth_null_cipher_snow_test_case_1),
14432                 /** AUTH NULL + CIPHER ZUC */
14433                 TEST_CASE_ST(ut_setup, ut_teardown,
14434                         test_auth_null_cipher_zuc_test_case_1),
14435                 TEST_CASE_ST(ut_setup, ut_teardown,
14436                         test_verify_auth_null_cipher_zuc_test_case_1),
14437                 /** AUTH SNOW3G + CIPHER NULL */
14438                 TEST_CASE_ST(ut_setup, ut_teardown,
14439                         test_auth_snow_cipher_null_test_case_1),
14440                 TEST_CASE_ST(ut_setup, ut_teardown,
14441                         test_verify_auth_snow_cipher_null_test_case_1),
14442                 /** AUTH ZUC + CIPHER NULL */
14443                 TEST_CASE_ST(ut_setup, ut_teardown,
14444                         test_auth_zuc_cipher_null_test_case_1),
14445                 TEST_CASE_ST(ut_setup, ut_teardown,
14446                         test_verify_auth_zuc_cipher_null_test_case_1),
14447                 /** AUTH NULL + CIPHER AES CTR */
14448                 TEST_CASE_ST(ut_setup, ut_teardown,
14449                         test_auth_null_cipher_aes_ctr_test_case_1),
14450                 TEST_CASE_ST(ut_setup, ut_teardown,
14451                         test_verify_auth_null_cipher_aes_ctr_test_case_1),
14452                 /** AUTH AES CMAC + CIPHER NULL */
14453                 TEST_CASE_ST(ut_setup, ut_teardown,
14454                         test_auth_aes_cmac_cipher_null_test_case_1),
14455                 TEST_CASE_ST(ut_setup, ut_teardown,
14456                         test_verify_auth_aes_cmac_cipher_null_test_case_1),
14457                 TEST_CASES_END()
14458         }
14459 };
14460
14461 static int
14462 run_cryptodev_testsuite(const char *pmd_name)
14463 {
14464         uint8_t ret, j, i = 0, blk_start_idx = 0;
14465         const enum blockcipher_test_type blk_suites[] = {
14466                 BLKCIPHER_AES_CHAIN_TYPE,
14467                 BLKCIPHER_AES_CIPHERONLY_TYPE,
14468                 BLKCIPHER_AES_DOCSIS_TYPE,
14469                 BLKCIPHER_3DES_CHAIN_TYPE,
14470                 BLKCIPHER_3DES_CIPHERONLY_TYPE,
14471                 BLKCIPHER_DES_CIPHERONLY_TYPE,
14472                 BLKCIPHER_DES_DOCSIS_TYPE,
14473                 BLKCIPHER_AUTHONLY_TYPE};
14474         struct unit_test_suite *static_suites[] = {
14475                 &cryptodev_multi_session_testsuite,
14476                 &cryptodev_null_testsuite,
14477                 &cryptodev_aes_ccm_auth_testsuite,
14478                 &cryptodev_aes_gcm_auth_testsuite,
14479                 &cryptodev_aes_gmac_auth_testsuite,
14480                 &cryptodev_snow3g_testsuite,
14481                 &cryptodev_chacha20_poly1305_testsuite,
14482                 &cryptodev_zuc_testsuite,
14483                 &cryptodev_hmac_md5_auth_testsuite,
14484                 &cryptodev_kasumi_testsuite,
14485                 &cryptodev_esn_testsuite,
14486                 &cryptodev_negative_aes_gcm_testsuite,
14487                 &cryptodev_negative_aes_gmac_testsuite,
14488                 &cryptodev_mixed_cipher_hash_testsuite,
14489                 &cryptodev_negative_hmac_sha1_testsuite,
14490                 &cryptodev_gen_testsuite,
14491 #ifdef RTE_LIB_SECURITY
14492                 &pdcp_proto_testsuite,
14493                 &docsis_proto_testsuite,
14494 #endif
14495                 &end_testsuite
14496         };
14497         static struct unit_test_suite ts = {
14498                 .suite_name = "Cryptodev Unit Test Suite",
14499                 .setup = testsuite_setup,
14500                 .teardown = testsuite_teardown,
14501                 .unit_test_cases = {TEST_CASES_END()}
14502         };
14503
14504         gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
14505
14506         if (gbl_driver_id == -1) {
14507                 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
14508                 return TEST_SKIPPED;
14509         }
14510
14511         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
14512                         (RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
14513
14514         ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
14515         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
14516         ret = unit_test_suite_runner(&ts);
14517
14518         FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
14519         free(ts.unit_test_suites);
14520         return ret;
14521 }
14522
14523 static int
14524 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
14525 {
14526         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14527 }
14528
14529 static int
14530 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
14531 {
14532         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
14533 }
14534
14535 static int
14536 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
14537 {
14538         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14539 }
14540
14541 static int
14542 test_cryptodev_cpu_aesni_mb(void)
14543 {
14544         int32_t rc;
14545         enum rte_security_session_action_type at = gbl_action_type;
14546         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14547         rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14548         gbl_action_type = at;
14549         return rc;
14550 }
14551
14552 static int
14553 test_cryptodev_openssl(void)
14554 {
14555         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
14556 }
14557
14558 static int
14559 test_cryptodev_aesni_gcm(void)
14560 {
14561         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14562 }
14563
14564 static int
14565 test_cryptodev_cpu_aesni_gcm(void)
14566 {
14567         int32_t rc;
14568         enum rte_security_session_action_type at = gbl_action_type;
14569         gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14570         rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14571         gbl_action_type = at;
14572         return rc;
14573 }
14574
14575 static int
14576 test_cryptodev_null(void)
14577 {
14578         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
14579 }
14580
14581 static int
14582 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
14583 {
14584         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
14585 }
14586
14587 static int
14588 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
14589 {
14590         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
14591 }
14592
14593 static int
14594 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
14595 {
14596         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
14597 }
14598
14599 static int
14600 test_cryptodev_armv8(void)
14601 {
14602         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
14603 }
14604
14605 static int
14606 test_cryptodev_mrvl(void)
14607 {
14608         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
14609 }
14610
14611 #ifdef RTE_CRYPTO_SCHEDULER
14612
14613 static int
14614 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
14615 {
14616         uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
14617         const enum blockcipher_test_type blk_suites[] = {
14618                 BLKCIPHER_AES_CHAIN_TYPE,
14619                 BLKCIPHER_AES_CIPHERONLY_TYPE,
14620                 BLKCIPHER_AUTHONLY_TYPE
14621         };
14622         static struct unit_test_suite scheduler_multicore = {
14623                 .suite_name = "Scheduler Multicore Unit Test Suite",
14624                 .setup = scheduler_multicore_testsuite_setup,
14625                 .teardown = scheduler_mode_testsuite_teardown,
14626                 .unit_test_cases = {TEST_CASES_END()}
14627         };
14628         static struct unit_test_suite scheduler_round_robin = {
14629                 .suite_name = "Scheduler Round Robin Unit Test Suite",
14630                 .setup = scheduler_roundrobin_testsuite_setup,
14631                 .teardown = scheduler_mode_testsuite_teardown,
14632                 .unit_test_cases = {TEST_CASES_END()}
14633         };
14634         static struct unit_test_suite scheduler_failover = {
14635                 .suite_name = "Scheduler Failover Unit Test Suite",
14636                 .setup = scheduler_failover_testsuite_setup,
14637                 .teardown = scheduler_mode_testsuite_teardown,
14638                 .unit_test_cases = {TEST_CASES_END()}
14639         };
14640         static struct unit_test_suite scheduler_pkt_size_distr = {
14641                 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
14642                 .setup = scheduler_pkt_size_distr_testsuite_setup,
14643                 .teardown = scheduler_mode_testsuite_teardown,
14644                 .unit_test_cases = {TEST_CASES_END()}
14645         };
14646         struct unit_test_suite *sched_mode_suites[] = {
14647                 &scheduler_multicore,
14648                 &scheduler_round_robin,
14649                 &scheduler_failover,
14650                 &scheduler_pkt_size_distr
14651         };
14652         static struct unit_test_suite scheduler_config = {
14653                 .suite_name = "Crypto Device Scheduler Config Unit Test Suite",
14654                 .unit_test_cases = {
14655                         TEST_CASE(test_scheduler_attach_slave_op),
14656                         TEST_CASE(test_scheduler_mode_multicore_op),
14657                         TEST_CASE(test_scheduler_mode_roundrobin_op),
14658                         TEST_CASE(test_scheduler_mode_failover_op),
14659                         TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
14660                         TEST_CASE(test_scheduler_detach_slave_op),
14661
14662                         TEST_CASES_END() /**< NULL terminate array */
14663                 }
14664         };
14665         struct unit_test_suite *static_suites[] = {
14666                 &scheduler_config,
14667                 &end_testsuite
14668         };
14669         static struct unit_test_suite ts = {
14670                 .suite_name = "Scheduler Unit Test Suite",
14671                 .setup = scheduler_testsuite_setup,
14672                 .teardown = testsuite_teardown,
14673                 .unit_test_cases = {TEST_CASES_END()}
14674         };
14675
14676         gbl_driver_id = rte_cryptodev_driver_id_get(
14677                         RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14678
14679         if (gbl_driver_id == -1) {
14680                 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
14681                 return TEST_SKIPPED;
14682         }
14683
14684         if (rte_cryptodev_driver_id_get(
14685                                 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
14686                 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
14687                 return TEST_SKIPPED;
14688         }
14689
14690         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
14691                 uint8_t blk_i = 0;
14692                 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
14693                                 (struct unit_test_suite *) *
14694                                 (RTE_DIM(blk_suites) + 1));
14695                 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
14696                                 blk_suites, RTE_DIM(blk_suites));
14697                 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
14698         }
14699
14700         ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
14701                         (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
14702         ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
14703                         RTE_DIM(sched_mode_suites));
14704         ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
14705         ret = unit_test_suite_runner(&ts);
14706
14707         for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
14708                 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
14709                                 (*sched_mode_suites[sched_i]),
14710                                 RTE_DIM(blk_suites));
14711                 free(sched_mode_suites[sched_i]->unit_test_suites);
14712         }
14713         free(ts.unit_test_suites);
14714         return ret;
14715 }
14716
14717 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
14718
14719 #endif
14720
14721 static int
14722 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
14723 {
14724         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
14725 }
14726
14727 static int
14728 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
14729 {
14730         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
14731 }
14732
14733 static int
14734 test_cryptodev_ccp(void)
14735 {
14736         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
14737 }
14738
14739 static int
14740 test_cryptodev_octeontx(void)
14741 {
14742         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
14743 }
14744
14745 static int
14746 test_cryptodev_octeontx2(void)
14747 {
14748         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
14749 }
14750
14751 static int
14752 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/)
14753 {
14754         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
14755 }
14756
14757 static int
14758 test_cryptodev_nitrox(void)
14759 {
14760         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
14761 }
14762
14763 static int
14764 test_cryptodev_bcmfs(void)
14765 {
14766         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
14767 }
14768
14769 static int
14770 test_cryptodev_qat_raw_api(void /*argv __rte_unused, int argc __rte_unused*/)
14771 {
14772         int ret;
14773
14774         global_api_test_type = CRYPTODEV_RAW_API_TEST;
14775         ret = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14776         global_api_test_type = CRYPTODEV_API_TEST;
14777
14778         return ret;
14779 }
14780
14781 static int
14782 test_cryptodev_cn9k(void)
14783 {
14784         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
14785 }
14786
14787 static int
14788 test_cryptodev_cn10k(void)
14789 {
14790         return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
14791 }
14792
14793 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
14794                 test_cryptodev_qat_raw_api);
14795 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
14796 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
14797 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
14798         test_cryptodev_cpu_aesni_mb);
14799 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
14800 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
14801 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
14802         test_cryptodev_cpu_aesni_gcm);
14803 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
14804 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
14805 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
14806 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
14807 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
14808 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
14809 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
14810 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
14811 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
14812 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
14813 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
14814 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
14815 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
14816 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
14817 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
14818 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
14819 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);